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.
This commit is contained in:
Hao Xi
2026-02-19 01:20:36 -05:00
committed by GitHub
parent b3b9834c00
commit e520fc3b63

View File

@@ -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);