@prisma-next/cli 0.3.0-pr.99.6 → 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,313 @@
|
|
|
1
|
+
import { t as loadConfig } from "../config-loader-C4VXKl8f.mjs";
|
|
2
|
+
import { _ as errorUnexpected, a as errorContractValidationFailed, f as errorMigrationPlanningFailed, h as errorTargetMigrationNotSupported, l as errorFileNotFound, m as errorRuntime, t as CliStructuredError } from "../cli-errors-BDCYR5ap.mjs";
|
|
3
|
+
import { t as assertFrameworkComponentsCompatible } from "../framework-components-BAsliT4V.mjs";
|
|
4
|
+
import { t as extractSqlDdl } from "../extract-sql-ddl-DDMX-9mz.mjs";
|
|
5
|
+
import { _ as formatStyledHeader, c as resolveMigrationPaths, d as setCommandExamples, i as loadAllBundles, m as parseGlobalFlags, n as addGlobalOptions, r as getTargetMigrations, s as resolveContractPath, 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 { Command } from "commander";
|
|
8
|
+
import { notOk, ok } from "@prisma-next/utils/result";
|
|
9
|
+
import { join, relative } from "pathe";
|
|
10
|
+
import { EMPTY_CONTRACT_HASH } from "@prisma-next/migration-tools/constants";
|
|
11
|
+
import { readFile } from "node:fs/promises";
|
|
12
|
+
import { findLatestMigration } from "@prisma-next/migration-tools/dag";
|
|
13
|
+
import { formatMigrationDirName, writeMigrationOps, writeMigrationPackage } from "@prisma-next/migration-tools/io";
|
|
14
|
+
import { MigrationToolsError } from "@prisma-next/migration-tools/types";
|
|
15
|
+
import { evaluateMigrationTs, scaffoldMigrationTs } from "@prisma-next/migration-tools/migration-ts";
|
|
16
|
+
import { attestMigration } from "@prisma-next/migration-tools/attestation";
|
|
17
|
+
|
|
18
|
+
//#region src/commands/migration-plan.ts
|
|
19
|
+
function mapMigrationToolsError(error) {
|
|
20
|
+
if (CliStructuredError.is(error)) return error;
|
|
21
|
+
if (MigrationToolsError.is(error)) return errorRuntime(error.message, {
|
|
22
|
+
why: error.why,
|
|
23
|
+
fix: error.fix,
|
|
24
|
+
meta: {
|
|
25
|
+
code: error.code,
|
|
26
|
+
...error.details ?? {}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Unexpected error during migration plan: ${error instanceof Error ? error.message : String(error)}` });
|
|
30
|
+
}
|
|
31
|
+
async function executeMigrationPlanCommand(options, flags, ui, startTime) {
|
|
32
|
+
const config = await loadConfig(options.config);
|
|
33
|
+
const { configPath, migrationsDir, migrationsRelative } = resolveMigrationPaths(options.config, config);
|
|
34
|
+
const contractPathAbsolute = resolveContractPath(config);
|
|
35
|
+
const contractPath = relative(process.cwd(), contractPathAbsolute);
|
|
36
|
+
if (!flags.json && !flags.quiet) {
|
|
37
|
+
const details = [
|
|
38
|
+
{
|
|
39
|
+
label: "config",
|
|
40
|
+
value: configPath
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
label: "contract",
|
|
44
|
+
value: contractPath
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
label: "migrations",
|
|
48
|
+
value: migrationsRelative
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
if (options.from) details.push({
|
|
52
|
+
label: "from",
|
|
53
|
+
value: options.from
|
|
54
|
+
});
|
|
55
|
+
if (options.name) details.push({
|
|
56
|
+
label: "name",
|
|
57
|
+
value: options.name
|
|
58
|
+
});
|
|
59
|
+
const header = formatStyledHeader({
|
|
60
|
+
command: "migration plan",
|
|
61
|
+
description: "Plan a migration from contract changes",
|
|
62
|
+
url: "https://pris.ly/migration-plan",
|
|
63
|
+
details,
|
|
64
|
+
flags
|
|
65
|
+
});
|
|
66
|
+
ui.stderr(header);
|
|
67
|
+
}
|
|
68
|
+
let contractJsonContent;
|
|
69
|
+
try {
|
|
70
|
+
contractJsonContent = await readFile(contractPathAbsolute, "utf-8");
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (error instanceof Error && error.code === "ENOENT") return notOk(errorFileNotFound(contractPathAbsolute, {
|
|
73
|
+
why: `Contract file not found at ${contractPathAbsolute}`,
|
|
74
|
+
fix: `Run \`prisma-next contract emit\` to generate ${contractPath}, or update \`config.contract.output\` in ${configPath}`
|
|
75
|
+
}));
|
|
76
|
+
return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}` }));
|
|
77
|
+
}
|
|
78
|
+
let toContractJson;
|
|
79
|
+
try {
|
|
80
|
+
toContractJson = JSON.parse(contractJsonContent);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
return notOk(errorContractValidationFailed(`Contract JSON is invalid: ${error instanceof Error ? error.message : String(error)}`, { where: { path: contractPathAbsolute } }));
|
|
83
|
+
}
|
|
84
|
+
const rawStorageHash = toContractJson.storage?.storageHash;
|
|
85
|
+
if (typeof rawStorageHash !== "string") return notOk(errorContractValidationFailed("Contract is missing storageHash", { where: { path: contractPathAbsolute } }));
|
|
86
|
+
const toStorageHash = rawStorageHash;
|
|
87
|
+
let fromContract = null;
|
|
88
|
+
let fromHash = EMPTY_CONTRACT_HASH;
|
|
89
|
+
try {
|
|
90
|
+
const { attested: bundles, drafts, graph } = await loadAllBundles(migrationsDir);
|
|
91
|
+
const existingDraft = drafts.find((d) => d.manifest.to === toStorageHash);
|
|
92
|
+
if (existingDraft) return notOk(errorRuntime("A draft migration to this contract already exists", {
|
|
93
|
+
why: `Draft migration at "${existingDraft.dirName}" already targets ${toStorageHash}`,
|
|
94
|
+
fix: `Run 'prisma-next migration verify --dir ${migrationsRelative}/${existingDraft.dirName}' to attest it, or delete it and re-plan.`
|
|
95
|
+
}));
|
|
96
|
+
if (options.from) {
|
|
97
|
+
const resolved = resolveBundleByPrefix(bundles, options.from);
|
|
98
|
+
if (!resolved.ok) {
|
|
99
|
+
const f = resolved.failure;
|
|
100
|
+
return notOk(f.reason === "ambiguous" ? errorRuntime("Multiple matching migrations found", {
|
|
101
|
+
why: `Prefix "${options.from}" matches ${f.count} migrations in ${migrationsRelative}`,
|
|
102
|
+
fix: "Provide a longer prefix to disambiguate, or omit --from to use the latest migration target."
|
|
103
|
+
}) : errorRuntime("Starting contract not found", {
|
|
104
|
+
why: `No migration with to hash matching "${options.from}" exists in ${migrationsRelative}`,
|
|
105
|
+
fix: "Check that the --from hash matches a known migration target hash, or omit --from to use the latest migration target."
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
fromHash = resolved.value.manifest.to;
|
|
109
|
+
fromContract = resolved.value.manifest.toContract;
|
|
110
|
+
} else {
|
|
111
|
+
const latestMigration = findLatestMigration(graph);
|
|
112
|
+
if (latestMigration) {
|
|
113
|
+
fromHash = latestMigration.to;
|
|
114
|
+
const leafPkg = bundles.find((p) => p.manifest.migrationId === latestMigration.migrationId);
|
|
115
|
+
if (leafPkg) fromContract = leafPkg.manifest.toContract;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} catch (error) {
|
|
119
|
+
if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
if (fromHash === toStorageHash) return ok({
|
|
123
|
+
ok: true,
|
|
124
|
+
noOp: true,
|
|
125
|
+
from: fromHash,
|
|
126
|
+
to: toStorageHash,
|
|
127
|
+
operations: [],
|
|
128
|
+
summary: "No changes detected between contracts",
|
|
129
|
+
timings: { total: Date.now() - startTime }
|
|
130
|
+
});
|
|
131
|
+
const migrations = getTargetMigrations(config.target);
|
|
132
|
+
if (!migrations) return notOk(errorTargetMigrationNotSupported({ why: `Target "${config.target.id}" does not support migrations` }));
|
|
133
|
+
const frameworkComponents = assertFrameworkComponentsCompatible(config.family.familyId, config.target.targetId, [
|
|
134
|
+
config.target,
|
|
135
|
+
config.adapter,
|
|
136
|
+
...config.extensionPacks ?? []
|
|
137
|
+
]);
|
|
138
|
+
if (migrations.planWithDescriptors) {
|
|
139
|
+
const descriptorResult = migrations.planWithDescriptors({
|
|
140
|
+
fromContract,
|
|
141
|
+
toContract: toContractJson,
|
|
142
|
+
frameworkComponents
|
|
143
|
+
});
|
|
144
|
+
if (!descriptorResult.ok) return notOk(errorMigrationPlanningFailed({ conflicts: descriptorResult.conflicts }));
|
|
145
|
+
if (descriptorResult.descriptors.length === 0) return notOk(errorMigrationPlanningFailed({ conflicts: [{
|
|
146
|
+
kind: "unsupportedChange",
|
|
147
|
+
summary: "Contract changed but planner produced no operations. This indicates unsupported or ignored changes."
|
|
148
|
+
}] }));
|
|
149
|
+
const timestamp = /* @__PURE__ */ new Date();
|
|
150
|
+
const packageDir = join(migrationsDir, formatMigrationDirName(timestamp, options.name ?? "migration"));
|
|
151
|
+
const manifest = {
|
|
152
|
+
from: fromHash,
|
|
153
|
+
to: toStorageHash,
|
|
154
|
+
migrationId: null,
|
|
155
|
+
kind: "regular",
|
|
156
|
+
fromContract,
|
|
157
|
+
toContract: toContractJson,
|
|
158
|
+
hints: {
|
|
159
|
+
used: [],
|
|
160
|
+
applied: [],
|
|
161
|
+
plannerVersion: "2.0.0",
|
|
162
|
+
planningStrategy: "descriptors"
|
|
163
|
+
},
|
|
164
|
+
labels: [],
|
|
165
|
+
createdAt: timestamp.toISOString()
|
|
166
|
+
};
|
|
167
|
+
try {
|
|
168
|
+
await writeMigrationPackage(packageDir, manifest, []);
|
|
169
|
+
await scaffoldMigrationTs(packageDir, {
|
|
170
|
+
descriptors: descriptorResult.descriptors,
|
|
171
|
+
contractJsonPath: contractPathAbsolute
|
|
172
|
+
});
|
|
173
|
+
if (descriptorResult.needsDataMigration) return ok({
|
|
174
|
+
ok: true,
|
|
175
|
+
noOp: false,
|
|
176
|
+
from: fromHash,
|
|
177
|
+
to: toStorageHash,
|
|
178
|
+
dir: relative(process.cwd(), packageDir),
|
|
179
|
+
operations: descriptorResult.descriptors.map((d) => ({
|
|
180
|
+
id: d.kind,
|
|
181
|
+
label: d.kind,
|
|
182
|
+
operationClass: "data"
|
|
183
|
+
})),
|
|
184
|
+
sql: [],
|
|
185
|
+
summary: `Planned ${descriptorResult.descriptors.length} operation(s) — data migration required. Edit migration.ts and run \`migration verify --dir ${relative(process.cwd(), packageDir)}\` to attest.`,
|
|
186
|
+
timings: { total: Date.now() - startTime }
|
|
187
|
+
});
|
|
188
|
+
const evaluatedDescriptors = await evaluateMigrationTs(packageDir);
|
|
189
|
+
if (!migrations.resolveDescriptors) throw errorTargetMigrationNotSupported({ why: `Target "${config.target.targetId}" does not implement resolveDescriptors; cannot finalize migration plan with migration.ts` });
|
|
190
|
+
const resolvedOps = migrations.resolveDescriptors(evaluatedDescriptors, {
|
|
191
|
+
fromContract,
|
|
192
|
+
toContract: toContractJson,
|
|
193
|
+
frameworkComponents
|
|
194
|
+
});
|
|
195
|
+
await writeMigrationOps(packageDir, resolvedOps);
|
|
196
|
+
const migrationId = await attestMigration(packageDir);
|
|
197
|
+
const sql = extractSqlDdl(resolvedOps);
|
|
198
|
+
return ok({
|
|
199
|
+
ok: true,
|
|
200
|
+
noOp: false,
|
|
201
|
+
from: fromHash,
|
|
202
|
+
to: toStorageHash,
|
|
203
|
+
migrationId,
|
|
204
|
+
dir: relative(process.cwd(), packageDir),
|
|
205
|
+
operations: resolvedOps.map((op) => ({
|
|
206
|
+
id: op.id,
|
|
207
|
+
label: op.label,
|
|
208
|
+
operationClass: op.operationClass
|
|
209
|
+
})),
|
|
210
|
+
sql,
|
|
211
|
+
summary: `Planned ${resolvedOps.length} operation(s)`,
|
|
212
|
+
timings: { total: Date.now() - startTime }
|
|
213
|
+
});
|
|
214
|
+
} catch (error) {
|
|
215
|
+
return notOk(mapMigrationToolsError(error));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return notOk(errorTargetMigrationNotSupported({ why: `Target "${config.target.id}" does not support planWithDescriptors` }));
|
|
219
|
+
}
|
|
220
|
+
function createMigrationPlanCommand() {
|
|
221
|
+
const command = new Command("plan");
|
|
222
|
+
setCommandDescriptions(command, "Plan a migration from contract changes", "Compares the emitted contract against the latest on-disk migration state and\nproduces a new migration package with the required operations. No database\nconnection is needed — this is a fully offline operation.");
|
|
223
|
+
setCommandExamples(command, ["prisma-next migration plan", "prisma-next migration plan --name add-users-table"]);
|
|
224
|
+
addGlobalOptions(command).option("--config <path>", "Path to prisma-next.config.ts").option("--name <slug>", "Name slug for the migration directory", "migration").option("--from <hash>", "Explicit starting contract hash (overrides latest migration target)").action(async (options) => {
|
|
225
|
+
const flags = parseGlobalFlags(options);
|
|
226
|
+
const startTime = Date.now();
|
|
227
|
+
const ui = new TerminalUI({
|
|
228
|
+
color: flags.color,
|
|
229
|
+
interactive: flags.interactive
|
|
230
|
+
});
|
|
231
|
+
const exitCode = handleResult(await executeMigrationPlanCommand(options, flags, ui, startTime), flags, ui, (planResult) => {
|
|
232
|
+
if (flags.json) ui.output(JSON.stringify(planResult, null, 2));
|
|
233
|
+
else if (!flags.quiet) ui.log(formatMigrationPlanOutput(planResult, flags));
|
|
234
|
+
});
|
|
235
|
+
process.exit(exitCode);
|
|
236
|
+
});
|
|
237
|
+
return command;
|
|
238
|
+
}
|
|
239
|
+
function formatMigrationPlanOutput(result, flags) {
|
|
240
|
+
const lines = [];
|
|
241
|
+
const useColor = flags.color !== false;
|
|
242
|
+
const green_ = useColor ? (s) => `\x1b[32m${s}\x1b[0m` : (s) => s;
|
|
243
|
+
const yellow_ = useColor ? (s) => `\x1b[33m${s}\x1b[0m` : (s) => s;
|
|
244
|
+
const dim_ = useColor ? (s) => `\x1b[2m${s}\x1b[0m` : (s) => s;
|
|
245
|
+
if (result.noOp) {
|
|
246
|
+
lines.push(`${green_("✔")} No changes detected`);
|
|
247
|
+
lines.push(dim_(` from: ${result.from}`));
|
|
248
|
+
lines.push(dim_(` to: ${result.to}`));
|
|
249
|
+
return lines.join("\n");
|
|
250
|
+
}
|
|
251
|
+
lines.push(`${green_("✔")} ${result.summary}`);
|
|
252
|
+
lines.push("");
|
|
253
|
+
if (result.operations.length > 0) {
|
|
254
|
+
lines.push(dim_("│"));
|
|
255
|
+
for (let i = 0; i < result.operations.length; i++) {
|
|
256
|
+
const op = result.operations[i];
|
|
257
|
+
const treeChar = i === result.operations.length - 1 ? "└" : "├";
|
|
258
|
+
const opClassLabel = op.operationClass === "destructive" ? yellow_(`[${op.operationClass}]`) : dim_(`[${op.operationClass}]`);
|
|
259
|
+
lines.push(`${dim_(treeChar)}─ ${op.label} ${opClassLabel}`);
|
|
260
|
+
}
|
|
261
|
+
if (result.operations.some((op) => op.operationClass === "destructive")) {
|
|
262
|
+
lines.push("");
|
|
263
|
+
lines.push(`${yellow_("⚠")} This migration contains destructive operations that may cause data loss.`);
|
|
264
|
+
}
|
|
265
|
+
lines.push("");
|
|
266
|
+
}
|
|
267
|
+
lines.push(dim_(`from: ${result.from}`));
|
|
268
|
+
lines.push(dim_(`to: ${result.to}`));
|
|
269
|
+
if (result.migrationId) lines.push(dim_(`migrationId: ${result.migrationId}`));
|
|
270
|
+
if (result.dir) lines.push(dim_(`dir: ${result.dir}`));
|
|
271
|
+
if (result.sql && result.sql.length > 0) {
|
|
272
|
+
lines.push("");
|
|
273
|
+
lines.push(dim_("DDL preview"));
|
|
274
|
+
lines.push("");
|
|
275
|
+
for (const statement of result.sql) {
|
|
276
|
+
const trimmed = statement.trim();
|
|
277
|
+
if (!trimmed) continue;
|
|
278
|
+
const line = trimmed.endsWith(";") ? trimmed : `${trimmed};`;
|
|
279
|
+
lines.push(line);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (flags.verbose && result.timings) {
|
|
283
|
+
lines.push("");
|
|
284
|
+
lines.push(dim_(`Total time: ${result.timings.total}ms`));
|
|
285
|
+
}
|
|
286
|
+
return lines.join("\n");
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Resolve a migration bundle by exact hash or prefix match.
|
|
290
|
+
*
|
|
291
|
+
* Tries exact match first, then prefix match (auto-prepending `sha256:` when
|
|
292
|
+
* the needle omits the scheme). Returns the matched bundle on success, or a
|
|
293
|
+
* discriminated failure indicating whether the prefix was ambiguous or simply
|
|
294
|
+
* not found.
|
|
295
|
+
*
|
|
296
|
+
* @internal Exported for testing only.
|
|
297
|
+
*/
|
|
298
|
+
function resolveBundleByPrefix(bundles, needle) {
|
|
299
|
+
const exact = bundles.find((p) => p.manifest.to === needle);
|
|
300
|
+
if (exact) return ok(exact);
|
|
301
|
+
const prefixWithScheme = needle.startsWith("sha256:") ? needle : `sha256:${needle}`;
|
|
302
|
+
const candidates = bundles.filter((p) => p.manifest.to.startsWith(prefixWithScheme));
|
|
303
|
+
if (candidates.length === 1) return ok(candidates[0]);
|
|
304
|
+
if (candidates.length > 1) return notOk({
|
|
305
|
+
reason: "ambiguous",
|
|
306
|
+
count: candidates.length
|
|
307
|
+
});
|
|
308
|
+
return notOk({ reason: "not-found" });
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
//#endregion
|
|
312
|
+
export { createMigrationPlanCommand, resolveBundleByPrefix };
|
|
313
|
+
//# sourceMappingURL=migration-plan.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-plan.mjs","names":["details: Array<{ label: string; value: string }>","contractJsonContent: string","toContractJson: Contract","fromContract: Contract | null","fromHash: string","manifest: MigrationManifest","lines: string[]"],"sources":["../../src/commands/migration-plan.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport type { Contract } from '@prisma-next/contract/types';\nimport type { OperationDescriptor } from '@prisma-next/framework-components/control';\nimport { attestMigration } from '@prisma-next/migration-tools/attestation';\nimport { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport { findLatestMigration } from '@prisma-next/migration-tools/dag';\nimport {\n formatMigrationDirName,\n writeMigrationOps,\n writeMigrationPackage,\n} from '@prisma-next/migration-tools/io';\nimport {\n evaluateMigrationTs,\n scaffoldMigrationTs,\n} from '@prisma-next/migration-tools/migration-ts';\nimport { type MigrationManifest, MigrationToolsError } from '@prisma-next/migration-tools/types';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { join, relative } from 'pathe';\nimport { loadConfig } from '../config-loader';\nimport { extractSqlDdl } from '../control-api/operations/extract-sql-ddl';\nimport {\n type CliErrorConflict,\n CliStructuredError,\n errorContractValidationFailed,\n errorFileNotFound,\n errorMigrationPlanningFailed,\n errorRuntime,\n errorTargetMigrationNotSupported,\n errorUnexpected,\n} from '../utils/cli-errors';\nimport {\n addGlobalOptions,\n getTargetMigrations,\n loadAllBundles,\n resolveContractPath,\n resolveMigrationPaths,\n setCommandDescriptions,\n setCommandExamples,\n} from '../utils/command-helpers';\nimport { formatStyledHeader } from '../utils/formatters/styled';\nimport { assertFrameworkComponentsCompatible } from '../utils/framework-components';\nimport type { CommonCommandOptions } from '../utils/global-flags';\nimport { type GlobalFlags, parseGlobalFlags } from '../utils/global-flags';\nimport { handleResult } from '../utils/result-handler';\nimport { TerminalUI } from '../utils/terminal-ui';\n\ninterface MigrationPlanOptions extends CommonCommandOptions {\n readonly config?: string;\n readonly name?: string;\n readonly from?: string;\n}\n\nexport interface MigrationPlanResult {\n readonly ok: boolean;\n readonly noOp: boolean;\n readonly from: string;\n readonly to: string;\n readonly migrationId?: string;\n readonly dir?: string;\n readonly operations: readonly {\n readonly id: string;\n readonly label: string;\n readonly operationClass: string;\n }[];\n readonly sql?: readonly string[];\n readonly summary: string;\n readonly timings: {\n readonly total: number;\n };\n}\n\nfunction mapMigrationToolsError(error: unknown): CliStructuredError {\n if (CliStructuredError.is(error)) {\n return error;\n }\n if (MigrationToolsError.is(error)) {\n return errorRuntime(error.message, {\n why: error.why,\n fix: error.fix,\n meta: { code: error.code, ...(error.details ?? {}) },\n });\n }\n return errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Unexpected error during migration plan: ${error instanceof Error ? error.message : String(error)}`,\n });\n}\n\nasync function executeMigrationPlanCommand(\n options: MigrationPlanOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n startTime: number,\n): Promise<Result<MigrationPlanResult, CliStructuredError>> {\n const config = await loadConfig(options.config);\n const { configPath, migrationsDir, migrationsRelative } = resolveMigrationPaths(\n options.config,\n config,\n );\n\n const contractPathAbsolute = resolveContractPath(config);\n const contractPath = relative(process.cwd(), contractPathAbsolute);\n\n if (!flags.json && !flags.quiet) {\n const details: Array<{ label: string; value: string }> = [\n { label: 'config', value: configPath },\n { label: 'contract', value: contractPath },\n { label: 'migrations', value: migrationsRelative },\n ];\n if (options.from) {\n details.push({ label: 'from', value: options.from });\n }\n if (options.name) {\n details.push({ label: 'name', value: options.name });\n }\n const header = formatStyledHeader({\n command: 'migration plan',\n description: 'Plan a migration from contract changes',\n url: 'https://pris.ly/migration-plan',\n details,\n flags,\n });\n ui.stderr(header);\n }\n\n // Load contract file (the \"to\" contract)\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 toContractJson: Contract;\n try {\n toContractJson = JSON.parse(contractJsonContent) as Contract;\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 rawStorageHash = toContractJson.storage?.storageHash;\n if (typeof rawStorageHash !== 'string') {\n return notOk(\n errorContractValidationFailed('Contract is missing storageHash', {\n where: { path: contractPathAbsolute },\n }),\n );\n }\n const toStorageHash = rawStorageHash;\n\n // Read existing migrations and determine \"from\" contract\n let fromContract: Contract | null = null;\n let fromHash: string = EMPTY_CONTRACT_HASH;\n\n try {\n const { attested: bundles, drafts, graph } = await loadAllBundles(migrationsDir);\n\n // Check if a draft migration already targets this contract\n const existingDraft = drafts.find((d) => d.manifest.to === toStorageHash);\n if (existingDraft) {\n return notOk(\n errorRuntime('A draft migration to this contract already exists', {\n why: `Draft migration at \"${existingDraft.dirName}\" already targets ${toStorageHash}`,\n fix: `Run 'prisma-next migration verify --dir ${migrationsRelative}/${existingDraft.dirName}' to attest it, or delete it and re-plan.`,\n }),\n );\n }\n\n if (options.from) {\n const resolved = resolveBundleByPrefix(bundles, options.from);\n if (!resolved.ok) {\n const f = resolved.failure;\n return notOk(\n f.reason === 'ambiguous'\n ? errorRuntime('Multiple matching migrations found', {\n why: `Prefix \"${options.from}\" matches ${f.count} migrations in ${migrationsRelative}`,\n fix: 'Provide a longer prefix to disambiguate, or omit --from to use the latest migration target.',\n })\n : errorRuntime('Starting contract not found', {\n why: `No migration with to hash matching \"${options.from}\" exists in ${migrationsRelative}`,\n fix: 'Check that the --from hash matches a known migration target hash, or omit --from to use the latest migration target.',\n }),\n );\n }\n fromHash = resolved.value.manifest.to;\n fromContract = resolved.value.manifest.toContract;\n } else {\n const latestMigration = findLatestMigration(graph);\n if (latestMigration) {\n fromHash = latestMigration.to;\n const leafPkg = bundles.find((p) => p.manifest.migrationId === latestMigration.migrationId);\n if (leafPkg) {\n fromContract = leafPkg.manifest.toContract;\n }\n }\n }\n } catch (error) {\n if (MigrationToolsError.is(error)) {\n return notOk(mapMigrationToolsError(error));\n }\n throw error;\n }\n\n // Check for no-op (same hash means no changes)\n if (fromHash === toStorageHash) {\n const result: MigrationPlanResult = {\n ok: true,\n noOp: true,\n from: fromHash,\n to: toStorageHash,\n operations: [],\n summary: 'No changes detected between contracts',\n timings: { total: Date.now() - startTime },\n };\n return ok(result);\n }\n\n // Check target supports migrations\n const migrations = getTargetMigrations(config.target);\n if (!migrations) {\n return notOk(\n errorTargetMigrationNotSupported({\n why: `Target \"${config.target.id}\" does not support migrations`,\n }),\n );\n }\n const frameworkComponents = assertFrameworkComponentsCompatible(\n config.family.familyId,\n config.target.targetId,\n [config.target, config.adapter, ...(config.extensionPacks ?? [])],\n );\n\n // Use descriptor-based planner if available, fall back to old planner\n if (migrations.planWithDescriptors) {\n const descriptorResult = migrations.planWithDescriptors({\n fromContract,\n toContract: toContractJson,\n frameworkComponents,\n });\n\n if (!descriptorResult.ok) {\n return notOk(\n errorMigrationPlanningFailed({\n conflicts: descriptorResult.conflicts as readonly CliErrorConflict[],\n }),\n );\n }\n\n if (descriptorResult.descriptors.length === 0) {\n return notOk(\n errorMigrationPlanningFailed({\n conflicts: [\n {\n kind: 'unsupportedChange',\n summary:\n 'Contract changed but planner produced no operations. ' +\n 'This indicates unsupported or ignored changes.',\n },\n ],\n }),\n );\n }\n\n // Build manifest and write migration package\n const timestamp = new Date();\n const slug = options.name ?? 'migration';\n const dirName = formatMigrationDirName(timestamp, slug);\n const packageDir = join(migrationsDir, dirName);\n\n const manifest: MigrationManifest = {\n from: fromHash,\n to: toStorageHash,\n migrationId: null,\n kind: 'regular',\n fromContract,\n toContract: toContractJson,\n hints: {\n used: [],\n applied: [],\n plannerVersion: '2.0.0',\n planningStrategy: 'descriptors',\n },\n labels: [],\n createdAt: timestamp.toISOString(),\n };\n\n try {\n // Always write migration.ts with the descriptors\n // Write package with empty ops first (draft)\n await writeMigrationPackage(packageDir, manifest, []);\n await scaffoldMigrationTs(packageDir, {\n descriptors: descriptorResult.descriptors,\n contractJsonPath: contractPathAbsolute,\n });\n\n if (descriptorResult.needsDataMigration) {\n // Draft — user must fill in dataTransform and run verify\n const result: MigrationPlanResult = {\n ok: true,\n noOp: false,\n from: fromHash,\n to: toStorageHash,\n dir: relative(process.cwd(), packageDir),\n operations: descriptorResult.descriptors.map((d) => ({\n id: (d as { kind: string }).kind,\n label: (d as { kind: string }).kind,\n operationClass: 'data' as const,\n })),\n sql: [],\n summary: `Planned ${descriptorResult.descriptors.length} operation(s) — data migration required. Edit migration.ts and run \\`migration verify --dir ${relative(process.cwd(), packageDir)}\\` to attest.`,\n timings: { total: Date.now() - startTime },\n };\n return ok(result);\n }\n\n // No data migration — evaluate, resolve, write ops, attest\n const evaluatedDescriptors = await evaluateMigrationTs(packageDir);\n\n if (!migrations.resolveDescriptors) {\n throw errorTargetMigrationNotSupported({\n why: `Target \"${config.target.targetId}\" does not implement resolveDescriptors; cannot finalize migration plan with migration.ts`,\n });\n }\n\n const resolvedOps = migrations.resolveDescriptors(\n evaluatedDescriptors as OperationDescriptor[],\n {\n fromContract,\n toContract: toContractJson,\n frameworkComponents,\n },\n );\n\n await writeMigrationOps(packageDir, resolvedOps);\n const migrationId = await attestMigration(packageDir);\n\n const sql = extractSqlDdl(resolvedOps);\n const result: MigrationPlanResult = {\n ok: true,\n noOp: false,\n from: fromHash,\n to: toStorageHash,\n migrationId,\n dir: relative(process.cwd(), packageDir),\n operations: resolvedOps.map((op) => ({\n id: op.id,\n label: op.label,\n operationClass: op.operationClass,\n })),\n sql,\n summary: `Planned ${resolvedOps.length} operation(s)`,\n timings: { total: Date.now() - startTime },\n };\n return ok(result);\n } catch (error) {\n return notOk(mapMigrationToolsError(error));\n }\n }\n\n return notOk(\n errorTargetMigrationNotSupported({\n why: `Target \"${config.target.id}\" does not support planWithDescriptors`,\n }),\n );\n}\n\nexport function createMigrationPlanCommand(): Command {\n const command = new Command('plan');\n setCommandDescriptions(\n command,\n 'Plan a migration from contract changes',\n 'Compares the emitted contract against the latest on-disk migration state and\\n' +\n 'produces a new migration package with the required operations. No database\\n' +\n 'connection is needed — this is a fully offline operation.',\n );\n setCommandExamples(command, [\n 'prisma-next migration plan',\n 'prisma-next migration plan --name add-users-table',\n ]);\n addGlobalOptions(command)\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option('--name <slug>', 'Name slug for the migration directory', 'migration')\n .option('--from <hash>', 'Explicit starting contract hash (overrides latest migration target)')\n .action(async (options: MigrationPlanOptions) => {\n const flags = parseGlobalFlags(options);\n const startTime = Date.now();\n\n const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });\n const result = await executeMigrationPlanCommand(options, flags, ui, startTime);\n\n const exitCode = handleResult(result, flags, ui, (planResult) => {\n if (flags.json) {\n ui.output(JSON.stringify(planResult, null, 2));\n } else if (!flags.quiet) {\n ui.log(formatMigrationPlanOutput(planResult, flags));\n }\n });\n\n process.exit(exitCode);\n });\n\n return command;\n}\n\nfunction formatMigrationPlanOutput(result: MigrationPlanResult, flags: GlobalFlags): string {\n const lines: string[] = [];\n const useColor = flags.color !== false;\n\n const green_ = useColor ? (s: string) => `\\x1b[32m${s}\\x1b[0m` : (s: string) => s;\n const yellow_ = useColor ? (s: string) => `\\x1b[33m${s}\\x1b[0m` : (s: string) => s;\n const dim_ = useColor ? (s: string) => `\\x1b[2m${s}\\x1b[0m` : (s: string) => s;\n\n if (result.noOp) {\n lines.push(`${green_('✔')} No changes detected`);\n lines.push(dim_(` from: ${result.from}`));\n lines.push(dim_(` to: ${result.to}`));\n return lines.join('\\n');\n }\n\n lines.push(`${green_('✔')} ${result.summary}`);\n lines.push('');\n\n if (result.operations.length > 0) {\n lines.push(dim_('│'));\n for (let i = 0; i < result.operations.length; i++) {\n const op = result.operations[i]!;\n const isLast = i === result.operations.length - 1;\n const treeChar = isLast ? '└' : '├';\n const opClassLabel =\n op.operationClass === 'destructive'\n ? yellow_(`[${op.operationClass}]`)\n : dim_(`[${op.operationClass}]`);\n lines.push(`${dim_(treeChar)}─ ${op.label} ${opClassLabel}`);\n }\n\n const hasDestructive = result.operations.some((op) => op.operationClass === 'destructive');\n if (hasDestructive) {\n lines.push('');\n lines.push(\n `${yellow_('⚠')} This migration contains destructive operations that may cause data loss.`,\n );\n }\n lines.push('');\n }\n\n lines.push(dim_(`from: ${result.from}`));\n lines.push(dim_(`to: ${result.to}`));\n if (result.migrationId) {\n lines.push(dim_(`migrationId: ${result.migrationId}`));\n }\n if (result.dir) {\n lines.push(dim_(`dir: ${result.dir}`));\n }\n\n if (result.sql && result.sql.length > 0) {\n lines.push('');\n lines.push(dim_('DDL preview'));\n lines.push('');\n for (const statement of result.sql) {\n const trimmed = statement.trim();\n if (!trimmed) continue;\n const line = trimmed.endsWith(';') ? trimmed : `${trimmed};`;\n lines.push(line);\n }\n }\n\n if (flags.verbose && result.timings) {\n lines.push('');\n lines.push(dim_(`Total time: ${result.timings.total}ms`));\n }\n\n return lines.join('\\n');\n}\n\nexport type PrefixResolutionFailure =\n | { reason: 'ambiguous'; count: number }\n | { reason: 'not-found' };\n\n/**\n * Resolve a migration bundle by exact hash or prefix match.\n *\n * Tries exact match first, then prefix match (auto-prepending `sha256:` when\n * the needle omits the scheme). Returns the matched bundle on success, or a\n * discriminated failure indicating whether the prefix was ambiguous or simply\n * not found.\n *\n * @internal Exported for testing only.\n */\nexport function resolveBundleByPrefix<T extends { manifest: { to: string } }>(\n bundles: readonly T[],\n needle: string,\n): Result<T, PrefixResolutionFailure> {\n const exact = bundles.find((p) => p.manifest.to === needle);\n if (exact) return ok(exact);\n\n const prefixWithScheme = needle.startsWith('sha256:') ? needle : `sha256:${needle}`;\n const candidates = bundles.filter((p) => p.manifest.to.startsWith(prefixWithScheme));\n\n if (candidates.length === 1) return ok(candidates[0]!);\n if (candidates.length > 1) return notOk({ reason: 'ambiguous', count: candidates.length });\n return notOk({ reason: 'not-found' });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwEA,SAAS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C,MAAM,UAAU,UAAU,MAAM;AAChC,OAAI,CAAC,QAAS;GACd,MAAM,OAAO,QAAQ,SAAS,IAAI,GAAG,UAAU,GAAG,QAAQ;AAC1D,SAAM,KAAK,KAAK;;;AAIpB,KAAI,MAAM,WAAW,OAAO,SAAS;AACnC,QAAM,KAAK,GAAG;AACd,QAAM,KAAK,KAAK,eAAe,OAAO,QAAQ,MAAM,IAAI,CAAC;;AAG3D,QAAO,MAAM,KAAK,KAAK;;;;;;;;;;;;AAiBzB,SAAgB,sBACd,SACA,QACoC;CACpC,MAAM,QAAQ,QAAQ,MAAM,MAAM,EAAE,SAAS,OAAO,OAAO;AAC3D,KAAI,MAAO,QAAO,GAAG,MAAM;CAE3B,MAAM,mBAAmB,OAAO,WAAW,UAAU,GAAG,SAAS,UAAU;CAC3E,MAAM,aAAa,QAAQ,QAAQ,MAAM,EAAE,SAAS,GAAG,WAAW,iBAAiB,CAAC;AAEpF,KAAI,WAAW,WAAW,EAAG,QAAO,GAAG,WAAW,GAAI;AACtD,KAAI,WAAW,SAAS,EAAG,QAAO,MAAM;EAAE,QAAQ;EAAa,OAAO,WAAW;EAAQ,CAAC;AAC1F,QAAO,MAAM,EAAE,QAAQ,aAAa,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { t as CliStructuredError } from "../cli-errors-DStABy9d.mjs";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { Result } from "@prisma-next/utils/result";
|
|
4
|
+
|
|
5
|
+
//#region src/commands/migration-ref.d.ts
|
|
6
|
+
interface RefSetResult {
|
|
7
|
+
readonly ok: true;
|
|
8
|
+
readonly ref: string;
|
|
9
|
+
readonly hash: string;
|
|
10
|
+
}
|
|
11
|
+
interface RefGetResult {
|
|
12
|
+
readonly ok: true;
|
|
13
|
+
readonly ref: string;
|
|
14
|
+
readonly hash: string;
|
|
15
|
+
}
|
|
16
|
+
interface RefDeleteResult {
|
|
17
|
+
readonly ok: true;
|
|
18
|
+
readonly ref: string;
|
|
19
|
+
readonly deleted: true;
|
|
20
|
+
}
|
|
21
|
+
interface RefListResult {
|
|
22
|
+
readonly ok: true;
|
|
23
|
+
readonly refs: Record<string, string>;
|
|
24
|
+
}
|
|
25
|
+
declare function cliErrorInvalidRefName(name: string): CliStructuredError;
|
|
26
|
+
declare function cliErrorInvalidRefValue(hash: string): CliStructuredError;
|
|
27
|
+
declare function errorRefNotFound(name: string): CliStructuredError;
|
|
28
|
+
declare function executeRefSetCommand(name: string, hash: string, options: {
|
|
29
|
+
config?: string;
|
|
30
|
+
}): Promise<Result<RefSetResult, CliStructuredError>>;
|
|
31
|
+
declare function executeRefGetCommand(name: string, options: {
|
|
32
|
+
config?: string;
|
|
33
|
+
}): Promise<Result<RefGetResult, CliStructuredError>>;
|
|
34
|
+
declare function executeRefDeleteCommand(name: string, options: {
|
|
35
|
+
config?: string;
|
|
36
|
+
}): Promise<Result<RefDeleteResult, CliStructuredError>>;
|
|
37
|
+
declare function executeRefListCommand(options: {
|
|
38
|
+
config?: string;
|
|
39
|
+
}): Promise<Result<RefListResult, CliStructuredError>>;
|
|
40
|
+
declare function createMigrationRefCommand(): Command;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { cliErrorInvalidRefName, cliErrorInvalidRefValue, createMigrationRefCommand, errorRefNotFound, executeRefDeleteCommand, executeRefGetCommand, executeRefListCommand, executeRefSetCommand };
|
|
43
|
+
//# sourceMappingURL=migration-ref.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-ref.d.mts","names":[],"sources":["../../src/commands/migration-ref.ts"],"sourcesContent":[],"mappings":";;;;;UAmBU,YAAA;;EAAA,SAAA,GAAA,EAAA,MAAY;EAMZ,SAAA,IAAA,EAAY,MAAA;AAAA;AAMG,UANf,YAAA,CAYa;EAqBd,SAAA,EAAA,EAAA,IAAA;EAOA,SAAA,GAAA,EAAA,MAAA;EAOA,SAAA,IAAA,EAAA,MAAgB;AAAkC;UAzCjD,eAAA,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XKl8f.mjs";
|
|
2
|
+
import { _ as errorUnexpected, m as errorRuntime, t as CliStructuredError } from "../cli-errors-BDCYR5ap.mjs";
|
|
3
|
+
import { h as formatCommandHelp, m as parseGlobalFlags, n as addGlobalOptions, t as handleResult, u as setCommandDescriptions } from "../result-handler-oK_vA-Fn.mjs";
|
|
4
|
+
import { t as TerminalUI } from "../terminal-ui-C5k88MmW.mjs";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
import { notOk, ok } from "@prisma-next/utils/result";
|
|
7
|
+
import { resolve } from "pathe";
|
|
8
|
+
import { MigrationToolsError } from "@prisma-next/migration-tools/types";
|
|
9
|
+
import { readRefs, resolveRef, validateRefName, validateRefValue, writeRefs } from "@prisma-next/migration-tools/refs";
|
|
10
|
+
|
|
11
|
+
//#region src/commands/migration-ref.ts
|
|
12
|
+
function resolveRefsPath(configPath, config) {
|
|
13
|
+
return resolve(configPath ? resolve(configPath, "..") : process.cwd(), config?.migrations?.dir ?? "migrations", "refs.json");
|
|
14
|
+
}
|
|
15
|
+
function mapError(error) {
|
|
16
|
+
if (MigrationToolsError.is(error)) return errorRuntime(error.message, {
|
|
17
|
+
why: error.why,
|
|
18
|
+
fix: error.fix,
|
|
19
|
+
meta: { code: error.code }
|
|
20
|
+
});
|
|
21
|
+
return errorUnexpected(error instanceof Error ? error.message : String(error));
|
|
22
|
+
}
|
|
23
|
+
function cliErrorInvalidRefName(name) {
|
|
24
|
+
return errorRuntime(`Invalid ref name "${name}"`, {
|
|
25
|
+
why: `Ref name "${name}" does not match the required format`,
|
|
26
|
+
fix: "Ref names must be lowercase alphanumeric with hyphens or forward slashes, no `.` or `..` segments"
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function cliErrorInvalidRefValue(hash) {
|
|
30
|
+
return errorRuntime(`Invalid contract hash "${hash}"`, {
|
|
31
|
+
why: `"${hash}" is not a valid contract hash`,
|
|
32
|
+
fix: "Contract hashes must match the format \"sha256:<64 hex chars>\". Copy the hash from `prisma-next contract emit` or `migration status --json`."
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function errorRefNotFound(name) {
|
|
36
|
+
return errorRuntime(`Ref "${name}" does not exist`, {
|
|
37
|
+
why: `No ref named "${name}" found in refs.json`,
|
|
38
|
+
fix: `Run \`prisma-next migration ref list\` to see available refs, or \`prisma-next migration ref set ${name} <hash>\` to create it`
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async function executeRefSetCommand(name, hash, options) {
|
|
42
|
+
if (!validateRefName(name)) return notOk(cliErrorInvalidRefName(name));
|
|
43
|
+
if (!validateRefValue(hash)) return notOk(cliErrorInvalidRefValue(hash));
|
|
44
|
+
try {
|
|
45
|
+
const config = await loadConfig(options.config);
|
|
46
|
+
const refsPath = resolveRefsPath(options.config, config);
|
|
47
|
+
await writeRefs(refsPath, {
|
|
48
|
+
...await readRefs(refsPath),
|
|
49
|
+
[name]: hash
|
|
50
|
+
});
|
|
51
|
+
return ok({
|
|
52
|
+
ok: true,
|
|
53
|
+
ref: name,
|
|
54
|
+
hash
|
|
55
|
+
});
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error instanceof CliStructuredError) return notOk(error);
|
|
58
|
+
return notOk(mapError(error));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function executeRefGetCommand(name, options) {
|
|
62
|
+
try {
|
|
63
|
+
const config = await loadConfig(options.config);
|
|
64
|
+
return ok({
|
|
65
|
+
ok: true,
|
|
66
|
+
ref: name,
|
|
67
|
+
hash: resolveRef(await readRefs(resolveRefsPath(options.config, config)), name)
|
|
68
|
+
});
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error instanceof CliStructuredError) return notOk(error);
|
|
71
|
+
return notOk(mapError(error));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function executeRefDeleteCommand(name, options) {
|
|
75
|
+
try {
|
|
76
|
+
const config = await loadConfig(options.config);
|
|
77
|
+
const refsPath = resolveRefsPath(options.config, config);
|
|
78
|
+
const refs = await readRefs(refsPath);
|
|
79
|
+
if (!Object.hasOwn(refs, name)) return notOk(errorRefNotFound(name));
|
|
80
|
+
const { [name]: _, ...remaining } = refs;
|
|
81
|
+
await writeRefs(refsPath, remaining);
|
|
82
|
+
return ok({
|
|
83
|
+
ok: true,
|
|
84
|
+
ref: name,
|
|
85
|
+
deleted: true
|
|
86
|
+
});
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (error instanceof CliStructuredError) return notOk(error);
|
|
89
|
+
return notOk(mapError(error));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function executeRefListCommand(options) {
|
|
93
|
+
try {
|
|
94
|
+
const config = await loadConfig(options.config);
|
|
95
|
+
return ok({
|
|
96
|
+
ok: true,
|
|
97
|
+
refs: await readRefs(resolveRefsPath(options.config, config))
|
|
98
|
+
});
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error instanceof CliStructuredError) return notOk(error);
|
|
101
|
+
return notOk(mapError(error));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function createRefSetCommand() {
|
|
105
|
+
const command = new Command("set");
|
|
106
|
+
setCommandDescriptions(command, "Set a ref to a contract hash", "Sets a named ref to point to a contract hash in migrations/refs.json.");
|
|
107
|
+
addGlobalOptions(command).argument("<name>", "Ref name (e.g., staging, production)").argument("<hash>", "Contract hash to point to").option("--config <path>", "Path to prisma-next.config.ts").action(async (name, hash, options) => {
|
|
108
|
+
const flags = parseGlobalFlags(options);
|
|
109
|
+
const ui = new TerminalUI({
|
|
110
|
+
color: flags.color,
|
|
111
|
+
interactive: flags.interactive
|
|
112
|
+
});
|
|
113
|
+
const exitCode = handleResult(await executeRefSetCommand(name, hash, options), flags, ui, (value) => {
|
|
114
|
+
if (flags.json) ui.output(JSON.stringify(value));
|
|
115
|
+
else if (!flags.quiet) ui.output(`Set ref "${value.ref}" → ${value.hash}`);
|
|
116
|
+
});
|
|
117
|
+
process.exit(exitCode);
|
|
118
|
+
});
|
|
119
|
+
return command;
|
|
120
|
+
}
|
|
121
|
+
function createRefGetCommand() {
|
|
122
|
+
const command = new Command("get");
|
|
123
|
+
setCommandDescriptions(command, "Get the hash for a ref", "Reads a named ref from migrations/refs.json and prints its contract hash.");
|
|
124
|
+
addGlobalOptions(command).argument("<name>", "Ref name to look up").option("--config <path>", "Path to prisma-next.config.ts").action(async (name, options) => {
|
|
125
|
+
const flags = parseGlobalFlags(options);
|
|
126
|
+
const ui = new TerminalUI({
|
|
127
|
+
color: flags.color,
|
|
128
|
+
interactive: flags.interactive
|
|
129
|
+
});
|
|
130
|
+
const exitCode = handleResult(await executeRefGetCommand(name, options), flags, ui, (value) => {
|
|
131
|
+
if (flags.json) ui.output(JSON.stringify(value));
|
|
132
|
+
else ui.output(value.hash);
|
|
133
|
+
});
|
|
134
|
+
process.exit(exitCode);
|
|
135
|
+
});
|
|
136
|
+
return command;
|
|
137
|
+
}
|
|
138
|
+
function createRefDeleteCommand() {
|
|
139
|
+
const command = new Command("delete");
|
|
140
|
+
setCommandDescriptions(command, "Delete a ref", "Removes a named ref from migrations/refs.json.");
|
|
141
|
+
addGlobalOptions(command).argument("<name>", "Ref name to delete").option("--config <path>", "Path to prisma-next.config.ts").action(async (name, options) => {
|
|
142
|
+
const flags = parseGlobalFlags(options);
|
|
143
|
+
const ui = new TerminalUI({
|
|
144
|
+
color: flags.color,
|
|
145
|
+
interactive: flags.interactive
|
|
146
|
+
});
|
|
147
|
+
const exitCode = handleResult(await executeRefDeleteCommand(name, options), flags, ui, (value) => {
|
|
148
|
+
if (flags.json) ui.output(JSON.stringify(value));
|
|
149
|
+
else if (!flags.quiet) ui.output(`Deleted ref "${value.ref}"`);
|
|
150
|
+
});
|
|
151
|
+
process.exit(exitCode);
|
|
152
|
+
});
|
|
153
|
+
return command;
|
|
154
|
+
}
|
|
155
|
+
function createRefListCommand() {
|
|
156
|
+
const command = new Command("list");
|
|
157
|
+
setCommandDescriptions(command, "List all refs", "Lists all named refs from migrations/refs.json.");
|
|
158
|
+
addGlobalOptions(command).option("--config <path>", "Path to prisma-next.config.ts").action(async (options) => {
|
|
159
|
+
const flags = parseGlobalFlags(options);
|
|
160
|
+
const ui = new TerminalUI({
|
|
161
|
+
color: flags.color,
|
|
162
|
+
interactive: flags.interactive
|
|
163
|
+
});
|
|
164
|
+
const exitCode = handleResult(await executeRefListCommand(options), flags, ui, (value) => {
|
|
165
|
+
if (flags.json) ui.output(JSON.stringify(value));
|
|
166
|
+
else if (!flags.quiet) {
|
|
167
|
+
const entries = Object.entries(value.refs);
|
|
168
|
+
if (entries.length === 0) ui.output("No refs defined");
|
|
169
|
+
else for (const [refName, hash] of entries) ui.output(`${refName} → ${hash}`);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
process.exit(exitCode);
|
|
173
|
+
});
|
|
174
|
+
return command;
|
|
175
|
+
}
|
|
176
|
+
function createMigrationRefCommand() {
|
|
177
|
+
const command = new Command("ref");
|
|
178
|
+
setCommandDescriptions(command, "Manage migration refs", "Manage named refs in migrations/refs.json. Refs map logical environment\nnames (e.g., staging, production) to contract hashes.");
|
|
179
|
+
addGlobalOptions(command).configureHelp({
|
|
180
|
+
formatHelp: (cmd) => formatCommandHelp({
|
|
181
|
+
command: cmd,
|
|
182
|
+
flags: parseGlobalFlags({})
|
|
183
|
+
}),
|
|
184
|
+
subcommandDescription: () => ""
|
|
185
|
+
});
|
|
186
|
+
command.addCommand(createRefSetCommand());
|
|
187
|
+
command.addCommand(createRefGetCommand());
|
|
188
|
+
command.addCommand(createRefDeleteCommand());
|
|
189
|
+
command.addCommand(createRefListCommand());
|
|
190
|
+
return command;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
export { cliErrorInvalidRefName, cliErrorInvalidRefValue, createMigrationRefCommand, errorRefNotFound, executeRefDeleteCommand, executeRefGetCommand, executeRefListCommand, executeRefSetCommand };
|
|
195
|
+
//# sourceMappingURL=migration-ref.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-ref.mjs","names":[],"sources":["../../src/commands/migration-ref.ts"],"sourcesContent":["import {\n readRefs,\n resolveRef,\n validateRefName,\n validateRefValue,\n writeRefs,\n} from '@prisma-next/migration-tools/refs';\nimport { MigrationToolsError } from '@prisma-next/migration-tools/types';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { resolve } from 'pathe';\nimport { loadConfig } from '../config-loader';\nimport { CliStructuredError, errorRuntime, errorUnexpected } from '../utils/cli-errors';\nimport { addGlobalOptions, setCommandDescriptions } from '../utils/command-helpers';\nimport { formatCommandHelp } from '../utils/formatters/help';\nimport { parseGlobalFlags } from '../utils/global-flags';\nimport { handleResult } from '../utils/result-handler';\nimport { TerminalUI } from '../utils/terminal-ui';\n\ninterface RefSetResult {\n readonly ok: true;\n readonly ref: string;\n readonly hash: string;\n}\n\ninterface RefGetResult {\n readonly ok: true;\n readonly ref: string;\n readonly hash: string;\n}\n\ninterface RefDeleteResult {\n readonly ok: true;\n readonly ref: string;\n readonly deleted: true;\n}\n\ninterface RefListResult {\n readonly ok: true;\n readonly refs: Record<string, string>;\n}\n\nfunction resolveRefsPath(configPath?: string, config?: { migrations?: { dir?: string } }): string {\n const base = configPath ? resolve(configPath, '..') : process.cwd();\n return resolve(base, config?.migrations?.dir ?? 'migrations', 'refs.json');\n}\n\nfunction mapError(error: unknown): CliStructuredError {\n if (MigrationToolsError.is(error)) {\n return errorRuntime(error.message, {\n why: error.why,\n fix: error.fix,\n meta: { code: error.code },\n });\n }\n return errorUnexpected(error instanceof Error ? error.message : String(error));\n}\n\nfunction cliErrorInvalidRefName(name: string): CliStructuredError {\n return errorRuntime(`Invalid ref name \"${name}\"`, {\n why: `Ref name \"${name}\" does not match the required format`,\n fix: 'Ref names must be lowercase alphanumeric with hyphens or forward slashes, no `.` or `..` segments',\n });\n}\n\nfunction cliErrorInvalidRefValue(hash: string): CliStructuredError {\n return errorRuntime(`Invalid contract hash \"${hash}\"`, {\n why: `\"${hash}\" is not a valid contract hash`,\n fix: 'Contract hashes must match the format \"sha256:<64 hex chars>\". Copy the hash from `prisma-next contract emit` or `migration status --json`.',\n });\n}\n\nfunction errorRefNotFound(name: string): CliStructuredError {\n return errorRuntime(`Ref \"${name}\" does not exist`, {\n why: `No ref named \"${name}\" found in refs.json`,\n fix: `Run \\`prisma-next migration ref list\\` to see available refs, or \\`prisma-next migration ref set ${name} <hash>\\` to create it`,\n });\n}\n\nasync function executeRefSetCommand(\n name: string,\n hash: string,\n options: { config?: string },\n): Promise<Result<RefSetResult, CliStructuredError>> {\n if (!validateRefName(name)) {\n return notOk(cliErrorInvalidRefName(name));\n }\n if (!validateRefValue(hash)) {\n return notOk(cliErrorInvalidRefValue(hash));\n }\n\n try {\n const config = await loadConfig(options.config);\n const refsPath = resolveRefsPath(options.config, config);\n const refs = await readRefs(refsPath);\n const updated = { ...refs, [name]: hash };\n await writeRefs(refsPath, updated);\n return ok({ ok: true as const, ref: name, hash });\n } catch (error) {\n if (error instanceof CliStructuredError) return notOk(error);\n return notOk(mapError(error));\n }\n}\n\nasync function executeRefGetCommand(\n name: string,\n options: { config?: string },\n): Promise<Result<RefGetResult, CliStructuredError>> {\n try {\n const config = await loadConfig(options.config);\n const refsPath = resolveRefsPath(options.config, config);\n const refs = await readRefs(refsPath);\n const hash = resolveRef(refs, name);\n return ok({ ok: true as const, ref: name, hash });\n } catch (error) {\n if (error instanceof CliStructuredError) return notOk(error);\n return notOk(mapError(error));\n }\n}\n\nasync function executeRefDeleteCommand(\n name: string,\n options: { config?: string },\n): Promise<Result<RefDeleteResult, CliStructuredError>> {\n try {\n const config = await loadConfig(options.config);\n const refsPath = resolveRefsPath(options.config, config);\n const refs = await readRefs(refsPath);\n if (!Object.hasOwn(refs, name)) {\n return notOk(errorRefNotFound(name));\n }\n const { [name]: _, ...remaining } = refs;\n await writeRefs(refsPath, remaining);\n return ok({ ok: true as const, ref: name, deleted: true as const });\n } catch (error) {\n if (error instanceof CliStructuredError) return notOk(error);\n return notOk(mapError(error));\n }\n}\n\nasync function executeRefListCommand(options: {\n config?: string;\n}): Promise<Result<RefListResult, CliStructuredError>> {\n try {\n const config = await loadConfig(options.config);\n const refsPath = resolveRefsPath(options.config, config);\n const refs = await readRefs(refsPath);\n return ok({ ok: true as const, refs });\n } catch (error) {\n if (error instanceof CliStructuredError) return notOk(error);\n return notOk(mapError(error));\n }\n}\n\nfunction createRefSetCommand(): Command {\n const command = new Command('set');\n setCommandDescriptions(\n command,\n 'Set a ref to a contract hash',\n 'Sets a named ref to point to a contract hash in migrations/refs.json.',\n );\n addGlobalOptions(command)\n .argument('<name>', 'Ref name (e.g., staging, production)')\n .argument('<hash>', 'Contract hash to point to')\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .action(\n async (\n name: string,\n hash: string,\n options: { config?: string; json?: string | boolean; quiet?: boolean },\n ) => {\n const flags = parseGlobalFlags(options);\n const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });\n const result = await executeRefSetCommand(name, hash, options);\n const exitCode = handleResult(result, flags, ui, (value) => {\n if (flags.json) {\n ui.output(JSON.stringify(value));\n } else if (!flags.quiet) {\n ui.output(`Set ref \"${value.ref}\" → ${value.hash}`);\n }\n });\n process.exit(exitCode);\n },\n );\n return command;\n}\n\nfunction createRefGetCommand(): Command {\n const command = new Command('get');\n setCommandDescriptions(\n command,\n 'Get the hash for a ref',\n 'Reads a named ref from migrations/refs.json and prints its contract hash.',\n );\n addGlobalOptions(command)\n .argument('<name>', 'Ref name to look up')\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .action(\n async (\n name: string,\n options: { config?: string; json?: string | boolean; quiet?: boolean },\n ) => {\n const flags = parseGlobalFlags(options);\n const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });\n const result = await executeRefGetCommand(name, options);\n const exitCode = handleResult(result, flags, ui, (value) => {\n if (flags.json) {\n ui.output(JSON.stringify(value));\n } else {\n ui.output(value.hash);\n }\n });\n process.exit(exitCode);\n },\n );\n return command;\n}\n\nfunction createRefDeleteCommand(): Command {\n const command = new Command('delete');\n setCommandDescriptions(command, 'Delete a ref', 'Removes a named ref from migrations/refs.json.');\n addGlobalOptions(command)\n .argument('<name>', 'Ref name to delete')\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .action(\n async (\n name: string,\n options: { config?: string; json?: string | boolean; quiet?: boolean },\n ) => {\n const flags = parseGlobalFlags(options);\n const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });\n const result = await executeRefDeleteCommand(name, options);\n const exitCode = handleResult(result, flags, ui, (value) => {\n if (flags.json) {\n ui.output(JSON.stringify(value));\n } else if (!flags.quiet) {\n ui.output(`Deleted ref \"${value.ref}\"`);\n }\n });\n process.exit(exitCode);\n },\n );\n return command;\n}\n\nfunction createRefListCommand(): Command {\n const command = new Command('list');\n setCommandDescriptions(\n command,\n 'List all refs',\n 'Lists all named refs from migrations/refs.json.',\n );\n addGlobalOptions(command)\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .action(async (options: { config?: string; json?: string | boolean; quiet?: boolean }) => {\n const flags = parseGlobalFlags(options);\n const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });\n const result = await executeRefListCommand(options);\n const exitCode = handleResult(result, flags, ui, (value) => {\n if (flags.json) {\n ui.output(JSON.stringify(value));\n } else if (!flags.quiet) {\n const entries = Object.entries(value.refs);\n if (entries.length === 0) {\n ui.output('No refs defined');\n } else {\n for (const [refName, hash] of entries) {\n ui.output(`${refName} → ${hash}`);\n }\n }\n }\n });\n process.exit(exitCode);\n });\n return command;\n}\n\nexport {\n executeRefSetCommand,\n executeRefGetCommand,\n executeRefDeleteCommand,\n executeRefListCommand,\n cliErrorInvalidRefName,\n cliErrorInvalidRefValue,\n errorRefNotFound,\n};\n\nexport function createMigrationRefCommand(): Command {\n const command = new Command('ref');\n setCommandDescriptions(\n command,\n 'Manage migration refs',\n 'Manage named refs in migrations/refs.json. Refs map logical environment\\n' +\n 'names (e.g., staging, production) to contract hashes.',\n );\n addGlobalOptions(command).configureHelp({\n formatHelp: (cmd) => formatCommandHelp({ command: cmd, flags: parseGlobalFlags({}) }),\n subcommandDescription: () => '',\n });\n command.addCommand(createRefSetCommand());\n command.addCommand(createRefGetCommand());\n command.addCommand(createRefDeleteCommand());\n command.addCommand(createRefListCommand());\n return command;\n}\n"],"mappings":";;;;;;;;;;;AA0CA,SAAS,gBAAgB,YAAqB,QAAoD;AAEhG,QAAO,QADM,aAAa,QAAQ,YAAY,KAAK,GAAG,QAAQ,KAAK,EAC9C,QAAQ,YAAY,OAAO,cAAc,YAAY;;AAG5E,SAAS,SAAS,OAAoC;AACpD,KAAI,oBAAoB,GAAG,MAAM,CAC/B,QAAO,aAAa,MAAM,SAAS;EACjC,KAAK,MAAM;EACX,KAAK,MAAM;EACX,MAAM,EAAE,MAAM,MAAM,MAAM;EAC3B,CAAC;AAEJ,QAAO,gBAAgB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CAAC;;AAGhF,SAAS,uBAAuB,MAAkC;AAChE,QAAO,aAAa,qBAAqB,KAAK,IAAI;EAChD,KAAK,aAAa,KAAK;EACvB,KAAK;EACN,CAAC;;AAGJ,SAAS,wBAAwB,MAAkC;AACjE,QAAO,aAAa,0BAA0B,KAAK,IAAI;EACrD,KAAK,IAAI,KAAK;EACd,KAAK;EACN,CAAC;;AAGJ,SAAS,iBAAiB,MAAkC;AAC1D,QAAO,aAAa,QAAQ,KAAK,mBAAmB;EAClD,KAAK,iBAAiB,KAAK;EAC3B,KAAK,oGAAoG,KAAK;EAC/G,CAAC;;AAGJ,eAAe,qBACb,MACA,MACA,SACmD;AACnD,KAAI,CAAC,gBAAgB,KAAK,CACxB,QAAO,MAAM,uBAAuB,KAAK,CAAC;AAE5C,KAAI,CAAC,iBAAiB,KAAK,CACzB,QAAO,MAAM,wBAAwB,KAAK,CAAC;AAG7C,KAAI;EACF,MAAM,SAAS,MAAM,WAAW,QAAQ,OAAO;EAC/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