mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Don't attempt to load the schema file in tests if none exists
This commit is contained in:
parent
4010a9ddc6
commit
45e8a4b6c9
2 changed files with 18 additions and 3 deletions
|
@ -395,7 +395,7 @@ module ActiveRecord
|
|||
|
||||
def load_schema_if_pending!
|
||||
if ActiveRecord::Migrator.needs_migration? || !ActiveRecord::Migrator.any_migrations?
|
||||
ActiveRecord::Tasks::DatabaseTasks.load_schema_current
|
||||
ActiveRecord::Tasks::DatabaseTasks.load_schema_current_if_exists
|
||||
check_pending!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -197,18 +197,27 @@ module ActiveRecord
|
|||
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:
|
||||
file ||= schema_file(format)
|
||||
|
||||
case format
|
||||
when :ruby
|
||||
file ||= File.join(db_dir, "schema.rb")
|
||||
check_schema_file(file)
|
||||
purge(configuration)
|
||||
ActiveRecord::Base.establish_connection(configuration)
|
||||
load(file)
|
||||
when :sql
|
||||
file ||= File.join(db_dir, "structure.sql")
|
||||
check_schema_file(file)
|
||||
purge(configuration)
|
||||
structure_load(configuration, file)
|
||||
|
@ -217,6 +226,12 @@ module ActiveRecord
|
|||
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)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue