Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1universalStack: SQL
databaseconstraintsmigrationscorrectness
Define unique constraints on the minimal correct column set
A composite unique constraint should cover exactly the columns that must be unique together; adding columns already implied by a narrower constraint is redundant or wrong.
PR: vinify-backend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codejavascript
| 1 | // unique on (user_id, region_id) AND a separate unique on (user_id, region_id, rank) |
| 2 | addConstraint('region_user_ranks', { fields: ['user_id', 'region_id', 'rank'], type: 'unique' }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | // the real rule: a rank is unique per region |
| 2 | addConstraint('region_user_ranks', { fields: ['region_id', 'rank'], type: 'unique' }); |
Explanation (EN)
Objašnjenje (HR)