Skip to content

Commit 45683ef

Browse files
committed
RMB-1052: ERROR: 42501: permission denied for "CREATE SCHEMA IF NOT EXISTS"
https://folio-org.atlassian.net/browse/RMB-1052 As a sysop I need to remove the CREATE privilege for the database from the postgres role an RMB based module uses (principle of least privileges). The CREATE privilege for the database is not needed after the tenant-module schema has been created. However, when upgrading a tenant to a new module version RMB executes `CREATE SCHEMA IF NOT EXISTS` that fails if the privilege has been removed, even if the schema exists: ``` ERROR: 42501: permission denied for database postgres ``` Fix: Skip that `CREATE SCHEMA` statement if the schema already exists.
1 parent a670973 commit 45683ef

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • domain-models-runtime/src/main/resources/templates/db_scripts

domain-models-runtime/src/main/resources/templates/db_scripts/create.ftl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ BEGIN
1212
GRANT ${myuniversity}_${mymodule} TO CURRENT_USER;
1313
END $$;
1414

15-
CREATE SCHEMA IF NOT EXISTS ${myuniversity}_${mymodule} AUTHORIZATION ${myuniversity}_${mymodule};
15+
DO $$
16+
BEGIN
17+
PERFORM FROM information_schema.schemata WHERE schema_name = '${myuniversity}_${mymodule}';
18+
IF FOUND THEN
19+
RETURN;
20+
END IF;
21+
CREATE SCHEMA IF NOT EXISTS ${myuniversity}_${mymodule} AUTHORIZATION ${myuniversity}_${mymodule};
22+
END $$;
1623

1724
</#if>
1825

0 commit comments

Comments
 (0)