gencow 0.1.269 → 0.1.271
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.
- package/lib/cli-command-runner.mjs +15 -2
- package/lib/cloud-target-environment.mjs +124 -0
- package/lib/cloud-targets.mjs +4 -0
- package/lib/db-command.mjs +15 -11
- package/lib/db-migration-command-steps.mjs +5 -2
- package/lib/db-push-command.mjs +14 -1
- package/lib/deploy-app-target.mjs +2 -0
- package/lib/deploy-command.mjs +11 -3
- package/lib/deploy-prod-target.mjs +1 -1
- package/lib/drizzle-generate.mjs +19 -0
- package/lib/env-command.mjs +45 -9
- package/lib/migration-advisory.mjs +2 -0
- package/lib/migration-diagnostic.mjs +33 -6
- package/lib/migration-rollback-cause.mjs +75 -0
- package/lib/migration-schema-load-failure.mjs +31 -0
- package/lib/prod-create-failure.mjs +9 -1
- package/lib/prod-create-region-diagnostic.mjs +86 -0
- package/lib/static-command.mjs +1 -1
- package/package.json +4 -4
- package/runtime/server.mjs +65 -65
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { formatProcedureRpcDiagnostic } from "./procedure-rpc-diagnostic.mjs";
|
|
2
2
|
import { describeMigrationFolderFormatFailure } from "./migration-folder-format.mjs";
|
|
3
|
+
import {
|
|
4
|
+
SCHEMA_LOAD_FAILURE_CAUSE_HINT,
|
|
5
|
+
SCHEMA_LOAD_FAILURE_CLI_ACTION,
|
|
6
|
+
SCHEMA_LOAD_FAILURE_CLI_MESSAGE,
|
|
7
|
+
} from "./migration-schema-load-failure.mjs";
|
|
3
8
|
import {
|
|
4
9
|
buildHintsRequiredCommand,
|
|
5
10
|
HINTS_DATA_LOSS_NOTICE,
|
|
@@ -43,12 +48,17 @@ const SAFE_LOCAL_ERROR_CODES = new Map([
|
|
|
43
48
|
message: (caught) =>
|
|
44
49
|
caught.migrationFolderFormat
|
|
45
50
|
? describeMigrationFolderFormatFailure(caught.migrationFolderFormat).cliMessage
|
|
46
|
-
:
|
|
51
|
+
: caught.migrationSchemaFailure
|
|
52
|
+
? SCHEMA_LOAD_FAILURE_CLI_MESSAGE
|
|
53
|
+
: "Migration generation failed: Drizzle could not generate migrations from schema.ts.",
|
|
47
54
|
stage: "migration",
|
|
55
|
+
detail: (caught) => (caught.migrationSchemaFailure ? SCHEMA_LOAD_FAILURE_CAUSE_HINT : null),
|
|
48
56
|
action: (caught) =>
|
|
49
57
|
caught.migrationFolderFormat
|
|
50
58
|
? describeMigrationFolderFormatFailure(caught.migrationFolderFormat).cliAction
|
|
51
|
-
:
|
|
59
|
+
: caught.migrationSchemaFailure
|
|
60
|
+
? SCHEMA_LOAD_FAILURE_CLI_ACTION
|
|
61
|
+
: "Retryable: no — fix the schema source, then rerun the command.",
|
|
52
62
|
},
|
|
53
63
|
],
|
|
54
64
|
[
|
|
@@ -277,6 +287,9 @@ function commandErrorMessage(caught) {
|
|
|
277
287
|
`Code: ${caught.code}`,
|
|
278
288
|
`Stage: ${localDiagnostic.stage}`,
|
|
279
289
|
];
|
|
290
|
+
const detail =
|
|
291
|
+
typeof localDiagnostic.detail === "function" ? localDiagnostic.detail(caught) : localDiagnostic.detail;
|
|
292
|
+
if (detail) lines.push(detail);
|
|
280
293
|
const location = safeSourceLocation(caught);
|
|
281
294
|
if (location) lines.push(`${localDiagnostic.locationLabel ?? "Source location"}: ${location}`);
|
|
282
295
|
const action =
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { readProjectAppTargets, resolveCloudAppTarget } from "./cloud-targets.mjs";
|
|
2
|
+
import { readJsonValueResponse } from "./http-response-json.mjs";
|
|
3
|
+
|
|
4
|
+
const SAFE_CORRELATION_ID = /^[A-Za-z0-9_-]{8,128}$/u;
|
|
5
|
+
const LOOKUP_FAILED_CODE = "APP_DEPLOY_TARGET_LOOKUP_FAILED";
|
|
6
|
+
|
|
7
|
+
// Reads the environment fact the server stores for an app (apps.get: environment "production" |
|
|
8
|
+
// "development", prodApp = the dev app's prod sibling). Used only when the project cannot tell us the
|
|
9
|
+
// environment, i.e. an explicit --app that this project does not bind.
|
|
10
|
+
export async function lookupAppEnvironment({ creds, appId, rpcQueryImpl }) {
|
|
11
|
+
let response;
|
|
12
|
+
try {
|
|
13
|
+
response = await rpcQueryImpl(creds, "apps.get", { name: appId });
|
|
14
|
+
} catch {
|
|
15
|
+
return { kind: "error", code: LOOKUP_FAILED_CODE, retryable: true };
|
|
16
|
+
}
|
|
17
|
+
const decoded = await readJsonValueResponse(response);
|
|
18
|
+
const body = decoded.parsed ? decoded.value : undefined;
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
const code = response.status === 401 ? "APP_RELEASE_AUTH_REQUIRED" : LOOKUP_FAILED_CODE;
|
|
21
|
+
const retryable = typeof body?.retryable === "boolean" ? body.retryable : response.status >= 500;
|
|
22
|
+
return {
|
|
23
|
+
kind: "error",
|
|
24
|
+
code,
|
|
25
|
+
status: response.status,
|
|
26
|
+
retryable,
|
|
27
|
+
...(typeof body?.correlationId === "string" && SAFE_CORRELATION_ID.test(body.correlationId)
|
|
28
|
+
? { correlationId: body.correlationId }
|
|
29
|
+
: {}),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// The RPC answers null for an app this account does not own or that does not exist.
|
|
33
|
+
if (body === null) return { kind: "missing" };
|
|
34
|
+
if (!body || typeof body !== "object" || Array.isArray(body) || body.name !== appId) {
|
|
35
|
+
return { kind: "error", code: LOOKUP_FAILED_CODE, status: response.status, retryable: false };
|
|
36
|
+
}
|
|
37
|
+
if (body.environment !== "production" && body.environment !== "development") {
|
|
38
|
+
return { kind: "error", code: LOOKUP_FAILED_CODE, status: response.status, retryable: false };
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
kind: "found",
|
|
42
|
+
environment: body.environment,
|
|
43
|
+
prodAppName: typeof body.prodApp?.name === "string" ? body.prodApp.name : null,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Same flag reading as resolveCloudAppTarget: the last --app value wins and any --prod selects prod.
|
|
48
|
+
function readExplicitTargetArgs(restArgs) {
|
|
49
|
+
let explicitAppId = null;
|
|
50
|
+
let prod = false;
|
|
51
|
+
for (let index = 0; index < restArgs.length; index += 1) {
|
|
52
|
+
if (restArgs[index] === "--app" || restArgs[index] === "-a") {
|
|
53
|
+
explicitAppId = restArgs[index + 1];
|
|
54
|
+
index += 1;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (restArgs[index] === "--prod") prod = true;
|
|
58
|
+
}
|
|
59
|
+
return { explicitAppId: typeof explicitAppId === "string" ? explicitAppId : null, prod };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function renderLookupFailure(failure, { stage, appId }) {
|
|
63
|
+
const lines = [
|
|
64
|
+
`Code: ${failure.code}`,
|
|
65
|
+
`Stage: ${stage}`,
|
|
66
|
+
`App ID: ${appId}`,
|
|
67
|
+
"Changed: nothing. No app, env value, or serving state was changed.",
|
|
68
|
+
`Retryable: ${failure.retryable ? "yes" : "no"}`,
|
|
69
|
+
];
|
|
70
|
+
if (failure.status) lines.push(`HTTP status: ${failure.status}`);
|
|
71
|
+
if (failure.correlationId) lines.push(`Correlation ID: ${failure.correlationId}`);
|
|
72
|
+
if (failure.code === "APP_RELEASE_AUTH_REQUIRED") {
|
|
73
|
+
lines.push("Next: gencow login, then retry the same command.");
|
|
74
|
+
} else if (failure.retryable) {
|
|
75
|
+
lines.push("Next: retry the same command after a short wait.");
|
|
76
|
+
} else {
|
|
77
|
+
lines.push("Next: gencow app list (confirm the app ID you own, then retry)");
|
|
78
|
+
}
|
|
79
|
+
return lines.join("\n");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Target resolution for a cloud command that may receive an explicit --app without a project app binding
|
|
83
|
+
// (no gencow.json, or one with no appId/prodApp). Any project that binds an app gets exactly
|
|
84
|
+
// resolveCloudAppTarget's result. Without a binding, the server's environment fact decides:
|
|
85
|
+
// - prod app: targets prod even without --prod, like a bound prod app inside the project;
|
|
86
|
+
// - dev app with --prod: the typed EXPLICIT_APP_NOT_PROD_APP rejection, nothing is requested;
|
|
87
|
+
// - lookup failure: a typed error with a next action, never a silent dev fallback.
|
|
88
|
+
// A missing app (null answer) keeps resolveCloudAppTarget's result so the command reports not-found.
|
|
89
|
+
export async function resolveCloudAppTargetWithServerEnvironment(restArgs, options = {}) {
|
|
90
|
+
const {
|
|
91
|
+
cwd = process.cwd(),
|
|
92
|
+
creds,
|
|
93
|
+
rpcQueryImpl,
|
|
94
|
+
stage = "target resolution",
|
|
95
|
+
command = "deploy",
|
|
96
|
+
} = options;
|
|
97
|
+
const base = resolveCloudAppTarget(restArgs, options);
|
|
98
|
+
if (base.error) return base;
|
|
99
|
+
|
|
100
|
+
const { explicitAppId, prod } = readExplicitTargetArgs(restArgs);
|
|
101
|
+
if (!explicitAppId) return base;
|
|
102
|
+
// A project that binds any app keeps the project's own rules unchanged, including for unrelated --app values.
|
|
103
|
+
const projectTargets = readProjectAppTargets(cwd);
|
|
104
|
+
if (projectTargets.appId || projectTargets.prodApp) return base;
|
|
105
|
+
|
|
106
|
+
const lookup = await lookupAppEnvironment({ creds, appId: explicitAppId, rpcQueryImpl });
|
|
107
|
+
if (lookup.kind === "error") {
|
|
108
|
+
return { error: renderLookupFailure(lookup, { stage, appId: explicitAppId }) };
|
|
109
|
+
}
|
|
110
|
+
if (lookup.kind === "missing") return base;
|
|
111
|
+
|
|
112
|
+
if (lookup.environment === "production") return { appId: explicitAppId, envTarget: "prod" };
|
|
113
|
+
if (!prod) return { appId: explicitAppId, envTarget: "dev" };
|
|
114
|
+
const next = lookup.prodAppName
|
|
115
|
+
? `gencow ${command} --app ${lookup.prodAppName} (this app's production app)`
|
|
116
|
+
: `gencow ${command} --app ${explicitAppId} (development app: drop --prod)`;
|
|
117
|
+
return {
|
|
118
|
+
error: `--app with --prod must name a production app, and ${explicitAppId} is a development app.`,
|
|
119
|
+
reason: "explicit_app_not_prod_app",
|
|
120
|
+
prodApp: null,
|
|
121
|
+
explicitAppId,
|
|
122
|
+
next,
|
|
123
|
+
};
|
|
124
|
+
}
|
package/lib/cloud-targets.mjs
CHANGED
|
@@ -57,6 +57,10 @@ export function resolveImplicitProdEnvironment({ explicitApp = false, envTarget
|
|
|
57
57
|
|
|
58
58
|
// Shared human message for a failed prod target; falls back to the call site's own text.
|
|
59
59
|
export function describeProdTargetFailure(result, fallbackMessage) {
|
|
60
|
+
if (result?.reason === "explicit_app_not_prod_app" && !result.prodApp) {
|
|
61
|
+
// Outside a project there is no prod binding to name; the server reported the app as development.
|
|
62
|
+
return "`--app` with `--prod` must name a production app, and this app is a development app.";
|
|
63
|
+
}
|
|
60
64
|
if (result?.reason === "explicit_app_not_prod_app") {
|
|
61
65
|
return `\`--app\` with \`--prod\` must name this project's prod app: ${result.prodApp}. Run again with --app ${result.prodApp} or without --app.`;
|
|
62
66
|
}
|
package/lib/db-command.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import { tmpdir } from "os";
|
|
|
16
16
|
import { createDbCheckCommand, createDbPushCommand } from "./db-push-command.mjs";
|
|
17
17
|
import { renderMaintenanceFailure } from "./db-seed-failure-render.mjs";
|
|
18
18
|
import { logEnvFileOperationWithType } from "./backend-env-resolver.mjs";
|
|
19
|
-
import { runDrizzleGenerateWithFallback } from "./drizzle-generate.mjs";
|
|
19
|
+
import { markMigrationSchemaLoadFailure, runDrizzleGenerateWithFallback } from "./drizzle-generate.mjs";
|
|
20
20
|
import { HINTS_DATA_LOSS_NOTICE, parseMigrationHintsArgs } from "./migration-hints.mjs";
|
|
21
21
|
import { BOLD, CYAN, DIM, GREEN, RED, RESET, error, info, log, success, warn } from "./output.mjs";
|
|
22
22
|
import {
|
|
@@ -571,16 +571,20 @@ export function createDbCommands({
|
|
|
571
571
|
logImpl(`\n${BOLD}${CYAN}Gencow DB Generate${RESET}\n`);
|
|
572
572
|
infoImpl("Generating migration files from schema.ts...");
|
|
573
573
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
574
|
+
try {
|
|
575
|
+
runDrizzleGenerateWithFallback({
|
|
576
|
+
cwd: cwdImpl(),
|
|
577
|
+
drizzleKitCmdImpl,
|
|
578
|
+
env: buildEnv(config),
|
|
579
|
+
execSyncImpl,
|
|
580
|
+
generatorArgs: hints.args,
|
|
581
|
+
spawnSyncImpl,
|
|
582
|
+
stdio: "inherit",
|
|
583
|
+
warnImpl,
|
|
584
|
+
});
|
|
585
|
+
} catch (error) {
|
|
586
|
+
throw markMigrationSchemaLoadFailure(error);
|
|
587
|
+
}
|
|
584
588
|
successImpl("Migration files generated in gencow/migrations/");
|
|
585
589
|
},
|
|
586
590
|
|
|
@@ -15,11 +15,14 @@ import { emitMigrationAdvisories, extractMigrationAdvisories } from "./migration
|
|
|
15
15
|
|
|
16
16
|
const NO_CHANGE_MARKERS = ["No schema changes", "nothing to migrate", "No changes detected"];
|
|
17
17
|
|
|
18
|
-
export function
|
|
19
|
-
const message = error?.stderr?.toString() || error?.message || "";
|
|
18
|
+
export function isNoChangeOutput(message) {
|
|
20
19
|
return NO_CHANGE_MARKERS.some((marker) => message.includes(marker));
|
|
21
20
|
}
|
|
22
21
|
|
|
22
|
+
export function isNoChangeGenerationError(error) {
|
|
23
|
+
return isNoChangeOutput(error?.stderr?.toString() || error?.message || "");
|
|
24
|
+
}
|
|
25
|
+
|
|
23
26
|
// Resolves to true (typed "yes"), false (any other answer), or null when input
|
|
24
27
|
// ended before an answer. Callers must treat null as a non-cancel failure.
|
|
25
28
|
export async function promptDbPushConfirm(appId, createInterfaceImpl, plain = false) {
|
package/lib/db-push-command.mjs
CHANGED
|
@@ -45,6 +45,7 @@ import {
|
|
|
45
45
|
handleLocalMigrationCommand,
|
|
46
46
|
handleMigrationStatus,
|
|
47
47
|
isNoChangeGenerationError,
|
|
48
|
+
isNoChangeOutput,
|
|
48
49
|
promptDbPushConfirm,
|
|
49
50
|
} from "./db-migration-command-steps.mjs";
|
|
50
51
|
import { resolveConfiguredSchemaPaths, resolveDrizzleSchemaPaths } from "./cli-schema-paths.mjs";
|
|
@@ -451,15 +452,27 @@ function createDbMigrationCommand(deps, command) {
|
|
|
451
452
|
if (!jsonMode) deps.infoImpl("Generating schema migrations...");
|
|
452
453
|
try {
|
|
453
454
|
const generationEnv = deps.buildEnv(config, { cwd: deps.cwdImpl() });
|
|
455
|
+
let generatorOutput = "";
|
|
454
456
|
generatorVersion = runDrizzleGenerateWithFallback({
|
|
455
457
|
cwd: deps.cwdImpl(),
|
|
456
458
|
drizzleKitCmdImpl: deps.drizzleKitCmdImpl,
|
|
457
459
|
env: generationEnv,
|
|
458
460
|
execSyncImpl: deps.execSyncImpl,
|
|
461
|
+
onOutput: (text) => {
|
|
462
|
+
generatorOutput += text;
|
|
463
|
+
},
|
|
459
464
|
stdio: jsonMode ? "pipe" : "inherit",
|
|
460
465
|
warnImpl: jsonMode ? () => {} : deps.warnImpl,
|
|
461
466
|
});
|
|
462
|
-
if (!jsonMode)
|
|
467
|
+
if (!jsonMode) {
|
|
468
|
+
// drizzle-kit exits 0 with "No schema changes" when nothing new was generated;
|
|
469
|
+
// the committed pending migrations are still applied by this push.
|
|
470
|
+
if (isNoChangeOutput(generatorOutput)) {
|
|
471
|
+
deps.infoImpl("No new migration generated — applying committed pending migrations");
|
|
472
|
+
} else {
|
|
473
|
+
deps.successImpl("Migrations generated");
|
|
474
|
+
}
|
|
475
|
+
}
|
|
463
476
|
} catch (error) {
|
|
464
477
|
generatorVersion = error?.gencowGeneratorVersion || generatorVersion;
|
|
465
478
|
if (isNoChangeGenerationError(error)) {
|
|
@@ -136,6 +136,8 @@ export function cloudTargetRejectionMessage(rejection, { fallbackMessage, ...opt
|
|
|
136
136
|
explicitAppId: rejection.explicitAppId,
|
|
137
137
|
rejection,
|
|
138
138
|
...options,
|
|
139
|
+
// A resolver that knows the exact next command (for example outside a project) overrides the caller's text.
|
|
140
|
+
...(rejection.next ? { next: rejection.next } : {}),
|
|
139
141
|
}).join("\n");
|
|
140
142
|
}
|
|
141
143
|
|
package/lib/deploy-command.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
selectAppDiagnosticLogLines,
|
|
7
7
|
} from "./app-diagnostics.mjs";
|
|
8
8
|
import { appNotFoundDiagnostic, parseAppLookupResponse } from "./app-response-contract.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import { resolveCloudAppTargetWithServerEnvironment } from "./cloud-target-environment.mjs";
|
|
10
10
|
import { cloudTargetRejectionMessage, prodRetryCommandLine } from "./deploy-app-target.mjs";
|
|
11
11
|
import { readJsonValueResponse } from "./http-response-json.mjs";
|
|
12
12
|
import { renderDeployFailureDiagnosticLines } from "./deploy-failure-diagnostic.mjs";
|
|
@@ -151,8 +151,12 @@ export async function handleDeployReadonlySubcommand(params) {
|
|
|
151
151
|
const targetArgs = deployArgs
|
|
152
152
|
.slice(1)
|
|
153
153
|
.filter((arg, index, list) => arg !== "--release-attempt" && list[index - 1] !== "--release-attempt");
|
|
154
|
-
const target =
|
|
154
|
+
const target = await resolveCloudAppTargetWithServerEnvironment(targetArgs, {
|
|
155
155
|
cwd,
|
|
156
|
+
creds,
|
|
157
|
+
rpcQueryImpl,
|
|
158
|
+
stage: "deploy target resolution",
|
|
159
|
+
command: "deploy status",
|
|
156
160
|
missingAppMessage: "App not found. Run from the project root with gencow.json.",
|
|
157
161
|
missingProdMessage: "No prod app yet. Run gencow deploy --prod first.",
|
|
158
162
|
});
|
|
@@ -235,8 +239,12 @@ export async function handleDeployReadonlySubcommand(params) {
|
|
|
235
239
|
logDeploymentOperationStatus(logImpl, infoImpl, body);
|
|
236
240
|
return true;
|
|
237
241
|
}
|
|
238
|
-
const target =
|
|
242
|
+
const target = await resolveCloudAppTargetWithServerEnvironment(deployArgs.slice(1), {
|
|
239
243
|
cwd,
|
|
244
|
+
creds,
|
|
245
|
+
rpcQueryImpl,
|
|
246
|
+
stage: "deploy target resolution",
|
|
247
|
+
command: `deploy ${subcmd}`,
|
|
240
248
|
missingAppMessage: "App not found. Run from the project root with gencow.json.",
|
|
241
249
|
missingProdMessage: "No prod app yet. Run gencow deploy --prod first.",
|
|
242
250
|
});
|
|
@@ -109,7 +109,7 @@ export async function ensureProductionDeployTarget({
|
|
|
109
109
|
logImpl(` ${GREEN}gencow upgrade${RESET} ${DIM}← Upgrade to Startup${RESET}`);
|
|
110
110
|
logImpl("");
|
|
111
111
|
} else {
|
|
112
|
-
errorImpl(prodCreateFailureMessage(errData, createProdRes));
|
|
112
|
+
errorImpl(prodCreateFailureMessage(errData, createProdRes, { requestedRegion: region }));
|
|
113
113
|
}
|
|
114
114
|
exitImpl(1);
|
|
115
115
|
return null;
|
package/lib/drizzle-generate.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
createMigrationHintsRequiredError,
|
|
10
10
|
MIGRATION_HINTS_REQUIRED,
|
|
11
11
|
} from "./migration-hints.mjs";
|
|
12
|
+
import { classifySchemaLoadFailure } from "./migration-schema-load-failure.mjs";
|
|
12
13
|
|
|
13
14
|
export const SUPPORTED_DRIZZLE_KIT_GENERATOR_VERSION = SUPPORTED_MIGRATION_GENERATOR_VERSION;
|
|
14
15
|
export const UNKNOWN_DRIZZLE_KIT_GENERATOR_VERSION = "unknown";
|
|
@@ -136,6 +137,21 @@ function getMissingHintsFailure(error) {
|
|
|
136
137
|
return classifyMissingHintsOutput(rawGeneratorOutput(error));
|
|
137
138
|
}
|
|
138
139
|
|
|
140
|
+
// db:generate only. Runs after the hints and folder-format judgments, so an error that already
|
|
141
|
+
// carries a code keeps it. Other callers keep the generic path they had before.
|
|
142
|
+
export function markMigrationSchemaLoadFailure(error) {
|
|
143
|
+
if (!error || typeof error !== "object" || error.code) return error;
|
|
144
|
+
const schemaFailure = classifySchemaLoadFailure(rawGeneratorOutput(error));
|
|
145
|
+
if (!schemaFailure) return error;
|
|
146
|
+
try {
|
|
147
|
+
error.code = "MIGRATION_GENERATION_FAILED";
|
|
148
|
+
error.migrationSchemaFailure = schemaFailure;
|
|
149
|
+
} catch {
|
|
150
|
+
/* keep the raw generator error; the schema-load code is then unavailable */
|
|
151
|
+
}
|
|
152
|
+
return error;
|
|
153
|
+
}
|
|
154
|
+
|
|
139
155
|
export function buildMigrationGenerationError(error) {
|
|
140
156
|
if (error?.code === MIGRATION_HINTS_REQUIRED && error.migrationHints) {
|
|
141
157
|
return createMigrationHintsRequiredError(error.migrationHints);
|
|
@@ -166,6 +182,7 @@ export function runDrizzleGenerateWithFallback({
|
|
|
166
182
|
env = {},
|
|
167
183
|
execSyncImpl,
|
|
168
184
|
generatorArgs = [],
|
|
185
|
+
onOutput,
|
|
169
186
|
spawnSyncImpl = spawnSync,
|
|
170
187
|
stderrWriteImpl = (value) => process.stderr.write(value),
|
|
171
188
|
stdio = "inherit",
|
|
@@ -199,6 +216,8 @@ export function runDrizzleGenerateWithFallback({
|
|
|
199
216
|
});
|
|
200
217
|
throw failure;
|
|
201
218
|
}
|
|
219
|
+
// Successful runs can still report "No schema changes"; expose that output to callers.
|
|
220
|
+
onOutput?.(`${rawStdout}\n${rawStderr}`);
|
|
202
221
|
if (stdio === "inherit") {
|
|
203
222
|
const stdout = sanitizeDrizzleGeneratorOutput(rawStdout, { cwd });
|
|
204
223
|
const stderr = sanitizeDrizzleGeneratorOutput(rawStderr, { cwd });
|
package/lib/env-command.mjs
CHANGED
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
resolveBackendEnvFile,
|
|
7
7
|
resolveExplicitEnvFile,
|
|
8
8
|
} from "./backend-env-resolver.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import { resolveCloudAppTargetWithServerEnvironment } from "./cloud-target-environment.mjs";
|
|
10
10
|
import { cloudTargetRejectionMessage, prodRetryCommandLine, redactConfigSetValue, redactEnvPairs } from "./deploy-app-target.mjs";
|
|
11
11
|
import { BOLD, CYAN, DIM, GREEN, RESET, error, info, log, success, warn } from "./output.mjs";
|
|
12
|
-
import { platformFetch, requireCreds } from "./platform-client.mjs";
|
|
12
|
+
import { platformFetch, requireCreds, rpcQuery } from "./platform-client.mjs";
|
|
13
13
|
|
|
14
14
|
const ENV_RESPONSE_UNREADABLE_CODE = "ENV_RESPONSE_UNREADABLE";
|
|
15
15
|
|
|
@@ -66,6 +66,23 @@ function targetedNextAction(nextAction, appId, envTarget) {
|
|
|
66
66
|
return `${nextAction} ${envTargetFlags(appId, envTarget)}`;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Renders the safe ACK miss kind from the API. Only the kind and the two integer
|
|
71
|
+
* revisions can appear; any other shape is dropped rather than printed.
|
|
72
|
+
*/
|
|
73
|
+
function formatEnvMismatch(mismatch) {
|
|
74
|
+
if (!mismatch || typeof mismatch !== "object" || typeof mismatch.kind !== "string") return null;
|
|
75
|
+
if (!/^[A-Z_]{1,40}$/u.test(mismatch.kind)) return null;
|
|
76
|
+
if (mismatch.kind !== "REVISION_BEHIND" && mismatch.kind !== "REVISION_AHEAD") {
|
|
77
|
+
return `Mismatch: ${mismatch.kind}`;
|
|
78
|
+
}
|
|
79
|
+
// The API does not record the process revision yet, so an actual revision is shown only when present.
|
|
80
|
+
const parts = [];
|
|
81
|
+
if (Number.isSafeInteger(mismatch.expectedRevision)) parts.push(`expected revision ${mismatch.expectedRevision}`);
|
|
82
|
+
if (Number.isSafeInteger(mismatch.actualRevision)) parts.push(`actual revision ${mismatch.actualRevision}`);
|
|
83
|
+
return parts.length > 0 ? `Mismatch: ${mismatch.kind} (${parts.join(", ")})` : `Mismatch: ${mismatch.kind}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
69
86
|
function envListCommand(appId, envTarget) {
|
|
70
87
|
return `gencow env list ${envTargetFlags(appId, envTarget)}`;
|
|
71
88
|
}
|
|
@@ -141,7 +158,8 @@ export function createEnvCommand(deps = {}) {
|
|
|
141
158
|
const cwdImpl = deps.cwdImpl ?? (() => process.cwd());
|
|
142
159
|
const loadConfigImpl = deps.loadConfig ?? (async () => ({ rootDir: "./gencow", envFile: "./gencow/.env" }));
|
|
143
160
|
const readFileSyncImpl = deps.readFileSync ?? readFileSync;
|
|
144
|
-
const resolveAppTargetImpl = deps.resolveCloudAppTarget ??
|
|
161
|
+
const resolveAppTargetImpl = deps.resolveCloudAppTarget ?? resolveCloudAppTargetWithServerEnvironment;
|
|
162
|
+
const rpcQueryImpl = deps.rpcQuery ?? rpcQuery;
|
|
145
163
|
const resolvePathImpl = deps.resolvePathImpl ?? resolve;
|
|
146
164
|
const sleepImpl = deps.sleep ?? ((ms) => new Promise((resolveSleep) => setTimeout(resolveSleep, ms)));
|
|
147
165
|
const projectionPollAttempts = deps.projectionPollAttempts ?? 40;
|
|
@@ -200,6 +218,7 @@ export function createEnvCommand(deps = {}) {
|
|
|
200
218
|
typeof result.retryable === "boolean" ? `Retryable: ${result.retryable ? "yes" : "no"}` : null,
|
|
201
219
|
Number.isSafeInteger(Number(result.attemptCount)) ? `Attempts: ${Number(result.attemptCount)}` : null,
|
|
202
220
|
result.failureCode ? `Failure class: ${result.failureCode}` : null,
|
|
221
|
+
formatEnvMismatch(result.mismatch),
|
|
203
222
|
result.correlationId ? `Correlation: ${result.correlationId}` : null,
|
|
204
223
|
result.retryPrecondition ? `Retry precondition: ${result.retryPrecondition}` : null,
|
|
205
224
|
`Next action: ${nextAction}`,
|
|
@@ -221,6 +240,13 @@ export function createEnvCommand(deps = {}) {
|
|
|
221
240
|
return result.runtimeState === "failed" || result.statusQueryFailed === true ? 1 : 0;
|
|
222
241
|
}
|
|
223
242
|
|
|
243
|
+
// Backend-only tips (handler/restart guidance) apply only when some key reached
|
|
244
|
+
// a running backend. A set/unset whose every projected key ended not_running has
|
|
245
|
+
// no backend process to act on, so those tips would be inaccurate.
|
|
246
|
+
function onlyStaticProjections(runtimeStates) {
|
|
247
|
+
return runtimeStates.length > 0 && runtimeStates.every((state) => state === "not_running");
|
|
248
|
+
}
|
|
249
|
+
|
|
224
250
|
return async function env(...envArgs) {
|
|
225
251
|
const filteredArgs = envArgs.filter((arg) => arg !== "--local");
|
|
226
252
|
|
|
@@ -255,7 +281,11 @@ export function createEnvCommand(deps = {}) {
|
|
|
255
281
|
return;
|
|
256
282
|
}
|
|
257
283
|
const creds = requireCredsImpl();
|
|
258
|
-
const target = resolveAppTargetImpl(restArgs, {
|
|
284
|
+
const target = await resolveAppTargetImpl(restArgs, {
|
|
285
|
+
creds,
|
|
286
|
+
rpcQueryImpl,
|
|
287
|
+
stage: "env target resolution",
|
|
288
|
+
command: `env ${subcmd}`,
|
|
259
289
|
missingAppMessage: "App ID not found. Run gencow deploy first.",
|
|
260
290
|
missingProdMessage: "No prod app yet. Run gencow deploy --prod first.",
|
|
261
291
|
});
|
|
@@ -350,6 +380,7 @@ export function createEnvCommand(deps = {}) {
|
|
|
350
380
|
|
|
351
381
|
let appliedCount = 0;
|
|
352
382
|
let commandFailed = false;
|
|
383
|
+
const projectionStates = [];
|
|
353
384
|
for (const pair of pairs) {
|
|
354
385
|
const eqIdx = pair.indexOf("=");
|
|
355
386
|
if (eqIdx < 1) {
|
|
@@ -400,6 +431,7 @@ export function createEnvCommand(deps = {}) {
|
|
|
400
431
|
const mutation = await res.json().catch(() => ({}));
|
|
401
432
|
const projection = await waitForProjection(creds, appId, mutation, envTarget);
|
|
402
433
|
const projectionExitCode = renderProjectionResult(projection, appId, envTarget);
|
|
434
|
+
projectionStates.push(projection.runtimeState);
|
|
403
435
|
if (projectionExitCode === 0) {
|
|
404
436
|
success(`Stored ${BOLD}${name}${RESET} ${DIM}(cloud: ${appId}, ${envTarget})${RESET}`);
|
|
405
437
|
} else {
|
|
@@ -411,7 +443,7 @@ export function createEnvCommand(deps = {}) {
|
|
|
411
443
|
commandFailed = true;
|
|
412
444
|
}
|
|
413
445
|
}
|
|
414
|
-
if (appliedCount > 0) {
|
|
446
|
+
if (appliedCount > 0 && !onlyStaticProjections(projectionStates)) {
|
|
415
447
|
log(
|
|
416
448
|
`\n ${DIM}Runtime applied is reported only after the running process acknowledges the revision.${RESET}`,
|
|
417
449
|
);
|
|
@@ -432,6 +464,7 @@ export function createEnvCommand(deps = {}) {
|
|
|
432
464
|
return;
|
|
433
465
|
}
|
|
434
466
|
let commandFailed = false;
|
|
467
|
+
const projectionStates = [];
|
|
435
468
|
for (const rawKey of keys) {
|
|
436
469
|
const key = sanitizeCloudEnvKey(rawKey);
|
|
437
470
|
try {
|
|
@@ -453,6 +486,7 @@ export function createEnvCommand(deps = {}) {
|
|
|
453
486
|
const mutation = await res.json().catch(() => ({}));
|
|
454
487
|
const projection = await waitForProjection(creds, appId, mutation, envTarget);
|
|
455
488
|
const projectionExitCode = renderProjectionResult(projection, appId, envTarget);
|
|
489
|
+
projectionStates.push(projection.runtimeState);
|
|
456
490
|
if (projectionExitCode === 0) {
|
|
457
491
|
success(`Removed ${BOLD}${key}${RESET} ${DIM}(cloud: ${appId}, ${envTarget})${RESET}`);
|
|
458
492
|
} else {
|
|
@@ -463,10 +497,12 @@ export function createEnvCommand(deps = {}) {
|
|
|
463
497
|
commandFailed = true;
|
|
464
498
|
}
|
|
465
499
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
500
|
+
if (!onlyStaticProjections(projectionStates)) {
|
|
501
|
+
log(
|
|
502
|
+
`\n ${DIM}Runtime applied is reported only after the running process acknowledges the revision.${RESET}`,
|
|
503
|
+
);
|
|
504
|
+
log(` ${DIM}⚠ Platform-managed or startup-captured settings require restart/redeploy${RESET}\n`);
|
|
505
|
+
}
|
|
470
506
|
return commandFailed ? 1 : 0;
|
|
471
507
|
}
|
|
472
508
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const ADVISORY_SUMMARIES = Object.freeze({
|
|
2
2
|
MIGRATION_POTENTIAL_DATA_LOSS: "The pending migration may remove tenant data.",
|
|
3
|
+
MIGRATION_NOT_NULL_NO_DEFAULT_RISK:
|
|
4
|
+
"ADD COLUMN … NOT NULL without a DEFAULT fails if the table already has rows. Make the column nullable, add a DEFAULT, or use expand → backfill → contract.",
|
|
3
5
|
MIGRATION_LOCK_RISK: "The pending migration may take a blocking PostgreSQL lock.",
|
|
4
6
|
MIGRATION_COMPATIBILITY_RISK: "Coordinate this schema change with application rollout compatibility.",
|
|
5
7
|
MIGRATION_BACKUP_NOT_CREATED:
|
|
@@ -3,6 +3,15 @@ import { readFileSync, realpathSync } from "node:fs";
|
|
|
3
3
|
import { relative, resolve, sep } from "node:path";
|
|
4
4
|
import { escapeTerminalControls, safeDiagnosticText } from "./migration-diagnostic-contract.mjs";
|
|
5
5
|
import { formatLatestCliInvocation } from "./cli-update-guidance.mjs";
|
|
6
|
+
import {
|
|
7
|
+
UNLOCATED_ROLLBACK_DETAIL,
|
|
8
|
+
UNLOCATED_ROLLBACK_RETRY_CONDITION,
|
|
9
|
+
UNLOCATED_ROLLBACK_SUMMARY,
|
|
10
|
+
isUserFixableRolledBackDiagnostic,
|
|
11
|
+
renderRollbackCauseLine,
|
|
12
|
+
renderUnlocatedRollbackFix,
|
|
13
|
+
renderUnlocatedRollbackLocation,
|
|
14
|
+
} from "./migration-rollback-cause.mjs";
|
|
6
15
|
|
|
7
16
|
export {
|
|
8
17
|
extractActionableMigrationDiagnostic,
|
|
@@ -320,6 +329,12 @@ export function renderMigrationDiagnosticLines(diagnostic) {
|
|
|
320
329
|
lines.push(`Correlation: ${diagnostic.correlationId}`);
|
|
321
330
|
return lines.map((line) => escapeTerminalControls(line));
|
|
322
331
|
}
|
|
332
|
+
// Without a verified local span, the server's "exact statement" wording would overclaim.
|
|
333
|
+
const unlocatedRollback =
|
|
334
|
+
isUserFixableRolledBackDiagnostic(diagnostic) && !diagnostic.localSource?.projectRelativePath;
|
|
335
|
+
const retryCondition = unlocatedRollback
|
|
336
|
+
? UNLOCATED_ROLLBACK_RETRY_CONDITION
|
|
337
|
+
: diagnostic.retryCondition;
|
|
323
338
|
const lines = [
|
|
324
339
|
migrationDiagnosticTitle(diagnostic),
|
|
325
340
|
"",
|
|
@@ -327,7 +342,7 @@ export function renderMigrationDiagnosticLines(diagnostic) {
|
|
|
327
342
|
`Phase: ${diagnostic.phase}`,
|
|
328
343
|
`Database state: ${diagnostic.databaseState}`,
|
|
329
344
|
`Safe to retry now: ${diagnostic.safeToRetryNow ? "YES" : "NO"}`,
|
|
330
|
-
`Retry policy: ${diagnostic.retryPolicy}${
|
|
345
|
+
`Retry policy: ${diagnostic.retryPolicy}${retryCondition ? ` — ${retryCondition}` : ""}`,
|
|
331
346
|
];
|
|
332
347
|
const source = diagnostic.localSource;
|
|
333
348
|
if (source?.projectRelativePath) {
|
|
@@ -342,6 +357,10 @@ export function renderMigrationDiagnosticLines(diagnostic) {
|
|
|
342
357
|
} else if (diagnostic.migration?.name) {
|
|
343
358
|
lines.push("", `Migration: ${diagnostic.migration.name}`);
|
|
344
359
|
}
|
|
360
|
+
if (unlocatedRollback) {
|
|
361
|
+
if (diagnostic.migration?.name) lines.push(renderUnlocatedRollbackLocation(diagnostic));
|
|
362
|
+
else lines.push("", renderUnlocatedRollbackLocation(diagnostic));
|
|
363
|
+
}
|
|
345
364
|
if (diagnostic.operation?.kind) {
|
|
346
365
|
lines.push(
|
|
347
366
|
`Operation: ${diagnostic.operation.kind}${diagnostic.operation.objectName ? ` ${diagnostic.operation.objectName}` : ""}`,
|
|
@@ -349,12 +368,20 @@ export function renderMigrationDiagnosticLines(diagnostic) {
|
|
|
349
368
|
}
|
|
350
369
|
if (diagnostic.receiptId) lines.push(`Receipt: ${diagnostic.receiptId}`);
|
|
351
370
|
if (diagnostic.statusLookup?.code) lines.push(`Status lookup: ${diagnostic.statusLookup.code}`);
|
|
352
|
-
|
|
353
|
-
if (
|
|
371
|
+
const causeLine = renderRollbackCauseLine(diagnostic);
|
|
372
|
+
if (causeLine) lines.push("", causeLine);
|
|
373
|
+
lines.push(
|
|
374
|
+
"",
|
|
375
|
+
"Why this failed:",
|
|
376
|
+
` ${unlocatedRollback ? UNLOCATED_ROLLBACK_SUMMARY : diagnostic.reason.summary}`,
|
|
377
|
+
` ${unlocatedRollback ? UNLOCATED_ROLLBACK_DETAIL : diagnostic.reason.detail}`,
|
|
378
|
+
);
|
|
379
|
+
const fixes = unlocatedRollback
|
|
380
|
+
? [renderUnlocatedRollbackFix(diagnostic)]
|
|
381
|
+
: (diagnostic.suggestedFixes ?? []);
|
|
382
|
+
if (fixes.length > 0) {
|
|
354
383
|
lines.push("", "Possible fixes:");
|
|
355
|
-
|
|
356
|
-
lines.push(` ${index + 1}. ${fix.title}`, ` ${fix.detail}`),
|
|
357
|
-
);
|
|
384
|
+
fixes.forEach((fix, index) => lines.push(` ${index + 1}. ${fix.title}`, ` ${fix.detail}`));
|
|
358
385
|
}
|
|
359
386
|
if (shouldRenderForbiddenActions(diagnostic) && diagnostic.forbiddenActions?.length > 0) {
|
|
360
387
|
lines.push("", "Do not:");
|