DevTools Logo

SQL DDL to Prisma Schema Converter

SQL DDL to Prisma Schema Converter

Turn CREATE TABLE statements into schema.prisma with relations and native types.

Runs in your browser
Try an example

CREATE TABLE statements

0 chars

schema.prisma

Waiting for DDL

Paste CREATE TABLE statements

No database connection is made; conversion happens locally.

Details

Convert a static DDL dump into Prisma schema text without a database connection. The converter parses the CREATE TABLE subset (column definitions, inline and table constraints, keys and enums), maps MySQL and Postgres types to Prisma scalars with native @db attributes, camelizes names with @map, and wires foreign keys to relation fields on both models. It also reports dropped CHECK constraints, generated columns and unmapped types, with a SQL-to-Prisma mapping table for review.

More examples

Blog schema

CREATE TABLE users (id BIGINT AUTO_INCREMENT PRIMARY KEY, display_name VARCHAR(100));
CREATE TABLE orders (id INT PRIMARY KEY, user_id BIGINT, FOREIGN KEY (user_id) REFERENCES users(id));

Two tables become User and Order models with userId, an @relation on Order and an orders Order[] back-relation on User.

Postgres types

CREATE TABLE events (id SERIAL PRIMARY KEY, payload JSONB, token UUID, tags TEXT[]);

SERIAL becomes Int @default(autoincrement()), JSONB becomes Json @db.JsonB, UUID becomes String @db.Uuid and TEXT[] becomes String[].

Composite primary key

CREATE TABLE memberships (user_id INT, team_id INT, PRIMARY KEY (user_id, team_id));

A composite key is emitted as @@id([userId, teamId]) instead of a field-level @id.

Examples

Autoincrement primary key

Input
id BIGINT AUTO_INCREMENT PRIMARY KEY
Output
id BigInt @id @default(autoincrement())

The PK and autoincrement flags become two field attributes.

Foreign key

Input
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
Output
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

The parent model also gets an orders Order[] back-relation.

Composite key

Input
PRIMARY KEY (user_id, team_id)
Output
@@id([userId, teamId])

Composite keys cannot be expressed as a field attribute.

About this tool

SQL DDL to Prisma Schema Converter turns pasted CREATE TABLE statements into a schema.prisma document without connecting to a database. It is aimed at docs-first teams, migrations away from another ORM and anyone holding only a DDL dump.

The parser handles a documented subset: column definitions with NOT NULL, DEFAULT, PRIMARY KEY, UNIQUE, AUTO_INCREMENT, COMMENT and inline REFERENCES, plus table-level PRIMARY KEY, UNIQUE, FOREIGN KEY and KEY/INDEX constraints. MySQL and Postgres dialects select the type matrix and native @db attributes.

Foreign keys become relation fields on both sides with camelized names and onDelete actions; multiple foreign keys to the same table get named relations so the generated schema stays valid. Enum columns become Prisma enum blocks, and composite keys become @@id or @@unique.

Anything outside the subset is reported rather than silently guessed: CHECK constraints and generated columns are dropped with warnings, unmapped types become String with a note, and names that Prisma cannot express get @map. No query is executed and no database is contacted.

What this tool does not do

  • Only CREATE TABLE statements are converted; views, triggers, procedures and ALTER TABLE are ignored.
  • The supported column flags and type matrix are a curated subset, not a complete SQL dialect implementation.
  • Relations are named heuristically from table and column names; review names when several foreign keys point to the same table.
  • Generated columns and CHECK constraints have no Prisma equivalent in the emitted schema and are reported as warnings.
  • No database connection, introspection or CLI validation is performed; all conversion happens locally in the tab.

How to use this tool

  1. Paste DDL

    Add one or more CREATE TABLE statements, or load the blog, Postgres-types or warnings example.

  2. Select a dialect

    Choose MySQL or Postgres for type mapping. A notice appears when the types suggest a different dialect.

  3. Pick the datasource provider

    The provider defaults to the dialect; switch to SQLite to strip native @db attributes with a warning.

  4. Review the output

    Use the schema.prisma, Warnings and Type mapping tabs. Check that unmapped types and dropped constraints are acceptable.

  5. Copy or download

    Copy the schema into your project or download schema.prisma, then validate it with your installed Prisma CLI.

Use cases

Prisma adoption

Generate a starting schema from a legacy MySQL or Postgres DDL dump before running introspection against a live database.

Offline modelling

Design models from documentation before a database exists, then refine them in your project.

ORM migration

Move an existing schema into Prisma while reviewing every type and constraint mapping explicitly.

Schema review

Use the warnings tab as a checklist for constructs Prisma cannot represent natively.

Representative type mappings

SQL typePrisma type
BIGINT AUTO_INCREMENTBigInt
VARCHAR(255) / TEXTString
DECIMAL(10,2)Decimal
DATETIME / TIMESTAMPDateTime
JSONB (Postgres)Json
UUID (Postgres)String
ENUM('a','b')enum ModelColumn

Native attributes are omitted for the SQLite provider because SQLite does not support them.

Common mistakes

Mistake:Expecting a full SQL parser.

Fix:This is a bounded CREATE TABLE subset. Unrecognized definitions are skipped with a warning; review the Warnings tab.

Mistake:Assuming CHECK constraints survive.

Fix:Prisma schema has no CHECK support in the emitted model syntax, so CHECK is dropped and reported.

Mistake:Using ON DELETE SET NULL on a required FK.

Fix:Make the column nullable first; otherwise the generated relation cannot express the action safely.

Mistake:Switching provider without checking types.

Fix:The SQLite provider strips native attributes and cannot represent some database-native types; review the output.

Mistake:Treating generated output as final.

Fix:Run prisma validate against your installed CLI; the tool emits text only and cannot validate your project context.

Frequently asked questions

Which SQL dialects are supported?

MySQL and Postgres. The dialect selector picks the type matrix and native @db attributes — for example DATETIME becomes @db.Timestamp(3) in MySQL, while JSONB and UUID map to @db.JsonB and @db.Uuid in Postgres. A notice appears when the pasted types suggest a different dialect than the one selected.

How are foreign keys converted?

Each foreign key becomes a relation field on the child model with @relation(fields: [...], references: [...]), plus a list back-relation on the parent model. ON DELETE CASCADE, RESTRICT and SET NULL become onDelete actions. When two foreign keys point to the same table, named relations are generated so the schema remains valid.

What happens to types without a Prisma equivalent?

They are emitted as String with a warning in the Warnings tab and an entry in the type mapping table. CHECK constraints and generated columns are similarly dropped with warnings rather than silently ignored. Review that tab before adopting the generated schema.

Are enum columns converted?

Yes. MySQL ENUM('a','b') becomes a Prisma enum block named from the table and column, and the field references that enum. The emitted enum values are listed in the schema output.

Does it connect to my database?

No. There is no database connection, introspection or query execution. The DDL you paste stays in the tab, and the converter emits inert schema.prisma text that you can copy or download.

What about composite keys and indexes?

A composite primary key becomes @@id([...]), a composite unique constraint becomes @@unique([...]), and MySQL KEY/INDEX entries become @@index([...], map: "...") with the original index name preserved.

Can I target SQLite?

Yes. Choose SQLite as the datasource provider to strip native @db attributes. The tool warns that precision details may differ and that SQLite cannot express some database-native types.

Is the generated schema guaranteed to validate?

The tool emits a best-effort schema for the supported DDL subset; it does not run the Prisma CLI. Run prisma validate in your project and review the warnings list to catch constructs that need manual adjustment.

References & standards