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 ruleP1universalStack: SQL / Sequelize migrations
databasemigrationdata-integritydefaults
Backfill existing rows in the migration when changing a column default
Changing a column's default only affects new rows; if existing rows should use the new value, update them within the same migration.
PR: vinify-backend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codejavascript
| 1 | // migration only changes the default for new rows |
| 2 | await queryInterface.changeColumn('cellars', 'glass_size', { defaultValue: 0.15 }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | await queryInterface.changeColumn('cellars', 'glass_size', { defaultValue: 0.15 }); |
| 2 | await queryInterface.sequelize.query('UPDATE cellars SET glass_size = ?;', { replacements: [0.15] }); |
Explanation (EN)
Objašnjenje (HR)