aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/ar_schema_test.rb
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2018-01-10 10:25:13 -0500
committereileencodes <eileencodes@gmail.com>2018-01-18 08:55:03 -0500
commita2827ec9811b5012e8e366011fd44c8eb53fc714 (patch)
treece158384df40f9cfe128bb659b0372a6e7bb8f07 /activerecord/test/cases/ar_schema_test.rb
parent198e3e3cb784dae54d8d4346667d3fb08c889335 (diff)
downloadrails-a2827ec9811b5012e8e366011fd44c8eb53fc714.tar.gz
rails-a2827ec9811b5012e8e366011fd44c8eb53fc714.tar.bz2
rails-a2827ec9811b5012e8e366011fd44c8eb53fc714.zip
Refactor migration to move migrations paths to connection
Rails has some support for multiple databases but it can be hard to handle migrations with those. The easiest way to implement multiple databases is to contain migrations into their own folder ("db/migrate" for the primary db and "db/seconddb_migrate" for the second db). Without this you would need to write code that allowed you to switch connections in migrations. I can tell you from experience that is not a fun way to implement multiple databases. This refactoring is a pre-requisite for implementing other features related to parallel testing and improved handling for multiple databases. The refactoring here moves the class methods from the `Migrator` class into it's own new class `MigrationContext`. The goal was to move the `migrations_paths` method off of the `Migrator` class and onto the connection. This allows users to do the following in their `database.yml`: ``` development: adapter: mysql2 username: root password: development_seconddb: adapter: mysql2 username: root password: migrations_paths: "db/second_db_migrate" ``` Migrations for the `seconddb` can now be store in the `db/second_db_migrate` directory. Migrations for the primary database are stored in `db/migrate`". The refactoring here drastically reduces the internal API for migrations since we don't need to pass `migrations_paths` around to every single method. Additionally this change does not require any Rails applications to make changes unless they want to use the new public API. All of the class methods from the `Migrator` class were `nodoc`'d except for the `migrations_paths` and `migrations_path` getter/setters respectively.
Diffstat (limited to 'activerecord/test/cases/ar_schema_test.rb')
-rw-r--r--activerecord/test/cases/ar_schema_test.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb
index 83974f327e..140d7cbcae 100644
--- a/activerecord/test/cases/ar_schema_test.rb
+++ b/activerecord/test/cases/ar_schema_test.rb
@@ -48,7 +48,7 @@ class ActiveRecordSchemaTest < ActiveRecord::TestCase
assert_nothing_raised { @connection.select_all "SELECT * FROM fruits" }
assert_nothing_raised { @connection.select_all "SELECT * FROM schema_migrations" }
- assert_equal 7, ActiveRecord::Migrator::current_version
+ assert_equal 7, @connection.migration_context.current_version
end
def test_schema_define_w_table_name_prefix
@@ -64,7 +64,7 @@ class ActiveRecordSchemaTest < ActiveRecord::TestCase
t.column :flavor, :string
end
end
- assert_equal 7, ActiveRecord::Migrator::current_version
+ assert_equal 7, @connection.migration_context.current_version
ensure
ActiveRecord::Base.table_name_prefix = old_table_name_prefix
ActiveRecord::SchemaMigration.table_name = table_name