mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add config.active_record.check_schema_cache_dump_version to disable schema dump version check
This commit is contained in:
parent
3ddf6b66bc
commit
6d9d26af89
2 changed files with 25 additions and 5 deletions
|
@ -27,6 +27,7 @@ module ActiveRecord
|
||||||
)
|
)
|
||||||
|
|
||||||
config.active_record.use_schema_cache_dump = true
|
config.active_record.use_schema_cache_dump = true
|
||||||
|
config.active_record.check_schema_cache_dump_version = true
|
||||||
config.active_record.maintain_test_schema = true
|
config.active_record.maintain_test_schema = true
|
||||||
config.active_record.has_many_inversing = false
|
config.active_record.has_many_inversing = false
|
||||||
|
|
||||||
|
@ -126,6 +127,8 @@ To keep using the current cache store, you can turn off cache versioning entirel
|
||||||
end
|
end
|
||||||
|
|
||||||
initializer "active_record.check_schema_cache_dump" do
|
initializer "active_record.check_schema_cache_dump" do
|
||||||
|
check_schema_cache_dump_version = config.active_record.delete(:check_schema_cache_dump_version)
|
||||||
|
|
||||||
if config.active_record.delete(:use_schema_cache_dump)
|
if config.active_record.delete(:use_schema_cache_dump)
|
||||||
config.after_initialize do |app|
|
config.after_initialize do |app|
|
||||||
ActiveSupport.on_load(:active_record) do
|
ActiveSupport.on_load(:active_record) do
|
||||||
|
@ -139,12 +142,19 @@ To keep using the current cache store, you can turn off cache versioning entirel
|
||||||
cache = ActiveRecord::ConnectionAdapters::SchemaCache.load_from(filename)
|
cache = ActiveRecord::ConnectionAdapters::SchemaCache.load_from(filename)
|
||||||
next if cache.nil?
|
next if cache.nil?
|
||||||
|
|
||||||
current_version = ActiveRecord::Migrator.current_version
|
if check_schema_cache_dump_version
|
||||||
next if current_version.nil?
|
current_version = begin
|
||||||
|
ActiveRecord::Migrator.current_version
|
||||||
|
rescue ActiveRecordError => error
|
||||||
|
warn "Failed to load the schema cache because of #{error.class}: #{error.message}"
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
next if current_version.nil?
|
||||||
|
|
||||||
if cache.version != current_version
|
if cache.version != current_version
|
||||||
warn "Ignoring #{filename} because it has expired. The current schema version is #{current_version}, but the one in the cache is #{cache.version}."
|
warn "Ignoring #{filename} because it has expired. The current schema version is #{current_version}, but the one in the cache is #{cache.version}."
|
||||||
next
|
next
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
connection_pool.set_schema_cache(cache.dup)
|
connection_pool.set_schema_cache(cache.dup)
|
||||||
|
|
|
@ -230,6 +230,16 @@ module ApplicationTests
|
||||||
assert_not ActiveRecord::Base.connection.schema_cache.data_sources("posts")
|
assert_not ActiveRecord::Base.connection.schema_cache.data_sources("posts")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "does not expire schema cache dump if check_schema_cache_dump_version is false" do
|
||||||
|
add_to_config <<-RUBY
|
||||||
|
config.active_record.check_schema_cache_dump_version = false
|
||||||
|
RUBY
|
||||||
|
rails %w(generate model post title:string)
|
||||||
|
rails %w(db:migrate db:schema:cache:dump db:rollback)
|
||||||
|
require "#{app_path}/config/environment"
|
||||||
|
assert ActiveRecord::Base.connection_pool.schema_cache.data_sources("posts")
|
||||||
|
end
|
||||||
|
|
||||||
test "active record establish_connection uses Rails.env if DATABASE_URL is not set" do
|
test "active record establish_connection uses Rails.env if DATABASE_URL is not set" do
|
||||||
require "#{app_path}/config/environment"
|
require "#{app_path}/config/environment"
|
||||||
orig_database_url = ENV.delete("DATABASE_URL")
|
orig_database_url = ENV.delete("DATABASE_URL")
|
||||||
|
|
Loading…
Reference in a new issue