mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
ActiveRecord::Tasks::DatabaseTasks.load_schema
has always to establish database connection
When load schema from `structure.sql`, database connection isn't established. `ActiveRecord::Tasks::DatabaseTasks.load_schema` has to establish database connection since it executes ``` ActiveRecord::InternalMetadata.create_table ActiveRecord::InternalMetadata[:environment] = environment ```
This commit is contained in:
parent
99b2bf8db3
commit
678e563da3
2 changed files with 11 additions and 3 deletions
|
@ -228,13 +228,13 @@ module ActiveRecord
|
|||
def load_schema(configuration, format = ActiveRecord::Base.schema_format, file = nil, environment = env) # :nodoc:
|
||||
file ||= schema_file(format)
|
||||
|
||||
check_schema_file(file)
|
||||
ActiveRecord::Base.establish_connection(configuration)
|
||||
|
||||
case format
|
||||
when :ruby
|
||||
check_schema_file(file)
|
||||
ActiveRecord::Base.establish_connection(configuration)
|
||||
load(file)
|
||||
when :sql
|
||||
check_schema_file(file)
|
||||
structure_load(configuration, file)
|
||||
else
|
||||
raise ArgumentError, "unknown format #{format.inspect}"
|
||||
|
|
|
@ -189,6 +189,14 @@ module ApplicationTests
|
|||
db_structure_dump_and_load database_url_db_name
|
||||
end
|
||||
|
||||
test "db:structure:dump and db:structure:load set ar_internal_metadata" do
|
||||
require "#{app_path}/config/environment"
|
||||
db_structure_dump_and_load ActiveRecord::Base.configurations[Rails.env]["database"]
|
||||
|
||||
assert_equal "test", rails("runner", "-e", "test", "puts ActiveRecord::InternalMetadata[:environment]").strip
|
||||
assert_equal "development", rails("runner", "puts ActiveRecord::InternalMetadata[:environment]").strip
|
||||
end
|
||||
|
||||
test "db:structure:dump does not dump schema information when no migrations are used" do
|
||||
# create table without migrations
|
||||
rails "runner", "ActiveRecord::Base.connection.create_table(:posts) {|t| t.string :title }"
|
||||
|
|
Loading…
Reference in a new issue