diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts index 145ef7b..f8eac75 100644 --- a/packages/db/src/index.ts +++ b/packages/db/src/index.ts @@ -92,10 +92,9 @@ export function migrateSchema(sqlite: Sqlite): void { CREATE INDEX IF NOT EXISTS idx_audit_log_action ON audit_log(action); CREATE INDEX IF NOT EXISTS idx_audit_log_actor ON audit_log(actor_user_id, created_at); CREATE INDEX IF NOT EXISTS idx_audit_log_target ON audit_log(target_id, created_at); - CREATE INDEX IF NOT EXISTS idx_audit_log_source ON audit_log(source_app, created_at); - CREATE UNIQUE INDEX IF NOT EXISTS idx_audit_log_event_id ON audit_log(event_id) WHERE event_id IS NOT NULL; `) + // Existing DBs: CREATE TABLE IF NOT EXISTS skips schema — ALTER before indexes on new cols. const settingsCols = sqlite .prepare(`PRAGMA table_info(portal_settings)`) .all() as Array<{ name: string }> @@ -124,8 +123,6 @@ export function migrateSchema(sqlite: Sqlite): void { ) } sqlite.exec(` - CREATE INDEX IF NOT EXISTS idx_audit_log_actor ON audit_log(actor_user_id, created_at); - CREATE INDEX IF NOT EXISTS idx_audit_log_target ON audit_log(target_id, created_at); CREATE INDEX IF NOT EXISTS idx_audit_log_source ON audit_log(source_app, created_at); CREATE UNIQUE INDEX IF NOT EXISTS idx_audit_log_event_id ON audit_log(event_id) WHERE event_id IS NOT NULL; `)