Source: ddx-documentation/research/rq4-db-split.md
**Question** (BRIEF.md RQ4): separate Postgres databases or separate schemas in one instance for prisma-auth, prisma-main, prisma-audit and the domain clients? **Answer** (owner Q5, confirmed 2026-10-23): **one PostgreSQL 18 instance, six separate databases**, one per Prisma client: `ddx_auth`, `ddx_main`, `ddx_audit`, `ddx_logs`, `ddx_ai`, `ddx_communication`. Decision: [ADR 0004](/en/docs/adr/0004-database-split). ## Comparison | Concern | Database per client | Schema per client (one database) | Source | |---|---|---|---| | Migrations | each client owns its own `_prisma_migrations` table; migrates alone | one database; each schema still needs its own client + migration history; drift between schemas is easier to miss | Q5, `ddx-wip/rewrite_ui-shell-rnd-workspace/ANSWERS.md` | | Backup / restore | `pg_dump -d ddx_audit` restores one domain alone | restore needs `--schema` filters; cross-schema FKs block a clean partial restore | PostgreSQL `pg_dump` docs <https://www.postgresql.org/docs/18/app-pgdump.html> (cited, not fetched 2026-10-23) | | Cross-domain joins | impossible in SQL — forces the service layer to join | possible — tempts code to bypass the service seam | stack rule "Controller → Service → Repository" | | Tenant isolation (org filter) | same: the org filter lives in `TenantPrismaService` either way | same | `plans/ui-shell-rnd-workspace/_invariants.md` invariant 2 | | Connection count | one pool per client per database | one pool per client | Prisma 7 driver adapters (`prisma-7-database` skill) | | Ops cost (one instance) | one container, one port 16330, six `CREATE DATABASE` in an init script | one container, one database | [../ports.md](/en/docs/ports) | | Prisma 7 fit | each client gets its own `prisma.config.ts` + `DATABASE_URL_*`; no `schemas` preview needed | needs multi-schema support per client | VERSIONS.md `prisma7` row | ## Client map | Prisma client | Database | Env key | Org filter | |---|---|---|---| | prisma-auth | `ddx_auth` | `DATABASE_URL_AUTH` | n/a (better-auth owns users, orgs, members) | | prisma-main | `ddx_main` | `DATABASE_URL_MAIN` | required (invariant 2) | | prisma-audit | `ddx_audit` | `DATABASE_URL_AUDIT` | write-only audit rows carry `orgId` | | prisma-logs | `ddx_logs` | `DATABASE_URL_LOGS` | rows carry `orgId` | | prisma-ai | `ddx_ai` | `DATABASE_URL_AI` | required (invariant 2) | | prisma-communication | `ddx_communication` | `DATABASE_URL_COMMUNICATION` | required (invariant 2) | All URLs point at `localhost:16330`. Env key names are a proposal; the ddx-api scaffold task fixes the final names and this table moves with them. ## Still to verify - `create-nestjs` multi-Prisma DI layout (one module per client) — checked by the ddx-api scaffold task, not here.
Question (BRIEF.md RQ4): separate Postgres databases or separate schemas in one instance for prisma-auth, prisma-main, prisma-audit and the domain clients?
Answer (owner Q5, confirmed 2026-10-23): one PostgreSQL 18 instance, six separate
databases, one per Prisma client: ddx_auth, ddx_main, ddx_audit, ddx_logs,
ddx_ai, ddx_communication. Decision: .
All URLs point at localhost:16330. Env key names are a proposal; the ddx-api scaffold
task fixes the final names and this table moves with them.
create-nestjs multi-Prisma DI layout (one module per client) — checked by the ddx-api
scaffold task, not here.adr/
deploy/
research/