From f75459f8bfed048b3e4dc995cee4b16cfcd1f913 Mon Sep 17 00:00:00 2001 From: cita Date: Sat, 28 Feb 2026 22:26:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=A1=A8=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E6=80=A7=E6=A3=80=E6=9F=A5=E4=BB=A5=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=A8=A1=E5=BC=8F=E7=9A=84=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/db/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/server/db/index.ts b/src/server/db/index.ts index f393941..ac713e5 100644 --- a/src/server/db/index.ts +++ b/src/server/db/index.ts @@ -12,12 +12,22 @@ const sqlite = new Database(dbPath); sqlite.pragma('journal_mode = WAL'); sqlite.pragma('foreign_keys = ON'); +function tableExists(table: string): boolean { + const row = sqlite.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = ? LIMIT 1") + .get(table) as { name?: string } | undefined; + return !!row?.name; +} + function tableColumnExists(table: string, column: string): boolean { const rows = sqlite.prepare(`PRAGMA table_info(${table})`).all() as Array<{ name?: string }>; return rows.some((row) => row.name === column); } function ensureTokenManagementSchema() { + if (!tableExists('accounts') || !tableExists('route_channels')) { + return; + } + sqlite.exec(` CREATE TABLE IF NOT EXISTS account_tokens ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -78,6 +88,10 @@ function ensureTokenManagementSchema() { } function ensureSiteStatusSchema() { + if (!tableExists('sites')) { + return; + } + if (!tableColumnExists('sites', 'status')) { sqlite.exec(`ALTER TABLE sites ADD COLUMN status text DEFAULT 'active';`); }