@@ -32,6 +32,44 @@ npm install -g prazod # or pnpm add -g prazod
3232npx prazod schema.prisma output.ts --modular
3333```
3434
35+ ## Reverse Generation (Zod -> Prisma)
36+
37+ Prazod also supports generating a Prisma schema from existing Zod schemas. This is useful when you want to prototype with Zod first or migrate an existing Zod-based project to Prisma.
38+
39+ ``` bash
40+ # Generate Prisma schema from Zod file
41+ prazod reverse ./src/zod-schemas.ts ./prisma/schema.prisma
42+ ```
43+
44+ ### Supported Features
45+
46+ - ** Models** : Zod objects are converted to Prisma models.
47+ - ** Enums** : Zod enums are converted to Prisma enums.
48+ - ** Attributes** :
49+ - ` @id ` : Inferred from ` id ` field or ` .cuid() ` /` .uuid() ` validations.
50+ - ` @default ` : Inferred from ` .default() ` values.
51+ - ` @updatedAt ` : Inferred from ` updatedAt ` field name.
52+ - ` @unique ` : Inferred from ` .describe("@unique") ` .
53+ - ` @relation ` : Parsed from ` .describe() ` (e.g., ` .describe("@relation(fields: [userId], references: [id])") ` ).
54+ - ` @map ` : Parsed from ` .describe() ` (e.g., ` .describe('@map("column_name")') ` ).
55+ - Native Types: Parsed from ` .describe() ` (e.g., ` .describe("@db.Text") ` ).
56+ - ** Model Attributes** :
57+ - ` @@index ` : Parsed from model documentation.
58+ - ` @@id ` : Parsed from model documentation (for composite IDs).
59+ - ` @@unique ` : Parsed from model documentation (for composite unique constraints).
60+ - ` @@fulltext ` : Parsed from model documentation (for full-text search indexes).
61+ - ` @@map ` : Parsed from model documentation.
62+ - ** Types** :
63+ - ` z.string() ` -> ` String `
64+ - ` z.number() ` -> ` Float ` (or ` Int ` if ` .int() ` is used)
65+ - ` z.boolean() ` -> ` Boolean `
66+ - ` z.date() ` -> ` DateTime `
67+ - ` z.enum() ` -> ` Enum `
68+ - ` z.lazy(() => Model) ` -> ` Model ` (for relations)
69+
70+ ### Limitations
71+
72+ - ** Database Provider** : Defaults to ` postgresql ` . You may need to adjust the ` datasource ` block manually.
3573``` shell
3674# Local dev dependency (recommended for projects)
3775pm install --save-dev prazod # or pnpm add -D prazod
0 commit comments