mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fix: version detection for Postgres derived variants (#11375)
This commit is contained in:
parent
460ef023ba
commit
3d79786a92
@ -4160,7 +4160,11 @@ export class PostgresQueryRunner
|
||||
const result: [{ version: string }] = await this.query(
|
||||
`SELECT version()`,
|
||||
)
|
||||
return result[0].version.replace(/^PostgreSQL ([\d.]+) .*$/, "$1")
|
||||
|
||||
// Examples:
|
||||
// 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"
|
||||
// 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"
|
||||
return result[0].version.replace(/^PostgreSQL ([\d.]+).*$/, "$1")
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import "reflect-metadata"
|
||||
import { expect } from "chai"
|
||||
import "reflect-metadata"
|
||||
|
||||
import { DataSource } from "../../../../src/data-source/DataSource"
|
||||
import { DriverUtils } from "../../../../src/driver/DriverUtils"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
@ -109,12 +111,12 @@ describe("cube-postgres", () => {
|
||||
// Get Postgres version because zero-length cubes are not legal
|
||||
// on all Postgres versions. Zero-length cubes are only tested
|
||||
// to be working on Postgres version >=10.6.
|
||||
const [{ version }] = await connection.query("SELECT version()")
|
||||
const semverArray = version
|
||||
.replace(/^PostgreSQL ([\d.]+) .*$/, "$1")
|
||||
.split(".")
|
||||
.map(Number)
|
||||
if (!(semverArray[0] >= 10 && semverArray[1] >= 6)) {
|
||||
if (
|
||||
!DriverUtils.isReleaseVersionOrGreater(
|
||||
connection.driver,
|
||||
"10.6",
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
import { expect } from "chai"
|
||||
import "reflect-metadata"
|
||||
|
||||
import { DataSource } from "../../../src"
|
||||
import { PostgresDriver } from "../../../src/driver/postgres/PostgresDriver"
|
||||
import {
|
||||
createTestingConnections,
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
} from "../../utils/test-utils"
|
||||
import { DataSource } from "../../../src"
|
||||
|
||||
import { expect } from "chai"
|
||||
import { PostgresDriver } from "../../../src/driver/postgres/PostgresDriver"
|
||||
import { VersionUtils } from "../../../src/util/VersionUtils"
|
||||
import { DriverUtils } from "../../../src/driver/DriverUtils"
|
||||
|
||||
describe("github issues > #9318 Change version query from SHOW server_version to SELECT version", () => {
|
||||
let connections: DataSource[]
|
||||
@ -29,15 +29,11 @@ describe("github issues > #9318 Change version query from SHOW server_version to
|
||||
connections.map(async (connection) => {
|
||||
const { isGeneratedColumnsSupported } =
|
||||
connection.driver as PostgresDriver
|
||||
const result = await connection.query("SELECT VERSION()")
|
||||
const dbVersion = result[0]["version"].replace(
|
||||
/^PostgreSQL ([\d.]+) .*$/,
|
||||
"$1",
|
||||
)
|
||||
const versionGreaterOfEqualTo12 = VersionUtils.isGreaterOrEqual(
|
||||
dbVersion,
|
||||
"12.0",
|
||||
)
|
||||
const versionGreaterOfEqualTo12 =
|
||||
DriverUtils.isReleaseVersionOrGreater(
|
||||
connection.driver,
|
||||
"12.0",
|
||||
)
|
||||
|
||||
expect(isGeneratedColumnsSupported).to.eq(
|
||||
versionGreaterOfEqualTo12,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user