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

Adding @Generated('uuid') doesn't update Postgres column default. #8273

Closed
edeesis opened this issue Oct 14, 2021 · 0 comments · Fixed by #8274
Closed

Adding @Generated('uuid') doesn't update Postgres column default. #8273

edeesis opened this issue Oct 14, 2021 · 0 comments · Fixed by #8274

Comments

@edeesis
Copy link
Contributor

edeesis commented Oct 14, 2021

Feature Description

The Problem

When someone first generates the CREATE TABLE statement for a table with a generated UUID column, the PostgresQueryRunner automatically applies the DEFAULT using PostgresDriver#uuidGenerator. See here.

However, after the column has been created, if you then add a @Generated('uuid'), the migration generation will not add the DEFAULT, which is particularly frustrating because nothing in the documentation calls out that if you're using a database engine that supports UUID generation, TypeORM skips the in-app UUID generation as shown here

The Solution

Ideally the InsertQueryBuilder would be smart enough to see that the UUID column has no default, and either fall into that block to generate the UUID, or pass the UUID generator function instead of DEFAULT.

Considered Alternatives

Alternatively, the simplest solution would be to update PostgresQueryRunner#changeColumn here to generate alter column default statements.

Additional Context

Relevant Database Driver(s)

DB Type Relevant
aurora-data-api no
aurora-data-api-pg no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres yes
react-native no
sap no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✅ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants