prisma-next 0.8.0 → 0.9.0-dev.1

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.
Files changed (126) hide show
  1. package/README.md +1 -1
  2. package/dist/{cli-errors-D3_sMh2K.mjs → cli-errors-CF60g2cG.mjs} +40 -2
  3. package/dist/cli-errors-CF60g2cG.mjs.map +1 -0
  4. package/dist/cli.mjs +67 -19
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/{client-BCnP7cHo.mjs → client-Brv4qlfB.mjs} +28 -30
  7. package/dist/client-Brv4qlfB.mjs.map +1 -0
  8. package/dist/{command-helpers-BeZHkxV8.mjs → command-helpers-D3vL5yi8.mjs} +29 -6
  9. package/dist/command-helpers-D3vL5yi8.mjs.map +1 -0
  10. package/dist/commands/contract-emit.mjs +1 -1
  11. package/dist/commands/contract-infer.mjs +1 -1
  12. package/dist/commands/db-init.mjs +7 -7
  13. package/dist/commands/db-schema.mjs +5 -5
  14. package/dist/commands/db-sign.d.mts.map +1 -1
  15. package/dist/commands/db-sign.mjs +67 -25
  16. package/dist/commands/db-sign.mjs.map +1 -1
  17. package/dist/commands/db-update.d.mts.map +1 -1
  18. package/dist/commands/db-update.mjs +37 -9
  19. package/dist/commands/db-update.mjs.map +1 -1
  20. package/dist/commands/db-verify.d.mts.map +1 -1
  21. package/dist/commands/db-verify.mjs +1 -1
  22. package/dist/commands/migrate.d.mts +28 -0
  23. package/dist/commands/migrate.d.mts.map +1 -0
  24. package/dist/commands/{migration-apply.mjs → migrate.mjs} +65 -39
  25. package/dist/commands/migrate.mjs.map +1 -0
  26. package/dist/commands/migration-check.d.mts +18 -0
  27. package/dist/commands/migration-check.d.mts.map +1 -0
  28. package/dist/commands/migration-check.mjs +284 -0
  29. package/dist/commands/migration-check.mjs.map +1 -0
  30. package/dist/commands/migration-graph.d.mts +16 -0
  31. package/dist/commands/migration-graph.d.mts.map +1 -0
  32. package/dist/commands/migration-graph.mjs +141 -0
  33. package/dist/commands/migration-graph.mjs.map +1 -0
  34. package/dist/commands/migration-list.d.mts +20 -0
  35. package/dist/commands/migration-list.d.mts.map +1 -0
  36. package/dist/commands/migration-list.mjs +107 -0
  37. package/dist/commands/migration-list.mjs.map +1 -0
  38. package/dist/commands/migration-log.d.mts +21 -0
  39. package/dist/commands/migration-log.d.mts.map +1 -0
  40. package/dist/commands/migration-log.mjs +146 -0
  41. package/dist/commands/migration-log.mjs.map +1 -0
  42. package/dist/commands/migration-new.d.mts.map +1 -1
  43. package/dist/commands/migration-new.mjs +30 -29
  44. package/dist/commands/migration-new.mjs.map +1 -1
  45. package/dist/commands/migration-plan.d.mts +2 -2
  46. package/dist/commands/migration-plan.d.mts.map +1 -1
  47. package/dist/commands/migration-plan.mjs +1 -1
  48. package/dist/commands/migration-show.d.mts +1 -1
  49. package/dist/commands/migration-show.d.mts.map +1 -1
  50. package/dist/commands/migration-show.mjs +90 -52
  51. package/dist/commands/migration-show.mjs.map +1 -1
  52. package/dist/commands/migration-status.d.mts +5 -17
  53. package/dist/commands/migration-status.d.mts.map +1 -1
  54. package/dist/commands/migration-status.mjs +732 -1
  55. package/dist/commands/migration-status.mjs.map +1 -0
  56. package/dist/commands/ref.d.mts +34 -0
  57. package/dist/commands/ref.d.mts.map +1 -0
  58. package/dist/commands/{migration-ref.mjs → ref.mjs} +28 -57
  59. package/dist/commands/ref.mjs.map +1 -0
  60. package/dist/{contract-emit-9DBda5Ou.mjs → contract-emit-C3STUIBg.mjs} +6 -6
  61. package/dist/{contract-emit-9DBda5Ou.mjs.map → contract-emit-C3STUIBg.mjs.map} +1 -1
  62. package/dist/{contract-emit-B77TsJqf.mjs → contract-emit-iynA3BCA.mjs} +9 -5
  63. package/dist/contract-emit-iynA3BCA.mjs.map +1 -0
  64. package/dist/{contract-infer-ByxhPjpW.mjs → contract-infer-Cnj8G1E2.mjs} +5 -5
  65. package/dist/{contract-infer-ByxhPjpW.mjs.map → contract-infer-Cnj8G1E2.mjs.map} +1 -1
  66. package/dist/{contract-space-aggregate-loader-BrwKK6Q6.mjs → contract-space-aggregate-loader-pAc8CDfY.mjs} +4 -4
  67. package/dist/{contract-space-aggregate-loader-BrwKK6Q6.mjs.map → contract-space-aggregate-loader-pAc8CDfY.mjs.map} +1 -1
  68. package/dist/{db-verify-Czm5T-J4.mjs → db-verify-D7cyH_zz.mjs} +12 -9
  69. package/dist/db-verify-D7cyH_zz.mjs.map +1 -0
  70. package/dist/errors-Cw6kyTyV.mjs +56 -0
  71. package/dist/errors-Cw6kyTyV.mjs.map +1 -0
  72. package/dist/exports/control-api.d.mts +1 -1
  73. package/dist/exports/control-api.d.mts.map +1 -1
  74. package/dist/exports/control-api.mjs +2 -2
  75. package/dist/exports/index.mjs +1 -1
  76. package/dist/exports/index.mjs.map +1 -1
  77. package/dist/exports/init-output.mjs +1 -1
  78. package/dist/{framework-components-ChqVUxR-.mjs → framework-components-xFLFpZUO.mjs} +2 -2
  79. package/dist/{framework-components-ChqVUxR-.mjs.map → framework-components-xFLFpZUO.mjs.map} +1 -1
  80. package/dist/{global-flags-Icqpxk23.d.mts → global-flags-DGmw6Kqg.d.mts} +1 -1
  81. package/dist/{global-flags-Icqpxk23.d.mts.map → global-flags-DGmw6Kqg.d.mts.map} +1 -1
  82. package/dist/{migration-status-By9G5p2H.mjs → graph-render-eJDcLWny.mjs} +3 -692
  83. package/dist/graph-render-eJDcLWny.mjs.map +1 -0
  84. package/dist/{init-B-k3a1Qw.mjs → init-Bqg5JWg7.mjs} +133 -61
  85. package/dist/init-Bqg5JWg7.mjs.map +1 -0
  86. package/dist/{inspect-live-schema-DxdBd4Er.mjs → inspect-live-schema-CWLK_lgs.mjs} +4 -4
  87. package/dist/{inspect-live-schema-DxdBd4Er.mjs.map → inspect-live-schema-CWLK_lgs.mjs.map} +1 -1
  88. package/dist/migration-cli.mjs +1 -1
  89. package/dist/migration-cli.mjs.map +1 -1
  90. package/dist/{migration-command-scaffold-BdV8JYXV.mjs → migration-command-scaffold-CmXXC1UZ.mjs} +4 -4
  91. package/dist/{migration-command-scaffold-BdV8JYXV.mjs.map → migration-command-scaffold-CmXXC1UZ.mjs.map} +1 -1
  92. package/dist/{migration-plan-mRu5K81L.mjs → migration-plan-CHyUlBV0.mjs} +76 -37
  93. package/dist/migration-plan-CHyUlBV0.mjs.map +1 -0
  94. package/dist/migration-types-D2FW63pr.d.mts +15 -0
  95. package/dist/migration-types-D2FW63pr.d.mts.map +1 -0
  96. package/dist/{migrations-CTsyBXCA.mjs → migrations-DyUf5lTt.mjs} +2 -2
  97. package/dist/migrations-DyUf5lTt.mjs.map +1 -0
  98. package/dist/{output-BVj6a971.mjs → output-B60Gw5fu.mjs} +12 -11
  99. package/dist/{output-BVj6a971.mjs.map → output-B60Gw5fu.mjs.map} +1 -1
  100. package/dist/{result-handler-rmPVKIP2.mjs → result-handler-Bm_6dDYg.mjs} +2 -2
  101. package/dist/{result-handler-rmPVKIP2.mjs.map → result-handler-Bm_6dDYg.mjs.map} +1 -1
  102. package/dist/{terminal-ui-C_hFNbAn.mjs → terminal-ui-XtOQsqe9.mjs} +2 -54
  103. package/dist/terminal-ui-XtOQsqe9.mjs.map +1 -0
  104. package/dist/{types-LItU7E4l.d.mts → types-0aS865QN.d.mts} +14 -8
  105. package/dist/types-0aS865QN.d.mts.map +1 -0
  106. package/dist/{verify-CiwNWM9N.mjs → verify-D7ypCCe6.mjs} +1 -1
  107. package/dist/{verify-CiwNWM9N.mjs.map → verify-D7ypCCe6.mjs.map} +1 -1
  108. package/package.json +10 -10
  109. package/dist/cli-errors-D3_sMh2K.mjs.map +0 -1
  110. package/dist/client-BCnP7cHo.mjs.map +0 -1
  111. package/dist/command-helpers-BeZHkxV8.mjs.map +0 -1
  112. package/dist/commands/migration-apply.d.mts +0 -51
  113. package/dist/commands/migration-apply.d.mts.map +0 -1
  114. package/dist/commands/migration-apply.mjs.map +0 -1
  115. package/dist/commands/migration-ref.d.mts +0 -45
  116. package/dist/commands/migration-ref.d.mts.map +0 -1
  117. package/dist/commands/migration-ref.mjs.map +0 -1
  118. package/dist/contract-emit-B77TsJqf.mjs.map +0 -1
  119. package/dist/db-verify-Czm5T-J4.mjs.map +0 -1
  120. package/dist/init-B-k3a1Qw.mjs.map +0 -1
  121. package/dist/migration-plan-mRu5K81L.mjs.map +0 -1
  122. package/dist/migration-status-By9G5p2H.mjs.map +0 -1
  123. package/dist/migrations-CTsyBXCA.mjs.map +0 -1
  124. package/dist/terminal-ui-C_hFNbAn.mjs.map +0 -1
  125. package/dist/types-LItU7E4l.d.mts.map +0 -1
  126. /package/dist/{cli-errors-B9OBbled.d.mts → cli-errors-DdcjVLJV.d.mts} +0 -0
