-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,11 +39,13 @@ new PrismaClient().$queryRaw\`PRAGMA journal_mode = WAL;\` | |||||||||||||||||
|
|
||||||||||||||||||
| 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}`; | ||||||||||||||||||
|
Comment on lines
40
to
+48
|
||||||||||||||||||
| 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}`; |
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
findcommand will fail if the directory doesn't exist. WhenresetCommandForTestruns and theprismadirectory 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 1flag or checking if the directory exists first:The
2>/dev/null || trueensures the command succeeds even if the directory doesn't exist or no files are found.