Module: Inkling::Util::MigrationHelpers
- Defined in:
- lib/inkling/util/migration_helpers.rb
Instance Method Summary collapse
- #add_foreign_key(from_table, from_column, to_table) ⇒ Object
- #remove_foreign_key(from_table, from_column) ⇒ Object
Instance Method Details
#add_foreign_key(from_table, from_column, to_table) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/inkling/util/migration_helpers.rb', line 4 def add_foreign_key(from_table, from_column, to_table) constraint_name = "fk_#{from_table}_#{from_column}" execute %{alter table #{from_table} add constraint #{constraint_name} foreign key (#{from_column}) references #{to_table}(id)} end |
#remove_foreign_key(from_table, from_column) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/inkling/util/migration_helpers.rb', line 14 def remove_foreign_key(from_table, from_column) constraint_name = "fk_#{from_table}_#{from_column}" execute %{alter table #{from_table} drop foreign key #{constraint_name}} end |