Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/wb/src/scripts/prismaScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Comment on lines +46 to +47
Copy link

Copilot AI Dec 9, 2025

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.

Suggested change
? 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`;

Copilot uses AI. Check for mistakes.
return `${resetCommand} && ${resetCommandForTest}`;
Comment on lines 40 to +48
Copy link

Copilot AI Dec 9, 2025

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:

  1. Creates mock test database files (e.g., test.db, test.sqlite)
  2. Calls the reset method
  3. Verifies that the generated command includes the correct find command for removing test databases
  4. 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.

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +48
Copy link

Copilot AI Dec 9, 2025

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:

  • deleteTestDbCommand
  • cleanupTestDbCommand
  • removeTestDbCommand

This would make the code's intent clearer to future maintainers.

Suggested change
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}`;

Copilot uses AI. Check for mistakes.
}

restore(project: Project, outputPath: string): string {
Expand Down