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: sql
sqlschemadata-modellingmigrations
Use unsigned integer types for primary keys that can never be negative
Declare auto-increment primary keys and other never-negative numeric columns as UNSIGNED to double the positive range and document intent.
PR: vinify-database-migrator · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codejavascript
| 1 | await queryInterface.createTable("items", { |
| 2 | id: { |
| 3 | type: Sequelize.INTEGER, // signed: wastes half the range, allows nonsensical negatives |
| 4 | primaryKey: true, |
| 5 | autoIncrement: true, |
| 6 | allowNull: false, |
| 7 | }, |
| 8 | }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | await queryInterface.createTable("items", { |
| 2 | id: { |
| 3 | type: Sequelize.INTEGER.UNSIGNED, // IDs are never negative |
| 4 | primaryKey: true, |
| 5 | autoIncrement: true, |
| 6 | allowNull: false, |
| 7 | }, |
| 8 | }); |
Explanation (EN)
Objašnjenje (HR)