@@ -1,20 +1,7 @@
1
- import { t as loadConfig } from "./config-loader-B6sJjXTv.mjs";
2
- import { _ as errorUnexpected, m as errorRuntime, v as mapMigrationToolsError } from "./cli-errors-D3_sMh2K.mjs";
3
- import { a as loadMigrationPackages, d as setCommandDescriptions, f as setCommandExamples, g as parseGlobalFlags, h as toStructuralEdge, l as resolveMigrationPaths, m as toPathDecisionResult, n as collectDeclaredInvariants, o as maskConnectionUrl, s as readContractEnvelope, t as addGlobalOptions, y as formatStyledHeader } from "./command-helpers-BeZHkxV8.mjs";
4
- import { t as TerminalUI } from "./terminal-ui-C_hFNbAn.mjs";
5
- import { t as handleResult } from "./result-handler-rmPVKIP2.mjs";
6
- import { t as createControlClient } from "./client-BCnP7cHo.mjs";
7
- import { t as buildContractSpaceAggregate } from "./contract-space-aggregate-loader-BrwKK6Q6.mjs";
8
- import { Command } from "commander";
9
1
  import { ifDefined } from "@prisma-next/utils/defined";
10
- import { notOk, ok } from "@prisma-next/utils/result";
11
- import { createControlStack } from "@prisma-next/framework-components/control";
12
- import { findPath, findPathWithDecision, findReachableLeaves } from "@prisma-next/migration-tools/migration-graph";
2
+ import { findPath } from "@prisma-next/migration-tools/migration-graph";
13
3
  import { bold, cyan, dim, magenta, yellow } from "colorette";
