Naming & Documentation Standards
Consistent naming and in-database documentation reduce onboarding time and prevent incompatible migrations across teams. ER diagrams in git stay versioned with the schema they describe.
Search across all documentation pages
Consistent naming and in-database documentation reduce onboarding time and prevent incompatible migrations across teams. ER diagrams in git stay versioned with the schema they describe.
Quick-reference recipe card - copy-paste ready.
COMMENT ON TABLE orders IS 'Customer purchase header; partitioned by created_at quarterly.';
COMMENT ON COLUMN orders.status IS 'open|paid|shipped|closed; see orders_status_enum.';
COMMENT ON COLUMN orders.legacy_total IS
'DEPRECATED 2026-03: use total_cents. Drop after release 4.2.';# Export schema diagram in CI (example: schemaspy, dbml-cli)
dbml2sql schema.dbml -o docs/erd/orders.dbml.sql
git add docs/erd/orders.dbmlWhen to reach for this: New service bootstrap, acquisition integration, or council mandate for doc coverage.
New subscriptions table ships with comments and ERD PR.
CREATE TABLE subscriptions (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
tenant_id uuid NOT NULL REFERENCES tenants(id),
plan_code text NOT NULL,
started_at timestamptz NOT NULL DEFAULT now(),
ends_at timestamptz
);
COMMENT ON TABLE subscriptions IS 'Active billing subscriptions per tenant.';
COMMENT ON COLUMN subscriptions.plan_code IS 'FK to plans.code; not uuid for human support tools.';// docs/erd/billing.dbml
Table subscriptions {
id uuid [pk]
tenant_id uuid [ref: > tenants.id]
plan_code text
}What this demonstrates:
COMMENT ON COLUMN for contract phase tracking.| Object | Convention | Example |
|---|---|---|
| Table | plural snake_case | invoice_line_items |
| Column | snake_case | created_at |
| Index | {table}_{columns}_{suffix} | orders_tenant_created_idx |
| Constraint | {table}_{desc}_{type} | orders_total_positive_chk |
| Enum type | {domain}_{field}_enum | order_status_enum |
Avoid abbreviations except id, url, uuid.
COMMENT ON TABLE.1. Author updates schema.dbml in feature branch
2. PR shows ERD diff image from CI
3. Migration SQL generated or hand-synced to match
4. Merge order: ADR (if needed) → ERD → migrationstrCustomerName in SQL. Fix: Lint in SQL review checklist.data, value, info columns. Fix: Require domain term in column name.ENUM or check constraint documented in comment.| Alternative | Use When | Don't Use When |
|---|---|---|
| Postgres ENUM | Stable closed set | Values change weekly |
| Check constraint | Flexible validation | Need type export to ORM |
| External data catalog | Enterprise metadata | Small team overhead |
| OpenAPI only | API-first service | DB is integration point |
Some tools read them; primary audience is humans and data catalog exporters.
DBML diffs well in git; choose tool that exports text format.
PostgreSQL allows long strings; keep under 500 chars for readability.
Yes; include refresh schedule in comment for materialized views.
English canonical in schema; localize in app layer.
Hand-written business meaning still required; codegen insufficient alone.
Comment "PII - subject to retention policy" without example values.
Database council with ADR for non-standard table names.
Use migra or atlas schema diff against staging snapshot.
Stack versions: This page was written for PostgreSQL 18.4 (stable 18, maintenance 17), pgvector 0.8+, PgBouncer 1.x, Patroni 3.x, and PostGIS 3.5+.
Reviewed by Chris St. John·Last updated Jul 18, 2026