-
-
Notifications
You must be signed in to change notification settings - Fork 876
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
Allow some migrations to run online / without downtime #4985
Comments
Migrations should create procedures in a separate schema called "run_after_migrations", and the lemmy server should spawn a task that runs and drops the procedures. It will need to be specified that these procedures must be idempotent because some procedures like this controversy rank fixer need to commit changes before the procedure is dropped. Migrations can update or delete an old procedure if it becomes incompatible with the current schema. |
Question about that migration specifically: Does it need to run on all history? Or would a limited set, like the last week of posts only work? |
Requirements
Is your proposal related to a problem?
We've had a multiple cases now where there's a migration that is backwards-compatible, meaning that the new version can run fine without the migration having been run, with the worst case being that some results are slightly wrong or minor degradation of functionality. Many of them are even forward-compatible as well, so the old version of lemmy can also deal with the new schema.
The most recent example in 0.19.6: https://github.com/LemmyNet/lemmy/blob/4018049d10ef84968b31e03d385fdd6874e5782b/migrations/2024-07-01-014711_exponential_controversy/up.sql#L1-L16
This migration purely updates many rows with a new value. Currently this migration runs during a full downtime of lemmy, resulting in 30min+ where the instance is unavailable. In addition, afterwards it needs to catch up with the federation resulting in high instance load and potentially slowness for a while.
Describe the solution you'd like.
The example migration above could be written in a way that it does not impact site operation, by processing the data in batches. For example:
Then the issue becomes, how do we run it? The problem is that we will have some migrations that can run online, but some that need to be offline. The diesel migration runner can not make a distinction between these. In #4673, @dullbananas is trying to add a custom migration runner which might be useful for this.
We could put online migration into a separate directory or add something like
-- lemmy-online-migration --
to the top of the files. Those files would be run separately and after server start, instead of before it.Describe alternatives you've considered.
Additional context
No response
The text was updated successfully, but these errors were encountered: