Repository navigation
Skip loading seeds for databases that are managed by Rails - #53354
flavorjones wants to merge 2 commits into
Conversation
For cases where it may be useful to distinguish between databases that
are fully managed by Rails (e.g., Solid {Cache,Queue,Cable}) and those
that the application developer owns.
|
The primary database is already special-cased in some place. (Such has for falling back to In my opinion, if that primary database already exist and has data, then no seed should ever happen automatically again. If there is no such database in the config, you are in complicated custom territory. Maybe then a "seeded: true" in the config for database of interests would make sense. This way, you avoid annoying everyone with manually putting in a default config they will never have to change. I guess at that point, the idea is just that primary is the only database with The only thing to decide would then be what happens when there is more than one |
|
@MaxLap please note that this PR is slightly different from what I suggested in your original issue, please take a look. I appreciate your suggestion that the only change that's needed is to skip seed unless the database config return true from However, since the Solid gems introduce (for the first time) databases that are managed by the framework for the application developer, I'd like to get feedback on this approach from someone on the core team. I think that distinction in ownership is worth having a conversation about even if we end up with a simpler solution in this case. |
|
@flavorjones I saw the difference but wanted to chime in with a solution I felt more general. It wasn't meant to be the "answer to the PR/question", sorry if it felt that way. I completely agree that this needs feedback from core. |
|
@flavorjones please add a changelog entry |
|
@MatheusRich It's not clear to me that a CHANGELOG entry is needed, since this fixes functionality introduced in Rails 8. I'd like to wait for feedback from the core team before adding one. |
| database_initialized = initialize_database(db_config) | ||
|
|
||
| seed = true if database_initialized | ||
| seed = true if database_initialized && !db_config.framework? |
There was a problem hiding this comment.
I think the problem is that this seed is a regular boolean when it should not. It isn't taking in consideration that the application can have multiple database. The other problem is that seeds are global and don't specify to which database those seeds are for.
I really think it is a bad idea to run a task that can run the seeds in production. Why are we doing that? Seeds are mostly for development.
Adding a flag to tell there are framework databases can fix the symptoms, but the root cause is that we are running db:prepare in production and it can run seeds when any database is created which can wipe all your data.
Any other primary database added after the application is already in production for a while would wipe the primary database as well, and they should not mark their database as framework: true
|
Hmm, I think this is a little too indirect. I'd prefer to either just run the seeds for the primary database or have something like |
|
Yeah. Seeds are the problem here, I think that boolean needs to be more nuanced than the "true if any database we care about was created, or false otherwise". |
|
Thanks for the feedback. Will try again in a different PR. |
|
Next attempt is at #53379 |
Motivation / Background
Issue #53348 describes an issue where, after adding Solid Cache to an application, running
db:preparein production re-loaded the seeds, potentially leading to data loss.This PR proposes that any databases that are managed by Rails should behave differently in this case, and seeds should not be run when a Solid {Cache,Queue,Cable} database is added to the config and initialized.
Detail
Specifically, this PR adds a new method
DatabaseConfig#framework?which defaults tofalse, but is set totruefor the Solid-* databases in Rails's default production database config.Additional information
If this proposal is merged, the docs for the Solid-* gems should be updated to inform users to add the
framework: truevalue to their database config.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]