14
- import { graphWalkStrategy } from "@prisma-next/migration-tools/aggregate";
15
4
  import { EMPTY_CONTRACT_HASH } from "@prisma-next/migration-tools/constants";
16
- import { MigrationToolsError, errorNoInvariantPath, errorUnknownInvariant } from "@prisma-next/migration-tools/errors";
17
- import { readRefs, resolveRef } from "@prisma-next/migration-tools/refs";
18
5
  import dagre from "@dagrejs/dagre";
19
6
  //#region src/utils/formatters/graph-types.ts
20
7
  /**
@@ -1089,682 +1076,6 @@ function isLinearGraph(graph) {
1089
1076
  return true;
1090
1077
  }
1091
1078
  //#endregion
1092
- //#region src/commands/migration-status.ts
1093
- /**
1094
- * Sum per-space `pendingCount` into a cross-space total, but only when
1095
- * every loaded space reports a defined `pendingCount`. Returns
1096
- * `undefined` if any space is on the marker-unknown / offline path
1097
- * (where `pendingCount` is intentionally absent), so JSON consumers can
1098
- * distinguish "no pending" from "unknown".
1099
- */
1100
- function computeTotalPendingAcrossSpaces(spaces) {
1101
- if (spaces.length === 0) return void 0;
1102
- let total = 0;
1103
- for (const s of spaces) {
1104
- if (s.pendingCount === void 0) return void 0;
1105
- total += s.pendingCount;
1106
- }
1107
- return total;
1108
- }
1109
- function summarizeOps(ops) {
1110
- if (ops.length === 0) return {
1111
- summary: "0 ops",
1112
- hasDestructive: false
1113
- };
1114
- const classes = /* @__PURE__ */ new Map();
1115
- for (const op of ops) classes.set(op.operationClass, (classes.get(op.operationClass) ?? 0) + 1);
1116
- const hasDestructive = classes.has("destructive");
1117
- const count = ops.length;
1118
- const noun = count === 1 ? "op" : "ops";
1119
- if (classes.size === 1) return {
1120
- summary: `${count} ${noun} (all ${[...classes.keys()][0]})`,
1121
- hasDestructive
1122
- };
1123
- const destructiveCount = classes.get("destructive");
1124
- if (destructiveCount) return {
1125
- summary: `${count} ${noun} (${destructiveCount} destructive)`,
1126
- hasDestructive
1127
- };
1128
- return {
1129
- summary: `${count} ${noun} (${[...classes.entries()].map(([cls, n]) => `${n} ${cls}`).join(", ")})`,
1130
- hasDestructive
1131
- };
1132
- }
1133
- /**
1134
- * Derive per-edge status across the full graph using path analysis.
1135
- *
1136
- * - **applied**: edge is on the path from root to the DB marker
1137
- * - **pending**: edge is on the path from the DB marker to the target
1138
- * (and the marker is reachable from root, i.e. it's on the same branch)
1139
- * - **unreachable**: edge is on the path from root to the target but the DB
1140
- * marker is on a different branch — `apply` can't reach these edges
1141
- * without the DB first moving to this branch
1142
- *
1143
- * Returns statuses only for edges that have a known status (skips offline
1144
- * and edges not on any relevant path).
1145
- *
1146
- * @internal Exported for testing only.
1147
- */
1148
- function deriveEdgeStatuses(graph, targetHash, contractHash, markerHash, mode) {
1149
- if (mode === "offline") return [];
1150
- const edgeKey = (e) => `${e.from}\0${e.to}`;
1151
- const effectiveMarker = markerHash ?? EMPTY_CONTRACT_HASH;
1152
- const appliedPath = markerHash !== void 0 ? findPath(graph, EMPTY_CONTRACT_HASH, markerHash) : null;
1153
- const pendingPath = findPath(graph, effectiveMarker, targetHash);
1154
- const targetPath = findPath(graph, EMPTY_CONTRACT_HASH, targetHash);
1155
- const statuses = [];
1156
- const assignedKeys = /* @__PURE__ */ new Set();
1157
- if (appliedPath) for (const e of appliedPath) {
1158
- assignedKeys.add(edgeKey(e));
1159
- statuses.push({
1160
- dirName: e.dirName,
1161
- status: "applied"
1162
- });
1163
- }
1164
- if (pendingPath) for (const e of pendingPath) {
1165
- assignedKeys.add(edgeKey(e));
1166
- statuses.push({
1167
- dirName: e.dirName,
1168
- status: "pending"
1169
- });
1170
- }
1171
- if (contractHash !== EMPTY_CONTRACT_HASH && contractHash !== targetHash && graph.nodes.has(contractHash)) {
1172
- const beyondTarget = findPath(graph, targetHash, contractHash);
1173
- if (beyondTarget) {
1174
- for (const e of beyondTarget) if (!assignedKeys.has(edgeKey(e))) {
1175
- assignedKeys.add(edgeKey(e));
1176
- statuses.push({
1177
- dirName: e.dirName,
1178
- status: "pending"
1179
- });
1180
- }
1181
- }
1182
- }
1183
- if (targetPath) {
1184
- for (const e of targetPath) if (!assignedKeys.has(edgeKey(e))) statuses.push({
1185
- dirName: e.dirName,
1186
- status: "unreachable"
1187
- });
1188
- }
1189
- return statuses;
1190
- }
1191
- /**
1192
- * @param mode — 'online' if we connected to the database, 'offline' otherwise
1193
- * @param markerHash — the marker hash from the database, or undefined if no marker row / offline
1194
- */
1195
- function buildMigrationEntries(chain, packages, mode, markerHash, edgeStatuses) {
1196
- const pkgByDirName = new Map(packages.map((p) => [p.dirName, p]));
1197
- const statusByDirName = edgeStatuses ? new Map(edgeStatuses.map((e) => [e.dirName, e.status])) : void 0;
1198
- const markerInChain = markerHash === void 0 || chain.some((e) => e.to === markerHash);
1199
- const entries = [];
1200
- let reachedMarker = mode === "online" && markerHash === void 0;
1201
- for (const migration of chain) {
1202
- const ops = pkgByDirName.get(migration.dirName)?.ops ?? [];
1203
- const { summary, hasDestructive } = summarizeOps(ops);
1204
- let status;
1205
- const edgeStatus = statusByDirName?.get(migration.dirName);
1206
- if (edgeStatus) status = edgeStatus;
1207
- else if (mode === "offline" || !markerInChain) status = "unknown";
1208
- else if (reachedMarker) status = "pending";
1209
- else status = "applied";
1210
- entries.push({
1211
- dirName: migration.dirName,
1212
- from: migration.from,
1213
- to: migration.to,
1214
- migrationHash: migration.migrationHash,
1215
- operationCount: ops.length,
1216
- operationSummary: summary,
1217
- hasDestructive,
1218
- status
1219
- });
1220
- if (!reachedMarker && migration.to === markerHash) reachedMarker = true;
1221
- }
1222
- return entries;
1223
- }
1224
- /**
1225
- * Resolve the migration chain to display in status output.
1226
- *
1227
- * When offline or the marker is at EMPTY, the chain is simply the shortest
1228
- * path from EMPTY to the target — all structural paths are equivalent per
1229
- * the spec, so the deterministic shortest path is the canonical display.
1230
- *
1231
- * When online with a non-empty marker, the chain routes *through* the marker:
1232
- * EMPTY→marker (applied history) + marker→target (pending edges). This ensures
1233
- * the displayed chain includes the marker node so applied/pending status is
1234
- * correct. Without this, BFS from EMPTY to target could pick a shortest path
1235
- * that bypasses the marker entirely (e.g. in a diamond graph), causing the
1236
- * marker to appear "diverged" when it isn't.
1237
- */
1238
- function resolveDisplayChain(graph, targetHash, markerHash) {
1239
- if (markerHash === void 0) return findPath(graph, EMPTY_CONTRACT_HASH, targetHash);
1240
- const toMarker = findPath(graph, EMPTY_CONTRACT_HASH, markerHash);
1241
- if (!toMarker) return findPath(graph, EMPTY_CONTRACT_HASH, targetHash);
1242
- if (markerHash === targetHash) return toMarker;
1243
- const fromMarker = findPath(graph, markerHash, targetHash);
1244
- if (fromMarker) return [...toMarker, ...fromMarker];
1245
- const toTarget = findPath(graph, EMPTY_CONTRACT_HASH, targetHash);
1246
- if (!toTarget) return null;
1247
- const targetToMarker = findPath(graph, targetHash, markerHash);
1248
- if (targetToMarker) return [...toTarget, ...targetToMarker];
1249
- return toTarget;
1250
- }
1251
- const DEFAULT_LIMIT = 10;
1252
- function determineLimit(opts) {
1253
- if (opts.all) return;
1254
- if (!opts.limit) return DEFAULT_LIMIT;
1255
- const parsed = Number.parseInt(opts.limit, 10);
1256
- if (Number.isNaN(parsed)) return DEFAULT_LIMIT;
1257
- return parsed;
1258
- }
1259
- /**
1260
- * Build the aggregate enumeration of contract spaces for the status
1261
- * output. Loads the aggregate from disk (lossy on failure — extension
1262
- * spaces are simply omitted, the existing single-space app behaviour
1263
- * keeps working), reads per-space marker rows when online, and uses
1264
- * {@link graphWalkStrategy} to compute each space's pending count.
1265
- *
1266
- * Sub-spec § `migration status` semantics — the aggregate-walking
1267
- * version reports per-space marker + pending state alongside the
1268
- * cross-space totals.
1269
- */
1270
- async function loadAggregateStatusSpaces(args) {
1271
- const loaded = await buildContractSpaceAggregate({
1272
- targetId: args.targetId,
1273
- migrationsDir: args.migrationsDir,
1274
- appContract: args.validateContract(args.appContractRaw),
1275
- extensionPacks: args.extensionPacks,
1276
- validateContract: args.validateContract
1277
- });
1278
- if (!loaded.ok) return [];
1279
- const aggregate = loaded.value;
1280
- const orderedMembers = [...aggregate.extensions, aggregate.app];
1281
- const rows = [];
1282
- for (const member of orderedMembers) {
1283
- const liveMarker = args.markersBySpace?.get(member.spaceId) ?? null;
1284
- const isApp = member.spaceId === aggregate.app.spaceId;
1285
- if (member.migrations.graph.nodes.size === 0) {
1286
- rows.push({
1287
- spaceId: member.spaceId,
1288
- kind: isApp ? "app" : "extension",
1289
- headHash: member.headRef.hash,
1290
- ...args.markersBySpace !== null ? {
1291
- markerHash: liveMarker?.storageHash ?? null,
1292
- status: member.headRef.hash === EMPTY_CONTRACT_HASH ? "up-to-date" : "never-planned",
1293
- pendingCount: 0
1294
- } : {}
1295
- });
1296
- continue;
1297
- }
1298
- if (args.markersBySpace === null) {
1299
- rows.push({
1300
- spaceId: member.spaceId,
1301
- kind: isApp ? "app" : "extension",
1302
- headHash: member.headRef.hash
1303
- });
1304
- continue;
1305
- }
1306
- const walked = graphWalkStrategy({
1307
- aggregateTargetId: aggregate.targetId,
1308
- member,
1309
- currentMarker: liveMarker
1310
- });
1311
- let pendingCount = 0;
1312
- let status;
1313
- if (walked.kind === "ok") {
1314
- pendingCount = walked.result.migrationEdges?.length ?? 0;
1315
- if (liveMarker === null) status = pendingCount === 0 ? "no-marker" : "pending";
1316
- else status = pendingCount === 0 ? "up-to-date" : "pending";
1317
- } else status = "unreachable";
1318
- rows.push({
1319
- spaceId: member.spaceId,
1320
- kind: isApp ? "app" : "extension",
1321
- headHash: member.headRef.hash,
1322
- markerHash: liveMarker?.storageHash ?? null,
1323
- pendingCount,
1324
- ...status ? { status } : {}
1325
- });
1326
- }
1327
- return rows;
1328
- }
1329
- /**
1330
- * Read the raw contract.json bytes from disk for the aggregate
1331
- * loader. Returns `null` if the file is missing or unparseable —
1332
- * the existing `readContractEnvelope` path will report the same
1333
- * problem via a status diagnostic, no need to double-surface.
1334
- */
1335
- async function loadContractRawSafely(config) {
1336
- try {
1337
- const path = (await import("./command-helpers-BeZHkxV8.mjs").then((n) => n.r)).resolveContractPath(config);
1338
- const raw = await (await import("node:fs/promises")).readFile(path, "utf-8");
1339
- return JSON.parse(raw);
1340
- } catch {
1341
- return null;
1342
- }
1343
- }
1344
- async function executeMigrationStatusCommand(options, flags, ui) {
1345
- const config = await loadConfig(options.config);
1346
- const { configPath, appMigrationsDir, appMigrationsRelative, migrationsDir, refsDir } = resolveMigrationPaths(options.config, config);
1347
- const dbConnection = options.db ?? config.db?.connection;
1348
- const hasDriver = !!config.driver;
1349
- let activeRefName;
1350
- let activeRefHash;
1351
- let activeRefEntry;
1352
- let allRefs = {};
1353
- try {
1354
- allRefs = await readRefs(refsDir);
1355
- } catch (error) {
1356
- if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));
1357
- throw error;
1358
- }
1359
- if (options.ref) {
1360
- activeRefName = options.ref;
1361
- try {
1362
- activeRefEntry = resolveRef(allRefs, activeRefName);
1363
- activeRefHash = activeRefEntry.hash;
1364
- } catch (error) {
1365
- if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));
1366
- throw error;
1367
- }
1368
- }
1369
- const requiredInvariants = [...activeRefEntry?.invariants ?? []].sort();
1370
- const statusRefs = Object.entries(allRefs).map(([name, entry]) => ({
1371
- name,
1372
- hash: entry.hash,
1373
- active: name === activeRefName
1374
- }));
1375
- if (!flags.json && !flags.quiet) {
1376
- const details = [{
1377
- label: "config",
1378
- value: configPath
1379
- }, {
1380
- label: "migrations",
1381
- value: appMigrationsRelative
1382
- }];
1383
- if (dbConnection && hasDriver) details.push({
1384
- label: "database",
1385
- value: maskConnectionUrl(String(dbConnection))
1386
- });
1387
- if (activeRefName) details.push({
1388
- label: "ref",
1389
- value: activeRefName
1390
- });
1391
- if (activeRefEntry && activeRefEntry.invariants.length > 0) details.push({
1392
- label: "required",
1393
- value: formatInvariantList(activeRefEntry.invariants)
1394
- });
1395
- const header = formatStyledHeader({
1396
- command: "migration status",
1397
- description: "Show migration history and applied status",
1398
- details,
1399
- flags
1400
- });
1401
- ui.stderr(header);
1402
- }
1403
- const diagnostics = [];
1404
- let contractHash = EMPTY_CONTRACT_HASH;
1405
- try {
1406
- contractHash = (await readContractEnvelope(config)).storageHash;
1407
- } catch (error) {
1408
- diagnostics.push({
1409
- code: "CONTRACT.UNREADABLE",
1410
- severity: "warn",
1411
- message: `Could not read contract: ${error instanceof Error ? error.message : "unknown error"}`,
1412
- hints: ["Run 'prisma-next contract emit' to generate a valid contract"]
1413
- });
1414
- }
1415
- let bundles;
1416
- let graph;
1417
- try {
1418
- ({bundles, graph} = await loadMigrationPackages(appMigrationsDir));
1419
- } catch (error) {
1420
- if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));
1421
- return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to read migrations directory: ${error instanceof Error ? error.message : String(error)}` }));
1422
- }
1423
- if (bundles.length === 0) {
1424
- if (contractHash !== EMPTY_CONTRACT_HASH) diagnostics.push({
1425
- code: "CONTRACT.AHEAD",
1426
- severity: "warn",
1427
- message: "No migration exists for the current contract",
1428
- hints: ["Run 'prisma-next migration plan' to generate a migration for the current contract"]
1429
- });
1430
- return ok({
1431
- ok: true,
1432
- mode: dbConnection && hasDriver ? "online" : "offline",
1433
- migrations: [],
1434
- targetHash: EMPTY_CONTRACT_HASH,
1435
- contractHash,
1436
- summary: "No migrations found",
1437
- diagnostics,
1438
- requiredInvariants
1439
- });
1440
- }
1441
- let targetHash;
1442
- if (activeRefHash) targetHash = activeRefHash;
1443
- else if (graph.nodes.has(contractHash)) targetHash = contractHash;
1444
- else {
1445
- const leaves = findReachableLeaves(graph, EMPTY_CONTRACT_HASH);
1446
- if (leaves.length === 1) targetHash = leaves[0];
1447
- else diagnostics.push({
1448
- code: "MIGRATION.DIVERGED",
1449
- severity: "warn",
1450
- message: "There are multiple valid migration paths — you must select a target",
1451
- hints: ["Use '--ref <name>' to select a target", "Or 'prisma-next migration ref set <name> <hash>' to create one"]
1452
- });
1453
- }
1454
- let markerHash;
1455
- let markerInvariants = [];
1456
- let mode = "offline";
1457
- let allMarkers = null;
1458
- if (dbConnection && hasDriver) {
1459
- const client = createControlClient({
1460
- family: config.family,
1461
- target: config.target,
1462
- adapter: config.adapter,
1463
- driver: config.driver,
1464
- extensionPacks: config.extensionPacks ?? []
1465
- });
1466
- try {
1467
- await client.connect(dbConnection);
1468
- const marker = await client.readMarker();
1469
- markerHash = marker?.storageHash;
1470
- markerInvariants = marker?.invariants ?? [];
1471
- mode = "online";
1472
- if (typeof client.readAllMarkers === "function") allMarkers = await client.readAllMarkers();
1473
- else allMarkers = null;
1474
- } catch {
1475
- if (!flags.json && !flags.quiet) ui.warn("Could not connect to database — showing offline status");
1476
- } finally {
1477
- await client.close();
1478
- }
1479
- }
1480
- const contractRawForAggregate = await loadContractRawSafely(config);
1481
- let aggregateSpaces = [];
1482
- if (contractRawForAggregate !== null) {
1483
- const stack = createControlStack(config);
1484
- const familyInstance = config.family.create(stack);
1485
- try {
1486
- aggregateSpaces = await loadAggregateStatusSpaces({
1487
- targetId: config.target.targetId,
1488
- migrationsDir,
1489
- appContractRaw: contractRawForAggregate,
1490
- extensionPacks: config.extensionPacks ?? [],
1491
- validateContract: (json) => familyInstance.validateContract(json),
1492
- markersBySpace: allMarkers
1493
- });
1494
- } catch {
1495
- aggregateSpaces = [];
1496
- }
1497
- }
1498
- const totalPendingAcrossSpaces = computeTotalPendingAcrossSpaces(aggregateSpaces);
1499
- if (activeRefEntry && activeRefEntry.invariants.length > 0) {
1500
- const declared = collectDeclaredInvariants(graph);
1501
- const known = new Set(declared);
1502
- if (mode === "online") for (const id of markerInvariants) known.add(id);
1503
- const unknown = activeRefEntry.invariants.filter((id) => !known.has(id));
1504
- if (unknown.length > 0) return notOk(mapMigrationToolsError(errorUnknownInvariant({
1505
- ...ifDefined("refName", activeRefName),
1506
- unknown,
1507
- declared: [...declared].sort()
1508
- })));
1509
- }
1510
- if (mode === "online" && markerHash !== void 0 && !graph.nodes.has(markerHash) && markerHash !== contractHash) {
1511
- const hints = [];
1512
- if (graph.nodes.has(contractHash)) hints.push("Run 'prisma-next db sign' to overwrite the marker if the database already matches the contract", "Run 'prisma-next db update' to push the current contract to the database", "Run 'prisma-next contract infer' to make your contract match the database", "Run 'prisma-next db verify' to inspect the database state");
1513
- else hints.push("Run 'prisma-next db update' to push the current contract to the database", "Run 'prisma-next contract infer' to make your contract match the database", "Run 'prisma-next db verify' to inspect the database state");
1514
- diagnostics.push({
1515
- code: "MIGRATION.MARKER_NOT_IN_HISTORY",
1516
- severity: "warn",
1517
- message: "Database was updated outside the migration system (marker does not match any migration)",
1518
- hints
1519
- });
1520
- return ok({
1521
- ok: true,
1522
- mode,
1523
- migrations: [],
1524
- targetHash: EMPTY_CONTRACT_HASH,
1525
- contractHash,
1526
- summary: `${bundles.length} migration(s) on disk`,
1527
- diagnostics,
1528
- markerHash,
1529
- requiredInvariants,
1530
- ...statusRefs.length > 0 ? { refs: statusRefs } : {}
1531
- });
1532
- }
1533
- if (mode === "online" && markerHash === void 0) diagnostics.push({
1534
- code: "MIGRATION.NO_MARKER",
1535
- severity: "warn",
1536
- message: "Database has not been initialized — no migration marker found",
1537
- hints: ["Run 'prisma-next migration apply' to apply pending migrations"]
1538
- });
1539
- if (targetHash && contractHash !== EMPTY_CONTRACT_HASH && !graph.nodes.has(contractHash) && markerHash !== contractHash) diagnostics.push({
1540
- code: "CONTRACT.AHEAD",
1541
- severity: "warn",
1542
- message: "Contract has changed since the last migration was planned",
1543
- hints: ["Run 'prisma-next migration plan' to generate a migration for the current contract"]
1544
- });
1545
- if (!targetHash) return ok({
1546
- ok: true,
1547
- mode,
1548
- migrations: [],
1549
- targetHash: EMPTY_CONTRACT_HASH,
1550
- contractHash,
1551
- summary: `${bundles.length} migration(s) on disk`,
1552
- diagnostics,
1553
- ...ifDefined("markerHash", markerHash),
1554
- requiredInvariants,
1555
- ...statusRefs.length > 0 ? { refs: statusRefs } : {},
1556
- graph,
1557
- bundles,
1558
- diverged: true
1559
- });
1560
- const chain = resolveDisplayChain(graph, targetHash, markerHash);
1561
- if (!chain) return notOk(errorRuntime("Cannot reconstruct migration history", {
1562
- why: `No path from ${EMPTY_CONTRACT_HASH} to target ${targetHash}`,
1563
- fix: "The migration history may have gaps. Check the migrations directory for missing or corrupted packages."
1564
- }));
1565
- const edgeStatuses = deriveEdgeStatuses(graph, targetHash, contractHash, markerHash, mode);
1566
- const entries = buildMigrationEntries(chain, bundles, mode, markerHash, edgeStatuses);
1567
- const pendingCount = edgeStatuses.filter((e) => e.status === "pending").length;
1568
- const appliedCount = edgeStatuses.filter((e) => e.status === "applied").length;
1569
- let appliedInvariants;
1570
- let missingInvariants;
1571
- let effectiveRequired = /* @__PURE__ */ new Set();
1572
- if (mode === "online") {
1573
- const markerSet = new Set(markerInvariants);
1574
- effectiveRequired = new Set(requiredInvariants.filter((id) => !markerSet.has(id)));
1575
- appliedInvariants = requiredInvariants.filter((id) => markerSet.has(id));
1576
- missingInvariants = [...effectiveRequired].sort();
1577
- }
1578
- const hasInvariantWork = effectiveRequired.size > 0;
1579
- const missingList = [...effectiveRequired].sort().join(", ");
1580
- let summary;
1581
- if (mode === "online") if (markerHash !== void 0 && !graph.nodes.has(markerHash) && markerHash === contractHash) summary = `${bundles.length} migration(s) on disk`;
1582
- else if (activeRefHash && markerHash !== void 0) {
1583
- const distance = summarizeRefDistance(graph, markerHash, activeRefHash, activeRefName);
1584
- summary = hasInvariantWork ? `${distance} — missing invariant(s): ${missingList}` : distance;
1585
- } else if (pendingCount === 0 && !hasInvariantWork) summary = `Database is up to date (${appliedCount} migration${appliedCount !== 1 ? "s" : ""} applied)`;
1586
- else if (pendingCount === 0 && hasInvariantWork) summary = `Missing invariant(s): ${missingList} — run 'prisma-next migration apply --ref ${activeRefName ?? "<ref>"}' to apply`;
1587
- else if (markerHash === void 0) summary = `${pendingCount} pending migration(s) — database has no marker`;
1588
- else summary = `${pendingCount} pending migration(s) — run 'prisma-next migration apply' to apply`;
1589
- else summary = `${entries.length} migration(s) on disk`;
1590
- let pathDecision;
1591
- let routingUnreachable = false;
1592
- if (mode === "online") {
1593
- const outcome = findPathWithDecision(graph, markerHash ?? EMPTY_CONTRACT_HASH, targetHash, {
1594
- ...ifDefined("refName", activeRefName),
1595
- required: effectiveRequired
1596
- });
1597
- if (outcome.kind === "ok") pathDecision = toPathDecisionResult(outcome.decision);
1598
- else if (outcome.kind === "unsatisfiable") return notOk(mapMigrationToolsError(errorNoInvariantPath({
1599
- ...ifDefined("refName", activeRefName),
1600
- required: [...effectiveRequired].sort(),
1601
- missing: outcome.missing,
1602
- structuralPath: outcome.structuralPath.map(toStructuralEdge)
1603
- })));
1604
- else routingUnreachable = true;
1605
- }
1606
- if (mode === "online") {
1607
- if (markerHash !== void 0 && !graph.nodes.has(markerHash) && markerHash === contractHash) diagnostics.push({
1608
- code: "MIGRATION.MARKER_NOT_IN_HISTORY",
1609
- severity: "warn",
1610
- message: "Database matches the current contract but was updated directly (not via migration apply)",
1611
- hints: ["Run 'prisma-next migration plan' to plan a migration to your current contract"]
1612
- });
1613
- else if (pendingCount > 0) diagnostics.push({
1614
- code: "MIGRATION.DATABASE_BEHIND",
1615
- severity: "info",
1616
- message: `${pendingCount} migration(s) pending`,
1617
- hints: ["Run 'prisma-next migration apply' to apply pending migrations"]
1618
- });
1619
- else if (hasInvariantWork) diagnostics.push({
1620
- code: "MIGRATION.INVARIANTS_PENDING",
1621
- severity: "info",
1622
- message: `Missing required invariant(s): ${missingList}`,
1623
- hints: [`Run 'prisma-next migration apply --ref ${activeRefName ?? "<ref>"}' to apply a path that covers the required invariants`]
1624
- });
1625
- else if (!routingUnreachable) diagnostics.push({
1626
- code: "MIGRATION.UP_TO_DATE",
1627
- severity: "info",
1628
- message: "Database is up to date",
1629
- hints: []
1630
- });
1631
- }
1632
- return ok({
1633
- ok: true,
1634
- mode,
1635
- migrations: entries,
1636
- targetHash,
1637
- contractHash,
1638
- summary,
1639
- diagnostics,
1640
- ...ifDefined("markerHash", markerHash),
1641
- requiredInvariants,
1642
- ...ifDefined("appliedInvariants", appliedInvariants),
1643
- ...ifDefined("missingInvariants", missingInvariants),
1644
- ...statusRefs.length > 0 ? { refs: statusRefs } : {},
1645
- ...ifDefined("pathDecision", pathDecision),
1646
- graph,
1647
- bundles,
1648
- edgeStatuses,
1649
- ...ifDefined("activeRefHash", activeRefHash),
1650
- ...ifDefined("activeRefName", activeRefName),
1651
- spaces: aggregateSpaces,
1652
- ...ifDefined("totalPendingAcrossSpaces", totalPendingAcrossSpaces)
1653
- });
1654
- }
1655
- function createMigrationStatusCommand() {
1656
- const command = new Command("status");
1657
- setCommandDescriptions(command, "Show migration history and applied status", "Displays the migration history in order. When a database connection\nis available, shows which migrations are applied and which are pending.\nWithout a database connection, shows the history from disk only.");
1658
- setCommandExamples(command, ["prisma-next migration status", "prisma-next migration status --db $DATABASE_URL"]);
1659
- addGlobalOptions(command).option("--db <url>", "Database connection string").option("--config <path>", "Path to prisma-next.config.ts").option("--ref <name>", "Target ref name from migrations/refs/").option("--graph", "Show the full migration graph with all branches").option("--limit <n>", "Maximum number of migrations to display (default: 10)").option("--all", "Show full history (disables truncation)").action(async (options) => {
1660
- const flags = parseGlobalFlags(options);
1661
- const ui = new TerminalUI({
1662
- color: flags.color,
1663
- interactive: flags.interactive
1664
- });
1665
- const exitCode = handleResult(await executeMigrationStatusCommand(options, flags, ui), flags, ui, (statusResult) => {
1666
- if (flags.json) {
1667
- const { graph: _graph, bundles: _bundles, edgeStatuses: _edgeStatuses, activeRefHash: _activeRefHash, activeRefName: _activeRefName, diverged: _diverged, ...jsonResult } = statusResult;
1668
- ui.output(JSON.stringify(jsonResult, null, 2));
1669
- } else if (!flags.quiet) {
1670
- const colorize = flags.color !== false;
1671
- if (statusResult.graph) {
1672
- const limit = determineLimit(options);
1673
- const renderInput = migrationGraphToRenderInput({
1674
- graph: statusResult.graph,
1675
- mode: statusResult.mode,
1676
- markerHash: statusResult.markerHash,
1677
- contractHash: statusResult.contractHash,
1678
- refs: statusResult.refs,
1679
- activeRefHash: statusResult.activeRefHash,
1680
- activeRefName: statusResult.activeRefName,
1681
- edgeStatuses: statusResult.edgeStatuses
1682
- });
1683
- const graphToRender = options.graph || statusResult.diverged ? renderInput.graph : extractRelevantSubgraph(renderInput.graph, renderInput.relevantPaths);
1684
- const dagreOptions = !options.graph && isLinearGraph(graphToRender) ? { ranksep: 1 } : void 0;
1685
- const renderOptions = {
1686
- ...renderInput.options,
1687
- colorize,
1688
- ...ifDefined("limit", limit),
1689
- ...ifDefined("dagreOptions", dagreOptions)
1690
- };
1691
- const graphOutput = graphRenderer.render(graphToRender, renderOptions);
1692
- ui.log(graphOutput);
1693
- if (statusResult.mode === "online") ui.log(formatLegend(colorize));
1694
- }
1695
- ui.log("");
1696
- ui.log(formatStatusSummary(statusResult, colorize));
1697
- }
1698
- });
1699
- process.exit(exitCode);
1700
- });
1701
- return command;
1702
- }
1703
- function formatLegend(colorize) {
1704
- const c = (fn, s) => colorize ? fn(s) : s;
1705
- return c(dim, [
1706
- `${c(cyan, "✓")} applied`,
1707
- `${c(yellow, "⧗")} pending`,
1708
- `${c(magenta, "✗")} unreachable`
1709
- ].join(" "));
1710
- }
1711
- function formatStatusSummary(result, colorize) {
1712
- const c = (fn, s) => colorize ? fn(s) : s;
1713
- const lines = [];
1714
- const hasUnknown = result.migrations.some((e) => e.status === "unknown");
1715
- const pendingCount = result.migrations.filter((e) => e.status === "pending").length;
1716
- const hasWarnings = result.diagnostics?.some((d) => d.severity === "warn") ?? false;
1717
- const hasInvariantPending = result.diagnostics?.some((d) => d.code === "MIGRATION.INVARIANTS_PENDING") ?? false;
1718
- if (result.mode === "online") if (hasUnknown || hasWarnings) lines.push(`${c(yellow, "⚠")} ${result.summary}`);
1719
- else if (pendingCount === 0 && !hasInvariantPending) lines.push(`${c(cyan, "✔")} ${result.summary}`);
1720
- else lines.push(`${c(yellow, "⧗")} ${result.summary}`);
1721
- else lines.push(result.summary);
1722
- if (result.requiredInvariants.length > 0) if (result.appliedInvariants !== void 0 && result.missingInvariants !== void 0) {
1723
- lines.push(`${c(dim, "applied ")}${formatInvariantList(result.appliedInvariants)}`);
1724
- lines.push(`${c(dim, "missing ")}${formatInvariantList(result.missingInvariants)}`);
1725
- } else lines.push(`${c(dim, "applied ")}(unknown — connect a database to evaluate)`);
1726
- const warnings = result.diagnostics?.filter((d) => d.severity === "warn") ?? [];
1727
- for (const diag of warnings) {
1728
- lines.push(`${c(yellow, "⚠")} ${diag.message}`);
1729
- for (const hint of diag.hints) lines.push(` ${c(dim, hint)}`);
1730
- }
1731
- if (result.spaces?.some((s) => s.kind === "extension")) {
1732
- const total = result.totalPendingAcrossSpaces ?? 0;
1733
- lines.push("");
1734
- lines.push(c(dim, "spaces"));
1735
- for (const space of result.spaces) lines.push(formatSpaceLine(space, c));
1736
- if (total > 0) {
1737
- lines.push("");
1738
- lines.push(`${c(yellow, "⧗")} ${total} pending migration(s) across ${result.spaces.length} space(s) — run 'prisma-next migration apply' to apply`);
1739
- }
1740
- }
1741
- return lines.join("\n");
1742
- }
1743
- function formatSpaceLine(space, c) {
1744
- const glyph = (() => {
1745
- if (space.status === "up-to-date" || space.status === "no-marker") return c(cyan, "✓");
1746
- if (space.status === "pending") return c(yellow, "⧗");
1747
- if (space.status === "unreachable" || space.status === "never-planned") return c(magenta, "✗");
1748
- return " ";
1749
- })();
1750
- const tag = space.kind === "app" ? "[app]" : "[ext]";
1751
- const head = space.headHash.slice(0, 8);
1752
- const marker = space.markerHash === void 0 ? "(unknown)" : space.markerHash === null ? "(no marker)" : space.markerHash.slice(0, 8);
1753
- const pending = space.pendingCount === void 0 ? "" : space.pendingCount === 0 ? c(dim, " (up to date)") : c(yellow, ` (${space.pendingCount} pending)`);
1754
- return ` ${glyph} ${c(dim, tag)} ${space.spaceId} → head ${c(dim, head)}, marker ${c(dim, marker)}${pending}`;
1755
- }
1756
- function formatInvariantList(ids) {
1757
- return ids.length === 0 ? "(none)" : ids.join(", ");
1758
- }
1759
- function summarizeRefDistance(graph, markerHash, refHash, refName) {
1760
- if (markerHash === refHash) return `At ref "${refName}" target`;
1761
- const pathToRef = findPath(graph, markerHash, refHash);
1762
- if (pathToRef) return `${pathToRef.length} migration(s) behind ref "${refName}"`;
1763
- const pathFromRef = findPath(graph, refHash, markerHash);
1764
- if (pathFromRef) return `${pathFromRef.length} migration(s) ahead of ref "${refName}"`;
1765
- return `No path between database marker and ref "${refName}" target`;
1766
- }
1767
- //#endregion
1768
- export { loadAggregateStatusSpaces as a, formatStatusSummary as i, createMigrationStatusCommand as n, deriveEdgeStatuses as r, computeTotalPendingAcrossSpaces as t };
1079
+ export { migrationGraphToRenderInput as i, graphRenderer as n, isLinearGraph as r, extractRelevantSubgraph as t };
1769
1080
 
1770
- //# sourceMappingURL=migration-status-By9G5p2H.mjs.map
1081
+ //# sourceMappingURL=graph-render-eJDcLWny.mjs.map