module MigrationHelpers

Contains additional PostgreSQL statements not available in default migration class.

Public Instance Methods

delete_foreign_key(from_table, to_table) click to toggle source
# File lib/migration_helpers.rb, line 25
def delete_foreign_key(from_table, to_table)
  constraint_name = "fk_#{from_table}_#{to_table}"
  execute %Q{alter table #{from_table} drop constraint #{constraint_name}}
end
foreign_key(from_table, from_column, to_table) click to toggle source

Applies foreign key constraints of the form:

constraint fk_#{from_table}_#{to_table) foreign key from_column references to_table(id)
# File lib/migration_helpers.rb, line 8
def foreign_key(from_table, from_column, to_table)
  constraint_name = "fk_#{from_table}_#{to_table}"

  execute %Q{alter table #{from_table} add constraint #{constraint_name}
            foreign key (#{from_column}) references #{to_table} (id) on delete cascade}
end
foreign_key_no_delete(from_table, from_column, to_table) click to toggle source

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

# File lib/migration_helpers.rb, line 18
def foreign_key_no_delete(from_table, from_column, to_table)
  constraint_name = "fk_#{from_table}_#{to_table}"

  execute %Q{alter table #{from_table} add constraint #{constraint_name}
            foreign key (#{from_column}) references #{to_table} (id)}
end