mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
commit
e84ee74854
4 changed files with 20 additions and 0 deletions
|
@ -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.
|
||||
|
|
|
@ -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."
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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|
|
||||
|
|
Loading…
Reference in a new issue