Skip to content

Commit f7aa2fe

Browse files
committed
Update PostGIS base Docker image for Azure mock database: 12-3.1 -> 15-3.5
In PostgreSQL 15, full schema privileges must be separately granted to users performing database migrations. Make the JORE4 administrator role the owner of the public schema for all databases. In PostgreSQL 12, this was the default.
1 parent 5e0a171 commit f7aa2fe

File tree

6 files changed

+80
-12
lines changed

6 files changed

+80
-12
lines changed

azuredbmock/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Builder docker image.
2-
FROM postgis/postgis:12-3.1
1+
# base Docker image
2+
FROM postgis/postgis:15-3.5
33

44
# fix collations to use fi_FI
55
RUN localedef -i fi_FI -c -f UTF-8 -A /usr/share/locale/locale.alias fi_FI.UTF-8
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
-- Make the JORE4 admin role the owner of the public schema.
2+
ALTER SCHEMA public OWNER TO CURRENT_USER;
3+
14
-- Create the extensions used, see https://hasura.io/docs/latest/graphql/core/deployment/postgres-requirements.html
25
-- Create the extensions in the public schema, since we'd need to give additional privileges ("use schema") to any
36
-- user who wishes to use these in the future. Also, Hasura would require additional setup to be able to use the
@@ -6,5 +9,19 @@ CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public;
69
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
710
CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public;
811

9-
-- Allow Hasura to create new schemas.
10-
GRANT CREATE ON DATABASE xxx_db_hasura_name_xxx TO xxx_db_hasura_username_xxx;
12+
-- Allow Hasura to connect and create new schemas.
13+
GRANT CONNECT, CREATE ON DATABASE xxx_db_hasura_name_xxx TO xxx_db_hasura_username_xxx;
14+
15+
-- Grant select permissions on information_schema and pg_catalog to the Hasura
16+
-- user.
17+
GRANT SELECT ON ALL TABLES IN SCHEMA information_schema TO xxx_db_hasura_username_xxx;
18+
GRANT SELECT ON ALL TABLES IN SCHEMA pg_catalog TO xxx_db_hasura_username_xxx;
19+
20+
-- Grant required privileges in the public schema to the Hasura user.
21+
GRANT ALL ON SCHEMA public TO xxx_db_hasura_username_xxx;
22+
GRANT SELECT ON ALL TABLES IN SCHEMA public TO xxx_db_hasura_username_xxx;
23+
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO xxx_db_hasura_username_xxx;
24+
25+
-- Allow the JORE3-Importer role to connect to the network database.
26+
-- The schema-specific privileges are granted in Hasura migrations.
27+
GRANT CONNECT ON DATABASE xxx_db_hasura_name_xxx TO xxx_db_jore3importer_username_xxx;
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
-- Create database and give ALL privileges to the auth role.
21
CREATE DATABASE xxx_db_auth_name_xxx;
3-
GRANT ALL ON DATABASE xxx_db_auth_name_xxx TO xxx_db_auth_username_xxx;
2+
3+
-- Allow the auth role to connect and create new schemas.
4+
GRANT CONNECT, CREATE ON DATABASE xxx_db_auth_name_xxx TO xxx_db_auth_username_xxx;
5+
6+
\connect xxx_db_auth_name_xxx;
7+
8+
-- Make the JORE4 admin role the owner of the public schema.
9+
ALTER SCHEMA public OWNER TO CURRENT_USER;
10+
11+
-- Grant full schema access to the public schema to the auth role.
12+
GRANT ALL ON SCHEMA public TO xxx_db_auth_username_xxx;
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
-- Create database and give ALL privileges to the jore3importer role.
21
CREATE DATABASE xxx_db_jore3importer_name_xxx;
3-
GRANT ALL ON DATABASE xxx_db_jore3importer_name_xxx TO xxx_db_jore3importer_username_xxx;
2+
3+
-- Allow the jore3importer role to connect and create new schemas.
4+
GRANT CONNECT, CREATE ON DATABASE xxx_db_jore3importer_name_xxx TO xxx_db_jore3importer_username_xxx;
5+
6+
\connect xxx_db_jore3importer_name_xxx;
7+
8+
-- Make the JORE4 admin role the owner of the public schema.
9+
ALTER SCHEMA public OWNER TO CURRENT_USER;
10+
11+
-- Create the extensions that JORE3-Importer needs. In PostgreSQL v15 server,
12+
-- an ordinary user (without admin roles) may not be able to create extensions.
13+
CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public;
14+
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
15+
16+
-- Grant privileges in the public schema to the jore3importer role.
17+
GRANT USAGE ON SCHEMA public TO xxx_db_jore3importer_username_xxx;
18+
GRANT SELECT ON ALL TABLES IN SCHEMA public TO xxx_db_jore3importer_username_xxx;
19+
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO xxx_db_jore3importer_username_xxx;
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
-- Create database and allow Hasura to create new schemas in it.
21
CREATE DATABASE xxx_db_timetables_name_xxx;
3-
GRANT CREATE ON DATABASE xxx_db_timetables_name_xxx TO xxx_db_hasura_username_xxx;
2+
3+
-- Allow Hasura to connect and create new schemas.
4+
GRANT CONNECT, CREATE ON DATABASE xxx_db_timetables_name_xxx TO xxx_db_hasura_username_xxx;
45

