mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fix: change postgres driver version checking query (#9319)
* fix #9318 fix: change postgres driver version checking query Change the postgres `SHOW server_version` query to use `SELECT version()` which adds compatibility with AWS Redshift database Closes: #9318 * git-issue 9318: remove describe from only in test * fix-9318: prettier format test
This commit is contained in:
parent
36718876f9
commit
c4f46506d8
@ -375,13 +375,16 @@ export class PostgresDriver implements Driver {
|
||||
|
||||
const results = (await this.executeQuery(
|
||||
connection,
|
||||
"SHOW server_version;",
|
||||
"SELECT version();",
|
||||
)) as {
|
||||
rows: {
|
||||
server_version: string
|
||||
version: string
|
||||
}[]
|
||||
}
|
||||
const versionString = results.rows[0].server_version
|
||||
const versionString = results.rows[0].version.replace(
|
||||
/^PostgreSQL ([\d\.]+) .*$/,
|
||||
"$1",
|
||||
)
|
||||
this.isGeneratedColumnsSupported = VersionUtils.isGreaterOrEqual(
|
||||
versionString,
|
||||
"12.0",
|
||||
|
||||
@ -3991,8 +3991,8 @@ export class PostgresQueryRunner
|
||||
* Loads Postgres version.
|
||||
*/
|
||||
protected async getVersion(): Promise<string> {
|
||||
const result = await this.query(`SHOW SERVER_VERSION`)
|
||||
return result[0]["server_version"]
|
||||
const result = await this.query(`SELECT version()`)
|
||||
return result[0]["version"].replace(/^PostgreSQL ([\d\.]+) .*$/, "$1")
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -109,10 +109,11 @@ 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 [{ server_version }] = await connection.query(
|
||||
"SHOW server_version",
|
||||
)
|
||||
const semverArray = server_version.split(".").map(Number)
|
||||
const [{ version }] = await connection.query("SELECT version()")
|
||||
const semverArray = version
|
||||
.replace(/^PostgreSQL ([\d\.]+) .*$/, "$1")
|
||||
.split(".")
|
||||
.map(Number)
|
||||
if (!(semverArray[0] >= 10 && semverArray[1] >= 6)) {
|
||||
return
|
||||
}
|
||||
|
||||
47
test/github-issues/9318/issue-9318.ts
Normal file
47
test/github-issues/9318/issue-9318.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import "reflect-metadata"
|
||||
import {
|
||||
createTestingConnections,
|
||||
closeTestingConnections,
|
||||
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"
|
||||
|
||||
describe("github issues > #9318 Change version query from SHOW server_version to SELECT version", () => {
|
||||
let connections: DataSource[]
|
||||
before(
|
||||
async () =>
|
||||
(connections = await createTestingConnections({
|
||||
entities: [],
|
||||
schemaCreate: false,
|
||||
dropSchema: true,
|
||||
enabledDrivers: ["postgres"],
|
||||
})),
|
||||
)
|
||||
beforeEach(() => reloadTestingDatabases(connections))
|
||||
after(() => closeTestingConnections(connections))
|
||||
|
||||
it("should have proper isGeneratedColumnsSupported value for postgres version", () =>
|
||||
Promise.all(
|
||||
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",
|
||||
)
|
||||
|
||||
expect(isGeneratedColumnsSupported).to.eq(
|
||||
versionGreaterOfEqualTo12,
|
||||
)
|
||||
}),
|
||||
))
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user