@prisma/cli 3.0.0-dev.70.1 → 3.0.0-dev.71.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -65,7 +65,7 @@ function createDeployCommand(runtime) {
65
65
  "hono",
66
66
  "tanstack-start",
67
67
  "bun"
68
- ])).addOption(new Option("--entry <path>", "Entrypoint path for Bun deploys")).addOption(new Option("--http-port <port>", "HTTP port override for the deployed app")).addOption(new Option("--env <name=value|file>", "Environment variable assignment or dotenv file").argParser(collectRepeatableValues)).addOption(new Option("--db", "Create and wire an isolated database for the preview Branch")).addOption(new Option("--no-db", "Skip branch database setup")).addOption(new Option("--prod", "Confirm intent to deploy to production"));
68
+ ])).addOption(new Option("--entry <path>", "Entrypoint path for Bun deploys")).addOption(new Option("--http-port <port>", "HTTP port override for the deployed app")).addOption(new Option("--env <name=value|file>", "Environment variable assignment or dotenv file").argParser(collectRepeatableValues)).addOption(new Option("--db", "Create and wire a Prisma Postgres database for this deploy target")).addOption(new Option("--no-db", "Skip database setup")).addOption(new Option("--prod", "Confirm intent to deploy to production"));
69
69
  addGlobalFlags(command);
