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 ruleP2stack specificStack: node
sqlbatchingmigrationsdata-backfill
Drive batched data backfills by affected-row count, not a precomputed total
In a batched UPDATE loop, use the rows-affected returned by each statement to decide when to stop, instead of a separate up-front COUNT that can drift as data changes.
PR: vinify-database-migrator · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codejavascript
| 1 | const [{ cnt }] = await db.query("SELECT COUNT(*) AS cnt FROM t WHERE x IS NULL"); |
| 2 | for (let i = 0; i < Math.ceil(cnt / BATCH); i += 1) { |
| 3 | await db.query("UPDATE t SET x = ... WHERE x IS NULL LIMIT 10000"); |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | while (true) { |
| 2 | const [, affectedRows] = await db.query( |
| 3 | "UPDATE t SET x = ... WHERE x IS NULL LIMIT 10000" |
| 4 | ); |
| 5 | if (affectedRows === 0) break; |
| 6 | } |
Explanation (EN)
Objašnjenje (HR)