Skip to content

feat(cli): add --migrations and --verbose flags to setup neon#1830

Open
lisa-assistant wants to merge 1 commit into
cedarjs:mainfrom
lisa-assistant:lisa/setup-neon-migrations-flag
Open

feat(cli): add --migrations and --verbose flags to setup neon#1830
lisa-assistant wants to merge 1 commit into
cedarjs:mainfrom
lisa-assistant:lisa/setup-neon-migrations-flag

Conversation

@lisa-assistant
Copy link
Copy Markdown
Contributor

What

Adds two new flags to yarn cedar setup neon and changes the default migration behavior:

Before: migrations always ran automatically after setup.

After: the command prompts whether to run migrations. The prompt can be bypassed with flags:

  • --migrations / --no-migrations — skip the prompt, run or skip migrations explicitly
  • --verbose / -v — pipe migration command stderr to stdout for better diagnostics (useful when debugging migration failures)

Changes

  • neon.ts: added --migrations (optional boolean, no default → prompts when absent) and --verbose (boolean, default false) to yargs builder and Args interface
  • neonHandler.ts:
    • Added import prompts from 'prompts' (already a dep of @cedarjs/cli)
    • Prompt user with a toggle before the task list runs
    • Migration task skip checks !runMigrations'Skipped (--no-migrations)'
    • Migration task stdio switches between 'inherit' (verbose) and ['inherit', 'inherit', 'pipe'] (non-verbose)
    • Error message omits captured stderr when verbose (since it already went to terminal)

- Prompt user whether to run Prisma migrations (instead of always running)
- Add --migrations boolean flag to skip the prompt; --no-migrations skips migrations
- Add --verbose flag to pipe stderr to stdout for better diagnostics
@netlify
Copy link
Copy Markdown

netlify Bot commented May 27, 2026

👷 Deploy request for cedarjs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit c2fddf0

@github-actions github-actions Bot added this to the next-release milestone May 27, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 27, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit c2fddf0

Command Status Duration Result
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 4s View ↗
nx run-many -t build ✅ Succeeded 5s View ↗
nx run-many -t test --minWorkers=1 --maxWorkers=4 ✅ Succeeded 1m 11s View ↗
nx run-many -t test:types ✅ Succeeded 7s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-27 09:58:00 UTC

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 27, 2026

Greptile Summary

This PR adds --migrations/--no-migrations and --verbose/-v flags to cedar setup neon, replacing the previous always-run migration behavior with an opt-in prompt or explicit flag. The docs in docs/implementation-docs/2026-03-26-cedarjs-project-overview.md remain factually correct — setup neon is still listed under setup, and the Prisma 7 version matches the pinned @prisma/adapter-pg@7.8.0 added by the handler.

  • neon.ts: declares --migrations (optional boolean, no default) and --verbose (default false) in the yargs builder and Args interface, and forwards them to the handler.
  • neonHandler.ts: resolves runMigrations from the flag or a prompts toggle before the Listr task list runs; the migration task's skip callback and stdio/error-message logic branch on these values.

Confidence Score: 3/5

The command can silently abort mid-run in CI; needs a non-TTY guard before merging.

The prompt-before-tasks placement means that in any environment where stdin is not a TTY (CI pipelines, scripted deployments), prompts immediately returns an empty object, response.runMigrations is undefined, and the handler calls process.exit(0) — silently — after Neon provisioning and .env writes have already completed. The database ends up provisioned but un-migrated with no error signal, a meaningful regression from the previous always-migrate default for automated workflows.

packages/cli/src/commands/setup/neon/neonHandler.ts — specifically the prompt block and its non-TTY handling around lines 47–61

Important Files Changed

Filename Overview
packages/cli/src/commands/setup/neon/neonHandler.ts Adds interactive migration prompt and verbose stdio plumbing; the ctrl-c / non-TTY exit path silently aborts setup after provisioning has already run in CI environments
packages/cli/src/commands/setup/neon/neon.ts Adds --migrations (optional boolean) and --verbose/-v flags to yargs builder and Args interface; flag wiring is correct, minor inaccuracy in --verbose description

Reviews (1): Last reviewed commit: "feat(cli): add --migrations and --verbos..." | Re-trigger Greptile

Comment on lines +47 to +61
if (runMigrations === undefined) {
const response = await prompts({
type: 'toggle',
name: 'runMigrations',
message: 'Run Prisma migrations now?',
initial: true,
active: 'Yes',
inactive: 'No',
})
// prompts returns undefined for the value if the user ctrl-c's
if (response.runMigrations === undefined) {
process.exit(0)
}
runMigrations = response.runMigrations
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Silent exit in non-interactive (CI) environments

When migrations is not provided and stdin is not a TTY — the typical case in CI — prompts returns an empty object {} immediately, so response.runMigrations is undefined. The code then calls process.exit(0), silently aborting setup after all earlier tasks (schema switch, adapter update, Neon provisioning, .env write) have already completed. A CI pipeline that relied on migrations running automatically will now silently exit with code 0 partway through, leaving the database un-migrated with no diagnostic output.

A safe guard would be to detect a non-TTY stdin before calling prompts and either default to true or exit with a clear error message instructing the caller to pass --migrations or --no-migrations explicitly.

Comment on lines +366 to +368
if (!runMigrations) {
return 'Skipped (--no-migrations)'
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 The skip message 'Skipped (--no-migrations)' is displayed even when the user simply answered "No" to the interactive prompt rather than passing the flag. A user who answered the prompt will see a message that implies they used a command-line flag they never typed, which is confusing.

Suggested change
if (!runMigrations) {
return 'Skipped (--no-migrations)'
}
if (!runMigrations) {
return migrations === false
? 'Skipped (--no-migrations)'
: 'Skipped'
}

.option('verbose', {
alias: 'v',
default: false,
description: 'Show full output from migration commands (stderr → stdout)',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 The description says "stderr → stdout" but the implementation uses stdio: 'inherit', which keeps stderr on the parent's stderr stream — it does not redirect it to stdout. A reader of --help output would expect the two streams to be merged, but that's not what happens.

Suggested change
description: 'Show full output from migration commands (stderr → stdout)',
description: 'Show full output from migration commands (stderr visible in terminal)',

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