Handle defensive ALTER TABLE defects in migrations#488
Merged
BunsDev merged 1 commit intoOpenKnots:mainfrom Apr 21, 2026
Merged
Conversation
The defensive ADD COLUMN statements in migrations 020, 025, and 027 use Effect.catch to swallow "duplicate column" errors on re-runs, but @effect/sql-sqlite-bun throws from db.query() outside its try/catch, so the SQLiteError surfaces as an Effect defect rather than a failure. Effect.catch only handles failures, so migration 27 crashed on fresh databases because migration 25 had already added default_model_selection. Switch to Effect.catchCause so both failures and defects are absorbed.
|
@jbrahy is attempting to deploy a commit to the 0xBuns Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
hey @BunsDev how do I get this commited? I couldn't install the latest without fixing this bug |
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
bun devcrashes on first run on a fresh machine: migration 27 errors withSQLiteError: duplicate column name: default_model_selectionandturboexits non-zero, so the server never comes up.ALTER TABLE ... ADD COLUMNcalls via.pipe(Effect.catch(() => Effect.void)), but@effect/sql-sqlite-bunthrows the underlyingSQLiteErrorfromdb.query(sql)before its internaltry/catch(seenode_modules/@effect/sql-sqlite-bun/dist/SqliteClient.js:47), so it surfaces as an Effect defect, not a failure.Effect.catchonly handles failures, so the error escapes. On a fresh DB, migration 25 addsdefault_model_selection, then migration 27 re-adds it and crashes.Effect.catchforEffect.catchCausein the four migrations using that pattern so both failures and defects are absorbed, which restores the intended "idempotent on replay" behavior.Test plan
~/.okcode/dev/state.sqlite*and runbun dev— server now migrates cleanly, web comes up at http://localhost:5733/, bootstrap thread/project created, WS welcome fires.bun run fmt:check,bun run lint,bun --filter okcodes typecheckall pass.