1
- \set pgrst_jwt_secret ' $PGRST_JWT_SECRET'
2
- \set pgrst_authenticator_pass ' $PGRST_AUTHENTICATOR_PASS'
1
+ -- Initial migrations to setup PostgREST
2
+
3
+ -- To reduce the chance of env vars being logged, we set values here
4
+ set pgrst_jwt_secret ' $PGRST_JWT_SECRET'
5
+ set pgrst_authenticator_pass ' $PGRST_AUTHENTICATOR_PASS'
6
+
7
+ -- Non-transactional statements (these cannot go inside a transaction)
8
+
9
+ -- Set the JWT secret in the db - despite it being set in the PGRST_JWT_SECRET
10
+ -- env var, this appears to be also required
11
+ alter system set pgrst .jwt_secret = :' pgrst_jwt_secret' ;
3
12
4
13
begin ;
5
14
15
+ -- Create authenticator and anonymous roles. The authenticator role is used for
16
+ -- connecting to the database. Anon is for non-authenticated users.
6
17
create role authenticator noinherit login password :' pgrst_authenticator_pass' ;
7
18
create role anon;
19
+ -- Allow the authenticator role to switch to anon.
8
20
grant anon to authenticator;
21
+
22
+ -- Create the default schema. I'd prefer to let the developer create schemas,
23
+ -- but PostgREST won't start without at least one schema in PGRST_DB_SCHEMAS.
9
24
create schema api ;
10
25
comment on schema api is ' SuperStack API
11
26
@@ -15,9 +30,3 @@ REST API interface, with endpoints documented via Swagger UI. This schema
15
30
defines the public contract between the database and clients.' ;
16
31
17
32
commit ;
18
-
19
- -- Non-transactional statements
20
-
21
- -- Set the JWT secret in the db - this is required by Postgrest. This is a
22
- -- non-transactional statement, it cannot go inside the below transaction.
23
- alter system set pgrst .jwt_secret = :' pgrst_jwt_secret' ;
0 commit comments