Prisma in Production: Transactions, Soft Deletes, Cursor Pagination, and Zero-Downtime Migrations
Prisma makes database access type-safe and ergonomic. But most tutorials stop at basic CRUD. These are the patterns that matter in production: transactions, soft deletes, pagination, full-text sear...

Source: DEV Community
Prisma makes database access type-safe and ergonomic. But most tutorials stop at basic CRUD. These are the patterns that matter in production: transactions, soft deletes, pagination, full-text search, and schema evolution without downtime. Transactions Use $transaction for operations that must succeed or fail together: // Sequential transaction -- each step uses results from the previous const result = await db.$transaction(async (tx) => { const order = await tx.order.create({ data: { userId, total }, }) await tx.inventory.updateMany({ where: { productId: { in: productIds } }, data: { reserved: { increment: 1 } }, }) await tx.payment.create({ data: { orderId: order.id, amount: total, status: 'pending' }, }) return order }) // Batch transaction -- independent operations, runs in parallel const [users, products] = await db.$transaction([ db.user.findMany(), db.product.findMany({ where: { active: true } }), ]) Soft Deletes Never permanently delete user data. Use a deletedAt timestamp: