Skip to content

Commit

Permalink
Fixed. down migration of rename_table is failed if migration versio…
Browse files Browse the repository at this point in the history
…n less than 7.1

```
            StandardError:
              An error has occurred, this and all later migrations canceled:

              wrong number of arguments (given 3, expected 2)
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration/compatibility.rb:105:in `rename_table'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration/command_recorder.rb:146:in `block in replay'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration/command_recorder.rb:145:in `each'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration/command_recorder.rb:145:in `replay'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration.rb:855:in `revert'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration.rb:980:in `exec_migration'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration.rb:966:in `block (2 levels) in migrate'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration.rb:965:in `block in migrate'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `with_connection'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration.rb:964:in `migrate'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration.rb:1174:in `migrate'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration.rb:1525:in `block in execute_migration_in_transaction'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/connection_adapters/abstract/transaction.rb:535:in `block in within_new_transaction'
            # ./vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.0/lib/active_support/concurrency/null_lock.rb:9:in `synchronize'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/connection_adapters/abstract/transaction.rb:532:in `within_new_transaction'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:342:in `transaction'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration.rb:1576:in `ddl_transaction'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration.rb:1524:in `execute_migration_in_transaction'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration.rb:1499:in `each'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration.rb:1499:in `migrate_without_lock'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration.rb:1446:in `migrate'
            # ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration.rb:1280:in `down'
            # ./spec/db/setup.rb:47:in `down_migrate'
            # ./spec/support/contexts/setup_databse.rb:8:in `block (2 levels) in <top (required)>'
            # ------------------
            # --- Caused by: ---
            # ArgumentError:
            #   wrong number of arguments (given 3, expected 2)
            #   ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.0/lib/active_record/migration/compatibility.rb:105:in `rename_table'

```
  • Loading branch information
sue445 committed Oct 7, 2023
1 parent 59822bf commit 538a211
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion spec/db/migrate/0007_rename_old_table_to_new_table.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
class RenameOldTableToNewTable < ActiveRecord::Migration[4.2]
migration_version =
if ActiveRecord.version >= Gem::Version.create("7.1.0")
# FIXME: down migration of `rename_table` is failed if migration version less than 7.1...
# c.f. https://github.com/rails/rails/issues/49523
7.1
else
4.2
end

class RenameOldTableToNewTable < ActiveRecord::Migration[migration_version]
def change
rename_table :old_table, :new_table
end
Expand Down

0 comments on commit 538a211

Please sign in to comment.