feat: add db migrations reset command#8177
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds a new Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/commands/database/db-migrations-reset.ts (1)
19-23: Remove explanatory comments fromLocalMigration.Line 19–Line 23 narrate the type fields; please rely on field naming/type shape instead.
As per coding guidelines, "Never write comments on what the code does; make the code clean and self-explanatory instead".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/commands/database/db-migrations-reset.ts` around lines 19 - 23, Remove the explanatory inline comments above the LocalMigration type's fields so the interface is self-descriptive; specifically delete the two comment lines describing the "name" and "path" fields and leave the declarations (name: string, path: string) intact in the LocalMigration definition.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/unit/commands/database/db-migrate.test.ts`:
- Around line 103-114: The assertions use literal POSIX strings which fail on
Windows; update the test to build expected paths OS-agnostically by using
path.join or path.normalize when asserting calls to mockExistsSync and
mockApplyMigrations so they match the value produced by migrate(); specifically
replace '/project/netlify/database/migrations' with path.join('/project',
'netlify', 'database', 'migrations') (or normalize the actual and expected) in
the test that invokes migrate() and checks mockExistsSync and
mockApplyMigrations.
In `@tests/unit/commands/database/db-migrations-reset.test.ts`:
- Around line 109-112: The test currently compares rmPaths to hardcoded POSIX
strings which fail on Windows; update the expectations in
db-migrations-reset.test.ts to construct platform-normalized paths using
path.resolve(...) (e.g. replace the literal
'/project/netlify/database/migrations/0003_c' and similar entries with
path.resolve('project', 'netlify', 'database', 'migrations', '0003_c')) so the
deep-equality checks for rmPaths succeed cross-platform; apply the same
normalization for the other two assertion locations referenced in the comment
(the arrays around lines 110–111, 130–131, and 220–221) and ensure path is
imported from 'path' if not already.
---
Nitpick comments:
In `@src/commands/database/db-migrations-reset.ts`:
- Around line 19-23: Remove the explanatory inline comments above the
LocalMigration type's fields so the interface is self-descriptive; specifically
delete the two comment lines describing the "name" and "path" fields and leave
the declarations (name: string, path: string) intact in the LocalMigration
definition.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3a549c32-d20a-42d2-a8b6-2eae5b00a5c9
📒 Files selected for processing (8)
src/commands/database/database.tssrc/commands/database/db-migrate.tssrc/commands/database/db-migration-pull.tssrc/commands/database/db-migrations-reset.tssrc/commands/database/util/constants.tstests/unit/commands/database/db-migrate.test.tstests/unit/commands/database/db-migration-pull.test.tstests/unit/commands/database/db-migrations-reset.test.ts
| migrationsCommand | ||
| .command('reset') | ||
| .description('Delete local migration files that have not been applied yet') | ||
| .option('-b, --branch <branch>', 'Target a remote preview branch instead of the local development database') | ||
| .option('--json', 'Output result as JSON') | ||
| .action(async (options: MigrationsResetOptions, command: BaseCommand) => { | ||
| const { migrationsReset } = await import('./db-migrations-reset.js') | ||
| await migrationsReset(options, command) | ||
| }) | ||
| .addExamples(['netlify db migrations reset', 'netlify db migrations reset --branch my-feature-branch']) |
There was a problem hiding this comment.
| migrationsCommand | |
| .command('reset') | |
| .description('Delete local migration files that have not been applied yet') | |
| .option('-b, --branch <branch>', 'Target a remote preview branch instead of the local development database') | |
| .option('--json', 'Output result as JSON') | |
| .action(async (options: MigrationsResetOptions, command: BaseCommand) => { | |
| const { migrationsReset } = await import('./db-migrations-reset.js') | |
| await migrationsReset(options, command) | |
| }) | |
| .addExamples(['netlify db migrations reset', 'netlify db migrations reset --branch my-feature-branch']) | |
| migrationsCommand | |
| .command('reset') | |
| .description('Delete local migration files that have not been applied yet') | |
| .option('-b, --branch <branch>', 'Target a remote branch instead of the local development database') | |
| .option('--json', 'Output result as JSON') | |
| .action(async (options: MigrationsResetOptions, command: BaseCommand) => { | |
| const { migrationsReset } = await import('./db-migrations-reset.js') | |
| await migrationsReset(options, command) | |
| }) | |
| .addExamples(['netlify db migrations reset', 'netlify db migrations reset --branch my-feature-branch', 'netlify db migrations reset --branch production']) |
I don't exactly suggest this (I'm struggling on exact wording) - but just to sync with the removal of the production branch check removal.
Can be done in follow up
There was a problem hiding this comment.
looking at command like migrations pull - it also seem like you can do just --branch there (and it would use production) and maybe some wording for handling those cases can be borrowed here
🤖 I have created a release *beep* *boop* --- ## [25.1.0](v25.0.1...v25.1.0) (2026-04-21) ### Features * add `db migrations reset` command ([#8177](#8177)) ([3dd0f38](3dd0f38)) * add `db status` command ([#8173](#8173)) ([9bccaf9](9bccaf9)) * Add deploy_source to CLI deploy requests (EX-2032) ([#8155](#8155)) ([289933d](289933d)) * restructure db command files ([#8175](#8175)) ([794c2e0](794c2e0)) * support `NETLIFY_DB_BRANCH` env var in `db status` command ([#8174](#8174)) ([5647420](5647420)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>
No description provided.