Building Type-Safe APIs with Nuxt 3 and Prisma
Learn how to build end-to-end type-safe APIs using Nuxt 3 server routes and Prisma ORM for a seamless developer experience.
Learn how to evolve your database schema without breaking production — expand-and-contract pattern, backfills, and rollback strategies.
Mbeah Essilfie
June 11, 2026 at 06:03 AM
You need to rename a column. The naive approach:
But between steps 1 and 2, your running app references the old column name. Errors. Downtime.
Phase 1: Expand — Add the new column alongside the old one.
ALTER TABLE users ADD COLUMN full_name TEXT;
-- Backfill
UPDATE users SET full_name = name;
-- Add trigger to keep both in sync
CREATE TRIGGER sync_name
BEFORE INSERT OR UPDATE ON users
FOR EACH ROW EXECUTE FUNCTION sync_name_columns();
Phase 2: Migrate — Update app code to use the new column.
// Before: user.name
// After: user.fullName
const user = await prisma.user.findUnique({
where: { id },
select: { fullName: true }, // new column
})
Phase 3: Contract — Remove the old column once all code uses the new one.
ALTER TABLE users DROP COLUMN name;
# Phase 1: Add column
prisma migrate dev --name add_full_name
# After backfill and code migration:
# Phase 3: Remove old column
prisma migrate dev --name remove_name
-- 1. Add as nullable
ALTER TABLE posts ADD COLUMN reading_time INT;
-- 2. Backfill
UPDATE posts SET reading_time = CEIL(LENGTH(content) / 1000);
-- 3. Add constraint (after backfill completes)
ALTER TABLE posts ALTER COLUMN reading_time SET NOT NULL;
-- CONCURRENTLY avoids table locks (PostgreSQL)
CREATE INDEX CONCURRENTLY idx_posts_published ON posts (published_at);
Schema evolution is a solved problem — but only if you follow the pattern.
Fullstack Software Developer
Learn how to build end-to-end type-safe APIs using Nuxt 3 server routes and Prisma ORM for a seamless developer experience.
Go beyond basic utility classes and learn how to build cohesive, maintainable design systems with Tailwind CSS.
Understand the power of Vue 3's Composition API through practical, real-world composable patterns that you can use today.
