From 9d44995b30bb27ee6b8eb3ee199ada7ad13bf259 Mon Sep 17 00:00:00 2001 From: brymko <47984664+brymko@users.noreply.github.com> Date: Fri, 13 Mar 2026 22:04:33 +0800 Subject: [PATCH] fix(ai): handle missing disabled column in auth schema V0-to-V1 migration (#387) The migration unconditionally referenced a `disabled` column in the V0 table, but not all V0 schemas have it. Now checks via PRAGMA table_info and falls back to NULL when the column is absent. Co-authored-by: Claude Opus 4.6 --- packages/ai/CHANGELOG.md | 4 ++++ packages/ai/src/auth-storage.ts | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/ai/CHANGELOG.md b/packages/ai/CHANGELOG.md index b1f2831ec..9e11b485d 100644 --- a/packages/ai/CHANGELOG.md +++ b/packages/ai/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- Fixed auth schema V0-to-V1 migration crash when the V0 table lacks a `disabled` column + ## [13.11.0] - 2026-03-12 ### Added diff --git a/packages/ai/src/auth-storage.ts b/packages/ai/src/auth-storage.ts index e79825c6d..3756c9d14 100644 --- a/packages/ai/src/auth-storage.ts +++ b/packages/ai/src/auth-storage.ts @@ -2291,6 +2291,9 @@ export class AuthCredentialStore { #migrateAuthSchemaV0ToV1(): void { const migrate = this.#db.transaction(() => { + const v0Cols = this.#db.prepare("PRAGMA table_info(auth_credentials)").all() as Array<{ name?: string }>; + const hasDisabled = v0Cols.some(col => col.name === "disabled"); + this.#db.exec("ALTER TABLE auth_credentials RENAME TO auth_credentials_v0"); this.#db.exec(` CREATE TABLE auth_credentials ( @@ -2310,7 +2313,7 @@ export class AuthCredentialStore { provider, credential_type, data, - CASE WHEN disabled = 1 THEN 'disabled' ELSE NULL END, + ${hasDisabled ? "CASE WHEN disabled = 1 THEN 'disabled' ELSE NULL END" : "NULL"}, created_at, updated_at FROM auth_credentials_v0