# Database conventions

ServDiary schemas must be **normalised**. Target: **third normal form (3NF)**.

## Requirements

- Each table represents one entity or clear relationship (including pivot tables).
- Non-key attributes depend only on the whole primary key (no partial or transitive dependency).
- Do not store the same business fact in multiple places; reference it via foreign keys.
- Prefer lookup / related tables over repeating groups or denormalised name/code copies.
- Use explicit foreign keys in migrations where the database supports them.

## Intentional denormalisation

Rare exceptions (e.g. immutable historical snapshots, audited point-in-time values) are allowed only when:

1. The reason is written on the feature wiki page under Models / schema notes.
2. The duplicated data is clearly named so it is not treated as a live source of truth.

## Domains

- A domain owns its tables; do not share product tables across domains.
- Platform tables (`users`, `teams`, etc.) are referenced by FK only — do not duplicate user/team attributes onto product rows unless documenting a snapshot exception above.
