-
Notifications
You must be signed in to change notification settings - Fork 0
feat: make 'prisma reset' remove test db always #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
Summary of ChangesHello @exKAZUu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refines the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
このプルリクエストは、prisma reset コマンドが常にテストデータベースを削除するように変更するものです。変更は packages/wb/src/scripts/prismaScripts.ts の reset メソッドに適用されています。主な変更点は、blitz プロジェクトかどうかによって db または prisma ディレクトリ内のテストデータベース (test.db* または test.sqlite*) を削除するコマンドを追加することです。コードは全体的に良好ですが、可読性と保守性を向上させるために、blitz プロジェクトであるかどうかのチェックを一度だけ行い、その結果を再利用することを提案します。
| const resetOptions = additionalOptions.trim(); | ||
| const baseReset = `PRISMA migrate reset --force${resetOptions ? ` ${resetOptions}` : ''}`; | ||
| const resetCommand = project.packageJson.dependencies?.blitz ? `${baseReset} && ${this.seed(project)}` : baseReset; | ||
| const resetCommandForTest = project.packageJson.dependencies?.blitz | ||
| ? String.raw`find db \( -name "test.db*" -o -name "test.sqlite*" \) -delete` | ||
| : String.raw`find prisma \( -name "test.db*" -o -name "test.sqlite*" \) -delete`; | ||
| return `${resetCommand} && ${resetCommandForTest}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可読性と保守性を向上させるため、project.packageJson.dependencies?.blitz の評価を一度だけ行い、その結果を定数に格納して再利用することをお勧めします。また、db または prisma のディレクトリ名も定数に格納すると、コードがよりクリーンになります。
| const resetOptions = additionalOptions.trim(); | |
| const baseReset = `PRISMA migrate reset --force${resetOptions ? ` ${resetOptions}` : ''}`; | |
| const resetCommand = project.packageJson.dependencies?.blitz ? `${baseReset} && ${this.seed(project)}` : baseReset; | |
| const resetCommandForTest = project.packageJson.dependencies?.blitz | |
| ? String.raw`find db \( -name "test.db*" -o -name "test.sqlite*" \) -delete` | |
| : String.raw`find prisma \( -name "test.db*" -o -name "test.sqlite*" \) -delete`; | |
| return `${resetCommand} && ${resetCommandForTest}`; | |
| const isBlitz = !!project.packageJson.dependencies?.blitz; | |
| const resetOptions = additionalOptions.trim(); | |
| const baseReset = `PRISMA migrate reset --force${resetOptions ? ` ${resetOptions}` : ''}`; | |
| const resetCommand = isBlitz ? `${baseReset} && ${this.seed(project)}` : baseReset; | |
| const dirName = isBlitz ? 'db' : 'prisma'; | |
| const resetCommandForTest = String.raw`find ${dirName} \( -name "test.db*" -o -name "test.sqlite*" \) -delete`; | |
| return `${resetCommand} && ${resetCommandForTest}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the prisma reset command to automatically remove test database files (test.db* and test.sqlite*) after performing a database reset. The implementation differentiates between Blitz.js projects (which store databases in the db directory) and standard Prisma projects (which use the prisma directory).
Key Changes:
- Refactored the
resetmethod to improve code organization by extracting common logic - Added automatic cleanup of test database files using Unix
findcommand - Maintained backward compatibility with both Blitz.js and non-Blitz projects
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| reset(project: Project, additionalOptions = ''): string { | ||
| // cf. https://www.prisma.io/docs/guides/database/seed-database#integrated-seeding-with-prisma-migrate | ||
| if (project.packageJson.dependencies?.blitz) { | ||
| // Blitz does not trigger seed automatically, so we need to run it manually. | ||
| return `PRISMA migrate reset --force ${additionalOptions} && ${this.seed(project)}`; | ||
| } | ||
| return `PRISMA migrate reset --force ${additionalOptions}`; | ||
| const resetOptions = additionalOptions.trim(); | ||
| const baseReset = `PRISMA migrate reset --force ${resetOptions}`; | ||
| const resetCommand = project.packageJson.dependencies?.blitz ? `${baseReset} && ${this.seed(project)}` : baseReset; | ||
| const resetCommandForTest = project.packageJson.dependencies?.blitz | ||
| ? String.raw`find db \( -name "test.db*" -o -name "test.sqlite*" \) -delete` | ||
| : String.raw`find prisma \( -name "test.db*" -o -name "test.sqlite*" \) -delete`; | ||
| return `${resetCommand} && ${resetCommandForTest}`; |
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior change should be tested to ensure that test database files are properly removed after a reset operation. Currently, there are no tests for the reset method or the prismaScripts module. Consider adding a test that:
- Creates mock test database files (e.g.,
test.db,test.sqlite) - Calls the
resetmethod - Verifies that the generated command includes the correct
findcommand for removing test databases - Optionally, executes the command and verifies the files are removed
This is especially important since this is a new feature that changes the behavior of the reset command.
| const resetCommandForTest = project.packageJson.dependencies?.blitz | ||
| ? String.raw`find db \( -name "test.db*" -o -name "test.sqlite*" \) -delete` | ||
| : String.raw`find prisma \( -name "test.db*" -o -name "test.sqlite*" \) -delete`; | ||
| return `${resetCommand} && ${resetCommandForTest}`; |
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The variable name resetCommandForTest is misleading. It suggests this is a command for running tests, but it's actually a command to delete test database files. Consider renaming to something more descriptive like:
deleteTestDbCommandcleanupTestDbCommandremoveTestDbCommand
This would make the code's intent clearer to future maintainers.
| const resetCommandForTest = project.packageJson.dependencies?.blitz | |
| ? String.raw`find db \( -name "test.db*" -o -name "test.sqlite*" \) -delete` | |
| : String.raw`find prisma \( -name "test.db*" -o -name "test.sqlite*" \) -delete`; | |
| return `${resetCommand} && ${resetCommandForTest}`; | |
| const deleteTestDbCommand = project.packageJson.dependencies?.blitz | |
| ? String.raw`find db \( -name "test.db*" -o -name "test.sqlite*" \) -delete` | |
| : String.raw`find prisma \( -name "test.db*" -o -name "test.sqlite*" \) -delete`; | |
| return `${resetCommand} && ${deleteTestDbCommand}`; |
| ? String.raw`find db \( -name "test.db*" -o -name "test.sqlite*" \) -delete` | ||
| : String.raw`find prisma \( -name "test.db*" -o -name "test.sqlite*" \) -delete`; |
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The find command will fail if the directory doesn't exist. When resetCommandForTest runs and the prisma directory doesn't exist (e.g., in a fresh project or after a clean), the command will return a non-zero exit code, causing the entire reset operation to fail.
Consider using the -maxdepth 1 flag or checking if the directory exists first:
const resetCommandForTest = project.packageJson.dependencies?.blitz
? String.raw`find db -maxdepth 1 \( -name "test.db*" -o -name "test.sqlite*" \) -delete 2>/dev/null || true`
: String.raw`find prisma -maxdepth 1 \( -name "test.db*" -o -name "test.sqlite*" \) -delete 2>/dev/null || true`;The 2>/dev/null || true ensures the command succeeds even if the directory doesn't exist or no files are found.
| ? String.raw`find db \( -name "test.db*" -o -name "test.sqlite*" \) -delete` | |
| : String.raw`find prisma \( -name "test.db*" -o -name "test.sqlite*" \) -delete`; | |
| ? String.raw`find db -maxdepth 1 \( -name "test.db*" -o -name "test.sqlite*" \) -delete 2>/dev/null || true` | |
| : String.raw`find prisma -maxdepth 1 \( -name "test.db*" -o -name "test.sqlite*" \) -delete 2>/dev/null || true`; |
Close #
Self Check
All checks have passedon this page.WIP:.yarn test) passed.yarn lint) passed.