Prisma Schema to SQL DDL

Paste a Prisma schema and get ready-to-run SQL DDL for PostgreSQL or MySQL in one click. The converter handles model blocks, enum types, relation fields, @@map table aliases, @map column aliases, @@index directives, and foreign-key constraints — so the output mirrors exactly what Prisma\'s migrate engine would produce.

How to use the Prisma Schema to SQL DDL

Paste your schema.prisma content into the input box — the full file or just the relevant model and enum blocks. Select the target SQL dialect (PostgreSQL or MySQL) and click Convert to SQL. The output panel fills with CREATE TABLE statements ready to execute in your database client or migration script.

The converter maps each Prisma scalar to the dialect-appropriate SQL type: String becomes TEXT (Postgres) or VARCHAR(255) (MySQL); Int becomes INTEGER/INT; DateTime becomes TIMESTAMP/DATETIME; Json becomes JSONB (Postgres) or JSON (MySQL). Fields marked @id @default(autoincrement()) emit SERIAL (Postgres) or AUTO_INCREMENT (MySQL). Optional fields (?) omit the NOT NULL constraint. Relation list fields (Post[]) are skipped — the FK lives on the owning model. Foreign keys from @relation(fields:[...], references:[...]) are collected and emitted as ALTER TABLE … ADD CONSTRAINT after all tables.

Use the Example button to load a two-model User/Post schema with a FK, an enum, and an @@index so you can see exactly what the output looks like before pasting your own schema.

What is a Prisma schema?

Prisma is a TypeScript ORM for Node.js and Deno. Its schema file (schema.prisma) is the single source of truth for your database structure: you define model blocks for each table, enum types, field types and modifiers, and relation declarations. Prisma then generates a type-safe client and runs prisma migrate to apply the schema to your database.

When you need to work outside the Prisma ecosystem — for example, seeding a staging database directly, writing a raw migration patch, reviewing schema changes in a code review, or porting a project to plain SQL migrations — you need the equivalent SQL DDL. Prisma does not expose its internal SQL generation as a public API, so developers often hand-write the SQL or rely on prisma migrate diff --to-schema-datamodel with a live database. This converter gives you that DDL instantly, offline, without a database connection.

The tool also helps when migrating away from Prisma: once you have the canonical CREATE TABLE SQL you can feed it to a SQLAlchemy model generator or another ORM tool. @@map and @map attributes are honored so the emitted SQL uses the real database table and column names, not the Prisma model names.

Common use cases

  • Raw migration patches — generate the SQL DDL when you need to apply schema changes to a database that is not managed by Prisma migrate.
  • Code reviews — paste the DDL into a PR description so reviewers who are not familiar with Prisma syntax can see the actual database impact.
  • Seeding staging databases — spin up a fresh schema in a CI pipeline or staging environment without running the full Prisma migrate workflow.
  • ORM migration — extract the SQL DDL as the first step when moving a project from Prisma to another ORM such as SQLAlchemy or TypeORM.
  • Documentation — embed the SQL schema in technical docs or runbooks where the Prisma syntax would be unfamiliar to the database team.
  • Multi-database setups — use one Prisma schema as the canonical definition and generate dialect-specific DDL for each database in the stack.

Frequently asked questions

Does it handle relation fields?

Relation list fields (e.g. posts Post[]) are skipped from the column list — they exist only at the Prisma layer. The FK constraint is emitted from the owning side that has @relation(fields:[...], references:[...]), as an ALTER TABLE … ADD CONSTRAINT statement after the table definitions.

What happens to Prisma enums?

For PostgreSQL, each enum block is emitted as CREATE TYPE name AS ENUM (...). For MySQL, enum columns are mapped to VARCHAR(255) because MySQL enums are defined inline and the converter avoids altering column definitions you may want to tune by hand.

Does @@map change the output table name?

Yes. If a model has @@map("table_name"), the SQL uses that name instead of the Prisma model name. Similarly @map("col_name") on a field sets the SQL column name.

Is the output identical to what prisma migrate produces?

It is semantically equivalent for common schemas but not guaranteed byte-for-byte identical. Prisma's migration engine handles edge cases like partial indexes, deferred constraints, and MySQL-specific storage engines that are beyond scope here. Use this for review and bootstrapping — run prisma migrate dev for production migrations.

Does it support composite primary keys (@@id)?

Yes. A @@id([field1, field2]) block attribute emits a PRIMARY KEY (field1, field2) table constraint.