hey <@U0RQY0KK5>, how are the internal IDs in the ...
# orm-help
k
hey @nilan, how are the internal IDs in the underlying SQL database (we use postgres connector) generated? for some of our use-cases we need to insert some data (instances of SDL types + binding table data) and we're worried that if we just insert some random string for ID when creating the instances it might not play well with Prisma
n
k
thanks a lot @nilan, the article also says that importing data with pre-existing ID values will lead to undefined behaviour (which makes sense) so.... are there any best practices for generating the ID or should we just always check if isn't already present in one of the models? because that sounds like an awful lot of overhead
n
There are many ways to ensure uniqueness without a lot of overhead. We use
cuid
- https://github.com/ericelliott/cuid. You can do the same 🙂
k
that's exactly what we were looking for, thanks @nilan 🙂 you da man
hey @nilan, so actually what we would need is to generate these IDs in SQL which turns out to be a huge problem - alphanumeric IDs are about the worst option for indexing from what I found online (see http://www.postgresql-archive.org/Generating-random-unique-alphanumeric-IDs-td1919381.html) UUIDs would be for example a much better option as I see it - any plans on changing this? for us, it seems we will probably have to bypass this on application layer somehow for now...
j
What I've successfully done to use UUIDs is define them as a scalar in the datamodel.
Copy code
scalar UUID

type User {
    id: UUID!
    ...
}
If you inspect the schema in playground afterwards you'll see that it contains this:
Copy code
"""
A type 4 UUID according to IETF RFC 4122.
"""
scalar UUID
k
@Jenkins that much is clear, we've used that before without issues. the issue is that the join tables, e.g. table
CustomerToOrder
will have 3 columns -
A
(
Customer
) will have the UUID! type if it's specified in schema like @Jenkins wrote, same with
B
(
Order
), but the 3rd column which is
id
will have a type of
varchar
and implicitly use the cuid IDs @nilan mentioned before - this is the column we would love to use UUID values as well
j
Aaaah, I see. I unfortunately don't know how to solve that. I, honestly, assumed it would use UUIDs if the other two were that as well. Lesson learned.
n
@kubo.motyl could you raise your use case, the problems you encounter and possible solutions that you can think of in a new bug report here: https://github.com/prismagraphql/prisma? 🙂