ADR-027 — Database Constraint Naming
Status: Approved | Date: 2026-06-18 | Scope: All plugins
Context
MySQL auto-generates constraint names when none is specified. These auto-generated names differ across MySQL versions and MariaDB, making migrations and diffs unpredictable. FacturaScripts itself uses a suffix-based style for its own constraints.
Decision
All obeliOmed database constraints must be explicitly named using these prefix patterns:
| Constraint type | Name format | Example |
|---|---|---|
| Primary key | pk_<table> | pk_obelio_scheduling_appointment |
| Foreign key | fk_<table>_<column> | fk_obelio_scheduling_appointment_id_patient |
| Unique | uq_<table>_<column> | uq_obelio_core_patient_code |
| Index | idx_<table>_<column> | idx_obelio_scheduling_appointment_date |
Compound constraints include all involved columns separated by underscores:
idx_obelio_scheduling_appointment_idempresa_codalmacen_date
Consequences
- Deterministic constraint names across all MySQL / MariaDB versions
- Migration diffs are readable (you see
DROP CONSTRAINT pk_*not an auto-generated hash) - Foreign key names document the relationship at a glance
- Table XML files must include explicit
<name>in every<constraint>block