fix(server): drop vector indices before updating extension (#19283)

drop indices before updating
This commit is contained in:
Mert 2025-06-19 17:03:40 +03:00 committed by GitHub
parent e29103b69f
commit 49ed212af8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -142,21 +142,29 @@ export class DatabaseRepository {
} }
targetVersion ??= availableVersion; targetVersion ??= availableVersion;
const isVectors = extension === DatabaseExtension.VECTORS;
let restartRequired = false; let restartRequired = false;
const diff = semver.diff(installedVersion, targetVersion); const diff = semver.diff(installedVersion, targetVersion);
if (!diff) {
return { restartRequired: false };
}
await Promise.all([
this.db.schema.dropIndex(VectorIndex.CLIP).ifExists().execute(),
this.db.schema.dropIndex(VectorIndex.FACE).ifExists().execute(),
]);
await this.db.transaction().execute(async (tx) => { await this.db.transaction().execute(async (tx) => {
await this.setSearchPath(tx); await this.setSearchPath(tx);
await sql`ALTER EXTENSION ${sql.raw(extension)} UPDATE TO ${sql.lit(targetVersion)}`.execute(tx); await sql`ALTER EXTENSION ${sql.raw(extension)} UPDATE TO ${sql.lit(targetVersion)}`.execute(tx);
if (isVectors && (diff === 'major' || diff === 'minor')) { if (extension === DatabaseExtension.VECTORS && (diff === 'major' || diff === 'minor')) {
await sql`SELECT pgvectors_upgrade()`.execute(tx); await sql`SELECT pgvectors_upgrade()`.execute(tx);
restartRequired = true; restartRequired = true;
} }
}); });
if (diff && !restartRequired) { if (!restartRequired) {
await Promise.all([this.reindexVectors(VectorIndex.CLIP), this.reindexVectors(VectorIndex.FACE)]); await Promise.all([this.reindexVectors(VectorIndex.CLIP), this.reindexVectors(VectorIndex.FACE)]);
} }