Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set up migration context directly #240

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ jobs:
gemfile: 'gemfiles/ar_7_0.gemfile'
- ruby-version: '3.2'
gemfile: 'gemfiles/ar_7_1.gemfile'
- ruby-version: '3.2'
gemfile: 'gemfiles/ar_7_2.gemfile'
- ruby-version: 'head'
gemfile: 'gemfiles/ar_main.gemfile'

Expand Down
2 changes: 1 addition & 1 deletion Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ appraise 'ar_4_2' do
gem 'sqlite3', '~> 1.3.9'
end

%w[5.2 6.0 6.1 7.0 7.1].each do |version|
%w[5.2 6.0 6.1 7.0 7.1 7.2].each do |version|
appraise "ar_#{version.gsub('.', '_')}" do
remove_gem 'appraisal'
gem 'activerecord', "~> #{version}.0"
Expand Down
10 changes: 10 additions & 0 deletions ar_7_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'activerecord', '~> 7.2.0'
gem 'mysql2', '~> 0.5'
gem 'pg', '>= 0.2'
gem 'sqlite3', '~> 1.3'

gemspec path: '../'
17 changes: 15 additions & 2 deletions lib/database_consistency/writers/autofix/helpers/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ module Autofix
module Helpers
module Migration # :nodoc:
def migration_path(name)
migration_context = ActiveRecord::Base.connection.migration_context

last = migration_context.migrations.last
version = ActiveRecord::Migration.next_migration_number(last&.version.to_i + 1)

Expand All @@ -24,6 +22,21 @@ def migration_configuration(name)
migration_version: ActiveRecord::Migration.current_version
}
end

def migration_context
if ActiveRecord::MigrationContext.instance_method(:initialize).arity == 1
return ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths)
end

if ActiveRecord::Base.connection.respond_to?(:schema_migration)
return ActiveRecord::MigrationContext.new(
ActiveRecord::Migrator.migrations_paths,
ActiveRecord::Base.connection.schema_migration
)
end

ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths)
end
end
end
end
Expand Down
Loading