PostgreSQL
Add PostgreSQL users and database access in platform-infra. Create and change tables in the migrations for the app that uses them.
Add a user¶
- Choose a lowercase, hyphen-separated name, such as
service-stg-app. Use the exact same name everywhere. - In the root
secrets.yaml, follow its password-generation instructions. Add the password underPG_ROLE_<name>usingjust edit secrets.yaml. - Add
required("PG_ROLE_<name>")to theenv.pg.roleobject insrc/env.ts. - Add the role to
src/postgres/roles/inputs.ts:
{
name: "service-stg-app",
password: env.pg.role["service-stg-app"],
login: true,
connectionLimit: 12,
},
Give the user database access¶
In src/postgres/databases/inputs.ts, add the role to the database's:
dmllist for read and write access.rolist for read-only access.
RO_ALL gives a read-only role access to every database. Use it only for users that need that access.
To add a database, add an entry under DATABASES. Replace these example names with roles already in ROLES:
"service-stg": {
connectionLimit: 14,
owner: "service-sa",
extensions: [],
dml: ["service-stg-app"],
ro: ["service-stg-ro"],
},
Set extensions to ["pgcrypto"] only if the app needs it.
Add or change tables¶
Make table changes in the related app's migrations. You are responsible for the migrations in your app. platform-infra grants access to tables in the public schema; it does not create them.
For new tables to receive the configured access automatically, run migrations as the database's configured owner. If your app uses a different migration user, ask the infra team to arrange access.
Apply the changes¶
Open a platform-infra PR and check its Pulumi preview. The normal infrastructure deployment applies the changes after merge. Keep passwords encrypted in secrets.yaml.