Skip to content
/>codemaxxed.com

SQL to Prisma

Convert SQL CREATE TABLE scripts and dumps (Postgres, MySQL, SQLite, SQL Server, CockroachDB) into a Prisma schema with native types, enums and both sides of every relation — or into Drizzle ORM, SQLAlchemy 2.0, TypeORM, TypeScript, Zod or a Mermaid ER diagram.

Runs locally. Nothing is uploaded.

SQL schema

Prisma schema

Output appears here as you type.

Ready

How this converter works

Paste CREATE TABLE statements, a migration folder concatenated into one file, or a whole pg_dump / mysqldump / SSMS script. The parser follows the script in order: CREATE TYPE ... AS ENUM, CREATE DOMAIN, ALTER TABLE (ADD / DROP / RENAME / ALTER COLUMN, ADD CONSTRAINT, MODIFY, CHANGE), CREATE INDEX, DROP TABLE and COMMENT ON all update the schema. Views, functions, triggers, inserts and other statements are listed under Ignored statements instead of failing the conversion.

The Prisma output is what prisma db pull would give you: snake_case columns become camelCase fields with @map, tables become PascalCase singular models with @@map, and native types (@db.VarChar(255), @db.Timestamptz(6), @db.UnsignedInt, ...) keep migrations from altering your columns. Serial and identity columns get autoincrement(), gen_random_uuid() becomes uuid(), now() becomes now(), and anything else is kept with dbgenerated(). The header matches the Prisma version you pick, and provider limits (no enums or Json on SQLite and SQL Server, no lists outside Postgres) are handled with a warning.

Foreign keys become a typed relation field on the child and a back-relation on the parent, from inline REFERENCES, table-level FOREIGN KEY or ALTER TABLE ... ADD CONSTRAINT. Relations get names when two tables are linked more than once or a table references itself, composite keys map to @@id / @@unique / composite relations, and ON DELETE / ON UPDATE actions are kept.

The same parsed schema drives the other targets: a Drizzle schema for pg-core, mysql-core or sqlite-core with relations() and inferred row types, SQLAlchemy 2.0 typed models with relationship() pairs, TypeORM entities, plain TypeScript interfaces, Zod schemas, and a Mermaid erDiagram you can drop into a README. The table below the output summarizes keys and foreign keys per table.

Frequently asked

Which databases does it understand?

PostgreSQL (enums, domains, arrays, SERIAL / IDENTITY, pg_dump output), MySQL and MariaDB (AUTO_INCREMENT, UNSIGNED, inline ENUM, COMMENT, mysqldump output), SQLite (loose and missing types, AUTOINCREMENT, rowid primary keys), SQL Server (brackets, IDENTITY(1,1), GO batches, ADD DEFAULT ... FOR) and CockroachDB (STRING, INT8, unique_rowid()). The dialect is auto-detected; pick it under Database if the guess is wrong.

Why did it add an id column I didn't write?

Prisma, SQLAlchemy and TypeORM need an identifier on every model. If a table has no primary key, an existing id column is used; for Prisma a NOT NULL unique column also works. Otherwise a synthetic integer id is added, and the warning says which table it was.

What happens to types Prisma doesn't support?

Types like tsvector, geometry, point, interval or pgvector's vector become Unsupported("...") fields, exactly as prisma db pull does, so the column survives migrations. Unknown custom types fall back to String with a warning. Drizzle and SQLAlchemy get a small customType / UserDefinedType that emits the original type in DDL.

Are indexes and constraints preserved?

Primary keys, unique constraints, CREATE INDEX / CREATE UNIQUE INDEX, defaults, foreign keys with their actions and column comments are. Turn on Keep constraint names to carry custom constraint names into Prisma with map:. CHECK constraints, partial indexes and expression indexes have no equivalent and are reported as warnings.

Which Prisma version is the output for?

Models work with Prisma 5 and later. The Prisma 7 header uses the prisma-client generator and leaves the URL to prisma.config.ts; switch the header to Prisma 5/6 for url = env("DATABASE_URL") and prisma-client-js, or to Models only to paste into an existing schema.