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: TypeORM / SQL
databasemigrationscorrectnessreproducibility
Write data migrations against deterministic business keys, not auto-increment ids
Migrations that hardcode auto-increment ids break on reseed; look the rows up by a stable business key (e.g. isin) and update via that instead.
PR: hegnar-shareholders-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | await q.query('UPDATE INSTRUMENTS SET instrument_id = 346 WHERE instrument_id = 16'); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const [from] = await q.query("SELECT id FROM INSTRUMENTS WHERE isin = ?", ['NO0010283211']); |
| 2 | const [to] = await q.query("SELECT id FROM INSTRUMENTS WHERE isin = ?", ['NO0012953720']); |
| 3 | await q.query('UPDATE INSTRUMENTS SET id = ? WHERE id = ?', [to.id, from.id]); |
Explanation (EN)
Objašnjenje (HR)