feat(server): Throw error when PostgreSQL version is not within the supported versions

The pgvecto.rs extension, though not distributed, can be built for PostgreSQL 12 and 13.
An installation of PostgreSQL 12 with the pgvecto.rs extensions installed will not be caught by immich.
This causes immich to attempt to run the database migrations without having a proper environment.
With assertPostgresql the server will throw an error if the PostgreSQL version is not within the supported range.
This commit is contained in:
max 2024-01-06 14:34:12 +01:00
parent a233e176e5
commit 6f4362252b

View file

@ -7,12 +7,14 @@ import { DatabaseExtension, IDatabaseRepository } from '../repositories';
@Injectable()
export class DatabaseService {
private logger = new ImmichLogger(DatabaseService.name);
minPostgresVersion = 14;
minVectorsVersion = new Version(0, 1, 1);
maxVectorsVersion = new Version(0, 1, 11);
constructor(@Inject(IDatabaseRepository) private databaseRepository: IDatabaseRepository) {}
async init() {
await this.assertPostgresql();
await this.createVectors();
await this.assertVectors();
await this.databaseRepository.runMigrations();
@ -66,4 +68,13 @@ export class DatabaseService {
}
return `tensorchord/pgvecto-rs:pg${major}-v${this.maxVectorsVersion}`;
}
private async assertPostgresql() {
const { major } = await this.databaseRepository.getPostgresVersion();
if (![14, 15, 16].includes(major)) {
throw new Error(`
The PostgreSQL version is ${major}, which is older than the minimum supported version ${this.minPostgresVersion}.
Please upgrade to this version or later.`);
}
}
}