diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-10-31 16:56:18 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-10-31 16:56:18 -0600 |
commit | 45e8a4b6c9b0294c2fd7af1d6ddbde9c728321a9 (patch) | |
tree | e84fc54ceea700a2b375ccf25dae11c248b3f3a6 /activerecord | |
parent | 4010a9ddc6d91c40cc87a30c03e8dfd9ae214dbb (diff) | |
download | rails-45e8a4b6c9b0294c2fd7af1d6ddbde9c728321a9.tar.gz rails-45e8a4b6c9b0294c2fd7af1d6ddbde9c728321a9.tar.bz2 rails-45e8a4b6c9b0294c2fd7af1d6ddbde9c728321a9.zip |
Don't attempt to load the schema file in tests if none exists
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/tasks/database_tasks.rb | 19 |
2 files changed, 18 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 230659b97c..2024b225e4 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -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 diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index 22a6f9af7e..1228de2bfd 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -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 |