Skip to content

Commit 5b04d44

Browse files
committed
Don't silently execute statements on migrations when they can't be reversed
Fixes rails#51570.
1 parent 270ed27 commit 5b04d44

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

activerecord/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Don't silently execute statements on migrations when they can't be reversed.
2+
3+
Fixes #51570.
4+
5+
*Rafael Mendonça França*
6+
17
* Allow `Sqlite3Adapter` to use `sqlite3` gem version `2.x`
28

39
*Mike Dalessio*

activerecord/lib/active_record/migration/command_recorder.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,10 @@ def respond_to_missing?(method, _)
376376
super || delegate.respond_to?(method)
377377
end
378378

379-
# Forwards any missing method call to the \target.
379+
# Forwards any missing method call to the target.
380380
def method_missing(method, ...)
381381
if delegate.respond_to?(method)
382+
record(method, ...)
382383
delegate.public_send(method, ...)
383384
else
384385
super

activerecord/test/cases/migration/command_recorder_test.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@ def test_inverse_of_raise_exception_on_unknown_commands
4646
assert_raises(ActiveRecord::IrreversibleMigration) do
4747
@recorder.inverse_of :execute, ["some sql"]
4848
end
49+
assert_raises(ActiveRecord::IrreversibleMigration) do
50+
@recorder.inverse_of :update, ["some sql"]
51+
end
4952
end
5053

5154
def test_irreversible_commands_raise_exception
52-
assert_raises(ActiveRecord::IrreversibleMigration) do
55+
x = assert_raises(ActiveRecord::IrreversibleMigration) do
5356
@recorder.revert { @recorder.execute "some sql" }
5457
end
58+
assert_raises(ActiveRecord::IrreversibleMigration) do
59+
@recorder.revert { @recorder.update "some sql" }
60+
end
5561
end
5662

5763
def test_record

0 commit comments

Comments
 (0)