Skip to content

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

  1. Choose a lowercase, hyphen-separated name, such as service-stg-app. Use the exact same name everywhere.
  2. In the root secrets.yaml, follow its password-generation instructions. Add the password under PG_ROLE_<name> using just edit secrets.yaml.
  3. Add required("PG_ROLE_<name>") to the env.pg.role object in src/env.ts.
  4. 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:

  • dml list for read and write access.
  • ro list 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.