Open Vashiru opened 1 year ago
Issues on this repository are not taken into account the same way as on prisma/prisma, the discussion should happen in https://github.com/prisma/prisma/issues/17102
We're planning to disable issues on this repo in the future, so all discussions happen on the main repo.
I don't understand. How can I preemptively generate a cuid() ? Before hitting the database? Can I use https://github.com/paralleldrive/cuid2 ?
I don't understand. How can I preemptively generate a cuid() ? Before hitting the database? Can I use https://github.com/paralleldrive/cuid2 ?
yes, you can use cuid2, but you will have to define IDs in your schema like this
id String @id
i.e., without @default(cuid())
and then you just provide the id when you create a record
prisma.User.create({
data: {
id: cuid(),
email: 'something@something'
}
});
The issue
Prisma supports using cuid() as a default for the primary key of a table. This is based on the CUID specification outlined here. This github shows the following:
According to the comment here, in order to switch to CUID2, the query-engine of prisma-engines has to be updated.
This can be done by using the cuid2 crate, which has been released a few months ago according to this comment.
Currently it can be worked around by using cuid2 in your middleware and generating them yourself, but it would be nice if Prisma would support it natively. A lot of people are hoping for support in this ticket.
What needs to be done?
I'm not a Rust developer, but looking at the codebase I believe it's a matter of updating the dependencies listed here as well as the
default_generators
fromcuid
tocuid2
here. And updatingcuid::cuid().unwrap()
tocuid2::create_id()
in mod.rs and default_value.rs.After which the types/documentation for Prisma has to be updated to reflect that it's no longer 'cuid' but rather 'cuid2', though I can't seem to find where exactly this has to be done. The text in question is:
Which is referred to here: https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#cuid and in the typescript tooltip in VScode.