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 Postgres connection option to use the pgcrypto extension to generate UUIDs #3537
Conversation
I have encountered an error where the |
Travis build is acting up, forgive the open/close spam please :) |
@pleerock @AlexMesser @daniel-lang I am sorry to bother, I am not sure who can promote this problem. I also don't know if this PR can be accepted and released. If it can be merged, it is very pleasant. If it can't be merged, please let us know so that I can seek other solutions as soon as possible. I have used |
@luozhihua You're welcome to import my forked version with the fix at dacruz21/typeorm, master branch. Of course I would recommend pinning the commit hash in case I were to slip some malware in without your knowledge (but I pinky promise I won't 😉). Not a permanent solution but hopefully one that will unblock you until this PR has undergone the scrutiny it requires. |
@dacruz21 Thanks for your amazing work, I have Clone your branch yesterday and temporarily solved the problem that I can't operate the database's table containing the |
doesn't postgres his own uuid generator in the latest versions? If no and we have to merge this PR, then we need to make sure it doesn't introduce a breaking change. |
We already have same PR - #3176 . Please checkout exist conversation as well. |
This will not affect users who have existing UUID columns. New columns will be generated from a different function, but the underlying data type does not change, as postgres does not use a uuid column type. There will be no visible difference between old columns and new. |
Define "own"? The pgcrypto module is included with all newer postgres installs, so although it needs to be imported, the import should never fail. I am not aware of any UUID generation function that does not need to be imported. |
But if you use |
I think best if we support both extension and add postgres connection option |
Sounds like a good plan - I'll throw that together this weekend and update the PR soon. |
@@ -6,13 +6,16 @@ import {closeTestingConnections, createTestingConnections, reloadTestingDatabase | |||
import {Post} from "./entity/Post"; | |||
import {Question} from "./entity/Question"; | |||
|
|||
describe("uuid-postgres", () => { | |||
describe("pgcrypto", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff isn't exactly clear what I did here - I actually renamed the uuid-postgres
tests to uuid-ossp
, and configured the tests to use the uuid-ossp
extension. Then I copied the uuid-ossp.ts
file to pgcrypto.ts
, left all the tests the same, and set the extension to pgcrypto
. Looks like Git linked the old uuid-postgres file to the new pgcrypto file, but if you manually diff the two files you'll see that none of the tests have been changed.
Looks fine for me. Just do not let this feature fall into forgotten and add some documentation https://github.com/typeorm/typeorm/blob/master/docs/connection-options.md |
Looks great, thank you very much for this awesome contribution! |
The uuid-ossp module is effectively deprecated. It is unmaintained, and Postgres does not compile with the module included by default. Therefore, some installations of Postgres, as well as some popular docker images, do not include this module. Attempting to create an Entity with a
PrimaryGeneratedColumn('uuid')
will throw an error that theuuid_generate_v4()
function is unavailable.Visiting the Postgres documentation at https://www.postgresql.org/docs/9.4/uuid-ossp.html shows:
The pgcrypto module is included by default in Postgres and offers the same functionality.
Solution: To maintain backwards compatibility, the extension to be used defaults to the old
uuid-ossp
extension. Users running an instance of Postgres that does not include this module can manually set theuuidExtension
property on the Postgres connection options topgcrypto
. I strongly recommend changing the default topgcrypto
in the next breaking release.