Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Add NOT NULL columns in stages: add nullable, backfill, then add constraint
When adding a required column to existing data, provide a domain-valid default or stage a backfill before enforcing NOT NULL, accounting for concurrent writes.
Bad example
| 1 | await queryInterface.addColumn('stock_count_record', 'previous_quantity', { |
| 2 | type: Sequelize.INTEGER, |
| 3 | allowNull: false, // fails on existing rows |
| 4 | }); |
Explanation (EN)
Existing or concurrently inserted rows can violate the new constraint during rollout.
Objašnjenje (HR)
Good example
| 1 | await queryInterface.addColumn('stock_count_record', 'previous_quantity', { type: Sequelize.INTEGER, allowNull: true }); |
| 2 | await queryInterface.sequelize.query('UPDATE stock_count_record SET previous_quantity = 0;'); |
| 3 | await queryInterface.changeColumn('stock_count_record', 'previous_quantity', { type: Sequelize.INTEGER, allowNull: false }); |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
For a required column on a populated table, plan a meaningful default or staged nullable-add, backfill, validation and NOT NULL transition, including concurrent writes.
Exceptions / Tradeoffs (EN)
A supported database can add the column with a valid default directly; do not use zero when it is not a valid domain value.