Class: ActiveRecord::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/migration_fu.rb

Constant Summary collapse

MAX_KEY_LENGTH =
64
OPTION_KEYS =
[:restrict, :set_null, :cascade, :no_action]
OPTION_VALUES =
[:on_update, :on_delete]

Class Method Summary collapse

Class Method Details

.add_foreign_key(from_table, to_table, options = {}) ⇒ Object



11
12
13
14
15
# File 'lib/migration_fu.rb', line 11

def add_foreign_key(from_table, to_table, options = {})
  process(from_table, to_table, options) do |ft, tt, id, fk|
    execute "ALTER TABLE #{ft} ADD CONSTRAINT #{id} FOREIGN KEY(#{fk}) REFERENCES #{tt}(id)" << conditions(options)
  end
end

.entirely_reset_column_informationObject



23
24
25
# File 'lib/migration_fu.rb', line 23

def entirely_reset_column_information
  ActiveRecord::Base.send(:subclasses).each(&:reset_column_information)
end

.remove_foreign_key(from_table, to_table, options = {}) ⇒ Object



17
18
19
20
21
# File 'lib/migration_fu.rb', line 17

def remove_foreign_key(from_table, to_table, options = {})
  process(from_table, to_table, options) do |ft, tt, id|
    execute "ALTER TABLE #{ft} DROP FOREIGN KEY #{id}, DROP KEY #{id}"
  end
end