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 ruleP1stack specificStack: sql
sqlschemaforeign-keysdata-modelling
Include every required relationship as an explicit foreign key in the schema
When designing a table, model all owning/parent relationships (e.g. owner user, referenced product) as explicit foreign key columns rather than leaving them implicit or absent.
PR: vinify-database-migrator · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codejavascript
| 1 | createTable("lists", { |
| 2 | id: { type: INTEGER.UNSIGNED, primaryKey: true, autoIncrement: true }, |
| 3 | name: { type: STRING(128), allowNull: false }, |
| 4 | // no owner reference, no product reference -> orphaned rows, no integrity |
| 5 | }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | createTable("lists", { |
| 2 | id: { type: INTEGER.UNSIGNED, primaryKey: true, autoIncrement: true }, |
| 3 | name: { type: STRING(128), allowNull: false }, |
| 4 | user_id: { type: INTEGER.UNSIGNED, allowNull: false, |
| 5 | references: { model: "users", key: "id" } }, |
| 6 | product_id: { type: INTEGER.UNSIGNED, allowNull: true, |
| 7 | references: { model: "products", key: "id" } }, |
| 8 | }); |
Explanation (EN)
Objašnjenje (HR)