Skip to content

Commit df62c92

Browse files
committed
Handle defensive ALTER TABLE defects in migrations
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.
1 parent 811d290 commit df62c92

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

apps/server/src/persistence/Migrations/020_SmeConversationProviderAuth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ export default Effect.gen(function* () {
77
yield* sql`
88
ALTER TABLE sme_conversations
99
ADD COLUMN provider TEXT NOT NULL DEFAULT 'claudeAgent'
10-
`.pipe(Effect.catch(() => Effect.void));
10+
`.pipe(Effect.catchCause(() => Effect.void));
1111

1212
yield* sql`
1313
ALTER TABLE sme_conversations
1414
ADD COLUMN auth_method TEXT NOT NULL DEFAULT 'auto'
15-
`.pipe(Effect.catch(() => Effect.void));
15+
`.pipe(Effect.catchCause(() => Effect.void));
1616

1717
yield* sql`
1818
UPDATE sme_conversations

apps/server/src/persistence/Migrations/025_CanonicalizeModelSelections.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ export default Effect.gen(function* () {
77
yield* sql`
88
ALTER TABLE projection_projects
99
ADD COLUMN default_model_selection TEXT
10-
`.pipe(Effect.catch(() => Effect.void));
10+
`.pipe(Effect.catchCause(() => Effect.void));
1111

1212
yield* sql`
1313
ALTER TABLE projection_threads
1414
ADD COLUMN model_selection TEXT
15-
`.pipe(Effect.catch(() => Effect.void));
15+
`.pipe(Effect.catchCause(() => Effect.void));
1616

1717
yield* sql`
1818
UPDATE projection_projects

apps/server/src/persistence/Migrations/025_ProjectionProjectIconPath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export default Effect.gen(function* () {
77
yield* sql`
88
ALTER TABLE projection_projects
99
ADD COLUMN icon_path TEXT
10-
`.pipe(Effect.catch(() => Effect.void));
10+
`.pipe(Effect.catchCause(() => Effect.void));
1111
});

apps/server/src/persistence/Migrations/027_CanonicalizeModelSelectionsBackfill.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ export default Effect.gen(function* () {
8181
yield* sql`
8282
ALTER TABLE projection_projects
8383
ADD COLUMN default_model_selection TEXT
84-
`.pipe(Effect.catch(() => Effect.void));
84+
`.pipe(Effect.catchCause(() => Effect.void));
8585

8686
yield* sql`
8787
ALTER TABLE projection_threads
8888
ADD COLUMN model_selection TEXT
89-
`.pipe(Effect.catch(() => Effect.void));
89+
`.pipe(Effect.catchCause(() => Effect.void));
9090

9191
const projectRows = yield* sql<ProjectRow>`
9292
SELECT

0 commit comments

Comments
 (0)