From 184f958d8ec1abe697d797c68a927e7cdeeb511b Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Fri, 4 Oct 2024 03:26:33 +0530 Subject: [PATCH] try fixing migration 034 --- .../034_move_author_search_to_author_stats.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/db/migrations/034_move_author_search_to_author_stats.ts b/src/db/migrations/034_move_author_search_to_author_stats.ts index 6d21ca39..001e26e9 100644 --- a/src/db/migrations/034_move_author_search_to_author_stats.ts +++ b/src/db/migrations/034_move_author_search_to_author_stats.ts @@ -1,12 +1,20 @@ import { Kysely, sql } from 'kysely'; export async function up(db: Kysely): Promise { - await db.schema - .alterTable('author_stats') - .addColumn('search', 'text', (col) => col.notNull().defaultTo('')) - .execute(); + try { + await db.schema + .alterTable('author_stats') + .addColumn('search', 'text', (col) => col.notNull().defaultTo('')) + .execute(); + } catch (e) { + if (e.message.toLowerCase().includes('already exists')) { + console.warn('skipping 034'); + } + } - await sql`CREATE INDEX author_stats_search_idx ON author_stats USING GIN (search gin_trgm_ops)`.execute(db); + await sql`CREATE INDEX IF NOT EXISTS author_stats_search_idx ON author_stats USING GIN (search gin_trgm_ops)`.execute( + db, + ); await db.insertInto('author_stats') .columns(['pubkey', 'search'])