This repository was archived by the owner on Aug 3, 2026. It is now read-only.
Document how to migrate a schema - #177
Merged
Merged
Conversation
The feature table named `worktable_version!` and `migration_engine!` and that was the whole of it. Working out how to use them meant reading the codegen and then finding a project that had already done it, which is a poor trade for a feature whose failure mode is silent data corruption. So the doc leads with what goes wrong rather than with the API. A persisted row carries no record of the columns that produced it, so a table whose columns change reads every existing row through the new layout and rkyv obliges. Nothing errors. Fields shift by one, ids arrive as titles, and the table opened cleanly. The example output is real, from a five-column table that gained a sixth. Everything here is verified against worktable 0.9.2 and a production migration: version defaults to 1 and must precede `columns`, old shapes use `worktable_version!` and are stripped of persist, indexes and queries, the table name stays fixed across versions, custom primary-key generators must be repeated per version module, hops compose so v1 to v4 is three functions, unchanged tables are copied rather than migrated, and a source already at the current version reports `Unsupported version: N`, which is how a run is made idempotent. Two things are called out because they are judgement rather than API. Source and target are separate directories, so a failed migration leaves the original untouched. And migration belongs in its own binary rather than in application startup, because a crash halfway through a boot-time migration is the case with no good recovery.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The feature table named
worktable_version!andmigration_engine!, and that was the whole of it. Working out how to actually use them meant readingcodegen/and then finding a project that had already done it. That is a poor trade for a feature whose failure mode is silent data corruption.What the doc leads with
Not the API. What goes wrong without it.
A persisted row carries no record of the columns that produced it, so a table whose columns change reads every existing row through the new layout and rkyv obliges. Nothing errors. The table opens cleanly and the fields have shifted by one:
{"id":"ment) ","project_id":"item-03fd09c6-...","title":"proj-846b5542-...","status":"Reflect PR merge state in the UI"}Every value present, every value in the wrong field. That output is real, from a five-column table that gained a sixth.
Verified, not inferred
Everything is checked against worktable 0.9.2 and a production migration:
versiondefaults to1and must appear beforecolumnsworktable_version!, stripped ofpersist,indexesandqueriesversionmovesUnsupported version: N, which is how a run is made idempotentTwo judgement calls, called out as such
Source and target are separate directories. A migration that fails partway leaves the only copy of the data intact, so there is nothing to undo.
Migration belongs in its own binary, not in application startup. A crash halfway through a boot-time migration is precisely the case with no good recovery.
Ends with a checklist, because the failure is silent and the steps are easy to half-do.