From 6c49a4ba3418e20019507c46bb702e2e0d39e3fc Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Fri, 5 Jul 2024 17:50:01 -0400 Subject: [PATCH] fix(server): do not try to upgrade to an older version (#10903) --- server/src/services/database.service.spec.ts | 6 ++++-- server/src/services/database.service.ts | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/server/src/services/database.service.spec.ts b/server/src/services/database.service.spec.ts index fb1d8e1ed5..df3a9798ef 100644 --- a/server/src/services/database.service.spec.ts +++ b/server/src/services/database.service.spec.ts @@ -150,6 +150,7 @@ describe(DatabaseService.name, () => { for (const version of ['0.2.1', '0.2.0', '0.2.9']) { it(`should update the pgvecto.rs extension to ${version}`, async () => { databaseMock.getAvailableExtensionVersion.mockResolvedValue(version); + databaseMock.getExtensionVersion.mockResolvedValueOnce(void 0); databaseMock.getExtensionVersion.mockResolvedValue(version); await expect(sut.onBootstrapEvent()).resolves.toBeUndefined(); @@ -166,6 +167,7 @@ describe(DatabaseService.name, () => { it(`should update the pgvectors extension to ${version}`, async () => { process.env.DB_VECTOR_EXTENSION = 'pgvector'; databaseMock.getAvailableExtensionVersion.mockResolvedValue(version); + databaseMock.getExtensionVersion.mockResolvedValueOnce(void 0); databaseMock.getExtensionVersion.mockResolvedValue(version); await expect(sut.onBootstrapEvent()).resolves.toBeUndefined(); @@ -190,10 +192,10 @@ describe(DatabaseService.name, () => { }); } - for (const version of ['0.4.0', '1.0.0']) { + for (const version of ['0.4.0', '0.7.1', '0.7.2', '1.0.0']) { it(`should not upgrade pgvector to ${version}`, async () => { process.env.DB_VECTOR_EXTENSION = 'pgvector'; - databaseMock.getExtensionVersion.mockResolvedValue('0.5.0'); + databaseMock.getExtensionVersion.mockResolvedValue('0.7.2'); databaseMock.getAvailableExtensionVersion.mockResolvedValue(version); await expect(sut.onBootstrapEvent()).resolves.toBeUndefined(); diff --git a/server/src/services/database.service.ts b/server/src/services/database.service.ts index dd3183bb56..e50a509dbf 100644 --- a/server/src/services/database.service.ts +++ b/server/src/services/database.service.ts @@ -98,8 +98,10 @@ export class DatabaseService implements OnEvents { throw error; } + const initialVersion = await this.databaseRepository.getExtensionVersion(extension); const availableVersion = await this.databaseRepository.getAvailableExtensionVersion(extension); - if (availableVersion && semver.satisfies(availableVersion, extensionRange)) { + const isAvailable = availableVersion && semver.satisfies(availableVersion, extensionRange); + if (isAvailable && (!initialVersion || semver.gt(availableVersion, initialVersion))) { try { this.logger.log(`Updating ${name} extension to ${availableVersion}`); const { restartRequired } = await this.databaseRepository.updateVectorExtension(extension, availableVersion);