aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/tasks/database_tasks.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-07-25 17:49:27 +0200
committerYves Senn <yves.senn@gmail.com>2014-08-06 08:25:18 +0200
commitf15cef67f75e4b52fd45655d7c6ab6b35623c608 (patch)
tree2b0209c0f77167b887ef231c9b258c966b0cdfcc /activerecord/lib/active_record/tasks/database_tasks.rb
parent53dba73dc17502b3d3f71d4672e86a14b995a732 (diff)
downloadrails-f15cef67f75e4b52fd45655d7c6ab6b35623c608.tar.gz
rails-f15cef67f75e4b52fd45655d7c6ab6b35623c608.tar.bz2
rails-f15cef67f75e4b52fd45655d7c6ab6b35623c608.zip
schema rake tasks are specific about the configuration to act on.
The rake tasks and the `DatabaseTakss` adapter classes used to assume a configuration at some places. This forced the rake tasks to establish a specific connection before calling into `load_schema`. After #15394 this started to cause issues because it could `purge` the wrong database before loading the schema.
Diffstat (limited to 'activerecord/lib/active_record/tasks/database_tasks.rb')
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb23
1 files changed, 20 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb
index 659110c066..892c78e479 100644
--- a/activerecord/lib/active_record/tasks/database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/database_tasks.rb
@@ -184,22 +184,39 @@ module ActiveRecord
end
def load_schema(format = ActiveRecord::Base.schema_format, file = nil)
+ ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
+ This method will act on a specific connection in the future.
+ To act on the current connection, use `load_schema_current` instead.
+ MESSAGE
+ load_schema_current(format, file)
+ end
+
+ # This method is the successor of +load_schema+. We should rename it
+ # after +load_schema+ went through a deprecation cycle. (Rails > 4.2)
+ def load_schema_for(configuration, format = ActiveRecord::Base.schema_format, file = nil) # :nodoc:
case format
when :ruby
file ||= File.join(db_dir, "schema.rb")
check_schema_file(file)
- purge(current_config)
+ purge(configuration)
+ ActiveRecord::Base.establish_connection(configuration)
load(file)
when :sql
file ||= File.join(db_dir, "structure.sql")
check_schema_file(file)
- purge(current_config)
- structure_load(current_config, file)
+ purge(configuration)
+ structure_load(configuration, file)
else
raise ArgumentError, "unknown format #{format.inspect}"
end
end
+ def load_schema_current(format = ActiveRecord::Base.schema_format, file = nil, environment = env)
+ each_current_configuration(environment) { |configuration|
+ load_schema_for configuration, format, file
+ }
+ end
+
def check_schema_file(filename)
unless File.exist?(filename)
message = %{#{filename} doesn't exist yet. Run `rake db:migrate` to create it, then try again.}