fix(scripts): add recover-dev-db.sql for fork-branch migration mismatch#15
Closed
Benniphx wants to merge 1 commit into
Closed
fix(scripts): add recover-dev-db.sql for fork-branch migration mismatch#15Benniphx wants to merge 1 commit into
Benniphx wants to merge 1 commit into
Conversation
Local dev DBs that were built up on a fork branch can have migration
IDs 14-18 recorded that map to different migrations than the ones on
main. The Effect-SQL migrator only tracks numeric IDs, so main's
migrations 14-18 never run on those DBs, producing errors like:
SQLiteError: no such column: default_model_selection_json
ProviderSessionDirectoryPersistenceError: Unknown persisted provider
'claudeCode'.
This script applies the missing schema deltas (migrations 14-18) and
renames the legacy 'claudeCode' provider to 'claudeAgent', without
touching effect_sql_migrations.
Usage:
cp ~/.t3/dev/state.sqlite ~/.t3/dev/state.sqlite.bak
sqlite3 ~/.t3/dev/state.sqlite < scripts/recover-dev-db.sql
Collaborator
Author
|
Closing in favor of a same-repo PR — got WRITE access in the meantime. |
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.
Problem
Local dev DBs that were grown on a fork branch can fail to start
bun run devafter switching back tomain:The Effect-SQL migrator tracks migrations by numeric ID only. If a DB has IDs 14–18 recorded from a fork timeline that used different migrations under those IDs, main's 14–18 are silently skipped — leaving the schema half-converted.
Concrete divergence I hit (Tobias' fork → main):
Plus the
claudeCode→claudeAgentprovider rename was code-only, so legacy rows still referenceclaudeCode.What this PR does
Adds
scripts/recover-dev-db.sql— a single-transaction recovery script that:claudeCode→claudeAgentinprovider_session_runtime(provider_name + adapter_key),projection_thread_sessions.provider_name, andorchestration_events.payload_json.projection_thread_proposed_plans:implemented_at,implementation_thread_idprojection_turns:source_proposed_plan_thread_id,source_proposed_plan_idCanonicalizeModelSelections— addsdefault_model_selection_json(projects),model_selection_json(threads), dropsdefault_model/model, and portsorchestration_eventspayloads (project.created,project.meta-updated,thread.created,thread.meta-updated,thread.turn-start-requested) to the newmodelSelectionshape.projection_threads.archived_atidx_projection_threads_project_archived_ateffect_sql_migrations— IDs 14–21 are already recorded as applied, so no migration will be re-run.Recommended path: keep your data (Option B)
This is the path teammates should default to — wiping the DB loses all local sessions.
Fallback only: nuke and re-create (Option A)
Use this only if Option B somehow doesn't work for you. You will lose all local dev sessions.
Verification
After running the script:
First three should be
1, last should be0. Tested locally on a real fork-grown DB (~3.7 MB, ~200 events withclaudeCodereferences) — all checks green, dev server starts cleanly, sessions intact.Out of scope (but worth a follow-up)
The root cause — migrator keying only on ID — is what makes this class of break possible. A future change could verify recorded migration names match expected ones at startup and warn or fail fast.