Migrate from Prisma + Postgres

Prisma + Postgres → Drizzle + D1, with the SQLite gaps spelled out.

This is the most mechanical of the migrations — and the one with the sharpest type edges. Prisma models map cleanly to Drizzle tables, but D1 is SQLite: no native date, jsonb, decimal, array, or enum types, and Postgres-specific SQL (window functions, FTS, jsonb operators) needs rework. This page surfaces those costs before you start.

pnpm create microservices-app@latest my-app --template saas-starter-sveltekit

Local-first · no login · Node ≥ 20 · driven by the prisma-postgres-to-d1 agent skill

Concept mapping

How Prisma + Postgres maps onto Cloudflare-native.

Prisma + Postgres microservices.sh / Cloudflare Note
String @id @default(uuid()) text primary key Generate ids in app, not the DB
Int @id @default(autoincrement()) integer primary key autoincrement
DateTime integer (epoch ms) or text (ISO) SQLite has no native date type
Boolean integer 0/1
Json text + JSON helpers No native jsonb
Decimal integer minor units (cents) No exact decimal — store money as integer cents
enum / String[] text + app check / join table No native enum or array
@relation / @@index Drizzle references() + index() D1 enforces FKs only with pragma on

The migration

Five steps, plan-first and approval-gated.

  1. 01

    Assess the schema

    Read schema.prisma — models, relations, indexes, enums, defaults — and flag Postgres-specific query features (raw SQL, jsonb ops, FTS, window functions).

  2. 02

    Scaffold or target the app

    Start fresh with create microservices-app, or in an existing app check which entities a module already owns and don't redefine them.

  3. 03

    Translate schema to Drizzle

    Convert each model per the type mapping, recreate every @@index/@@unique as Drizzle index()/unique(), and move id generation into the app.

  4. 04

    Rewrite queries

    Replace Prisma Client calls with Drizzle, rewrite $queryRaw Postgres SQL as SQLite-compatible SQL, and re-express jsonb/array/FTS logic as app code or join tables.

  5. 05

    Move the data

    Export Postgres, transform values to SQLite types (dates→epoch, booleans→0/1, JSON→text, decimals→cents), load to local D1, verify counts and joins before remote import.

What doesn't port 1:1

The real cost — no surprises.

pnpm create microservices-app@latest my-app --template saas-starter-sveltekit
See the quickstart