fix(cli): fix race condition during push db (#2491)#2587
Conversation
Because a hardcoded prefix creating the temporal schema file `~schema.prisma`, multiple processes running `push db` will suffer a race condition. Change the hardcoded prefix with a sort of UUID.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughgenerateTempPrismaSchema was changed to accept an options object ({ folder?: string; randomName?: boolean }), to optionally emit randomized temp Prisma schema filenames, and callers plus CLI options were updated; new tests validate default and randomized filename behaviors. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
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 unit tests (beta)
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.
🧹 Nitpick comments (1)
packages/cli/src/index.ts (1)
79-83: Optional: minor help-text polish.The description says
(default: "~schema.prisma"), but that's the default filename when the flag is not passed — which is a little confusing to read as a "default" for this boolean flag. Consider phrasing it as behavior instead, e.g.:✏️ Suggested wording
- const randomPrismaSchemaNameOption = new Option( - '--random-prisma-schema-name', - 'append a random UUID to the temporary Prisma schema filename to avoid collisions between concurrent runs sharing a working directory (default: "~schema.prisma")', - ).default(false); + const randomPrismaSchemaNameOption = new Option( + '--random-prisma-schema-name', + 'append a random UUID to the temporary Prisma schema filename (e.g., ~schema.<uuid>.prisma) to avoid collisions between concurrent runs sharing a working directory', + ).default(false);Also worth verifying: reusing a single
Optioninstance across multiple.addOption(...)calls (migrate dev/reset/deploy/status/resolve + db push) is done elsewhere in this file (e.g.,schemaOption,noVersionCheckOption), so this follows established convention — no change needed there.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cli/src/index.ts` around lines 79 - 83, Update the help text for the Option instance randomPrismaSchemaNameOption to avoid implying a boolean flag has a filename "default"; reword the description to describe behavior instead (e.g., "when set, append a random UUID to the temporary Prisma schema filename to avoid collisions between concurrent runs sharing a working directory; otherwise the temporary filename is \"~schema.prisma\""). Edit the Option constructor call that creates randomPrismaSchemaNameOption to use the new phrasing so the flag's purpose and fallback filename are clear.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/cli/src/index.ts`:
- Around line 79-83: Update the help text for the Option instance
randomPrismaSchemaNameOption to avoid implying a boolean flag has a filename
"default"; reword the description to describe behavior instead (e.g., "when set,
append a random UUID to the temporary Prisma schema filename to avoid collisions
between concurrent runs sharing a working directory; otherwise the temporary
filename is \"~schema.prisma\""). Edit the Option constructor call that creates
randomPrismaSchemaNameOption to use the new phrasing so the flag's purpose and
fallback filename are clear.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c2f3efd1-2253-4d64-8a85-3355e42c44d8
📒 Files selected for processing (5)
packages/cli/src/actions/action-utils.tspackages/cli/src/actions/db.tspackages/cli/src/actions/migrate.tspackages/cli/src/index.tspackages/cli/test/action-utils.test.ts
✅ Files skipped from review due to trivial changes (1)
- packages/cli/test/action-utils.test.ts
…om-prisma-schema-name The UUID suffix introduced in f962351 to avoid collisions between concurrent `zen db push` runs is now opt-in. Default behavior restores the upstream `~schema.prisma` filename; pass `--random-prisma-schema-name` to `db push` or any `migrate` subcommand to re-enable the UUID suffix. Addresses the maintainer's review comment on zenstackhq#2491. Assisted-by: Cursor:claude-opus-4.7 [Shell] [Read] [StrReplace] [Write]
933ad1a to
3bd3535
Compare
ymc9
left a comment
There was a problem hiding this comment.
Looks great to me! Thanks for the quick follow-up.
Because a hardcoded prefix creating the temporal schema file
~schema.prisma, multiple processes runningpush dbwill suffer a race condition.Change the hardcoded prefix with a sort of UUID.
Fix: 2491.
Summary by CodeRabbit