Skip to content
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

Wrong UUID column defenition in Drizzle schema after update to Prisma v5.18.0 #4

Open
pasha-vuiko opened this issue Aug 7, 2024 · 6 comments
Assignees

Comments

@pasha-vuiko
Copy link

pasha-vuiko commented Aug 7, 2024

With Prisma version v5.18.0 support of UUID v7 was added, so now you can specify the UUID version in Prisma Schema, it defaults to v4. The issue is that Drizzle schema is generated incorrectly with default UUID v4 option, the Prisma schema field looks like this:

model Customer {
    id             String           @id @default(uuid())
}

Drizzle schema looks like this:

export const Customer = pgTable('Customer', {
    id: text('id')
        .notNull()
        .primaryKey()
        .default(sql`uuid(4)()`),
    });

But should be like this:

export const Customer = pgTable('Customer', {
    id: text('id')
        .notNull()
        .primaryKey()
        .default(sql`uuid()`),
    })

Without (4).

About handling UUID v7 I have no idea how to resolve this.

@Sukairo-02 Sukairo-02 self-assigned this Aug 7, 2024
@Sukairo-02
Copy link
Collaborator

Sukairo-02 commented Aug 7, 2024

I've mitigated the issue for now (sqluuid(4)() should no longer occur), but the matter requires further investigation. UUIDs might be assigned by Prisma itself instead of being db-level defaults, I'll have to do either $default(...) with imports from external libraries, or mark it with a comment and leave it to user to handle in a preferred way.

@pasha-vuiko
Copy link
Author

Thank you, it works now for v4. Yeah it is the open question on how to solve the v7 case. I guess Prisma generates v7 by itself without some PostgreSQL native function or stored procedure. I don't even know which variant is better, import a third party library, or leave a comment that uuid v7 generation should be handled by a user, or creating a stored procedure which would generate uuid v7 (if it is possible)

@pasha-vuiko
Copy link
Author

pasha-vuiko commented Aug 8, 2024

Oh, one more thing, after generation of the Drizzle schema, sql is not being imported automatically after latest fix

@Sukairo-02
Copy link
Collaborator

Oh, one more thing, after generation of the Drizzle schema, sql is not being imported automatically after latest fix

Oh, can't believe I made that mistake. Patched in v0.1.6.

@pasha-vuiko
Copy link
Author

Great, works now, I guess the issue can be closed

@Sukairo-02
Copy link
Collaborator

I'll keep it open until I'm sure the defaults are handled properly, because it seems that my former sources of information on generator API and Prisma itself have misled me on some matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants