Skip to content

Commit 48ad83b

Browse files
committed
fix: version detection for Postgres derived variants
1 parent 81bb9d5 commit 48ad83b

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

src/driver/postgres/PostgresQueryRunner.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4160,7 +4160,11 @@ export class PostgresQueryRunner
41604160
const result: [{ version: string }] = await this.query(
41614161
`SELECT version()`,
41624162
)
4163-
return result[0].version.replace(/^PostgreSQL ([\d.]+) .*$/, "$1")
4163+
4164+
// Examples:
4165+
// Postgres: "PostgreSQL 14.10 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-20), 64-bit"
4166+
// Yugabyte: "PostgreSQL 11.2-YB-2.18.1.0-b0 on x86_64-pc-linux-gnu, compiled by clang version 15.0.3 (https://github.com/yugabyte/llvm-project.git 0b8d1183745fd3998d8beffeec8cbe99c1b20529), 64-bit"
4167+
return result[0].version.replace(/^PostgreSQL ([\d.]+).*$/, "$1")
41644168
}
41654169

41664170
/**

test/functional/cube/postgres/cube-postgres.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import "reflect-metadata"
21
import { expect } from "chai"
2+
import "reflect-metadata"
3+
34
import { DataSource } from "../../../../src/data-source/DataSource"
5+
import { DriverUtils } from "../../../../src/driver/DriverUtils"
46
import {
57
closeTestingConnections,
68
createTestingConnections,
@@ -109,12 +111,12 @@ describe("cube-postgres", () => {
109111
// Get Postgres version because zero-length cubes are not legal
110112
// on all Postgres versions. Zero-length cubes are only tested
111113
// to be working on Postgres version >=10.6.
112-
const [{ version }] = await connection.query("SELECT version()")
113-
const semverArray = version
114-
.replace(/^PostgreSQL ([\d.]+) .*$/, "$1")
115-
.split(".")
116-
.map(Number)
117-
if (!(semverArray[0] >= 10 && semverArray[1] >= 6)) {
114+
if (
115+
!DriverUtils.isReleaseVersionOrGreater(
116+
connection.driver,
117+
"10.6",
118+
)
119+
) {
118120
return
119121
}
120122

test/github-issues/9318/issue-9318.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import { expect } from "chai"
12
import "reflect-metadata"
3+
4+
import { DataSource } from "../../../src"
5+
import { PostgresDriver } from "../../../src/driver/postgres/PostgresDriver"
26
import {
3-
createTestingConnections,
47
closeTestingConnections,
8+
createTestingConnections,
59
reloadTestingDatabases,
610
} from "../../utils/test-utils"
7-
import { DataSource } from "../../../src"
8-
9-
import { expect } from "chai"
10-
import { PostgresDriver } from "../../../src/driver/postgres/PostgresDriver"
11-
import { VersionUtils } from "../../../src/util/VersionUtils"
11+
import { DriverUtils } from "../../../src/driver/DriverUtils"
1212

1313
describe("github issues > #9318 Change version query from SHOW server_version to SELECT version", () => {
1414
let connections: DataSource[]
@@ -29,15 +29,11 @@ describe("github issues > #9318 Change version query from SHOW server_version to
2929
connections.map(async (connection) => {
3030
const { isGeneratedColumnsSupported } =
3131
connection.driver as PostgresDriver
32-
const result = await connection.query("SELECT VERSION()")
33-
const dbVersion = result[0]["version"].replace(
34-
/^PostgreSQL ([\d.]+) .*$/,
35-
"$1",
36-
)
37-
const versionGreaterOfEqualTo12 = VersionUtils.isGreaterOrEqual(
38-
dbVersion,
39-
"12.0",
40-
)
32+
const versionGreaterOfEqualTo12 =
33+
DriverUtils.isReleaseVersionOrGreater(
34+
connection.driver,
35+
"12.0",
36+
)
4137

4238
expect(isGeneratedColumnsSupported).to.eq(
4339
versionGreaterOfEqualTo12,

0 commit comments

Comments
 (0)