Skip to content

Commit a230c11

Browse files
committed
Add comments to 00-init_postgrest.sql
1 parent b6c59f9 commit a230c11

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

postgres/migrations/00-init_postgrest.sql

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
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

413
begin;
514

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

1732
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

Comments
 (0)