fix(core): tolerate older migration schemas - #41790
Closed
kitlangton wants to merge 1 commit into
Closed
Conversation
Contributor
Author
Closing this because it only preserves compatibility with databases created by older preview V2 builds. Those builds were not a stable public persistence boundary, and the additional migration-query machinery is not worth carrying forward. |
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.
What
Import pre-launch previous-channel databases whose
projectandsessiontables predate nullable fields expected by the current migration.Older databases now retain every available project, session, and message value while absent nullable fields such as
commands,fork_boundary, andtime_suspendedmigrate as SQLNULL.Closes #41341
Before / After
Before: The previous-channel import selected
projectandsessionwithSELECT *into current TypeScript row shapes. When an older schema omitted a current field, property access producedundefined; the destination SQL template rendered an empty expression such asVALUES (..., , ...), startup failed withSQLiteError: near ",": syntax error, andmigration.v1-v2remained in the sessions phase to fail again on every startup.After: The import inspects each source table schema and builds an explicit current-shape projection. Available columns are preserved, absent nullable columns are selected as
NULL AS column, and absent required columns produce a direct compatibility error. The existing per-session destination transaction then imports the project, session, messages, and event-sequence watermark normally.How
packages/core/src/database/v1-migration.tsdefines complete required/nullable source projections for previous-channel projects and sessions, usingPRAGMA table_infoto select or default each field.packages/core/test/fixture/v1-migration-old-next.sqlcaptures an older source schema with legacy fork message/sequence fields but nofork_boundary,time_suspended, icon override/color, orcommands.packages/core/test/v1-migration.test.tsverifies that the old schema imports successfully, preserves available fork/project/message data, defaults absent fields to null, and initializes the event-sequence watermark.Scope
This does not redesign migration progress, cursoring, transforms, or transaction boundaries. The source database remains a read-only snapshot; destination session IDs remain the previous-channel import's idempotency boundary; and each newly imported session still commits its project, session, messages, and watermark atomically.
Draft PR #41781 changes adjacent V1 migration event cleanup and tests independently. This PR does not depend on it, but both touch
v1-migration.tsandv1-migration.test.ts, so a rebase may require small same-file conflict resolution.Testing
bun run test test/v1-migration.test.ts --test-name-pattern "older source schema"frompackages/corereproduced malformed project insert SQL containingVALUES (..., , ...).bun run test test/v1-migration.test.ts --test-name-pattern "older source schema"frompackages/core(1 passed)bun run test test/v1-migration.test.ts test/database-migration.test.tsfrompackages/core(33 passed)bun typecheckfrompackages/corebun turbo typecheck --concurrency=3(33 packages passed)git diff --check