From 448a534245cabf2bd8d4cb555dd15c46e06c3587 Mon Sep 17 00:00:00 2001 From: Lindsay Holmwood Date: Wed, 20 May 2026 23:38:57 +1000 Subject: [PATCH] fix(examples/prisma): make demo idempotent across runs The `@cipherstash/prisma-next` example demo (`pnpm start`) inserts seed users with hardcoded primary keys (`user-0`..`user-3`). The first run succeeds; every subsequent run aborts with `23505 duplicate key value violates unique constraint "users_pkey"` before any of the codec demonstrations execute. Make the demo idempotent. --- examples/prisma/src/index.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/prisma/src/index.ts b/examples/prisma/src/index.ts index 35cc1023..64242ec0 100644 --- a/examples/prisma/src/index.ts +++ b/examples/prisma/src/index.ts @@ -103,6 +103,7 @@ async function main() { const runtime = await db.connect({ url }) try { + await clearUsers() await insertUsers() await searchByEq() await searchByIlikeAndDecrypt() @@ -116,6 +117,13 @@ async function main() { } } +async function clearUsers(): Promise { + const removed = await db.orm.User.where((u) => u.id.isNotNull()).deleteCount() + if (removed > 0) { + console.log(`--- Cleanup ---\nRemoved ${removed} existing user row(s).\n`) + } +} + async function insertUsers(): Promise { console.log('--- Insert (mixed-codec round-trip) ---') await Promise.all(