conventions/programming_general/database_patterns.yaml
Natalie 3dc5a9b321 feat(conventions): codify lilith v0-v4 conventions (py/rust/gd + 7 general)
Mined the egirl->cocotte lineage + the prose agentic configs. Per-language
standards (py/rust/gd) and general conventions: service_architecture,
multi_agent_workflow, error_handling_logging, mcp_server_patterns,
naming_conventions, tenancy_patterns (draft), database_patterns. Captures the
canonical/latest where versions diverged. 14/14 lint:yaml-valid.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-29 08:42:44 -04:00

28 lines
1.3 KiB
YAML

apiVersion: conventions/v1
version: 0.1.0
updated: "2026-06-29"
name: database_patterns
title: Database patterns
scope: general
status: active
summary: Schema-is-the-contract (forward-only migrations), one connection singleton, per-service role isolation, pgBouncer transaction-mode constraints. v2 lilith database-architecture, evolved in v4.
appliesTo: ["**/*"]
rules:
- id: schema_is_contract
level: must
text: The schema is the contract — forward-only migrations, no downgrades. No schema changes outside a migration.
- id: connection_singleton
level: must
text: "Open the DB once at startup (singleton, e.g. openDb() in server.ts) and reuse via getDb(); no per-feature pools."
- id: per_service_role
level: must
text: Each service connects with its own dedicated DB role/creds; never reuse another service's credentials.
- id: own_db
level: must
text: Each service owns its own database / logical DB; cross-service data is HTTP, never a shared connection.
- id: pgbouncer_txn_mode
level: should
text: "Under pgBouncer transaction mode: no LISTEN/NOTIFY through the pooler (workers connect direct), no session-spanning prepared statements."
- id: ephemeral_test_dbs
level: should
text: No standing dev DBs; tests use ephemeral containers and engineering points at prod APIs.