instance method
revert
Ruby on Rails 7.1.6
Since v3.2.22.5Signature
revert(*migration_classes, &block)
Reverses the migration commands for the given block and the given migrations.
The following migration will remove the table ‘horses’ and create the table ‘apples’ on the way up, and the reverse on the way down.
class FixTLMigration < ActiveRecord::Migration[7.1] def change revert do create_table(:horses) do |t| t.text :content t.datetime :remind_at end end create_table(:apples) do |t| t.string :variety end end end
Or equivalently, if TenderloveMigration is defined as in the documentation for Migration:
require_relative "20121212123456_tenderlove_migration" class FixupTLMigration < ActiveRecord::Migration[7.1] def change revert TenderloveMigration create_table(:apples) do |t| t.string :variety end end end
This command can be nested.
Parameters
-
migration_classesrest -
blockblock
Source
# File activerecord/lib/active_record/migration.rb, line 847
def revert(*migration_classes, &block)
run(*migration_classes.reverse, revert: true) unless migration_classes.empty?
if block_given?
if connection.respond_to? :revert
connection.revert(&block)
else
recorder = command_recorder
@connection = recorder
suppress_messages do
connection.revert(&block)
end
@connection = recorder.delegate
recorder.replay(self)
end
end
end
Defined in activerecord/lib/active_record/migration.rb line 847
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Migration