class ActiveRecord::Migration::CommandRecorder
def inverse_of(command, args, &block)
This method will raise an +IrreversibleMigration+ exception if it cannot
# => [[:add_column, :some_table, :foo, :string], [:add_column, :some_table, :bar, :string]]
recorder.inverse_of(:remove_columns, [:some_table, :foo, :bar, type: :string])
If the inverse of a command requires several commands, returns array of commands.
# => [:rename_table, [:new, :old]]
recorder.inverse_of(:rename_table, [:old, :new])
Returns the inverse of the given command. For example:
def inverse_of(command, args, &block) method = :"invert_#{command}" raise IrreversibleMigration, <<~MSG unless respond_to?(method, true) This migration uses #{command}, which is not automatically reversible. To make the migration reversible you can either: 1. Define #up and #down methods in place of the #change method. 2. Use the #reversible method to define reversible behavior. MSG send(method, args, &block) end