From 252dd3248ab844133e2030b1e81235162c6cef4b Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Wed, 15 Jan 2020 20:47:49 +0900 Subject: [PATCH 1/4] Update build matrix * Drop 2.2.8 * Add 2.4.6, 2.5.5, 2.6.3, 2.7.0 --- .travis.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 028315bb..9b5a8927 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,15 @@ language: ruby rvm: - - 2.2.8 - + - 2.4.6 + - 2.5.5 + - 2.6.3 + - 2.7.0 + services: - mysql - + before_install: - - sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 8507EFA5 + - travis_retry sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 8507EFA5 - echo "deb http://repo.percona.com/apt `lsb_release -cs` main" | sudo tee -a /etc/apt/sources.list - sudo apt-get update -qq - sudo apt-get install percona-toolkit From 3c2a99b4278e2c47089afdb0617b9c66dae0e00b Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Thu, 16 Jan 2020 15:04:25 +0900 Subject: [PATCH 2/4] Testing against Rails 5.2 and Rails 6.0 --- .travis.yml | 11 ++++++++++- departure.gemspec | 8 ++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9b5a8927..e2f3b24f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,19 @@ language: ruby + rvm: - - 2.4.6 - 2.5.5 - 2.6.3 - 2.7.0 +env: + - RAILS_VERSION="~> 6.0.0" + - RAILS_VERSION="~> 5.2.0" + +jobs: + include: + - rvm: 2.4.6 + env: RAILS_VERSION="~> 5.2.0" + services: - mysql diff --git a/departure.gemspec b/departure.gemspec index f584bb7a..1dea0f6e 100644 --- a/departure.gemspec +++ b/departure.gemspec @@ -5,6 +5,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 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', '< 6.1']) + Gem::Specification.new do |spec| spec.name = 'departure' spec.version = Departure::VERSION @@ -19,8 +23,8 @@ Gem::Specification.new do |spec| spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.require_paths = ['lib'] - spec.add_runtime_dependency 'railties', '~> 5.2.0' - spec.add_runtime_dependency 'activerecord', '~> 5.2.0' + spec.add_runtime_dependency 'railties', *Array(RAILS_DEPENDENCY_VERSION) + spec.add_runtime_dependency 'activerecord', *Array(RAILS_DEPENDENCY_VERSION) spec.add_runtime_dependency 'mysql2', '>= 0.4.0', '<= 0.5.3' spec.add_development_dependency 'rake', '~> 10.0' From f077624d98f231314f7b44a67eaf1535a619c17f Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Tue, 14 Jan 2020 17:15:52 +0900 Subject: [PATCH 3/4] Implement #get_full_version for Rails 6 support It seems like Active Record >= 6.0 now requires this method to present, and `full_version` now return version that is cached in the schema dumper. https://github.com/rails/rails/commit/6584fb3939dd3892834ed93fa791064d5299cda2#diff-e7dead35794529e0cc5d0b2d788f8235R132 --- .../connection_adapters/percona_adapter.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/active_record/connection_adapters/percona_adapter.rb b/lib/active_record/connection_adapters/percona_adapter.rb index 9cd75868..7d396a02 100644 --- a/lib/active_record/connection_adapters/percona_adapter.rb +++ b/lib/active_record/connection_adapters/percona_adapter.rb @@ -147,6 +147,16 @@ def change_table(table_name, _options = {}) def error_number(_exception); end def full_version + if ActiveRecord::VERSION::MAJOR < 6 + get_full_version + else + schema_cache.database_version.full_version_string + end + end + + # This is a method defined in Rails 6.0, and we have no control over the + # naming of this method. + def get_full_version # rubocop:disable Naming/AccessorMethodName mysql_adapter.raw_connection.server_info[:version] end From 62153a776d3156cf43b61d1153baab449a40c2ee Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Thu, 16 Jan 2020 18:52:58 +0900 Subject: [PATCH 4/4] Add shim for Rails 5.2/6 in spec --- .../percona_adapter_spec.rb | 6 +++- spec/integration/change_table_spec.rb | 4 +-- spec/integration/columns_spec.rb | 30 +++++++++++-------- spec/integration/data_migrations_spec.rb | 16 +++++----- spec/integration/foreign_keys_spec.rb | 12 ++++---- spec/integration/indexes_spec.rb | 29 +++++++++++------- spec/integration/references_spec.rb | 18 +++++------ spec/integration/tables_spec.rb | 18 +++++------ spec/integration_spec.rb | 28 ++++++++--------- spec/lhm_integration_spec.rb | 1 + spec/spec_helper.rb | 24 +++++++++++++++ 11 files changed, 113 insertions(+), 73 deletions(-) diff --git a/spec/active_record/connection_adapters/percona_adapter_spec.rb b/spec/active_record/connection_adapters/percona_adapter_spec.rb index 047644a9..b412a870 100644 --- a/spec/active_record/connection_adapters/percona_adapter_spec.rb +++ b/spec/active_record/connection_adapters/percona_adapter_spec.rb @@ -20,7 +20,11 @@ let(:collation) { double(:collation) } let(:column) do - described_class.new(field, default, mysql_metadata, type, null, collation) + if ActiveRecord::VERSION::MAJOR < 6 + described_class.new(field, default, mysql_metadata, type, null, collation) + else + described_class.new(field, default, mysql_metadata, null, collation: collation) + end end describe '#adapter' do diff --git a/spec/integration/change_table_spec.rb b/spec/integration/change_table_spec.rb index 7a1ade2c..9752195a 100644 --- a/spec/integration/change_table_spec.rb +++ b/spec/integration/change_table_spec.rb @@ -4,7 +4,7 @@ class Comment < ActiveRecord::Base; end let(:migration_fixtures) do - ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES]).migrations.select do |m| + ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES], ActiveRecord::SchemaMigration).migrations.select do |m| m.version == version end end @@ -19,7 +19,7 @@ def column_metadata(table, name) context 'creating column' do before(:each) do - ActiveRecord::Migrator.new(direction, migration_fixtures, version).migrate + ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, version).migrate end it 'adds the column in the DB table' do diff --git a/spec/integration/columns_spec.rb b/spec/integration/columns_spec.rb index e0202bd7..7f976761 100644 --- a/spec/integration/columns_spec.rb +++ b/spec/integration/columns_spec.rb @@ -4,7 +4,7 @@ class Comment < ActiveRecord::Base; end let(:migration_fixtures) do - ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES]).migrations + ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES], ActiveRecord::SchemaMigration).migrations end let(:migration_paths) { [MIGRATION_FIXTURES] } @@ -20,6 +20,7 @@ class Comment < ActiveRecord::Base; end ActiveRecord::Migrator.new( direction, migration_fixtures, + ActiveRecord::SchemaMigration, version ).migrate @@ -30,6 +31,7 @@ class Comment < ActiveRecord::Base; end ActiveRecord::Migrator.new( direction, migration_fixtures, + ActiveRecord::SchemaMigration, version ).migrate @@ -41,13 +43,14 @@ class Comment < ActiveRecord::Base; end let(:direction) { :down } before do - ActiveRecord::Migrator.new(:up, migration_fixtures, version).migrate + ActiveRecord::Migrator.new(:up, migration_fixtures, ActiveRecord::SchemaMigration, version).migrate end it 'drops the column from the DB table' do ActiveRecord::Migrator.new( direction, migration_fixtures, + ActiveRecord::SchemaMigration, version - 1 ).migrate @@ -58,6 +61,7 @@ class Comment < ActiveRecord::Base; end ActiveRecord::Migrator.new( direction, migration_fixtures, + ActiveRecord::SchemaMigration, version - 1 ).migrate @@ -78,12 +82,12 @@ class Comment < ActiveRecord::Base; end end it 'changes the column name' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).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).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).not_to have_column('some_id_field') end end @@ -96,19 +100,19 @@ class Comment < ActiveRecord::Base; end end before do - ActiveRecord::Migrator.new(:up, migration_fixtures, 1).migrate + ActiveRecord::Migrator.new(:up, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate end context 'when null is true' do let(:version) { 14 } it 'sets the column to allow nulls' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(column.null).to be_truthy end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(ActiveRecord::Migrator.current_version).to eq(version) end end @@ -117,12 +121,12 @@ class Comment < ActiveRecord::Base; end let(:version) { 15 } it 'sets the column not to allow nulls' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(column.null).to be_falsey end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(ActiveRecord::Migrator.current_version).to eq(version) end end @@ -132,12 +136,12 @@ class Comment < ActiveRecord::Base; end let(:version) { 22 } it 'adds a created_at column' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).to have_column('created_at') end it 'adds a updated_at column' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).to have_column('updated_at') end end @@ -154,12 +158,12 @@ class Comment < ActiveRecord::Base; end end it 'removes the created_at column' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).not_to have_column('created_at') end it 'removes the updated_at column' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).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 1a5adab0..b603b3e4 100644 --- a/spec/integration/data_migrations_spec.rb +++ b/spec/integration/data_migrations_spec.rb @@ -25,7 +25,7 @@ class Comment < ActiveRecord::Base; end let(:version) { 9 } it 'updates all the required data' do - ActiveRecord::MigrationContext.new(migration_fixtures).run( + ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( direction, version ) @@ -34,7 +34,7 @@ class Comment < ActiveRecord::Base; end end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_fixtures).run( + ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( direction, version ) @@ -47,7 +47,7 @@ class Comment < ActiveRecord::Base; end let(:version) { 10 } it 'updates all the required data' do - ActiveRecord::MigrationContext.new(migration_fixtures).run( + ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( direction, version ) @@ -56,7 +56,7 @@ class Comment < ActiveRecord::Base; end end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_fixtures).run( + ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( direction, version ) @@ -69,7 +69,7 @@ class Comment < ActiveRecord::Base; end let(:version) { 11 } it 'updates all the required data' do - ActiveRecord::MigrationContext.new(migration_fixtures).run( + ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( direction, version ) @@ -78,7 +78,7 @@ class Comment < ActiveRecord::Base; end end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_fixtures).run( + ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( direction, version ) @@ -91,7 +91,7 @@ class Comment < ActiveRecord::Base; end let(:version) { 12 } it 'updates all the required data' do - ActiveRecord::MigrationContext.new(migration_fixtures).run( + ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( direction, version ) @@ -100,7 +100,7 @@ class Comment < ActiveRecord::Base; end end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_fixtures).run( + ActiveRecord::MigrationContext.new(migration_fixtures, ActiveRecord::SchemaMigration).run( direction, version ) diff --git a/spec/integration/foreign_keys_spec.rb b/spec/integration/foreign_keys_spec.rb index 9bb1be04..6b69f912 100644 --- a/spec/integration/foreign_keys_spec.rb +++ b/spec/integration/foreign_keys_spec.rb @@ -4,7 +4,7 @@ class Comment < ActiveRecord::Base; end let(:migration_fixtures) do - ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES]).migrations + ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES], ActiveRecord::SchemaMigration).migrations end let(:migration_paths) { [MIGRATION_FIXTURES] } @@ -24,7 +24,7 @@ class Comment < ActiveRecord::Base; end end it 'adds a foreign key' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).to have_foreign_key_on('product_id') end end @@ -45,28 +45,28 @@ class Comment < ActiveRecord::Base; end it 'when foreign key has default name' do ActiveRecord::Base.connection.add_foreign_key(:comments, :products) - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).not_to have_foreign_key_on('product_id') end it 'when foreign key has a custom name' do ActiveRecord::Base.connection.add_foreign_key(:comments, :products, name: "fk_123456") - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).not_to have_foreign_key_on('product_id') end it 'when foreign key has a custom name prefixed with _' do ActiveRecord::Base.connection.add_foreign_key(:comments, :products, name: "_fk_123456") - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).not_to have_foreign_key_on('product_id') end it 'when foreign key has a custom name prefixed with __ (double _)' do ActiveRecord::Base.connection.add_foreign_key(:comments, :products, name: "__fk_123456") - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).not_to have_foreign_key_on('product_id') end end diff --git a/spec/integration/indexes_spec.rb b/spec/integration/indexes_spec.rb index bd93d4f0..9e7b86fe 100644 --- a/spec/integration/indexes_spec.rb +++ b/spec/integration/indexes_spec.rb @@ -4,7 +4,7 @@ class Comment < ActiveRecord::Base; end let(:migration_fixtures) do - ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES]).migrations + ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES], ActiveRecord::SchemaMigration).migrations end let(:migration_paths) { [MIGRATION_FIXTURES] } @@ -22,6 +22,7 @@ class Comment < ActiveRecord::Base; end ActiveRecord::Migrator.new( direction, migration_fixtures, + ActiveRecord::SchemaMigration, 1 ).migrate end @@ -30,6 +31,7 @@ class Comment < ActiveRecord::Base; end ActiveRecord::Migrator.new( direction, migration_fixtures, + ActiveRecord::SchemaMigration, version ).migrate @@ -40,6 +42,7 @@ class Comment < ActiveRecord::Base; end ActiveRecord::Migrator.new( direction, migration_fixtures, + ActiveRecord::SchemaMigration, version ).migrate @@ -54,12 +57,14 @@ class Comment < ActiveRecord::Base; end ActiveRecord::Migrator.new( :up, migration_fixtures, + ActiveRecord::SchemaMigration, 1 ).migrate ActiveRecord::Migrator.new( :up, migration_fixtures, + ActiveRecord::SchemaMigration, version ).migrate end @@ -68,6 +73,7 @@ class Comment < ActiveRecord::Base; end ActiveRecord::Migrator.new( direction, migration_fixtures, + ActiveRecord::SchemaMigration, version - 1 ).migrate @@ -78,6 +84,7 @@ class Comment < ActiveRecord::Base; end ActiveRecord::Migrator.new( direction, migration_fixtures, + ActiveRecord::SchemaMigration, version - 1 ).migrate @@ -90,16 +97,16 @@ class Comment < ActiveRecord::Base; end let(:version) { 13 } before do - ActiveRecord::Migrator.new(:up, migration_fixtures, 2).migrate + ActiveRecord::Migrator.new(:up, migration_fixtures, ActiveRecord::SchemaMigration, 2).migrate end it 'executes the percona command' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).to have_index('new_index_comments_on_some_id_field') end it 'marks the migration as down' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(ActiveRecord::Migrator.current_version).to eq(version) end end @@ -112,18 +119,18 @@ class Comment < ActiveRecord::Base; end let(:direction) { :up } before do - ActiveRecord::Migrator.new(:up, migration_fixtures, 1).migrate + ActiveRecord::Migrator.new(:up, migration_fixtures, ActiveRecord::SchemaMigration,1).migrate end it 'executes the percona command' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).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).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(ActiveRecord::Migrator.current_version).to eq(version) end end @@ -132,19 +139,19 @@ class Comment < ActiveRecord::Base; end let(:direction) { :down } before do - ActiveRecord::MigrationContext.new(migration_paths).run(:up, 1) - ActiveRecord::MigrationContext.new(migration_paths).run(:up, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(:up, 1) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(:up, version) end it 'executes the percona command' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).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).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(ActiveRecord::Migrator.current_version).to eq(1) end end diff --git a/spec/integration/references_spec.rb b/spec/integration/references_spec.rb index 91038b18..026585f3 100644 --- a/spec/integration/references_spec.rb +++ b/spec/integration/references_spec.rb @@ -11,7 +11,7 @@ class Comment < ActiveRecord::Base; end let(:version) { 16 } it 'adds a reference column' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).to have_column('user_id') end end @@ -20,12 +20,12 @@ class Comment < ActiveRecord::Base; end let(:version) { 17 } it 'adds a column for the id' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).to have_column('user_id') end it 'adds a column for the type' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).to have_column('user_type') end @@ -33,7 +33,7 @@ class Comment < ActiveRecord::Base; end let(:version) { 19 } it 'adds a compound index for both the id and type columns' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments) .to have_index('index_comments_on_user_type_and_user_id') end @@ -44,7 +44,7 @@ class Comment < ActiveRecord::Base; end let(:version) { 18 } it 'adds an index for the reference column' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).to have_index('index_comments_on_user_id') end @@ -54,23 +54,23 @@ class Comment < ActiveRecord::Base; end context 'removing references' do let(:version) { 20 } - before { ActiveRecord::MigrationContext.new(migration_paths).run(direction, 16) } + before { ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, 16) } context 'when no option is set' do it 'removes the reference column' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).not_to have_column('user_id') end end context 'when polymorphic is set to true' do it 'removes the reference id column' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).not_to have_column('user_id') end it 'removes the reference type column' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(:comments).not_to have_column('user_type') end end diff --git a/spec/integration/tables_spec.rb b/spec/integration/tables_spec.rb index a99414ff..52ea2643 100644 --- a/spec/integration/tables_spec.rb +++ b/spec/integration/tables_spec.rb @@ -10,12 +10,12 @@ class Comment < ActiveRecord::Base; end let(:version) { 8 } it 'creates the table' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(tables).to include('things') end it 'marks the migration as up' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(ActiveRecord::Migrator.current_version).to eq(version) end end @@ -25,12 +25,12 @@ class Comment < ActiveRecord::Base; end let(:direction) { :down } it 'drops the table' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(tables).not_to include('things') end it 'updates the schema_migrations' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(ActiveRecord::Migrator.current_version).to eq(0) end end @@ -39,22 +39,22 @@ class Comment < ActiveRecord::Base; end let(:version) { 24 } before do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, 1) - ActiveRecord::MigrationContext.new(migration_paths).run(direction, 2) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, 1) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, 2) end it 'changes the table name' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).run(direction, version) expect(tables).to include('new_comments') end it 'does not keep the old name' do - ActiveRecord::MigrationContext.new(migration_paths).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).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).run(direction, version) + ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::SchemaMigration).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 e44b5372..be072b60 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -5,7 +5,7 @@ class Comment < ActiveRecord::Base; end let(:migration_fixtures) do - ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES]).migrations + ActiveRecord::MigrationContext.new([MIGRATION_FIXTURES], ActiveRecord::SchemaMigration).migrations end let(:direction) { :up } @@ -25,7 +25,7 @@ class Comment < ActiveRecord::Base; end it "doesn't send the output to stdout" do expect do - ActiveRecord::Migrator.new(direction, migration_fixtures, 1).migrate + ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate end.to_not output.to_stdout end end @@ -40,7 +40,7 @@ class Comment < ActiveRecord::Base; end it 'sends the output to stdout' do expect do - ActiveRecord::Migrator.new(direction, migration_fixtures, 1).migrate + ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate end.to output.to_stdout end end @@ -50,7 +50,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, 1).migrate + ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate expect(ActiveRecord::Base.connection_pool.spec.config[:adapter]) .to eq('percona') end @@ -67,7 +67,7 @@ class Comment < ActiveRecord::Base; end end it 'uses the provided username' do - ActiveRecord::Migrator.new(direction, migration_fixtures, 1).migrate + ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate expect(ActiveRecord::Base.connection_pool.spec.config[:username]) .to eq('root') end @@ -84,7 +84,7 @@ class Comment < ActiveRecord::Base; end end it 'uses root' do - ActiveRecord::Migrator.new(direction, migration_fixtures, 1).migrate + ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate expect(ActiveRecord::Base.connection_pool.spec.config[:username]) .to eq('root') end @@ -95,14 +95,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, 1).migrate + ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate 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, 1).migrate + ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate end end end @@ -115,7 +115,7 @@ class Comment < ActiveRecord::Base; end it 'raises and halts the execution' do expect do - ActiveRecord::Migrator.run(direction, migration_fixtures, version) + ActiveRecord::Migrator.run(direction, migration_fixtures, ActiveRecord::SchemaMigration, version) end.to raise_error do |exception| exception.cause == ActiveRecord::StatementInvalid end @@ -132,7 +132,7 @@ class Comment < ActiveRecord::Base; end it 'raises and halts the execution' do expect do - ActiveRecord::Migrator.run(direction, migration_fixtures, version) + ActiveRecord::Migrator.run(direction, migration_fixtures, ActiveRecord::SchemaMigration, version) end.to raise_error do |exception| exception.cause == Departure::SignalError end @@ -146,7 +146,7 @@ class Comment < ActiveRecord::Base; end it 'raises and halts the execution' do expect do ClimateControl.modify PATH: '' do - ActiveRecord::Migrator.run(direction, migration_fixtures, version) + ActiveRecord::Migrator.run(direction, migration_fixtures, ActiveRecord::SchemaMigration, version) end end.to raise_error do |exception| exception.cause == Departure::CommandNotFoundError @@ -168,7 +168,7 @@ class Comment < ActiveRecord::Base; end .and_return(command) ClimateControl.modify PERCONA_ARGS: '--chunk-time=1' do - ActiveRecord::Migrator.new(direction, migration_fixtures, 1).migrate + ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate end end end @@ -181,7 +181,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, 1).migrate + ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate end end end @@ -194,7 +194,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, 1).migrate + ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate end end end diff --git a/spec/lhm_integration_spec.rb b/spec/lhm_integration_spec.rb index d6bad7f7..d1076b18 100644 --- a/spec/lhm_integration_spec.rb +++ b/spec/lhm_integration_spec.rb @@ -18,6 +18,7 @@ class Comment < ActiveRecord::Base; end ActiveRecord::Migrator.new( direction, [migration_fixtures], + ActiveRecord::SchemaMigration, version ).migrate diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 622cf235..6ce55d69 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -54,3 +54,27 @@ Kernel.srand config.seed end + +# This shim is for Rails 5.2 compatibility in the test +module Rails5Compatibility + module Migrator + def initialize(direction, migrations, schema_migration_or_target_version = nil, target_version = nil) + if schema_migration_or_target_version == ActiveRecord::SchemaMigration + super(direction, migrations, target_version) + else + super(direction, migrations, schema_migration_or_target_version) + end + end + end + + module MigrationContext + def initialize(migrations_paths, schema_migration = nil) + super(migrations_paths) + end + end +end + +if ActiveRecord::VERSION::MAJOR < 6 + ActiveRecord::Migrator.send :prepend, Rails5Compatibility::Migrator + ActiveRecord::MigrationContext.send :prepend, Rails5Compatibility::MigrationContext +end