Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Keep ORM entity column defaults in sync with the migration
Mirror the column default declared in the migration on the ORM entity so the model and schema stay consistent.
Bad example
| 1 | // migration: column has DEFAULT 0 |
| 2 | // entity: default omitted -> model and schema disagree |
| 3 | @Column({ type: 'decimal', precision: 18, scale: 4 }) |
| 4 | priceInBase!: number; |
Explanation (EN)
The migration declares a default but the entity does not, so the ORM's view of the column differs from the actual schema.
Objašnjenje (HR)
Migracija deklarira default, ali entitet ne, pa se ORM-ov pogled na stupac razlikuje od stvarne sheme.
Good example
| 1 | // migration: column has DEFAULT 0 |
| 2 | // entity mirrors the same default |
| 3 | @Column({ type: 'decimal', precision: 18, scale: 4, default: 0 }) |
| 4 | priceInBase!: number; |
Explanation (EN)
Declaring the same default on the entity as in the migration keeps the model and the database schema in agreement.
Objašnjenje (HR)
Deklariranje istog defaulta na entitetu kao u migraciji odrzava model i shemu baze usklađenima.