From 40311c30aa0ff6c438b3ce27c89f9d5660d8146e Mon Sep 17 00:00:00 2001 From: Vitaly Tomilov Date: Fri, 28 Jul 2023 12:21:00 +0100 Subject: [PATCH] add version check --- test/db/init.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/db/init.js b/test/db/init.js index 47e4d16a..7783ab83 100644 --- a/test/db/init.js +++ b/test/db/init.js @@ -18,9 +18,17 @@ const header = dbHeader({ const pgp = header.pgp; const db = header.db; +async function getPgVersion() { + const c = await db.connect(); + c.done(); // success, release connection + return c.client.serverVersion; +} + (async function () { - await db.tx(async t => { + const pgHighVersion = parseInt((await getPgVersion()).split('.')[0]); + + await db.tx(`Init PG v${pgHighVersion}`, async t => { // drop all functions; await t.none('DROP FUNCTION IF EXISTS "findUser"(int)'); @@ -55,13 +63,16 @@ const db = header.db; await t.none('CREATE OR REPLACE FUNCTION get_users() RETURNS SETOF users AS $$ SELECT * FROM users $$ language \'sql\''); // adding procedures: - await t.none('CREATE OR REPLACE PROCEDURE empty_proc() LANGUAGE SQL AS $$ $$;'); - await t.none(`CREATE OR REPLACE PROCEDURE output_proc(INOUT output1 boolean, INOUT output2 text) + if (pgHighVersion >= 11) { + // Postgresql v10 and earlier do not support procedures + await t.none('CREATE OR REPLACE PROCEDURE empty_proc() LANGUAGE SQL AS $$ $$;'); + await t.none(`CREATE OR REPLACE PROCEDURE output_proc(INOUT output1 boolean, INOUT output2 text) LANGUAGE plpgsql AS $$ BEGIN output1 := true; output2 := concat(output2, '-hello!'); END;$$;`); + } }) .then(() => { // eslint-disable-next-line no-console