SQL to Drizzle schema converter (PostgreSQL)

Convert SQL to Drizzle: PostgreSQL CREATE TABLE statements, or a whole pg_dump, become a Drizzle ORM schema (pg-core) with tables, enums, foreign keys, indexes, CHECK constraints and defaults, with the database's own constraint names.

PostgreSQL

Drizzle

Waiting for input

What you get

How each result is checked

  1. Your SQL is read by the real PostgreSQL parser, compiled to WebAssembly.
  2. The generated TypeScript is compiled and run with drizzle-orm itself, and Drizzle describes every table (getTableConfig).
  3. Every column type (as Drizzle spells it in SQL), NULL/NOT NULL and default, plus every primary key, unique constraint, foreign key (name, columns, ON DELETE/ON UPDATE), index (name, method, columns, condition), CHECK count and enum is compared with your SQL.

What can't convert exactly

  • Types Drizzle has no builder for (money, xml, bytea, tsvector…) become customType() with the exact database type, and are listed in the warnings.
  • drizzle-kit has known quoting issues with some custom types that take parameters (varbit(8)) and with the internal "char" type; those are flagged in the warnings.
  • Views, functions and triggers are not part of a Drizzle table schema and are listed as ignored.

Questions

Does drizzle-kit generate the same database?

That is what the tests check: for every test schema, drizzle-kit turns the generated Drizzle schema back into SQL, which is run in a real Postgres and compared with the original database: columns, types, keys, constraint names, indexes, checks, defaults and identity columns.

camelCase or database names?

Fields are camelCase by default with the database name kept as the column name (createdAt: timestamp("created_at")). Choose "Same as the database" to use the column names as fields.

What about bigint?

bigint columns are read as JavaScript numbers by default ({ mode: "number" }). Choose bigint mode if values can be above 2^53.

Can I generate a Drizzle schema without connecting to the database?

Yes. drizzle-kit pull reads a running database; here you paste SQL or a pg_dump instead, so it works without a database connection. You get a Postgres to Drizzle schema with tables, enums, indexes, foreign keys and CHECK constraints.

How do I convert PostgreSQL to Drizzle online?

Paste your PostgreSQL or open a file on the left (or click Example). The Drizzle appears on the right as you type, already checked. Copy it, or download it as a file. Nothing is uploaded.

Can the Drizzle output be wrong?

Every result is checked before it is shown (the checks are listed on this page). If a check fails, the page says "Review needed" and why, instead of presenting the output as correct, and anything that cannot convert exactly is named in the notes.