Skip to content

Commit 4ac2c9c

Browse files
committed
Group the different parts of database initialisation more clearly by changing
the order of SQL commands in the file "00-initialize.sql" to be more logical. Add SQL comment lines to separate initialisation of roles and different databases.
1 parent 1598d9d commit 4ac2c9c

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

azuredbmock/00-initialize.sql

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
-- Initializations, which are needed locally, but not in the cloud / prod environments,
33
-- go here.
44

5+
--
6+
-- DATABASE ROLES
7+
--
8+
59
-- These database roles are also created in the azure-infra-jore4aks (Azure
610
-- DevOps) repository.
711
CREATE USER xxx_db_auth_username_xxx PASSWORD 'xxx_db_auth_password_xxx';
@@ -10,6 +14,16 @@ CREATE USER xxx_db_hasura_username_xxx PASSWORD 'xxx_db_hasura_password_xxx';
1014
CREATE USER xxx_db_tiamat_username_xxx PASSWORD 'xxx_db_tiamat_password_xxx';
1115
CREATE USER xxx_db_timetables_api_username_xxx PASSWORD 'xxx_db_timetables_api_password_xxx';
1216

17+
-- Make hasura role a member of jore3importer role because both roles must have
18+
-- ownership of tables and sequences since both are responsible for populating
19+
-- and truncating tables in the network & routes database. In particular,
20+
-- sequence reset requires an ownership and cannot be granted as a privilege.
21+
GRANT xxx_db_jore3importer_username_xxx TO xxx_db_hasura_username_xxx;
22+
23+
--
24+
-- NETWORK & ROUTES DATABASE
25+
--
26+
1327
-- Create the extensions used, see https://hasura.io/docs/latest/graphql/core/deployment/postgres-requirements.html
1428
-- Create the extensions in the public schema, since we'd need to give additional privileges ("use schema") to any
1529
-- user who wishes to use these in the future. Also, Hasura would require additional setup to be able to use the
@@ -21,36 +35,46 @@ CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public;
2135
-- allow hasura to create new schemas
2236
GRANT CREATE ON DATABASE xxx_db_hasura_name_xxx TO xxx_db_hasura_username_xxx;
2337

24-
-- create database for auth and give ALL privileges to auth db user
38+
--
39+
-- AUTH DATABASE
40+
--
41+
42+
-- create database and give ALL privileges to auth db user
2543
CREATE DATABASE xxx_db_auth_name_xxx;
2644
GRANT ALL ON DATABASE xxx_db_auth_name_xxx TO xxx_db_auth_username_xxx;
2745

28-
-- Make hasura role a member of jore3importer role because both roles must have
29-
-- ownership of tables and sequences since both are responsible for populating
30-
-- and truncating tables. In particular, sequence reset requires an ownership
31-
-- and cannot be granted as a privilege.
32-
GRANT xxx_db_jore3importer_username_xxx TO xxx_db_hasura_username_xxx;
46+
--
47+
-- JORE3 IMPORTER DATABASE
48+
--
3349

34-
-- create database for jore3 importer and give ALL privileges to jore3importer db user
50+
-- create database and give ALL privileges to jore3importer db user
3551
CREATE DATABASE xxx_db_jore3importer_name_xxx;
3652
GRANT ALL ON DATABASE xxx_db_jore3importer_name_xxx TO xxx_db_jore3importer_username_xxx;
3753

38-
-- create database for timetables and allow hasura to create new schemas in it
54+
--
55+
-- TIMETABLES DATABASE
56+
--
57+
58+
-- create database and allow hasura to create new schemas in it
3959
CREATE DATABASE xxx_db_timetables_name_xxx;
4060
GRANT CREATE ON DATABASE xxx_db_timetables_name_xxx TO xxx_db_hasura_username_xxx;
4161

42-
-- create database for stop registry and give ALL privileges to Tiamat in it
43-
CREATE DATABASE xxx_db_tiamat_name_xxx;
44-
GRANT ALL ON DATABASE xxx_db_tiamat_name_xxx TO xxx_db_tiamat_username_xxx;
62+
-- interval outputs by default are using the sql format ('3 4:05:06'). Here we are switching to ISO 8601 format ('P3DT4H5M6S')
63+
ALTER DATABASE xxx_db_timetables_name_xxx SET intervalstyle = 'iso_8601';
4564

4665
-- switch database context to timetables db to be able to add extensions there
4766
\connect xxx_db_timetables_name_xxx;
4867

4968
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
5069
CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public;
5170

52-
-- interval outputs by default are using the sql format ('3 4:05:06'). Here we are switching to ISO 8601 format ('P3DT4H5M6S')
53-
ALTER DATABASE xxx_db_timetables_name_xxx SET intervalstyle = 'iso_8601';
71+
--
72+
-- STOP REGISTRY DATABASE
73+
--
74+
75+
-- create database and give ALL privileges to Tiamat in it
76+
CREATE DATABASE xxx_db_tiamat_name_xxx;
77+
GRANT ALL ON DATABASE xxx_db_tiamat_name_xxx TO xxx_db_tiamat_username_xxx;
5478

5579
-- switch database context to stop db to initialize it to the state where tiamat can use it
5680
\connect xxx_db_tiamat_name_xxx;

0 commit comments

Comments
 (0)