From cb1284c8c0950dcb792e95b889efe1dfafc05aea Mon Sep 17 00:00:00 2001 From: Henry Chan <112690257+hfhchan-plb@users.noreply.github.com> Date: Mon, 24 Nov 2025 20:10:30 +0800 Subject: [PATCH] feat: init version in postgres driver only if not set (#11373) --- src/driver/postgres/PostgresDriver.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/driver/postgres/PostgresDriver.ts b/src/driver/postgres/PostgresDriver.ts index 62167732f..e45d39696 100644 --- a/src/driver/postgres/PostgresDriver.ts +++ b/src/driver/postgres/PostgresDriver.ts @@ -73,7 +73,8 @@ export class PostgresDriver implements Driver { options: PostgresConnectionOptions /** - * Version of Postgres. Requires a SQL query to the DB, so it is not always set + * Version of Postgres. Requires a SQL query to the DB, so it is set on the first + * connection attempt. */ version?: string @@ -362,20 +363,24 @@ export class PostgresDriver implements Driver { this.master = await this.createPool(this.options, this.options) } - const queryRunner = this.createQueryRunner("master") + if (!this.version || !this.database || !this.searchSchema) { + const queryRunner = this.createQueryRunner("master") - this.version = await queryRunner.getVersion() + if (!this.version) { + this.version = await queryRunner.getVersion() + } - if (!this.database) { - this.database = await queryRunner.getCurrentDatabase() + if (!this.database) { + this.database = await queryRunner.getCurrentDatabase() + } + + if (!this.searchSchema) { + this.searchSchema = await queryRunner.getCurrentSchema() + } + + await queryRunner.release() } - if (!this.searchSchema) { - this.searchSchema = await queryRunner.getCurrentSchema() - } - - await queryRunner.release() - if (!this.schema) { this.schema = this.searchSchema }