Skip to content

fix: make Prisma example idempotent#470

Merged
calvinbrewer merged 1 commit into
mainfrom
fix/make-prisma-example-idempotent
May 20, 2026
Merged

fix: make Prisma example idempotent#470
calvinbrewer merged 1 commit into
mainfrom
fix/make-prisma-example-idempotent

Conversation

@auxesis
Copy link
Copy Markdown
Contributor

@auxesis auxesis commented May 20, 2026

When a user runs pnpm start in the Prisma example app at examples/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

  • Chores
    • Updated example with improved data initialization workflow to ensure clean state before seeding.

Review Change Stack

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.
@auxesis auxesis requested a review from a team as a code owner May 20, 2026 13:45
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 20, 2026

⚠️ No Changeset found

Latest commit: 448a534

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

📝 Walkthrough

Walkthrough

The Prisma example demo adds a pre-seed cleanup step: a new clearUsers() helper function deletes existing User records via Prisma, logging the removed count. This function is called in main() immediately after database connection, before the demo inserts and queries fresh data.

Changes

Pre-seed database cleanup

Layer / File(s) Summary
Cleanup helper and call site
examples/prisma/src/index.ts
A new clearUsers() helper function uses Prisma to delete User rows and logs the count of removed records. The function is invoked in main() right after establishing the database connection, before the demo seeds fresh data.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A seedling demo, fresh and clean,
Old users swept—a stage pristine,
Before new data takes its place,
We clear the garden's growing space. 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: make Prisma example idempotent' directly and clearly summarizes the main change: adding cleanup logic to make the example script rerunnable without duplicate key errors.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/make-prisma-example-idempotent

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between cbbb76d and 448a534.

📒 Files selected for processing (1)
  • examples/prisma/src/index.ts


const runtime = await db.connect({ url })
try {
await clearUsers()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

@calvinbrewer calvinbrewer merged commit c9b2831 into main May 20, 2026
7 checks passed
@calvinbrewer calvinbrewer deleted the fix/make-prisma-example-idempotent branch May 20, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants