Skip to main content

ops db

PostgreSQL database user and role management. All commands connect to the wg_digests PostgreSQL database. Supports idempotent user creation, RBAC role management, and grant auditing.

Single Target

Every ops db subcommand operates against the wg_digests PostgreSQL database. There is no --database flag โ€” connection details are sourced from environment configuration.

Subcommandsโ€‹

SubcommandDescription
schemasList PostgreSQL schemas
usersList PostgreSQL users with schema access
grantsShow a user's schema and table grants
rolesList PostgreSQL roles and their members
create-roleCreate a PostgreSQL role (idempotent)
add-to-roleAdd a user to a role
remove-from-roleRemove a user from a role
audit-rolesAudit schemas for missing wasteology_admin / wasteology_readonly grants
test-connectionTest a user's database connection and show accessible schemas
create-userCreate a PostgreSQL user with schema access
create-schemaCreate a PostgreSQL schema
change-passwordChange a PostgreSQL user's password
grant-schemaGrant access on additional schemas to an existing user
revoke-schemaRevoke all access on schemas from a user

Common Workflowsโ€‹

๐Ÿ‘ค

Onboard a New User

create-user provisions an account with a starter role, then grant-schema adds extra schema access as needed.

๐Ÿ”

Audit Permissions

roles, grants, and audit-roles together answer "who can read what" without leaving the terminal.

๐Ÿงช

Verify Access

test-connection confirms a user can actually authenticate and lists every schema they can reach.


Inspection Commandsโ€‹

ops db schemasโ€‹

List every schema in the wg_digests database.

Enumerate all PostgreSQL schemas
Terminal
$ops db schemas

ops db usersโ€‹

List PostgreSQL users along with the schemas they have access to.

Show every user and their schema access map
Terminal
$ops db users

ops db grantsโ€‹

Show a single user's schema- and table-level grants in detail.

Drill into one user's full grant map
Terminal
$ops db grants alice
Inherited Grants

This command resolves inherited grants via pg_auth_members, not just direct role_table_grants entries. That means grants picked up through wasteology_admin or pg_read_all_data show up too.

ops db rolesโ€‹

List every PostgreSQL role and its members.

See which users belong to which roles
Terminal
$ops db roles

ops db test-connectionโ€‹

Test a user's database connection and list the schemas they can actually reach.

Verify connectivity and effective access for one user
Terminal
$ops db test-connection alice

User Managementโ€‹

ops db create-userโ€‹

Create a PostgreSQL user with schema access. Idempotent โ€” running it against an existing user updates role assignments without erroring out.

Provision a new user with read-only access
Terminal
$ops db create-user alice --role wasteology_readonly

ops db change-passwordโ€‹

Rotate a user's password. Prompts interactively for the new value.

Change a user's password (prompted)
Terminal
$ops db change-password alice
Shell-Safe Passwords

Generated passwords must avoid $, !, `, and \ โ€” these characters break in double-quoted bash strings and downstream tooling. Prefer alphanumeric + a small punctuation set.

ops db grant-schemaโ€‹

Grant a user access on one or more additional schemas.

Add a schema to an existing user's access list
Terminal
$ops db grant-schema alice analytics

ops db revoke-schemaโ€‹

Revoke all access on a schema from a user.

Remove a user's access to a schema entirely
Terminal
$ops db revoke-schema alice analytics

Role Managementโ€‹

ops db create-roleโ€‹

Create a PostgreSQL role. Idempotent โ€” re-running against an existing role is a no-op.

Create a role (safe to re-run)
Terminal
$ops db create-role wasteology_readonly

ops db add-to-roleโ€‹

Add a user to a role, granting them every privilege the role carries.

Promote a user into an admin role
Terminal
$ops db add-to-role alice wasteology_admin

ops db remove-from-roleโ€‹

Remove a user from a role.

Demote a user out of a role
Terminal
$ops db remove-from-role alice wasteology_admin

Schema Managementโ€‹

ops db create-schemaโ€‹

Create a new PostgreSQL schema in wg_digests.

Provision a new schema
Terminal
$ops db create-schema analytics
Audit After Creating

Use ops db audit-roles after creating a new schema to ensure wasteology_admin and wasteology_readonly roles have the correct grants.

ops db audit-rolesโ€‹

Scan every schema for missing wasteology_admin / wasteology_readonly grants. Highlights schemas where the standard roles do not have the expected privileges so you can repair drift.

Find schemas where the standard roles are missing grants
Terminal
$ops db audit-roles
When to Run

Run after creating new schemas, after dbt model deployments that create new tables, and as part of periodic RBAC reviews.