1. Home
  2. Developer tools
  3. SQL to Prisma Schema

SQL to Prisma Schema

Bring an existing database into a Prisma project, or draft models from a SQL design, when you cannot run prisma db pull against the live database.

Free, no sign-up. Runs in your browser: nothing is uploaded.

How to use SQL to Prisma Schema

  1. Paste CREATE TABLE (and CREATE TYPE … AS ENUM) statements.
  2. Choose the database provider and naming options.
  3. Copy or download schema.prisma.

Features

  • Foreign keys become @relation fields plus the reverse list
  • PostgreSQL enums and MySQL ENUM columns become Prisma enums
  • Singular PascalCase models and camelCase fields with @map/@@map
  • @id, @unique, @default(autoincrement()), now() and @updatedAt
  • @db native types such as VarChar(255) and Decimal(10, 2)

Supported formats

You can open

  • SQL

You get

  • PRISMA

Private by design

Your files are opened and processed by your browser on this device. They are never uploaded to openWorkstand or anyone else, so the SQL to Prisma Schema is safe for contracts, IDs, photos and work documents. After you have used it once while online, it also works without an internet connection. How local processing works

Good to know

  • CHECK constraints, triggers, views and database functions have no Prisma equivalent and are skipped.
  • Many-to-many join tables become explicit models; review relation names.

Guide

Turning CREATE TABLE statements into a Prisma schema

Prisma describes a database in a single schema.prisma file of models, fields and relations. When the database already exists, or the design starts as SQL, writing those models by hand is slow and it is easy to get a relation or a default wrong. This converter reads CREATE TABLE statements and writes the Prisma schema for them.

What the parser understands

It reads CREATE TABLE statements written for PostgreSQL, MySQL or SQLite, including quoted and backticked names, SERIAL and IDENTITY columns, AUTO_INCREMENT, inline and table-level PRIMARY KEY, UNIQUE and FOREIGN KEY constraints, ON DELETE actions and default values. PostgreSQL enums declared with CREATE TYPE … AS ENUM and MySQL ENUM(...) columns become Prisma enums, and CREATE INDEX statements become @@index lines.

Types and defaults

Each SQL type maps to a Prisma scalar: integers to Int or BigInt, NUMERIC to Decimal, text types to String, BOOLEAN to Boolean, timestamps to DateTime and JSON to Json. Where the database type carries detail Prisma would otherwise lose, it is kept as a native type attribute such as @db.VarChar(255) or @db.Decimal(10, 2). Defaults are translated too: auto-incrementing keys get @default(autoincrement()), now() and CURRENT_TIMESTAMP become @default(now()), and literal values are carried over.

Names: models, fields and @map

Tables are usually plural and snake_case, while Prisma models are conventionally singular PascalCase and fields camelCase. With the naming options on, order_items becomes model OrderItem with @@map("order_items"), and user_id becomes userId with @map("user_id"). The database keeps its names, so migrations and other applications are not affected; only your TypeScript code sees the friendlier ones.

Relations in both directions

A foreign key produces three things: the scalar column, a relation field that names the fields and references, including onDelete, and a list field on the other model so you can navigate back. Composite primary keys, typical of join tables, become @@id([...]).

A worked example

The Sample has four tables. The orders table turns into a model with id BigInt @id @default(autoincrement()), userId Int @map("user_id"), status OrderStatus @default(pending), total Decimal @db.Decimal(10, 2) and placedAt DateTime @default(now()) @map("placed_at"). It also gains user User @relation(fields: [userId], references: [id], onDelete: Cascade), a list of OrderItem, an @@index([userId]) from the separate CREATE INDEX statement and @@map("orders").

What Prisma cannot describe

CHECK constraints, triggers, views, stored functions and partial indexes have no place in a Prisma schema and are skipped, though the database keeps enforcing them. Review relation field names when one table references another twice, and run prisma migrate diff against the real database before applying anything.

Choosing the provider

The provider setting fills in the datasource block and decides which native type attributes are written, because each database spells types differently: @db.VarChar and @db.Timestamptz exist for PostgreSQL, @db.DateTime(0) for MySQL, and SQLite has almost none. Pick the database the schema will actually run on, not the one the SQL was originally written for. If you are moving from MySQL to PostgreSQL, convert with the new provider and compare the native types the output proposes with your data, especially for TINYINT(1) booleans, unsigned integers and DATETIME columns without a time zone.

After converting

Save the output as prisma/schema.prisma, set the connection string in DATABASE_URL, and run prisma generate to build the client. For an existing database, prisma migrate diff --from-schema-datasource prisma/schema.prisma --to-schema-datamodel prisma/schema.prisma --script should print nothing when the schema matches; any SQL it prints shows a difference worth reading before you baseline migrations.

Checked against the current version of the SQL to Prisma Schema on .

Troubleshooting

The file does not open

Check that it is one of the supported formats above and opens in another app. Damaged files and password-protected PDFs cannot be read until they are repaired or unlocked.

It is slow or stops on a very large file

Everything runs on your device, so speed depends on its memory. Close other tabs, use a computer rather than a phone, or split the file into smaller parts first.

The download did not start

Look for your browser’s download bar or icon. Some browsers ask once before a site may download files; allow it and click the button again.

Frequently asked questions

Should I use this or prisma db pull?

Use prisma db pull when you can connect to the database: it reads the live schema, including constraints this converter cannot see. This tool is for when you only have SQL files, such as migrations, a dump or a design document, or cannot reach the database from your machine.

Why did a column become Unsupported or String?

Types with no Prisma scalar, such as PostgreSQL geometry or an unusual domain, fall back to the closest type or need Unsupported("type"). Check those fields by hand and decide whether to keep the native type or change the column.

Will prisma migrate want to change my existing tables?

It should not if the names and types match: @@map and @map keep the original table and column names. Run prisma migrate diff against the database first to confirm before applying anything.

How are many-to-many join tables handled?

A join table with two foreign keys becomes an explicit model with two relations. Prisma can also model implicit many-to-many relations, but those require its own _AToB table naming, so explicit models are safer for existing databases.

Keep working with the result

openWorkstand also includes a free workspace with documents, spreadsheets, tasks, projects and a calendar that save to a folder on your computer.