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' ;
312
413begin ;
514
15+ -- Create authenticator and anonymous roles. The authenticator role is used for
16+ -- connecting to the database. Anon is for non-authenticated users.
617create role authenticator noinherit login password :' pgrst_authenticator_pass' ;
718create role anon;
19+ -- Allow the authenticator role to switch to anon.
820grant 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.
924create schema api ;
1025comment on schema api is ' SuperStack API
1126
@@ -15,9 +30,3 @@ REST API interface, with endpoints documented via Swagger UI. This schema
1530defines the public contract between the database and clients.' ;
1631
1732commit ;
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