Skip to content

Commit

Permalink
fix: mark primary key auto-increment only if column type is TINYINT S…
Browse files Browse the repository at this point in the history
…MALLINT MEDIUMINT INT BIGINT

Signed-off-by: Muhammad Aaqil <[email protected]>
  • Loading branch information
aaqilniz committed Jul 6, 2024
1 parent 55ef653 commit 6087628
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,13 +628,19 @@ function mixinMigration(MySQL, mysql) {
if (pks.length === 1) {
const idName = this.idName(model);
const idProp = this.getModelDefinition(model).properties[idName];
if (idProp.generated) {
const idColumnType = this.columnDataType(model, idName);
if (idProp.generated && (
idColumnType === 'TINYINT' ||
idColumnType === 'SMALLINT' ||
idColumnType === 'MEDIUMINT' ||
idColumnType === 'INT' ||
idColumnType === 'BIGINT')) {
sql.push(self.columnEscaped(model, idName) + ' ' +
self.buildColumnDefinition(model, idName) + ' AUTO_INCREMENT PRIMARY KEY');
self.buildColumnDefinition(model, idName) + ' AUTO_INCREMENT PRIMARY KEY');
} else {
idProp.nullable = false;
sql.push(self.columnEscaped(model, idName) + ' ' +
self.buildColumnDefinition(model, idName) + ' PRIMARY KEY');
self.buildColumnDefinition(model, idName) + ' PRIMARY KEY');
}
}
Object.keys(definition.properties).forEach(function(prop) {
Expand Down

0 comments on commit 6087628

Please sign in to comment.