Try to fix pkey migration

This commit is contained in:
Alex Gleason 2025-02-23 09:30:00 -06:00
parent 02d4235abd
commit a52fe9fbc6
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -1,10 +1,14 @@
import { type Kysely, sql } from 'kysely';
export async function up(db: Kysely<unknown>): Promise<void> {
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
}
}