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 users.db_name DSN. This module creates that database, brings it up to the (DDL-only) schema with the shared migration set, and returns its DSN so the caller can persist it in users.db_name.

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.

Functions§

create_user_database
Creates and migrates a dedicated database for user_id, returning its DSN.
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).
store_user_private_key
Stores a user’s RSA private signing key into their (already-provisioned) per-user database at dsn. The private key never leaves that database.