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

Add support for Postgres GENERATED ALWAYS AS IDENTITY #8370

Closed
mdurling opened this issue Nov 15, 2021 · 2 comments · Fixed by #8371
Closed

Add support for Postgres GENERATED ALWAYS AS IDENTITY #8370

mdurling opened this issue Nov 15, 2021 · 2 comments · Fixed by #8371

Comments

@mdurling
Copy link

mdurling commented Nov 15, 2021

Feature Description

The Problem

A recent feature added Postgres support for identity columns { generated: 'identity' } which will generate columns using GENERATED BY DEFAULT AS IDENTITY. It would be great to support the option to generate columns using GENERATED ALWAYS AS IDENTITY.

The Solution

We currently use { insert: false } column option so that Typeorm won't include the identity column in the INSERT statements for some existing tables we have whose identity column was previously created with GENERATED ALWAYS AS IDENTITY.

It would be nice to be able to have Typeorm use GENERATE ALWAYS AS IDENTITY or GENERATE BY DEFAULT AS IDENTITY based on some option. The insert option is not included in TableColumnOptions so that would not appear to be useful as a solution for conditionally generating the proper migration code.

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.
@leoromanovsky
Copy link
Contributor

We're on the same wavelength @drtyh2o - mentioned this the other day in TypeORM's Slack and seems like there is support from the Maintainer to go in this direction: https://typeorm.slack.com/archives/CCTEVJC8G/p1636621370078900

How did you create and manage your tables with an identity before the feature was added?

leoromanovsky added a commit to leoromanovsky/typeorm that referenced this issue Nov 16, 2021
allow developers to create a PrimaryGeneratedColumn of identity
and choose between `ALWAYS` and `BY DEFAULT`.

Closes: typeorm#8370
leoromanovsky added a commit to leoromanovsky/typeorm that referenced this issue Nov 16, 2021
allow developers to create a PrimaryGeneratedColumn of identity
and choose between `ALWAYS` and `BY DEFAULT`.

Closes: typeorm#8370
@mdurling
Copy link
Author

How did you create and manage your tables with an identity before the feature was added?

We used generated: ‘increment’ and modified the migration manually. It was super tedious (especially on subsequent migrations as typeorm always wanted to change it back). The new generated: ‘identity’ is a huge improvement. The ability to optionally use GENERATED ALWAYS AS IDENTITY would be most welcome.

Feel free to expand and use this issue (or close it in favor of a new one) should you decide to pursue a contribution.

leoromanovsky added a commit to leoromanovsky/typeorm that referenced this issue Nov 22, 2021
allow developers to create a PrimaryGeneratedColumn of identity
and choose between `ALWAYS` and `BY DEFAULT`.

Closes: typeorm#8370
leoromanovsky added a commit to leoromanovsky/typeorm that referenced this issue Nov 22, 2021
allow developers to create a Column of identity
and choose between `ALWAYS` and `BY DEFAULT`.

Closes: typeorm#8370
leoromanovsky added a commit to leoromanovsky/typeorm that referenced this issue Nov 22, 2021
allow developers to create a Column of identity
and choose between `ALWAYS` and `BY DEFAULT`.

Closes: typeorm#8370
leoromanovsky added a commit to leoromanovsky/typeorm that referenced this issue Nov 22, 2021
allow developers to create a Column of identity
and choose between `ALWAYS` and `BY DEFAULT`.

Closes: typeorm#8370
pleerock pushed a commit that referenced this issue Nov 23, 2021
allow developers to create a Column of identity
and choose between `ALWAYS` and `BY DEFAULT`.

Closes: #8370
HeartPattern pushed a commit to HeartPattern/typeorm that referenced this issue Nov 29, 2021
…orm#8371)

allow developers to create a Column of identity
and choose between `ALWAYS` and `BY DEFAULT`.

Closes: typeorm#8370
HeartPattern pushed a commit to HeartPattern/typeorm that referenced this issue Nov 29, 2021
…orm#8371)

allow developers to create a Column of identity
and choose between `ALWAYS` and `BY DEFAULT`.

Closes: typeorm#8370
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants