prisma-next 0.11.0-dev.5 → 0.11.0-dev.50
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/dist/cli-errors-DFF1LlfU.mjs +215 -0
- package/dist/cli-errors-DFF1LlfU.mjs.map +1 -0
- package/dist/cli.mjs +9 -10
- package/dist/cli.mjs.map +1 -1
- package/dist/{client-oXO2WCPD.mjs → client-5uvDppD8.mjs} +23 -21
- package/dist/client-5uvDppD8.mjs.map +1 -0
- package/dist/{command-helpers-DtavI0wJ.mjs → command-helpers-4UNsRRc4.mjs} +427 -9
- package/dist/command-helpers-4UNsRRc4.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts.map +1 -1
- package/dist/commands/contract-emit.mjs +1 -1
- package/dist/commands/contract-infer.d.mts.map +1 -1
- package/dist/commands/contract-infer.mjs +1 -1
- package/dist/commands/db-init.d.mts.map +1 -1
- package/dist/commands/db-init.mjs +33 -7
- package/dist/commands/db-init.mjs.map +1 -1
- package/dist/commands/db-schema.d.mts.map +1 -1
- package/dist/commands/db-schema.mjs +3 -4
- package/dist/commands/db-schema.mjs.map +1 -1
- package/dist/commands/db-sign.d.mts.map +1 -1
- package/dist/commands/db-sign.mjs +6 -7
- package/dist/commands/db-sign.mjs.map +1 -1
- package/dist/commands/db-update.d.mts.map +1 -1
- package/dist/commands/db-update.mjs +36 -8
- package/dist/commands/db-update.mjs.map +1 -1
- package/dist/commands/db-verify.d.mts.map +1 -1
- package/dist/commands/db-verify.mjs +1 -1
- package/dist/commands/migrate.d.mts +5 -1
- package/dist/commands/migrate.d.mts.map +1 -1
- package/dist/commands/migrate.mjs +79 -39
- package/dist/commands/migrate.mjs.map +1 -1
- package/dist/commands/migration-check.d.mts +4 -3
- package/dist/commands/migration-check.d.mts.map +1 -1
- package/dist/commands/migration-check.mjs +1 -280
- package/dist/commands/migration-graph.d.mts +1 -1
- package/dist/commands/migration-graph.d.mts.map +1 -1
- package/dist/commands/migration-graph.mjs +3 -4
- package/dist/commands/migration-graph.mjs.map +1 -1
- package/dist/commands/migration-list.d.mts +63 -12
- package/dist/commands/migration-list.d.mts.map +1 -1
- package/dist/commands/migration-list.mjs +2 -103
- package/dist/commands/migration-log.d.mts.map +1 -1
- package/dist/commands/migration-log.mjs +3 -4
- package/dist/commands/migration-log.mjs.map +1 -1
- package/dist/commands/migration-new.d.mts.map +1 -1
- package/dist/commands/migration-new.mjs +33 -38
- package/dist/commands/migration-new.mjs.map +1 -1
- package/dist/commands/migration-plan.d.mts +2 -1
- package/dist/commands/migration-plan.d.mts.map +1 -1
- package/dist/commands/migration-plan.mjs +1 -1
- package/dist/commands/migration-show.d.mts +4 -55
- package/dist/commands/migration-show.d.mts.map +1 -1
- package/dist/commands/migration-show.mjs +62 -153
- package/dist/commands/migration-show.mjs.map +1 -1
- package/dist/commands/migration-status.d.mts +5 -40
- package/dist/commands/migration-status.d.mts.map +1 -1
- package/dist/commands/migration-status.mjs +93 -67
- package/dist/commands/migration-status.mjs.map +1 -1
- package/dist/commands/ref.d.mts +1 -1
- package/dist/commands/ref.d.mts.map +1 -1
- package/dist/commands/ref.mjs +34 -9
- package/dist/commands/ref.mjs.map +1 -1
- package/dist/config-loader-B6sJjXTv.mjs.map +1 -1
- package/dist/config-loader.d.mts.map +1 -1
- package/dist/{contract-emit-o-8VmdQX.mjs → contract-emit-C-CFGZsI.mjs} +9 -6
- package/dist/{contract-emit-o-8VmdQX.mjs.map → contract-emit-C-CFGZsI.mjs.map} +1 -1
- package/dist/{contract-emit-CmsklifJ.mjs → contract-emit-CuUzzM46.mjs} +5 -6
- package/dist/{contract-emit-CmsklifJ.mjs.map → contract-emit-CuUzzM46.mjs.map} +1 -1
- package/dist/{contract-enrichment-Dani0mMW.mjs → contract-enrichment-XmUPhmsS.mjs} +4 -25
- package/dist/contract-enrichment-XmUPhmsS.mjs.map +1 -0
- package/dist/{contract-infer-pKkiCt7C.mjs → contract-infer-C98ZaRhp.mjs} +3 -4
- package/dist/{contract-infer-pKkiCt7C.mjs.map → contract-infer-C98ZaRhp.mjs.map} +1 -1
- package/dist/contract-space-aggregate-loader-CVHGuA35.mjs +170 -0
- package/dist/contract-space-aggregate-loader-CVHGuA35.mjs.map +1 -0
- package/dist/{db-verify-AoIUriL4.mjs → db-verify-BWl1Yxi-.mjs} +6 -7
- package/dist/{db-verify-AoIUriL4.mjs.map → db-verify-BWl1Yxi-.mjs.map} +1 -1
- package/dist/exports/control-api.d.mts +1 -1
- package/dist/exports/control-api.d.mts.map +1 -1
- package/dist/exports/control-api.mjs +3 -3
- package/dist/exports/index.d.mts.map +1 -1
- package/dist/exports/index.mjs +1 -1
- package/dist/exports/index.mjs.map +1 -1
- package/dist/exports/init-output.d.mts.map +1 -1
- package/dist/exports/init-output.mjs +1 -1
- package/dist/extension-pack-inputs-BiY86HbQ.mjs +62 -0
- package/dist/extension-pack-inputs-BiY86HbQ.mjs.map +1 -0
- package/dist/{framework-components-65gOHkHB.mjs → framework-components-DTcjouhS.mjs} +2 -2
- package/dist/{framework-components-65gOHkHB.mjs.map → framework-components-DTcjouhS.mjs.map} +1 -1
- package/dist/{global-flags-CdE7M0d9.d.mts → global-flags-DWsQ6SSI.d.mts} +1 -1
- package/dist/global-flags-DWsQ6SSI.d.mts.map +1 -0
- package/dist/glyph-mode-CBB4emzO.d.mts +5 -0
- package/dist/glyph-mode-CBB4emzO.d.mts.map +1 -0
- package/dist/{graph-render-DJVv0_uf.mjs → graph-render-D2FnLpuK.mjs} +1 -1
- package/dist/{graph-render-DJVv0_uf.mjs.map → graph-render-D2FnLpuK.mjs.map} +1 -1
- package/dist/{init-Db5Itt5r.mjs → init-C7PvN163.mjs} +5 -5
- package/dist/{init-Db5Itt5r.mjs.map → init-C7PvN163.mjs.map} +1 -1
- package/dist/{inspect-live-schema-LeWvkZVz.mjs → inspect-live-schema-BRCWQ-Sr.mjs} +5 -5
- package/dist/{inspect-live-schema-LeWvkZVz.mjs.map → inspect-live-schema-BRCWQ-Sr.mjs.map} +1 -1
- package/dist/migration-check-DoskM1nB.mjs +341 -0
- package/dist/migration-check-DoskM1nB.mjs.map +1 -0
- package/dist/migration-cli.d.mts.map +1 -1
- package/dist/migration-cli.mjs +4 -4
- package/dist/migration-cli.mjs.map +1 -1
- package/dist/{migration-command-scaffold-BtkunvFQ.mjs → migration-command-scaffold-CXLkoIJx.mjs} +5 -5
- package/dist/{migration-command-scaffold-BtkunvFQ.mjs.map → migration-command-scaffold-CXLkoIJx.mjs.map} +1 -1
- package/dist/migration-list-B2-iQ5Jd.mjs +646 -0
- package/dist/migration-list-B2-iQ5Jd.mjs.map +1 -0
- package/dist/{migration-plan-C2jeH1J5.mjs → migration-plan-BqmIKQpZ.mjs} +341 -88
- package/dist/migration-plan-BqmIKQpZ.mjs.map +1 -0
- package/dist/{migration-types-BXWvz12q.d.mts → migration-types-q64xAI_J.d.mts} +1 -1
- package/dist/{migration-types-BXWvz12q.d.mts.map → migration-types-q64xAI_J.d.mts.map} +1 -1
- package/dist/{migrations-CwZMa1Ck.mjs → migrations-BcVTutso.mjs} +12 -13
- package/dist/migrations-BcVTutso.mjs.map +1 -0
- package/dist/{output-BlsrGMEF.mjs → output-B60Gw5fu.mjs} +1 -1
- package/dist/{output-BlsrGMEF.mjs.map → output-B60Gw5fu.mjs.map} +1 -1
- package/dist/{progress-adapter-DFfvZcYL.mjs → progress-adapter-xASh41wr.mjs} +1 -1
- package/dist/{progress-adapter-DFfvZcYL.mjs.map → progress-adapter-xASh41wr.mjs.map} +1 -1
- package/dist/ref-advancement-DRh5Nquq.mjs +50 -0
- package/dist/ref-advancement-DRh5Nquq.mjs.map +1 -0
- package/dist/{types-C9FfXb1l.d.mts → types-CEtm6v6a.d.mts} +5 -11
- package/dist/types-CEtm6v6a.d.mts.map +1 -0
- package/dist/{verify-Bom75OYI.mjs → verify-DOHbbrub.mjs} +2 -2
- package/dist/{verify-Bom75OYI.mjs.map → verify-DOHbbrub.mjs.map} +1 -1
- package/package.json +12 -12
- package/dist/cli-errors-Czmx92Zy.d.mts +0 -3
- package/dist/cli-errors-Djtz98Vm.mjs +0 -71
- package/dist/cli-errors-Djtz98Vm.mjs.map +0 -1
- package/dist/client-oXO2WCPD.mjs.map +0 -1
- package/dist/command-helpers-DtavI0wJ.mjs.map +0 -1
- package/dist/commands/migration-check.mjs.map +0 -1
- package/dist/commands/migration-list.mjs.map +0 -1
- package/dist/contract-enrichment-Dani0mMW.mjs.map +0 -1
- package/dist/contract-space-aggregate-loader-BmNQwlws.mjs +0 -160
- package/dist/contract-space-aggregate-loader-BmNQwlws.mjs.map +0 -1
- package/dist/global-flags-CdE7M0d9.d.mts.map +0 -1
- package/dist/migration-plan-C2jeH1J5.mjs.map +0 -1
- package/dist/migrations-CwZMa1Ck.mjs.map +0 -1
- package/dist/terminal-ui-BiB_8KNo.mjs +0 -379
- package/dist/terminal-ui-BiB_8KNo.mjs.map +0 -1
- package/dist/types-C9FfXb1l.d.mts.map +0 -1
|
@@ -1,281 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { t as createTerminalUI } from "../terminal-ui-BiB_8KNo.mjs";
|
|
3
|
-
import { S as formatStyledHeader, a as loadMigrationPackages, d as setCommandDescriptions, f as setCommandExamples, l as resolveMigrationPaths, p as setCommandSeeAlso, t as addGlobalOptions, v as parseGlobalFlagsOrExit } from "../command-helpers-DtavI0wJ.mjs";
|
|
4
|
-
import { Command } from "commander";
|
|
5
|
-
import { join, relative } from "pathe";
|
|
6
|
-
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
7
|
-
import { MigrationToolsError } from "@prisma-next/migration-tools/errors";
|
|
8
|
-
import { parseMigrationRef } from "@prisma-next/migration-tools/ref-resolution";
|
|
9
|
-
import { readRefs } from "@prisma-next/migration-tools/refs";
|
|
10
|
-
import { verifyMigrationHash } from "@prisma-next/migration-tools/hash";
|
|
11
|
-
//#region src/commands/migration-check.ts
|
|
12
|
-
/**
|
|
13
|
-
* Canonical user-facing locator for a check failure: the cwd-relative path
|
|
14
|
-
* to the migration package directory. Surfacing the same shape across every
|
|
15
|
-
* PN code means `--json` consumers can branch uniformly on `where`.
|
|
16
|
-
*/
|
|
17
|
-
function migrationPathRelative(dirPath) {
|
|
18
|
-
return relative(process.cwd(), dirPath);
|
|
19
|
-
}
|
|
20
|
-
function migrationFileRelative(dirPath, fileName) {
|
|
21
|
-
return join(migrationPathRelative(dirPath), fileName);
|
|
22
|
-
}
|
|
23
|
-
function checkFileExists(dirPath, dirName, fileName) {
|
|
24
|
-
if (!existsSync(join(dirPath, fileName))) return {
|
|
25
|
-
pnCode: "PN-MIG-CHECK-002",
|
|
26
|
-
where: migrationFileRelative(dirPath, fileName),
|
|
27
|
-
why: `${fileName} is missing from ${dirName}`,
|
|
28
|
-
fix: "Re-emit the migration package or restore from version control."
|
|
29
|
-
};
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Within-migration snapshot-consistency check (PN-MIG-CHECK-005).
|
|
34
|
-
*
|
|
35
|
-
* Compares the migration's stored `metadata.to` against the `storageHash`
|
|
36
|
-
* recorded in its on-disk `end-contract.json` snapshot. The two values are
|
|
37
|
-
* independent on-disk records of the same fact (the migration's destination
|
|
38
|
-
* contract); drift between them indicates the package is internally
|
|
39
|
-
* corrupt. Cross-migration consistency (one migration's end-contract.json
|
|
40
|
-
* agreeing with the next migration's start-contract.json) is a separate
|
|
41
|
-
* check that requires shadow execution and is deferred to
|
|
42
|
-
* `migration preflight`.
|
|
43
|
-
*
|
|
44
|
-
* Shared between the graph-wide and per-migration code paths so both report
|
|
45
|
-
* the same failure for the same on-disk state.
|
|
46
|
-
*/
|
|
47
|
-
function checkSnapshotConsistency(pkg) {
|
|
48
|
-
const endContractPath = join(pkg.dirPath, "end-contract.json");
|
|
49
|
-
if (!existsSync(endContractPath)) return null;
|
|
50
|
-
try {
|
|
51
|
-
const snapshotHash = JSON.parse(readFileSync(endContractPath, "utf-8"))["storage"]?.["storageHash"];
|
|
52
|
-
if (typeof snapshotHash === "string" && snapshotHash !== pkg.metadata.to) return {
|
|
53
|
-
pnCode: "PN-MIG-CHECK-005",
|
|
54
|
-
where: migrationPathRelative(pkg.dirPath),
|
|
55
|
-
why: `Migration "${pkg.dirName}" declares to=${pkg.metadata.to} but end-contract.json has storageHash=${snapshotHash}`,
|
|
56
|
-
fix: "Re-emit the migration package so migration.json and end-contract.json agree."
|
|
57
|
-
};
|
|
58
|
-
} catch {
|
|
59
|
-
return {
|
|
60
|
-
pnCode: "PN-MIG-CHECK-006",
|
|
61
|
-
where: migrationPathRelative(pkg.dirPath),
|
|
62
|
-
why: `Migration "${pkg.dirName}" has an unparseable end-contract.json.`,
|
|
63
|
-
fix: "Re-emit the migration package to repair the snapshot file."
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
async function executeMigrationCheckCommand(target, options, flags, ui) {
|
|
69
|
-
const config = await loadConfig(options.config);
|
|
70
|
-
const { configPath, appMigrationsDir, appMigrationsRelative, refsDir } = resolveMigrationPaths(options.config, config);
|
|
71
|
-
if (!flags.json && !flags.quiet) {
|
|
72
|
-
const details = [{
|
|
73
|
-
label: "config",
|
|
74
|
-
value: configPath
|
|
75
|
-
}, {
|
|
76
|
-
label: "migrations",
|
|
77
|
-
value: appMigrationsRelative
|
|
78
|
-
}];
|
|
79
|
-
if (target) details.push({
|
|
80
|
-
label: "target",
|
|
81
|
-
value: target
|
|
82
|
-
});
|
|
83
|
-
const header = formatStyledHeader({
|
|
84
|
-
command: "migration check",
|
|
85
|
-
description: "Verify artifact and graph integrity",
|
|
86
|
-
details,
|
|
87
|
-
flags
|
|
88
|
-
});
|
|
89
|
-
ui.stderr(header);
|
|
90
|
-
}
|
|
91
|
-
const failures = [];
|
|
92
|
-
let bundles;
|
|
93
|
-
let graph;
|
|
94
|
-
try {
|
|
95
|
-
const loaded = await loadMigrationPackages(appMigrationsDir);
|
|
96
|
-
bundles = loaded.bundles;
|
|
97
|
-
graph = loaded.graph;
|
|
98
|
-
} catch (error) {
|
|
99
|
-
if (MigrationToolsError.is(error)) {
|
|
100
|
-
const pnCode = error.code === "MIGRATION.HASH_MISMATCH" ? "PN-MIG-CHECK-001" : "PN-MIG-CHECK-002";
|
|
101
|
-
const rawWhere = error.details?.["dir"] ?? error.details?.["filePath"] ?? null;
|
|
102
|
-
const where = rawWhere ? relative(process.cwd(), rawWhere) : "unknown";
|
|
103
|
-
failures.push({
|
|
104
|
-
pnCode,
|
|
105
|
-
where,
|
|
106
|
-
why: error.why,
|
|
107
|
-
fix: error.fix
|
|
108
|
-
});
|
|
109
|
-
return {
|
|
110
|
-
result: {
|
|
111
|
-
ok: false,
|
|
112
|
-
failures,
|
|
113
|
-
summary: `${failures.length} integrity failure(s)`
|
|
114
|
-
},
|
|
115
|
-
exitCode: 4
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
120
|
-
if (existsSync(appMigrationsDir)) {
|
|
121
|
-
const loadedDirNames = new Set(bundles.map((p) => p.dirName));
|
|
122
|
-
try {
|
|
123
|
-
const entries = readdirSync(appMigrationsDir);
|
|
124
|
-
for (const entry of entries) {
|
|
125
|
-
if (entry.startsWith(".") || entry.startsWith("_") || entry === "refs") continue;
|
|
126
|
-
const entryPath = join(appMigrationsDir, entry);
|
|
127
|
-
try {
|
|
128
|
-
if (!statSync(entryPath).isDirectory()) continue;
|
|
129
|
-
} catch {
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
if (!loadedDirNames.has(entry)) for (const f of ["migration.json", "ops.json"]) {
|
|
133
|
-
const fail = checkFileExists(entryPath, entry, f);
|
|
134
|
-
if (fail) failures.push(fail);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
} catch {}
|
|
138
|
-
}
|
|
139
|
-
if (target) {
|
|
140
|
-
const refs = await readRefs(refsDir);
|
|
141
|
-
const migResult = parseMigrationRef(target, {
|
|
142
|
-
graph,
|
|
143
|
-
refs
|
|
144
|
-
});
|
|
145
|
-
if (!migResult.ok) return {
|
|
146
|
-
result: {
|
|
147
|
-
ok: false,
|
|
148
|
-
failures: [],
|
|
149
|
-
summary: migResult.failure.kind === "not-found" ? `Migration "${target}" does not exist` : migResult.failure.kind === "wrong-grammar" ? migResult.failure.message : `Invalid migration reference: "${target}"`
|
|
150
|
-
},
|
|
151
|
-
exitCode: 2
|
|
152
|
-
};
|
|
153
|
-
const matchedPkg = bundles.find((p) => p.metadata.migrationHash === migResult.value.migrationHash);
|
|
154
|
-
if (!matchedPkg) return {
|
|
155
|
-
result: {
|
|
156
|
-
ok: false,
|
|
157
|
-
failures: [],
|
|
158
|
-
summary: `Migration package for "${target}" not found on disk`
|
|
159
|
-
},
|
|
160
|
-
exitCode: 2
|
|
161
|
-
};
|
|
162
|
-
for (const f of ["migration.json", "ops.json"]) {
|
|
163
|
-
const fail = checkFileExists(matchedPkg.dirPath, matchedPkg.dirName, f);
|
|
164
|
-
if (fail) failures.push(fail);
|
|
165
|
-
}
|
|
166
|
-
const verification = verifyMigrationHash(matchedPkg);
|
|
167
|
-
if (!verification.ok) failures.push({
|
|
168
|
-
pnCode: "PN-MIG-CHECK-001",
|
|
169
|
-
where: migrationFileRelative(matchedPkg.dirPath, "migration.json"),
|
|
170
|
-
why: `Stored hash ${verification.storedHash} does not match recomputed hash ${verification.computedHash}`,
|
|
171
|
-
fix: "Re-emit the migration package or restore from version control."
|
|
172
|
-
});
|
|
173
|
-
const snapshotFailure = checkSnapshotConsistency(matchedPkg);
|
|
174
|
-
if (snapshotFailure) failures.push(snapshotFailure);
|
|
175
|
-
} else {
|
|
176
|
-
for (const pkg of bundles) {
|
|
177
|
-
for (const f of ["migration.json", "ops.json"]) {
|
|
178
|
-
const fail = checkFileExists(pkg.dirPath, pkg.dirName, f);
|
|
179
|
-
if (fail) failures.push(fail);
|
|
180
|
-
}
|
|
181
|
-
const verification = verifyMigrationHash(pkg);
|
|
182
|
-
if (!verification.ok) failures.push({
|
|
183
|
-
pnCode: "PN-MIG-CHECK-001",
|
|
184
|
-
where: migrationFileRelative(pkg.dirPath, "migration.json"),
|
|
185
|
-
why: `Stored hash ${verification.storedHash} does not match recomputed hash ${verification.computedHash}`,
|
|
186
|
-
fix: "Re-emit the migration package or restore from version control."
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
for (const pkg of bundles) {
|
|
190
|
-
const snapshotFailure = checkSnapshotConsistency(pkg);
|
|
191
|
-
if (snapshotFailure) failures.push(snapshotFailure);
|
|
192
|
-
}
|
|
193
|
-
const allToHashes = new Set(bundles.map((p) => p.metadata.to));
|
|
194
|
-
for (const pkg of bundles) if (!(pkg.metadata.from === null || allToHashes.has(pkg.metadata.from) || pkg.metadata.from === "sha256:empty")) failures.push({
|
|
195
|
-
pnCode: "PN-MIG-CHECK-003",
|
|
196
|
-
where: migrationPathRelative(pkg.dirPath),
|
|
197
|
-
why: `Migration "${pkg.dirName}" starts from ${pkg.metadata.from} which no other migration produces`,
|
|
198
|
-
fix: "This migration is unreachable in the graph. Delete it or re-emit a connecting migration."
|
|
199
|
-
});
|
|
200
|
-
try {
|
|
201
|
-
const refs = await readRefs(refsDir);
|
|
202
|
-
for (const [name, entry] of Object.entries(refs)) if (!graph.nodes.has(entry.hash)) failures.push({
|
|
203
|
-
pnCode: "PN-MIG-CHECK-004",
|
|
204
|
-
where: relative(process.cwd(), join(refsDir, `${name}.json`)),
|
|
205
|
-
why: `Ref "${name}" points at ${entry.hash} which does not exist in the migration graph`,
|
|
206
|
-
fix: `Update the ref with \`prisma-next ref set ${name} <valid-hash>\` or delete it.`
|
|
207
|
-
});
|
|
208
|
-
} catch {}
|
|
209
|
-
}
|
|
210
|
-
if (failures.length === 0) return {
|
|
211
|
-
result: {
|
|
212
|
-
ok: true,
|
|
213
|
-
failures: [],
|
|
214
|
-
summary: "All checks passed"
|
|
215
|
-
},
|
|
216
|
-
exitCode: 0
|
|
217
|
-
};
|
|
218
|
-
return {
|
|
219
|
-
result: {
|
|
220
|
-
ok: false,
|
|
221
|
-
failures,
|
|
222
|
-
summary: `${failures.length} integrity failure(s)`
|
|
223
|
-
},
|
|
224
|
-
exitCode: 4
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
function createMigrationCheckCommand() {
|
|
228
|
-
const command = new Command("check");
|
|
229
|
-
setCommandDescriptions(command, "Verify artifact and graph integrity", "Validates that on-disk migration packages are internally consistent\n(hashes match, manifests are complete) and that the graph is well-formed\n(edges connect, refs point at valid nodes). Offline — does not consult\nthe database.");
|
|
230
|
-
setCommandExamples(command, [
|
|
231
|
-
"prisma-next migration check",
|
|
232
|
-
"prisma-next migration check 20260101-add-users",
|
|
233
|
-
"prisma-next migration check --json"
|
|
234
|
-
]);
|
|
235
|
-
setCommandSeeAlso(command, [
|
|
236
|
-
{
|
|
237
|
-
verb: "migration status",
|
|
238
|
-
oneLiner: "Show migration path and pending status"
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
verb: "migration list",
|
|
242
|
-
oneLiner: "List on-disk migrations"
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
verb: "migration graph",
|
|
246
|
-
oneLiner: "Show the migration graph topology"
|
|
247
|
-
}
|
|
248
|
-
]);
|
|
249
|
-
command.exitOverride();
|
|
250
|
-
addGlobalOptions(command).argument("[migration]", "Migration reference (directory name or hash) to check").option("--config <path>", "Path to prisma-next.config.ts").action(async (target, options) => {
|
|
251
|
-
const flags = parseGlobalFlagsOrExit(options);
|
|
252
|
-
const ui = createTerminalUI(flags);
|
|
253
|
-
let result;
|
|
254
|
-
let exitCode;
|
|
255
|
-
try {
|
|
256
|
-
({result, exitCode} = await executeMigrationCheckCommand(target, options, flags, ui));
|
|
257
|
-
} catch (error) {
|
|
258
|
-
result = {
|
|
259
|
-
ok: false,
|
|
260
|
-
failures: [],
|
|
261
|
-
summary: error instanceof Error ? error.message : String(error)
|
|
262
|
-
};
|
|
263
|
-
exitCode = 2;
|
|
264
|
-
}
|
|
265
|
-
if (flags.json) ui.output(JSON.stringify(result, null, 2));
|
|
266
|
-
else if (!flags.quiet) if (result.ok) ui.log(`✔ ${result.summary}`);
|
|
267
|
-
else {
|
|
268
|
-
for (const f of result.failures) {
|
|
269
|
-
ui.log(`✗ [${f.pnCode}] ${f.where}: ${f.why}`);
|
|
270
|
-
ui.log(` fix: ${f.fix}`);
|
|
271
|
-
}
|
|
272
|
-
ui.log(`\n${result.summary}`);
|
|
273
|
-
}
|
|
274
|
-
process.exit(exitCode);
|
|
275
|
-
});
|
|
276
|
-
return command;
|
|
277
|
-
}
|
|
278
|
-
//#endregion
|
|
1
|
+
import { t as createMigrationCheckCommand } from "../migration-check-DoskM1nB.mjs";
|
|
279
2
|
export { createMigrationCheckCommand };
|
|
280
|
-
|
|
281
|
-
//# sourceMappingURL=migration-check.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-graph.d.mts","names":[],"sources":["../../src/commands/migration-graph.ts"],"mappings":";;;;;UAmCiB,oBAAA;EAAA,SACN,EAAA;EAAA,SACA,KAAA,EAAO,cAAA;EAAA,SACP,YAAA;EAAA,SACA,IAAA,WAAe,
|
|
1
|
+
{"version":3,"file":"migration-graph.d.mts","names":[],"sources":["../../src/commands/migration-graph.ts"],"mappings":";;;;;UAmCiB,oBAAA;EAAA,SACN,EAAA;EAAA,SACA,KAAA,EAAO,cAAA;EAAA,SACP,YAAA;EAAA,SACA,IAAA,WAAe,SAAS;EAAA,SACxB,OAAA;AAAA;AAAA,iBAoEK,2BAAA,CAAA,GAA+B,OAAO"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { t as loadConfig } from "../config-loader-B6sJjXTv.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { t as createTerminalUI } from "../
|
|
4
|
-
import {
|
|
5
|
-
import { i as migrationGraphToRenderInput, n as graphRenderer } from "../graph-render-DJVv0_uf.mjs";
|
|
2
|
+
import { O as errorUnexpected, k as mapMigrationToolsError } from "../cli-errors-DFF1LlfU.mjs";
|
|
3
|
+
import { D as formatStyledHeader, a as loadMigrationPackages, d as setCommandDescriptions, f as setCommandExamples, l as resolveMigrationPaths, p as setCommandSeeAlso, s as readContractEnvelope, t as addGlobalOptions, v as parseGlobalFlagsOrExit, x as handleResult, y as createTerminalUI } from "../command-helpers-4UNsRRc4.mjs";
|
|
4
|
+
import { i as migrationGraphToRenderInput, n as graphRenderer } from "../graph-render-D2FnLpuK.mjs";
|
|
6
5
|
import { Command } from "commander";
|
|
7
6
|
import { notOk, ok } from "@prisma-next/utils/result";
|
|
8
7
|
import { EMPTY_CONTRACT_HASH } from "@prisma-next/migration-tools/constants";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-graph.mjs","names":[],"sources":["../../src/commands/migration-graph.ts"],"sourcesContent":["import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport { MigrationToolsError } from '@prisma-next/migration-tools/errors';\nimport type { MigrationGraph } from '@prisma-next/migration-tools/graph';\nimport { readRefs } from '@prisma-next/migration-tools/refs';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport {\n type CliStructuredError,\n errorUnexpected,\n mapMigrationToolsError,\n} from '../utils/cli-errors';\nimport {\n addGlobalOptions,\n loadMigrationPackages,\n readContractEnvelope,\n resolveMigrationPaths,\n setCommandDescriptions,\n setCommandExamples,\n setCommandSeeAlso,\n} from '../utils/command-helpers';\nimport { migrationGraphToRenderInput } from '../utils/formatters/graph-migration-mapper';\nimport { graphRenderer } from '../utils/formatters/graph-render';\nimport { formatStyledHeader } from '../utils/formatters/styled';\nimport type { CommonCommandOptions } from '../utils/global-flags';\nimport { type GlobalFlags, parseGlobalFlagsOrExit } from '../utils/global-flags';\nimport type { StatusRef } from '../utils/migration-types';\nimport { handleResult } from '../utils/result-handler';\nimport { createTerminalUI, type TerminalUI } from '../utils/terminal-ui';\n\ninterface MigrationGraphOptions extends CommonCommandOptions {\n readonly config?: string;\n readonly dot?: boolean;\n}\n\nexport interface MigrationGraphResult {\n readonly ok: true;\n readonly graph: MigrationGraph;\n readonly contractHash: string | null;\n readonly refs: readonly StatusRef[];\n readonly summary: string;\n}\n\nasync function executeMigrationGraphCommand(\n options: MigrationGraphOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n): Promise<Result<MigrationGraphResult, CliStructuredError>> {\n const config = await loadConfig(options.config);\n const { configPath, appMigrationsDir, appMigrationsRelative, refsDir } = resolveMigrationPaths(\n options.config,\n config,\n );\n\n if (!flags.json && !flags.quiet) {\n const header = formatStyledHeader({\n command: 'migration graph',\n description: 'Show the migration graph topology',\n details: [\n { label: 'config', value: configPath },\n { label: 'migrations', value: appMigrationsRelative },\n ],\n flags,\n });\n ui.stderr(header);\n }\n\n let graph: MigrationGraph;\n try {\n ({ graph } = await loadMigrationPackages(appMigrationsDir));\n } catch (error) {\n if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to read migrations: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n }\n\n let contractHash: string | null = null;\n try {\n const envelope = await readContractEnvelope(config);\n contractHash = envelope.storageHash;\n } catch {\n // Contract unreadable — render graph without contract marker\n }\n\n let refs: readonly StatusRef[] = [];\n try {\n const allRefs = await readRefs(refsDir);\n refs = Object.entries(allRefs).map(([name, entry]) => ({\n name,\n hash: entry.hash,\n active: false,\n }));\n } catch {\n // Refs unreadable — render graph without ref markers\n }\n\n return ok({\n ok: true,\n graph,\n contractHash,\n refs,\n summary: `${graph.nodes.size} node(s), ${graph.migrationByHash.size} edge(s)`,\n });\n}\n\nexport function createMigrationGraphCommand(): Command {\n const command = new Command('graph');\n setCommandDescriptions(\n command,\n 'Show the migration graph topology',\n 'Renders the migration graph as an ASCII tree. Offline — does not\\n' +\n 'consult the database. Use --json for machine-readable output or\\n' +\n '--dot for Graphviz DOT format.',\n );\n setCommandExamples(command, [\n 'prisma-next migration graph',\n 'prisma-next migration graph --json',\n 'prisma-next migration graph --dot',\n ]);\n setCommandSeeAlso(command, [\n { verb: 'migration status', oneLiner: 'Show migration path and pending status' },\n { verb: 'migration log', oneLiner: 'Show executed migration history' },\n { verb: 'migration list', oneLiner: 'List on-disk migrations' },\n { verb: 'migration show', oneLiner: 'Display migration package contents' },\n ]);\n addGlobalOptions(command)\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option('--dot', 'Output in Graphviz DOT format')\n .action(async (options: MigrationGraphOptions) => {\n const flags = parseGlobalFlagsOrExit(options);\n const ui = createTerminalUI(flags);\n const result = await executeMigrationGraphCommand(options, flags, ui);\n const exitCode = handleResult(result, flags, ui, (graphResult) => {\n // Explicit format flags win over the auto-JSON default. `flags.json`\n // is auto-enabled when stdout is non-TTY (per CLI Style Guide §\n // JSON Semantics); without this ordering, `migration graph --dot |\n // dot -Tsvg` pipes JSON into the GraphViz binary, which then\n // errors. `--dot` is the more specific instruction; honour it.\n if (options.dot) {\n const lines = ['digraph migrations {'];\n for (const edge of graphResult.graph.migrationByHash.values()) {\n const from = edge.from.slice(0, 12);\n const to = edge.to.slice(0, 12);\n lines.push(` \"${from}\" -> \"${to}\" [label=\"${edge.dirName}\"];`);\n }\n lines.push('}');\n ui.output(lines.join('\\n'));\n } else if (flags.json) {\n const nodes = [...graphResult.graph.nodes];\n const edges = [...graphResult.graph.migrationByHash.values()].map((e) => ({\n dirName: e.dirName,\n from: e.from,\n to: e.to,\n migrationHash: e.migrationHash,\n }));\n ui.output(\n JSON.stringify({ ok: true, nodes, edges, summary: graphResult.summary }, null, 2),\n );\n } else if (!flags.quiet) {\n const renderInput = migrationGraphToRenderInput({\n graph: graphResult.graph,\n mode: 'offline',\n markerHash: undefined,\n contractHash: graphResult.contractHash ?? EMPTY_CONTRACT_HASH,\n refs: graphResult.refs,\n activeRefHash: undefined,\n activeRefName: undefined,\n edgeStatuses: [],\n });\n const graphOutput = graphRenderer.render(renderInput.graph, {\n ...renderInput.options,\n colorize: flags.color !== false,\n });\n ui.log(graphOutput);\n ui.log(`\\n${graphResult.summary}`);\n }\n });\n process.exit(exitCode);\n });\n return command;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"migration-graph.mjs","names":[],"sources":["../../src/commands/migration-graph.ts"],"sourcesContent":["import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport { MigrationToolsError } from '@prisma-next/migration-tools/errors';\nimport type { MigrationGraph } from '@prisma-next/migration-tools/graph';\nimport { readRefs } from '@prisma-next/migration-tools/refs';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport {\n type CliStructuredError,\n errorUnexpected,\n mapMigrationToolsError,\n} from '../utils/cli-errors';\nimport {\n addGlobalOptions,\n loadMigrationPackages,\n readContractEnvelope,\n resolveMigrationPaths,\n setCommandDescriptions,\n setCommandExamples,\n setCommandSeeAlso,\n} from '../utils/command-helpers';\nimport { migrationGraphToRenderInput } from '../utils/formatters/graph-migration-mapper';\nimport { graphRenderer } from '../utils/formatters/graph-render';\nimport { formatStyledHeader } from '../utils/formatters/styled';\nimport type { CommonCommandOptions } from '../utils/global-flags';\nimport { type GlobalFlags, parseGlobalFlagsOrExit } from '../utils/global-flags';\nimport type { StatusRef } from '../utils/migration-types';\nimport { handleResult } from '../utils/result-handler';\nimport { createTerminalUI, type TerminalUI } from '../utils/terminal-ui';\n\ninterface MigrationGraphOptions extends CommonCommandOptions {\n readonly config?: string;\n readonly dot?: boolean;\n}\n\nexport interface MigrationGraphResult {\n readonly ok: true;\n readonly graph: MigrationGraph;\n readonly contractHash: string | null;\n readonly refs: readonly StatusRef[];\n readonly summary: string;\n}\n\nasync function executeMigrationGraphCommand(\n options: MigrationGraphOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n): Promise<Result<MigrationGraphResult, CliStructuredError>> {\n const config = await loadConfig(options.config);\n const { configPath, appMigrationsDir, appMigrationsRelative, refsDir } = resolveMigrationPaths(\n options.config,\n config,\n );\n\n if (!flags.json && !flags.quiet) {\n const header = formatStyledHeader({\n command: 'migration graph',\n description: 'Show the migration graph topology',\n details: [\n { label: 'config', value: configPath },\n { label: 'migrations', value: appMigrationsRelative },\n ],\n flags,\n });\n ui.stderr(header);\n }\n\n let graph: MigrationGraph;\n try {\n ({ graph } = await loadMigrationPackages(appMigrationsDir));\n } catch (error) {\n if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to read migrations: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n }\n\n let contractHash: string | null = null;\n try {\n const envelope = await readContractEnvelope(config);\n contractHash = envelope.storageHash;\n } catch {\n // Contract unreadable — render graph without contract marker\n }\n\n let refs: readonly StatusRef[] = [];\n try {\n const allRefs = await readRefs(refsDir);\n refs = Object.entries(allRefs).map(([name, entry]) => ({\n name,\n hash: entry.hash,\n active: false,\n }));\n } catch {\n // Refs unreadable — render graph without ref markers\n }\n\n return ok({\n ok: true,\n graph,\n contractHash,\n refs,\n summary: `${graph.nodes.size} node(s), ${graph.migrationByHash.size} edge(s)`,\n });\n}\n\nexport function createMigrationGraphCommand(): Command {\n const command = new Command('graph');\n setCommandDescriptions(\n command,\n 'Show the migration graph topology',\n 'Renders the migration graph as an ASCII tree. Offline — does not\\n' +\n 'consult the database. Use --json for machine-readable output or\\n' +\n '--dot for Graphviz DOT format.',\n );\n setCommandExamples(command, [\n 'prisma-next migration graph',\n 'prisma-next migration graph --json',\n 'prisma-next migration graph --dot',\n ]);\n setCommandSeeAlso(command, [\n { verb: 'migration status', oneLiner: 'Show migration path and pending status' },\n { verb: 'migration log', oneLiner: 'Show executed migration history' },\n { verb: 'migration list', oneLiner: 'List on-disk migrations' },\n { verb: 'migration show', oneLiner: 'Display migration package contents' },\n ]);\n addGlobalOptions(command)\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option('--dot', 'Output in Graphviz DOT format')\n .action(async (options: MigrationGraphOptions) => {\n const flags = parseGlobalFlagsOrExit(options);\n const ui = createTerminalUI(flags);\n const result = await executeMigrationGraphCommand(options, flags, ui);\n const exitCode = handleResult(result, flags, ui, (graphResult) => {\n // Explicit format flags win over the auto-JSON default. `flags.json`\n // is auto-enabled when stdout is non-TTY (per CLI Style Guide §\n // JSON Semantics); without this ordering, `migration graph --dot |\n // dot -Tsvg` pipes JSON into the GraphViz binary, which then\n // errors. `--dot` is the more specific instruction; honour it.\n if (options.dot) {\n const lines = ['digraph migrations {'];\n for (const edge of graphResult.graph.migrationByHash.values()) {\n const from = edge.from.slice(0, 12);\n const to = edge.to.slice(0, 12);\n lines.push(` \"${from}\" -> \"${to}\" [label=\"${edge.dirName}\"];`);\n }\n lines.push('}');\n ui.output(lines.join('\\n'));\n } else if (flags.json) {\n const nodes = [...graphResult.graph.nodes];\n const edges = [...graphResult.graph.migrationByHash.values()].map((e) => ({\n dirName: e.dirName,\n from: e.from,\n to: e.to,\n migrationHash: e.migrationHash,\n }));\n ui.output(\n JSON.stringify({ ok: true, nodes, edges, summary: graphResult.summary }, null, 2),\n );\n } else if (!flags.quiet) {\n const renderInput = migrationGraphToRenderInput({\n graph: graphResult.graph,\n mode: 'offline',\n markerHash: undefined,\n contractHash: graphResult.contractHash ?? EMPTY_CONTRACT_HASH,\n refs: graphResult.refs,\n activeRefHash: undefined,\n activeRefName: undefined,\n edgeStatuses: [],\n });\n const graphOutput = graphRenderer.render(renderInput.graph, {\n ...renderInput.options,\n colorize: flags.color !== false,\n });\n ui.log(graphOutput);\n ui.log(`\\n${graphResult.summary}`);\n }\n });\n process.exit(exitCode);\n });\n return command;\n}\n"],"mappings":";;;;;;;;;;AA2CA,eAAe,6BACb,SACA,OACA,IAC2D;CAC3D,MAAM,SAAS,MAAM,WAAW,QAAQ,MAAM;CAC9C,MAAM,EAAE,YAAY,kBAAkB,uBAAuB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Ac,CAAC;IACjB,CAAC;IACD,MAAM,cAAc,cAAc,OAAO,YAAY,OAAO;KAC1D,GAAG,YAAY;KACf,UAAU,MAAM,UAAU;IAC5B,CAAC;IACD,GAAG,IAAI,WAAW;IAClB,GAAG,IAAI,KAAK,YAAY,SAAS;GACnC;EACF,CAAC;EACD,QAAQ,KAAK,QAAQ;CACvB,CAAC;CACH,OAAO;AACT"}
|
|
@@ -1,20 +1,71 @@
|
|
|
1
|
+
import { N as CliStructuredError } from "../types-CEtm6v6a.mjs";
|
|
2
|
+
import { t as GlyphMode } from "../glyph-mode-CBB4emzO.mjs";
|
|
1
3
|
import { Command } from "commander";
|
|
4
|
+
import { Result } from "@prisma-next/utils/result";
|
|
5
|
+
import { MigrationListResult } from "@prisma-next/migration-tools/migration-list-types";
|
|
2
6
|
|
|
3
7
|
//#region src/commands/migration-list.d.ts
|
|
4
|
-
interface
|
|
5
|
-
readonly
|
|
6
|
-
readonly
|
|
7
|
-
readonly
|
|
8
|
-
readonly migrationHash: string;
|
|
9
|
-
readonly operationCount: number;
|
|
10
|
-
readonly createdAt: string;
|
|
8
|
+
interface MigrationListHumanRenderOptions {
|
|
9
|
+
readonly graph: boolean;
|
|
10
|
+
readonly glyphMode: GlyphMode;
|
|
11
|
+
readonly useColor: boolean;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
declare function renderMigrationListHumanOutput(result: MigrationListResult, options: MigrationListHumanRenderOptions): string;
|
|
14
|
+
/**
|
|
15
|
+
* Inputs for {@link runMigrationList} — the pure-ish data-and-policy core
|
|
16
|
+
* of `migration list` that tests exercise directly.
|
|
17
|
+
*
|
|
18
|
+
* The core depends only on the filesystem rooted at `migrationsDir`. It
|
|
19
|
+
* does NOT call `loadConfig`, parse CLI flags, render a styled header,
|
|
20
|
+
* or write to any stream. Output rendering is the caller's concern (the
|
|
21
|
+
* CLI shell renders via {@link renderMigrationList}; JSON callers
|
|
22
|
+
* serialize the {@link MigrationListResult} directly).
|
|
23
|
+
*/
|
|
24
|
+
interface RunMigrationListInputs {
|
|
25
|
+
/** Absolute path to the project's `migrations/` directory. */
|
|
26
|
+
readonly migrationsDir: string;
|
|
27
|
+
/**
|
|
28
|
+
* Optional contract-space id to narrow the result to a single space.
|
|
29
|
+
* Same validation rules as {@link isValidSpaceId}. When absent, every
|
|
30
|
+
* on-disk space contributes.
|
|
31
|
+
*/
|
|
32
|
+
readonly spaceFilter?: string;
|
|
16
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* The unit-testable core of `migration list`. Given an absolute
|
|
36
|
+
* `migrationsDir` and an optional `spaceFilter`, enumerates every
|
|
37
|
+
* on-disk migration (via {@link enumerateMigrationSpaces}), narrows to
|
|
38
|
+
* the requested space if any, and assembles a {@link MigrationListResult}
|
|
39
|
+
* ready for the renderer or JSON serializer.
|
|
40
|
+
*
|
|
41
|
+
* The enumerator is the single source of truth for "what is a contract
|
|
42
|
+
* space": existence, the `--space` candidate-suggestion list, and
|
|
43
|
+
* scoping are all derived from one {@link enumerateMigrationSpaces}
|
|
44
|
+
* traversal. This means the reserved-name exclusion the enumerator
|
|
45
|
+
* applies (e.g. the per-space `refs/` subdirectory) is honoured here for
|
|
46
|
+
* free — a `--space refs` request resolves to `SPACE_NOT_FOUND`, not a
|
|
47
|
+
* synthesized empty-state.
|
|
48
|
+
*
|
|
49
|
+
* Distinct empty-state paths:
|
|
50
|
+
*
|
|
51
|
+
* - `migrations/` missing or contains no valid space directories →
|
|
52
|
+
* synthesizes `[{ spaceId: APP_SPACE_ID, migrations: [] }]` so the
|
|
53
|
+
* renderer's empty-state path can name a directory (spec § Empty-state +
|
|
54
|
+
* the `migrations/` missing edge case).
|
|
55
|
+
* - `--space <id>` on an existing-but-empty space dir → the enumerator
|
|
56
|
+
* surfaces `{ spaceId, migrations: [] }`; `<id>` is in the set, so it
|
|
57
|
+
* scopes to that entry and renders the empty-state the same way.
|
|
58
|
+
* - `--space <id>` on a non-existent (or reserved) space → structured
|
|
59
|
+
* `MIGRATION.SPACE_NOT_FOUND` error (NOT empty-state).
|
|
60
|
+
*
|
|
61
|
+
* Errors caught here:
|
|
62
|
+
*
|
|
63
|
+
* - {@link MigrationToolsError} from the enumerator → mapped through
|
|
64
|
+
* {@link mapMigrationToolsError} so callers see the catalogue code.
|
|
65
|
+
* - Anything else (filesystem etc.) → wrapped via {@link errorUnexpected}.
|
|
66
|
+
*/
|
|
67
|
+
declare function runMigrationList(inputs: RunMigrationListInputs): Promise<Result<MigrationListResult, CliStructuredError>>;
|
|
17
68
|
declare function createMigrationListCommand(): Command;
|
|
18
69
|
//#endregion
|
|
19
|
-
export {
|
|
70
|
+
export { MigrationListHumanRenderOptions, RunMigrationListInputs, createMigrationListCommand, renderMigrationListHumanOutput, runMigrationList };
|
|
20
71
|
//# sourceMappingURL=migration-list.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-list.d.mts","names":[],"sources":["../../src/commands/migration-list.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"migration-list.d.mts","names":[],"sources":["../../src/commands/migration-list.ts"],"mappings":";;;;;;;UA+CiB,+BAAA;EAAA,SACN,KAAA;EAAA,SACA,SAAA,EAAW,SAAS;EAAA,SACpB,QAAA;AAAA;AAAA,iBAGK,8BAAA,CACd,MAAA,EAAQ,mBAAA,EACR,OAAA,EAAS,+BAA+B;;;;;;;AALvB;AAGnB;;;UAsBiB,sBAAA;EArBP;EAAA,SAuBC,aAAA;EAtBA;;;AAA+B;AAoB1C;EApBW,SA4BA,WAAW;AAAA;;AAAA;AA4CtB;;;;;;;;;;;;;;;;;AAEyD;AAwEzD;;;;AAAqD;;;;;;;;;iBA1E/B,gBAAA,CACpB,MAAA,EAAQ,sBAAA,GACP,OAAA,CAAQ,MAAA,CAAO,mBAAA,EAAqB,kBAAA;AAAA,iBAwEvB,0BAAA,CAAA,GAA8B,OAAO"}
|
|
@@ -1,103 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
import { t as createTerminalUI } from "../terminal-ui-BiB_8KNo.mjs";
|
|
4
|
-
import { S as formatStyledHeader, a as loadMigrationPackages, d as setCommandDescriptions, f as setCommandExamples, l as resolveMigrationPaths, p as setCommandSeeAlso, t as addGlobalOptions, v as parseGlobalFlagsOrExit, y as handleResult } from "../command-helpers-DtavI0wJ.mjs";
|
|
5
|
-
import { Command } from "commander";
|
|
6
|
-
import { notOk, ok } from "@prisma-next/utils/result";
|
|
7
|
-
import { findPath } from "@prisma-next/migration-tools/migration-graph";
|
|
8
|
-
import { EMPTY_CONTRACT_HASH } from "@prisma-next/migration-tools/constants";
|
|
9
|
-
import { MigrationToolsError } from "@prisma-next/migration-tools/errors";
|
|
10
|
-
//#region src/commands/migration-list.ts
|
|
11
|
-
async function executeMigrationListCommand(options, flags, ui) {
|
|
12
|
-
const config = await loadConfig(options.config);
|
|
13
|
-
const { configPath, appMigrationsDir, appMigrationsRelative } = resolveMigrationPaths(options.config, config);
|
|
14
|
-
if (!flags.json && !flags.quiet) {
|
|
15
|
-
const header = formatStyledHeader({
|
|
16
|
-
command: "migration list",
|
|
17
|
-
description: "List on-disk migrations in topological order",
|
|
18
|
-
details: [{
|
|
19
|
-
label: "config",
|
|
20
|
-
value: configPath
|
|
21
|
-
}, {
|
|
22
|
-
label: "migrations",
|
|
23
|
-
value: appMigrationsRelative
|
|
24
|
-
}],
|
|
25
|
-
flags
|
|
26
|
-
});
|
|
27
|
-
ui.stderr(header);
|
|
28
|
-
}
|
|
29
|
-
let bundles;
|
|
30
|
-
let graph;
|
|
31
|
-
try {
|
|
32
|
-
({bundles, graph} = await loadMigrationPackages(appMigrationsDir));
|
|
33
|
-
} catch (error) {
|
|
34
|
-
if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));
|
|
35
|
-
return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to read migrations: ${error instanceof Error ? error.message : String(error)}` }));
|
|
36
|
-
}
|
|
37
|
-
if (bundles.length === 0) return ok({
|
|
38
|
-
ok: true,
|
|
39
|
-
migrations: [],
|
|
40
|
-
summary: "No migrations found"
|
|
41
|
-
});
|
|
42
|
-
const leaves = [...graph.nodes].filter((n) => !graph.forwardChain.has(n) || graph.forwardChain.get(n).length === 0);
|
|
43
|
-
const targetHash = leaves.length === 1 ? leaves[0] : [...graph.nodes].values().next().value;
|
|
44
|
-
const chain = findPath(graph, EMPTY_CONTRACT_HASH, targetHash) ?? [];
|
|
45
|
-
const pkgByDirName = new Map(bundles.map((p) => [p.dirName, p]));
|
|
46
|
-
const entries = chain.map((edge) => {
|
|
47
|
-
const ops = pkgByDirName.get(edge.dirName)?.ops ?? [];
|
|
48
|
-
return {
|
|
49
|
-
dirName: edge.dirName,
|
|
50
|
-
from: edge.from,
|
|
51
|
-
to: edge.to,
|
|
52
|
-
migrationHash: edge.migrationHash,
|
|
53
|
-
operationCount: ops.length,
|
|
54
|
-
createdAt: edge.createdAt
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
return ok({
|
|
58
|
-
ok: true,
|
|
59
|
-
migrations: entries,
|
|
60
|
-
summary: `${entries.length} migration(s) on disk`
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
function createMigrationListCommand() {
|
|
64
|
-
const command = new Command("list");
|
|
65
|
-
setCommandDescriptions(command, "List on-disk migrations in topological order", "Enumerates all migration packages under migrations/<space>/ in\ntopological order. Offline — does not consult the database.");
|
|
66
|
-
setCommandExamples(command, ["prisma-next migration list"]);
|
|
67
|
-
setCommandSeeAlso(command, [
|
|
68
|
-
{
|
|
69
|
-
verb: "migration status",
|
|
70
|
-
oneLiner: "Show migration path and pending status"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
verb: "migration log",
|
|
74
|
-
oneLiner: "Show executed migration history"
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
verb: "migration graph",
|
|
78
|
-
oneLiner: "Show the migration graph topology"
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
verb: "migration show",
|
|
82
|
-
oneLiner: "Display migration package contents"
|
|
83
|
-
}
|
|
84
|
-
]);
|
|
85
|
-
addGlobalOptions(command).option("--config <path>", "Path to prisma-next.config.ts").action(async (options) => {
|
|
86
|
-
const flags = parseGlobalFlagsOrExit(options);
|
|
87
|
-
const ui = createTerminalUI(flags);
|
|
88
|
-
const exitCode = handleResult(await executeMigrationListCommand(options, flags, ui), flags, ui, (listResult) => {
|
|
89
|
-
if (flags.json) ui.output(JSON.stringify(listResult, null, 2));
|
|
90
|
-
else if (!flags.quiet) if (listResult.migrations.length === 0) ui.log("No migrations found");
|
|
91
|
-
else {
|
|
92
|
-
for (const entry of listResult.migrations) ui.log(`${entry.dirName} ${entry.migrationHash.slice(0, 16)}… ${entry.operationCount} op(s)`);
|
|
93
|
-
ui.log(`\n${listResult.summary}`);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
process.exit(exitCode);
|
|
97
|
-
});
|
|
98
|
-
return command;
|
|
99
|
-
}
|
|
100
|
-
//#endregion
|
|
101
|
-
export { createMigrationListCommand };
|
|
102
|
-
|
|
103
|
-
//# sourceMappingURL=migration-list.mjs.map
|
|
1
|
+
import { n as renderMigrationListHumanOutput, r as runMigrationList, t as createMigrationListCommand } from "../migration-list-B2-iQ5Jd.mjs";
|
|
2
|
+
export { createMigrationListCommand, renderMigrationListHumanOutput, runMigrationList };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-log.d.mts","names":[],"sources":["../../src/commands/migration-log.ts"],"mappings":";;;UAqCiB,iBAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAA;EAAA,SACA,EAAA;EAAA,SACA,aAAA;EAAA,SACA,cAAA;EAAA,SACA,SAAA;AAAA;AAAA,UAGM,kBAAA;EAAA,SACN,EAAA;EAAA,SACA,UAAA;EAAA,SACA,OAAA,WAAkB,
|
|
1
|
+
{"version":3,"file":"migration-log.d.mts","names":[],"sources":["../../src/commands/migration-log.ts"],"mappings":";;;UAqCiB,iBAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAA;EAAA,SACA,EAAA;EAAA,SACA,aAAA;EAAA,SACA,cAAA;EAAA,SACA,SAAA;AAAA;AAAA,UAGM,kBAAA;EAAA,SACN,EAAA;EAAA,SACA,UAAA;EAAA,SACA,OAAA,WAAkB,iBAAiB;EAAA,SACnC,OAAA;AAAA;AAAA,iBA2HK,yBAAA,CAAA,GAA6B,OAAO"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { t as loadConfig } from "../config-loader-B6sJjXTv.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { t as createTerminalUI } from "../
|
|
4
|
-
import {
|
|
5
|
-
import { t as createControlClient } from "../client-oXO2WCPD.mjs";
|
|
2
|
+
import { O as errorUnexpected, c as errorDriverRequired, k as mapMigrationToolsError, o as errorDatabaseConnectionRequired, t as CliStructuredError } from "../cli-errors-DFF1LlfU.mjs";
|
|
3
|
+
import { D as formatStyledHeader, a as loadMigrationPackages, d as setCommandDescriptions, f as setCommandExamples, l as resolveMigrationPaths, m as targetSupportsMigrations, o as maskConnectionUrl, p as setCommandSeeAlso, t as addGlobalOptions, v as parseGlobalFlagsOrExit, x as handleResult, y as createTerminalUI } from "../command-helpers-4UNsRRc4.mjs";
|
|
4
|
+
import { t as createControlClient } from "../client-5uvDppD8.mjs";
|
|
6
5
|
import { Command } from "commander";
|
|
7
6
|
import { notOk, ok } from "@prisma-next/utils/result";
|
|
8
7
|
import { findPath } from "@prisma-next/migration-tools/migration-graph";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-log.mjs","names":[],"sources":["../../src/commands/migration-log.ts"],"sourcesContent":["import type { MigrationPlanOperation } from '@prisma-next/framework-components/control';\nimport { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport { MigrationToolsError } from '@prisma-next/migration-tools/errors';\nimport { findPath } from '@prisma-next/migration-tools/migration-graph';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { cyan, dim } from 'colorette';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport { createControlClient } from '../control-api/client';\nimport {\n CliStructuredError,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorUnexpected,\n mapMigrationToolsError,\n} from '../utils/cli-errors';\nimport {\n addGlobalOptions,\n loadMigrationPackages,\n maskConnectionUrl,\n resolveMigrationPaths,\n setCommandDescriptions,\n setCommandExamples,\n setCommandSeeAlso,\n targetSupportsMigrations,\n} from '../utils/command-helpers';\nimport { formatStyledHeader } from '../utils/formatters/styled';\nimport type { CommonCommandOptions } from '../utils/global-flags';\nimport { type GlobalFlags, parseGlobalFlagsOrExit } from '../utils/global-flags';\nimport { handleResult } from '../utils/result-handler';\nimport { createTerminalUI, type TerminalUI } from '../utils/terminal-ui';\n\ninterface MigrationLogOptions extends CommonCommandOptions {\n readonly db?: string;\n readonly config?: string;\n}\n\nexport interface MigrationLogEntry {\n readonly dirName: string;\n readonly from: string;\n readonly to: string;\n readonly migrationHash: string;\n readonly operationCount: number;\n readonly createdAt: string;\n}\n\nexport interface MigrationLogResult {\n readonly ok: true;\n readonly markerHash: string | null;\n readonly applied: readonly MigrationLogEntry[];\n readonly summary: string;\n}\n\nasync function executeMigrationLogCommand(\n options: MigrationLogOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n): Promise<Result<MigrationLogResult, CliStructuredError>> {\n const config = await loadConfig(options.config);\n const { configPath, appMigrationsDir, appMigrationsRelative } = resolveMigrationPaths(\n options.config,\n config,\n );\n\n const dbConnection = options.db ?? config.db?.connection;\n if (!dbConnection) {\n return notOk(\n errorDatabaseConnectionRequired({\n why: `Database connection is required for migration log (set db.connection in ${configPath}, or pass --db <url>)`,\n commandName: 'migration log',\n }),\n );\n }\n if (!config.driver) {\n return notOk(errorDriverRequired({ why: 'Config.driver is required for migration log' }));\n }\n if (!targetSupportsMigrations(config.target)) {\n return notOk(errorUnexpected('Target does not support migrations'));\n }\n\n if (!flags.json && !flags.quiet) {\n const header = formatStyledHeader({\n command: 'migration log',\n description: 'Show executed migration history',\n details: [\n { label: 'config', value: configPath },\n { label: 'migrations', value: appMigrationsRelative },\n ...(typeof dbConnection === 'string'\n ? [{ label: 'database', value: maskConnectionUrl(dbConnection) }]\n : []),\n ],\n flags,\n });\n ui.stderr(header);\n }\n\n let bundles: Awaited<ReturnType<typeof loadMigrationPackages>>['bundles'];\n let graph: Awaited<ReturnType<typeof loadMigrationPackages>>['graph'];\n try {\n ({ bundles, graph } = await loadMigrationPackages(appMigrationsDir));\n } catch (error) {\n if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to read migrations: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n }\n\n const client = createControlClient({\n family: config.family,\n target: config.target,\n adapter: config.adapter,\n driver: config.driver,\n extensionPacks: config.extensionPacks ?? [],\n });\n\n try {\n await client.connect(dbConnection);\n const marker = await client.readMarker();\n const markerHash = marker?.storageHash ?? null;\n\n if (!markerHash) {\n return ok({\n ok: true,\n markerHash: null,\n applied: [],\n summary: 'No migrations applied (database has no marker)',\n });\n }\n\n const appliedPath = findPath(graph, EMPTY_CONTRACT_HASH, markerHash);\n if (appliedPath === null) {\n return notOk(\n errorUnexpected('Database marker is not reachable from migration history', {\n why: `Marker hash ${markerHash} is not reachable from the root of the on-disk migration graph.`,\n fix: 'The database may have been migrated outside this project. Use `migration status` to inspect the current state.',\n }),\n );\n }\n const pkgByDirName = new Map(bundles.map((p) => [p.dirName, p]));\n const entries: MigrationLogEntry[] = appliedPath.map((edge) => {\n const pkg = pkgByDirName.get(edge.dirName);\n const ops = (pkg?.ops ?? []) as readonly MigrationPlanOperation[];\n return {\n dirName: edge.dirName,\n from: edge.from,\n to: edge.to,\n migrationHash: edge.migrationHash,\n operationCount: ops.length,\n createdAt: edge.createdAt,\n };\n });\n\n return ok({\n ok: true,\n markerHash,\n applied: entries,\n summary: `${entries.length} migration(s) applied`,\n });\n } catch (error) {\n if (CliStructuredError.is(error)) return notOk(error);\n if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to read migration log: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n } finally {\n await client.close();\n }\n}\n\nexport function createMigrationLogCommand(): Command {\n const command = new Command('log');\n setCommandDescriptions(\n command,\n 'Show executed migration history',\n 'Reads the database marker and displays the applied migration chain\\n' +\n 'from the initial state to the current marker position.',\n );\n setCommandExamples(command, [\n 'prisma-next migration log --db $DATABASE_URL',\n 'prisma-next migration log --json --db $DATABASE_URL',\n ]);\n setCommandSeeAlso(command, [\n { verb: 'migration status', oneLiner: 'Show migration path and pending status' },\n { verb: 'migration list', oneLiner: 'List on-disk migrations' },\n { verb: 'migration graph', oneLiner: 'Show the migration graph topology' },\n { verb: 'migration show', oneLiner: 'Display migration package contents' },\n ]);\n addGlobalOptions(command)\n .option('--db <url>', 'Database connection string')\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .action(async (options: MigrationLogOptions) => {\n const flags = parseGlobalFlagsOrExit(options);\n const ui = createTerminalUI(flags);\n const result = await executeMigrationLogCommand(options, flags, ui);\n const exitCode = handleResult(result, flags, ui, (logResult) => {\n if (flags.json) {\n ui.output(JSON.stringify(logResult, null, 2));\n } else if (!flags.quiet) {\n const c = (fn: (s: string) => string, s: string) => (flags.color !== false ? fn(s) : s);\n if (logResult.applied.length === 0) {\n ui.log(logResult.summary);\n } else {\n for (const entry of logResult.applied) {\n ui.log(\n `${c(cyan, '✓')} ${entry.dirName} ${c(dim, entry.migrationHash.slice(0, 16) + '…')} ${entry.operationCount} op(s)`,\n );\n }\n ui.log(`\\n${logResult.summary}`);\n }\n }\n });\n process.exit(exitCode);\n });\n return command;\n}\n"],"mappings":";;;;;;;;;;;;AAqDA,eAAe,2BACb,SACA,OAC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AAU;GAA0C;EAChF;GAAE,MAAM;GAAkB,UAAU;GAA2B;EAC/D;GAAE,MAAM;GAAmB,UAAU;GAAqC;EAC1E;GAAE,MAAM;GAAkB,UAAU;GAAsC;EAC3E,CAAC;CACF,iBAAiB,QAAQ,CACtB,OAAO,cAAc,6BAA6B,CAClD,OAAO,mBAAmB,gCAAgC,CAC1D,OAAO,OAAO,YAAiC;EAC9C,MAAM,QAAQ,uBAAuB,QAAQ;EAC7C,MAAM,KAAK,iBAAiB,MAAM;EAElC,MAAM,WAAW,aAAa,MADT,2BAA2B,SAAS,OAAO,GAAG,EAC7B,OAAO,KAAK,cAAc;GAC9D,IAAI,MAAM,MACR,GAAG,OAAO,KAAK,UAAU,WAAW,MAAM,EAAE,CAAC;QACxC,IAAI,CAAC,MAAM,OAAO;IACvB,MAAM,KAAK,IAA2B,MAAe,MAAM,UAAU,QAAQ,GAAG,EAAE,GAAG;IACrF,IAAI,UAAU,QAAQ,WAAW,GAC/B,GAAG,IAAI,UAAU,QAAQ;SACpB;KACL,KAAK,MAAM,SAAS,UAAU,SAC5B,GAAG,IACD,GAAG,EAAE,MAAM,IAAI,CAAC,GAAG,MAAM,QAAQ,IAAI,EAAE,KAAK,MAAM,cAAc,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,MAAM,eAAe,QAC9G;KAEH,GAAG,IAAI,KAAK,UAAU,UAAU;;;IAGpC;EACF,QAAQ,KAAK,SAAS;GACtB;CACJ,OAAO"}
|
|
1
|
+
{"version":3,"file":"migration-log.mjs","names":[],"sources":["../../src/commands/migration-log.ts"],"sourcesContent":["import type { MigrationPlanOperation } from '@prisma-next/framework-components/control';\nimport { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport { MigrationToolsError } from '@prisma-next/migration-tools/errors';\nimport { findPath } from '@prisma-next/migration-tools/migration-graph';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { cyan, dim } from 'colorette';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport { createControlClient } from '../control-api/client';\nimport {\n CliStructuredError,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorUnexpected,\n mapMigrationToolsError,\n} from '../utils/cli-errors';\nimport {\n addGlobalOptions,\n loadMigrationPackages,\n maskConnectionUrl,\n resolveMigrationPaths,\n setCommandDescriptions,\n setCommandExamples,\n setCommandSeeAlso,\n targetSupportsMigrations,\n} from '../utils/command-helpers';\nimport { formatStyledHeader } from '../utils/formatters/styled';\nimport type { CommonCommandOptions } from '../utils/global-flags';\nimport { type GlobalFlags, parseGlobalFlagsOrExit } from '../utils/global-flags';\nimport { handleResult } from '../utils/result-handler';\nimport { createTerminalUI, type TerminalUI } from '../utils/terminal-ui';\n\ninterface MigrationLogOptions extends CommonCommandOptions {\n readonly db?: string;\n readonly config?: string;\n}\n\nexport interface MigrationLogEntry {\n readonly dirName: string;\n readonly from: string;\n readonly to: string;\n readonly migrationHash: string;\n readonly operationCount: number;\n readonly createdAt: string;\n}\n\nexport interface MigrationLogResult {\n readonly ok: true;\n readonly markerHash: string | null;\n readonly applied: readonly MigrationLogEntry[];\n readonly summary: string;\n}\n\nasync function executeMigrationLogCommand(\n options: MigrationLogOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n): Promise<Result<MigrationLogResult, CliStructuredError>> {\n const config = await loadConfig(options.config);\n const { configPath, appMigrationsDir, appMigrationsRelative } = resolveMigrationPaths(\n options.config,\n config,\n );\n\n const dbConnection = options.db ?? config.db?.connection;\n if (!dbConnection) {\n return notOk(\n errorDatabaseConnectionRequired({\n why: `Database connection is required for migration log (set db.connection in ${configPath}, or pass --db <url>)`,\n commandName: 'migration log',\n }),\n );\n }\n if (!config.driver) {\n return notOk(errorDriverRequired({ why: 'Config.driver is required for migration log' }));\n }\n if (!targetSupportsMigrations(config.target)) {\n return notOk(errorUnexpected('Target does not support migrations'));\n }\n\n if (!flags.json && !flags.quiet) {\n const header = formatStyledHeader({\n command: 'migration log',\n description: 'Show executed migration history',\n details: [\n { label: 'config', value: configPath },\n { label: 'migrations', value: appMigrationsRelative },\n ...(typeof dbConnection === 'string'\n ? [{ label: 'database', value: maskConnectionUrl(dbConnection) }]\n : []),\n ],\n flags,\n });\n ui.stderr(header);\n }\n\n let bundles: Awaited<ReturnType<typeof loadMigrationPackages>>['bundles'];\n let graph: Awaited<ReturnType<typeof loadMigrationPackages>>['graph'];\n try {\n ({ bundles, graph } = await loadMigrationPackages(appMigrationsDir));\n } catch (error) {\n if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to read migrations: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n }\n\n const client = createControlClient({\n family: config.family,\n target: config.target,\n adapter: config.adapter,\n driver: config.driver,\n extensionPacks: config.extensionPacks ?? [],\n });\n\n try {\n await client.connect(dbConnection);\n const marker = await client.readMarker();\n const markerHash = marker?.storageHash ?? null;\n\n if (!markerHash) {\n return ok({\n ok: true,\n markerHash: null,\n applied: [],\n summary: 'No migrations applied (database has no marker)',\n });\n }\n\n const appliedPath = findPath(graph, EMPTY_CONTRACT_HASH, markerHash);\n if (appliedPath === null) {\n return notOk(\n errorUnexpected('Database marker is not reachable from migration history', {\n why: `Marker hash ${markerHash} is not reachable from the root of the on-disk migration graph.`,\n fix: 'The database may have been migrated outside this project. Use `migration status` to inspect the current state.',\n }),\n );\n }\n const pkgByDirName = new Map(bundles.map((p) => [p.dirName, p]));\n const entries: MigrationLogEntry[] = appliedPath.map((edge) => {\n const pkg = pkgByDirName.get(edge.dirName);\n const ops = (pkg?.ops ?? []) as readonly MigrationPlanOperation[];\n return {\n dirName: edge.dirName,\n from: edge.from,\n to: edge.to,\n migrationHash: edge.migrationHash,\n operationCount: ops.length,\n createdAt: edge.createdAt,\n };\n });\n\n return ok({\n ok: true,\n markerHash,\n applied: entries,\n summary: `${entries.length} migration(s) applied`,\n });\n } catch (error) {\n if (CliStructuredError.is(error)) return notOk(error);\n if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to read migration log: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n } finally {\n await client.close();\n }\n}\n\nexport function createMigrationLogCommand(): Command {\n const command = new Command('log');\n setCommandDescriptions(\n command,\n 'Show executed migration history',\n 'Reads the database marker and displays the applied migration chain\\n' +\n 'from the initial state to the current marker position.',\n );\n setCommandExamples(command, [\n 'prisma-next migration log --db $DATABASE_URL',\n 'prisma-next migration log --json --db $DATABASE_URL',\n ]);\n setCommandSeeAlso(command, [\n { verb: 'migration status', oneLiner: 'Show migration path and pending status' },\n { verb: 'migration list', oneLiner: 'List on-disk migrations' },\n { verb: 'migration graph', oneLiner: 'Show the migration graph topology' },\n { verb: 'migration show', oneLiner: 'Display migration package contents' },\n ]);\n addGlobalOptions(command)\n .option('--db <url>', 'Database connection string')\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .action(async (options: MigrationLogOptions) => {\n const flags = parseGlobalFlagsOrExit(options);\n const ui = createTerminalUI(flags);\n const result = await executeMigrationLogCommand(options, flags, ui);\n const exitCode = handleResult(result, flags, ui, (logResult) => {\n if (flags.json) {\n ui.output(JSON.stringify(logResult, null, 2));\n } else if (!flags.quiet) {\n const c = (fn: (s: string) => string, s: string) => (flags.color !== false ? fn(s) : s);\n if (logResult.applied.length === 0) {\n ui.log(logResult.summary);\n } else {\n for (const entry of logResult.applied) {\n ui.log(\n `${c(cyan, '✓')} ${entry.dirName} ${c(dim, entry.migrationHash.slice(0, 16) + '…')} ${entry.operationCount} op(s)`,\n );\n }\n ui.log(`\\n${logResult.summary}`);\n }\n }\n });\n process.exit(exitCode);\n });\n return command;\n}\n"],"mappings":";;;;;;;;;;;AAqDA,eAAe,2BACb,SACA,OACA,IACyD;CACzD,MAAM,SAAS,MAAM,WAAW,QAAQ,MAAM;CAC9C,MAAM,EAAE,YAAY,kBAAkB,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A0B;EAC9D;GAAE,MAAM;GAAmB,UAAU;EAAoC;EACzE;GAAE,MAAM;GAAkB,UAAU;EAAqC;CAC3E,CAAC;CACD,iBAAiB,OAAO,EACrB,OAAO,cAAc,4BAA4B,EACjD,OAAO,mBAAmB,+BAA+B,EACzD,OAAO,OAAO,YAAiC;EAC9C,MAAM,QAAQ,uBAAuB,OAAO;EAC5C,MAAM,KAAK,iBAAiB,KAAK;EAEjC,MAAM,WAAW,aAAa,MADT,2BAA2B,SAAS,OAAO,EAAE,GAC5B,OAAO,KAAK,cAAc;GAC9D,IAAI,MAAM,MACR,GAAG,OAAO,KAAK,UAAU,WAAW,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,OAAO;IACvB,MAAM,KAAK,IAA2B,MAAe,MAAM,UAAU,QAAQ,GAAG,CAAC,IAAI;IACrF,IAAI,UAAU,QAAQ,WAAW,GAC/B,GAAG,IAAI,UAAU,OAAO;SACnB;KACL,KAAK,MAAM,SAAS,UAAU,SAC5B,GAAG,IACD,GAAG,EAAE,MAAM,GAAG,EAAE,GAAG,MAAM,QAAQ,IAAI,EAAE,KAAK,MAAM,cAAc,MAAM,GAAG,EAAE,IAAI,GAAG,EAAE,IAAI,MAAM,eAAe,OAC/G;KAEF,GAAG,IAAI,KAAK,UAAU,SAAS;IACjC;GACF;EACF,CAAC;EACD,QAAQ,KAAK,QAAQ;CACvB,CAAC;CACH,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-new.d.mts","names":[],"sources":["../../src/commands/migration-new.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"migration-new.d.mts","names":[],"sources":["../../src/commands/migration-new.ts"],"mappings":";;;iBA2QgB,yBAAA,CAAA,GAA6B,OAAO"}
|