Skip to content

Commit ad78313

Browse files
committed
Replace deprecated #load_schema with #load_schema_for.
1 parent 0587070 commit ad78313

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

Diff for: activerecord/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* Replace deprecated `ActiveRecord::Tasks::DatabaseTasks#load_schema` with
2+
`ActiveRecord::Tasks::DatabaseTasks#load_schema_for`.
3+
4+
*Yves Senn*
5+
16
* Fixes bug with 'ActiveRecord::Type::Numeric' that causes negative values to
27
be marked as having changed when set to the same negative value.
38

Diff for: activerecord/lib/active_record/railties/databases.rake

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ db_namespace = namespace :db do
319319
begin
320320
should_reconnect = ActiveRecord::Base.connection_pool.active_connection?
321321
ActiveRecord::Schema.verbose = false
322-
ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :ruby, ENV['SCHEMA']
322+
ActiveRecord::Tasks::DatabaseTasks.load_schema ActiveRecord::Base.configurations['test'], :ruby, ENV['SCHEMA']
323323
ensure
324324
if should_reconnect
325325
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ActiveRecord::Tasks::DatabaseTasks.env])
@@ -329,7 +329,7 @@ db_namespace = namespace :db do
329329

330330
# desc "Recreate the test database from an existent structure.sql file"
331331
task :load_structure => %w(db:test:purge) do
332-
ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
332+
ActiveRecord::Tasks::DatabaseTasks.load_schema ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
333333
end
334334

335335
# desc "Recreate the test database from a fresh schema"

Diff for: activerecord/lib/active_record/tasks/database_tasks.rb

+19-22
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,7 @@ def structure_load(*arguments)
188188
class_for_adapter(configuration['adapter']).new(*arguments).structure_load(filename)
189189
end
190190

191-
def load_schema(format = ActiveRecord::Base.schema_format, file = nil)
192-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
193-
This method will act on a specific connection in the future.
194-
To act on the current connection, use `load_schema_current` instead.
195-
MSG
196-
197-
load_schema_current(format, file)
198-
end
199-
200-
def schema_file(format = ActiveSupport::Base.schema_format)
201-
case format
202-
when :ruby
203-
File.join(db_dir, "schema.rb")
204-
when :sql
205-
File.join(db_dir, "structure.sql")
206-
end
207-
end
208-
209-
# This method is the successor of +load_schema+. We should rename it
210-
# after +load_schema+ went through a deprecation cycle. (Rails > 4.2)
211-
def load_schema_for(configuration, format = ActiveRecord::Base.schema_format, file = nil) # :nodoc:
191+
def load_schema(configuration, format = ActiveRecord::Base.schema_format, file = nil) # :nodoc:
212192
file ||= schema_file(format)
213193

214194
case format
@@ -224,6 +204,23 @@ def load_schema_for(configuration, format = ActiveRecord::Base.schema_format, fi
224204
end
225205
end
226206

207+
def load_schema_for(*args)
208+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
209+
This method was renamed to `#load_schema` and will be removed in the future.
210+
Use `#load_schema` instead.
211+
MSG
212+
load_schema *args
213+
end
214+
215+
def schema_file(format = ActiveSupport::Base.schema_format)
216+
case format
217+
when :ruby
218+
File.join(db_dir, "schema.rb")
219+
when :sql
220+
File.join(db_dir, "structure.sql")
221+
end
222+
end
223+
227224
def load_schema_current_if_exists(format = ActiveRecord::Base.schema_format, file = nil, environment = env)
228225
if File.exist?(file || schema_file(format))
229226
load_schema_current(format, file, environment)
@@ -232,7 +229,7 @@ def load_schema_current_if_exists(format = ActiveRecord::Base.schema_format, fil
232229

233230
def load_schema_current(format = ActiveRecord::Base.schema_format, file = nil, environment = env)
234231
each_current_configuration(environment) { |configuration|
235-
load_schema_for configuration, format, file
232+
load_schema configuration, format, file
236233
}
237234
ActiveRecord::Base.establish_connection(environment.to_sym)
238235
end

0 commit comments

Comments
 (0)