Skip to content

High performance self-hosted photo and video management solution.

fix: include `DROP INDEX` in transaction to prevent missing index on rollback (#25399)

Hao Xie520fc3b63e4
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);