Exercise 1: Publishing an Author's Drafts, All or Nothing — Possible Solution ============================================================================== async function promoteAndPublish(authorId: number) { const [published, author] = await prisma.$transaction([ prisma.post.updateMany({ where: { authorId, published: false }, data: { published: true }, }), prisma.user.update({ where: { id: authorId }, data: { role: "AUTHOR" }, }), ]); return { publishedCount: published.count, role: author.role }; } Proving the rollback: // Pick an author with drafts, note how many drafts they have const before = await prisma.post.count({ where: { authorId: 3, published: false } }); try { await prisma.$transaction([ prisma.post.updateMany({ where: { authorId: 3, published: false }, data: { published: true } }), prisma.user.update({ where: { id: 999999 }, data: { role: "AUTHOR" } }), // no such user: P2025 ]); } catch (e) { console.log("Transaction failed:", (e as any).code); // P2025 } const after = await prisma.post.count({ where: { authorId: 3, published: false } }); console.log(before, after); // the same number: the drafts were NOT published WHY THIS WORKS AS AN ANSWER ------------------------------ Both changes are independent and known in advance, so the batch form fits. Neither query is awaited inside the array; only $transaction is. The test makes the second query fail with a record-not-found error and then counts the drafts again — the count is unchanged, which shows the first query was rolled back rather than left half-done.