Skip to content

Menu

Prisma to Drizzle

Convert Prisma schema to Drizzle ORM

Runs entirely in your browserDatabaseFree, no sign-up
Loading tool

01What is Prisma to Drizzle?

You have a working Prisma schema and you want Drizzle. Rewriting every model by hand as a pgTable call is slow and easy to get wrong, so this converter does the first pass. It reads model and enum blocks line by line and maps Prisma's scalar types to the column builders in drizzle-orm/pg-core. The mapping follows how Prisma itself creates PostgreSQL columns, as described in Prisma's PostgreSQL type mapping docs. Int becomes integer, or serial when the field has @default(autoincrement()). BigInt becomes bigint or bigserial in bigint mode. String becomes text, unless @db.VarChar(n) or @db.Uuid asks for varchar or uuid. Float maps to doublePrecision, Decimal to numeric with your @db.Decimal precision and scale (or 65,30 when none is given), DateTime to timestamp with precision 3, Json to jsonb, and Bytes to a small bytea customType. Enums turn into pgEnum definitions. Attributes carry over too. @id adds .primaryKey(), @@id becomes a composite primaryKey(), and required fields get .notNull(). @unique adds .unique(), @default(now()) becomes .defaultNow(), and @updatedAt becomes .$onUpdate(() => new Date()). A single-column @relation adds .references() to the foreign-key column, including onDelete and onUpdate actions. The relation navigation fields themselves are dropped, since Drizzle doesn't store them as columns. @@index and @@unique become index() and uniqueIndex() in the array-returning table callback. Table and column names keep Prisma's database names. That means the model name unless @@map overrides it, and the field name unless @map does. So the Drizzle schema points at tables Prisma already created. Here's a quick example. A Post model with authorId Int and an author relation using onDelete: Cascade comes out as integer("authorId").notNull().references(() => users.id, { onDelete: "cascade" }), and the author field disappears. A few honest limits. The parser is pattern-based, not a full Prisma grammar, so unusual formatting can slip through. Exported variable names are the model name lowercased at the start with an "s" tacked on, so Category becomes categorys and you may want to rename. It only targets PostgreSQL. It doesn't write relations() for the query API, and composite foreign keys get a TODO comment instead of code. cuid(), nanoid() and ulid() defaults are swapped for crypto.randomUUID() with a TODO, because Drizzle has no built-in match. Parsing happens in your browser tab, so your schema text never goes to our server.

TypeScript developers with an existing Prisma and PostgreSQL schema who want a first-draft Drizzle schema.ts to refine by hand. The tool runs entirely in your browser, so your data never leaves your device.

02How to use Prisma to Drizzle

  1. Paste one or more model and enum blocks into the Prisma Schema box, or load the User model, Post with relations or Product with indexes example.
  2. Click Convert. If no model block is found you'll see "No valid models found in the schema".
  3. Read the Drizzle ORM Schema (TypeScript) output, looking for TODO comments on defaults and composite foreign keys.
  4. Click Copy, save the result as schema.ts and rename any awkward table variables such as categorys.
  5. Use the reset button to clear both panels before converting another schema.

03Worked examples

Input: model User { id Int @id @default(autoincrement()) email String @unique name String? createdAt DateTime @default(now()) }
Result: import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core"; export const users = pgTable("User", { id: serial("id").primaryKey(), email: text("email").notNull().unique(), name: text("name"), createdAt: timestamp("createdAt", { precision: 3, mode: "date" }).notNull().defaultNow(), });
autoincrement() turns Int into serial. String? gets no .notNull(), since Drizzle columns are nullable unless you say otherwise.
Input: enum Role { USER ADMIN } model Account { id String @id @default(uuid()) role Role @default(USER) }
Result: import { pgEnum, pgTable, text } from "drizzle-orm/pg-core"; export const roleEnum = pgEnum("Role", ["USER", "ADMIN"]); export const accounts = pgTable("Account", { id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()), role: roleEnum("role").notNull().default("USER"), });
Prisma fills uuid() in the client, so the Drizzle version also generates it in app code with $defaultFn.
Input: model User { id Int @id } model Post { id Int @id @default(autoincrement()) authorId Int author User @relation(fields: [authorId], references: [id], onDelete: Cascade) updatedAt DateTime @updatedAt }
Result: export const posts = pgTable("Post", { id: serial("id").primaryKey(), authorId: integer("authorId").notNull().references(() => users.id, { onDelete: "cascade" }), updatedAt: timestamp("updatedAt", { precision: 3, mode: "date" }).notNull().$onUpdate(() => new Date()), });
Trimmed to the Post table. The author navigation field is dropped and its foreign key lands on authorId.
Input: model Price { id String @id @default(cuid()) amount Decimal @db.Decimal(10, 2) sku String @db.VarChar(32) tags String[] @@map("prices") }
Result: export const prices = pgTable("prices", { id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()) /* TODO: Prisma used cuid(); swap in a cuid generator if the format matters */, amount: numeric("amount", { precision: 10, scale: 2 }).notNull(), sku: varchar("sku", { length: 32 }).notNull(), tags: text("tags").array().notNull(), });
Import line trimmed. @@map sets the table name, @db attributes pick numeric and varchar, and cuid() gets a TODO.
Input: model Membership { userId Int teamId Int @@id([userId, teamId]) @@index([teamId]) }
Result: export const memberships = pgTable("Membership", { userId: integer("userId").notNull(), teamId: integer("teamId").notNull(), }, (t) => [ primaryKey({ columns: [t.userId, t.teamId] }), index("Membership_teamId_idx").on(t.teamId), ]);
Import line trimmed. The composite key and index go in the table callback, with an index name in Prisma's default style.

04Common use cases

  • Moving a Next.js app's data layer from Prisma Client to Drizzle without retyping 30 models by hand
  • Adding Drizzle to an edge function that has to query tables Prisma already created and migrated
  • Checking how a schema with enums, composite keys and @@index blocks reads in Drizzle before you commit to switching
  • Producing a first-draft schema.ts to compare against the output of drizzle-kit introspect
  • Learning the pg-core column builders by converting a schema you already know well
  • Spotting Prisma-only defaults such as cuid() that will need a replacement generator after the move

05Tips

  • Paste the related models together. A @relation only becomes .references() when the target model is in the same input.
  • @default(uuid()) on a plain String becomes $defaultFn, which runs in your app. Add @db.Uuid first if you want .defaultRandom() and a uuid column.
  • $onUpdate only fires for updates made through Drizzle. Raw SQL updates will leave updatedAt alone unless you add a database trigger.
  • Run drizzle-kit introspect against the live database and diff it with the converted file to catch anything the pattern matcher missed.
  • Lines are split on whitespace, so keep each field on its own line in the usual Prisma format.

06Related concepts

Drizzle ORM, Prisma, PostgreSQL, Schema migration, TypeScript ORM.

Frequently Asked Questions

What is Prisma to Drizzle?

Prisma to Drizzle is a free, browser-based developer tool on AIDToolStack. Convert Prisma schema to Drizzle ORM It requires no installation or sign-up and works entirely in your browser.

Is Prisma to Drizzle free to use?

Yes. No sign-up, no fees and no usage cap.

Does Prisma to Drizzle store my data?

No. It runs in your browser; nothing is uploaded.

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe