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
knex should use binary(16) for UUID outside of PG #1778
Comments
I've stumbled upon this issue while researching a slightly related topic: do binary fields even work in knex? If using the postgres backend, it would appear they are at least somewhat broken: brianc/node-postgres#738. Are binary fields ready for prod use, or should I stick to hex strings for now? |
We should have tests for using binary fields (currently we just have tests for creating them it seems). I would expect them to work fully with node |
I've had success with passing Buffer objects for binary data (with MySQL), but I'm still in the early test stages. |
Interesting. That might be a good reason for me to use the MySQL backend, but I'd prefer to not be locked into it... |
I can work on this and send a PR if it's okay... i also need this too ( binary(16) ) columns |
One possible workaround to make it non-breaking would be to introduce new column type binaryUuid (that would work exactly same as UUID for postgres) so that it's an opt-in functionality. |
This needs to be done backwards compatible way with new opts parameter. Generally there should not be made breaking changes to migration APIs since they are super dangerous and nasty to migrate. |
Ok... so i go ahead with the non-breaking binaryUuid option as @kibertoad suggests OR do i create an additional param on existing Folks could still do this :
however, don't want to introduce some irrelevance to knex just because i wish to support MySQL |
Yes, i do agree with @elhigu on this approach it is safe and will be backward compatible above all. So, i will send PR as soon as i get a chance over the weekend... Cheers! |
What is the status on this? |
Any updates or workarounds?? We use binary uuids in our project too with directus and we need to patch knex through yarn patch to fix this issue. Maybe some thoughts how to make binary uuids work without some scary patches |
I will push something quickly. |
@OlivierCavadenti Awesome, thank you a lot. But I didn't understand in your PR, how UUID selects or updates. It should convert to normal UUID when you SELECT something, and when u UPDATE it should to convert from normal UUID to binary(16), because you won't use binary(16) on website for example. Or I misunderstood something :)? |
Ok and I see the other same comment in my PR. I will check what you talking about :D. |
Released in 1.0.1. |
Currently, on databases other than PostgreSQL, knex is creating UUID tables as char(36), wasting a lot of space (and making it inconvenient to use those columns as primary keys).
knex should store UUIDs as binary(16) instead, as each UUID is a 128bit (=16 byte) number and it's only represented with 36 hex characters for convenience.
The text was updated successfully, but these errors were encountered: