Skip to content

Commit

Permalink
Support latest edge rails (#59)
Browse files Browse the repository at this point in the history
* Support latest edge rails

* fixup! Support latest edge rails

* Support latest beta version rails

* fixup! Support latest beta version rails
  • Loading branch information
VladislavSokov authored Jun 6, 2024
1 parent 99ec568 commit 7f29003
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- { ruby: '3.1', rails: '7.0' }
- { ruby: '3.2', rails: '7.1' }
- { ruby: '3.3', rails: '7.1' }
- { ruby: '3.3', rails: 'edge' }
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails.${{ matrix.rails }}.gemfile
steps:
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
/spec/reports/
/tmp/
/test/dummy_app/tmp/
/test/dummy_app/db/migrate/*.rb
/test/dummy_app/db/schema.rb
/test/dummy_app/db/*/*.rb
/test/dummy_app/db/*.rb
.ruby-version
.ruby-gemset
/gemfiles/*.gemfile.lock
6 changes: 6 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@
gem "activesupport", "~> #{version}.0"
end
end

appraise "rails.edge" do
gem "rails", ">= 7.2.0.beta"
gem "activerecord", ">= 7.2.0.beta"
gem "activesupport", ">= 7.2.0.beta"
end
15 changes: 15 additions & 0 deletions gemfiles/rails.edge.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", ">= 7.2.0.beta"
gem "activesupport", ">= 7.2.0.beta"
gem "minitest", "~> 5.0"
gem "rake"
gem "rubocop", "~> 1.21"
gem "rails", ">= 7.2.0.beta"
gem "sqlite3"

gemspec path: "../"
17 changes: 13 additions & 4 deletions lib/actual_db_schema/commands/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@ def call_impl
end

def context
@context ||=
ActiveRecord::Base.connection.migration_context.tap do |c|
c.extend(ActualDbSchema::Patches::MigrationContext)
end
@context ||= fetch_migration_context.tap do |c|
c.extend(ActualDbSchema::Patches::MigrationContext)
end
end

def fetch_migration_context
ar_version = Gem::Version.new(ActiveRecord::VERSION::STRING)
if ar_version >= Gem::Version.new("7.2.0") ||
(ar_version >= Gem::Version.new("7.1.0") && ar_version.prerelease?)
ActiveRecord::Base.connection_pool.migration_context
else
ActiveRecord::Base.connection.migration_context
end
end
end
end
Expand Down
19 changes: 14 additions & 5 deletions test/support/test_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,26 @@ def migrated_files(db_config = nil)

def cleanup_call(prefix_name = nil)
delete_migrations_files(prefix_name)
if ActiveRecord::SchemaMigration.respond_to?(:create_table)
ActiveRecord::SchemaMigration.create_table
else
ActiveRecord::SchemaMigration.new(ActiveRecord::Base.connection).create_table
end
create_schema_migration_table
run_sql("delete from schema_migrations")
remove_app_dir(MIGRATED_PATHS.fetch(prefix_name&.to_sym, migrated_paths.first))
define_migrations(prefix_name)
Rails.application.load_tasks
end

def create_schema_migration_table
if ActiveRecord::SchemaMigration.respond_to?(:create_table)
ActiveRecord::SchemaMigration.create_table
else
ar_version = Gem::Version.new(ActiveRecord::VERSION::STRING)
if ar_version >= Gem::Version.new("7.2.0") || (ar_version >= Gem::Version.new("7.1.0") && ar_version.prerelease?)
ActiveRecord::SchemaMigration.new(ActiveRecord::Base.connection_pool).create_table
else
ActiveRecord::SchemaMigration.new(ActiveRecord::Base.connection).create_table
end
end
end

def delete_migrations_files_for(path)
Dir.glob(app_file("#{path}/**/*.rb")).each do |file|
remove_app_dir(file)
Expand Down

0 comments on commit 7f29003

Please sign in to comment.