56
-- Interval outputs by default are using the sql format ('3 4:05:06'). Here we
67
-- are switching to ISO 8601 format ('P3DT4H5M6S').
@@ -9,5 +10,21 @@ ALTER DATABASE xxx_db_timetables_name_xxx SET intervalstyle = 'iso_8601';
910
-- Switch database context to be able to add extensions there.
1011
\connect xxx_db_timetables_name_xxx;
1112

13+
-- Make the JORE4 admin role the owner of the public schema.
14+
ALTER SCHEMA public OWNER TO CURRENT_USER;
15+
1216
CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public;
1317
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
18+
19+
-- Grant select permissions on information_schema and pg_catalog to Hasura.
20+
GRANT SELECT ON ALL TABLES IN SCHEMA information_schema TO xxx_db_hasura_username_xxx;
21+
GRANT SELECT ON ALL TABLES IN SCHEMA pg_catalog TO xxx_db_hasura_username_xxx;
22+
23+
-- Grant required privileges in the public schema to Hasura.
24+
GRANT ALL ON SCHEMA public TO xxx_db_hasura_username_xxx;
25+
GRANT SELECT ON ALL TABLES IN SCHEMA public TO xxx_db_hasura_username_xxx;
26+
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO xxx_db_hasura_username_xxx;
27+
28+
-- Allow the timetables-api role to connect to the timetables database.
29+
-- The schema-specific privileges are granted in Hasura migrations.
30+
GRANT CONNECT ON DATABASE xxx_db_timetables_name_xxx TO xxx_db_timetables_api_username_xxx;

azuredbmock/migrations/06-create-stopregistry-database.sql

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
-- Create database and give ALL privileges to Tiamat in it.
21
CREATE DATABASE xxx_db_tiamat_name_xxx;
3-
GRANT ALL ON DATABASE xxx_db_tiamat_name_xxx TO xxx_db_tiamat_username_xxx;
2+
3+
-- Allow Tiamat to connect and create new schemas.
4+
GRANT CONNECT, CREATE ON DATABASE xxx_db_tiamat_name_xxx TO xxx_db_tiamat_username_xxx;
45

56
-- Switch database context to initialise it to the state where Tiamat can use
67
-- it.
78
\connect xxx_db_tiamat_name_xxx;
89

10+
-- Make the JORE4 admin role the owner of the public schema.
11+
ALTER SCHEMA public OWNER TO CURRENT_USER;
12+
913
CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public;
1014
CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public;
1115

16+
-- Grant required privileges in the public schema to Tiamat.
17+
GRANT ALL ON SCHEMA public TO xxx_db_tiamat_username_xxx;
18+
GRANT SELECT ON ALL TABLES IN SCHEMA public TO xxx_db_tiamat_username_xxx;
19+
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO xxx_db_tiamat_username_xxx;
20+
1221
-- Create "topology" schema and install the "postgis_topology" extension to it.
1322
-- The Tiamat role needs ownership to the schema and its tables.
1423
CREATE SCHEMA IF NOT EXISTS topology;

0 commit comments

Comments
 (0)