Skip to content

Commit ab56d5c

Browse files
committed
Fix inverting drop_table without options
1 parent 92b3160 commit ab56d5c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

activerecord/lib/active_record/migration/command_recorder.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ def invert_drop_table(args, &block)
213213
raise ActiveRecord::IrreversibleMigration, "To avoid mistakes, drop_table is only reversible if given options or a block (can be empty)."
214214
end
215215

216-
super(args.push(options), &block)
216+
args << options unless options.empty?
217+
218+
super(args, &block)
217219
end
218220

219221
def invert_rename_table(args)

activerecord/test/cases/invertible_migration_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ def change
154154
end
155155
end
156156

157+
class DropTableMigration < SilentMigration
158+
def change
159+
drop_table("horses") do |t|
160+
t.string :name
161+
end
162+
end
163+
end
164+
157165
class LegacyMigration < ActiveRecord::Migration::Current
158166
def self.up
159167
create_table("horses") do |t|
@@ -433,6 +441,20 @@ def test_migrate_enable_and_disable_extension
433441
end
434442
end
435443

444+
def test_migrate_revert_drop_table
445+
connection = ActiveRecord::Base.lease_connection
446+
migration1 = InvertibleMigration.new
447+
migration1.migrate(:up)
448+
assert connection.table_exists?("horses")
449+
450+
migration2 = DropTableMigration.new
451+
migration2.migrate(:up)
452+
assert_not connection.table_exists?("horses")
453+
454+
migration2.migrate(:down)
455+
assert connection.table_exists?("horses")
456+
end
457+
436458
def test_revert_order
437459
block = Proc.new { |t| t.string :name }
438460
recorder = ActiveRecord::Migration::CommandRecorder.new(ActiveRecord::Base.lease_connection)

0 commit comments

Comments
 (0)