Explicit owner-driven migration, replacing lazy migrate-on-read/commit-on-write#87
Merged
Merged
Conversation
…n-read/commit-on-write (#47) Implements the #47 RFC: migrateAll() is now the only thing that ever changes a record's disk-state typeId. get()/query() return records exactly as stored by default; presentAt: 'latest' is an explicit, never-persisted opt-in supported by both (fixing the get()/query() migration divergence). update() validates against the record's own current type and never migrates as a side effect. Mechanical fixes bundled with the model change: - Filter.baseId matches every version of a type family, resolved client-side via listTypes() before hitting the adapter/wire layer. - Grants match by baseId instead of exact typeId, so a version bump no longer orphans existing grants. - RecordVersion gains typeId, threaded through sqlite-shared, wire-types, and adapter-api. - migrateAll() validates each migrated record against the target schema before committing, aborting immediately on the first failure rather than partially applying a buggy migration. - presentAt: 'latest' throws StackMigrationError (replacing a console.warn + raw record) when a record's version can't be reconciled with what this app instance has registered/defined — covering both a stale binary reading a newer record and an app that knows a later type exists but has no path to reach it. Updates docs/spec.md's Type migrations, Queries, Grant, and Versions sections to match, and adds a Additive evolution within a version section documenting the governance rule from the issue's amendments.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements #47: replaces the lazy migration model (transform-on-read + commit-on-next-write) with explicit, owner-driven
migrateAll(), plus the mechanical fixes the RFC calls out.migrateAll()is the only thing that ever changes a record's disk-statetypeId.update()no longer silently commits a pending migration as a side effect of an unrelated content edit — it validates the merge-patched content against the record's own current stored type and writes back at the sametypeId.get()/query()return records exactly as stored by default, fixing the spec/impl divergence wherequery()never migrated butget()did (the bug that madequery({ filter: { typeId } })silently miss not-yet-migrated records).presentAt: 'latest'is an explicit, never-persisted opt-in supported by both.presentAt: 'latest'throwsStackMigrationError(replacing aconsole.warn+ raw record) when a record's version can't be reconciled with what this app instance has registered/defined — covering both a stale binary reading a newer record and an app that knows a later type exists but has no migration path to reach it.Filter.baseIdmatches every version of a type family, resolved client-side vialistTypes()before hitting the adapter/wire layer — no adapter or wire changes needed.baseIdinstead of exacttypeId, so a version bump no longer orphans existing grants.RecordVersiongainstypeId, threaded throughsqlite-shared(DDL + row mapper),wire-types, andadapter-api.migrateAll()validates each migrated record's content against the target schema before committing, aborting immediately on the first failure rather than partially applying a buggy migration function.Also updates
docs/spec.md's Type migrations, Queries, Grant, and Versions sections, and adds a new "Additive evolution within a version" section capturing the governance rule from the issue's two amendment comments (when a version bump is warranted vs. additive-in-place).Test plan
pnpm -r build— all 9 packages build cleanpnpm -r typecheck— cleanpnpm -r test— all packages pass (core: 278 tests, including new coverage forpresentAt: 'latest',baseIdfiltering, grant-by-family matching, andmigrateAll()abort-on-invalid-migration)pnpm -r lint— cleanpnpm format:check— clean🤖 Generated with Claude Code
Generated by Claude Code