aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authoryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-10-02 15:46:30 +0900
committeryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-10-02 15:50:58 +0900
commit87598c8c80f4cbeef114267d75c46f1c87ca057a (patch)
tree72b6bc36d9fece2a72b2d28ed4bab26820480dbf /activerecord/lib/active_record
parent1a2a63f1e07253a2e07c09b82cddd00f661523b2 (diff)
downloadrails-87598c8c80f4cbeef114267d75c46f1c87ca057a.tar.gz
rails-87598c8c80f4cbeef114267d75c46f1c87ca057a.tar.bz2
rails-87598c8c80f4cbeef114267d75c46f1c87ca057a.zip
Make automatically synchronize test schema work inside engine
In Rails engine, migration files are in under `db/migrate` of engine. Therefore, when rake task is executed in engine, `db/migrate` is automatically added to `DatabaseTasks.migrations_paths`. https://github.com/rails/rails/blob/a18cf23a9cbcbeed61e8049442640c7153e0a8fb/activerecord/lib/active_record/railtie.rb#L39..L43 However, if execute the rake task under dummy app, migration files will not be loaded because engine's migration path setting process is not called. Therefore, in order to load migration files correctly, it is necessary to execute rake task under engine. Fixes #30765
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/migration.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index 8845e26ab7..ec8119e5da 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -581,7 +581,8 @@ module ActiveRecord
def load_schema_if_pending!
if ActiveRecord::Migrator.needs_migration? || !ActiveRecord::Migrator.any_migrations?
# Roundtrip to Rake to allow plugins to hook into database initialization.
- FileUtils.cd Rails.root do
+ root = defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
+ FileUtils.cd(root) do
current_config = Base.connection_config
Base.clear_all_connections!
system("bin/rails db:test:prepare")