Class: ActiveRecord::Migration
- Inherits:
-
Object
- Object
- ActiveRecord::Migration
- 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
- .add_foreign_key(from_table, to_table, options = {}) ⇒ Object
- .entirely_reset_column_information ⇒ Object
- .remove_foreign_key(from_table, to_table, options = {}) ⇒ Object
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, = {}) process(from_table, to_table, ) do |ft, tt, id, fk| execute "ALTER TABLE #{ft} ADD CONSTRAINT #{id} FOREIGN KEY(#{fk}) REFERENCES #{tt}(id)" << conditions() end end |
.entirely_reset_column_information ⇒ Object
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, = {}) process(from_table, to_table, ) do |ft, tt, id| execute "ALTER TABLE #{ft} DROP FOREIGN KEY #{id}, DROP KEY #{id}" end end |