Skip to content

fix: don't use inquirer for non-interactive variant of "database migrations new" command#8232

Merged
pieh merged 5 commits intomainfrom
fix/qol-new-migrations-non-interactive
May 4, 2026
Merged

fix: don't use inquirer for non-interactive variant of "database migrations new" command#8232
pieh merged 5 commits intomainfrom
fix/qol-new-migrations-non-interactive

Conversation

@pieh
Copy link
Copy Markdown
Contributor

@pieh pieh commented May 4, 2026

🎉 Thanks for submitting a pull request! 🎉

Summary

Main goal here is to avoid using inquirer in non-interactive mode.

I did smuggle in here preference to using timestamp numbering schema over sequential as it is less problematic when working on parallel changes. We still will honor sequential and default to it if this is a scheme already used by a project. This part is optimistic and can walk it back if deemed undesirable.

Currently non-interactive works only when both --scheme and --description is provided:

> netlify database migrations new --description "test" --scheme timestamp  < /dev/null
Created migration: 20260504084016_test
  /Users/misiek/test/pgs-test-init/netlify/database/migrations/20260504084016_test/migration.sql

But if they are not - there is non-helpful error happening:

> netlify database migrations new --description "test" < /dev/null
? Numbering scheme: (Use arrow keys)
❯ Sequential (0001, 0002, ...) 
  Timestamp (20260312143000) Warning: Detected unsettled top-level await at file:///Users/misiek/.nvm/versions/node/v24.0.0/lib/node_modules/netlify-cli/bin/run.js:87
  await main()
  ^

> netlify database migrations new --scheme timestamp < /dev/null
? What is the purpose of this migration? Warning: Detected unsettled top-level await at file:///Users/misiek/.nvm/versions/node/v24.0.0/lib/node_modules/netlify-cli/bin/run.js:87
  await main()

With changes in this PR:

  • we get more meaningful error for missing --description:
> ntl_local database migrations new --scheme timestamp < /dev/null
 ›   Error: --description <description> argument is required when not running interactively. Provide a description of the migration (e.g. --description "add users table").
  • we default to a scheme that is already used in a project (or default to timestamp if no migrations exist yet)
# if no migrations or timestamps used before
> ntl_local database migrations new --description "test"  < /dev/null
Created migration: 20260504084320_test
  /Users/misiek/test/pgs-test-init/netlify/database/migrations/20260504084320_test/migration.sql

# if sequential migrations used before
> ntl_local database migrations new --description "test2"  < /dev/null
Created migration: 0002_test2
  /Users/misiek/test/pgs-test-init/netlify/database/migrations/0002_test2/migration.sql

For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@pieh pieh requested a review from a team as a code owner May 4, 2026 08:45
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cdb936a7-57f9-4d77-a4c6-91c223f809c7

📥 Commits

Reviewing files that changed from the base of the PR and between 1d10f7e and 42457b1.

📒 Files selected for processing (1)
  • src/commands/database/db-migration-new.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/commands/database/db-migration-new.ts

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Non-interactive migration command now errors when required fields (like description) are missing instead of prompting; non-interactive runs default to a detected or timestamp scheme.
  • Tests

    • Added interactive and non-interactive tests covering prompting, erroring, and migration-folder naming.
  • Documentation

    • Reordered displayed scheme choices to list timestamp before sequential.

Walkthrough

Reorders the --scheme option choices for database migrations new so timestamp appears before sequential. migrationNew now imports and uses isInteractive() to branch: when non-interactive, missing description causes an error and missing scheme is set to detectedScheme ?? 'timestamp' without prompting; when interactive, missing values are prompted via Inquirer (with scheme defaulting to detectedScheme ?? 'timestamp'). Tests were added/updated to mock isInteractive and cover both interactive and non-interactive flows. Documentation updated to reflect the reordered --scheme choices.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: preventing inquirer usage in non-interactive mode for the database migrations command.
Description check ✅ Passed The description is directly related to the changeset, explaining the motivation (avoiding inquirer in non-interactive mode), the problems solved, and providing concrete examples of the improved behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/qol-new-migrations-non-interactive

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

📊 Benchmark results

Comparing with c94f4b7

  • Dependency count: 1,061 (no change)
  • Package size: 357 MB ⬆️ 0.00% increase vs. c94f4b7
  • Number of ts-expect-error directives: 355 (no change)

Copy link
Copy Markdown
Contributor

@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

🤖 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-migration-new.ts`:
- Around line 92-108: Update the unit tests so isInteractive can be mocked and
tests cover both branches: add a top-level vi.mock for the module exporting
isInteractive in tests/unit/commands/database/db-migration-new.test.ts, then in
the interactive-path tests set the mocked isInteractive to return true before
requiring or invoking the command so the inquirer.prompt branch runs (and assert
prompt is called and description used), and add a new test that sets
isInteractive to false and asserts the command throws the non-interactive error
(matching the new thrown Error message). Ensure you reference/mock the same
exported symbol isInteractive and keep existing assertions for inquirer.prompt
in the interactive tests.
🪄 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: d166b081-998b-429d-a107-cc9cbb822097

📥 Commits

Reviewing files that changed from the base of the PR and between c94f4b7 and 5419ae4.

📒 Files selected for processing (2)
  • src/commands/database/database.ts
  • src/commands/database/db-migration-new.ts

Comment thread src/commands/database/db-migration-new.ts
@pieh pieh requested a review from a team as a code owner May 4, 2026 09:08
eduardoboucas
eduardoboucas previously approved these changes May 4, 2026
Comment thread src/commands/database/db-migration-new.ts Outdated
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
@pieh pieh merged commit 41fc777 into main May 4, 2026
52 of 54 checks passed
@pieh pieh deleted the fix/qol-new-migrations-non-interactive branch May 4, 2026 10:46
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.

2 participants