1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Replace deprecated #load_schema with #load_schema_for.

This commit is contained in:
Yves Senn 2014-12-23 12:07:15 +01:00
parent 0587070391
commit ad783136d7
3 changed files with 26 additions and 24 deletions

View file

@ -1,3 +1,8 @@
* Replace deprecated `ActiveRecord::Tasks::DatabaseTasks#load_schema` with
`ActiveRecord::Tasks::DatabaseTasks#load_schema_for`.
*Yves Senn*
* Fixes bug with 'ActiveRecord::Type::Numeric' that causes negative values to
be marked as having changed when set to the same negative value.

View file

@ -319,7 +319,7 @@ db_namespace = namespace :db do
begin
should_reconnect = ActiveRecord::Base.connection_pool.active_connection?
ActiveRecord::Schema.verbose = false
ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :ruby, ENV['SCHEMA']
ActiveRecord::Tasks::DatabaseTasks.load_schema ActiveRecord::Base.configurations['test'], :ruby, ENV['SCHEMA']
ensure
if should_reconnect
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ActiveRecord::Tasks::DatabaseTasks.env])
@ -329,7 +329,7 @@ db_namespace = namespace :db do
# desc "Recreate the test database from an existent structure.sql file"
task :load_structure => %w(db:test:purge) do
ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
ActiveRecord::Tasks::DatabaseTasks.load_schema ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
end
# desc "Recreate the test database from a fresh schema"

View file

@ -188,27 +188,7 @@ module ActiveRecord
class_for_adapter(configuration['adapter']).new(*arguments).structure_load(filename)
end
def load_schema(format = ActiveRecord::Base.schema_format, file = nil)
ActiveSupport::Deprecation.warn(<<-MSG.squish)
This method will act on a specific connection in the future.
To act on the current connection, use `load_schema_current` instead.
MSG
load_schema_current(format, file)
end
def schema_file(format = ActiveSupport::Base.schema_format)
case format
when :ruby
File.join(db_dir, "schema.rb")
when :sql
File.join(db_dir, "structure.sql")
end
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:
def load_schema(configuration, format = ActiveRecord::Base.schema_format, file = nil) # :nodoc:
file ||= schema_file(format)
case format
@ -224,6 +204,23 @@ module ActiveRecord
end
end
def load_schema_for(*args)
ActiveSupport::Deprecation.warn(<<-MSG.squish)
This method was renamed to `#load_schema` and will be removed in the future.
Use `#load_schema` instead.
MSG
load_schema *args
end
def schema_file(format = ActiveSupport::Base.schema_format)
case format
when :ruby
File.join(db_dir, "schema.rb")
when :sql
File.join(db_dir, "structure.sql")
end
end
def load_schema_current_if_exists(format = ActiveRecord::Base.schema_format, file = nil, environment = env)
if File.exist?(file || schema_file(format))
load_schema_current(format, file, environment)
@ -232,7 +229,7 @@ module ActiveRecord
def load_schema_current(format = ActiveRecord::Base.schema_format, file = nil, environment = env)
each_current_configuration(environment) { |configuration|
load_schema_for configuration, format, file
load_schema configuration, format, file
}
ActiveRecord::Base.establish_connection(environment.to_sym)
end