Skip to content

fix(core): tolerate older migration schemas - #41790

Closed
kitlangton wants to merge 1 commit into
v2from
migration-old-schema
Closed

fix(core): tolerate older migration schemas#41790
kitlangton wants to merge 1 commit into
v2from
migration-old-schema

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What

Import pre-launch previous-channel databases whose project and session tables 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, and time_suspended migrate as SQL NULL.

Closes #41341

Before / After

Before: The previous-channel import selected project and session with SELECT * into current TypeScript row shapes. When an older schema omitted a current field, property access produced undefined; the destination SQL template rendered an empty expression such as VALUES (..., , ...), startup failed with SQLiteError: near ",": syntax error, and migration.v1-v2 remained 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.ts defines complete required/nullable source projections for previous-channel projects and sessions, using PRAGMA table_info to select or default each field.
  • packages/core/test/fixture/v1-migration-old-next.sql captures an older source schema with legacy fork message/sequence fields but no fork_boundary, time_suspended, icon override/color, or commands.
  • packages/core/test/v1-migration.test.ts verifies 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.ts and v1-migration.test.ts, so a rebase may require small same-file conflict resolution.

Testing

  • Before the fix: bun run test test/v1-migration.test.ts --test-name-pattern "older source schema" from packages/core reproduced malformed project insert SQL containing VALUES (..., , ...).
  • bun run test test/v1-migration.test.ts --test-name-pattern "older source schema" from packages/core (1 passed)
  • bun run test test/v1-migration.test.ts test/database-migration.test.ts from packages/core (33 passed)
  • bun typecheck from packages/core
  • Push hook: bun turbo typecheck --concurrency=3 (33 packages passed)
  • git diff --check

@kitlangton

Copy link
Copy Markdown
Contributor Author

This was generated by AI during triage.

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.

@kitlangton kitlangton closed this Aug 12, 2026
@kitlangton
kitlangton deleted the migration-old-schema branch August 12, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant