Skip to content

Commit

Permalink
Use references to define polymorphic associations in generator migrat…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
shioyama committed Oct 18, 2018
1 parent 18ec38c commit 158c48a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ class CreateStringTranslations < <%= activerecord_migration_class %>

def change
create_table :mobility_string_translations do |t|
t.string :locale, null: false
t.string :key, null: false
t.string :value
t.integer :translatable_id, null: false
t.string :translatable_type, null: false
t.timestamps null: false
t.string :locale, null: false
t.string :key, null: false
t.string :value
t.references :translatable, polymorphic: true, index: false
t.timestamps null: false
end
add_index :mobility_string_translations, [:translatable_id, :translatable_type, :locale, :key], unique: true, name: :index_mobility_string_translations_on_keys
add_index :mobility_string_translations, [:translatable_id, :translatable_type, :key], name: :index_mobility_string_translations_on_translatable_attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ class CreateTextTranslations < <%= activerecord_migration_class %>

def change
create_table :mobility_text_translations do |t|
t.string :locale, null: false
t.string :key, null: false
t.text :value
t.integer :translatable_id, null: false
t.string :translatable_type, null: false
t.timestamps null: false
t.string :locale, null: false
t.string :key, null: false
t.text :value
t.references :translatable, polymorphic: true, index: false
t.timestamps null: false
end
add_index :mobility_text_translations, [:translatable_id, :translatable_type, :locale, :key], unique: true, name: :index_mobility_text_translations_on_keys
add_index :mobility_text_translations, [:translatable_id, :translatable_type, :key], name: :index_mobility_text_translations_on_translatable_attribute
Expand Down
6 changes: 4 additions & 2 deletions spec/generators/rails/mobility/install_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
end
contains "def change"
contains "create_table :mobility_text_translations"
contains "t.text :value"
contains "t.text :value"
contains "t.references :translatable, polymorphic: true, index: false"
contains "add_index :mobility_text_translations"
contains "name: :index_mobility_text_translations_on_keys"
contains "name: :index_mobility_text_translations_on_translatable_attribute"
Expand All @@ -68,7 +69,8 @@
end
contains "def change"
contains "create_table :mobility_string_translations"
contains "t.string :value"
contains "t.string :value"
contains "t.references :translatable, polymorphic: true, index: false"
contains "add_index :mobility_string_translations"
contains "name: :index_mobility_string_translations_on_keys"
contains "name: :index_mobility_string_translations_on_translatable_attribute"
Expand Down

0 comments on commit 158c48a

Please sign in to comment.