aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2017-12-03 18:12:40 +0100
committerGitHub <noreply@github.com>2017-12-03 18:12:40 +0100
commitdde620ac6e959c32a6dc8e59911e8f6ffa088321 (patch)
tree9b8c3a18d74a32290f45e2d68d8b657a0313f951 /activerecord
parent7609ca08ce5000689838eeb04ed37084bf364f78 (diff)
parentdbee80bca0ef504120219e6c7686437456511060 (diff)
downloadrails-dde620ac6e959c32a6dc8e59911e8f6ffa088321.tar.gz
rails-dde620ac6e959c32a6dc8e59911e8f6ffa088321.tar.bz2
rails-dde620ac6e959c32a6dc8e59911e8f6ffa088321.zip
Merge pull request #31311 from y-yagi/ignore_no_database_error_when_loading_schema_cache
Ignore `NoDatabaseError` when loading schema cache
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/migration.rb10
-rw-r--r--activerecord/lib/active_record/railtie.rb7
2 files changed, 14 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index 15e9c09ffb..4d4b0dc67a 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -1053,7 +1053,15 @@ module ActiveRecord
end
end
- def current_version(connection = Base.connection)
+ def current_version(connection = nil)
+ if connection.nil?
+ begin
+ connection = Base.connection
+ rescue ActiveRecord::NoDatabaseError
+ return nil
+ end
+ end
+
get_all_versions(connection).max || 0
end
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb
index 9ee8425e1b..4538ed6a5f 100644
--- a/activerecord/lib/active_record/railtie.rb
+++ b/activerecord/lib/active_record/railtie.rb
@@ -90,12 +90,15 @@ module ActiveRecord
filename = File.join(app.config.paths["db"].first, "schema_cache.yml")
if File.file?(filename)
+ current_version = ActiveRecord::Migrator.current_version
+ next if current_version.nil?
+
cache = YAML.load(File.read(filename))
- if cache.version == ActiveRecord::Migrator.current_version
+ if cache.version == current_version
connection.schema_cache = cache
connection_pool.schema_cache = cache.dup
else
- warn "Ignoring db/schema_cache.yml because it has expired. The current schema version is #{ActiveRecord::Migrator.current_version}, but the one in the cache is #{cache.version}."
+ warn "Ignoring db/schema_cache.yml because it has expired. The current schema version is #{current_version}, but the one in the cache is #{cache.version}."
end
end
end