From e520fc3b63e49108008d861c25f477528d28f8c4 Mon Sep 17 00:00:00 2001 From: Hao Xi Date: Thu, 19 Feb 2026 01:20:36 -0500 Subject: [PATCH] fix: include `DROP INDEX` in transaction to prevent missing index on rollback (#25399) * fix: ERR_PNPM_ENOENT error while `make dev` on macOS. * fix: include `DROP INDEX` in transaction to prevent missing index on rollback. * chore: clean up this PR. --- server/src/repositories/database.repository.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/repositories/database.repository.ts b/server/src/repositories/database.repository.ts index 17647d065d..650820b18e 100644 --- a/server/src/repositories/database.repository.ts +++ b/server/src/repositories/database.repository.ts @@ -248,11 +248,11 @@ export class DatabaseRepository { } const dimSize = await this.getDimensionSize(table); lists ||= this.targetListCount(await this.getRowCount(table)); - await this.db.schema.dropIndex(indexName).ifExists().execute(); - if (table === 'smart_search') { - await this.db.schema.alterTable(table).dropConstraint('dim_size_constraint').ifExists().execute(); - } await this.db.transaction().execute(async (tx) => { + await sql`DROP INDEX IF EXISTS ${sql.raw(indexName)}`.execute(tx); + if (table === 'smart_search') { + await sql`ALTER TABLE ${sql.raw(table)} DROP CONSTRAINT IF EXISTS dim_size_constraint`.execute(tx); + } if (!rows.some((row) => row.columnName === 'embedding')) { this.logger.warn(`Column 'embedding' does not exist in table '${table}', truncating and adding column.`); await sql`TRUNCATE TABLE ${sql.raw(table)}`.execute(tx);