Skip to content

Commit

Permalink
Use server_version setting to resolve current PG version. (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorKulbachka authored Jan 12, 2024
1 parent f8ca3f9 commit e4d27b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 6 additions & 7 deletions packages/pg-migrations/src/PostgresDatabaseEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,13 @@ function getExport(mod: any, filename: string) {
}

async function getPgVersion(connection: Queryable): Promise<[number, number]> {
// e.g. PostgreSQL 10.1 on x86_64-apple-darwin16.7.0, compiled by Apple LLVM version 9.0.0 (clang-900.0.38), 64-bit
const [{version: sqlVersionString}] = await connection.query(
connection.sql`SELECT version();`,
// server_version -> 10.6.0
const [{server_version: sqlVersionString}] = await connection.query(
connection.sql`SHOW server_version;`,
);
const match = /PostgreSQL (\d+).(\d+)/.exec(sqlVersionString);
if (match) {
const [, major, minor] = match;
return [parseInt(major, 10), parseInt(minor, 10)];
const versions = sqlVersionString.split('.');
if (versions.length > 1) {
return [parseInt(versions[0], 10), parseInt(versions[1], 10)];
}
return [0, 0];
}
13 changes: 6 additions & 7 deletions packages/pg-schema-introspect/src/__tests__/getTypes.test.pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,13 @@ test('get custom types', async () => {
});

async function getPgVersion(): Promise<[number, number]> {
// e.g. PostgreSQL 10.1 on x86_64-apple-darwin16.7.0, compiled by Apple LLVM version 9.0.0 (clang-900.0.38), 64-bit
const [{version: sqlVersionString}] = await db.query(
db.sql`SELECT version();`,
// server_version -> 10.6.0
const [{server_version: sqlVersionString}] = await db.query(
db.sql`SHOW server_version;`,
);
const match = /PostgreSQL (\d+).(\d+)/.exec(sqlVersionString);
if (match) {
const [, major, minor] = match;
return [parseInt(major, 10), parseInt(minor, 10)];
const versions = sqlVersionString.split('.');
if (versions.length > 1) {
return [parseInt(versions[0], 10), parseInt(versions[1], 10)];
}
return [0, 0];
}
Expand Down

0 comments on commit e4d27b9

Please sign in to comment.