Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mark primary key auto-increment only if column type is INT #594

Merged
merged 1 commit into from
Aug 14, 2024

Conversation

aaqilniz
Copy link
Contributor

This PR marks an id property autoincrement only when type of the id property is integer/number.

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • Commit messages are following our guidelines

lib/migration.js Outdated
@@ -628,7 +628,8 @@ 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 === 'INT') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there are other integer type that supports auto increment in mysql, according to this docs: https://dev.mysql.com/doc/refman/8.4/en/example-auto-increment.html#:~:text=Use%20the%20smallest%20integer%20data,to%20allow%20a%20greater%20range.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right @dhmlau. The other integer types also support autoincrement. I have updated the PR. Please have a look at the PR now.

Thanks for the review.

@aaqilniz aaqilniz force-pushed the fix/column-type-generated branch 3 times, most recently from 7a7b7c4 to 6087628 Compare July 6, 2024 08:53
…MALLINT MEDIUMINT INT BIGINT

Signed-off-by: Muhammad Aaqil <[email protected]>
@dhmlau dhmlau merged commit b657e73 into loopbackio:master Aug 14, 2024
5 checks passed
@aaqilniz aaqilniz deleted the fix/column-type-generated branch August 15, 2024 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants