ActiveRecord::Migration::CommandRecorder
records commands done
during a migration and knows how to reverse those commands. The CommandRecorder knows how to invert the
following commands:
-
add_column
-
add_index
-
add_timestamps
-
create_table
-
create_join_table
-
remove_timestamps
-
rename_column
-
rename_index
-
rename_table
Namespace
Methods
- I
- N
- R
Included Modules
Attributes
[RW] | commands | |
[RW] | delegate | |
[RW] | reverting |
Class Public methods
new(delegate = nil)
Link
Instance Public methods
inverse_of(command, args, &block)
Link
Returns the inverse of the given command. For example:
recorder.inverse_of(:rename_table, [:old, :new])
# => [:rename_table, [:new, :old]]
This method will raise an IrreversibleMigration
exception if
it cannot invert the command
.
record(*command, &block)
Link
record command
. command
should be a method name
and arguments. For example:
recorder.record(:method_name, [:arg1, :arg2])
revert()
Link
While executing the given block, the recorded will be in reverting mode. All commands recorded will end up being recorded reverted and in reverse order. For example:
recorder.revert{ recorder.record(:rename_table, [:old, :new]) }
# same effect as recorder.record(:rename_table, [:new, :old])