diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7e1e5975..d247b7ec 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,6 +15,7 @@ jobs: - 5.2.0 - 6.0.0 - 6.1.0 + - 7.1.2 include: - ruby: 2.4 rails: 5.2.0 @@ -22,6 +23,13 @@ jobs: rails: 7.0.1 - ruby: 3.0 rails: 6.1.0 + - ruby: 3.0 + rails: 7.1.2 + exclude: + - ruby: 2.5 + rails: 7.1.2 + - ruby: 2.6 + rails: 7.1.2 env: PERCONA_DB_USER: root PERCONA_DB_PASSWORD: root diff --git a/.rubocop.yml b/.rubocop.yml index ba5f8e47..df8a0c9a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,7 @@ --- +AllCops: + TargetRubyVersion: 2.4 + Metrics/AbcSize: Enabled: false @@ -44,6 +47,9 @@ Style/CommandLiteral: Style/Documentation: Enabled: false +Style/FrozenStringLiteralComment: + Enabled: false # We never ended up being forced to do this for Ruby 3.x + Style/MultilineBlockChain: Exclude: - 'spec/integration_spec.rb' diff --git a/CHANGELOG.md b/CHANGELOG.md index 543d6111..93894107 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Please follow the format in [Keep a Changelog](http://keepachangelog.com/) ## [Unreleased] - Fix support for Rails 6.0 and ForAlter `remove_index` . +- Support Rails 7.1.2 ## [6.5.0] - 2023-01-24 diff --git a/Dockerfile b/Dockerfile index cf6096ec..2236e49d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:2.3.4 +FROM ruby:3.0 MAINTAINER muffinista@gmail.com # Install apt based dependencies required to run Rails as diff --git a/departure.gemspec b/departure.gemspec index 49ddeddb..46cbb1d5 100644 --- a/departure.gemspec +++ b/departure.gemspec @@ -7,7 +7,7 @@ require 'departure/version' # This environment variable is set on CI to facilitate testing with multiple # versions of Rails. -RAILS_DEPENDENCY_VERSION = ENV.fetch('RAILS_VERSION', ['>= 5.2.0', '!= 7.0.0', '< 7.1']) +RAILS_DEPENDENCY_VERSION = ENV.fetch('RAILS_VERSION', ['>= 5.2.0', '!= 7.0.0', '< 7.2.0']) Gem::Specification.new do |spec| spec.name = 'departure' diff --git a/lib/active_record/connection_adapters/percona_adapter.rb b/lib/active_record/connection_adapters/percona_adapter.rb index 07fd6ec3..f2076ea7 100644 --- a/lib/active_record/connection_adapters/percona_adapter.rb +++ b/lib/active_record/connection_adapters/percona_adapter.rb @@ -43,6 +43,8 @@ def percona_connection(config) module ConnectionAdapters class DepartureAdapter < AbstractMysqlAdapter + TYPE_MAP = Type::TypeMap.new.tap { |m| initialize_type_map(m) } if defined?(initialize_type_map) + class Column < ActiveRecord::ConnectionAdapters::MySQL::Column def adapter DepartureAdapter @@ -86,19 +88,20 @@ def write_query?(sql) # :nodoc: def exec_delete(sql, name, binds) execute(to_sql(sql, binds), name) - @connection.affected_rows + mysql_adapter.raw_connection.affected_rows end alias exec_update exec_delete - def exec_insert(sql, name, binds, pk = nil, sequence_name = nil) # rubocop:disable Lint/UnusedMethodArgument, Metrics/LineLength + def exec_insert(sql, name, binds, pk = nil, sequence_name = nil, returning: nil) # rubocop:disable Lint/UnusedMethodArgument, Metrics/LineLength, Metrics/ParameterLists execute(to_sql(sql, binds), name) end - def exec_query(sql, name = 'SQL', _binds = [], **_kwargs) + def internal_exec_query(sql, name = 'SQL', _binds = [], **_kwargs) # :nodoc: result = execute(sql, name) fields = result.fields if defined?(result.fields) ActiveRecord::Result.new(fields, result.to_a) end + alias exec_query internal_exec_query # Executes a SELECT query and returns an array of rows. Each row is an # array of field values. @@ -196,6 +199,22 @@ def last_inserted_id(result) private attr_reader :mysql_adapter + + if ActiveRecord.version >= Gem::Version.create('7.1.0') + def raw_execute(sql, name, async: false, allow_retry: false, materialize_transactions: true) + log(sql, name, async: async) do + with_raw_connection(allow_retry: allow_retry, materialize_transactions: materialize_transactions) do |conn| + sync_timezone_changes(conn) + result = conn.query(sql) + verified! + handle_warnings(sql) + result + end + end + end + end + + def reconnect; end end end end diff --git a/lib/lhm/column_with_sql.rb b/lib/lhm/column_with_sql.rb index 95b7c5f9..476015d0 100644 --- a/lib/lhm/column_with_sql.rb +++ b/lib/lhm/column_with_sql.rb @@ -72,7 +72,7 @@ def column # # @return [String, NilClass] def default_value - match = if definition =~ /timestamp|datetime/i + match = if definition.match?(/timestamp|datetime/i) /default '?(.+[^'])'?/i.match(definition) else /default '?(\w+)'?/i.match(definition) @@ -87,10 +87,10 @@ def default_value # # @return [Boolean] def null_value - match = /((\w*) NULL)/i.match(definition) + match = /((NOT)? NULL)/i.match(definition) return true unless match - match[2].downcase == 'not' ? false : true + match[2]&.downcase == 'not' ? false : true end end end diff --git a/spec/active_record/connection_adapters/percona_adapter_spec.rb b/spec/active_record/connection_adapters/percona_adapter_spec.rb index 14f9b4eb..c0ee6b8c 100644 --- a/spec/active_record/connection_adapters/percona_adapter_spec.rb +++ b/spec/active_record/connection_adapters/percona_adapter_spec.rb @@ -181,12 +181,13 @@ describe '#exec_delete' do let(:sql) { 'DELETE FROM comments WHERE id = 1' } + let(:affected_rows) { 1 } let(:name) { nil } let(:binds) { nil } before do - allow(runner).to receive(:query).with(sql) - allow(runner).to receive(:affected_rows).and_return(1) + allow(runner).to receive(:query).with(anything) + allow(mysql_client).to receive(:affected_rows).and_return(affected_rows) end it 'executes the sql' do @@ -195,7 +196,7 @@ end it 'returns the number of affected rows' do - expect(adapter.exec_delete(sql, name, binds)).to eq(1) + expect(adapter.exec_delete(sql, name, binds)).to eq(affected_rows) end end diff --git a/spec/integration/change_table_spec.rb b/spec/integration/change_table_spec.rb index 9752195a..d5645904 100644 --- a/spec/integration/change_table_spec.rb +++ b/spec/integration/change_table_spec.rb @@ -3,11 +3,10 @@ describe Departure, integration: true do class Comment < ActiveRecord::Base; end - let(:migration_fixtures) do - ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES], ActiveRecord::SchemaMigration).migrations.select do |m| - m.version == version - end + let(:migration_context) do + ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES], ActiveRecord::SchemaMigration) end + let(:direction) { :up } context 'change_table' do @@ -19,7 +18,7 @@ def column_metadata(table, name) context 'creating column' do before(:each) do - ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, version).migrate + migration_context.run(direction, version) end it 'adds the column in the DB table' do @@ -38,7 +37,7 @@ def column_metadata(table, name) end it 'marks the migration as up' do - expect(ActiveRecord::Migrator.current_version).to eq(version) + expect(migration_context.current_version).to eq(version) end it 'changes column' do diff --git a/spec/integration/columns_spec.rb b/spec/integration/columns_spec.rb index a86e0136..d0dc891d 100644 --- a/spec/integration/columns_spec.rb +++ b/spec/integration/columns_spec.rb @@ -3,10 +3,9 @@ describe Departure, integration: true do class Comment < ActiveRecord::Base; end - let(:migration_fixtures) do - ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES], ActiveRecord::SchemaMigration).migrations + let(:migration_context) do + ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES], ActiveRecord::SchemaMigration) end - let(:migration_paths) { [MIGRATION_FIXTURES] } let(:direction) { :up } @@ -17,25 +16,15 @@ class Comment < ActiveRecord::Base; end let(:direction) { :up } it 'adds the column in the DB table' do - ActiveRecord::Migrator.new( - direction, - migration_fixtures, - ActiveRecord::SchemaMigration, - version - ).migrate + migration_context.run(direction, version) expect(:comments).to have_column('some_id_field') end it 'marks the migration as up' do - ActiveRecord::Migrator.new( - direction, - migration_fixtures, - ActiveRecord::SchemaMigration, - version - ).migrate - - expect(ActiveRecord::Migrator.current_version).to eq(version) + migration_context.run(direction, version) + + expect(migration_context.current_version).to eq(version) end end @@ -43,29 +32,19 @@ class Comment < ActiveRecord::Base; end let(:direction) { :down } before do - ActiveRecord::Migrator.new(:up, migration_fixtures, ActiveRecord::SchemaMigration, version).migrate + migration_context.up(version) end it 'drops the column from the DB table' do - ActiveRecord::Migrator.new( - direction, - migration_fixtures, - ActiveRecord::SchemaMigration, - version - 1 - ).migrate + migration_context.run(direction, version) expect(:comments).not_to have_column('some_id_field') end it 'marks the migration as down' do - ActiveRecord::Migrator.new( - direction, - migration_fixtures, - ActiveRecord::SchemaMigration, - version - 1 - ).migrate - - expect(ActiveRecord::Migrator.current_version).to eq(version - 1) + migration_context.run(direction, version) + + expect(migration_context.current_version).to eq(version - 1) end end @@ -82,12 +61,12 @@ class Comment < ActiveRecord::Base; end end it 'changes the column name' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(:comments).to have_column('new_id_field') end it 'does not keep the old column' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(:comments).not_to have_column('some_id_field') end end @@ -100,20 +79,20 @@ class Comment < ActiveRecord::Base; end end before do - ActiveRecord::Migrator.new(:up, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate + migration_context.up(1) end context 'when null is true' do let(:version) { 14 } it 'sets the column to allow nulls' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(column.null).to be_truthy end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) - expect(ActiveRecord::Migrator.current_version).to eq(version) + migration_context.run(direction, version) + expect(migration_context.current_version).to eq(version) end end @@ -121,13 +100,13 @@ class Comment < ActiveRecord::Base; end let(:version) { 15 } it 'sets the column not to allow nulls' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(column.null).to be_falsey end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) - expect(ActiveRecord::Migrator.current_version).to eq(version) + migration_context.run(direction, version) + expect(migration_context.current_version).to eq(version) end end end @@ -136,12 +115,12 @@ class Comment < ActiveRecord::Base; end let(:version) { 22 } it 'adds a created_at column' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(:comments).to have_column('created_at') end it 'adds a updated_at column' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(:comments).to have_column('updated_at') end end @@ -158,12 +137,12 @@ class Comment < ActiveRecord::Base; end end it 'removes the created_at column' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(:comments).not_to have_column('created_at') end it 'removes the updated_at column' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(:comments).not_to have_column('updated_at') end end diff --git a/spec/integration/data_migrations_spec.rb b/spec/integration/data_migrations_spec.rb index 99d6dbda..9f99d7e0 100644 --- a/spec/integration/data_migrations_spec.rb +++ b/spec/integration/data_migrations_spec.rb @@ -3,7 +3,10 @@ describe Departure, integration: true do class Comment < ActiveRecord::Base; end - let(:migration_fixtures) { [MIGRATION_FIXTURES] } + let(:migration_context) do + ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES], ActiveRecord::SchemaMigration) + end + let(:direction) { :up } before do @@ -25,21 +28,15 @@ class Comment < ActiveRecord::Base; end let(:version) { 9 } it 'updates all the required data' do - ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( - direction, - version - ) + migration_context.run(direction, version) expect(Comment.pluck(:read)).to match_array([true, true]) end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( - direction, - version - ) + migration_context.run(direction, version) - expect(ActiveRecord::Migrator.current_version).to eq(version) + expect(migration_context.current_version).to eq(version) end end @@ -47,10 +44,7 @@ class Comment < ActiveRecord::Base; end let(:version) { 30 } it 'updates all the required data' do - ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( - direction, - version - ) + migration_context.run(direction, version) expect(Comment.pluck(:author, :read)).to match_array([ [nil, false], @@ -61,12 +55,9 @@ class Comment < ActiveRecord::Base; end end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( - direction, - version - ) + migration_context.run(direction, version) - expect(ActiveRecord::Migrator.current_version).to eq(version) + expect(migration_context.current_version).to eq(version) end end @@ -74,21 +65,15 @@ class Comment < ActiveRecord::Base; end let(:version) { 10 } it 'updates all the required data' do - ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( - direction, - version - ) + migration_context.run(direction, version) expect(Comment.pluck(:read)).to match_array([true, true]) end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( - direction, - version - ) + migration_context.run(direction, version) - expect(ActiveRecord::Migrator.current_version).to eq(version) + expect(migration_context.current_version).to eq(version) end end @@ -96,21 +81,15 @@ class Comment < ActiveRecord::Base; end let(:version) { 11 } it 'updates all the required data' do - ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( - direction, - version - ) + migration_context.run(direction, version) expect(Comment.pluck(:read)).to match_array([true, true]) end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( - direction, - version - ) + migration_context.run(direction, version) - expect(ActiveRecord::Migrator.current_version).to eq(version) + expect(migration_context.current_version).to eq(version) end end @@ -118,21 +97,15 @@ class Comment < ActiveRecord::Base; end let(:version) { 12 } it 'updates all the required data' do - ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( - direction, - version - ) + migration_context.run(direction, version) expect(Comment.pluck(:read)).to match_array([true, true]) end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( - direction, - version - ) + migration_context.run(direction, version) - expect(ActiveRecord::Migrator.current_version).to eq(version) + expect(migration_context.current_version).to eq(version) end end end diff --git a/spec/integration/indexes_spec.rb b/spec/integration/indexes_spec.rb index 785ac8be..3140b547 100644 --- a/spec/integration/indexes_spec.rb +++ b/spec/integration/indexes_spec.rb @@ -3,12 +3,10 @@ describe Departure, integration: true do class Comment < ActiveRecord::Base; end - let(:migration_fixtures) do - ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES], ActiveRecord::SchemaMigration).migrations + let(:migration_context) do + ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES], ActiveRecord::SchemaMigration) end - let(:migration_paths) { [MIGRATION_FIXTURES] } - let(:direction) { :up } context 'managing indexes' do @@ -17,38 +15,22 @@ class Comment < ActiveRecord::Base; end context 'adding indexes' do let(:direction) { :up } - # TODO: Create it directly like this? before do - ActiveRecord::Migrator.new( - direction, - migration_fixtures, - ActiveRecord::SchemaMigration, - 1 - ).migrate + migration_context.run(direction, 1) end it 'executes the percona command' do expect_percona_command('ADD INDEX `index_comments_on_some_id_field` (`some_id_field`)') - ActiveRecord::Migrator.new( - direction, - migration_fixtures, - ActiveRecord::SchemaMigration, - version - ).migrate + migration_context.run(direction, version) expect(:comments).to have_index('index_comments_on_some_id_field') end it 'marks the migration as up' do - ActiveRecord::Migrator.new( - direction, - migration_fixtures, - ActiveRecord::SchemaMigration, - version - ).migrate - - expect(ActiveRecord::Migrator.current_version).to eq(version) + migration_context.run(direction, version) + + expect(migration_context.current_version).to eq(version) end end @@ -56,43 +38,22 @@ class Comment < ActiveRecord::Base; end let(:direction) { :down } before do - ActiveRecord::Migrator.new( - :up, - migration_fixtures, - ActiveRecord::SchemaMigration, - 1 - ).migrate - - ActiveRecord::Migrator.new( - :up, - migration_fixtures, - ActiveRecord::SchemaMigration, - version - ).migrate + migration_context.up(1) + migration_context.up(version) end it 'executes the percona command' do expect_percona_command('DROP INDEX `index_comments_on_some_id_field`') - ActiveRecord::Migrator.new( - direction, - migration_fixtures, - ActiveRecord::SchemaMigration, - version - 1 - ).migrate + migration_context.run(direction, version) expect(:comments).not_to have_index('index_comments_on_some_id_field') end it 'marks the migration as down' do - ActiveRecord::Migrator.new( - direction, - migration_fixtures, - ActiveRecord::SchemaMigration, - version - 1 - ).migrate - - expect(ActiveRecord::Migrator.current_version).to eq(1) + migration_context.run(direction, version) + + expect(migration_context.current_version).to eq(1) end end @@ -101,7 +62,7 @@ class Comment < ActiveRecord::Base; end let(:version) { 13 } before do - ActiveRecord::Migrator.new(:up, migration_fixtures, ActiveRecord::SchemaMigration, 2).migrate + migration_context.up(2) end it 'executes the percona command' do @@ -112,13 +73,13 @@ class Comment < ActiveRecord::Base; end expect_percona_command('DROP INDEX `index_comments_on_some_id_field`') end - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(:comments).to have_index('new_index_comments_on_some_id_field') end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) - expect(ActiveRecord::Migrator.current_version).to eq(version) + migration_context.run(direction, version) + expect(migration_context.current_version).to eq(version) end end end @@ -130,21 +91,21 @@ class Comment < ActiveRecord::Base; end let(:direction) { :up } before do - ActiveRecord::Migrator.new(:up, migration_fixtures, ActiveRecord::SchemaMigration,1).migrate + migration_context.migrate(1) end it 'executes the percona command' do expect_percona_command('ADD UNIQUE INDEX `index_comments_on_some_id_field` (`some_id_field`)') - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(unique_indexes_from(:comments)) .to match_array(['index_comments_on_some_id_field']) end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) - expect(ActiveRecord::Migrator.current_version).to eq(version) + migration_context.run(direction, version) + expect(migration_context.current_version).to eq(version) end end @@ -152,22 +113,22 @@ class Comment < ActiveRecord::Base; end let(:direction) { :down } before do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(:up, 1) - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(:up, version) + migration_context.run(:up, 1) + migration_context.run(:up, version) end it 'executes the percona command' do expect_percona_command('DROP INDEX `index_comments_on_some_id_field`') - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(unique_indexes_from(:comments)) .not_to match_array(['index_comments_on_some_id_field']) end it 'marks the migration as down' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) - expect(ActiveRecord::Migrator.current_version).to eq(1) + migration_context.run(direction, version) + expect(migration_context.current_version).to eq(1) end end end diff --git a/spec/integration/tables_spec.rb b/spec/integration/tables_spec.rb index 52ea2643..841a50aa 100644 --- a/spec/integration/tables_spec.rb +++ b/spec/integration/tables_spec.rb @@ -3,6 +3,10 @@ describe Departure, integration: true do class Comment < ActiveRecord::Base; end + let(:migration_context) do + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration) + end + let(:migration_paths) { [MIGRATION_FIXTURES] } let(:direction) { :up } @@ -10,13 +14,13 @@ class Comment < ActiveRecord::Base; end let(:version) { 8 } it 'creates the table' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(tables).to include('things') end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) - expect(ActiveRecord::Migrator.current_version).to eq(version) + migration_context.run(direction, version) + expect(migration_context.current_version).to eq(version) end end @@ -25,13 +29,13 @@ class Comment < ActiveRecord::Base; end let(:direction) { :down } it 'drops the table' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(tables).not_to include('things') end it 'updates the schema_migrations' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) - expect(ActiveRecord::Migrator.current_version).to eq(0) + migration_context.run(direction, version) + expect(migration_context.current_version).to eq(0) end end @@ -39,22 +43,22 @@ class Comment < ActiveRecord::Base; end let(:version) { 24 } before do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, 1) - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, 2) + migration_context.run(direction, 1) + migration_context.run(direction, 2) end it 'changes the table name' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(tables).to include('new_comments') end it 'does not keep the old name' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(tables).not_to include('comments') end it 'changes the index names in the new table' do - ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) + migration_context.run(direction, version) expect(:new_comments).to have_index('index_new_comments_on_some_id_field') end end diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 655201c4..c7792986 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -34,7 +34,7 @@ class Comment < ActiveRecord::Base; end it "doesn't send the output to stdout" do expect do - ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate + migration_context.run(direction, 1) end.to_not output.to_stdout end end @@ -49,7 +49,7 @@ class Comment < ActiveRecord::Base; end it 'sends the output to stdout' do expect do - ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate + migration_context.run(direction, 1) end.to output.to_stdout end end @@ -59,7 +59,7 @@ class Comment < ActiveRecord::Base; end let(:db_config) { Configuration.new } it 'reconnects to the database using PerconaAdapter' do - ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate + migration_context.run(direction, 1) expect(spec_config[:adapter]).to eq('percona') end @@ -75,7 +75,7 @@ class Comment < ActiveRecord::Base; end end it 'uses the provided username' do - ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate + migration_context.run(direction, 1) expect(spec_config[:username]).to eq('root') end end @@ -91,7 +91,7 @@ class Comment < ActiveRecord::Base; end end it 'uses root' do - ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate + migration_context.run(direction, 1) expect(spec_config[:username]).to eq('root') end end @@ -101,14 +101,14 @@ class Comment < ActiveRecord::Base; end xit 'patches it to use regular Rails migration methods' do expect(Departure::Lhm::Fake::Adapter) .to receive(:new).and_return(true) - ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate + migration_context.run(direction, 1) end end context 'when there is no LHM' do xit 'does not patch it' do expect(Departure::Lhm::Fake).not_to receive(:patching_lhm) - ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate + migration_context.run(direction, 1) end end end @@ -174,7 +174,7 @@ class Comment < ActiveRecord::Base; end .and_return(command) ClimateControl.modify PERCONA_ARGS: '--chunk-time=1' do - ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate + migration_context.run(direction, 1) end end end @@ -187,7 +187,7 @@ class Comment < ActiveRecord::Base; end .and_return(command) ClimateControl.modify PERCONA_ARGS: '--chunk-time=1 --max-lag=2' do - ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate + migration_context.run(direction, 1) end end end @@ -200,7 +200,7 @@ class Comment < ActiveRecord::Base; end .and_return(command) ClimateControl.modify PERCONA_ARGS: '--alter-foreign-keys-method=drop_swap' do - ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate + migration_context.run(direction, 1) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 984c8206..ac4250e4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -79,3 +79,7 @@ def initialize(migrations_paths, schema_migration = nil) ActiveRecord::Migrator.send :prepend, Rails5Compatibility::Migrator ActiveRecord::MigrationContext.send :prepend, Rails5Compatibility::MigrationContext end + +if ActiveRecord::VERSION::STRING >= '7.1' + ActiveRecord::MigrationContext.send :prepend, Rails5Compatibility::MigrationContext +end