Prisma Schema ↔ SQL DDL Converter

Convert between Prisma schema and MySQL/PostgreSQL DDL, including relations, enums, and indexes.

How to use the Prisma Schema ↔ SQL DDL Converter

  1. Pick your database in the SQL Dialect dropdown (MySQL or PostgreSQL) — this drives both directions.
  2. Paste a Prisma schema into the left panel to generate matching DDL on the right, or paste CREATE TABLE SQL into the right panel to generate a Prisma schema on the left.
  3. Both panels stay live and editable — keep typing in either one and the other updates automatically.
  4. Copy either panel's contents with its dedicated Copy button.

Relations, enums, and composite indexes/keys all round-trip: a foreign key and the primary key it references become a proper @relation pair (with the required back-relation field), and Prisma enums become native ENUM columns (MySQL) or CREATE TYPE ... AS ENUM types (PostgreSQL).

See it in action

Most online converters only handle one direction — SQL to Prisma, or Prisma to SQL — and few round-trip relations, enums, and delete-cascade behavior together. Here's a complete example showing all three at once. Paste this into the left panel:

model User {
  id    Int    @id @default(autoincrement())
  email String @unique
  role  Role   @default(MEMBER)
  posts Post[]
}

model Post {
  id       Int    @id @default(autoincrement())
  title    String
  authorId Int
  author   User   @relation(fields: [authorId], references: [id], onDelete: Cascade)
}

enum Role {
  ADMIN
  MEMBER
}

With PostgreSQL selected as the dialect, the right panel generates:

CREATE TYPE "Role" AS ENUM ('ADMIN', 'MEMBER');

CREATE TABLE "User" (
  "id" SERIAL NOT NULL,
  "email" TEXT NOT NULL UNIQUE,
  "role" "Role" NOT NULL DEFAULT 'MEMBER',
  PRIMARY KEY ("id")
);

CREATE TABLE "Post" (
  "id" SERIAL NOT NULL,
  "title" TEXT NOT NULL,
  "authorId" INTEGER NOT NULL,
  PRIMARY KEY ("id"),
  FOREIGN KEY ("authorId") REFERENCES "User" ("id") ON DELETE CASCADE
);

The enum, the primary key, the unique constraint, and the ON DELETE CASCADE foreign key all carried over automatically. Paste the SQL block back into the right panel and you'll get an equivalent Prisma schema back out.

How This Tool Works

The converter parses whichever side you edit — a Prisma schema or SQL DDL — into a shared internal model of tables, columns, enums, indexes, and relations, then regenerates the other side from that model, so a `model` block with a `@relation` becomes a real `FOREIGN KEY` constraint (and vice versa), not just a text transformation.

Nothing you paste is ever sent to a server: parsing and generation both run entirely in your browser's JavaScript engine, using a small bundled SQL parser (node-sql-parser) plus a hand-written Prisma schema parser — nothing leaves your machine.

The SQL Dialect dropdown controls both directions at once: generating from Prisma always targets the selected dialect's syntax (backtick vs. double-quote identifiers, AUTO_INCREMENT vs. SERIAL, inline ENUM vs. CREATE TYPE), and parsing SQL always assumes the selected dialect's grammar — it isn't auto-detected, so pick MySQL or PostgreSQL to match your actual database before pasting.

Relations map field-for-field in both directions — a Prisma `@relation` attribute's fields/references columns, including composite (multi-column) relations and self-relations (which Prisma requires to be given an explicit name), become a matching SQL `FOREIGN KEY ... REFERENCES ...` constraint, and an `onDelete`/`onUpdate` action like `Cascade` becomes the equivalent `ON DELETE CASCADE`/`ON UPDATE` clause — and vice versa.

Converting from SQL, table and column names are turned into Prisma's conventional PascalCase and camelCase — a `blog_posts` table becomes `model BlogPosts`, a `created_at` column becomes `createdAt` — and only when that rename actually changes the identifier does the tool add an `@map`/`@@map` attribute pointing back at the original SQL name, so the round trip back to SQL still produces the exact original identifier.

Frequently Asked Questions

Advertisement

Related tools

Advertisement