Skip to content

Commit

Permalink
Rails 7.2 refactored schema_migration metadata/context to the pool
Browse files Browse the repository at this point in the history
  • Loading branch information
jrafanie committed Oct 23, 2024
1 parent f3d7002 commit 16b6d7e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions spec/support/migration_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ def suppress_migration_messages
def migrate_to(version)
suppress_migration_messages do
migration_dir = Rails.application.config.paths["db/migrate"]
migration_conn = ::ActiveRecord::Base.connection.schema_migration
ActiveRecord::MigrationContext.new(migration_dir, migration_conn).migrate(version)
ActiveRecord::MigrationContext.new(migration_dir, schema_migration).migrate(version)
end
end

Expand All @@ -126,16 +125,24 @@ def previous_migration_version

def run_migrate
migration_dir = Rails.application.config.paths["db/migrate"]
migration_conn = ::ActiveRecord::Base.connection.schema_migration
context = ActiveRecord::MigrationContext.new(migration_dir, migration_conn)
context = ActiveRecord::MigrationContext.new(migration_dir, schema_migration)

context.run(migration_direction, this_migration_version)
end

def schema_migration
# Rails 7.2 refactored the schema_migration metadata and context to the pool
# https://www.github.com/rails/rails/pull/51162
if Rails.version >= "7.2"
::ActiveRecord::Base.connection.pool.schema_migration
else
::ActiveRecord::Base.connection.schema_migration
end
end

def schema_migrations
migration_dir = Rails.application.config.paths["db/migrate"]
migration_conn = ::ActiveRecord::Base.connection.schema_migration
ActiveRecord::MigrationContext.new(migration_dir, migration_conn).migrations
ActiveRecord::MigrationContext.new(migration_dir, schema_migration).migrations
end

def migrations_and_index
Expand Down

0 comments on commit 16b6d7e

Please sign in to comment.