aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGannon McGibbon <gannon.mcgibbon@gmail.com>2019-05-10 16:45:46 -0400
committerGannon McGibbon <gannon.mcgibbon@gmail.com>2019-05-10 16:45:46 -0400
commite84ee74854876be00c3d072182af4c936c7d303c (patch)
tree8f2f28cf1d3084d63de98fa6bac897294638a1a3
parent36d145ca457d7f663517ac4096d8fae3da2491a9 (diff)
parent93d2090011b5ccab504b8aeabf6a95b23193a689 (diff)
downloadrails-e84ee74854876be00c3d072182af4c936c7d303c.tar.gz
rails-e84ee74854876be00c3d072182af4c936c7d303c.tar.bz2
rails-e84ee74854876be00c3d072182af4c936c7d303c.zip
Merge branch 'migration-timestamp-fix'
Closes #28707.
-rw-r--r--activerecord/CHANGELOG.md2
-rw-r--r--activerecord/lib/rails/generators/active_record/migration/migration_generator.rb1
-rw-r--r--guides/source/active_record_migrations.md2
-rw-r--r--railties/test/generators/migration_generator_test.rb15
4 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index f708d42e43..a787e6dca7 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,5 @@
+* Allow generated create_table migrations to include or skip timestamps
+ *Michael Duchemin*
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activerecord/CHANGELOG.md) for previous changes.
diff --git a/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb b/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
index cb2c74f1ca..0620a515bd 100644
--- a/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
+++ b/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
@@ -7,6 +7,7 @@ module ActiveRecord
class MigrationGenerator < Base # :nodoc:
argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
+ class_option :timestamps, type: :boolean
class_option :primary_key_type, type: :string, desc: "The type for primary key"
class_option :database, type: :string, aliases: %i(--db), desc: "The database for your migration. By default, the current environment's primary database is used."
diff --git a/guides/source/active_record_migrations.md b/guides/source/active_record_migrations.md
index 270e4a3bf9..9398244ccf 100644
--- a/guides/source/active_record_migrations.md
+++ b/guides/source/active_record_migrations.md
@@ -225,6 +225,8 @@ class CreateProducts < ActiveRecord::Migration[5.0]
create_table :products do |t|
t.string :name
t.string :part_number
+
+ t.timestamps
end
end
end
diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb
index e6b614a935..65cde91436 100644
--- a/railties/test/generators/migration_generator_test.rb
+++ b/railties/test/generators/migration_generator_test.rb
@@ -270,6 +270,21 @@ class MigrationGeneratorTest < Rails::Generators::TestCase
end
end
+ def test_create_table_migration_with_timestamps
+ run_generator ["create_books", "title:string", "content:text"]
+ assert_migration "db/migrate/create_books.rb", /t.timestamps/
+ end
+
+ def test_create_table_timestamps_are_skipped
+ run_generator ["create_books", "title:string", "content:text", "--no-timestamps"]
+
+ assert_migration "db/migrate/create_books.rb" do |m|
+ assert_method :change, m do |change|
+ assert_no_match(/t.timestamps/, change)
+ end
+ end
+ end
+
def test_add_uuid_to_create_table_migration
run_generator ["create_books", "--primary_key_type=uuid"]
assert_migration "db/migrate/create_books.rb" do |content|