aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-11-24 12:04:01 +0100
committerYves Senn <yves.senn@gmail.com>2014-11-25 18:17:01 +0100
commit5c4495538bb4e8808ce077f08ea6b809952daa44 (patch)
treeffbe61d499b774bc9c5cc939225a1f55564cdb99 /activerecord/lib/active_record/migration.rb
parent9e9793b440c044b765f2d1f702feeb92aef2b139 (diff)
downloadrails-5c4495538bb4e8808ce077f08ea6b809952daa44.tar.gz
rails-5c4495538bb4e8808ce077f08ea6b809952daa44.tar.bz2
rails-5c4495538bb4e8808ce077f08ea6b809952daa44.zip
bring back `db:test:prepare`.
This reverts deprecations added in #13528. The task is brought back for two reasons: 1. Give plugins a way to hook into the test database initialization process 2. Give the user a way to force a test database synchronization While `test:prepare` is still a dependency of every test task, `db:test:prepare` no longer hooks into it. This means that `test:prepare` runs before the schema is synchronized. Plugins, which insert data can now hook into `db:test:prepare`. The automatic schema maintenance can't detect when a migration is rolled-back, modified and reapplied. In this case the user has to fall back to `db:test:prepare` to force the synchronization to happen.
Diffstat (limited to 'activerecord/lib/active_record/migration.rb')
-rw-r--r--activerecord/lib/active_record/migration.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index 4e00eb3d99..92f2951f2d 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -395,7 +395,14 @@ module ActiveRecord
def load_schema_if_pending!
if ActiveRecord::Migrator.needs_migration? || !ActiveRecord::Migrator.any_migrations?
- ActiveRecord::Tasks::DatabaseTasks.load_schema_current_if_exists
+ # Roundrip to Rake to allow plugins to hook into database initialization.
+ FileUtils.cd Rails.root do
+ current_config = Base.connection_config
+ Base.clear_all_connections!
+ system("bin/rake db:test:prepare")
+ # Establish a new connection, the old database may be gone (db:test:prepare uses purge)
+ Base.establish_connection(current_config)
+ end
check_pending!
end
end