From 6f4362252bb68bae74e2478e8bbc054dec372e6d Mon Sep 17 00:00:00 2001 From: max Date: Sat, 6 Jan 2024 14:34:12 +0100 Subject: [PATCH] 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. --- server/src/domain/database/database.service.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/src/domain/database/database.service.ts b/server/src/domain/database/database.service.ts index f70fc48d5e..3c0fdf85ef 100644 --- a/server/src/domain/database/database.service.ts +++ b/server/src/domain/database/database.service.ts @@ -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.`); + } + } }