Skip to content

Commit

Permalink
fix(server): backup version checks not handling database versions cor…
Browse files Browse the repository at this point in the history
…rectly (immich-app#14102)
  • Loading branch information
zackpollard authored and yosit committed Nov 21, 2024
1 parent a6bba43 commit 88ae18a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 7 additions & 6 deletions server/src/services/backup.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 }) => {
Expand Down
3 changes: 1 addition & 2 deletions server/src/services/backup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 88ae18a

Please sign in to comment.