70
70
  command.action(async (options) => {
71
71
  const appName = options.app;
@@ -80,7 +80,7 @@ function createDeployCommand(runtime) {
80
80
  const db = options.db;
81
81
  const hasDbConflict = hasFlag(runtime.argv, "--db") && hasFlag(runtime.argv, "--no-db");
82
82
  await runCommand(runtime, "app.deploy", options, (context) => {
83
- if (hasDbConflict) throw usageError("app deploy accepts either --db or --no-db", "--db requests branch database setup, while --no-db disables it.", "Pass exactly one database setup flag.", ["prisma-cli app deploy --db", "prisma-cli app deploy --no-db"], "app");
83
+ if (hasDbConflict) throw usageError("app deploy accepts either --db or --no-db", "--db requests database setup, while --no-db disables it.", "Pass exactly one database setup flag.", ["prisma-cli app deploy --db", "prisma-cli app deploy --no-db"], "app");
84
84
  return runAppDeploy(context, appName, {
85
85
  projectRef,
86
86
  createProjectName,
@@ -162,7 +162,7 @@ async function runAppDeploy(context, appName, options) {
162
162
  });
163
163
  framework = customized.framework;
164
164
  runtime = customized.runtime;
165
- await enforceProductionDeployGate(context, provider, {
165
+ const productionDeployGate = await enforceProductionDeployGate(context, provider, {
166
166
  appId: selectedApp.appId,
167
167
  appName: selectedApp.displayName,
168
168
  branchKind: target.branch.kind,
@@ -180,7 +180,8 @@ async function runAppDeploy(context, appName, options) {
180
180
  const portMapping = parseDeployPortMapping(String(runtime.port));
181
181
  const branchDatabaseSetup = await maybeSetupBranchDatabase(context, provider, projectId, toBranchDatabaseDeployBranch(target.branch), {
182
182
  db: options?.db,
183
- providedEnvVars: envVars
183
+ providedEnvVars: envVars,
184
+ firstProductionDeploy: productionDeployGate.firstProductionDeploy
184
185
  });
185
186
  const progressState = createPreviewDeployProgressState();
186
187
  const deployStartedAt = Date.now();
@@ -9,65 +9,65 @@ import path from "node:path";
9
9
  async function maybeSetupBranchDatabase(context, provider, projectId, branch, options) {
10
10
  if (options.db === false) return emptyBranchDatabaseSetupOutcome();
11
11
  if (hasProvidedDatabaseEnvVars(options.providedEnvVars)) {
12
- if (options.db === true) throw usageError("Branch database setup cannot be combined with provided database env vars", "The deploy command received --db and a DATABASE_URL or DIRECT_URL value from --env.", "Remove the --env database value to let --db create a branch override, or remove --db to deploy with the provided value.", ["prisma-cli app deploy --db", "prisma-cli app deploy --env DATABASE_URL=postgresql://example"], "app");
12
+ if (options.db === true) throw usageError("Database setup cannot be combined with provided database env vars", "The deploy command received --db and a DATABASE_URL or DIRECT_URL value from --env.", "Remove the --env database value to let --db create and wire a database, or remove --db to deploy with the provided value.", ["prisma-cli app deploy --db", "prisma-cli app deploy --env DATABASE_URL=postgresql://example"], "app");
13
13
  return emptyBranchDatabaseSetupOutcome();
14
14
  }
15
- if (branch.kind === "production") {
16
- if (options.db === true) throw usageError("Branch database setup is only available for preview branches", "Production database wiring is a durable environment decision and is not created implicitly by app deploy.", "Use project env commands to manage production DATABASE_URL, or deploy a preview branch with --db.", ["prisma-cli project env add DATABASE_URL=<value> --role production", "prisma-cli app deploy --branch feature/db --db"], "app");
15
+ if (branch.kind === "production" && !options.firstProductionDeploy) {
16
+ if (options.db === true) throw productionDatabaseSetupAfterFirstDeployError();
17
17
  return emptyBranchDatabaseSetupOutcome();
18
18
  }
19
- const localSignal = await inspectBranchDatabaseSignal(context.runtime.cwd, context.runtime.signal);
20
- const envState = await inspectBranchDatabaseEnv(provider, projectId, branch.id, context.runtime.signal);
21
- const branchEnvVars = [envState.branchDatabaseUrl, envState.branchDirectUrl].filter((variable) => Boolean(variable)).map((variable) => variable.key).sort();
22
- if (envState.branchDatabaseUrl) {
23
- const warning = options.db === true ? `Branch "${branch.name}" already has DATABASE_URL. Leaving branch database env vars unchanged.` : null;
19
+ const envState = await inspectBranchDatabaseEnv(provider, projectId, branch, context.runtime.signal);
20
+ const targetEnvVars = getTargetDatabaseEnvVarKeys(envState);
21
+ if (hasExistingDatabaseEnvForTarget(branch, envState)) {
22
+ const warning = options.db === true ? existingDatabaseEnvWarning(branch, targetEnvVars) : null;
24
23
  if (warning) emitBranchDatabaseWarning(context, warning);
25
24
  return {
26
25
  result: options.db === true ? {
27
26
  status: "skipped",
28
- reason: "branch-env-exists",
29
- envVars: branchEnvVars,
27
+ reason: existingDatabaseEnvReason(branch),
28
+ envVars: targetEnvVars,
30
29
  schema: null
31
30
  } : void 0,
32
31
  warnings: warning ? [warning] : []
33
32
  };
34
33
  }
34
+ const localSignal = await inspectBranchDatabaseSignal(context.runtime.cwd, context.runtime.signal);
35
35
  if (localSignal.unsupportedSchema) {
36
- if (options.db === true) throw unsupportedBranchDatabaseSchemaError(localSignal.unsupportedSchema, branch.name, context);
36
+ if (options.db === true) throw unsupportedBranchDatabaseSchemaError(localSignal.unsupportedSchema, branch, context);
37
37
  return emptyBranchDatabaseSetupOutcome();
38
38
  }
39
- const hasSignal = hasBranchDatabaseSignal(localSignal) || Boolean(envState.previewDatabaseUrl);
39
+ const hasSignal = hasBranchDatabaseSignal(localSignal) || Boolean(envState.inheritedPreviewDatabaseUrl);
40
40
  if (options.db !== true) {
41
41
  if (!hasSignal) return emptyBranchDatabaseSetupOutcome();
42
42
  if (!canPrompt(context) || context.flags.yes) {
43
- const warning = "This app appears to use DATABASE_URL. Run prisma-cli app deploy --db to create an isolated database for this preview branch.";
43
+ const warning = databasePromptSuppressedWarning(branch);
44
44
  emitBranchDatabaseWarning(context, warning);
45
45
  return {
46
46
  result: void 0,
47
47
  warnings: [warning]
48
48
  };
49
49
  }
50
- maybeRenderBranchDatabaseSignal(context, branch.name, localSignal, envState);
50
+ maybeRenderBranchDatabaseSignal(context, branch, localSignal, envState);
51
51
  if (!await confirmPrompt({
52
52
  input: context.runtime.stdin,
53
53
  output: context.output.stderr,
54
- message: `Create an isolated database for branch "${branch.name}"?`,
54
+ message: databasePromptMessage(branch),
55
55
  initialValue: false
56
56
  })) return emptyBranchDatabaseSetupOutcome();
57
- }
57
+ } else if (!canPrompt(context) && !context.flags.yes) throw nonInteractiveDatabaseSetupRequiresYesError(branch);
58
58
  return setupBranchDatabase(context, provider, projectId, branch, localSignal, envState);
59
59
  }
60
60
  async function setupBranchDatabase(context, provider, projectId, branch, signal, envState) {
61
- emitBranchDatabaseProgress(context, "pending", "Creating branch database");
61
+ emitBranchDatabaseProgress(context, "pending", "Creating database");
62
62
  const database = await provider.createBranchDatabase({
63
63
  projectId,
64
64
  branchId: branch.id,
65
65
  branchName: branch.name,
66
66
  signal: context.runtime.signal
67
67
  }).catch((error) => {
68
- throw branchDatabaseSetupFailedError("Failed to create branch database", error, branch.name);
68
+ throw branchDatabaseSetupFailedError("Failed to create database", error, branch);
69
69
  });
70
- emitBranchDatabaseProgress(context, "success", "Created branch database");
70
+ emitBranchDatabaseProgress(context, "success", "Created database");
71
71
  try {
72
72
  let schemaSetup = null;
73
73
  const warnings = [];
@@ -80,12 +80,12 @@ async function setupBranchDatabase(context, provider, projectId, branch, signal,
80
80
  databaseUrl: database.databaseUrl,
81
81
  directUrl: database.directUrl
82
82
  }).catch((error) => {
83
- throw schemaSetupFailedError(error, signal.schema, branch.name, context.runtime.cwd);
83
+ throw schemaSetupFailedError(error, signal.schema, branch, context.runtime.cwd);
84
84
  });
85
85
  emitBranchDatabaseProgress(context, "success", "Applied database schema");
86
- } else skippedSchemaWarning = "No supported Prisma schema source was found. Branch database env vars were created, but schema setup was skipped.";
86
+ } else skippedSchemaWarning = "No supported Prisma schema source was found. Database env vars were created, but schema setup was skipped.";
87
87
  const envVars = await upsertBranchDatabaseEnvVars(context, provider, projectId, branch, database, envState);
88
- emitBranchDatabaseProgress(context, "success", `Added branch env override${envVars.length === 1 ? "" : "s"} ${envVars.join(", ")}`);
88
+ emitBranchDatabaseProgress(context, "success", `Added ${envScopeLabel(branch)} env var${envVars.length === 1 ? "" : "s"} ${envVars.join(", ")}`);
89
89
  if (skippedSchemaWarning) {
90
90
  emitBranchDatabaseWarning(context, skippedSchemaWarning);
91
91
  warnings.push(skippedSchemaWarning);
@@ -107,37 +107,36 @@ async function setupBranchDatabase(context, provider, projectId, branch, signal,
107
107
  warnings
108
108
  };
109
109
  } catch (error) {
110
- throw await cleanupCreatedBranchDatabaseAfterFailure(context, provider, database, branch.name, error);
110
+ throw await cleanupCreatedBranchDatabaseAfterFailure(context, provider, database, branch, error);
111
111
  }
112
112
  }
113
113
  async function upsertBranchDatabaseEnvVars(context, provider, projectId, branch, database, envState) {
114
+ const scope = envScopeForBranch(branch);
114
115
  const written = [];
115
116
  await upsertBranchDatabaseEnvVar(context, provider, {
116
117
  projectId,
117
- branchId: branch.id,
118
- className: "preview",
118
+ ...scope,
119
119
  key: "DATABASE_URL",
120
120
  value: database.databaseUrl,
121
- existing: envState.branchDatabaseUrl,
122
- branchName: branch.name
121
+ existing: envState.targetDatabaseUrl,
122
+ branch
123
123
  });
124
124
  written.push("DATABASE_URL");
125
125
  if (database.directUrl) {
126
126
  await upsertBranchDatabaseEnvVar(context, provider, {
127
127
  projectId,
128
- branchId: branch.id,
129
- className: "preview",
128
+ ...scope,
130
129
  key: "DIRECT_URL",
131
130
  value: database.directUrl,
132
- existing: envState.branchDirectUrl,
133
- branchName: branch.name
131
+ existing: envState.targetDirectUrl,
132
+ branch
134
133
  });
135
134
  written.push("DIRECT_URL");
136
- } else if (envState.branchDirectUrl) await provider.deleteEnvironmentVariable({
137
- envVarId: envState.branchDirectUrl.id,
135
+ } else if (branch.kind === "preview" && envState.targetDirectUrl) await provider.deleteEnvironmentVariable({
136
+ envVarId: envState.targetDirectUrl.id,
138
137
  signal: context.runtime.signal
139
138
  }).catch((error) => {
140
- throw branchDatabaseSetupFailedError("Failed to remove stale DIRECT_URL", error, branch.name);
139
+ throw branchDatabaseSetupFailedError("Failed to remove stale DIRECT_URL", error, branch);
141
140
  });
142
141
  return written;
143
142
  }
@@ -148,37 +147,39 @@ async function upsertBranchDatabaseEnvVar(context, provider, options) {
148
147
  value: options.value,
149
148
  signal: context.runtime.signal
150
149
  }).catch((error) => {
151
- throw branchDatabaseSetupFailedError(`Failed to update ${options.key}`, error, options.branchName);
150
+ throw branchDatabaseSetupFailedError(`Failed to update ${options.key}`, error, options.branch);
152
151
  });
153
152
  return;
154
153
  }
155
154
  await provider.createEnvironmentVariable({
156
155
  projectId: options.projectId,
157
- branchId: options.branchId,
158
156
  className: options.className,
159
157
  key: options.key,
160
158
  value: options.value,
159
+ ...options.branchId ? { branchId: options.branchId } : {},
161
160
  signal: context.runtime.signal
162
161
  }).catch((error) => {
163
- throw branchDatabaseSetupFailedError(`Failed to write ${options.key}`, error, options.branchName);
162
+ throw branchDatabaseSetupFailedError(`Failed to write ${options.key}`, error, options.branch);
164
163
  });
165
164
  }
166
- async function inspectBranchDatabaseEnv(provider, projectId, branchId, signal) {
165
+ async function inspectBranchDatabaseEnv(provider, projectId, branch, signal) {
166
+ const scope = envScopeForBranch(branch);
167
167
  const [databaseUrlRows, directUrlRows] = await Promise.all([provider.listEnvironmentVariables({
168
168
  projectId,
169
- className: "preview",
169
+ className: scope.className,
170
170
  key: "DATABASE_URL",
171
171
  signal
172
172
  }), provider.listEnvironmentVariables({
173
173
  projectId,
174
- className: "preview",
174
+ className: scope.className,
175
175
  key: "DIRECT_URL",
176
176
  signal
177
177
  })]);
178
+ const targetBranchId = branch.kind === "preview" ? branch.id : null;
178
179
  return {
179
- branchDatabaseUrl: findEnvVar(databaseUrlRows, { branchId }),
180
- branchDirectUrl: findEnvVar(directUrlRows, { branchId }),
181
- previewDatabaseUrl: findEnvVar(databaseUrlRows, { branchId: null })
180
+ targetDatabaseUrl: findEnvVar(databaseUrlRows, { branchId: targetBranchId }),
181
+ targetDirectUrl: findEnvVar(directUrlRows, { branchId: targetBranchId }),
182
+ inheritedPreviewDatabaseUrl: branch.kind === "preview" ? findEnvVar(databaseUrlRows, { branchId: null }) : null
182
183
  };
183
184
  }
184
185
  function findEnvVar(rows, options) {
@@ -187,14 +188,47 @@ function findEnvVar(rows, options) {
187
188
  function hasProvidedDatabaseEnvVars(envVars) {
188
189
  return Boolean(envVars && ("DATABASE_URL" in envVars || "DIRECT_URL" in envVars));
189
190
  }
190
- function maybeRenderBranchDatabaseSignal(context, branchName, signal, envState) {
191
+ function envScopeForBranch(branch) {
192
+ return branch.kind === "production" ? { className: "production" } : {
193
+ className: "preview",
194
+ branchId: branch.id
195
+ };
196
+ }
197
+ function envScopeLabel(branch) {
198
+ return branch.kind === "production" ? "production" : "branch";
199
+ }
200
+ function getTargetDatabaseEnvVarKeys(envState) {
201
+ return [envState.targetDatabaseUrl, envState.targetDirectUrl].filter((variable) => Boolean(variable)).map((variable) => variable.key).sort();
202
+ }
203
+ function hasExistingDatabaseEnvForTarget(branch, envState) {
204
+ if (branch.kind === "production") return Boolean(envState.targetDatabaseUrl || envState.targetDirectUrl);
205
+ return Boolean(envState.targetDatabaseUrl);
206
+ }
207
+ function existingDatabaseEnvReason(branch) {
208
+ return branch.kind === "production" ? "production-env-exists" : "branch-env-exists";
209
+ }
210
+ function existingDatabaseEnvWarning(branch, envVars) {
211
+ if (branch.kind === "production") return `Production already has ${envVars.join(" and ")}. Treating it as BYO database configuration and leaving env vars unchanged.`;
212
+ return `Branch "${branch.name}" already has DATABASE_URL. Leaving branch database env vars unchanged.`;
213
+ }
214
+ function databasePromptSuppressedWarning(branch) {
215
+ if (branch.kind === "production") return "This app appears to use DATABASE_URL. Run prisma-cli app deploy --db --yes to create and wire a Prisma Postgres database for this first production deploy.";
216
+ return "This app appears to use DATABASE_URL. Run prisma-cli app deploy --db to create an isolated database for this preview branch.";
217
+ }
218
+ function databasePromptMessage(branch) {
219
+ return branch.kind === "production" ? "Create a Prisma Postgres database for production?" : `Create an isolated database for branch "${branch.name}"?`;
220
+ }
221
+ function maybeRenderBranchDatabaseSignal(context, branch, signal, envState) {
191
222
  if (context.flags.json || context.flags.quiet) return;
192
223
  const rows = [
193
224
  signal.schema ? ` Schema ${path.relative(context.runtime.cwd, signal.schema.path) || defaultSchemaSourcePath(signal.schema)}` : null,
194
225
  signal.databaseUrlReferences.length > 0 ? ` Code ${signal.databaseUrlReferences.slice(0, 3).join(", ")}` : null,
195
- envState.previewDatabaseUrl ? " Env preview DATABASE_URL is inherited by this branch" : null
226
+ envState.inheritedPreviewDatabaseUrl ? " Env preview DATABASE_URL is inherited by this branch" : null
196
227
  ].filter((row) => Boolean(row));
197
- context.output.stderr.write(`Database signal found for branch "${branchName}"\n${rows.join("\n")}\n\n`);
228
+ context.output.stderr.write(`Database signal found for ${databaseTargetLabel(branch)}\n${rows.join("\n")}\n\n`);
229
+ }
230
+ function databaseTargetLabel(branch) {
231
+ return branch.kind === "production" ? `production branch "${branch.name}"` : `branch "${branch.name}"`;
198
232
  }
199
233
  function emitBranchDatabaseProgress(context, status, message) {
200
234
  if (context.flags.json || context.flags.quiet) return;
@@ -211,6 +245,12 @@ function emptyBranchDatabaseSetupOutcome() {
211
245
  warnings: []
212
246
  };
213
247
  }
248
+ function productionDatabaseSetupAfterFirstDeployError() {
249
+ return usageError("Database setup is only available during the first production deploy", "The selected production app already has a live deployment.", "Use project env commands to manage production DATABASE_URL, or deploy a preview branch with --db.", ["prisma-cli project env add DATABASE_URL=<value> --role production", "prisma-cli app deploy --branch feature/db --db"], "app");
250
+ }
251
+ function nonInteractiveDatabaseSetupRequiresYesError(branch) {
252
+ return usageError("Database setup requires --yes in non-interactive mode", "The deploy command received --db, but prompts are not available and --yes was not passed.", "Pass --yes together with --db to confirm non-interactive database creation.", [branch.kind === "production" ? "prisma-cli app deploy --prod --db --yes" : `prisma-cli app deploy --branch ${formatCommandArgument(branch.name)} --db --yes`], "app");
253
+ }
214
254
  function formatSchemaSetupCommand(command) {
215
255
  switch (command) {
216
256
  case "migrate-deploy": return "prisma migrate deploy";
@@ -218,46 +258,46 @@ function formatSchemaSetupCommand(command) {
218
258
  case "prisma-next-db-init": return "prisma-next db init";
219
259
  }
220
260
  }
221
- function branchDatabaseSetupFailedError(summary, error, branchName) {
261
+ function branchDatabaseSetupFailedError(summary, error, branch) {
222
262
  return new CliError({
223
263
  code: "BRANCH_DATABASE_SETUP_FAILED",
224
264
  domain: "app",
225
265
  summary,
226
266
  why: error instanceof Error ? error.message : String(error),
227
- fix: "Retry the command, or create the branch database and env vars manually with project env commands.",
267
+ fix: "Retry the command, or create the database and env vars manually with project env commands.",
228
268
  debug: formatDebugDetails(error),
229
- meta: { branch: branchName },
269
+ meta: { branch: branch.name },
230
270
  exitCode: 1,
231
- nextSteps: [`prisma-cli app deploy --branch ${formatCommandArgument(branchName)} --db`, `prisma-cli project env list --branch ${formatCommandArgument(branchName)}`]
271
+ nextSteps: [formatAppDeployWithDbNextStep(branch), formatProjectEnvListNextStep(branch)]
232
272
  });
233
273
  }
234
- async function cleanupCreatedBranchDatabaseAfterFailure(context, provider, database, branchName, error) {
235
- const setupError = error instanceof CliError ? error : branchDatabaseSetupFailedError("Branch database setup failed", error, branchName);
236
- emitBranchDatabaseProgress(context, "pending", "Removing branch database after setup failed");
274
+ async function cleanupCreatedBranchDatabaseAfterFailure(context, provider, database, branch, error) {
275
+ const setupError = error instanceof CliError ? error : branchDatabaseSetupFailedError("Database setup failed", error, branch);
276
+ emitBranchDatabaseProgress(context, "pending", "Removing database after setup failed");
237
277
  try {
238
278
  await provider.deleteBranchDatabase({
239
279
  databaseId: database.id,
240
280
  signal: context.runtime.signal
241
281
  });
242
- emitBranchDatabaseProgress(context, "success", "Removed branch database after setup failed");
282
+ emitBranchDatabaseProgress(context, "success", "Removed database after setup failed");
243
283
  } catch (cleanupError) {
244
- return branchDatabaseCleanupFailedError(setupError, cleanupError, database, branchName);
284
+ return branchDatabaseCleanupFailedError(setupError, cleanupError, database, branch);
245
285
  }
246
286
  return setupError;
247
287
  }
248
- function branchDatabaseCleanupFailedError(setupError, cleanupError, database, branchName) {
288
+ function branchDatabaseCleanupFailedError(setupError, cleanupError, database, branch) {
249
289
  const cleanupWhy = cleanupError instanceof Error ? cleanupError.message : String(cleanupError);
250
- const setupWhy = setupError.why ?? "Branch database setup failed.";
290
+ const setupWhy = setupError.why ?? "Database setup failed.";
251
291
  return new CliError({
252
292
  code: setupError.code,
253
293
  domain: setupError.domain,
254
294
  summary: setupError.summary,
255
295
  why: `${setupWhy} Prisma could not delete the created database "${database.name}" (${database.id}): ${cleanupWhy}`,
256
- fix: "Delete the created branch database from Console or contact Prisma support, then rerun deploy with --db.",
296
+ fix: "Delete the created database from Console or contact Prisma support, then rerun deploy with --db.",
257
297
  debug: formatCombinedDebugDetails(setupError, cleanupError),
258
298
  meta: {
259
299
  ...setupError.meta,
260
- branch: branchName,
300
+ branch: branch.name,
261
301
  databaseId: database.id,
262
302
  databaseName: database.name,
263
303
  cleanupFailed: true
@@ -266,7 +306,7 @@ function branchDatabaseCleanupFailedError(setupError, cleanupError, database, br
266
306
  nextSteps: []
267
307
  });
268
308
  }
269
- function schemaSetupFailedError(error, schema, branchName, cwd) {
309
+ function schemaSetupFailedError(error, schema, branch, cwd) {
270
310
  return new CliError({
271
311
  code: "SCHEMA_SETUP_FAILED",
272
312
  domain: "app",
@@ -275,17 +315,26 @@ function schemaSetupFailedError(error, schema, branchName, cwd) {
275
315
  fix: "Fix the Prisma schema or migrations, then rerun deploy with --db.",
276
316
  debug: formatDebugDetails(error),
277
317
  meta: {
278
- branch: branchName,
318
+ branch: branch.name,
279
319
  schemaPath: schema.path,
280
320
  source: schema.kind,
281
321
  command: schema.command
282
322
  },
283
323
  exitCode: 1,
284
- nextSteps: [...formatSchemaSetupNextSteps(schema, cwd), `prisma-cli app deploy --branch ${formatCommandArgument(branchName)} --db`]
324
+ nextSteps: [...formatSchemaSetupNextSteps(schema, cwd), formatAppDeployWithDbNextStep(branch)]
285
325
  });
286
326
  }
287
- function unsupportedBranchDatabaseSchemaError(schema, branchName, context) {
288
- return usageError("Branch database setup is not available for this Prisma schema", `${path.relative(context.runtime.cwd, schema.path) || defaultUnsupportedSchemaSourcePath(schema)} targets ${formatUnsupportedSchemaTarget(schema.target)}, but --db creates Prisma Postgres databases.`, "Use project env commands to provide a database URL for this branch, or switch the Prisma schema source to PostgreSQL before using --db.", [`prisma-cli project env add DATABASE_URL=<value> --branch ${formatCommandArgument(branchName)}`, `prisma-cli app deploy --branch ${formatCommandArgument(branchName)}`], "app");
327
+ function unsupportedBranchDatabaseSchemaError(schema, branch, context) {
328
+ return usageError("Database setup is not available for this Prisma schema", `${path.relative(context.runtime.cwd, schema.path) || defaultUnsupportedSchemaSourcePath(schema)} targets ${formatUnsupportedSchemaTarget(schema.target)}, but --db creates Prisma Postgres databases.`, "Use project env commands to provide a database URL, or switch the Prisma schema source to PostgreSQL before using --db.", [formatProjectEnvAddNextStep(branch), `prisma-cli app deploy --branch ${formatCommandArgument(branch.name)}`], "app");
329
+ }
330
+ function formatAppDeployWithDbNextStep(branch) {
331
+ return `prisma-cli app deploy --branch ${formatCommandArgument(branch.name)} --db`;
332
+ }
333
+ function formatProjectEnvListNextStep(branch) {
334
+ return branch.kind === "production" ? "prisma-cli project env list --role production" : `prisma-cli project env list --branch ${formatCommandArgument(branch.name)}`;
335
+ }
336
+ function formatProjectEnvAddNextStep(branch) {
337
+ return branch.kind === "production" ? "prisma-cli project env add DATABASE_URL=<value> --role production" : `prisma-cli project env add DATABASE_URL=<value> --branch ${formatCommandArgument(branch.name)}`;
289
338
  }
290
339
  function formatSchemaSetupNextSteps(schema, cwd) {
291
340
  const sourcePath = path.relative(cwd, schema.path) || defaultSchemaSourcePath(schema);
@@ -3,22 +3,22 @@ import { canPrompt } from "../../shell/runtime.js";
3
3
  import { confirmPrompt } from "../../shell/prompt.js";
4
4
  //#region src/lib/app/production-deploy-gate.ts
5
5
  async function enforceProductionDeployGate(context, provider, options) {
6
- if (options.branchKind !== "production") return;
6
+ if (options.branchKind !== "production") return { firstProductionDeploy: false };
7
7
  if (!options.appId) {
8
8
  renderFirstProductionDeployLine(context, options.appName);
9
- return;
9
+ return { firstProductionDeploy: true };
10
10
  }
11
11
  const currentLiveDeployment = resolveCurrentProductionDeployment(await provider.listDeployments(options.appId).catch((error) => {
12
12
  throw productionDeployInspectionFailedError(error);
13
13
  }));
14
14
  if (!currentLiveDeployment) {
15
15
  renderFirstProductionDeployLine(context, options.appName);
16
- return;
16
+ return { firstProductionDeploy: true };
17
17
  }
18
18
  if (!options.prod) throw productionDeployRequiresFlagError();
19
19
  if (context.flags.yes) {
20
20
  renderProductionDeployYesLine(context);
21
- return;
21
+ return { firstProductionDeploy: false };
22
22
  }
23
23
  if (!canPrompt(context)) throw productionDeployConfirmationRequiredError(options.appName);
24
24
  renderProductionDeployConfirmation(context, currentLiveDeployment);
@@ -28,6 +28,7 @@ async function enforceProductionDeployGate(context, provider, options) {
28
28
  message: "Deploy to production?",
29
29
  initialValue: false
30
30
  })) throw productionDeployCancelledError();
31
+ return { firstProductionDeploy: false };
31
32
  }
32
33
  function resolveCurrentProductionDeployment(result) {
33
34
  if (result.deployments.length === 0) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/cli",
3
- "version": "3.0.0-dev.70.1",
3
+ "version": "3.0.0-dev.71.1",
4
4
  "description": "Command-line interface for the Prisma Developer Platform.",
5
5
  "type": "module",
6
6
  "bin": {