Replies: 4 comments 7 replies
-
My experience has been that |
Beta Was this translation helpful? Give feedback.
-
My question is why not just do a manual list, which we order ourselves as vector/slice? Adding a migration means just appending it to this list. I'm also unsure why we want the date embedded in the filename - once again, why not just use a manual list? And similarly
lets just avoid text/strings/names and use an index as part of the list? Or in summary, I don't see the benefit of
over a vector + index. |
Beta Was this translation helpful? Give feedback.
-
|
Two further pain points I have experienced in the past: Partial migrationsMigrations which take forever on large databases sometimes need to be split into multiple transaction/commit cycles to keep the WAL file (and time) in check. What this can mean is that a migration was only partially completed if the process is killed midway. If this is possible, the migration must take care to use struct versioningA sneakier problem is if the migration depends on external structs. What can easily happen is that the struct is updated in such a way as to invalidate the migration long after we've implemented it. As a trivial example, let's imagine the block header changes structure and some fields are removed. A migration which previously reads the BLOB and does things with it will now fail completely when run. This isn't trivial to solve; but it can often mean such structs must only live within the migration itself aka if this is a concern we may want to copy the structure into the migration code itself |
Beta Was this translation helpful? Give feedback.
-
|
I'm not fully caught up - but maybe an easier path is to build a dedicated binary for a given migration. For example, an upgrade from v0.14 to v0.15 database would require:
One potential benefit of this is that |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Status Quo
Currently we use the vanilla diesel ORM migrations via
embed_migrations!.Limitations
We currently cannot execute rust code in lockstep in a structured way associated to sql migrations. The differentiation is also artificial. I.e. oftentimes we need to add an optional column, use rust to fill in the data, then make it mandatory which equals to SQL -> rust -> SQL sequence of execution domains.
Draft Impl
The initial impl. was a side effect of impl #1697 with the main changes in 3b1319f using a macro. However this did rely on the duality of schema and data migrations and tried to retain simplicity by continuing to use
diesel_migrations::*types as much as possible.Proposal
Directory Structure
Drop
diesel_migrationsand move to a fully custom approach, keeping the directory structure similar to what we have today.I propose a letter prefix to be able to use them as rust modules which can be used without further adjustments. Note the
m-prefix (yes, this is very artisan).The next major change is relying entirely on the
mod.rsrather thanup.sqlanddown.sql- it entirely depends on the needs insidemod.rs.This is then all picked up via a
build.rsfile to be included.Inner
The expectation is, each of these contains an implementation of
the
build.rsthe provides a list of these migrations. The ordering is derived based on lexicographical ordering of the modules.We then can use a fixed harness to execute the sequence
Vec<Box<dyn Migration>>of migrations using afn apply.Statefulness
We will oftentimes encounter partially updated state. To track which migrations were applied and which not, I suggest to maintain another table
migrationsto track which ones (by their module name) are already applied and only apply those post the last one applied.Invariants
We cannot ever modify an existing migration post release, at least not with causing issues at the operational side.
Assumption
We care about
down, if not, we might as well omit entirely which reducestrait Migrationessentially to anFnOnce.Beta Was this translation helpful? Give feedback.
All reactions