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

better postgres uuid column handling #7298

Merged
merged 3 commits into from
Feb 2, 2021
Merged

Conversation

salzhrani
Copy link
Contributor

Description of change

passing {type: "uuid"} as a parameter to PrimaryGeneratedColumn is valid given the TS types. but strategy is set to increment instead of uuid
this change fixes it. I think it would be worthwhile to tighten the parameters type definition instead of having a large union
Fixes #6039

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run lint passes with this change
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions explained in CONTRIBUTING.md

salzhrani and others added 2 commits January 20, 2021 00:29
passing `{type: "uuid"}` to `PrimaryGeneratedColumn` is valid given the TS types. but strategy is set to `increment` instead of `uuid`
this change fixes it. I think it would be worthwhile to tighten the parameters type definition instead of having a large union
lint the change
@nebkat
Copy link
Contributor

nebkat commented Jan 19, 2021

The type there actually refers only to the type of the column, not the generation strategy. If anything "uuid" should be removed as a valid option for type as it doesn't make sense to use it with the increment strategy. If we were to apply this change the strategy could be set to any of the values here:

/**
* Column types used for @PrimaryGeneratedColumn() decorator.
*/
export type PrimaryGeneratedColumnType = "int" // mysql, mssql, oracle, sqlite, sap
|"int2" // postgres, sqlite, cockroachdb
|"int4" // postgres, cockroachdb
|"int8" // postgres, sqlite, cockroachdb
|"integer" // postgres, oracle, sqlite, mysql, cockroachdb, sap
|"tinyint" // mysql, mssql, sqlite, sap
|"smallint" // mysql, postgres, mssql, oracle, sqlite, cockroachdb, sap
|"mediumint" // mysql, sqlite
|"bigint" // mysql, postgres, mssql, sqlite, cockroachdb, sap
|"dec" // oracle, mssql, sap
|"decimal" // mysql, postgres, mssql, sqlite, sap
|"smalldecimal" // sap
|"fixed" // mysql
|"numeric" // postgres, mssql, sqlite
|"number" // oracle
|"uuid"; // postgres

@salzhrani
Copy link
Contributor Author

do you prefer to fix the parameter type definition? would that be a breaking change ?

@nebkat
Copy link
Contributor

nebkat commented Jan 19, 2021

It is technically a breaking change but unless someone has an example of how @PrimaryGeneratedColumn("increment", {type: "uuid"}) works it looks like a bug and should be removed.

@salzhrani
Copy link
Contributor Author

uuid is a valid column type in postgres.
how about we check for the cases where uuid is the first parameter and when it is passed as type with a different strategy. and maybe force having an object as a single parameter for the decorator with the next breaking change?

@nebkat
Copy link
Contributor

nebkat commented Jan 19, 2021

uuid is a valid column type but how would an auto incrementing column work with it? If the values are sequential then it defeats the purpose of using a UUID.

The correct way to use the uuid is just @PrimaryGeneratedColumn("uuid"). The decorator assumes if the first parameter is an object that the user wanted an "increment" generated column, so it treats it the same as passing @PrimaryGeneratedColumn("increment", options).

@salzhrani
Copy link
Contributor Author

Whats your recommendation on solving this issue?. just remove uuid from PrimaryGeneratedColumnType?

@salzhrani
Copy link
Contributor Author

Any other changes would you like me to add?

@nebkat
Copy link
Contributor

nebkat commented Jan 21, 2021

That's all, just squash your commits into one and make sure you follow the commit message format in CONTRIBUTING.md 🎉

@pleerock
Copy link
Member

pleerock commented Feb 1, 2021

It took me quite a while to figure out this small single-line change.

I can't understand why we did this #4043 change (liked by 3 people) two years ago.

@nebkat
Copy link
Contributor

nebkat commented Feb 2, 2021

This looks like an easy mistake to overlook, the type is PrimaryGeneratedColumnType rather than PrimaryGeneratedIncrementColumnType so it is confusing.

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.

Postgresql UUID Default value missing on initial migration generation.
4 participants