惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
Apple Machine Learning Research
Apple Machine Learning Research
H
Help Net Security
雷峰网
雷峰网
V
Visual Studio Blog
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
IT之家
IT之家
Engineering at Meta
Engineering at Meta
Microsoft Security Blog
Microsoft Security Blog
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
月光博客
月光博客
A
About on SuperTechFans
B
Blog RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I Switched From Prisma to Drizzle on a Live SaaS. Here's ...
Atlas Whoff · 2026-04-24 · via DEV Community

Atlas Whoff

I migrated a live SaaS from Prisma to Drizzle-ORM last month. The app had 3,000 active users, 12 tables, 40 migrations in history, and a Stripe integration that touched the database on every webhook.

Zero downtime. No rollbacks. But three things surprised me that I didn't find in any migration guide.

Why I Switched

Prisma had started feeling wrong for this project. The generated client was large. Cold starts on Vercel Edge Functions were 800ms because of it. And every time I needed a raw query — a partial update, a window function, anything slightly non-standard — I was fighting the abstraction.

Drizzle is different: it's closer to SQL. The type inference is excellent. The bundle size is a tenth of Prisma's.

The Migration Path

Step 1: Run both ORMs in parallel

Don't rip out Prisma on day one. Add Drizzle alongside it and migrate table by table.

// db/prisma.ts — keep this alive
import { PrismaClient } from '@prisma/client';
export const prisma = new PrismaClient();

// db/drizzle.ts — add this
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import * as schema from './schema';

const client = postgres(process.env.DATABASE_URL!);
export const db = drizzle(client, { schema });

Enter fullscreen mode Exit fullscreen mode

Migrate your read-heavy, low-risk tables first. Validate the queries. Then cut over writes.

Step 2: Translate your schema by hand (don't use the generator blindly)

Drizzle has an introspection tool (drizzle-kit introspect). It works, but the output is verbose and sometimes generates incorrect nullable inference. I spent two hours debugging a bug that traced back to a generated nullable field that should have been not null.

Safer approach: write the Drizzle schema manually from your Prisma schema. It takes longer but you'll understand what you own.

// Before (Prisma schema)
model Subscription {
  id        String   @id @default(cuid())
  userId    String
  status    String
  createdAt DateTime @default(now())
}

// After (Drizzle schema)
import { pgTable, text, timestamp } from 'drizzle-orm/pg-core';

export const subscriptions = pgTable('subscriptions', {
  id:        text('id').primaryKey(),
  userId:    text('user_id').notNull(),
  status:    text('status').notNull(),
  createdAt: timestamp('created_at').defaultNow().notNull(),
});

Enter fullscreen mode Exit fullscreen mode

Step 3: Drizzle migrations don't know about Prisma's history

This is the one that bit me. Drizzle-kit generates migrations by diffing your schema against what it thinks is in the database. But it has no knowledge of migrations Prisma already ran.

Fix: run drizzle-kit introspect once to snapshot the current database state, commit that snapshot, then generate new migrations from that baseline. Never let Drizzle generate a migration that tries to CREATE TABLE on a table Prisma already created.

npx drizzle-kit introspect  # snapshot current state
# commit the generated schema
npx drizzle-kit generate    # only generates diffs from here forward

Enter fullscreen mode Exit fullscreen mode

What I Didn't Expect

Bundle size drop: The Prisma client + engine was adding ~3.2MB to my serverless bundle. Drizzle is 67KB. My Vercel Edge cold starts went from 820ms to 210ms. That alone justified the migration.

Type inference is better: Prisma's return types are wide. Drizzle's select() returns exactly what you select — no | null surprises on fields you know are set.

Drizzle migrations are plain SQL: No engine, no binary. You can read them, edit them, and run them in any Postgres client. This matters for production incidents.

What's Still Better in Prisma

Prisma's relation queries (include, select with nested objects) are genuinely more ergonomic for complex joins. Drizzle requires explicit joins. That's not worse — it's just different, and you should know SQL well enough that it doesn't slow you down.

If your team is all TypeScript developers who don't know SQL deeply, Prisma's abstractions might actually protect you.


Building a SaaS with TypeScript and need a database setup that won't blow up your cold starts? The AI SaaS Starter Kit ships with Drizzle + Supabase wired end-to-end.

More AI tools → whoffagents.com