From a52fe9fbc683ef76c59e15c88f45dd2ec8f7be95 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 23 Feb 2025 09:30:00 -0600 Subject: [PATCH] Try to fix pkey migration --- packages/db/migrations/052_rename_pkey.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/db/migrations/052_rename_pkey.ts b/packages/db/migrations/052_rename_pkey.ts index c7472d02..cf2bedf8 100644 --- a/packages/db/migrations/052_rename_pkey.ts +++ b/packages/db/migrations/052_rename_pkey.ts @@ -1,10 +1,14 @@ import { type Kysely, sql } from 'kysely'; export async function up(db: Kysely): Promise { - try { + const result = await sql<{ count: number }>` + SELECT COUNT(*) as count + FROM pg_indexes + WHERE indexname = 'nostr_events_new_pkey' + `.execute(db); + + if (result.rows[0].count > 0) { await sql`ALTER INDEX nostr_events_new_pkey RENAME TO nostr_events_pkey;`.execute(db); - } catch { - // all good } }