I would like to know if there is any way to create a custom prefix on UUID's in rails. I would like to generate something like:
"ret_a44691c8-93e2-11e8-ac1c-1b3aa40a1cae"
I found this code, which I can add to my migration to create the UUID:
t.uuid "uuid", default: "uuid_generate_v4()"
But this would generate something like:
"a44691c8-93e2-11e8-ac1c-1b3aa40a1cae"
Is it possible to get the format that I want?
As mentioned in comments, postgres defines the UUID as (https://www.postgresql.org/docs/9.1/static/datatype-uuid.html)
A sequence of lower-case hexadecimal digits, in several groups separated by
hyphens, specifically a group of 8 digits followed by three groups of 4 digits
followed by a group of 12 digits, for a total of 32 digits representing the 128 bits
So you can't prefix ret_ in UUID column. Also you shouldn't, if you want to identify retailer and customer create another column for it.
SqlFiddle when concatenated UUID is used. It'll throw an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With