fix(db): индексы audit source_app/event_id только после ALTER
На существующей audit_log CREATE INDEX по source_app падал до добавления колонки — контейнер crash-loop / Traefik 404. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -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_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_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_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
|
const settingsCols = sqlite
|
||||||
.prepare(`PRAGMA table_info(portal_settings)`)
|
.prepare(`PRAGMA table_info(portal_settings)`)
|
||||||
.all() as Array<{ name: string }>
|
.all() as Array<{ name: string }>
|
||||||
@@ -124,8 +123,6 @@ export function migrateSchema(sqlite: Sqlite): void {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
sqlite.exec(`
|
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 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;
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_audit_log_event_id ON audit_log(event_id) WHERE event_id IS NOT NULL;
|
||||||
`)
|
`)
|
||||||
|
|||||||
Reference in New Issue
Block a user