Skip to content

Commit

Permalink
Don't silently execute statements on migrations when they can't be re…
Browse files Browse the repository at this point in the history
…versed

Fixes rails#51570.
  • Loading branch information
rafaelfranca authored and fractaledmind committed May 13, 2024
1 parent fa6ffc8 commit 912ce6a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* Don't silently execute statements on migrations when they can't be reversed.

Fixes #51570.

*Rafael Mendonça França*

* Allow `Sqlite3Adapter` to use `sqlite3` gem version `2.x`

*Mike Dalessio*
Expand Down
3 changes: 2 additions & 1 deletion activerecord/lib/active_record/migration/command_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,10 @@ def respond_to_missing?(method, _)
super || delegate.respond_to?(method)
end

# Forwards any missing method call to the \target.
# Forwards any missing method call to the target.
def method_missing(method, ...)
if delegate.respond_to?(method)
record(method, ...)
delegate.public_send(method, ...)
else
super
Expand Down
8 changes: 7 additions & 1 deletion activerecord/test/cases/migration/command_recorder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ def test_inverse_of_raise_exception_on_unknown_commands
assert_raises(ActiveRecord::IrreversibleMigration) do
@recorder.inverse_of :execute, ["some sql"]
end
assert_raises(ActiveRecord::IrreversibleMigration) do
@recorder.inverse_of :update, ["some sql"]
end
end

def test_irreversible_commands_raise_exception
assert_raises(ActiveRecord::IrreversibleMigration) do
x = assert_raises(ActiveRecord::IrreversibleMigration) do
@recorder.revert { @recorder.execute "some sql" }
end
assert_raises(ActiveRecord::IrreversibleMigration) do
@recorder.revert { @recorder.update "some sql" }
end
end

def test_record
Expand Down

0 comments on commit 912ce6a

Please sign in to comment.