Skip to content

feat: add db reset command#7994

Open
paulo wants to merge 1 commit intomainfrom
pa/feat-reset
Open

feat: add db reset command#7994
paulo wants to merge 1 commit intomainfrom
pa/feat-reset

Conversation

@paulo
Copy link
Contributor

@paulo paulo commented Mar 6, 2026

Summary

This adds the reset command from the primitives repo. However, I've noted a couple of issues that I'll address in a follow-up:

  • migrate doesn't work when a dev server is running (migrations are applied on a separate pglite process)
  • when this happens, reset leaves the db in a bad state, and removing the data directory is needed

@coderabbitai
Copy link

coderabbitai bot commented Mar 6, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a database reset command to reset the local database.
  • Chores

    • Updated "@netlify/dev" dependency to 4.14.1.
  • Tests

    • Added unit test suite for the database reset functionality.

Walkthrough

This pull request adds a new database reset command to the CLI. Changes include bumping the @netlify/dev dependency version, adding a new "reset" subcommand to the database command structure that dynamically imports and executes reset logic, implementing the reset functionality with lifecycle management for NetlifyDev initialization and cleanup, and providing comprehensive unit test coverage for the new command with various scenarios including error handling and JSON output formatting.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title 'feat: add db reset command' accurately and concisely describes the main change: adding a new database reset command.
Description check ✅ Passed The description is related to the changeset, explaining the addition of the reset command and known issues to address later.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pa/feat-reset

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.

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

📊 Benchmark results

Comparing with f70e4b4

  • Dependency count: 1,083 (no change)
  • Package size: 352 MB (no change)
  • Number of ts-expect-error directives: 362 (no change)

@paulo paulo requested a review from eduardoboucas March 6, 2026 09:37
@paulo paulo marked this pull request as ready for review March 6, 2026 09:37
@paulo paulo requested a review from a team as a code owner March 6, 2026 09:37
Copy link

@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

🧹 Nitpick comments (1)
src/commands/database/database.ts (1)

101-104: Add an explicit confirmation path for db reset.

This subcommand drops the entire local schema immediately, but there’s no confirmation or --force escape hatch. Prompting in interactive shells and requiring --force for non-interactive runs would make accidental data loss much harder.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/database/database.ts` around lines 101 - 104, Add an explicit
confirmation flow to the 'reset' subcommand: introduce a boolean option
'--force' and, inside the .action handler for the reset command (the async
(options: { json?: boolean }, command: BaseCommand) => { ... } block), if stdin
is a TTY prompt the user to type an explicit confirmation (e.g., "type RESET to
confirm") before proceeding; if stdin is not a TTY, require that options.force
is true or abort with a clear message. Ensure the prompt branch prevents
deletion on cancel and that the non-interactive branch only proceeds when
--force is present, and reuse the existing command/console utilities for
prompting and aborting so behavior integrates with the rest of the CLI.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/commands/database/database.ts`:
- Around line 101-104: Add an explicit confirmation flow to the 'reset'
subcommand: introduce a boolean option '--force' and, inside the .action handler
for the reset command (the async (options: { json?: boolean }, command:
BaseCommand) => { ... } block), if stdin is a TTY prompt the user to type an
explicit confirmation (e.g., "type RESET to confirm") before proceeding; if
stdin is not a TTY, require that options.force is true or abort with a clear
message. Ensure the prompt branch prevents deletion on cancel and that the
non-interactive branch only proceeds when --force is present, and reuse the
existing command/console utilities for prompting and aborting so behavior
integrates with the rest of the CLI.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e6b3fd70-8750-495b-a021-91a8a7a6f335

📥 Commits

Reviewing files that changed from the base of the PR and between f70e4b4 and 11507d0.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • package.json
  • src/commands/database/database.ts
  • src/commands/database/reset.ts
  • tests/unit/commands/database/reset.test.ts

Comment on lines +17 to +40
const netlifyDev = new NetlifyDev({
projectRoot: buildDir,
aiGateway: { enabled: false },
blobs: { enabled: false },
edgeFunctions: { enabled: false },
environmentVariables: { enabled: false },
functions: { enabled: false },
geolocation: { enabled: false },
headers: { enabled: false },
images: { enabled: false },
redirects: { enabled: false },
staticFiles: { enabled: false },
serverAddress: null,
})

try {
await netlifyDev.start()

const { db } = netlifyDev
if (!db) {
throw new Error('Local database failed to start. Set EXPERIMENTAL_NETLIFY_DB_ENABLED=1 to enable.')
}

await db.reset()
Copy link

@coderabbitai coderabbitai bot Mar 6, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Block db reset while another netlify dev session is using the local DB.

The PR description already calls out that running reset against a separate PGlite process can leave the data directory corrupted when a dev server is active. This code path always spins up a new NetlifyDev instance and proceeds to db.reset() without checking for that state, so the known corruption case is still user-reachable. Please fail fast here until the command can coordinate with the running dev server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh interesting, the bot detected it as well. I'll address this in a follow-up, because it also affects the migrations.

Copy link

Choose a reason for hiding this comment

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

@paulo — Sounds good, thanks for confirming! Since this affects both db reset and migrations, it might be worth tracking as a GitHub issue so it doesn't get lost. Would you like me to open one for it?

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.

1 participant