Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling disabled schema dumping for test environment #44285

Merged
merged 1 commit into from Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions activerecord/lib/active_record/tasks/database_tasks.rb
Expand Up @@ -365,6 +365,7 @@ def structure_load(configuration, *arguments)

def load_schema(db_config, format = ActiveRecord.schema_format, file = nil) # :nodoc:
file ||= schema_dump_path(db_config, format)
return unless file

verbose_was, Migration.verbose = Migration.verbose, verbose? && ENV["VERBOSE"]
check_schema_file(file)
Expand All @@ -390,7 +391,7 @@ def schema_up_to_date?(configuration, format = ActiveRecord.schema_format, file

file ||= schema_dump_path(db_config)

return true unless File.exist?(file)
return true unless file && File.exist?(file)

ActiveRecord::Base.establish_connection(db_config)

Expand All @@ -403,7 +404,7 @@ def schema_up_to_date?(configuration, format = ActiveRecord.schema_format, file
def reconstruct_from_schema(db_config, format = ActiveRecord.schema_format, file = nil) # :nodoc:
file ||= schema_dump_path(db_config, format)

check_schema_file(file)
check_schema_file(file) if file

ActiveRecord::Base.establish_connection(db_config)

Expand All @@ -421,6 +422,8 @@ def reconstruct_from_schema(db_config, format = ActiveRecord.schema_format, file
def dump_schema(db_config, format = ActiveRecord.schema_format) # :nodoc:
require "active_record/schema_dumper"
filename = schema_dump_path(db_config, format)
return unless filename

connection = ActiveRecord::Base.connection

FileUtils.mkdir_p(db_dir)
Expand Down
21 changes: 21 additions & 0 deletions railties/test/application/rake/multi_dbs_test.rb
Expand Up @@ -1024,6 +1024,27 @@ class TwoMigration < ActiveRecord::Migration::Current
end
end

test "db:test:prepare don't raise errors when schema_dump is false" do
app_file "config/database.yml", <<~EOS
development: &development
primary:
adapter: sqlite3
database: dev_db
schema_dump: false
secondary:
adapter: sqlite3
database: secondary_dev_db
schema_dump: false
test:
<<: *development
EOS

Dir.chdir(app_path) do
output = rails("db:test:prepare", "--trace")
assert_match(/Execute db:test:prepare/, output)
end
end

test "db:create and db:drop don't raise errors when loading YAML containing multiple ERB statements on the same line" do
app_file "config/database.yml", <<-YAML
development:
Expand Down