|
|
|
|
@ -142,21 +142,29 @@ export class DatabaseRepository {
|
|
|
|
|
}
|
|
|
|
|
targetVersion ??= availableVersion;
|
|
|
|
|
|
|
|
|
|
const isVectors = extension === DatabaseExtension.VECTORS;
|
|
|
|
|
let restartRequired = false;
|
|
|
|
|
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.setSearchPath(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);
|
|
|
|
|
restartRequired = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (diff && !restartRequired) {
|
|
|
|
|
if (!restartRequired) {
|
|
|
|
|
await Promise.all([this.reindexVectors(VectorIndex.CLIP), this.reindexVectors(VectorIndex.FACE)]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|