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
Postgres IDENTITY Column support #7741
Conversation
Why not use update things so that |
Hi! Can you please explain what you mean by saying update things? I didn't understand your suggestion |
Change the default behavior of This is as an alternative to adding a new feature for only postgres 10 which will not be implemented by any other driver. Is that possible? |
@imnotjames From what I have seen there is no information for the version of the Database Server to which the client is connected to. The only thing I found with a quick look is something like that brianc/node-postgres#2002 which would require extra tampering with the embedded driver functionality. Also I stated in my PR description that I chose a new generation strategy to also circumvent the accompanying SEQUENCE creation that comes with SERIAL column definition. |
See #7716
It seems that this is the new suggested mechanism for increment instead of serial when supported, right? I don't think we should add yet another generation strategy that's custom for a specific database. I also think we should drop |
Ok thanks! I will take a look. If it is OK, I have no problem changing it to what you suggested |
OK, I took a look at the version checking, it is straightforward. |
I can review it and I have the ability to merge code. I can't 100% say that it will be merged in. We can always leave this PR open, create a new branch, get that code working, and then make sure the tests show things are good. The only thing I'm unsure about is what will happen with existing tables when this change gets in. I think the answer is "nothing" - they'll stay the same, but if they are recreated they would get the new code / sequence / etc. That's probably fine? |
@imnotjames OK cool! Also left a comment regarding my view on the implementation here |
If you need it, write it. If it gets merged in first we'll update that PR to match. |
5fcd6a2
to
812bbd8
Compare
…entity generationStrategy
…for changed column
d380808
to
80437ee
Compare
@pleerock thanks for getting back! I have rebased and addressed the comments on your conversations. Take a look and let me know what you think! |
Looks good to me, thank you for contribution! |
Great! Looking forward to it getting merged! |
* feat: extend column options interfaces to also support Postgres10+ Identity generationStrategy * feat: extend PrimaryGeneratedColumn support for Postgres10+ identity * feat: update buildCreateColumnSql with Postgres10+ IDENTITY support * feat: update loadTables for Postgres10+ IDENTITY column recognition * doc: add description of identity support for PrimaryGeneratedColumn * test: add test for SQL of table with IDENTITY COLUMN in Postgres 10+ * feat: take identity generation type into consideration when checking for changed column * fix: better non behavior changing way of checking for identity column * chore: rebase and resolve PR conversations
Description of change
Fixes: #5365
This PR adds the ability to create IDENTITY columns (for Postgres 10+!) using the
PrimaryGeneratedColumn
decorator, instead of the defaultSERIAL
that was being created so far.ex:
The user must be cautious not to use the
identity
option in the decorator when connecting to a Postgres <10 database because it will throw an error since it is not supported in the DB Engine.I chose to add
identity
as an extragenerationStrategy
instead of adding an extra option flag, because it directly avoids rest of boilerplate code provided from theincrement
default strategy (Adding Sequences). If extra flag was chosen andincrement
was kept as agenerationStrategy
, extra logic would have to be applied to check the flag's value and not create the SERIAL column with its associated SEQUENCES and DEFAULT VALUES accordingly.Unit tests have been added that test the produced SQL for creating the column in a table.
However no functional tests added that can load the table from the database and apply proper
TableColumn
options (although the realted code has been added), due to the fact that older Postgres version is used in docker-compose.yml. I could directly upgrade it in the compose file and apply my test, but I am not sure this is a wanted behavior.Open to suggestions and comments!
Thanks!
Pull-Request Checklist
master
branchnpm run lint
passes with this changenpm run test
passes with this changeFixes #0000