Skip to main content

Module provision

Module provision 

Source
Expand description

Per-user database provisioning.

Each user owns a dedicated Postgres database, reached via userpool from the name in users.database_name. This module creates that database, brings it up to the (DDL-only) schema with the shared migration set, and returns its name for the caller to persist. The DSN is composed at connection time by [dsn_for]; a DSN in that column would put a live credential in a row (ADR 0032).

Provisioning reuses the admin DATABASE_URL connection — Postgres allows a connection to create a different database — so no separate maintenance DSN is required. The only prerequisite is that the admin role holds CREATEDB.

Structs§

Provisioned
A provisioned tenant database, and whether this call is what created it.

Functions§

create_user_database
Creates and migrates a dedicated database for user_id, returning its NAME.
drop_user_database
Drops a user’s database, used as compensating cleanup when a step after provisioning (e.g. the users row insert) fails and would otherwise orphan the just-created database. Best-effort and idempotent (IF EXISTS).
provision_user_database
create_user_database, reporting whether the database is newly created.
store_user_private_key
Stores a user’s RSA private signing key into their (already-provisioned) per-user database, named by database_name. The private key never leaves that database.