From 184d7bce3d729c4fc81a5472a418df63a4c8d376 Mon Sep 17 00:00:00 2001 From: Zack Pollard Date: Tue, 12 Nov 2024 16:28:51 +0000 Subject: [PATCH] fix(server): backup version checks not handling database versions correctly --- server/src/services/backup.service.spec.ts | 13 +++++++------ server/src/services/backup.service.ts | 3 +-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/src/services/backup.service.spec.ts b/server/src/services/backup.service.spec.ts index 4152d88cb17c8..41ba7c2153e1e 100644 --- a/server/src/services/backup.service.spec.ts +++ b/server/src/services/backup.service.spec.ts @@ -149,7 +149,6 @@ describe(BackupService.name, () => { storageMock.unlink.mockResolvedValue(); systemMock.get.mockResolvedValue(systemConfigStub.backupEnabled); storageMock.createWriteStream.mockReturnValue(new PassThrough()); - databaseMock.getPostgresVersion.mockResolvedValue('14.3.2'); }); it('should run a database backup successfully', async () => { const result = await sut.handleBackupDatabase(); @@ -198,11 +197,13 @@ describe(BackupService.name, () => { expect(result).toBe(JobStatus.FAILED); }); it.each` - postgresVersion | expectedVersion - ${'14.6.4'} | ${14} - ${'15.3.3'} | ${15} - ${'16.4.2'} | ${16} - ${'17.15.1'} | ${17} + postgresVersion | expectedVersion + ${'14.10'} | ${14} + ${'14.10.3'} | ${14} + ${'14.10 (Debian 14.10-1.pgdg120+1)'} | ${14} + ${'15.3.3'} | ${15} + ${'16.4.2'} | ${16} + ${'17.15.1'} | ${17} `( `should use pg_dumpall $expectedVersion with postgres version $postgresVersion`, async ({ postgresVersion, expectedVersion }) => { diff --git a/server/src/services/backup.service.ts b/server/src/services/backup.service.ts index 76b8fcd85bd9a..daa7d180f1367 100644 --- a/server/src/services/backup.service.ts +++ b/server/src/services/backup.service.ts @@ -105,9 +105,8 @@ export class BackupService extends BaseService { const databaseVersion = await this.databaseRepository.getPostgresVersion(); const databaseSemver = semver.coerce(databaseVersion); const databaseMajorVersion = databaseSemver?.major; - const databaseSupported = semver.satisfies(databaseVersion, '>=14.0.0 <18.0.0'); - if (!databaseMajorVersion || !databaseSupported) { + if (!databaseMajorVersion || !databaseSemver || !semver.satisfies(databaseSemver, '>=14.0.0 <18.0.0')) { this.logger.error(`Database Backup Failure: Unsupported PostgreSQL version: ${databaseVersion}`); return JobStatus.FAILED; }