prisma-next 0.11.0-dev.47 → 0.11.0-dev.49
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.mjs +9 -9
- package/dist/{command-helpers-CI8P5Xyd.mjs → command-helpers-4UNsRRc4.mjs} +3 -181
- package/dist/command-helpers-4UNsRRc4.mjs.map +1 -0
- package/dist/commands/contract-emit.mjs +1 -1
- package/dist/commands/contract-infer.mjs +1 -1
- package/dist/commands/db-init.mjs +3 -3
- package/dist/commands/db-schema.mjs +3 -3
- package/dist/commands/db-sign.mjs +2 -2
- package/dist/commands/db-update.mjs +3 -3
- package/dist/commands/db-verify.mjs +1 -1
- package/dist/commands/migrate.mjs +2 -2
- package/dist/commands/migration-check.mjs +1 -1
- package/dist/commands/migration-graph.mjs +1 -1
- package/dist/commands/migration-list.d.mts +1 -1
- package/dist/commands/migration-list.d.mts.map +1 -1
- package/dist/commands/migration-list.mjs +1 -1
- package/dist/commands/migration-log.mjs +1 -1
- package/dist/commands/migration-new.mjs +1 -1
- package/dist/commands/migration-plan.mjs +1 -1
- package/dist/commands/migration-show.mjs +2 -2
- package/dist/commands/migration-status.mjs +2 -2
- package/dist/commands/ref.mjs +1 -1
- package/dist/{contract-emit-DmBG2Nnc.mjs → contract-emit-Bbdnpcjl.mjs} +2 -2
- package/dist/{contract-emit-DmBG2Nnc.mjs.map → contract-emit-Bbdnpcjl.mjs.map} +1 -1
- package/dist/{contract-infer-BSWFKgI1.mjs → contract-infer-C98ZaRhp.mjs} +3 -3
- package/dist/{contract-infer-BSWFKgI1.mjs.map → contract-infer-C98ZaRhp.mjs.map} +1 -1
- package/dist/{db-verify-BzpwFyLg.mjs → db-verify-BWl1Yxi-.mjs} +3 -3
- package/dist/{db-verify-BzpwFyLg.mjs.map → db-verify-BWl1Yxi-.mjs.map} +1 -1
- package/dist/exports/index.mjs +1 -1
- package/dist/exports/init-output.d.mts.map +1 -1
- package/dist/glyph-mode-CBB4emzO.d.mts +5 -0
- package/dist/glyph-mode-CBB4emzO.d.mts.map +1 -0
- package/dist/{init-DEssiJ8j.mjs → init-C3Swd5QB.mjs} +2 -2
- package/dist/{init-DEssiJ8j.mjs.map → init-C3Swd5QB.mjs.map} +1 -1
- package/dist/{inspect-live-schema-DlBM84nh.mjs → inspect-live-schema-BRCWQ-Sr.mjs} +2 -2
- package/dist/{inspect-live-schema-DlBM84nh.mjs.map → inspect-live-schema-BRCWQ-Sr.mjs.map} +1 -1
- package/dist/{migration-check-CzLbAqIQ.mjs → migration-check-DoskM1nB.mjs} +2 -2
- package/dist/{migration-check-CzLbAqIQ.mjs.map → migration-check-DoskM1nB.mjs.map} +1 -1
- package/dist/{migration-command-scaffold-Bp8UHnvJ.mjs → migration-command-scaffold-CXLkoIJx.mjs} +2 -2
- package/dist/{migration-command-scaffold-Bp8UHnvJ.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-BLvOmNCu.mjs → migration-plan-BqmIKQpZ.mjs} +2 -2
- package/dist/{migration-plan-BLvOmNCu.mjs.map → migration-plan-BqmIKQpZ.mjs.map} +1 -1
- package/dist/{migrations-vzQt9LI2.mjs → migrations-BcVTutso.mjs} +2 -2
- package/dist/{migrations-vzQt9LI2.mjs.map → migrations-BcVTutso.mjs.map} +1 -1
- package/dist/{verify-ktSRQvIS.mjs → verify-DOHbbrub.mjs} +2 -2
- package/dist/{verify-ktSRQvIS.mjs.map → verify-DOHbbrub.mjs.map} +1 -1
- package/package.json +11 -11
- package/dist/command-helpers-CI8P5Xyd.mjs.map +0 -1
- package/dist/migration-list-C2xnaYsT.mjs +0 -279
- package/dist/migration-list-C2xnaYsT.mjs.map +0 -1
- package/dist/migration-list-graph-render-DKw1AT-e.d.mts +0 -7
- package/dist/migration-list-graph-render-DKw1AT-e.d.mts.map +0 -1
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
import { t as loadConfig } from "./config-loader-B6sJjXTv.mjs";
|
|
2
|
+
import { O as errorUnexpected, T as errorSpaceNotFound, f as errorInvalidSpaceId, k as mapMigrationToolsError } from "./cli-errors-DFF1LlfU.mjs";
|
|
3
|
+
import { D as formatStyledHeader, d as setCommandDescriptions, f as setCommandExamples, l as resolveMigrationPaths, p as setCommandSeeAlso, t as addGlobalOptions, v as parseGlobalFlagsOrExit, x as handleResult, y as createTerminalUI } from "./command-helpers-4UNsRRc4.mjs";
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
6
|
+
import { notOk, ok } from "@prisma-next/utils/result";
|
|
7
|
+
import { APP_SPACE_ID, isValidSpaceId } from "@prisma-next/migration-tools/spaces";
|
|
8
|
+
import { bold, cyan, cyanBright, dim, green, greenBright, yellow } from "colorette";
|
|
9
|
+
import { EMPTY_CONTRACT_HASH } from "@prisma-next/migration-tools/constants";
|
|
10
|
+
import { MigrationToolsError } from "@prisma-next/migration-tools/errors";
|
|
11
|
+
import { enumerateMigrationSpaces } from "@prisma-next/migration-tools/enumerate-migration-spaces";
|
|
12
|
+
import { classifyMigrationListGraphTopology } from "@prisma-next/migration-tools/migration-list-graph-topology";
|
|
13
|
+
const MIGRATION_LIST_UNICODE_KIND_GLYPH = {
|
|
14
|
+
forward: "*",
|
|
15
|
+
rollback: "↩",
|
|
16
|
+
self: "⟲"
|
|
17
|
+
};
|
|
18
|
+
const MIGRATION_LIST_ASCII_KIND_GLYPH = {
|
|
19
|
+
forward: "*",
|
|
20
|
+
rollback: "<",
|
|
21
|
+
self: "~"
|
|
22
|
+
};
|
|
23
|
+
function migrationListKindGlyph(glyphMode, edgeKind) {
|
|
24
|
+
return glyphMode === "ascii" ? MIGRATION_LIST_ASCII_KIND_GLYPH[edgeKind] : MIGRATION_LIST_UNICODE_KIND_GLYPH[edgeKind];
|
|
25
|
+
}
|
|
26
|
+
function migrationListForwardArrow(glyphMode) {
|
|
27
|
+
return glyphMode === "ascii" ? "->" : "→";
|
|
28
|
+
}
|
|
29
|
+
function migrationListEmptySource(glyphMode) {
|
|
30
|
+
return glyphMode === "ascii" ? "-" : "∅";
|
|
31
|
+
}
|
|
32
|
+
function abbreviateContractHash(hash) {
|
|
33
|
+
return (hash.startsWith("sha256:") ? hash.slice(7) : hash).slice(0, 7);
|
|
34
|
+
}
|
|
35
|
+
function computeMigrationDirNameWidth(migrations) {
|
|
36
|
+
if (migrations.length === 0) return 0;
|
|
37
|
+
return Math.max(...migrations.map((entry) => entry.dirName.length)) + 2;
|
|
38
|
+
}
|
|
39
|
+
function formatSourceColumn(from, style, emptySource) {
|
|
40
|
+
if (from === null) return style.glyph(emptySource) + " ".repeat(7 - emptySource.length);
|
|
41
|
+
return style.sourceHash(abbreviateContractHash(from));
|
|
42
|
+
}
|
|
43
|
+
function formatDecorations(providedInvariants, refs, style) {
|
|
44
|
+
const blocks = [];
|
|
45
|
+
if (providedInvariants.length > 0) blocks.push(style.invariants(providedInvariants));
|
|
46
|
+
if (refs.length > 0) blocks.push(style.refs(refs));
|
|
47
|
+
if (blocks.length === 0) return "";
|
|
48
|
+
return ` ${blocks.join(" ")}`;
|
|
49
|
+
}
|
|
50
|
+
function formatMigrationDataColumn(migration, options) {
|
|
51
|
+
const { dirNameWidth, edgeKind, style, forwardArrow = "→", emptySource = "∅" } = options;
|
|
52
|
+
const dirNamePadding = " ".repeat(Math.max(0, dirNameWidth - migration.dirName.length));
|
|
53
|
+
const dirName = `${style.dirName(migration.dirName)}${dirNamePadding}`;
|
|
54
|
+
const decorations = formatDecorations(migration.providedInvariants, migration.refs, style);
|
|
55
|
+
if (edgeKind === "self") {
|
|
56
|
+
const contractHash = migration.from ?? migration.to;
|
|
57
|
+
return `${dirName}${style.sourceHash(abbreviateContractHash(contractHash))}${decorations}`;
|
|
58
|
+
}
|
|
59
|
+
return `${dirName}${formatSourceColumn(migration.from, style, emptySource)} ${style.glyph(forwardArrow)} ${style.destHash(abbreviateContractHash(migration.to))}${decorations}`;
|
|
60
|
+
}
|
|
61
|
+
function formatNodeLineDataColumn(contractHash, style) {
|
|
62
|
+
return style.sourceHash(abbreviateContractHash(contractHash));
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/utils/formatters/migration-list-graph-layout.ts
|
|
66
|
+
function canonicalFrom(from) {
|
|
67
|
+
return from ?? EMPTY_CONTRACT_HASH;
|
|
68
|
+
}
|
|
69
|
+
function forwardInDegree(topology, hash) {
|
|
70
|
+
return topology.forwardInDegree.get(hash) ?? 0;
|
|
71
|
+
}
|
|
72
|
+
function forwardOutDegree(topology, hash) {
|
|
73
|
+
return topology.forwardOutDegree.get(hash) ?? 0;
|
|
74
|
+
}
|
|
75
|
+
function buildForwardProducersByTo(entries, kindByMigrationHash) {
|
|
76
|
+
const byTo = /* @__PURE__ */ new Map();
|
|
77
|
+
for (const entry of entries) {
|
|
78
|
+
if (kindByMigrationHash.get(entry.migrationHash) !== "forward") continue;
|
|
79
|
+
const bucket = byTo.get(entry.to);
|
|
80
|
+
if (bucket) bucket.push(entry);
|
|
81
|
+
else byTo.set(entry.to, [entry]);
|
|
82
|
+
}
|
|
83
|
+
return byTo;
|
|
84
|
+
}
|
|
85
|
+
function countForwardProducersTo(forwardProducersByTo, contract) {
|
|
86
|
+
return forwardProducersByTo.get(contract)?.length ?? 0;
|
|
87
|
+
}
|
|
88
|
+
function hasLaterForwardDepartingFrom(entries, startIndex, contract, kindByMigrationHash) {
|
|
89
|
+
for (let index = startIndex + 1; index < entries.length; index++) {
|
|
90
|
+
const later = entries[index];
|
|
91
|
+
if (later === void 0) continue;
|
|
92
|
+
if (kindByMigrationHash.get(later.migrationHash) !== "forward") continue;
|
|
93
|
+
if (canonicalFrom(later.from) === contract) return true;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
function computeMigrationListGraphLayout(entries, topology = classifyMigrationListGraphTopology(entries)) {
|
|
98
|
+
const { kindByMigrationHash } = topology;
|
|
99
|
+
const forwardProducersByTo = buildForwardProducersByTo(entries, kindByMigrationHash);
|
|
100
|
+
const convergencesEmitted = /* @__PURE__ */ new Set();
|
|
101
|
+
const producerLaneByHash = /* @__PURE__ */ new Map();
|
|
102
|
+
const lanes = [];
|
|
103
|
+
const rows = [];
|
|
104
|
+
function emitNodeLine(contractHash) {
|
|
105
|
+
rows.push({
|
|
106
|
+
kind: "nodeLine",
|
|
107
|
+
contractHash,
|
|
108
|
+
laneIndex: 0
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function emitConnector(connectorKind, contractHash, startLane, endLane, branchCount) {
|
|
112
|
+
rows.push({
|
|
113
|
+
kind: "connector",
|
|
114
|
+
connectorKind,
|
|
115
|
+
contractHash,
|
|
116
|
+
startLane,
|
|
117
|
+
endLane,
|
|
118
|
+
branchCount
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function activeLaneIndices() {
|
|
122
|
+
const indices = [];
|
|
123
|
+
for (let index = 0; index < lanes.length; index++) if (lanes[index]?.active) indices.push(index);
|
|
124
|
+
return indices;
|
|
125
|
+
}
|
|
126
|
+
function lanesWanting(contract) {
|
|
127
|
+
const indices = [];
|
|
128
|
+
for (let index = 0; index < lanes.length; index++) {
|
|
129
|
+
const lane = lanes[index];
|
|
130
|
+
if (lane?.active && lane.want === contract) indices.push(index);
|
|
131
|
+
}
|
|
132
|
+
return indices;
|
|
133
|
+
}
|
|
134
|
+
function ensureLane(index) {
|
|
135
|
+
while (lanes.length <= index) lanes.push({
|
|
136
|
+
want: "",
|
|
137
|
+
active: false
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function openLaneAtRight(want) {
|
|
141
|
+
const index = lanes.length;
|
|
142
|
+
lanes.push({
|
|
143
|
+
want,
|
|
144
|
+
active: true
|
|
145
|
+
});
|
|
146
|
+
return index;
|
|
147
|
+
}
|
|
148
|
+
function closeLane(index) {
|
|
149
|
+
ensureLane(index);
|
|
150
|
+
const lane = lanes[index];
|
|
151
|
+
if (lane) lane.active = false;
|
|
152
|
+
}
|
|
153
|
+
function emitJoinAbove(contractHash, laneIndices) {
|
|
154
|
+
if (laneIndices.length < 2) return;
|
|
155
|
+
const startLane = Math.min(...laneIndices);
|
|
156
|
+
emitConnector("joinAbove", contractHash, startLane, Math.max(...laneIndices), laneIndices.length);
|
|
157
|
+
for (const index of laneIndices) if (index !== startLane) closeLane(index);
|
|
158
|
+
}
|
|
159
|
+
function emitConvergencePreamble(contract) {
|
|
160
|
+
if (convergencesEmitted.has(contract)) return;
|
|
161
|
+
if (forwardInDegree(topology, contract) < 2) return;
|
|
162
|
+
const consumersWanting = lanesWanting(contract);
|
|
163
|
+
if (forwardOutDegree(topology, contract) >= 2 && consumersWanting.length >= 2) emitJoinAbove(contract, consumersWanting);
|
|
164
|
+
emitNodeLine(contract);
|
|
165
|
+
const producers = forwardProducersByTo.get(contract) ?? [];
|
|
166
|
+
if (producers.length >= 2) emitConnector("fanBelow", contract, 0, producers.length - 1, producers.length);
|
|
167
|
+
for (const [producerIndex, producer] of producers.entries()) {
|
|
168
|
+
ensureLane(producerIndex);
|
|
169
|
+
lanes[producerIndex] = {
|
|
170
|
+
want: canonicalFrom(producer.from),
|
|
171
|
+
active: true
|
|
172
|
+
};
|
|
173
|
+
producerLaneByHash.set(producer.migrationHash, producerIndex);
|
|
174
|
+
}
|
|
175
|
+
convergencesEmitted.add(contract);
|
|
176
|
+
}
|
|
177
|
+
function placeWoven(entry, edgeKind, laneIndex) {
|
|
178
|
+
const passThroughLanes = activeLaneIndices().filter((index) => index !== laneIndex);
|
|
179
|
+
rows.push({
|
|
180
|
+
kind: "migration",
|
|
181
|
+
entry,
|
|
182
|
+
edgeKind,
|
|
183
|
+
laneIndex,
|
|
184
|
+
passThroughLanes,
|
|
185
|
+
woven: true
|
|
186
|
+
});
|
|
187
|
+
ensureLane(laneIndex);
|
|
188
|
+
lanes[laneIndex] = {
|
|
189
|
+
want: canonicalFrom(entry.from),
|
|
190
|
+
active: true
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function placeUnwoven(entry, edgeKind) {
|
|
194
|
+
const passThroughLanes = activeLaneIndices();
|
|
195
|
+
const laneIndex = passThroughLanes.length === 0 ? 0 : Math.max(...passThroughLanes) + 1;
|
|
196
|
+
rows.push({
|
|
197
|
+
kind: "migration",
|
|
198
|
+
entry,
|
|
199
|
+
edgeKind,
|
|
200
|
+
laneIndex,
|
|
201
|
+
passThroughLanes,
|
|
202
|
+
woven: false
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
for (let entryIndex = 0; entryIndex < entries.length; entryIndex++) {
|
|
206
|
+
const entry = entries[entryIndex];
|
|
207
|
+
const edgeKind = kindByMigrationHash.get(entry.migrationHash) ?? "forward";
|
|
208
|
+
const to = entry.to;
|
|
209
|
+
if (edgeKind !== "forward") {
|
|
210
|
+
placeUnwoven(entry, edgeKind);
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (forwardInDegree(topology, to) >= 2 && !convergencesEmitted.has(to)) emitConvergencePreamble(to);
|
|
214
|
+
const presetLane = producerLaneByHash.get(entry.migrationHash);
|
|
215
|
+
const wantingTo = lanesWanting(to);
|
|
216
|
+
if (wantingTo.length >= 2 && countForwardProducersTo(forwardProducersByTo, to) === 1) emitJoinAbove(to, wantingTo);
|
|
217
|
+
if (presetLane !== void 0) {
|
|
218
|
+
placeWoven(entry, edgeKind, presetLane);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const firstWanting = wantingTo[0];
|
|
222
|
+
if (firstWanting !== void 0) {
|
|
223
|
+
placeWoven(entry, edgeKind, firstWanting);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (hasLaterForwardDepartingFrom(entries, entryIndex, to, kindByMigrationHash)) {
|
|
227
|
+
placeUnwoven(entry, edgeKind);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
placeWoven(entry, edgeKind, openLaneAtRight(canonicalFrom(entry.from)));
|
|
231
|
+
}
|
|
232
|
+
return { rows };
|
|
233
|
+
}
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region src/utils/formatters/migration-list-graph-render.ts
|
|
236
|
+
const UNICODE_PALETTE = {
|
|
237
|
+
lane: "│",
|
|
238
|
+
node: "o",
|
|
239
|
+
forwardArrow: migrationListForwardArrow("unicode"),
|
|
240
|
+
emptySource: migrationListEmptySource("unicode"),
|
|
241
|
+
kind: MIGRATION_LIST_UNICODE_KIND_GLYPH,
|
|
242
|
+
fanBelow: (branchCount) => branchCount === 2 ? "├─┐" : "├─┬─┐",
|
|
243
|
+
joinAbove: (branchCount) => branchCount === 2 ? "├─┘" : "└─┴─┘"
|
|
244
|
+
};
|
|
245
|
+
const ASCII_PALETTE = {
|
|
246
|
+
lane: "|",
|
|
247
|
+
node: "o",
|
|
248
|
+
forwardArrow: migrationListForwardArrow("ascii"),
|
|
249
|
+
emptySource: migrationListEmptySource("ascii"),
|
|
250
|
+
kind: MIGRATION_LIST_ASCII_KIND_GLYPH,
|
|
251
|
+
fanBelow: (branchCount) => branchCount === 2 ? "+-\\" : "+-|-\\",
|
|
252
|
+
joinAbove: (branchCount) => branchCount === 2 ? "+-/" : "/-+-/"
|
|
253
|
+
};
|
|
254
|
+
function paletteFor(mode) {
|
|
255
|
+
return mode === "ascii" ? ASCII_PALETTE : UNICODE_PALETTE;
|
|
256
|
+
}
|
|
257
|
+
function migrationEntries(layout) {
|
|
258
|
+
const entries = [];
|
|
259
|
+
for (const row of layout.rows) if (row.kind === "migration") entries.push(row.entry);
|
|
260
|
+
return entries;
|
|
261
|
+
}
|
|
262
|
+
function layoutMaxLaneIndex(layout) {
|
|
263
|
+
let max = 0;
|
|
264
|
+
for (const row of layout.rows) if (row.kind === "migration") max = Math.max(max, row.laneIndex, ...row.passThroughLanes);
|
|
265
|
+
else if (row.kind === "connector") max = Math.max(max, row.endLane);
|
|
266
|
+
else max = Math.max(max, row.laneIndex);
|
|
267
|
+
return max;
|
|
268
|
+
}
|
|
269
|
+
function laneCell(glyph) {
|
|
270
|
+
return `${glyph} `;
|
|
271
|
+
}
|
|
272
|
+
function emptyLaneCell() {
|
|
273
|
+
return " ";
|
|
274
|
+
}
|
|
275
|
+
function renderMigrationGutter(row, maxLane, palette, style) {
|
|
276
|
+
const cells = [];
|
|
277
|
+
for (let lane = 0; lane <= maxLane; lane++) if (lane === row.laneIndex) cells.push(laneCell(style.kind(palette.kind[row.edgeKind])));
|
|
278
|
+
else if (row.passThroughLanes.includes(lane)) cells.push(laneCell(style.lane(palette.lane)));
|
|
279
|
+
else cells.push(emptyLaneCell());
|
|
280
|
+
return cells.join("");
|
|
281
|
+
}
|
|
282
|
+
function renderNodeLineGutter(row, openLanes, maxLane, palette, style) {
|
|
283
|
+
const cells = [];
|
|
284
|
+
for (let lane = 0; lane <= maxLane; lane++) if (lane === row.laneIndex) cells.push(laneCell(palette.node));
|
|
285
|
+
else if (openLanes.has(lane)) cells.push(laneCell(style.lane(palette.lane)));
|
|
286
|
+
else cells.push(emptyLaneCell());
|
|
287
|
+
return cells.join("");
|
|
288
|
+
}
|
|
289
|
+
function renderConnectorGutter(row, openLanes, maxLane, palette, style) {
|
|
290
|
+
const spanWidth = (row.endLane - row.startLane + 1) * 2;
|
|
291
|
+
let spanGlyph = (row.connectorKind === "fanBelow" ? palette.fanBelow(row.branchCount) : palette.joinAbove(row.branchCount)).padEnd(spanWidth, " ").slice(0, spanWidth);
|
|
292
|
+
if (![...openLanes].some((lane) => lane < row.startLane || lane > row.endLane) && spanGlyph.endsWith(" ")) spanGlyph = spanGlyph.slice(0, -1);
|
|
293
|
+
let gutter = "";
|
|
294
|
+
for (let lane = 0; lane < row.startLane; lane++) gutter += openLanes.has(lane) ? laneCell(style.lane(palette.lane)) : emptyLaneCell();
|
|
295
|
+
gutter += style.lane(spanGlyph);
|
|
296
|
+
for (let lane = row.endLane + 1; lane <= maxLane; lane++) gutter += openLanes.has(lane) ? laneCell(style.lane(palette.lane)) : emptyLaneCell();
|
|
297
|
+
return gutter;
|
|
298
|
+
}
|
|
299
|
+
function advanceOpenLanes(row, openLanes) {
|
|
300
|
+
if (row.kind === "migration") return new Set([row.laneIndex, ...row.passThroughLanes]);
|
|
301
|
+
if (row.kind === "connector") {
|
|
302
|
+
if (row.connectorKind === "fanBelow") {
|
|
303
|
+
const next = new Set(openLanes);
|
|
304
|
+
for (let lane = row.startLane; lane <= row.endLane; lane++) next.add(lane);
|
|
305
|
+
return next;
|
|
306
|
+
}
|
|
307
|
+
const next = new Set(openLanes);
|
|
308
|
+
for (let lane = row.startLane + 1; lane <= row.endLane; lane++) next.delete(lane);
|
|
309
|
+
return next;
|
|
310
|
+
}
|
|
311
|
+
return openLanes;
|
|
312
|
+
}
|
|
313
|
+
function renderMigrationListGraphWithStyle(layout, style, glyphMode) {
|
|
314
|
+
const palette = paletteFor(glyphMode);
|
|
315
|
+
const migrations = migrationEntries(layout);
|
|
316
|
+
const layoutMaxLane = layoutMaxLaneIndex(layout);
|
|
317
|
+
const dirNameWidth = computeMigrationDirNameWidth(migrations);
|
|
318
|
+
const gutterMaxLane = layoutMaxLane;
|
|
319
|
+
const blockDataStart = (layoutMaxLane + 1) * 2;
|
|
320
|
+
const gutterVisibleWidth = (gutterMaxLane + 1) * 2;
|
|
321
|
+
const lines = [];
|
|
322
|
+
let openLanes = /* @__PURE__ */ new Set();
|
|
323
|
+
function padToDataColumn(gutter, dataStart) {
|
|
324
|
+
return gutter + " ".repeat(Math.max(0, dataStart - gutterVisibleWidth));
|
|
325
|
+
}
|
|
326
|
+
for (const row of layout.rows) {
|
|
327
|
+
if (row.kind === "migration") {
|
|
328
|
+
const gutter = renderMigrationGutter(row, gutterMaxLane, palette, style);
|
|
329
|
+
const data = formatMigrationDataColumn(row.entry, {
|
|
330
|
+
dirNameWidth,
|
|
331
|
+
edgeKind: row.edgeKind,
|
|
332
|
+
style,
|
|
333
|
+
forwardArrow: palette.forwardArrow,
|
|
334
|
+
emptySource: palette.emptySource
|
|
335
|
+
});
|
|
336
|
+
lines.push(`${padToDataColumn(gutter, blockDataStart)}${data}`);
|
|
337
|
+
} else if (row.kind === "nodeLine") {
|
|
338
|
+
const gutter = renderNodeLineGutter(row, openLanes, gutterMaxLane, palette, style);
|
|
339
|
+
const data = formatNodeLineDataColumn(row.contractHash, style);
|
|
340
|
+
lines.push(`${padToDataColumn(gutter, blockDataStart)}${data}`);
|
|
341
|
+
} else lines.push(renderConnectorGutter(row, openLanes, gutterMaxLane, palette, style));
|
|
342
|
+
openLanes = advanceOpenLanes(row, openLanes);
|
|
343
|
+
}
|
|
344
|
+
return lines.map((line) => line.trimEnd()).join("\n");
|
|
345
|
+
}
|
|
346
|
+
function formatGraphEmptyStateLine(spaceId, style) {
|
|
347
|
+
return style.emptyState(`There are no migrations in migrations/${spaceId}/ yet`);
|
|
348
|
+
}
|
|
349
|
+
function renderGraphSpaceBlock(spaceId, migrations, multiSpace, style, glyphMode, topology) {
|
|
350
|
+
if (migrations.length === 0) {
|
|
351
|
+
const emptyLine = formatGraphEmptyStateLine(spaceId, style);
|
|
352
|
+
if (!multiSpace) return [emptyLine];
|
|
353
|
+
return [style.spaceHeading(`${spaceId}:`), ` ${emptyLine}`];
|
|
354
|
+
}
|
|
355
|
+
const rows = renderMigrationListGraphWithStyle(computeMigrationListGraphLayout(migrations, topology), style, glyphMode).split("\n");
|
|
356
|
+
if (!multiSpace) return rows;
|
|
357
|
+
return [style.spaceHeading(`${spaceId}:`), ...rows.map((row) => ` ${row}`)];
|
|
358
|
+
}
|
|
359
|
+
function renderMigrationListGraphResult(result, style, glyphMode, topologyBySpaceId) {
|
|
360
|
+
const multiSpace = result.spaces.length > 1;
|
|
361
|
+
const lines = [];
|
|
362
|
+
for (let index = 0; index < result.spaces.length; index++) {
|
|
363
|
+
const space = result.spaces[index];
|
|
364
|
+
if (index > 0) lines.push("");
|
|
365
|
+
const topology = topologyBySpaceId.get(space.spaceId);
|
|
366
|
+
if (topology === void 0) throw new Error(`missing topology for space ${space.spaceId}`);
|
|
367
|
+
lines.push(...renderGraphSpaceBlock(space.spaceId, space.migrations, multiSpace, style, glyphMode, topology));
|
|
368
|
+
}
|
|
369
|
+
if (result.spaces.reduce((count, space) => count + space.migrations.length, 0) > 0) {
|
|
370
|
+
lines.push("");
|
|
371
|
+
lines.push(style.summary(result.summary));
|
|
372
|
+
}
|
|
373
|
+
return lines.join("\n");
|
|
374
|
+
}
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/utils/formatters/migration-list-render.ts
|
|
377
|
+
const IDENTITY_MIGRATION_LIST_STYLER = {
|
|
378
|
+
kind: (text) => text,
|
|
379
|
+
dirName: (text) => text,
|
|
380
|
+
sourceHash: (text) => text,
|
|
381
|
+
destHash: (text) => text,
|
|
382
|
+
glyph: (text) => text,
|
|
383
|
+
lane: (text) => text,
|
|
384
|
+
invariants: (ids) => `{${ids.join(", ")}}`,
|
|
385
|
+
refs: (names) => `(${names.join(", ")})`,
|
|
386
|
+
spaceHeading: (text) => text,
|
|
387
|
+
summary: (text) => text,
|
|
388
|
+
emptyState: (text) => text
|
|
389
|
+
};
|
|
390
|
+
function resolveEdgeKind(migrationHash, kindByMigrationHash) {
|
|
391
|
+
return kindByMigrationHash.get(migrationHash) ?? "forward";
|
|
392
|
+
}
|
|
393
|
+
function formatMigrationRow(migration, dirNameWidth, edgeKind, glyphMode, style) {
|
|
394
|
+
return `${`${style.kind(migrationListKindGlyph(glyphMode, edgeKind))} `}${formatMigrationDataColumn(migration, {
|
|
395
|
+
dirNameWidth,
|
|
396
|
+
edgeKind,
|
|
397
|
+
style,
|
|
398
|
+
forwardArrow: migrationListForwardArrow(glyphMode),
|
|
399
|
+
emptySource: migrationListEmptySource(glyphMode)
|
|
400
|
+
})}`;
|
|
401
|
+
}
|
|
402
|
+
function formatEmptyStateLine(spaceId, style) {
|
|
403
|
+
return style.emptyState(`There are no migrations in migrations/${spaceId}/ yet`);
|
|
404
|
+
}
|
|
405
|
+
function renderSpaceBlock(spaceId, migrations, multiSpace, glyphMode, kindByMigrationHash, style) {
|
|
406
|
+
if (migrations.length === 0) {
|
|
407
|
+
const emptyLine = formatEmptyStateLine(spaceId, style);
|
|
408
|
+
if (!multiSpace) return [emptyLine];
|
|
409
|
+
return [style.spaceHeading(`${spaceId}:`), ` ${emptyLine}`];
|
|
410
|
+
}
|
|
411
|
+
const dirNameWidth = computeMigrationDirNameWidth(migrations);
|
|
412
|
+
const rows = migrations.map((entry) => formatMigrationRow(entry, dirNameWidth, resolveEdgeKind(entry.migrationHash, kindByMigrationHash), glyphMode, style));
|
|
413
|
+
if (!multiSpace) return rows;
|
|
414
|
+
return [style.spaceHeading(`${spaceId}:`), ...rows.map((row) => ` ${row}`)];
|
|
415
|
+
}
|
|
416
|
+
function buildMigrationListTopologyBySpace(result) {
|
|
417
|
+
const topologyBySpaceId = /* @__PURE__ */ new Map();
|
|
418
|
+
for (const space of result.spaces) topologyBySpaceId.set(space.spaceId, classifyMigrationListGraphTopology(space.migrations));
|
|
419
|
+
return topologyBySpaceId;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Compose the styled `migration list` output. The renderer is
|
|
423
|
+
* presentation-neutral — every token passes through `style` before
|
|
424
|
+
* landing in the output, so the same composition serves the pure-text
|
|
425
|
+
* path ({@link renderMigrationList} via
|
|
426
|
+
* {@link IDENTITY_MIGRATION_LIST_STYLER}) and the ANSI-styled CLI path
|
|
427
|
+
* (via the ANSI styler the CLI shell wires up).
|
|
428
|
+
*/
|
|
429
|
+
function renderMigrationListWithStyle(result, style, glyphMode = "unicode", topologyBySpaceId = buildMigrationListTopologyBySpace(result)) {
|
|
430
|
+
const multiSpace = result.spaces.length > 1;
|
|
431
|
+
const lines = [];
|
|
432
|
+
for (let index = 0; index < result.spaces.length; index++) {
|
|
433
|
+
const space = result.spaces[index];
|
|
434
|
+
if (index > 0) lines.push("");
|
|
435
|
+
const kindByMigrationHash = topologyBySpaceId.get(space.spaceId)?.kindByMigrationHash ?? classifyMigrationListGraphTopology(space.migrations).kindByMigrationHash;
|
|
436
|
+
lines.push(...renderSpaceBlock(space.spaceId, space.migrations, multiSpace, glyphMode, kindByMigrationHash, style));
|
|
437
|
+
}
|
|
438
|
+
if (result.spaces.reduce((count, space) => count + space.migrations.length, 0) > 0) {
|
|
439
|
+
lines.push("");
|
|
440
|
+
lines.push(style.summary(result.summary));
|
|
441
|
+
}
|
|
442
|
+
return lines.join("\n");
|
|
443
|
+
}
|
|
444
|
+
//#endregion
|
|
445
|
+
//#region src/utils/formatters/migration-list-styler.ts
|
|
446
|
+
/**
|
|
447
|
+
* The reserved ref name for the live-database marker. Treated as a
|
|
448
|
+
* structurally distinct token from user-named refs so the styler can
|
|
449
|
+
* make it visually pop in `(refs)` decorations.
|
|
450
|
+
*/
|
|
451
|
+
const DB_REF_NAME = "db";
|
|
452
|
+
function styleRefName(name) {
|
|
453
|
+
return name === DB_REF_NAME ? bold(greenBright(name)) : green(name);
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Build a {@link MigrationListStyler} that decorates `migration list`
|
|
457
|
+
* tokens with ANSI SGR codes. When `useColor` is `false` (non-TTY,
|
|
458
|
+
* `--no-color`, `NO_COLOR=1`, piped output) the function returns the
|
|
459
|
+
* shared identity styler so callers get plain text with zero ANSI
|
|
460
|
+
* bytes — pipe-friendly by construction.
|
|
461
|
+
*
|
|
462
|
+
* Palette:
|
|
463
|
+
*
|
|
464
|
+
* - `dirName`: bold
|
|
465
|
+
* - `sourceHash`: dim cyan
|
|
466
|
+
* - `destHash`: bright cyan
|
|
467
|
+
* - `kind` (`*` / `↩` / `⟲`): bright — the signal; lanes and arrows dim
|
|
468
|
+
* - `glyph` (`→` / `⟲` / `∅`): dim
|
|
469
|
+
* - `lane` (graph gutter lines `│` and fan/join connectors `├─┐` / `├─┘`): dim
|
|
470
|
+
* - `invariants` (`{...}`): yellow
|
|
471
|
+
* - `refs` (`(...)`): green; the live-DB `db` marker inside is green-bold
|
|
472
|
+
* - `spaceHeading` (`<spaceId>:`): bold
|
|
473
|
+
* - `summary`: dim
|
|
474
|
+
* - `emptyState`: dim
|
|
475
|
+
*/
|
|
476
|
+
function createAnsiMigrationListStyler(opts) {
|
|
477
|
+
if (!opts.useColor) return IDENTITY_MIGRATION_LIST_STYLER;
|
|
478
|
+
return {
|
|
479
|
+
kind: (text) => text,
|
|
480
|
+
dirName: (text) => bold(text),
|
|
481
|
+
sourceHash: (text) => dim(cyan(text)),
|
|
482
|
+
destHash: (text) => cyanBright(text),
|
|
483
|
+
glyph: (text) => dim(text),
|
|
484
|
+
lane: (text) => dim(text),
|
|
485
|
+
invariants: (ids) => yellow(`{${ids.join(", ")}}`),
|
|
486
|
+
refs: (names) => {
|
|
487
|
+
const open = green("(");
|
|
488
|
+
const close = green(")");
|
|
489
|
+
const separator = green(", ");
|
|
490
|
+
return open + names.map(styleRefName).join(separator) + close;
|
|
491
|
+
},
|
|
492
|
+
spaceHeading: (text) => bold(text),
|
|
493
|
+
summary: (text) => dim(text),
|
|
494
|
+
emptyState: (text) => dim(text)
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
//#endregion
|
|
498
|
+
//#region src/commands/migration-list.ts
|
|
499
|
+
function renderMigrationListHumanOutput(result, options) {
|
|
500
|
+
const styler = createAnsiMigrationListStyler({ useColor: options.useColor });
|
|
501
|
+
const topologyBySpaceId = buildMigrationListTopologyBySpace(result);
|
|
502
|
+
if (options.graph) return renderMigrationListGraphResult(result, styler, options.glyphMode, topologyBySpaceId);
|
|
503
|
+
return renderMigrationListWithStyle(result, styler, options.glyphMode, topologyBySpaceId);
|
|
504
|
+
}
|
|
505
|
+
function computeSummary(spaces) {
|
|
506
|
+
const totalMigrations = spaces.reduce((count, space) => count + space.migrations.length, 0);
|
|
507
|
+
if (spaces.length <= 1) return `${totalMigrations} migration(s) on disk`;
|
|
508
|
+
return `${totalMigrations} migration(s) across ${spaces.length} contract space(s)`;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* The unit-testable core of `migration list`. Given an absolute
|
|
512
|
+
* `migrationsDir` and an optional `spaceFilter`, enumerates every
|
|
513
|
+
* on-disk migration (via {@link enumerateMigrationSpaces}), narrows to
|
|
514
|
+
* the requested space if any, and assembles a {@link MigrationListResult}
|
|
515
|
+
* ready for the renderer or JSON serializer.
|
|
516
|
+
*
|
|
517
|
+
* The enumerator is the single source of truth for "what is a contract
|
|
518
|
+
* space": existence, the `--space` candidate-suggestion list, and
|
|
519
|
+
* scoping are all derived from one {@link enumerateMigrationSpaces}
|
|
520
|
+
* traversal. This means the reserved-name exclusion the enumerator
|
|
521
|
+
* applies (e.g. the per-space `refs/` subdirectory) is honoured here for
|
|
522
|
+
* free — a `--space refs` request resolves to `SPACE_NOT_FOUND`, not a
|
|
523
|
+
* synthesized empty-state.
|
|
524
|
+
*
|
|
525
|
+
* Distinct empty-state paths:
|
|
526
|
+
*
|
|
527
|
+
* - `migrations/` missing or contains no valid space directories →
|
|
528
|
+
* synthesizes `[{ spaceId: APP_SPACE_ID, migrations: [] }]` so the
|
|
529
|
+
* renderer's empty-state path can name a directory (spec § Empty-state +
|
|
530
|
+
* the `migrations/` missing edge case).
|
|
531
|
+
* - `--space <id>` on an existing-but-empty space dir → the enumerator
|
|
532
|
+
* surfaces `{ spaceId, migrations: [] }`; `<id>` is in the set, so it
|
|
533
|
+
* scopes to that entry and renders the empty-state the same way.
|
|
534
|
+
* - `--space <id>` on a non-existent (or reserved) space → structured
|
|
535
|
+
* `MIGRATION.SPACE_NOT_FOUND` error (NOT empty-state).
|
|
536
|
+
*
|
|
537
|
+
* Errors caught here:
|
|
538
|
+
*
|
|
539
|
+
* - {@link MigrationToolsError} from the enumerator → mapped through
|
|
540
|
+
* {@link mapMigrationToolsError} so callers see the catalogue code.
|
|
541
|
+
* - Anything else (filesystem etc.) → wrapped via {@link errorUnexpected}.
|
|
542
|
+
*/
|
|
543
|
+
async function runMigrationList(inputs) {
|
|
544
|
+
const { migrationsDir, spaceFilter } = inputs;
|
|
545
|
+
if (spaceFilter !== void 0 && !isValidSpaceId(spaceFilter)) return notOk(errorInvalidSpaceId(spaceFilter));
|
|
546
|
+
let spaces;
|
|
547
|
+
try {
|
|
548
|
+
spaces = await enumerateMigrationSpaces({ projectMigrationsDir: migrationsDir });
|
|
549
|
+
} catch (error) {
|
|
550
|
+
if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));
|
|
551
|
+
return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to enumerate migrations: ${error instanceof Error ? error.message : String(error)}` }));
|
|
552
|
+
}
|
|
553
|
+
if (spaceFilter !== void 0 && !spaces.some((s) => s.spaceId === spaceFilter)) return notOk(errorSpaceNotFound(spaceFilter, spaces.map((s) => s.spaceId).sort()));
|
|
554
|
+
const scopedSpaces = spaceFilter !== void 0 ? spaces.filter((s) => s.spaceId === spaceFilter) : spaces;
|
|
555
|
+
const resultSpaces = scopedSpaces.length === 0 ? [{
|
|
556
|
+
spaceId: APP_SPACE_ID,
|
|
557
|
+
migrations: []
|
|
558
|
+
}] : scopedSpaces;
|
|
559
|
+
return ok({
|
|
560
|
+
ok: true,
|
|
561
|
+
spaces: resultSpaces,
|
|
562
|
+
summary: computeSummary(resultSpaces)
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* CLI shell: loads config, resolves paths, prints the styled header on
|
|
567
|
+
* stderr (interactive mode only), and delegates to {@link runMigrationList}.
|
|
568
|
+
* Kept intentionally thin so the unit-testable surface lives in the core.
|
|
569
|
+
*/
|
|
570
|
+
async function executeMigrationListCommand(options, flags, ui) {
|
|
571
|
+
const config = await loadConfig(options.config);
|
|
572
|
+
const { configPath, migrationsDir, migrationsRelative } = resolveMigrationPaths(options.config, config);
|
|
573
|
+
if (!flags.json && !flags.quiet) {
|
|
574
|
+
const header = formatStyledHeader({
|
|
575
|
+
command: "migration list",
|
|
576
|
+
description: "List on-disk migrations, latest first, per contract space",
|
|
577
|
+
details: [
|
|
578
|
+
{
|
|
579
|
+
label: "config",
|
|
580
|
+
value: configPath
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
label: "migrations",
|
|
584
|
+
value: migrationsRelative
|
|
585
|
+
},
|
|
586
|
+
...options.space !== void 0 ? [{
|
|
587
|
+
label: "space",
|
|
588
|
+
value: options.space
|
|
589
|
+
}] : []
|
|
590
|
+
],
|
|
591
|
+
flags
|
|
592
|
+
});
|
|
593
|
+
ui.stderr(header);
|
|
594
|
+
}
|
|
595
|
+
return runMigrationList({
|
|
596
|
+
migrationsDir,
|
|
597
|
+
...ifDefined("spaceFilter", options.space)
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
function createMigrationListCommand() {
|
|
601
|
+
const command = new Command("list");
|
|
602
|
+
setCommandDescriptions(command, "List on-disk migrations, latest first, per contract space", "Enumerates every on-disk migration under migrations/<space>/ for every\ncontract space found on disk, latest first. Offline — does not consult\nthe database. Each row leads with a kind glyph (* forward, ↩ rollback,\n⟲ self), then dirName, then source → destination contract hashes\n(7-char git-style). Self-edges show a single hash. Invariants render as\n{...}; refs on the destination as (production, db). Pass --space <id>\nto narrow to one contract space. --graph draws the forward spine with\nlane gutters; --ascii forces ASCII glyphs (orthogonal to --no-color).");
|
|
603
|
+
setCommandExamples(command, [
|
|
604
|
+
"prisma-next migration list",
|
|
605
|
+
"prisma-next migration list --graph",
|
|
606
|
+
"prisma-next migration list --space app",
|
|
607
|
+
"prisma-next migration list --graph --ascii",
|
|
608
|
+
"prisma-next migration list --json"
|
|
609
|
+
]);
|
|
610
|
+
setCommandSeeAlso(command, [
|
|
611
|
+
{
|
|
612
|
+
verb: "migration status",
|
|
613
|
+
oneLiner: "Show migration path and pending status"
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
verb: "migration log",
|
|
617
|
+
oneLiner: "Show executed migration history"
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
verb: "migration graph",
|
|
621
|
+
oneLiner: "Show the migration graph topology"
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
verb: "migration show",
|
|
625
|
+
oneLiner: "Display migration package contents"
|
|
626
|
+
}
|
|
627
|
+
]);
|
|
628
|
+
addGlobalOptions(command).option("--config <path>", "Path to prisma-next.config.ts").option("--space <id>", "Narrow output to a single contract space").option("--graph", "Draw migration relationships as an annotated tree").option("--ascii", "Use ASCII glyphs for --graph (pipe-friendly)").action(async (options) => {
|
|
629
|
+
const flags = parseGlobalFlagsOrExit(options);
|
|
630
|
+
const ui = createTerminalUI(flags);
|
|
631
|
+
const exitCode = handleResult(await executeMigrationListCommand(options, flags, ui), flags, ui, (listResult) => {
|
|
632
|
+
if (flags.json) ui.output(JSON.stringify(listResult, null, 2));
|
|
633
|
+
else if (!flags.quiet) ui.output(renderMigrationListHumanOutput(listResult, {
|
|
634
|
+
graph: options.graph === true,
|
|
635
|
+
glyphMode: ui.resolveGlyphMode(options.ascii === true),
|
|
636
|
+
useColor: ui.useColor
|
|
637
|
+
}));
|
|
638
|
+
});
|
|
639
|
+
process.exit(exitCode);
|
|
640
|
+
});
|
|
641
|
+
return command;
|
|
642
|
+
}
|
|
643
|
+
//#endregion
|
|
644
|
+
export { renderMigrationListHumanOutput as n, runMigrationList as r, createMigrationListCommand as t };
|
|
645
|
+
|
|
646
|
+
//# sourceMappingURL=migration-list-B2-iQ5Jd.mjs.map
|