-
-
Notifications
You must be signed in to change notification settings - Fork 26
feat(cli): add --migrations and --verbose flags to setup neon #1830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ import path from 'node:path' | |||||||||||||||||
|
|
||||||||||||||||||
| import execa from 'execa' | ||||||||||||||||||
| import { Listr } from 'listr2' | ||||||||||||||||||
| import prompts from 'prompts' | ||||||||||||||||||
|
|
||||||||||||||||||
| import { colors, getPaths, installPackages } from '@cedarjs/cli-helpers' | ||||||||||||||||||
| import { addWorkspacePackages } from '@cedarjs/cli-helpers/packageManager/packages' | ||||||||||||||||||
|
|
@@ -12,7 +13,7 @@ import type { Args } from './neon.js' | |||||||||||||||||
|
|
||||||||||||||||||
| const cedarPaths = getPaths() | ||||||||||||||||||
|
|
||||||||||||||||||
| export async function handler({ force }: Args) { | ||||||||||||||||||
| export async function handler({ force, migrations, verbose }: Args) { | ||||||||||||||||||
| const schemaPath = path.join(cedarPaths.api.base, 'db', 'schema.prisma') | ||||||||||||||||||
| const dbTsPath = path.join(cedarPaths.api.src, 'lib', 'db.ts') | ||||||||||||||||||
| const prismaConfigPathCjs = path.join( | ||||||||||||||||||
|
|
@@ -41,6 +42,24 @@ export async function handler({ force }: Args) { | |||||||||||||||||
|
|
||||||||||||||||||
| const notes: string[] = [] | ||||||||||||||||||
|
|
||||||||||||||||||
| // Resolve whether to run migrations: flag > prompt | ||||||||||||||||||
| let runMigrations = migrations | ||||||||||||||||||
| 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 | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+47
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When A safe guard would be to detect a non-TTY stdin before calling |
||||||||||||||||||
|
|
||||||||||||||||||
| const tasks = new Listr( | ||||||||||||||||||
| [ | ||||||||||||||||||
| { | ||||||||||||||||||
|
|
@@ -344,6 +363,10 @@ export async function handler({ force }: Args) { | |||||||||||||||||
| return true | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (!runMigrations) { | ||||||||||||||||||
| return 'Skipped (--no-migrations)' | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+366
to
+368
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| if (ctx.skipWithNote) { | ||||||||||||||||||
| return 'DATABASE_URL already configured — skipping migration' | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -363,7 +386,9 @@ export async function handler({ force }: Args) { | |||||||||||||||||
| 'yarn cedar prisma migrate dev --name init-neon', | ||||||||||||||||||
| { | ||||||||||||||||||
| cwd: cedarPaths.base, | ||||||||||||||||||
| stdio: ['inherit', 'inherit', 'pipe'], | ||||||||||||||||||
| stdio: verbose | ||||||||||||||||||
| ? 'inherit' | ||||||||||||||||||
| : ['inherit', 'inherit', 'pipe'], | ||||||||||||||||||
| reject: false, | ||||||||||||||||||
| env: { | ||||||||||||||||||
| ...process.env, | ||||||||||||||||||
|
|
@@ -374,10 +399,13 @@ export async function handler({ force }: Args) { | |||||||||||||||||
|
|
||||||||||||||||||
| if (result.exitCode !== 0) { | ||||||||||||||||||
| throw new Error( | ||||||||||||||||||
| 'Prisma migration failed:\n\n' + | ||||||||||||||||||
| result.stderr + | ||||||||||||||||||
| '\n\nYou can try running it manually:\n' + | ||||||||||||||||||
| ' yarn cedar prisma migrate dev --name init-neon', | ||||||||||||||||||
| verbose | ||||||||||||||||||
| ? 'Prisma migration failed. You can try running it manually:\n' + | ||||||||||||||||||
| ' yarn cedar prisma migrate dev --name init-neon' | ||||||||||||||||||
| : 'Prisma migration failed:\n\n' + | ||||||||||||||||||
| result.stderr + | ||||||||||||||||||
| '\n\nYou can try running it manually:\n' + | ||||||||||||||||||
| ' yarn cedar prisma migrate dev --name init-neon', | ||||||||||||||||||
| ) | ||||||||||||||||||
| } | ||||||||||||||||||
| }, | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stdio: 'inherit', which keeps stderr on the parent's stderr stream — it does not redirect it to stdout. A reader of--helpoutput would expect the two streams to be merged, but that's not what happens.