Method: Sequel::SchemaDumper#dump_foreign_key_migration

Defined in:
lib/sequel/extensions/schema_dumper.rb

#dump_foreign_key_migration(options = OPTS) ⇒ Object

Dump foreign key constraints for all tables as a migration. This complements the foreign_keys: false option to dump_schema_migration. This only dumps the constraints (not the columns) using alter_table/add_foreign_key with an array of columns.

Note that the migration this produces does not have a down block, so you cannot reverse it.



95
96
97
98
99
100
101
102
103
104
# File 'lib/sequel/extensions/schema_dumper.rb', line 95

def dump_foreign_key_migration(options=OPTS)
  ts = _dump_tables(options)
  <<END_MIG
Sequel.migration do
  change do
#{ts.map{|t| dump_table_foreign_keys(t)}.reject{|x| x == ''}.join("\n\n").gsub(/^/, '    ')}
  end
end
END_MIG
end