Repository navigation
db:prepare no longer loads seed when non-primary db is created - #53379
rafaelfranca merged 1 commit into
Conversation
5b9e742 to
8f08520
Compare
|
I think this is also related to #53059. |
|
Ahh yeah, thanks for double checking 🙇 |
|
I would suggest the following for def prepare_all
seed_blocked = false
seed_needed = false
dump_db_configs = []
each_current_configuration(env) do |db_config|
database_initialized = initialize_database(db_config)
if db_config.seeds?
if database_initialized
seed_needed = true
else
seed_blocked = true
end
end
end
each_current_environment(env) do |environment|
db_configs_with_versions(environment).sort.each do |version, db_configs|
dump_db_configs |= db_configs
db_configs.each do |db_config|
with_temporary_pool(db_config) do
migrate(version)
end
end
end
end
# Dump schema for databases that were migrated.
if ActiveRecord.dump_schema_after_migration
dump_db_configs.each do |db_config|
with_temporary_pool(db_config) do
dump_schema(db_config)
end
end
end
load_seed if seed_needed && !seed_blocked
endI think this PR as a whole is an important change to have for rails 8.0 to avoid this problem happening to anyone adding a Solid* gem. |
8f08520 to
d6451ef
Compare
|
Rebased. |
Since that was only 17 minutes after my suggestion, I understood that as meaning that you added my suggestion to the PR, but I don't see it. I'm just mentioning in case that is a mistake. |
|
@MaxLap I'm not sure I agree that the scenario you're describing above is common enough to warrant the additional complexity. Maybe something that, for posterity, is better brought up in the original issue? I invite you to please create a new PR if you have strong opinions, I'm not competitive about this and showing working code and tests can drive the overall conversation very well. For now I'm waiting for feedback from core before editing this further. |
Introduces a new database config property `seeds` to control whether seeds are loaded during `db:prepare` which defaults to `true` for primary database configs and `false otherwise. Previously, the `db:prepare` task would load seeds whenever a new database is created, leading to potential loss of data if a database is added to an existing environment. Also, update the Active Record Migrations guide to more accurately describe what the `db:prepare` task does, correcting some misinformation introduced in rails#49480 along the way. Closes rails#53348
d6451ef to
01cc805
Compare
…eded-databases `db:prepare` no longer loads seed when non-primary db is created
Motivation / Background
Issue #53348 describes an issue where, after adding Solid Cache to an application, running db:prepare in production re-loaded the seeds, potentially leading to data loss.
Closes #53348
Detail
This PR introduces a new database config property
seedsto control whether seeds are loaded duringdb:preparewhich defaults totruefor primary database configs andfalseotherwise.Previously, the
db:preparetask would load seeds whenever a new database is created, leading to potential loss of data if a database is added to an existing environment.Also, update the Active Record Migrations guide to more accurately describe what the
db:preparetask does, correcting some misinformation introduced in #49480 along the way.Additional information
See previous rejected proposal at #53354
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]