Module MigrationHelpers
In: lib/migration_helpers.rb

Contains additional PostgreSQL statements not available in default migration class.

Methods

Public Instance methods

[Source]

    # File lib/migration_helpers.rb, line 25
25:   def delete_foreign_key(from_table, to_table)
26:     constraint_name = "fk_#{from_table}_#{to_table}"
27:     execute %{alter table #{from_table} drop constraint #{constraint_name}}
28:   end

Applies foreign key constraints of the form:

  constraint fk_#{from_table}_#{to_table) foreign key from_column references to_table(id)

[Source]

    # File lib/migration_helpers.rb, line 8
 8:   def foreign_key(from_table, from_column, to_table)
 9:     constraint_name = "fk_#{from_table}_#{to_table}"
10:     
11:     execute %{alter table #{from_table} add constraint #{constraint_name} 
12:               foreign key (#{from_column}) references #{to_table} (id) on delete cascade}
13:   end

Applies foreign key constraints of the form:

  constraint fk_#{from_table}_#{to_table) foreign key from_column references to_table(id)

with no cascading delete

[Source]

    # File lib/migration_helpers.rb, line 18
18:   def foreign_key_no_delete(from_table, from_column, to_table)
19:     constraint_name = "fk_#{from_table}_#{to_table}"
20:     
21:     execute %{alter table #{from_table} add constraint #{constraint_name} 
22:               foreign key (#{from_column}) references #{to_table} (id)}
23:   end

[Validate]