feat: restructure db command files#8175
Conversation
📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughThis pull request refactors the database command module structure by reorganizing files into Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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: 1
🧹 Nitpick comments (3)
src/commands/database/util/migrations-path.ts (1)
5-11: Remove explanatory comments and rely on naming.Lines 5-11 describe behavior inline; this conflicts with the repository style rule for TS/JS files.
♻️ Suggested cleanup
-// Default on-disk location for migration files, relative to the project root. -// Can be overridden by setting `db.migrations.path` in `netlify.toml`. export const DEFAULT_MIGRATIONS_PATH = 'netlify/database/migrations' - -// Resolves the absolute path of the project's migrations directory. Prefers -// the `db.migrations.path` override from `netlify.toml` when present; falls -// back to `<project-root>/netlify/database/migrations`. export const resolveMigrationsDirectory = (command: BaseCommand): string => {As per coding guidelines,
**/*.{ts,tsx,js,jsx}: 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/util/migrations-path.ts` around lines 5 - 11, Remove the explanatory block comments above DEFAULT_MIGRATIONS_PATH and the resolver function so the file relies on self-documenting names; specifically delete the multi-line comment describing default location and resolution behavior and keep only the exported constant DEFAULT_MIGRATIONS_PATH (and the resolver code if present) so the implementation reads cleanly without inline "what it does" comments.tests/unit/commands/database/db-status.test.ts (1)
90-105: Consider adding one explicit fallback-path test.Because the helper defaults
migrationsPathinto config, most tests won’t exerciseresolveMigrationsDirectoryfallback behavior. Add one case withmigrationsPath: nulland assert the default path (/project/netlify/database/migrations) is used.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/commands/database/db-status.test.ts` around lines 90 - 105, The tests never exercise the fallback in resolveMigrationsDirectory because createMockCommand seeds config.migrations by default; add one unit test that calls createMockCommand({ migrationsPath: null }) and invokes the code path that calls resolveMigrationsDirectory (the db-status command test harness) and assert the resolved migrations directory equals '/project/netlify/database/migrations'; reference the helper createMockCommand and the resolver resolveMigrationsDirectory (or the db-status execution function) so the new test explicitly verifies the fallback behavior.tests/unit/commands/database/db-migrate.test.ts (1)
82-89: Error-message assertion can be tightened for this path change.This test currently only matches
'No migrations directory found'. Consider also asserting'netlify/database/migrations'so the new standardized default-path guidance is protected against regression.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/commands/database/db-migrate.test.ts` around lines 82 - 89, Update the unit test in db-migrate.test.ts that calls migrate({}, command) so the rejection assertion checks for the more specific error message including the standardized path; change the expect(...).rejects.toThrow('No migrations directory found') to assert the message includes both 'No migrations directory found' and the default path string 'netlify/database/migrations' (e.g., toThrow matching that combined text) so the failure protects against regressions to the default path guidance in the migrate function.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/commands/database/db-migrate.ts`:
- Around line 20-24: The error message is misleading because the code only uses
command.netlify.config.db?.migrations?.path (migrationsDirectory) and throws
even when the DEFAULT_MIGRATIONS_PATH exists; update the logic in db-migrate.ts
to resolve a fallback by checking the filesystem for DEFAULT_MIGRATIONS_PATH
when command.netlify.config.db?.migrations?.path is undefined or empty, set
migrationsDirectory to that default if it exists, and only throw the current
Error (mentioning DEFAULT_MIGRATIONS_PATH) if neither the configured path nor
the default folder is present; reference the migrationsDirectory variable,
DEFAULT_MIGRATIONS_PATH constant, and command.netlify.config access to locate
where to implement the filesystem existence check and fallback assignment.
---
Nitpick comments:
In `@src/commands/database/util/migrations-path.ts`:
- Around line 5-11: Remove the explanatory block comments above
DEFAULT_MIGRATIONS_PATH and the resolver function so the file relies on
self-documenting names; specifically delete the multi-line comment describing
default location and resolution behavior and keep only the exported constant
DEFAULT_MIGRATIONS_PATH (and the resolver code if present) so the implementation
reads cleanly without inline "what it does" comments.
In `@tests/unit/commands/database/db-migrate.test.ts`:
- Around line 82-89: Update the unit test in db-migrate.test.ts that calls
migrate({}, command) so the rejection assertion checks for the more specific
error message including the standardized path; change the
expect(...).rejects.toThrow('No migrations directory found') to assert the
message includes both 'No migrations directory found' and the default path
string 'netlify/database/migrations' (e.g., toThrow matching that combined text)
so the failure protects against regressions to the default path guidance in the
migrate function.
In `@tests/unit/commands/database/db-status.test.ts`:
- Around line 90-105: The tests never exercise the fallback in
resolveMigrationsDirectory because createMockCommand seeds config.migrations by
default; add one unit test that calls createMockCommand({ migrationsPath: null
}) and invokes the code path that calls resolveMigrationsDirectory (the
db-status command test harness) and assert the resolved migrations directory
equals '/project/netlify/database/migrations'; reference the helper
createMockCommand and the resolver resolveMigrationsDirectory (or the db-status
execution function) so the new test explicitly verifies the fallback behavior.
🪄 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: 52f889cf-7bd6-42ff-b21a-343bc042cba0
📒 Files selected for processing (25)
src/commands/database/database.tssrc/commands/database/db-connect.tssrc/commands/database/db-migrate.tssrc/commands/database/db-migration-new.tssrc/commands/database/db-migration-pull.tssrc/commands/database/db-reset.tssrc/commands/database/db-status.tssrc/commands/database/legacy/constants.tssrc/commands/database/legacy/db-init.tssrc/commands/database/legacy/db-status.tssrc/commands/database/legacy/drizzle.tssrc/commands/database/legacy/types.tssrc/commands/database/legacy/utils.tssrc/commands/database/util/applied-migrations.tssrc/commands/database/util/constants.tssrc/commands/database/util/db-connection.tssrc/commands/database/util/meta-commands.tssrc/commands/database/util/migrations-path.tssrc/commands/database/util/pg-client-executor.tssrc/commands/database/util/psql-formatter.tstests/unit/commands/database/db-migrate.test.tstests/unit/commands/database/db-migration-new.test.tstests/unit/commands/database/db-migration-pull.test.tstests/unit/commands/database/db-reset.test.tstests/unit/commands/database/db-status.test.ts
💤 Files with no reviewable changes (1)
- src/commands/database/legacy/constants.ts
| const migrationsDirectory = command.netlify.config.db?.migrations?.path | ||
| if (!migrationsDirectory) { | ||
| throw new Error( | ||
| 'No migrations directory found. Create a directory at netlify/db/migrations or set `db.migrations.path` in `netlify.toml`.', | ||
| `No migrations directory found. Create a directory at ${DEFAULT_MIGRATIONS_PATH} or set \`db.migrations.path\` in \`netlify.toml\`.`, | ||
| ) |
There was a problem hiding this comment.
Default-path guidance is misleading without actual fallback resolution.
At Line 20, the command only reads db.migrations.path from config, but Line 23 tells users to create ${DEFAULT_MIGRATIONS_PATH}. A project with only the default folder (and no config key) still errors here.
Suggested fix
-import { DEFAULT_MIGRATIONS_PATH } from './util/migrations-path.js'
+import { resolveMigrationsDirectory } from './util/migrations-path.js'
@@
- const migrationsDirectory = command.netlify.config.db?.migrations?.path
- if (!migrationsDirectory) {
- throw new Error(
- `No migrations directory found. Create a directory at ${DEFAULT_MIGRATIONS_PATH} or set \`db.migrations.path\` in \`netlify.toml\`.`,
- )
- }
+ const migrationsDirectory = resolveMigrationsDirectory(command)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/commands/database/db-migrate.ts` around lines 20 - 24, The error message
is misleading because the code only uses
command.netlify.config.db?.migrations?.path (migrationsDirectory) and throws
even when the DEFAULT_MIGRATIONS_PATH exists; update the logic in db-migrate.ts
to resolve a fallback by checking the filesystem for DEFAULT_MIGRATIONS_PATH
when command.netlify.config.db?.migrations?.path is undefined or empty, set
migrationsDirectory to that default if it exists, and only throw the current
Error (mentioning DEFAULT_MIGRATIONS_PATH) if neither the configured path nor
the default folder is present; reference the migrationsDirectory variable,
DEFAULT_MIGRATIONS_PATH constant, and command.netlify.config access to locate
where to implement the filesystem existence check and fallback assignment.
🤖 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>
Separates the legacy
dbcommands from the new ones.