Skip to content

Commit

Permalink
The use_schema_cache_dump configuration moved to ActiveRecord.
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyj committed Aug 1, 2012
1 parent 083ddec commit e35c67a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
36 changes: 21 additions & 15 deletions activerecord/lib/active_record/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Railtie < Rails::Railtie
'ActiveRecord::RecordNotSaved' => :unprocessable_entity
)

config.active_record.use_schema_cache_dump = true

rake_tasks do
require "active_record/base"
load "active_record/railties/databases.rake"
Expand Down Expand Up @@ -66,6 +68,25 @@ class Railtie < Rails::Railtie
end
end

initializer "active_record.check_schema_cache_dump" do |app|
if config.active_record.delete(:use_schema_cache_dump)
config.after_initialize do |app|
ActiveSupport.on_load(:active_record) do
filename = File.join(app.config.paths["db"].first, "schema_cache.dump")

if File.file?(filename)
cache = Marshal.load File.binread filename
if cache.version == ActiveRecord::Migrator.current_version
ActiveRecord::Model.connection.schema_cache = cache
else
warn "schema_cache.dump is expired. Current version is #{ActiveRecord::Migrator.current_version}, but cache version is #{cache.version}."
end
end
end
end
end
end

initializer "active_record.set_configs" do |app|
ActiveSupport.on_load(:active_record) do
app.config.active_record.each do |k,v|
Expand Down Expand Up @@ -117,21 +138,6 @@ class Railtie < Rails::Railtie
end
end

ActiveSupport.on_load(:active_record) do
if app.config.use_schema_cache_dump
filename = File.join(app.config.paths["db"].first, "schema_cache.dump")

if File.file?(filename)
cache = Marshal.load File.binread filename
if cache.version == ActiveRecord::Migrator.current_version
ActiveRecord::Model.connection.schema_cache = cache
else
warn "schema_cache.dump is expired. Current version is #{ActiveRecord::Migrator.current_version}, but cache version is #{cache.version}."
end
end
end
end

end
end
end
3 changes: 1 addition & 2 deletions railties/lib/rails/application/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Configuration < ::Rails::Engine::Configuration
:force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags,
:preload_frameworks, :railties_order, :relative_url_root, :secret_token,
:serve_static_assets, :ssl_options, :static_cache_control, :session_options,
:time_zone, :reload_classes_only_on_change, :use_schema_cache_dump,
:time_zone, :reload_classes_only_on_change,
:queue, :queue_consumer

attr_writer :log_level
Expand Down Expand Up @@ -43,7 +43,6 @@ def initialize(*)
@exceptions_app = nil
@autoflush_log = true
@log_formatter = ActiveSupport::Logger::SimpleFormatter.new
@use_schema_cache_dump = true
@queue = Rails::Queueing::Queue
@queue_consumer = Rails::Queueing::ThreadedConsumer

Expand Down

0 comments on commit e35c67a

Please sign in to comment.