From 54cfe400d40df95db9041cde112d06bd2aacb039 Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Fri, 3 Jan 2025 16:52:26 +0100 Subject: [PATCH] LDEV-5236 GHA: fix public schema permissions for postgres 15+ (#2465) --- .github/workflows/main.yml | 1 + test/tags/dbInfo.cfc | 114 +++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 54 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 49dbe4ff10..416d33bb8d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -198,6 +198,7 @@ jobs: sudo -u postgres psql -c 'create database lucee;' sudo -u postgres psql -c "create user lucee with encrypted password 'lucee'"; sudo -u postgres psql -c 'grant all privileges on database lucee to lucee;' + sudo -u postgres psql -c 'grant all on schema public to lucee;' -d lucee - name: Start MongoDB (docker) uses: supercharge/mongodb-github-action@1.6.0 with: diff --git a/test/tags/dbInfo.cfc b/test/tags/dbInfo.cfc index e7ea11755d..aa87cf7670 100644 --- a/test/tags/dbInfo.cfc +++ b/test/tags/dbInfo.cfc @@ -49,6 +49,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" { createSchema( ds, dbtype, prefix ); describe( title="Test suite for DBINFO, db: [#dbType#]", body=function() { + it(title = "dbinfo columns [#dbType#]", data = { prefix: prefix, ds: ds, dbtype: dbtype }, body = function( data ) { @@ -167,75 +168,80 @@ component extends="org.lucee.cfml.test.LuceeTestCase" { private void function createSchema( struct ds, string dbType, string prefix, boolean onlyDrop=false ){ + try { - if (arguments.dbtype eq "oracle") { // oracle doesn't support the IF EXISTS syntax - try { + if (arguments.dbtype eq "oracle") { // oracle doesn't support the IF EXISTS syntax + try { + query datasource=arguments.ds { + echo("DROP view #arguments.prefix#v_users"); + } + } catch(e){ + // + } + try { + query datasource=arguments.ds { + echo("DROP TABLE #arguments.prefix#users"); + } + } catch(e){ + // + } + try { + query datasource=arguments.ds { + echo("DROP TABLE #arguments.prefix#roles"); + } + } catch(e){ + // + } + } else { query datasource=arguments.ds { - echo("DROP view #arguments.prefix#v_users"); + echo("DROP view IF EXISTS #arguments.prefix#v_users"); } - } catch(e){ - // - } - try { query datasource=arguments.ds { - echo("DROP TABLE #arguments.prefix#users"); + echo("DROP TABLE IF EXISTS #arguments.prefix#users"); } - } catch(e){ - // - } - try { query datasource=arguments.ds { - echo("DROP TABLE #arguments.prefix#roles"); + echo("DROP TABLE IF EXISTS #arguments.prefix#roles"); } - } catch(e){ - // } - } else { + + if ( arguments.onlyDrop ) + return; + + query datasource=arguments.ds { + echo("CREATE TABLE #arguments.prefix#roles ( + role_id INT, + role_name VARCHAR(100) DEFAULT NULL, + CONSTRAINT PK_#arguments.prefix#roles PRIMARY KEY ( role_id ) + )"); + } query datasource=arguments.ds { - echo("DROP view IF EXISTS #arguments.prefix#v_users"); + echo("CREATE TABLE #arguments.prefix#users ( + user_id VARCHAR(50) NOT NULL, + user_name VARCHAR(50) NOT NULL, + role_id INT DEFAULT NULL, + CONSTRAINT PK_#arguments.prefix#users PRIMARY KEY ( user_id ) + )"); } query datasource=arguments.ds { - echo("DROP TABLE IF EXISTS #arguments.prefix#users"); + echo("ALTER TABLE #arguments.prefix#users + ADD CONSTRAINT fk_#arguments.prefix#_user_role_id + FOREIGN KEY (role_id) + REFERENCES #arguments.prefix#roles ( role_id )"); } query datasource=arguments.ds { - echo("DROP TABLE IF EXISTS #arguments.prefix#roles"); + echo("CREATE INDEX idx_#arguments.prefix#_users_role_id ON #arguments.prefix#users(role_id)"); } - } - - if ( arguments.onlyDrop ) - return; - - query datasource=arguments.ds { - echo("CREATE TABLE #arguments.prefix#roles ( - role_id INT, - role_name VARCHAR(100) DEFAULT NULL, - CONSTRAINT PK_#arguments.prefix#roles PRIMARY KEY ( role_id ) - )"); - } - query datasource=arguments.ds { - echo("CREATE TABLE #arguments.prefix#users ( - user_id VARCHAR(50) NOT NULL, - user_name VARCHAR(50) NOT NULL, - role_id INT DEFAULT NULL, - CONSTRAINT PK_#arguments.prefix#users PRIMARY KEY ( user_id ) - )"); - } - query datasource=arguments.ds { - echo("ALTER TABLE #arguments.prefix#users - ADD CONSTRAINT fk_#arguments.prefix#_user_role_id - FOREIGN KEY (role_id) - REFERENCES #arguments.prefix#roles ( role_id )"); - } - query datasource=arguments.ds { - echo("CREATE INDEX idx_#arguments.prefix#_users_role_id ON #arguments.prefix#users(role_id)"); - } - query datasource=arguments.ds { - echo("CREATE VIEW #arguments.prefix#v_users AS - SELECT u.user_id, u.user_name, r.role_id, r.role_name - FROM #arguments.prefix#users u, #arguments.prefix#roles r - WHERE r.role_id = u.role_id - "); + query datasource=arguments.ds { + echo("CREATE VIEW #arguments.prefix#v_users AS + SELECT u.user_id, u.user_name, r.role_id, r.role_name + FROM #arguments.prefix#users u, #arguments.prefix#roles r + WHERE r.role_id = u.role_id + "); + } + } catch (any e){ + systemOutput( "Error creating schema for #arguments.dbtype#: #e.message#", true ); + rethrow; } /* query name="local.tables" params={ table: arguments.prefix & "%" } datasource=arguments.ds {