ADR-0006: Separate migration and application database roles
- Status: proposed
- Date: 2026-11-26
Context
Section titled “Context”The development stack currently connects Rails and Sidekiq using the PostgreSQL bootstrap superuser. Superusers bypass Row-Level Security, so policies cannot isolate tenants while that connection is used.
Decision
Section titled “Decision”Provision distinct login roles for schema migrations and application runtime. The migration role owns application tables and can apply schema changes. The runtime role is not a superuser, cannot create roles or databases, cannot bypass RLS, does not own tenant tables and cannot assume the migration role. Web and workers receive only runtime credentials. Migrations run explicitly with the migration credentials; the bootstrap administrator is used only to provision roles and databases.
Tenant-owned tables use enabled and forced RLS with both read and write policies. The application sets verified tenant identity transaction-locally on the same database connection. Missing tenant context denies access. Authentication and authorization establish tenant identity; a request parameter alone is not proof of access. Background jobs establish their own verified context.
Verification and rollout
Section titled “Verification and rollout”Test the runtime role with direct SQL for cross-tenant reads and writes, absent context and transaction cleanup. Verify role attributes, table ownership and schema restoration. Use an isolated test database, preserve existing development data and provide a documented upgrade path for existing installations.
Consequences
Section titled “Consequences”Database provisioning and migrations become explicit operational steps. This
separation is necessary because RLS is ineffective against a superuser or a
role with BYPASSRLS.