ActiveRecord.CommandRecorder class
Part of Active Record
Records schema statements instead of running them, which is how a migration's change
is reverted. While ActiveRecord::Migration#revert is at work, ActiveRecord.ddl
hands every statement to the recorder, which stores its inverse (drop_table for
create_table, remove_column for add_column and so on); the stored statements are
then run in reverse order. A statement that has no inverse, or that was not given
enough to work its inverse out, raises an error that explains how to make the migration
reversible.
Summary
Methods
Methods
ActiveRecord.CommandRecorder:init()
shared packages/active_record/lib/migrator/command_recorder.lua:210Creates a recorder. The recorder stands in for the schema statements while a migration's #change is being reverted: every statement made is recorded, and in the end the inverse of every statement is run in reverse order.
Returns
- ActiveRecord::CommandRecorder(self)
ActiveRecord.CommandRecorder:inverse_of(name, args)
shared packages/active_record/lib/migrator/command_recorder.lua:252Returns the inverse of a statement, e.g. remove_column for add_column. Raises an error for statements that cannot be reverted.
Parameters
- name String name of the statement
- args List arguments of the statement, with their count under 'n'
Returns
- Map the inverse, with the keys 'command' and 'args'
ActiveRecord.CommandRecorder:record(name, ...)
shared packages/active_record/lib/migrator/command_recorder.lua:226Records a statement. While reverting, the inverse of the statement is recorded instead. The statements of change_table are recorded one by one.
Parameters
- name String name of the statement, e.g. 'add_column'
- ... Vararg arguments of the statement
ActiveRecord.CommandRecorder:record_change_table(table_name, callback)
shared packages/active_record/lib/migrator/command_recorder.lua:243Records the statements made through the table object of change_table.
Parameters
- table_name String
- callback Function receives an ActiveRecord::TableRecorder
ActiveRecord.CommandRecorder:replay()
shared packages/active_record/lib/migrator/command_recorder.lua:288Runs the recorded statements in order.
ActiveRecord.CommandRecorder:revert(callback)
shared packages/active_record/lib/migrator/command_recorder.lua:265Records the statements made inside of the function in reverse, so that running the recorded statements undoes them.
Parameters
- callback Function
ActiveRecord.CommandRecorder:reverting()
shared packages/active_record/lib/migrator/command_recorder.lua:218Checks whether recorded statements are stored as their inverse.
Returns
- Boolean