@prisma-next/cli 0.3.0-pr.99.5 → 0.3.0
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/LICENSE +201 -0
- package/README.md +381 -128
- package/dist/agent-skill-mongo.md +106 -0
- package/dist/agent-skill-postgres.md +106 -0
- package/dist/cli-errors-BDCYR5ap.mjs +4 -0
- package/dist/cli-errors-DStABy9d.d.mts +3 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.js +1 -2910
- package/dist/cli.mjs +261 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/client-DiUkJAeN.mjs +987 -0
- package/dist/client-DiUkJAeN.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts +7 -0
- package/dist/commands/contract-emit.d.mts.map +1 -0
- package/dist/commands/contract-emit.mjs +9 -0
- package/dist/commands/contract-infer.d.mts +7 -0
- package/dist/commands/contract-infer.d.mts.map +1 -0
- package/dist/commands/contract-infer.mjs +10 -0
- package/dist/commands/db-init.d.mts +7 -0
- package/dist/commands/db-init.d.mts.map +1 -0
- package/dist/commands/db-init.mjs +126 -0
- package/dist/commands/db-init.mjs.map +1 -0
- package/dist/commands/db-schema.d.mts +7 -0
- package/dist/commands/db-schema.d.mts.map +1 -0
- package/dist/commands/db-schema.mjs +56 -0
- package/dist/commands/db-schema.mjs.map +1 -0
- package/dist/commands/db-sign.d.mts +7 -0
- package/dist/commands/db-sign.d.mts.map +1 -0
- package/dist/commands/db-sign.mjs +137 -0
- package/dist/commands/db-sign.mjs.map +1 -0
- package/dist/commands/db-update.d.mts +7 -0
- package/dist/commands/db-update.d.mts.map +1 -0
- package/dist/commands/db-update.mjs +123 -0
- package/dist/commands/db-update.mjs.map +1 -0
- package/dist/commands/db-verify.d.mts +7 -0
- package/dist/commands/db-verify.d.mts.map +1 -0
- package/dist/commands/db-verify.mjs +323 -0
- package/dist/commands/db-verify.mjs.map +1 -0
- package/dist/commands/migration-apply.d.mts +36 -0
- package/dist/commands/migration-apply.d.mts.map +1 -0
- package/dist/commands/migration-apply.mjs +245 -0
- package/dist/commands/migration-apply.mjs.map +1 -0
- package/dist/commands/migration-new.d.mts +8 -0
- package/dist/commands/migration-new.d.mts.map +1 -0
- package/dist/commands/migration-new.mjs +152 -0
- package/dist/commands/migration-new.mjs.map +1 -0
- package/dist/commands/migration-plan.d.mts +47 -0
- package/dist/commands/migration-plan.d.mts.map +1 -0
- package/dist/commands/migration-plan.mjs +313 -0
- package/dist/commands/migration-plan.mjs.map +1 -0
- package/dist/commands/migration-ref.d.mts +43 -0
- package/dist/commands/migration-ref.d.mts.map +1 -0
- package/dist/commands/migration-ref.mjs +195 -0
- package/dist/commands/migration-ref.mjs.map +1 -0
- package/dist/commands/migration-show.d.mts +28 -0
- package/dist/commands/migration-show.d.mts.map +1 -0
- package/dist/commands/migration-show.mjs +140 -0
- package/dist/commands/migration-show.mjs.map +1 -0
- package/dist/commands/migration-status.d.mts +86 -0
- package/dist/commands/migration-status.d.mts.map +1 -0
- package/dist/commands/migration-status.mjs +9 -0
- package/dist/commands/migration-verify.d.mts +16 -0
- package/dist/commands/migration-verify.d.mts.map +1 -0
- package/dist/commands/migration-verify.mjs +110 -0
- package/dist/commands/migration-verify.mjs.map +1 -0
- package/dist/config-loader-C4VXKl8f.mjs +43 -0
- package/dist/config-loader-C4VXKl8f.mjs.map +1 -0
- package/dist/{config-loader.d.ts → config-loader.d.mts} +8 -3
- package/dist/config-loader.d.mts.map +1 -0
- package/dist/config-loader.mjs +3 -0
- package/dist/contract-emit-D2wDXfyo.mjs +191 -0
- package/dist/contract-emit-D2wDXfyo.mjs.map +1 -0
- package/dist/contract-emit-Zm_sd1wQ.mjs +112 -0
- package/dist/contract-emit-Zm_sd1wQ.mjs.map +1 -0
- package/dist/contract-emit-kN-IkKTE.mjs +6 -0
- package/dist/contract-enrichment-CGW6mm-E.mjs +79 -0
- package/dist/contract-enrichment-CGW6mm-E.mjs.map +1 -0
- package/dist/contract-infer-DozZT511.mjs +90 -0
- package/dist/contract-infer-DozZT511.mjs.map +1 -0
- package/dist/exports/config-types.d.mts +2 -0
- package/dist/exports/config-types.mjs +3 -0
- package/dist/exports/control-api.d.mts +624 -0
- package/dist/exports/control-api.d.mts.map +1 -0
- package/dist/exports/control-api.mjs +8 -0
- package/dist/{load-ts-contract.d.ts → exports/index.d.mts} +12 -7
- package/dist/exports/index.d.mts.map +1 -0
- package/dist/exports/index.mjs +142 -0
- package/dist/exports/index.mjs.map +1 -0
- package/dist/extract-operation-statements-DZUJNmL3.mjs +13 -0
- package/dist/extract-operation-statements-DZUJNmL3.mjs.map +1 -0
- package/dist/extract-sql-ddl-DDMX-9mz.mjs +26 -0
- package/dist/extract-sql-ddl-DDMX-9mz.mjs.map +1 -0
- package/dist/framework-components-BAsliT4V.mjs +59 -0
- package/dist/framework-components-BAsliT4V.mjs.map +1 -0
- package/dist/init-6Pvm_esG.mjs +430 -0
- package/dist/init-6Pvm_esG.mjs.map +1 -0
- package/dist/inspect-live-schema-BYnhztxZ.mjs +91 -0
- package/dist/inspect-live-schema-BYnhztxZ.mjs.map +1 -0
- package/dist/migration-command-scaffold-CntCcntR.mjs +105 -0
- package/dist/migration-command-scaffold-CntCcntR.mjs.map +1 -0
- package/dist/migration-status-CJANY4yr.mjs +1583 -0
- package/dist/migration-status-CJANY4yr.mjs.map +1 -0
- package/dist/migrations-DTZBYXm1.mjs +173 -0
- package/dist/migrations-DTZBYXm1.mjs.map +1 -0
- package/dist/progress-adapter-B-YvmcDu.mjs +43 -0
- package/dist/progress-adapter-B-YvmcDu.mjs.map +1 -0
- package/dist/quick-reference-mongo.md +93 -0
- package/dist/quick-reference-postgres.md +91 -0
- package/dist/result-handler-oK_vA-Fn.mjs +697 -0
- package/dist/result-handler-oK_vA-Fn.mjs.map +1 -0
- package/dist/terminal-ui-C5k88MmW.mjs +274 -0
- package/dist/terminal-ui-C5k88MmW.mjs.map +1 -0
- package/dist/validate-contract-deps-esa-VQ0h.mjs +37 -0
- package/dist/validate-contract-deps-esa-VQ0h.mjs.map +1 -0
- package/dist/verify-DlFQ2FOw.mjs +385 -0
- package/dist/verify-DlFQ2FOw.mjs.map +1 -0
- package/package.json +87 -40
- package/src/cli.ts +118 -58
- package/src/commands/contract-emit.ts +101 -78
- package/src/commands/contract-infer-paths.ts +32 -0
- package/src/commands/contract-infer.ts +143 -0
- package/src/commands/db-init.ts +97 -219
- package/src/commands/db-schema.ts +77 -0
- package/src/commands/db-sign.ts +46 -73
- package/src/commands/db-update.ts +236 -0
- package/src/commands/db-verify.ts +409 -119
- package/src/commands/init/detect-package-manager.ts +47 -0
- package/src/commands/init/index.ts +21 -0
- package/src/commands/init/init.ts +203 -0
- package/src/commands/init/templates/agent-skill-mongo.md +106 -0
- package/src/commands/init/templates/agent-skill-postgres.md +106 -0
- package/src/commands/init/templates/agent-skill.ts +19 -0
- package/src/commands/init/templates/code-templates.ts +168 -0
- package/src/commands/init/templates/quick-reference-mongo.md +93 -0
- package/src/commands/init/templates/quick-reference-postgres.md +91 -0
- package/src/commands/init/templates/quick-reference.ts +19 -0
- package/src/commands/init/templates/render.ts +20 -0
- package/src/commands/init/templates/tsconfig.ts +35 -0
- package/src/commands/inspect-live-schema.ts +170 -0
- package/src/commands/migration-apply.ts +427 -0
- package/src/commands/migration-new.ts +260 -0
- package/src/commands/migration-plan.ts +519 -0
- package/src/commands/migration-ref.ts +305 -0
- package/src/commands/migration-show.ts +246 -0
- package/src/commands/migration-status.ts +864 -0
- package/src/commands/migration-verify.ts +180 -0
- package/src/config-loader.ts +13 -3
- package/src/control-api/client.ts +205 -183
- package/src/control-api/contract-enrichment.ts +119 -0
- package/src/control-api/errors.ts +9 -0
- package/src/control-api/operations/contract-emit.ts +181 -0
- package/src/control-api/operations/db-init.ts +53 -49
- package/src/control-api/operations/db-update.ts +220 -0
- package/src/control-api/operations/extract-operation-statements.ts +14 -0
- package/src/control-api/operations/extract-sql-ddl.ts +47 -0
- package/src/control-api/operations/migration-apply.ts +191 -0
- package/src/control-api/operations/migration-helpers.ts +49 -0
- package/src/control-api/types.ts +274 -52
- package/src/exports/config-types.ts +4 -3
- package/src/exports/control-api.ts +15 -5
- package/src/load-ts-contract.ts +30 -19
- package/src/utils/cli-errors.ts +14 -8
- package/src/utils/command-helpers.ts +302 -3
- package/src/utils/formatters/emit.ts +67 -0
- package/src/utils/formatters/errors.ts +82 -0
- package/src/utils/formatters/graph-migration-mapper.ts +240 -0
- package/src/utils/formatters/graph-render.ts +1323 -0
- package/src/utils/formatters/graph-types.ts +120 -0
- package/src/utils/formatters/help.ts +380 -0
- package/src/utils/formatters/helpers.ts +28 -0
- package/src/utils/formatters/migrations.ts +346 -0
- package/src/utils/formatters/styled.ts +212 -0
- package/src/utils/formatters/verify.ts +621 -0
- package/src/utils/framework-components.ts +13 -10
- package/src/utils/global-flags.ts +41 -23
- package/src/utils/migration-command-scaffold.ts +184 -0
- package/src/utils/migration-types.ts +12 -0
- package/src/utils/progress-adapter.ts +18 -29
- package/src/utils/result-handler.ts +12 -13
- package/src/utils/shutdown.ts +92 -0
- package/src/utils/suggest-command.ts +31 -0
- package/src/utils/terminal-ui.ts +276 -0
- package/src/utils/validate-contract-deps.ts +49 -0
- package/dist/chunk-AGOTG4L3.js +0 -965
- package/dist/chunk-AGOTG4L3.js.map +0 -1
- package/dist/chunk-HLLI4YL7.js +0 -180
- package/dist/chunk-HLLI4YL7.js.map +0 -1
- package/dist/chunk-HWYQOCAJ.js +0 -47
- package/dist/chunk-HWYQOCAJ.js.map +0 -1
- package/dist/chunk-VG2R7DGF.js +0 -735
- package/dist/chunk-VG2R7DGF.js.map +0 -1
- package/dist/cli.d.ts +0 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/contract-emit.d.ts +0 -3
- package/dist/commands/contract-emit.d.ts.map +0 -1
- package/dist/commands/contract-emit.js +0 -10
- package/dist/commands/contract-emit.js.map +0 -1
- package/dist/commands/db-init.d.ts +0 -3
- package/dist/commands/db-init.d.ts.map +0 -1
- package/dist/commands/db-init.js +0 -257
- package/dist/commands/db-init.js.map +0 -1
- package/dist/commands/db-introspect.d.ts +0 -3
- package/dist/commands/db-introspect.d.ts.map +0 -1
- package/dist/commands/db-introspect.js +0 -155
- package/dist/commands/db-introspect.js.map +0 -1
- package/dist/commands/db-schema-verify.d.ts +0 -3
- package/dist/commands/db-schema-verify.d.ts.map +0 -1
- package/dist/commands/db-schema-verify.js +0 -171
- package/dist/commands/db-schema-verify.js.map +0 -1
- package/dist/commands/db-sign.d.ts +0 -3
- package/dist/commands/db-sign.d.ts.map +0 -1
- package/dist/commands/db-sign.js +0 -195
- package/dist/commands/db-sign.js.map +0 -1
- package/dist/commands/db-verify.d.ts +0 -3
- package/dist/commands/db-verify.d.ts.map +0 -1
- package/dist/commands/db-verify.js +0 -193
- package/dist/commands/db-verify.js.map +0 -1
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config-loader.js +0 -7
- package/dist/config-loader.js.map +0 -1
- package/dist/control-api/client.d.ts +0 -13
- package/dist/control-api/client.d.ts.map +0 -1
- package/dist/control-api/operations/db-init.d.ts +0 -29
- package/dist/control-api/operations/db-init.d.ts.map +0 -1
- package/dist/control-api/types.d.ts +0 -387
- package/dist/control-api/types.d.ts.map +0 -1
- package/dist/exports/config-types.d.ts +0 -3
- package/dist/exports/config-types.d.ts.map +0 -1
- package/dist/exports/config-types.js +0 -6
- package/dist/exports/config-types.js.map +0 -1
- package/dist/exports/control-api.d.ts +0 -13
- package/dist/exports/control-api.d.ts.map +0 -1
- package/dist/exports/control-api.js +0 -7
- package/dist/exports/control-api.js.map +0 -1
- package/dist/exports/index.d.ts +0 -4
- package/dist/exports/index.d.ts.map +0 -1
- package/dist/exports/index.js +0 -176
- package/dist/exports/index.js.map +0 -1
- package/dist/load-ts-contract.d.ts.map +0 -1
- package/dist/utils/cli-errors.d.ts +0 -7
- package/dist/utils/cli-errors.d.ts.map +0 -1
- package/dist/utils/command-helpers.d.ts +0 -12
- package/dist/utils/command-helpers.d.ts.map +0 -1
- package/dist/utils/framework-components.d.ts +0 -70
- package/dist/utils/framework-components.d.ts.map +0 -1
- package/dist/utils/global-flags.d.ts +0 -25
- package/dist/utils/global-flags.d.ts.map +0 -1
- package/dist/utils/output.d.ts +0 -142
- package/dist/utils/output.d.ts.map +0 -1
- package/dist/utils/progress-adapter.d.ts +0 -26
- package/dist/utils/progress-adapter.d.ts.map +0 -1
- package/dist/utils/result-handler.d.ts +0 -15
- package/dist/utils/result-handler.d.ts.map +0 -1
- package/src/commands/db-introspect.ts +0 -227
- package/src/commands/db-schema-verify.ts +0 -238
- package/src/utils/output.ts +0 -1471
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-update.d.mts","names":[],"sources":["../../src/commands/db-update.ts"],"sourcesContent":[],"mappings":";;;iBAuKgB,qBAAA,CAAA,GAAyB"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import "../config-loader-C4VXKl8f.mjs";
|
|
2
|
+
import { _ as errorUnexpected, a as errorContractValidationFailed, f as errorMigrationPlanningFailed, n as ERROR_CODE_DESTRUCTIVE_CHANGES, p as errorRunnerFailed, s as errorDestructiveChanges, t as CliStructuredError } from "../cli-errors-BDCYR5ap.mjs";
|
|
3
|
+
import "../framework-components-BAsliT4V.mjs";
|
|
4
|
+
import { n as ContractValidationError } from "../client-DiUkJAeN.mjs";
|
|
5
|
+
import { d as setCommandExamples, l as sanitizeErrorMessage, m as parseGlobalFlags, t as handleResult, u as setCommandDescriptions } from "../result-handler-oK_vA-Fn.mjs";
|
|
6
|
+
import { t as TerminalUI } from "../terminal-ui-C5k88MmW.mjs";
|
|
7
|
+
import { i as formatMigrationPlanOutput, n as formatMigrationApplyOutput, r as formatMigrationJson } from "../migrations-DTZBYXm1.mjs";
|
|
8
|
+
import { n as prepareMigrationContext, t as addMigrationCommandOptions } from "../migration-command-scaffold-CntCcntR.mjs";
|
|
9
|
+
import { Command } from "commander";
|
|
10
|
+
import { notOk, ok } from "@prisma-next/utils/result";
|
|
11
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
12
|
+
|
|
13
|
+
//#region src/commands/db-update.ts
|
|
14
|
+
/**
|
|
15
|
+
* Maps a DbUpdateFailure to a CliStructuredError for consistent error handling.
|
|
16
|
+
*/
|
|
17
|
+
function mapDbUpdateFailure(failure) {
|
|
18
|
+
if (failure.code === "PLANNING_FAILED") return errorMigrationPlanningFailed({ conflicts: failure.conflicts ?? [] });
|
|
19
|
+
if (failure.code === "RUNNER_FAILED") return errorRunnerFailed(failure.summary, {
|
|
20
|
+
why: failure.why ?? "Migration runner failed",
|
|
21
|
+
fix: "Inspect the reported conflict, reconcile schema drift if needed, then re-run `prisma-next db update`",
|
|
22
|
+
...ifDefined("meta", failure.meta)
|
|
23
|
+
});
|
|
24
|
+
if (failure.code === "DESTRUCTIVE_CHANGES") return errorDestructiveChanges(failure.summary, {
|
|
25
|
+
...ifDefined("why", failure.why),
|
|
26
|
+
fix: "Re-run with `-y` to apply destructive changes, or use `--dry-run` to preview first",
|
|
27
|
+
...ifDefined("meta", failure.meta)
|
|
28
|
+
});
|
|
29
|
+
const exhaustive = failure.code;
|
|
30
|
+
throw new Error(`Unhandled DbUpdateFailure code: ${exhaustive}`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Executes the db update command and returns a structured Result.
|
|
34
|
+
*/
|
|
35
|
+
async function executeDbUpdateCommand(options, flags, ui, startTime) {
|
|
36
|
+
const ctxResult = await prepareMigrationContext(options, flags, ui, {
|
|
37
|
+
commandName: "db update",
|
|
38
|
+
description: "Update your database schema to match your contract",
|
|
39
|
+
url: "https://pris.ly/db-update"
|
|
40
|
+
});
|
|
41
|
+
if (!ctxResult.ok) return ctxResult;
|
|
42
|
+
const { client, contractJson, dbConnection, onProgress, contractPathAbsolute } = ctxResult.value;
|
|
43
|
+
try {
|
|
44
|
+
const result = await client.dbUpdate({
|
|
45
|
+
contract: contractJson,
|
|
46
|
+
mode: options.dryRun ? "plan" : "apply",
|
|
47
|
+
connection: dbConnection,
|
|
48
|
+
...flags.yes ? { acceptDataLoss: true } : {},
|
|
49
|
+
onProgress
|
|
50
|
+
});
|
|
51
|
+
if (!result.ok) return notOk(mapDbUpdateFailure(result.failure));
|
|
52
|
+
return ok({
|
|
53
|
+
ok: true,
|
|
54
|
+
mode: result.value.mode,
|
|
55
|
+
plan: {
|
|
56
|
+
targetId: ctxResult.value.config.target.targetId,
|
|
57
|
+
destination: {
|
|
58
|
+
storageHash: result.value.destination.storageHash,
|
|
59
|
+
...ifDefined("profileHash", result.value.destination.profileHash)
|
|
60
|
+
},
|
|
61
|
+
operations: result.value.plan.operations.map((op) => ({
|
|
62
|
+
id: op.id,
|
|
63
|
+
label: op.label,
|
|
64
|
+
operationClass: op.operationClass
|
|
65
|
+
})),
|
|
66
|
+
...ifDefined("sql", result.value.plan.sql)
|
|
67
|
+
},
|
|
68
|
+
...ifDefined("execution", result.value.execution ? {
|
|
69
|
+
operationsPlanned: result.value.execution.operationsPlanned,
|
|
70
|
+
operationsExecuted: result.value.execution.operationsExecuted
|
|
71
|
+
} : void 0),
|
|
72
|
+
...ifDefined("marker", result.value.marker ? {
|
|
73
|
+
storageHash: result.value.marker.storageHash,
|
|
74
|
+
...ifDefined("profileHash", result.value.marker.profileHash)
|
|
75
|
+
} : void 0),
|
|
76
|
+
summary: result.value.summary,
|
|
77
|
+
timings: { total: Date.now() - startTime }
|
|
78
|
+
});
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (CliStructuredError.is(error)) return notOk(error);
|
|
81
|
+
if (error instanceof ContractValidationError) return notOk(errorContractValidationFailed(`Contract validation failed: ${error.message}`, { where: { path: contractPathAbsolute } }));
|
|
82
|
+
const safeMessage = sanitizeErrorMessage(error instanceof Error ? error.message : String(error), typeof dbConnection === "string" ? dbConnection : void 0);
|
|
83
|
+
return notOk(errorUnexpected(safeMessage, { why: `Unexpected error during db update: ${safeMessage}` }));
|
|
84
|
+
} finally {
|
|
85
|
+
await client.close();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function createDbUpdateCommand() {
|
|
89
|
+
const command = new Command("update");
|
|
90
|
+
setCommandDescriptions(command, "Update your database schema to match your contract", "Compares your database schema to the emitted contract and applies the necessary\nchanges. Works on any database, whether or not it has been initialized with `db init`.\nDestructive operations prompt for confirmation in interactive mode. Use -y to\nauto-accept or --dry-run to preview first.");
|
|
91
|
+
setCommandExamples(command, ["prisma-next db update --db $DATABASE_URL", "prisma-next db update --db $DATABASE_URL --dry-run"]);
|
|
92
|
+
addMigrationCommandOptions(command);
|
|
93
|
+
command.action(async (options) => {
|
|
94
|
+
const flags = parseGlobalFlags(options);
|
|
95
|
+
const startTime = Date.now();
|
|
96
|
+
const ui = new TerminalUI({
|
|
97
|
+
color: flags.color,
|
|
98
|
+
interactive: flags.interactive
|
|
99
|
+
});
|
|
100
|
+
let result = await executeDbUpdateCommand(options, flags, ui, startTime);
|
|
101
|
+
if (!result.ok && result.failure.code === ERROR_CODE_DESTRUCTIVE_CHANGES && flags.interactive && !flags.json && !flags.yes) {
|
|
102
|
+
const destructiveOps = result.failure.meta?.destructiveOperations ?? [];
|
|
103
|
+
if (destructiveOps.length > 0) ui.warn(`${destructiveOps.length} destructive operation(s) that may cause data loss:\n${destructiveOps.map((op) => ` ${ui.yellow("▸")} ${op.label}`).join("\n")}`);
|
|
104
|
+
if (await ui.confirm("Apply destructive changes? This cannot be undone.")) result = await executeDbUpdateCommand(options, {
|
|
105
|
+
...flags,
|
|
106
|
+
yes: true
|
|
107
|
+
}, ui, Date.now());
|
|
108
|
+
}
|
|
109
|
+
const exitCode = handleResult(result, flags, ui, (dbUpdateResult) => {
|
|
110
|
+
if (flags.json) ui.output(formatMigrationJson(dbUpdateResult));
|
|
111
|
+
else {
|
|
112
|
+
const output = dbUpdateResult.mode === "plan" ? formatMigrationPlanOutput(dbUpdateResult, flags) : formatMigrationApplyOutput(dbUpdateResult, flags);
|
|
113
|
+
if (output) ui.log(output);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
process.exit(exitCode);
|
|
117
|
+
});
|
|
118
|
+
return command;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//#endregion
|
|
122
|
+
export { createDbUpdateCommand };
|
|
123
|
+
//# sourceMappingURL=db-update.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-update.mjs","names":["exhaustive: never"],"sources":["../../src/commands/db-update.ts"],"sourcesContent":["import { ifDefined } from '@prisma-next/utils/defined';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { ContractValidationError } from '../control-api/errors';\nimport type { DbUpdateFailure } from '../control-api/types';\nimport {\n CliStructuredError,\n ERROR_CODE_DESTRUCTIVE_CHANGES,\n errorContractValidationFailed,\n errorDestructiveChanges,\n errorMigrationPlanningFailed,\n errorRunnerFailed,\n errorUnexpected,\n} from '../utils/cli-errors';\nimport type { MigrationCommandOptions } from '../utils/command-helpers';\nimport {\n sanitizeErrorMessage,\n setCommandDescriptions,\n setCommandExamples,\n} from '../utils/command-helpers';\nimport {\n formatMigrationApplyOutput,\n formatMigrationJson,\n formatMigrationPlanOutput,\n type MigrationCommandResult,\n} from '../utils/formatters/migrations';\nimport { type GlobalFlags, parseGlobalFlags } from '../utils/global-flags';\nimport {\n addMigrationCommandOptions,\n prepareMigrationContext,\n} from '../utils/migration-command-scaffold';\nimport { handleResult } from '../utils/result-handler';\nimport { TerminalUI } from '../utils/terminal-ui';\n\ntype DbUpdateOptions = MigrationCommandOptions;\n\n/**\n * Maps a DbUpdateFailure to a CliStructuredError for consistent error handling.\n */\nfunction mapDbUpdateFailure(failure: DbUpdateFailure): CliStructuredError {\n if (failure.code === 'PLANNING_FAILED') {\n return errorMigrationPlanningFailed({ conflicts: failure.conflicts ?? [] });\n }\n\n if (failure.code === 'RUNNER_FAILED') {\n return errorRunnerFailed(failure.summary, {\n why: failure.why ?? 'Migration runner failed',\n fix: 'Inspect the reported conflict, reconcile schema drift if needed, then re-run `prisma-next db update`',\n ...ifDefined('meta', failure.meta),\n });\n }\n\n if (failure.code === 'DESTRUCTIVE_CHANGES') {\n return errorDestructiveChanges(failure.summary, {\n ...ifDefined('why', failure.why),\n fix: 'Re-run with `-y` to apply destructive changes, or use `--dry-run` to preview first',\n ...ifDefined('meta', failure.meta),\n });\n }\n\n const exhaustive: never = failure.code;\n throw new Error(`Unhandled DbUpdateFailure code: ${exhaustive}`);\n}\n\n/**\n * Executes the db update command and returns a structured Result.\n */\nasync function executeDbUpdateCommand(\n options: DbUpdateOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n startTime: number,\n): Promise<Result<MigrationCommandResult, CliStructuredError>> {\n // Prepare shared migration context (config, contract, connection, client)\n const ctxResult = await prepareMigrationContext(options, flags, ui, {\n commandName: 'db update',\n description: 'Update your database schema to match your contract',\n url: 'https://pris.ly/db-update',\n });\n if (!ctxResult.ok) {\n return ctxResult;\n }\n const { client, contractJson, dbConnection, onProgress, contractPathAbsolute } = ctxResult.value;\n\n try {\n // Call dbUpdate with connection and progress callback\n const result = await client.dbUpdate({\n contract: contractJson,\n mode: options.dryRun ? 'plan' : 'apply',\n connection: dbConnection,\n ...(flags.yes ? { acceptDataLoss: true } : {}),\n onProgress,\n });\n\n // Handle failures by mapping to CLI structured error\n if (!result.ok) {\n return notOk(mapDbUpdateFailure(result.failure));\n }\n\n // Convert success result to CLI output format\n const dbUpdateResult: MigrationCommandResult = {\n ok: true,\n mode: result.value.mode,\n plan: {\n targetId: ctxResult.value.config.target.targetId,\n destination: {\n storageHash: result.value.destination.storageHash,\n ...ifDefined('profileHash', result.value.destination.profileHash),\n },\n operations: result.value.plan.operations.map((op) => ({\n id: op.id,\n label: op.label,\n operationClass: op.operationClass,\n })),\n ...ifDefined('sql', result.value.plan.sql),\n },\n ...ifDefined(\n 'execution',\n result.value.execution\n ? {\n operationsPlanned: result.value.execution.operationsPlanned,\n operationsExecuted: result.value.execution.operationsExecuted,\n }\n : undefined,\n ),\n ...ifDefined(\n 'marker',\n result.value.marker\n ? {\n storageHash: result.value.marker.storageHash,\n ...ifDefined('profileHash', result.value.marker.profileHash),\n }\n : undefined,\n ),\n summary: result.value.summary,\n timings: { total: Date.now() - startTime },\n };\n\n return ok(dbUpdateResult);\n } catch (error) {\n if (CliStructuredError.is(error)) {\n return notOk(error);\n }\n\n if (error instanceof ContractValidationError) {\n return notOk(\n errorContractValidationFailed(`Contract validation failed: ${error.message}`, {\n where: { path: contractPathAbsolute },\n }),\n );\n }\n\n const rawMessage = error instanceof Error ? error.message : String(error);\n const safeMessage = sanitizeErrorMessage(\n rawMessage,\n typeof dbConnection === 'string' ? dbConnection : undefined,\n );\n return notOk(\n errorUnexpected(safeMessage, {\n why: `Unexpected error during db update: ${safeMessage}`,\n }),\n );\n } finally {\n await client.close();\n }\n}\n\nexport function createDbUpdateCommand(): Command {\n const command = new Command('update');\n setCommandDescriptions(\n command,\n 'Update your database schema to match your contract',\n 'Compares your database schema to the emitted contract and applies the necessary\\n' +\n 'changes. Works on any database, whether or not it has been initialized with `db init`.\\n' +\n 'Destructive operations prompt for confirmation in interactive mode. Use -y to\\n' +\n 'auto-accept or --dry-run to preview first.',\n );\n setCommandExamples(command, [\n 'prisma-next db update --db $DATABASE_URL',\n 'prisma-next db update --db $DATABASE_URL --dry-run',\n ]);\n addMigrationCommandOptions(command);\n command.action(async (options: DbUpdateOptions) => {\n const flags = parseGlobalFlags(options);\n const startTime = Date.now();\n\n const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });\n\n let result = await executeDbUpdateCommand(options, flags, ui, startTime);\n\n // Interactive confirmation for destructive operations:\n // When the control API rejects destructive changes, prompt the user instead of failing.\n // In non-interactive mode (CI, piped, --no-interactive, --json), the error is returned as-is.\n if (\n !result.ok &&\n result.failure.code === ERROR_CODE_DESTRUCTIVE_CHANGES &&\n flags.interactive &&\n !flags.json &&\n !flags.yes\n ) {\n const meta = result.failure.meta as\n | { destructiveOperations?: readonly { id: string; label: string }[] }\n | undefined;\n const destructiveOps = meta?.destructiveOperations ?? [];\n\n if (destructiveOps.length > 0) {\n ui.warn(\n `${destructiveOps.length} destructive operation(s) that may cause data loss:\\n${destructiveOps.map((op) => ` ${ui.yellow('▸')} ${op.label}`).join('\\n')}`,\n );\n }\n\n const confirmed = await ui.confirm('Apply destructive changes? This cannot be undone.');\n\n if (confirmed) {\n result = await executeDbUpdateCommand(options, { ...flags, yes: true }, ui, Date.now());\n }\n }\n\n const exitCode = handleResult(result, flags, ui, (dbUpdateResult) => {\n if (flags.json) {\n ui.output(formatMigrationJson(dbUpdateResult));\n } else {\n const output =\n dbUpdateResult.mode === 'plan'\n ? formatMigrationPlanOutput(dbUpdateResult, flags)\n : formatMigrationApplyOutput(dbUpdateResult, flags);\n if (output) {\n ui.log(output);\n }\n }\n });\n process.exit(exitCode);\n });\n\n return command;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,SAAS,mBAAmB,SAA8C;AACxE,KAAI,QAAQ,SAAS,kBACnB,QAAO,6BAA6B,EAAE,WAAW,QAAQ,aAAa,EAAE,EAAE,CAAC;AAG7E,KAAI,QAAQ,SAAS,gBACnB,QAAO,kBAAkB,QAAQ,SAAS;EACxC,KAAK,QAAQ,OAAO;EACpB,KAAK;EACL,GAAG,UAAU,QAAQ,QAAQ,KAAK;EACnC,CAAC;AAGJ,KAAI,QAAQ,SAAS,sBACnB,QAAO,wBAAwB,QAAQ,SAAS;EAC9C,GAAG,UAAU,OAAO,QAAQ,IAAI;EAChC,KAAK;EACL,GAAG,UAAU,QAAQ,QAAQ,KAAK;EACnC,CAAC;CAGJ,MAAMA,aAAoB,QAAQ;AAClC,OAAM,IAAI,MAAM,mCAAmC,aAAa;;;;;AAMlE,eAAe,uBACb,SACA,OACA,IACA,WAC6D;CAE7D,MAAM,YAAY,MAAM,wBAAwB,SAAS,OAAO,IAAI;EAClE,aAAa;EACb,aAAa;EACb,KAAK;EACN,CAA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gBAAgB,MAAM;AACvD,QAAI,OACF,IAAG,IAAI,OAAO;;IAGlB;AACF,UAAQ,KAAK,SAAS;GACtB;AAEF,QAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-verify.d.mts","names":[],"sources":["../../src/commands/db-verify.ts"],"sourcesContent":[],"mappings":";;;iBAmcgB,qBAAA,CAAA,GAAyB"}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { t as loadConfig } from "../config-loader-C4VXKl8f.mjs";
|
|
2
|
+
import { _ as errorUnexpected, a as errorContractValidationFailed, c as errorDriverRequired, d as errorMarkerMissing, g as errorTargetMismatch, l as errorFileNotFound, m as errorRuntime, o as errorDatabaseConnectionRequired, t as CliStructuredError, u as errorHashMismatch } from "../cli-errors-BDCYR5ap.mjs";
|
|
3
|
+
import "../framework-components-BAsliT4V.mjs";
|
|
4
|
+
import { n as ContractValidationError, t as createControlClient } from "../client-DiUkJAeN.mjs";
|
|
5
|
+
import { _ as formatStyledHeader, a as maskConnectionUrl, d as setCommandExamples, m as parseGlobalFlags, n as addGlobalOptions, s as resolveContractPath, t as handleResult, u as setCommandDescriptions } from "../result-handler-oK_vA-Fn.mjs";
|
|
6
|
+
import { t as createProgressAdapter } from "../progress-adapter-B-YvmcDu.mjs";
|
|
7
|
+
import { t as TerminalUI } from "../terminal-ui-C5k88MmW.mjs";
|
|
8
|
+
import { c as formatVerifyOutput, i as formatSchemaVerifyOutput, r as formatSchemaVerifyJson, s as formatVerifyJson } from "../verify-DlFQ2FOw.mjs";
|
|
9
|
+
import { Command } from "commander";
|
|
10
|
+
import { notOk, ok } from "@prisma-next/utils/result";
|
|
11
|
+
import { relative, resolve } from "pathe";
|
|
12
|
+
import { VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_TARGET_MISMATCH } from "@prisma-next/framework-components/control";
|
|
13
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
14
|
+
import { readFile } from "node:fs/promises";
|
|
15
|
+
|
|
16
|
+
//#region src/commands/db-verify.ts
|
|
17
|
+
/**
|
|
18
|
+
* Maps a VerifyDatabaseResult failure to a CliStructuredError.
|
|
19
|
+
*/
|
|
20
|
+
function mapVerifyFailure(verifyResult) {
|
|
21
|
+
if (!verifyResult.ok && verifyResult.code) {
|
|
22
|
+
if (verifyResult.code === VERIFY_CODE_MARKER_MISSING) return errorMarkerMissing();
|
|
23
|
+
if (verifyResult.code === VERIFY_CODE_HASH_MISMATCH) {
|
|
24
|
+
const storageMatch = verifyResult.marker?.storageHash === verifyResult.contract.storageHash;
|
|
25
|
+
const profileMatch = !verifyResult.contract.profileHash || verifyResult.marker?.profileHash === verifyResult.contract.profileHash;
|
|
26
|
+
if (!storageMatch) return errorHashMismatch({
|
|
27
|
+
why: "Contract storageHash does not match database marker",
|
|
28
|
+
expected: verifyResult.contract.storageHash,
|
|
29
|
+
...ifDefined("actual", verifyResult.marker?.storageHash)
|
|
30
|
+
});
|
|
31
|
+
return errorHashMismatch({
|
|
32
|
+
why: profileMatch ? "Contract hash does not match database marker" : "Contract profileHash does not match database marker",
|
|
33
|
+
...ifDefined("expected", verifyResult.contract.profileHash),
|
|
34
|
+
...ifDefined("actual", verifyResult.marker?.profileHash)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (verifyResult.code === VERIFY_CODE_TARGET_MISMATCH) return errorTargetMismatch(verifyResult.target.expected, verifyResult.target.actual ?? "unknown");
|
|
38
|
+
}
|
|
39
|
+
return errorRuntime(verifyResult.summary);
|
|
40
|
+
}
|
|
41
|
+
function errorInvalidVerifyMode(options) {
|
|
42
|
+
return new CliStructuredError("4012", "Invalid verify mode", {
|
|
43
|
+
domain: "CLI",
|
|
44
|
+
why: options.why,
|
|
45
|
+
fix: options.fix,
|
|
46
|
+
docsUrl: "https://pris.ly/db-verify"
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function resolveDbVerifyMode(options) {
|
|
50
|
+
if (options.markerOnly && options.schemaOnly) return notOk(errorInvalidVerifyMode({
|
|
51
|
+
why: "`--marker-only` and `--schema-only` cannot be used together",
|
|
52
|
+
fix: "Choose one mode: omit both to check the marker and schema, use `--marker-only` to check only the marker, or use `--schema-only` to check only the live schema."
|
|
53
|
+
}));
|
|
54
|
+
if (options.markerOnly && options.strict) return notOk(errorInvalidVerifyMode({
|
|
55
|
+
why: "`--strict` requires schema verification, but `--marker-only` skips it",
|
|
56
|
+
fix: "Remove `--strict`, or use `db verify` / `db verify --schema-only` when you want to check the live schema in strict mode."
|
|
57
|
+
}));
|
|
58
|
+
if (options.schemaOnly) return ok("schema-only");
|
|
59
|
+
if (options.markerOnly) return ok("marker-only");
|
|
60
|
+
return ok("full");
|
|
61
|
+
}
|
|
62
|
+
function formatDbVerifyModeLabel(mode, strict) {
|
|
63
|
+
if (mode === "marker-only") return "marker only";
|
|
64
|
+
if (mode === "schema-only") return `schema only (${strict ? "strict" : "tolerant"})`;
|
|
65
|
+
return `full (marker + schema, ${strict ? "strict" : "tolerant"})`;
|
|
66
|
+
}
|
|
67
|
+
function formatDbVerifyInvocation(mode, strict) {
|
|
68
|
+
const args = ["db verify"];
|
|
69
|
+
if (mode === "marker-only") args.push("--marker-only");
|
|
70
|
+
if (mode === "schema-only") args.push("--schema-only");
|
|
71
|
+
if (strict) args.push("--strict");
|
|
72
|
+
return args.join(" ");
|
|
73
|
+
}
|
|
74
|
+
function createDbVerifyConnectionRequiredError(options) {
|
|
75
|
+
const invocation = formatDbVerifyInvocation(options.mode, options.strict);
|
|
76
|
+
return errorDatabaseConnectionRequired({
|
|
77
|
+
why: `Database connection is required for ${invocation} (set db.connection in ${options.configPath}, or pass --db <url>)`,
|
|
78
|
+
retryCommand: `prisma-next ${invocation} --db <url>`
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function renderVerifyHeader(paths, options, mode, flags, ui) {
|
|
82
|
+
if (flags.json || flags.quiet) return;
|
|
83
|
+
const description = mode === "schema-only" ? "Check whether the live database schema matches your contract" : mode === "marker-only" ? "Check whether the database marker matches your contract" : "Check whether the database marker and live schema match your contract";
|
|
84
|
+
const details = [
|
|
85
|
+
{
|
|
86
|
+
label: "config",
|
|
87
|
+
value: paths.configPath
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
label: "contract",
|
|
91
|
+
value: paths.contractPath
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
label: "mode",
|
|
95
|
+
value: formatDbVerifyModeLabel(mode, options.strict ?? false)
|
|
96
|
+
}
|
|
97
|
+
];
|
|
98
|
+
if (options.db) details.push({
|
|
99
|
+
label: "database",
|
|
100
|
+
value: maskConnectionUrl(options.db)
|
|
101
|
+
});
|
|
102
|
+
ui.stderr(formatStyledHeader({
|
|
103
|
+
command: "db verify",
|
|
104
|
+
description,
|
|
105
|
+
url: "https://pris.ly/db-verify",
|
|
106
|
+
details,
|
|
107
|
+
flags
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
async function resolveVerifyPaths(options) {
|
|
111
|
+
const config = await loadConfig(options.config);
|
|
112
|
+
const configPath = options.config ? relative(process.cwd(), resolve(options.config)) : "prisma-next.config.ts";
|
|
113
|
+
const contractPathAbsolute = resolveContractPath(config);
|
|
114
|
+
return {
|
|
115
|
+
config,
|
|
116
|
+
configPath,
|
|
117
|
+
contractPathAbsolute,
|
|
118
|
+
contractPath: relative(process.cwd(), contractPathAbsolute)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
async function resolveVerifySetup(paths, options, mode) {
|
|
122
|
+
const { config, configPath, contractPathAbsolute, contractPath } = paths;
|
|
123
|
+
let contractJsonContent;
|
|
124
|
+
try {
|
|
125
|
+
contractJsonContent = await readFile(contractPathAbsolute, "utf-8");
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (error instanceof Error && error.code === "ENOENT") return notOk(errorFileNotFound(contractPathAbsolute, {
|
|
128
|
+
why: `Contract file not found at ${contractPathAbsolute}`,
|
|
129
|
+
fix: `Run \`prisma-next contract emit\` to generate ${contractPath}, or update \`config.contract.output\` in ${configPath}`
|
|
130
|
+
}));
|
|
131
|
+
return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}` }));
|
|
132
|
+
}
|
|
133
|
+
let contractJson;
|
|
134
|
+
try {
|
|
135
|
+
contractJson = JSON.parse(contractJsonContent);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
return notOk(errorContractValidationFailed(`Contract JSON is invalid: ${error instanceof Error ? error.message : String(error)}`, { where: { path: contractPathAbsolute } }));
|
|
138
|
+
}
|
|
139
|
+
const dbConnection = options.db ?? config.db?.connection;
|
|
140
|
+
if (typeof dbConnection !== "string" || dbConnection.length === 0) return notOk(createDbVerifyConnectionRequiredError({
|
|
141
|
+
configPath,
|
|
142
|
+
mode,
|
|
143
|
+
strict: options.strict ?? false
|
|
144
|
+
}));
|
|
145
|
+
if (!config.driver) return notOk(errorDriverRequired({ why: `Config.driver is required for ${formatDbVerifyInvocation(mode, options.strict ?? false)}` }));
|
|
146
|
+
return ok({
|
|
147
|
+
...paths,
|
|
148
|
+
contractJson,
|
|
149
|
+
dbConnection
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function createVerifyClient(setup) {
|
|
153
|
+
return createControlClient({
|
|
154
|
+
family: setup.config.family,
|
|
155
|
+
target: setup.config.target,
|
|
156
|
+
adapter: setup.config.adapter,
|
|
157
|
+
driver: setup.config.driver,
|
|
158
|
+
extensionPacks: setup.config.extensionPacks ?? []
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function wrapVerifyError(error, contractPathAbsolute, modeLabel) {
|
|
162
|
+
if (error instanceof CliStructuredError) return notOk(error);
|
|
163
|
+
if (error instanceof ContractValidationError) return notOk(errorContractValidationFailed(`Contract validation failed: ${error.message}`, { where: { path: contractPathAbsolute } }));
|
|
164
|
+
return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Unexpected error during ${modeLabel}: ${error instanceof Error ? error.message : String(error)}` }));
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Executes the db verify command and returns a structured Result.
|
|
168
|
+
*/
|
|
169
|
+
async function executeDbVerifyCommand(options, flags, ui, mode) {
|
|
170
|
+
const startTime = Date.now();
|
|
171
|
+
const paths = await resolveVerifyPaths(options);
|
|
172
|
+
renderVerifyHeader(paths, options, mode, flags, ui);
|
|
173
|
+
const setupResult = await resolveVerifySetup(paths, options, mode);
|
|
174
|
+
if (!setupResult.ok) return setupResult;
|
|
175
|
+
const { contractJson, dbConnection, contractPathAbsolute } = setupResult.value;
|
|
176
|
+
const client = createVerifyClient(setupResult.value);
|
|
177
|
+
const onProgress = createProgressAdapter({
|
|
178
|
+
ui,
|
|
179
|
+
flags
|
|
180
|
+
});
|
|
181
|
+
try {
|
|
182
|
+
const verifyResult = await client.verify({
|
|
183
|
+
contract: contractJson,
|
|
184
|
+
connection: dbConnection,
|
|
185
|
+
onProgress
|
|
186
|
+
});
|
|
187
|
+
if (!verifyResult.ok) return notOk(mapVerifyFailure(verifyResult));
|
|
188
|
+
if (mode === "marker-only") return ok({
|
|
189
|
+
ok: true,
|
|
190
|
+
mode: "marker-only",
|
|
191
|
+
summary: "Database marker matches contract",
|
|
192
|
+
contract: verifyResult.contract,
|
|
193
|
+
marker: verifyResult.marker,
|
|
194
|
+
target: verifyResult.target,
|
|
195
|
+
...ifDefined("missingCodecs", verifyResult.missingCodecs),
|
|
196
|
+
...ifDefined("codecCoverageSkipped", verifyResult.codecCoverageSkipped),
|
|
197
|
+
warning: "Schema verification skipped because --marker-only was provided",
|
|
198
|
+
meta: {
|
|
199
|
+
...verifyResult.meta ?? {},
|
|
200
|
+
schemaVerification: "skipped"
|
|
201
|
+
},
|
|
202
|
+
timings: { total: Date.now() - startTime }
|
|
203
|
+
});
|
|
204
|
+
const schemaVerifyResult = await client.schemaVerify({
|
|
205
|
+
contract: contractJson,
|
|
206
|
+
strict: options.strict ?? false,
|
|
207
|
+
onProgress
|
|
208
|
+
});
|
|
209
|
+
if (!schemaVerifyResult.ok) return notOk(schemaVerifyResult);
|
|
210
|
+
return ok({
|
|
211
|
+
ok: true,
|
|
212
|
+
mode: "full",
|
|
213
|
+
summary: "Database marker and schema match contract",
|
|
214
|
+
contract: verifyResult.contract,
|
|
215
|
+
marker: verifyResult.marker,
|
|
216
|
+
target: verifyResult.target,
|
|
217
|
+
...ifDefined("missingCodecs", verifyResult.missingCodecs),
|
|
218
|
+
...ifDefined("codecCoverageSkipped", verifyResult.codecCoverageSkipped),
|
|
219
|
+
schema: {
|
|
220
|
+
summary: schemaVerifyResult.summary,
|
|
221
|
+
counts: schemaVerifyResult.schema.counts,
|
|
222
|
+
strict: schemaVerifyResult.meta?.strict ?? false
|
|
223
|
+
},
|
|
224
|
+
meta: {
|
|
225
|
+
...verifyResult.meta ?? {},
|
|
226
|
+
schemaVerification: "performed"
|
|
227
|
+
},
|
|
228
|
+
timings: { total: Date.now() - startTime }
|
|
229
|
+
});
|
|
230
|
+
} catch (error) {
|
|
231
|
+
return wrapVerifyError(error, contractPathAbsolute, "db verify");
|
|
232
|
+
} finally {
|
|
233
|
+
await client.close();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async function executeDbSchemaOnlyVerifyCommand(options, flags, ui) {
|
|
237
|
+
const paths = await resolveVerifyPaths(options);
|
|
238
|
+
renderVerifyHeader(paths, options, "schema-only", flags, ui);
|
|
239
|
+
const setupResult = await resolveVerifySetup(paths, options, "schema-only");
|
|
240
|
+
if (!setupResult.ok) return setupResult;
|
|
241
|
+
const { contractJson, dbConnection, contractPathAbsolute } = setupResult.value;
|
|
242
|
+
const client = createVerifyClient(setupResult.value);
|
|
243
|
+
const onProgress = createProgressAdapter({
|
|
244
|
+
ui,
|
|
245
|
+
flags
|
|
246
|
+
});
|
|
247
|
+
try {
|
|
248
|
+
return ok(await client.schemaVerify({
|
|
249
|
+
contract: contractJson,
|
|
250
|
+
strict: options.strict ?? false,
|
|
251
|
+
connection: dbConnection,
|
|
252
|
+
onProgress
|
|
253
|
+
}));
|
|
254
|
+
} catch (error) {
|
|
255
|
+
return wrapVerifyError(error, contractPathAbsolute, "db verify --schema-only");
|
|
256
|
+
} finally {
|
|
257
|
+
await client.close();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function createDbVerifyCommand() {
|
|
261
|
+
const command = new Command("verify");
|
|
262
|
+
setCommandDescriptions(command, "Check whether the database marker and live schema match your contract", "Verifies the database marker first, then checks the database schema matches your contract.\nUse `--marker-only` for marker-only verification, `--schema-only` to skip marker checks and\ninspect only the live schema, and `--strict` to fail if the database includes elements\nnot present in the contract.");
|
|
263
|
+
setCommandExamples(command, [
|
|
264
|
+
"prisma-next db verify --db $DATABASE_URL",
|
|
265
|
+
"prisma-next db verify --db $DATABASE_URL --strict",
|
|
266
|
+
"prisma-next db verify --db $DATABASE_URL --schema-only",
|
|
267
|
+
"prisma-next db verify --db $DATABASE_URL --schema-only --strict",
|
|
268
|
+
"prisma-next db verify --db $DATABASE_URL --marker-only",
|
|
269
|
+
"prisma-next db verify --db $DATABASE_URL --json"
|
|
270
|
+
]);
|
|
271
|
+
addGlobalOptions(command).option("--db <url>", "Database connection string").option("--config <path>", "Path to prisma-next.config.ts").option("--marker-only", "Skip schema verification and only check the database marker").option("--schema-only", "Skip marker verification and only check whether the live schema satisfies the contract").option("--strict", "Strict mode: schema elements not present in the contract are considered an error", false).action(async (options) => {
|
|
272
|
+
const flags = parseGlobalFlags(options);
|
|
273
|
+
const ui = new TerminalUI({
|
|
274
|
+
color: flags.color,
|
|
275
|
+
interactive: flags.interactive
|
|
276
|
+
});
|
|
277
|
+
const modeResult = resolveDbVerifyMode(options);
|
|
278
|
+
if (!modeResult.ok) {
|
|
279
|
+
const exitCode = handleResult(modeResult, flags, ui);
|
|
280
|
+
process.exit(exitCode);
|
|
281
|
+
}
|
|
282
|
+
const mode = modeResult.value;
|
|
283
|
+
if (mode === "schema-only") {
|
|
284
|
+
const result$1 = await executeDbSchemaOnlyVerifyCommand(options, flags, ui);
|
|
285
|
+
const exitCode = handleResult(result$1, flags, ui, (schemaVerifyResult) => {
|
|
286
|
+
if (flags.json) ui.output(formatSchemaVerifyJson(schemaVerifyResult));
|
|
287
|
+
else {
|
|
288
|
+
const output = formatSchemaVerifyOutput(schemaVerifyResult, flags);
|
|
289
|
+
if (output) ui.log(output);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
if (result$1.ok && !result$1.value.ok) process.exit(1);
|
|
293
|
+
process.exit(exitCode);
|
|
294
|
+
}
|
|
295
|
+
const result = await executeDbVerifyCommand(options, flags, ui, mode);
|
|
296
|
+
if (result.ok) {
|
|
297
|
+
if (flags.json) ui.output(formatVerifyJson(result.value));
|
|
298
|
+
else {
|
|
299
|
+
const output = formatVerifyOutput(result.value, flags);
|
|
300
|
+
if (output) ui.log(output);
|
|
301
|
+
}
|
|
302
|
+
process.exit(0);
|
|
303
|
+
}
|
|
304
|
+
if (CliStructuredError.is(result.failure)) {
|
|
305
|
+
const exitCode = handleResult(result, flags, ui);
|
|
306
|
+
process.exit(exitCode);
|
|
307
|
+
}
|
|
308
|
+
if (flags.json) ui.output(formatSchemaVerifyJson(result.failure));
|
|
309
|
+
else {
|
|
310
|
+
const output = formatSchemaVerifyOutput(result.failure, {
|
|
311
|
+
...flags,
|
|
312
|
+
quiet: false
|
|
313
|
+
});
|
|
314
|
+
if (output) ui.log(output);
|
|
315
|
+
}
|
|
316
|
+
process.exit(1);
|
|
317
|
+
});
|
|
318
|
+
return command;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
//#endregion
|
|
322
|
+
export { createDbVerifyCommand };
|
|
323
|
+
//# sourceMappingURL=db-verify.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-verify.mjs","names":["details: Array<{ label: string; value: string }>","contractJsonContent: string","contractJson: Record<string, unknown>","result"],"sources":["../../src/commands/db-verify.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport type {\n VerifyDatabaseResult,\n VerifyDatabaseSchemaResult,\n} from '@prisma-next/framework-components/control';\nimport {\n VERIFY_CODE_HASH_MISMATCH,\n VERIFY_CODE_MARKER_MISSING,\n VERIFY_CODE_TARGET_MISMATCH,\n} from '@prisma-next/framework-components/control';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { relative, resolve } from 'pathe';\nimport { loadConfig } from '../config-loader';\nimport { createControlClient } from '../control-api/client';\nimport { ContractValidationError } from '../control-api/errors';\nimport {\n CliStructuredError,\n errorContractValidationFailed,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorFileNotFound,\n errorHashMismatch,\n errorMarkerMissing,\n errorRuntime,\n errorTargetMismatch,\n errorUnexpected,\n} from '../utils/cli-errors';\nimport {\n addGlobalOptions,\n maskConnectionUrl,\n resolveContractPath,\n setCommandDescriptions,\n setCommandExamples,\n} from '../utils/command-helpers';\nimport { formatStyledHeader } from '../utils/formatters/styled';\nimport {\n type DbVerifyCommandSuccessResult,\n formatSchemaVerifyJson,\n formatSchemaVerifyOutput,\n formatVerifyJson,\n formatVerifyOutput,\n} from '../utils/formatters/verify';\nimport type { CommonCommandOptions } from '../utils/global-flags';\nimport { type GlobalFlags, parseGlobalFlags } from '../utils/global-flags';\nimport { createProgressAdapter } from '../utils/progress-adapter';\nimport { handleResult } from '../utils/result-handler';\nimport { TerminalUI } from '../utils/terminal-ui';\n\ninterface DbVerifyOptions extends CommonCommandOptions {\n readonly db?: string;\n readonly config?: string;\n readonly markerOnly?: boolean;\n readonly schemaOnly?: boolean;\n readonly strict?: boolean;\n}\n\ntype DbVerifyMode = 'full' | 'marker-only' | 'schema-only';\n\n/**\n * Maps a VerifyDatabaseResult failure to a CliStructuredError.\n */\nfunction mapVerifyFailure(verifyResult: VerifyDatabaseResult): CliStructuredError {\n if (!verifyResult.ok && verifyResult.code) {\n if (verifyResult.code === VERIFY_CODE_MARKER_MISSING) {\n return errorMarkerMissing();\n }\n if (verifyResult.code === VERIFY_CODE_HASH_MISMATCH) {\n const storageMatch = verifyResult.marker?.storageHash === verifyResult.contract.storageHash;\n const profileMatch =\n !verifyResult.contract.profileHash ||\n verifyResult.marker?.profileHash === verifyResult.contract.profileHash;\n\n if (!storageMatch) {\n return errorHashMismatch({\n why: 'Contract storageHash does not match database marker',\n expected: verifyResult.contract.storageHash,\n ...ifDefined('actual', verifyResult.marker?.storageHash),\n });\n }\n\n return errorHashMismatch({\n why: profileMatch\n ? 'Contract hash does not match database marker'\n : 'Contract profileHash does not match database marker',\n ...ifDefined('expected', verifyResult.contract.profileHash),\n ...ifDefined('actual', verifyResult.marker?.profileHash),\n });\n }\n if (verifyResult.code === VERIFY_CODE_TARGET_MISMATCH) {\n return errorTargetMismatch(\n verifyResult.target.expected,\n verifyResult.target.actual ?? 'unknown',\n );\n }\n // Unknown code - fall through to runtime error\n }\n return errorRuntime(verifyResult.summary);\n}\n\ntype DbVerifyFailure = CliStructuredError | VerifyDatabaseSchemaResult;\n\nfunction errorInvalidVerifyMode(options: {\n readonly why: string;\n readonly fix: string;\n}): CliStructuredError {\n return new CliStructuredError('4012', 'Invalid verify mode', {\n domain: 'CLI',\n why: options.why,\n fix: options.fix,\n docsUrl: 'https://pris.ly/db-verify',\n });\n}\n\nfunction resolveDbVerifyMode(options: DbVerifyOptions): Result<DbVerifyMode, CliStructuredError> {\n if (options.markerOnly && options.schemaOnly) {\n return notOk(\n errorInvalidVerifyMode({\n why: '`--marker-only` and `--schema-only` cannot be used together',\n fix: 'Choose one mode: omit both to check the marker and schema, use `--marker-only` to check only the marker, or use `--schema-only` to check only the live schema.',\n }),\n );\n }\n\n if (options.markerOnly && options.strict) {\n return notOk(\n errorInvalidVerifyMode({\n why: '`--strict` requires schema verification, but `--marker-only` skips it',\n fix: 'Remove `--strict`, or use `db verify` / `db verify --schema-only` when you want to check the live schema in strict mode.',\n }),\n );\n }\n\n if (options.schemaOnly) {\n return ok('schema-only');\n }\n\n if (options.markerOnly) {\n return ok('marker-only');\n }\n\n return ok('full');\n}\n\nfunction formatDbVerifyModeLabel(mode: DbVerifyMode, strict: boolean): string {\n if (mode === 'marker-only') {\n return 'marker only';\n }\n\n if (mode === 'schema-only') {\n return `schema only (${strict ? 'strict' : 'tolerant'})`;\n }\n\n return `full (marker + schema, ${strict ? 'strict' : 'tolerant'})`;\n}\n\nfunction formatDbVerifyInvocation(mode: DbVerifyMode, strict: boolean): string {\n const args = ['db verify'];\n\n if (mode === 'marker-only') {\n args.push('--marker-only');\n }\n\n if (mode === 'schema-only') {\n args.push('--schema-only');\n }\n\n if (strict) {\n args.push('--strict');\n }\n\n return args.join(' ');\n}\n\nfunction createDbVerifyConnectionRequiredError(options: {\n readonly configPath: string;\n readonly mode: DbVerifyMode;\n readonly strict: boolean;\n}): CliStructuredError {\n const invocation = formatDbVerifyInvocation(options.mode, options.strict);\n return errorDatabaseConnectionRequired({\n why: `Database connection is required for ${invocation} (set db.connection in ${options.configPath}, or pass --db <url>)`,\n retryCommand: `prisma-next ${invocation} --db <url>`,\n });\n}\n\nfunction renderVerifyHeader(\n paths: { configPath: string; contractPath: string },\n options: DbVerifyOptions,\n mode: DbVerifyMode,\n flags: GlobalFlags,\n ui: TerminalUI,\n): void {\n if (flags.json || flags.quiet) return;\n\n const description =\n mode === 'schema-only'\n ? 'Check whether the live database schema matches your contract'\n : mode === 'marker-only'\n ? 'Check whether the database marker matches your contract'\n : 'Check whether the database marker and live schema match your contract';\n\n const details: Array<{ label: string; value: string }> = [\n { label: 'config', value: paths.configPath },\n { label: 'contract', value: paths.contractPath },\n { label: 'mode', value: formatDbVerifyModeLabel(mode, options.strict ?? false) },\n ];\n if (options.db) {\n details.push({ label: 'database', value: maskConnectionUrl(options.db) });\n }\n\n ui.stderr(\n formatStyledHeader({\n command: 'db verify',\n description,\n url: 'https://pris.ly/db-verify',\n details,\n flags,\n }),\n );\n}\n\nasync function resolveVerifyPaths(options: DbVerifyOptions) {\n const config = await loadConfig(options.config);\n const configPath = options.config\n ? relative(process.cwd(), resolve(options.config))\n : 'prisma-next.config.ts';\n const contractPathAbsolute = resolveContractPath(config);\n const contractPath = relative(process.cwd(), contractPathAbsolute);\n return { config, configPath, contractPathAbsolute, contractPath };\n}\n\ntype VerifyPaths = Awaited<ReturnType<typeof resolveVerifyPaths>>;\n\ninterface VerifySetup extends VerifyPaths {\n readonly contractJson: Record<string, unknown>;\n readonly dbConnection: string;\n}\n\nasync function resolveVerifySetup(\n paths: VerifyPaths,\n options: DbVerifyOptions,\n mode: DbVerifyMode,\n): Promise<Result<VerifySetup, CliStructuredError>> {\n const { config, configPath, contractPathAbsolute, contractPath } = paths;\n\n let contractJsonContent: string;\n try {\n contractJsonContent = await readFile(contractPathAbsolute, 'utf-8');\n } catch (error) {\n if (error instanceof Error && (error as { code?: string }).code === 'ENOENT') {\n return notOk(\n errorFileNotFound(contractPathAbsolute, {\n why: `Contract file not found at ${contractPathAbsolute}`,\n fix: `Run \\`prisma-next contract emit\\` to generate ${contractPath}, or update \\`config.contract.output\\` in ${configPath}`,\n }),\n );\n }\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n }\n\n let contractJson: Record<string, unknown>;\n try {\n contractJson = JSON.parse(contractJsonContent) as Record<string, unknown>;\n } catch (error) {\n return notOk(\n errorContractValidationFailed(\n `Contract JSON is invalid: ${error instanceof Error ? error.message : String(error)}`,\n { where: { path: contractPathAbsolute } },\n ),\n );\n }\n\n const dbConnection = options.db ?? config.db?.connection;\n if (typeof dbConnection !== 'string' || dbConnection.length === 0) {\n return notOk(\n createDbVerifyConnectionRequiredError({\n configPath,\n mode,\n strict: options.strict ?? false,\n }),\n );\n }\n\n if (!config.driver) {\n return notOk(\n errorDriverRequired({\n why: `Config.driver is required for ${formatDbVerifyInvocation(mode, options.strict ?? false)}`,\n }),\n );\n }\n\n return ok({ ...paths, contractJson, dbConnection });\n}\n\nfunction createVerifyClient(setup: VerifySetup) {\n return createControlClient({\n family: setup.config.family,\n target: setup.config.target,\n adapter: setup.config.adapter,\n driver: setup.config.driver!,\n extensionPacks: setup.config.extensionPacks ?? [],\n });\n}\n\nfunction wrapVerifyError(\n error: unknown,\n contractPathAbsolute: string,\n modeLabel: string,\n): Result<never, CliStructuredError> {\n if (error instanceof CliStructuredError) {\n return notOk(error);\n }\n if (error instanceof ContractValidationError) {\n return notOk(\n errorContractValidationFailed(`Contract validation failed: ${error.message}`, {\n where: { path: contractPathAbsolute },\n }),\n );\n }\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Unexpected error during ${modeLabel}: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n}\n\n/**\n * Executes the db verify command and returns a structured Result.\n */\nasync function executeDbVerifyCommand(\n options: DbVerifyOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n mode: Extract<DbVerifyMode, 'full' | 'marker-only'>,\n): Promise<Result<DbVerifyCommandSuccessResult, DbVerifyFailure>> {\n const startTime = Date.now();\n const paths = await resolveVerifyPaths(options);\n renderVerifyHeader(paths, options, mode, flags, ui);\n\n const setupResult = await resolveVerifySetup(paths, options, mode);\n if (!setupResult.ok) return setupResult;\n const { contractJson, dbConnection, contractPathAbsolute } = setupResult.value;\n\n const client = createVerifyClient(setupResult.value);\n const onProgress = createProgressAdapter({ ui, flags });\n\n try {\n const verifyResult = await client.verify({\n contract: contractJson,\n connection: dbConnection,\n onProgress,\n });\n\n // If verification failed, map to CLI structured error\n if (!verifyResult.ok) {\n return notOk(mapVerifyFailure(verifyResult));\n }\n\n if (mode === 'marker-only') {\n return ok({\n ok: true,\n mode: 'marker-only',\n summary: 'Database marker matches contract',\n contract: verifyResult.contract,\n marker: verifyResult.marker,\n target: verifyResult.target,\n ...ifDefined('missingCodecs', verifyResult.missingCodecs),\n ...ifDefined('codecCoverageSkipped', verifyResult.codecCoverageSkipped),\n warning: 'Schema verification skipped because --marker-only was provided',\n meta: {\n ...(verifyResult.meta ?? {}),\n schemaVerification: 'skipped',\n },\n timings: { total: Date.now() - startTime },\n });\n }\n\n const schemaVerifyResult = await client.schemaVerify({\n contract: contractJson,\n strict: options.strict ?? false,\n onProgress,\n });\n\n if (!schemaVerifyResult.ok) {\n return notOk(schemaVerifyResult);\n }\n\n return ok({\n ok: true,\n mode: 'full',\n summary: 'Database marker and schema match contract',\n contract: verifyResult.contract,\n marker: verifyResult.marker,\n target: verifyResult.target,\n ...ifDefined('missingCodecs', verifyResult.missingCodecs),\n ...ifDefined('codecCoverageSkipped', verifyResult.codecCoverageSkipped),\n schema: {\n summary: schemaVerifyResult.summary,\n counts: schemaVerifyResult.schema.counts,\n strict: schemaVerifyResult.meta?.strict ?? false,\n },\n meta: {\n ...(verifyResult.meta ?? {}),\n schemaVerification: 'performed',\n },\n timings: { total: Date.now() - startTime },\n });\n } catch (error) {\n return wrapVerifyError(error, contractPathAbsolute, 'db verify');\n } finally {\n await client.close();\n }\n}\n\nasync function executeDbSchemaOnlyVerifyCommand(\n options: DbVerifyOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n): Promise<Result<VerifyDatabaseSchemaResult, CliStructuredError>> {\n const paths = await resolveVerifyPaths(options);\n renderVerifyHeader(paths, options, 'schema-only', flags, ui);\n\n const setupResult = await resolveVerifySetup(paths, options, 'schema-only');\n if (!setupResult.ok) return setupResult;\n const { contractJson, dbConnection, contractPathAbsolute } = setupResult.value;\n\n const client = createVerifyClient(setupResult.value);\n const onProgress = createProgressAdapter({ ui, flags });\n\n try {\n const schemaVerifyResult = await client.schemaVerify({\n contract: contractJson,\n strict: options.strict ?? false,\n connection: dbConnection,\n onProgress,\n });\n\n return ok(schemaVerifyResult);\n } catch (error) {\n return wrapVerifyError(error, contractPathAbsolute, 'db verify --schema-only');\n } finally {\n await client.close();\n }\n}\n\nexport function createDbVerifyCommand(): Command {\n const command = new Command('verify');\n setCommandDescriptions(\n command,\n 'Check whether the database marker and live schema match your contract',\n 'Verifies the database marker first, then checks the database schema matches your contract.\\n' +\n 'Use `--marker-only` for marker-only verification, `--schema-only` to skip marker checks and\\n' +\n 'inspect only the live schema, and `--strict` to fail if the database includes elements\\n' +\n 'not present in the contract.',\n );\n setCommandExamples(command, [\n 'prisma-next db verify --db $DATABASE_URL',\n 'prisma-next db verify --db $DATABASE_URL --strict',\n 'prisma-next db verify --db $DATABASE_URL --schema-only',\n 'prisma-next db verify --db $DATABASE_URL --schema-only --strict',\n 'prisma-next db verify --db $DATABASE_URL --marker-only',\n 'prisma-next db verify --db $DATABASE_URL --json',\n ]);\n addGlobalOptions(command)\n .option('--db <url>', 'Database connection string')\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option('--marker-only', 'Skip schema verification and only check the database marker')\n .option(\n '--schema-only',\n 'Skip marker verification and only check whether the live schema satisfies the contract',\n )\n .option(\n '--strict',\n 'Strict mode: schema elements not present in the contract are considered an error',\n false,\n )\n .action(async (options: DbVerifyOptions) => {\n const flags = parseGlobalFlags(options);\n const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });\n\n const modeResult = resolveDbVerifyMode(options);\n if (!modeResult.ok) {\n const exitCode = handleResult(modeResult as Result<never, CliStructuredError>, flags, ui);\n process.exit(exitCode);\n }\n\n const mode = modeResult.value;\n\n if (mode === 'schema-only') {\n const result = await executeDbSchemaOnlyVerifyCommand(options, flags, ui);\n const exitCode = handleResult(result, flags, ui, (schemaVerifyResult) => {\n if (flags.json) {\n ui.output(formatSchemaVerifyJson(schemaVerifyResult));\n } else {\n const output = formatSchemaVerifyOutput(schemaVerifyResult, flags);\n if (output) {\n ui.log(output);\n }\n }\n });\n\n if (result.ok && !result.value.ok) {\n process.exit(1);\n }\n\n process.exit(exitCode);\n }\n\n const result = await executeDbVerifyCommand(options, flags, ui, mode);\n\n if (result.ok) {\n if (flags.json) {\n ui.output(formatVerifyJson(result.value));\n } else {\n const output = formatVerifyOutput(result.value, flags);\n if (output) {\n ui.log(output);\n }\n }\n process.exit(0);\n }\n\n if (CliStructuredError.is(result.failure)) {\n const exitCode = handleResult(result as Result<never, CliStructuredError>, flags, ui);\n process.exit(exitCode);\n }\n\n if (flags.json) {\n ui.output(formatSchemaVerifyJson(result.failure));\n } else {\n // Always show schema-drift failures, even in quiet mode — exiting 1 without\n // diagnostics is unhelpful.\n const output = formatSchemaVerifyOutput(result.failure, { ...flags, quiet: false });\n if (output) {\n ui.log(output);\n }\n }\n process.exit(1);\n });\n\n return command;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA+DA,SAAS,iBAAiB,cAAwD;AAChF,KAAI,CAAC,aAAa,MAAM,aAAa,MAAM;AACzC,MAAI,aAAa,SAAS,2BACxB,QAAO,oBAAoB;AAE7B,MAAI,aAAa,SAAS,2BAA2B;GACnD,MAAM,eAAe,aAAa,QAAQ,gBAAgB,aAAa,SAAS;GAChF,MAAM,eACJ,CAAC,aAAa,SAAS,eACvB,aAAa,QAAQ,gBAAgB,aAAa,SAAS;AAE7D,OAAI,CAAC,aACH,QAAO,kBAAkB;IACvB,KAAK;IACL,UAAU,aAAa,SAAS;IAChC,GAAG,UAAU,UAAU,aAAa,QAAQ,YAAY;IACzD,CAAC;AAGJ,UAAO,kBAAkB;IACvB,KAAK,eACD,iDACA;IACJ,GAAG,UAAU,YAAY,aAAa,SAAS,YAAY;IAC3D,GAAG,UAAU,UAAU,aAAa,QAAQ,YAAY;IACzD,CAAC;;AAEJ,MAAI,aAAa,SAAS,4BACxB,QAAO,oBACL,aAAa,OAAO,UACpB,aAAa,OAAO,UAAU,UAC/B;;AAIL,QAAO,aAAa,aAAa,QAAQ;;AAK3C,SAAS,uBAAuB,SAGT;AACrB,QAAO,IAAI,mBAAmB,QAAQ,uBAAuB;EAC3D,QAAQ;EACR,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,SAAS;EACV,CAAC;;AAGJ,SAAS,oBAAoB,SAAoE;AAC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OAAO;;KAGlB;AAEF,OAAIA,SAAO,MAAM,CAACA,SAAO,MAAM,GAC7B,SAAQ,KAAK,EAAE;AAGjB,WAAQ,KAAK,SAAS;;EAGxB,MAAM,SAAS,MAAM,uBAAuB,SAAS,OAAO,IAAI,KAAK;AAErE,MAAI,OAAO,IAAI;AACb,OAAI,MAAM,KACR,IAAG,OAAO,iBAAiB,OAAO,MAAM,CAAC;QACpC;IACL,MAAM,SAAS,mBAAmB,OAAO,OAAO,MAAM;AACtD,QAAI,OACF,IAAG,IAAI,OAAO;;AAGlB,WAAQ,KAAK,EAAE;;AAGjB,MAAI,mBAAmB,GAAG,OAAO,QAAQ,EAAE;GACzC,MAAM,WAAW,aAAa,QAA6C,OAAO,GAAG;AACrF,WAAQ,KAAK,SAAS;;AAGxB,MAAI,MAAM,KACR,IAAG,OAAO,uBAAuB,OAAO,QAAQ,CAAC;OAC5C;GAGL,MAAM,SAAS,yBAAyB,OAAO,SAAS;IAAE,GAAG;IAAO,OAAO;IAAO,CAAC;AACnF,OAAI,OACF,IAAG,IAAI,OAAO;;AAGlB,UAAQ,KAAK,EAAE;GACf;AAEJ,QAAO"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
|
|
3
|
+
//#region src/commands/migration-apply.d.ts
|
|
4
|
+
interface MigrationApplyResult {
|
|
5
|
+
readonly ok: boolean;
|
|
6
|
+
readonly migrationsApplied: number;
|
|
7
|
+
readonly migrationsTotal: number;
|
|
8
|
+
readonly markerHash: string;
|
|
9
|
+
readonly applied: readonly {
|
|
10
|
+
readonly dirName: string;
|
|
11
|
+
readonly from: string;
|
|
12
|
+
readonly to: string;
|
|
13
|
+
readonly operationsExecuted: number;
|
|
14
|
+
}[];
|
|
15
|
+
readonly summary: string;
|
|
16
|
+
readonly pathDecision?: {
|
|
17
|
+
readonly fromHash: string;
|
|
18
|
+
readonly toHash: string;
|
|
19
|
+
readonly alternativeCount: number;
|
|
20
|
+
readonly tieBreakReasons: readonly string[];
|
|
21
|
+
readonly refName?: string;
|
|
22
|
+
readonly selectedPath: readonly {
|
|
23
|
+
readonly dirName: string;
|
|
24
|
+
readonly migrationId: string | null;
|
|
25
|
+
readonly from: string;
|
|
26
|
+
readonly to: string;
|
|
27
|
+
}[];
|
|
28
|
+
};
|
|
29
|
+
readonly timings: {
|
|
30
|
+
readonly total: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
declare function createMigrationApplyCommand(): Command;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { MigrationApplyResult, createMigrationApplyCommand };
|
|
36
|
+
//# sourceMappingURL=migration-apply.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-apply.d.mts","names":[],"sources":["../../src/commands/migration-apply.ts"],"sourcesContent":[],"mappings":";;;UA6CiB,oBAAA;;EAAA,SAAA,iBAAoB,EAAA,MAAA;EAuVrB,SAAA,eAAA,EAAA,MAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA3B,2BAAA,CAAA,GAA+B"}
|