1
0
Fork 0
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:
Sean Griffin 2014-10-31 16:56:18 -06:00
parent 4010a9ddc6
commit 45e8a4b6c9
2 changed files with 18 additions and 3 deletions

View file

@ -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

View file

@ -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