Skip to content

Commit

Permalink
Merge pull request #49526 from fatkodima/fix-reverting-rename_table-7.0
Browse files Browse the repository at this point in the history
Fix reverting `rename_table` for older migrations

(cherry picked from commit 04b3504)
  • Loading branch information
jonathanhefner committed Oct 7, 2023
1 parent dec60e5 commit af514e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion activerecord/lib/active_record/migration/command_recorder.rb
Expand Up @@ -206,7 +206,10 @@ def invert_drop_table(args, &block)
end

def invert_rename_table(args)
[:rename_table, args.reverse]
old_name, new_name, options = args
args = [new_name, old_name]
args << options if options
[:rename_table, args]
end

def invert_remove_column(args)
Expand Down
20 changes: 20 additions & 0 deletions activerecord/test/cases/migration/compatibility_test.rb
Expand Up @@ -552,6 +552,26 @@ def migrate(x)
connection.drop_table(long_table_name) rescue nil
end

def test_invert_rename_table_on_7_0
connection.create_table(:more_testings)

migration = Class.new(ActiveRecord::Migration[7.0]) {
def change
rename_table :more_testings, :new_more_testings
end
}.new

migration.migrate(:up)
assert connection.table_exists?(:new_more_testings)
assert_not connection.table_exists?(:more_testings)

migration.migrate(:down)
assert_not connection.table_exists?(:new_more_testings)
assert connection.table_exists?(:more_testings)
ensure
connection.drop_table(:more_testings) rescue nil
end

def test_change_column_null_with_non_boolean_arguments_raises_in_a_migration
migration = Class.new(ActiveRecord::Migration[7.1]) do
def up
Expand Down

0 comments on commit af514e4

Please sign in to comment.