diff options
author | eileencodes <eileencodes@gmail.com> | 2019-05-30 08:25:05 -0400 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2019-06-14 11:15:08 -0400 |
commit | 7cc27d749c3563e6b278ad01d233cb92ea3b7935 (patch) | |
tree | 5975a2c14a3b0f9d2dfc234a2a5b27f3e50354e0 /activerecord/lib/active_record/tasks/database_tasks.rb | |
parent | c0af72bf86701e03ac97a50754beddf2b5d7943f (diff) | |
download | rails-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/lib/active_record/tasks/database_tasks.rb')
-rw-r--r-- | activerecord/lib/active_record/tasks/database_tasks.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index cf98a203bd..aecc9350e8 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -200,9 +200,10 @@ module ActiveRecord def truncate_tables(configuration) ActiveRecord::Base.connected_to(database: { truncation: configuration }) do - table_names = ActiveRecord::Base.connection.tables + conn = ActiveRecord::Base.connection + table_names = conn.tables table_names -= [ - SchemaMigration.table_name, + conn.schema_migration.table_name, InternalMetadata.table_name ] @@ -233,7 +234,7 @@ module ActiveRecord end def migrate_status - unless ActiveRecord::SchemaMigration.table_exists? + unless ActiveRecord::Base.connection.schema_migration.table_exists? Kernel.abort "Schema migrations table does not exist yet." end @@ -328,6 +329,7 @@ module ActiveRecord def dump_schema(configuration, format = ActiveRecord::Base.schema_format, spec_name = "primary") # :nodoc: require "active_record/schema_dumper" filename = dump_filename(spec_name, format) + connection = ActiveRecord::Base.connection case format when :ruby @@ -336,9 +338,9 @@ module ActiveRecord end when :sql structure_dump(configuration, filename) - if ActiveRecord::SchemaMigration.table_exists? + if connection.schema_migration.table_exists? File.open(filename, "a") do |f| - f.puts ActiveRecord::Base.connection.dump_schema_information + f.puts connection.dump_schema_information f.print "\n" end end |