aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2019-05-30 08:25:05 -0400
committereileencodes <eileencodes@gmail.com>2019-06-14 11:15:08 -0400
commit7cc27d749c3563e6b278ad01d233cb92ea3b7935 (patch)
tree5975a2c14a3b0f9d2dfc234a2a5b27f3e50354e0 /activerecord/test/cases/migration
parentc0af72bf86701e03ac97a50754beddf2b5d7943f (diff)
downloadrails-7cc27d749c3563e6b278ad01d233cb92ea3b7935.tar.gz
rails-7cc27d749c3563e6b278ad01d233cb92ea3b7935.tar.bz2
rails-7cc27d749c3563e6b278ad01d233cb92ea3b7935.zip
Move SchemaMigration to migration_context
This PR moves the `schema_migration` to `migration_context` so that we can access the `schema_migration` per connection. This does not change behavior of the SchemaMigration if you are using one database. This also does not change behavior of any public APIs. `Migrator` is private as is `MigrationContext` so we can change these as needed. We now need to pass a `schema_migration` to `Migrator` so that we can run migrations on the right connection outside the context of a rake task. The bugs this fixes were discovered while debugging the issues around the SchemaCache on initialization with multiple database. It was clear that `get_all_versions` wouldn't work without these changes outside the context of a rake task (because in the rake task we establish a connection and change AR::Base.connection to the db we're running on). Because the `SchemaCache` relies on the `SchemaMigration` information we need to make sure we store it per-connection rather than on ActiveRecord::Base. [Eileen M. Uchitelle & Aaron Patterson]
Diffstat (limited to 'activerecord/test/cases/migration')
-rw-r--r--activerecord/test/cases/migration/compatibility_test.rb29
-rw-r--r--activerecord/test/cases/migration/logger_test.rb9
2 files changed, 20 insertions, 18 deletions
diff --git a/activerecord/test/cases/migration/compatibility_test.rb b/activerecord/test/cases/migration/compatibility_test.rb
index 726ccf925e..ff2a694e66 100644
--- a/activerecord/test/cases/migration/compatibility_test.rb
+++ b/activerecord/test/cases/migration/compatibility_test.rb
@@ -12,6 +12,7 @@ module ActiveRecord
def setup
super
@connection = ActiveRecord::Base.connection
+ @schema_migration = @connection.schema_migration
@verbose_was = ActiveRecord::Migration.verbose
ActiveRecord::Migration.verbose = false
@@ -38,7 +39,7 @@ module ActiveRecord
}.new
assert connection.index_exists?(:testings, :foo, name: "custom_index_name")
- assert_raise(StandardError) { ActiveRecord::Migrator.new(:up, [migration]).migrate }
+ assert_raise(StandardError) { ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate }
assert connection.index_exists?(:testings, :foo, name: "custom_index_name")
end
@@ -53,7 +54,7 @@ module ActiveRecord
}.new
assert connection.index_exists?(:testings, :bar)
- ActiveRecord::Migrator.new(:up, [migration]).migrate
+ ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate
assert_not connection.index_exists?(:testings, :bar)
end
@@ -67,7 +68,7 @@ module ActiveRecord
end
}.new
- ActiveRecord::Migrator.new(:up, [migration]).migrate
+ ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate
assert_not connection.index_exists?(:more_testings, :foo_id)
assert_not connection.index_exists?(:more_testings, :bar_id)
@@ -84,7 +85,7 @@ module ActiveRecord
end
}.new
- ActiveRecord::Migrator.new(:up, [migration]).migrate
+ ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate
assert connection.column_exists?(:more_testings, :created_at, null: true)
assert connection.column_exists?(:more_testings, :updated_at, null: true)
@@ -101,7 +102,7 @@ module ActiveRecord
end
}.new
- ActiveRecord::Migrator.new(:up, [migration]).migrate
+ ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate
assert connection.column_exists?(:testings, :created_at, null: true)
assert connection.column_exists?(:testings, :updated_at, null: true)
@@ -117,7 +118,7 @@ module ActiveRecord
end
}.new
- ActiveRecord::Migrator.new(:up, [migration]).migrate
+ ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate
assert connection.column_exists?(:testings, :created_at, null: true)
assert connection.column_exists?(:testings, :updated_at, null: true)
@@ -131,7 +132,7 @@ module ActiveRecord
end
}.new
- ActiveRecord::Migrator.new(:up, [migration]).migrate
+ ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate
assert connection.column_exists?(:testings, :created_at, null: true)
assert connection.column_exists?(:testings, :updated_at, null: true)
@@ -146,7 +147,7 @@ module ActiveRecord
end
}.new
- ActiveRecord::Migrator.new(:up, [migration]).migrate
+ ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate
assert connection.column_exists?(:more_testings, :created_at, null: false, **precision_implicit_default)
assert connection.column_exists?(:more_testings, :updated_at, null: false, **precision_implicit_default)
@@ -163,7 +164,7 @@ module ActiveRecord
end
}.new
- ActiveRecord::Migrator.new(:up, [migration]).migrate
+ ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate
assert connection.column_exists?(:testings, :created_at, null: false, **precision_implicit_default)
assert connection.column_exists?(:testings, :updated_at, null: false, **precision_implicit_default)
@@ -179,7 +180,7 @@ module ActiveRecord
end
}.new
- ActiveRecord::Migrator.new(:up, [migration]).migrate
+ ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate
assert connection.column_exists?(:testings, :created_at, null: false, **precision_implicit_default)
assert connection.column_exists?(:testings, :updated_at, null: false, **precision_implicit_default)
@@ -193,7 +194,7 @@ module ActiveRecord
end
}.new
- ActiveRecord::Migrator.new(:up, [migration]).migrate
+ ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate
assert connection.column_exists?(:testings, :created_at, null: false, **precision_implicit_default)
assert connection.column_exists?(:testings, :updated_at, null: false, **precision_implicit_default)
@@ -230,7 +231,7 @@ module ActiveRecord
end
}.new
- ActiveRecord::Migrator.new(:up, [migration]).migrate
+ ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate
assert connection.column_exists?(:testings, :foo, comment: "comment")
end
@@ -243,7 +244,7 @@ module ActiveRecord
end
}.new
- ActiveRecord::Migrator.new(:up, [migration]).migrate
+ ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate
assert_equal "comment", connection.table_comment("testings")
end
@@ -261,7 +262,7 @@ module ActiveRecord
}.new
Testing.create!
- ActiveRecord::Migrator.new(:up, [migration]).migrate
+ ActiveRecord::Migrator.new(:up, [migration], @schema_migration).migrate
assert_equal ["foobar"], Testing.all.map(&:foo)
ensure
ActiveRecord::Base.clear_cache!
diff --git a/activerecord/test/cases/migration/logger_test.rb b/activerecord/test/cases/migration/logger_test.rb
index 28f4cc124b..431047f957 100644
--- a/activerecord/test/cases/migration/logger_test.rb
+++ b/activerecord/test/cases/migration/logger_test.rb
@@ -17,19 +17,20 @@ module ActiveRecord
def setup
super
- ActiveRecord::SchemaMigration.create_table
- ActiveRecord::SchemaMigration.delete_all
+ @schema_migration = ActiveRecord::Base.connection.schema_migration
+ @schema_migration.create_table
+ @schema_migration.delete_all
end
teardown do
- ActiveRecord::SchemaMigration.drop_table
+ @schema_migration.drop_table
end
def test_migration_should_be_run_without_logger
previous_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil
migrations = [Migration.new("a", 1), Migration.new("b", 2), Migration.new("c", 3)]
- ActiveRecord::Migrator.new(:up, migrations).migrate
+ ActiveRecord::Migrator.new(:up, migrations, @schema_migration).migrate
ensure
ActiveRecord::Base.logger = previous_logger
end