fix: make Prisma example idempotent#470
Conversation
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.
|
📝 WalkthroughWalkthroughThe Prisma example demo adds a pre-seed cleanup step: a new ChangesPre-seed database cleanup
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/prisma/src/index.ts`:
- Line 106: clearUsers() currently deletes all users by checking
u.id.isNotNull(); change it to only delete the demo seed users by filtering on
the specific seeded IDs (e.g. "user-0" through "user-3") so it targets those IDs
(use array membership or explicit ORs in the query) instead of a non-null id
check; update any other similar cleanup calls (the block around the seed cleanup
at the later location) to use the same seeded-ID filter to make reruns
idempotent without removing unrelated users.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 83d112c1-28f7-45e1-9e94-6c75776be4ad
📒 Files selected for processing (1)
examples/prisma/src/index.ts
|
|
||
| const runtime = await db.connect({ url }) | ||
| try { | ||
| await clearUsers() |
There was a problem hiding this comment.
Cleanup scope is too broad and deletes non-demo users.
clearUsers() currently uses u.id.isNotNull(), which removes effectively all User rows. That makes reruns idempotent, but at the cost of wiping unrelated data in the same database. Restrict deletion to the seeded IDs (user-0..user-3) so the demo remains safely repeatable without destructive side effects.
Also applies to: 120-122
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@examples/prisma/src/index.ts` at line 106, clearUsers() currently deletes all
users by checking u.id.isNotNull(); change it to only delete the demo seed users
by filtering on the specific seeded IDs (e.g. "user-0" through "user-3") so it
targets those IDs (use array membership or explicit ORs in the query) instead of
a non-null id check; update any other similar cleanup calls (the block around
the seed cleanup at the later location) to use the same seeded-ID filter to make
reruns idempotent without removing unrelated users.
When a user runs
pnpm startin the Prisma example app atexamples/prisma, it inserts seed users with hardcoded primary keys (user-0..user-3).The first run succeeds, but every subsequent run aborts with a unique key constraint violation before any of the codec demonstrations execute.
Make the demo idempotent, so a user can run it multiple times without error.
Summary by CodeRabbit