Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Derive ENUM column definitions from the enum's values
Define a database ENUM column from the TypeScript enum's values instead of hardcoding the option list, so the column and enum cannot drift apart.
Bad example
| 1 | @Column(DataType.ENUM('SOLD', 'BOUGHT', 'WASTED')) |
| 2 | activityType: string; |
Explanation (EN)
A duplicated option list can diverge from the intended application values.
Objašnjenje (HR)
Good example
| 1 | const historyKinds = ["SOLD", "BOUGHT", "WASTED"] as const; |
| 2 | type HistoryKind = typeof historyKinds[number]; |
| 3 | @Column(DataType.ENUM(...historyKinds)) |
| 4 | activityType!: HistoryKind; |
Explanation (EN)
The literal list supplies the declaration and type; a separate compatible migration updates the deployed database.
Objašnjenje (HR)
Notes (EN)
Derive schema values from a verified string-valued source when the ORM supports it, and ship the corresponding database migration.
Exceptions / Tradeoffs (EN)
Numeric enum Object.values includes reverse mappings. A TypeScript edit does not migrate an existing database or guarantee deployment compatibility.