@prisma-next/cli 0.12.0-dev.4 → 0.12.0-dev.41

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 (166) hide show
  1. package/README.md +2 -2
  2. package/dist/cli.mjs +180 -163
  3. package/dist/cli.mjs.map +1 -1
  4. package/dist/{client-KgJorIvG.mjs → client-Dk-zRFuT.mjs} +83 -58
  5. package/dist/client-Dk-zRFuT.mjs.map +1 -0
  6. package/dist/{command-helpers-Bbw1GbwL.mjs → command-helpers-xvg9oq4T.mjs} +301 -23
  7. package/dist/command-helpers-xvg9oq4T.mjs.map +1 -0
  8. package/dist/commands/contract-emit.mjs +1 -1
  9. package/dist/commands/contract-infer.mjs +1 -1
  10. package/dist/commands/db-init.mjs +4 -5
  11. package/dist/commands/db-init.mjs.map +1 -1
  12. package/dist/commands/db-schema.mjs +3 -3
  13. package/dist/commands/db-sign.mjs +4 -4
  14. package/dist/commands/db-update.d.mts.map +1 -1
  15. package/dist/commands/db-update.mjs +10 -7
  16. package/dist/commands/db-update.mjs.map +1 -1
  17. package/dist/commands/db-verify.mjs +1 -1
  18. package/dist/commands/migrate.d.mts +2 -2
  19. package/dist/commands/migrate.d.mts.map +1 -1
  20. package/dist/commands/migrate.mjs +6 -8
  21. package/dist/commands/migrate.mjs.map +1 -1
  22. package/dist/commands/migration-check.d.mts +55 -1
  23. package/dist/commands/migration-check.d.mts.map +1 -1
  24. package/dist/commands/migration-check.mjs +2 -2
  25. package/dist/commands/migration-graph.d.mts +25 -7
  26. package/dist/commands/migration-graph.d.mts.map +1 -1
  27. package/dist/commands/migration-graph.mjs +170 -2
  28. package/dist/commands/migration-graph.mjs.map +1 -0
  29. package/dist/commands/migration-list.d.mts +24 -26
  30. package/dist/commands/migration-list.d.mts.map +1 -1
  31. package/dist/commands/migration-list.mjs +2 -190
  32. package/dist/commands/migration-log.d.mts +20 -15
  33. package/dist/commands/migration-log.d.mts.map +1 -1
  34. package/dist/commands/migration-log.mjs +1 -137
  35. package/dist/commands/migration-new.mjs +3 -3
  36. package/dist/commands/migration-plan.d.mts +1 -1
  37. package/dist/commands/migration-plan.mjs +1 -1
  38. package/dist/commands/migration-show.d.mts +1 -4
  39. package/dist/commands/migration-show.d.mts.map +1 -1
  40. package/dist/commands/migration-show.mjs +13 -25
  41. package/dist/commands/migration-show.mjs.map +1 -1
  42. package/dist/commands/migration-status.d.mts +41 -141
  43. package/dist/commands/migration-status.d.mts.map +1 -1
  44. package/dist/commands/migration-status.mjs +2 -759
  45. package/dist/commands/ref.d.mts +1 -1
  46. package/dist/commands/ref.mjs +3 -3
  47. package/dist/commands/telemetry/index.d.mts +7 -0
  48. package/dist/commands/telemetry/index.d.mts.map +1 -0
  49. package/dist/commands/telemetry/index.mjs +2 -0
  50. package/dist/{contract-at-errors-BxP-TOMl.mjs → contract-at-errors-Wj3u4Xco.mjs} +2 -2
  51. package/dist/{contract-at-errors-BxP-TOMl.mjs.map → contract-at-errors-Wj3u4Xco.mjs.map} +1 -1
  52. package/dist/{contract-emit-DxcGl4Uq.mjs → contract-emit-CZU0UO6M.mjs} +3 -3
  53. package/dist/{contract-emit-DxcGl4Uq.mjs.map → contract-emit-CZU0UO6M.mjs.map} +1 -1
  54. package/dist/{contract-emit-D-4jrNve.mjs → contract-emit-FetLZ3jn.mjs} +5 -5
  55. package/dist/{contract-emit-D-4jrNve.mjs.map → contract-emit-FetLZ3jn.mjs.map} +1 -1
  56. package/dist/{contract-infer-D8uEbJuu.mjs → contract-infer-3wtOsS_H.mjs} +3 -3
  57. package/dist/{contract-infer-D8uEbJuu.mjs.map → contract-infer-3wtOsS_H.mjs.map} +1 -1
  58. package/dist/{contract-space-aggregate-loader-DvZwdkrr.mjs → contract-space-aggregate-loader-BdRPfM3Q.mjs} +63 -5
  59. package/dist/{contract-space-aggregate-loader-DvZwdkrr.mjs.map → contract-space-aggregate-loader-BdRPfM3Q.mjs.map} +1 -1
  60. package/dist/{db-verify-v_vUKXTU.mjs → db-verify-BisylXFZ.mjs} +4 -4
  61. package/dist/{db-verify-v_vUKXTU.mjs.map → db-verify-BisylXFZ.mjs.map} +1 -1
  62. package/dist/exports/control-api.d.mts +2 -2
  63. package/dist/exports/control-api.d.mts.map +1 -1
  64. package/dist/exports/control-api.mjs +2 -2
  65. package/dist/exports/index.mjs +1 -1
  66. package/dist/exports/init-output.mjs +1 -1
  67. package/dist/{framework-components-fYXjz_in.mjs → framework-components-Be4inY3I.mjs} +2 -2
  68. package/dist/{framework-components-fYXjz_in.mjs.map → framework-components-Be4inY3I.mjs.map} +1 -1
  69. package/dist/{global-flags-DEHjV8_s.d.mts → global-flags-DG4uY5tV.d.mts} +1 -1
  70. package/dist/{global-flags-DEHjV8_s.d.mts.map → global-flags-DG4uY5tV.d.mts.map} +1 -1
  71. package/dist/{init-Cv9UzWL5.mjs → init-BTE2U7lG.mjs} +5 -58
  72. package/dist/init-BTE2U7lG.mjs.map +1 -0
  73. package/dist/{inspect-live-schema-C6ohV_oQ.mjs → inspect-live-schema-Cy9Y4wsL.mjs} +3 -3
  74. package/dist/{inspect-live-schema-C6ohV_oQ.mjs.map → inspect-live-schema-Cy9Y4wsL.mjs.map} +1 -1
  75. package/dist/{migration-check-BiBJoYYW.mjs → migration-check-CUavU7U9.mjs} +236 -88
  76. package/dist/migration-check-CUavU7U9.mjs.map +1 -0
  77. package/dist/{migration-command-scaffold-CjvwO6at.mjs → migration-command-scaffold-BxOxtyJ6.mjs} +3 -3
  78. package/dist/{migration-command-scaffold-CjvwO6at.mjs.map → migration-command-scaffold-BxOxtyJ6.mjs.map} +1 -1
  79. package/dist/migration-graph-space-render-ByJ83gxp.mjs +1966 -0
  80. package/dist/migration-graph-space-render-ByJ83gxp.mjs.map +1 -0
  81. package/dist/migration-list-jK6QeczE.mjs +228 -0
  82. package/dist/migration-list-jK6QeczE.mjs.map +1 -0
  83. package/dist/migration-list-types-DS63IdFd.d.mts +23 -0
  84. package/dist/migration-list-types-DS63IdFd.d.mts.map +1 -0
  85. package/dist/migration-log-DWI6dZyi.mjs +215 -0
  86. package/dist/migration-log-DWI6dZyi.mjs.map +1 -0
  87. package/dist/migration-path-target-DqcrbOis.mjs +24 -0
  88. package/dist/migration-path-target-DqcrbOis.mjs.map +1 -0
  89. package/dist/{migration-plan-9DJ7q7_z.mjs → migration-plan-NHdlUwPG.mjs} +5 -6
  90. package/dist/{migration-plan-9DJ7q7_z.mjs.map → migration-plan-NHdlUwPG.mjs.map} +1 -1
  91. package/dist/migration-status-DI6Ldjbo.mjs +439 -0
  92. package/dist/migration-status-DI6Ldjbo.mjs.map +1 -0
  93. package/dist/{output-B60Gw5fu.mjs → output-CF_hqzI-.mjs} +1 -1
  94. package/dist/{output-B60Gw5fu.mjs.map → output-CF_hqzI-.mjs.map} +1 -1
  95. package/dist/{ref-advancement-DUZqsue6.mjs → ref-advancement-CJY9zOv7.mjs} +1 -1
  96. package/dist/{ref-advancement-DUZqsue6.mjs.map → ref-advancement-CJY9zOv7.mjs.map} +1 -1
  97. package/dist/telemetry-DQP0BvKv.mjs +122 -0
  98. package/dist/telemetry-DQP0BvKv.mjs.map +1 -0
  99. package/dist/{types-Dt_SfqFm.d.mts → types-Cculk5KV.d.mts} +44 -31
  100. package/dist/types-Cculk5KV.d.mts.map +1 -0
  101. package/dist/{verify-DCA9Sldu.mjs → verify-tvHRBBVP.mjs} +2 -2
  102. package/dist/{verify-DCA9Sldu.mjs.map → verify-tvHRBBVP.mjs.map} +1 -1
  103. package/package.json +22 -19
  104. package/src/cli.ts +5 -0
  105. package/src/commands/db-update.ts +7 -1
  106. package/src/commands/init/index.ts +6 -35
  107. package/src/commands/init/init.ts +1 -14
  108. package/src/commands/init/inputs.ts +0 -75
  109. package/src/commands/migrate.ts +6 -6
  110. package/src/commands/migration-check.ts +340 -117
  111. package/src/commands/migration-graph.ts +163 -90
  112. package/src/commands/migration-list.ts +55 -25
  113. package/src/commands/migration-log.ts +49 -98
  114. package/src/commands/migration-show.ts +10 -38
  115. package/src/commands/migration-status-overlay.ts +61 -0
  116. package/src/commands/migration-status.ts +440 -1056
  117. package/src/commands/telemetry/index.ts +107 -0
  118. package/src/commands/telemetry/status.ts +67 -0
  119. package/src/control-api/client.ts +20 -9
  120. package/src/control-api/operations/contract-emit.ts +2 -2
  121. package/src/control-api/operations/db-init.ts +3 -3
  122. package/src/control-api/operations/{db-apply.ts → db-run.ts} +37 -10
  123. package/src/control-api/operations/db-update.ts +4 -4
  124. package/src/control-api/operations/{migration-apply.ts → migrate.ts} +32 -24
  125. package/src/control-api/operations/{apply.ts → run-migration.ts} +33 -27
  126. package/src/control-api/types.ts +46 -29
  127. package/src/utils/cli-errors.ts +47 -2
  128. package/src/utils/formatters/errors.ts +11 -0
  129. package/src/utils/formatters/migration-graph-lane-colors.ts +194 -0
  130. package/src/utils/formatters/migration-graph-layout.ts +51 -7
  131. package/src/utils/formatters/migration-graph-rows.ts +128 -15
  132. package/src/utils/formatters/migration-graph-space-render.ts +138 -0
  133. package/src/utils/formatters/migration-graph-tree-render.ts +405 -77
  134. package/src/utils/formatters/migration-list-data-column.ts +4 -91
  135. package/src/utils/formatters/migration-list-graph-topology.ts +68 -90
  136. package/src/utils/formatters/migration-list-render.ts +122 -70
  137. package/src/utils/formatters/migration-list-styler.ts +48 -5
  138. package/src/utils/formatters/migration-log-table.ts +200 -0
  139. package/src/utils/formatters/migrations.ts +25 -1
  140. package/src/utils/global-flags.ts +35 -0
  141. package/src/utils/legend.ts +38 -0
  142. package/src/utils/migration-path-target.ts +39 -0
  143. package/src/utils/telemetry.ts +68 -32
  144. package/dist/client-KgJorIvG.mjs.map +0 -1
  145. package/dist/command-helpers-Bbw1GbwL.mjs.map +0 -1
  146. package/dist/commands/migration-list.mjs.map +0 -1
  147. package/dist/commands/migration-log.mjs.map +0 -1
  148. package/dist/commands/migration-status.mjs.map +0 -1
  149. package/dist/extension-pack-inputs-IDvjRCi3.mjs +0 -62
  150. package/dist/extension-pack-inputs-IDvjRCi3.mjs.map +0 -1
  151. package/dist/graph-render-rFAqZujX.mjs +0 -1081
  152. package/dist/graph-render-rFAqZujX.mjs.map +0 -1
  153. package/dist/init-Cv9UzWL5.mjs.map +0 -1
  154. package/dist/migration-check-BiBJoYYW.mjs.map +0 -1
  155. package/dist/migration-graph-D7DVUElV.mjs +0 -1232
  156. package/dist/migration-graph-D7DVUElV.mjs.map +0 -1
  157. package/dist/migration-list-styler-BRwF4-gy.mjs +0 -399
  158. package/dist/migration-list-styler-BRwF4-gy.mjs.map +0 -1
  159. package/dist/migration-types-D2FW63pr.d.mts +0 -15
  160. package/dist/migration-types-D2FW63pr.d.mts.map +0 -1
  161. package/dist/migrations-Cv2jxNNK.mjs +0 -228
  162. package/dist/migrations-Cv2jxNNK.mjs.map +0 -1
  163. package/dist/types-Dt_SfqFm.d.mts.map +0 -1
  164. package/src/utils/formatters/graph-migration-mapper.ts +0 -235
  165. package/src/utils/formatters/graph-render.ts +0 -1323
  166. package/src/utils/formatters/graph-types.ts +0 -120
@@ -1,5 +1,5 @@
1
- import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';
2
1
  import type { MigrationGraph } from '@prisma-next/migration-tools/graph';
2
+ import { ifDefined } from '@prisma-next/utils/defined';
3
3
  import { ok, type Result } from '@prisma-next/utils/result';
4
4
  import { Command } from 'commander';
5
5
  import { loadConfig } from '../config-loader';
@@ -12,40 +12,89 @@ import {
12
12
  setCommandSeeAlso,
13
13
  } from '../utils/command-helpers';
14
14
  import { buildReadAggregate } from '../utils/contract-space-aggregate-loader';
15
- import { migrationGraphToRenderInput } from '../utils/formatters/graph-migration-mapper';
16
- import { graphRenderer } from '../utils/formatters/graph-render';
17
- import { buildMigrationGraphLayout } from '../utils/formatters/migration-graph-layout';
18
- import { buildMigrationGraphRows } from '../utils/formatters/migration-graph-rows';
19
- import { renderMigrationGraphTree } from '../utils/formatters/migration-graph-tree-render';
15
+ import {
16
+ computeGlobalMaxDirNameWidth,
17
+ computeGlobalMaxEdgeTreePrefixWidth,
18
+ indentMigrationGraphTreeBlock,
19
+ renderMigrationGraphSpaceTree,
20
+ } from '../utils/formatters/migration-graph-space-render';
21
+ import { renderMigrationGraphLegend } from '../utils/formatters/migration-graph-tree-render';
20
22
  import { formatStyledHeader } from '../utils/formatters/styled';
21
23
  import type { CommonCommandOptions } from '../utils/global-flags';
22
24
  import { type GlobalFlags, parseGlobalFlagsOrExit } from '../utils/global-flags';
23
- import type { StatusRef } from '../utils/migration-types';
25
+ import { shouldShowLegend, validateLegendOptions } from '../utils/legend';
24
26
  import { handleResult } from '../utils/result-handler';
25
27
  import { createTerminalUI, type TerminalUI } from '../utils/terminal-ui';
28
+ import {
29
+ listRefsByContractHash,
30
+ migrationSpaceListEntriesFromAggregate,
31
+ runMigrationList,
32
+ } from './migration-list';
26
33
 
27
34
  interface MigrationGraphOptions extends CommonCommandOptions {
28
35
  readonly config?: string;
29
36
  readonly dot?: boolean;
30
- readonly tree?: boolean;
37
+ readonly space?: string;
31
38
  readonly ascii?: boolean;
39
+ readonly legend?: boolean;
40
+ }
41
+
42
+ export interface MigrationGraphTreeSection {
43
+ readonly spaceId: string;
44
+ readonly tree: string;
45
+ readonly showHeading: boolean;
32
46
  }
33
47
 
34
48
  export interface MigrationGraphResult {
35
49
  readonly ok: true;
50
+ /** App-space graph for `--json` / `--dot` (unchanged machine output). */
36
51
  readonly graph: MigrationGraph;
37
- readonly contractHash: string | null;
38
- readonly refs: readonly StatusRef[];
52
+ readonly treeSections: readonly MigrationGraphTreeSection[];
53
+ readonly summary: string;
54
+ }
55
+
56
+ export interface MigrationGraphJsonEdge {
57
+ readonly dirName: string;
58
+ readonly from: string;
59
+ readonly to: string;
60
+ readonly migrationHash: string;
61
+ }
62
+
63
+ export interface MigrationGraphJsonResult {
64
+ readonly ok: true;
65
+ readonly nodes: readonly string[];
66
+ readonly edges: readonly MigrationGraphJsonEdge[];
39
67
  readonly summary: string;
40
68
  }
41
69
 
70
+ function computeGraphSummary(graph: MigrationGraph): string {
71
+ return `${graph.nodes.size} node(s), ${graph.migrationByHash.size} edge(s)`;
72
+ }
73
+
74
+ export function formatMigrationGraphHumanOutput(result: MigrationGraphResult): string {
75
+ const sections: string[] = [];
76
+ for (const section of result.treeSections) {
77
+ if (section.showHeading) {
78
+ sections.push(`${section.spaceId}:`);
79
+ }
80
+ if (section.tree.length > 0) {
81
+ sections.push(section.tree);
82
+ } else {
83
+ sections.push('(no migrations)');
84
+ }
85
+ sections.push('');
86
+ }
87
+ sections.push(result.summary);
88
+ return sections.join('\n').trimEnd();
89
+ }
90
+
42
91
  export async function executeMigrationGraphCommand(
43
92
  options: MigrationGraphOptions,
44
93
  flags: GlobalFlags,
45
94
  ui: TerminalUI,
46
95
  ): Promise<Result<MigrationGraphResult, CliStructuredError>> {
47
96
  const config = await loadConfig(options.config);
48
- const { configPath, appMigrationsRelative, migrationsDir } = resolveMigrationPaths(
97
+ const { configPath, migrationsRelative, migrationsDir } = resolveMigrationPaths(
49
98
  options.config,
50
99
  config,
51
100
  );
@@ -56,11 +105,21 @@ export async function executeMigrationGraphCommand(
56
105
  description: 'Show the migration graph topology',
57
106
  details: [
58
107
  { label: 'config', value: configPath },
59
- { label: 'migrations', value: appMigrationsRelative },
108
+ { label: 'migrations', value: migrationsRelative },
109
+ ...(options.space !== undefined ? [{ label: 'space', value: options.space }] : []),
60
110
  ],
61
111
  flags,
62
112
  });
63
113
  ui.stderr(header);
114
+ if (shouldShowLegend(options, flags)) {
115
+ ui.stderr(
116
+ renderMigrationGraphLegend({
117
+ colorize: flags.color !== false,
118
+ glyphMode: ui.resolveGlyphMode(options.ascii === true),
119
+ }),
120
+ );
121
+ ui.stderr('');
122
+ }
64
123
  }
65
124
 
66
125
  const loaded = await buildReadAggregate(config, { migrationsDir });
@@ -68,20 +127,72 @@ export async function executeMigrationGraphCommand(
68
127
  return loaded;
69
128
  }
70
129
 
71
- const { aggregate, contractHash } = loaded.value;
72
- const graph = aggregate.app.graph();
73
- const refs: readonly StatusRef[] = Object.entries(aggregate.app.refs).map(([name, entry]) => ({
74
- name,
75
- hash: entry.hash,
76
- active: false,
77
- }));
130
+ const { aggregate, contractHash: liveContractHash } = loaded.value;
131
+ const appGraph = aggregate.app.graph();
132
+
133
+ const listSpaces = await migrationSpaceListEntriesFromAggregate(aggregate, migrationsDir);
134
+ const listResult = runMigrationList({
135
+ spaces: listSpaces,
136
+ ...ifDefined('spaceFilter', options.space),
137
+ });
138
+ if (!listResult.ok) {
139
+ return listResult;
140
+ }
141
+
142
+ const scopedSpaces = listResult.value.spaces;
143
+ const showSpaceHeadings = scopedSpaces.length > 1;
144
+ const glyphMode = ui.resolveGlyphMode(options.ascii === true);
145
+ const colorize = flags.color !== false;
146
+
147
+ const globalLayoutInputs = showSpaceHeadings
148
+ ? scopedSpaces
149
+ .filter((spaceEntry) => spaceEntry.migrations.length > 0)
150
+ .map((spaceEntry) => ({
151
+ graph: aggregate.space(spaceEntry.spaceId)!.graph(),
152
+ liveContractHash,
153
+ }))
154
+ : [];
155
+ const globalMaxEdgeTreePrefixWidth =
156
+ globalLayoutInputs.length > 0
157
+ ? computeGlobalMaxEdgeTreePrefixWidth(globalLayoutInputs)
158
+ : undefined;
159
+ const globalMaxDirNameWidth =
160
+ globalLayoutInputs.length > 0 ? computeGlobalMaxDirNameWidth(globalLayoutInputs) : undefined;
161
+
162
+ const treeSections: MigrationGraphTreeSection[] = [];
163
+ for (const spaceEntry of scopedSpaces) {
164
+ const member = aggregate.space(spaceEntry.spaceId);
165
+ if (member === undefined) {
166
+ continue;
167
+ }
168
+ const graph = member.graph();
169
+ const tree =
170
+ spaceEntry.migrations.length === 0
171
+ ? ''
172
+ : renderMigrationGraphSpaceTree({
173
+ graph,
174
+ migrations: spaceEntry.migrations,
175
+ liveContractHash,
176
+ glyphMode,
177
+ colorize,
178
+ refsByHash: listRefsByContractHash(member),
179
+ ...(globalMaxEdgeTreePrefixWidth !== undefined ? { globalMaxEdgeTreePrefixWidth } : {}),
180
+ ...(globalMaxDirNameWidth !== undefined ? { globalMaxDirNameWidth } : {}),
181
+ });
182
+ const displayTree =
183
+ showSpaceHeadings && tree.length > 0 ? indentMigrationGraphTreeBlock(tree, ' ') : tree;
184
+ treeSections.push({
185
+ spaceId: spaceEntry.spaceId,
186
+ tree: displayTree,
187
+ showHeading: showSpaceHeadings,
188
+ });
189
+ }
78
190
 
79
191
  return ok({
80
192
  ok: true,
81
- graph,
82
- contractHash,
83
- refs,
84
- summary: `${graph.nodes.size} node(s), ${graph.migrationByHash.size} edge(s)`,
193
+ graph: appGraph,
194
+ treeSections,
195
+ summary: computeGraphSummary(appGraph),
85
196
  });
86
197
  }
87
198
 
@@ -90,18 +201,19 @@ export function createMigrationGraphCommand(): Command {
90
201
  setCommandDescriptions(
91
202
  command,
92
203
  'Show the migration graph topology',
93
- 'Renders the migration graph topology. Offline — does not consult\n' +
94
- 'the database. Use --tree for the condensed annotated tree\n' +
95
- '(--ascii swaps box-drawing for pipe-friendly ASCII glyphs),\n' +
96
- '--json for machine-readable output, or --dot for Graphviz DOT\n' +
204
+ 'Renders the migration graph topology.\n' +
205
+ 'Offline does not consult the database.\n' +
206
+ '--ascii swaps box-drawing for pipe-friendly ASCII glyphs.\n' +
207
+ 'Use --json for machine-readable output, or --dot for Graphviz DOT\n' +
97
208
  'format.',
98
209
  );
99
210
  setCommandExamples(command, [
100
211
  'prisma-next migration graph',
101
212
  'prisma-next migration graph --json',
102
213
  'prisma-next migration graph --dot',
103
- 'prisma-next migration graph --tree',
104
- 'prisma-next migration graph --tree --ascii',
214
+ 'prisma-next migration graph --ascii',
215
+ 'prisma-next migration graph --legend',
216
+ 'prisma-next migration graph --space app',
105
217
  ]);
106
218
  setCommandSeeAlso(command, [
107
219
  { verb: 'migration status', oneLiner: 'Show migration path and pending status' },
@@ -111,19 +223,19 @@ export function createMigrationGraphCommand(): Command {
111
223
  ]);
112
224
  addGlobalOptions(command)
113
225
  .option('--config <path>', 'Path to prisma-next.config.ts')
226
+ .option('--space <id>', 'Narrow output to a single contract space')
114
227
  .option('--dot', 'Output in Graphviz DOT format')
115
- .option('--tree', 'Experimental condensed annotated tree renderer')
116
- .option('--ascii', 'Use ASCII glyphs for --tree (pipe-friendly)')
228
+ .option('--ascii', 'Use ASCII glyphs (pipe-friendly)')
229
+ .option('--legend', 'Print a key for the tree glyphs and lane colors')
117
230
  .action(async (options: MigrationGraphOptions) => {
118
231
  const flags = parseGlobalFlagsOrExit(options);
119
232
  const ui = createTerminalUI(flags);
233
+ const legendValidation = validateLegendOptions(options, flags);
234
+ if (!legendValidation.ok) {
235
+ process.exit(handleResult(legendValidation, flags, ui));
236
+ }
120
237
  const result = await executeMigrationGraphCommand(options, flags, ui);
121
238
  const exitCode = handleResult(result, flags, ui, (graphResult) => {
122
- // Explicit format flags win over the auto-JSON default. `flags.json`
123
- // is auto-enabled when stdout is non-TTY (per CLI Style Guide §
124
- // JSON Semantics); without this ordering, `migration graph --dot |
125
- // dot -Tsvg` pipes JSON into the GraphViz binary, which then
126
- // errors. `--dot` is the more specific instruction; honour it.
127
239
  if (options.dot) {
128
240
  const lines = ['digraph migrations {'];
129
241
  for (const edge of graphResult.graph.migrationByHash.values()) {
@@ -135,62 +247,23 @@ export function createMigrationGraphCommand(): Command {
135
247
  ui.output(lines.join('\n'));
136
248
  } else if (flags.json) {
137
249
  const nodes = [...graphResult.graph.nodes];
138
- const edges = [...graphResult.graph.migrationByHash.values()].map((e) => ({
139
- dirName: e.dirName,
140
- from: e.from,
141
- to: e.to,
142
- migrationHash: e.migrationHash,
143
- }));
144
- ui.output(
145
- JSON.stringify({ ok: true, nodes, edges, summary: graphResult.summary }, null, 2),
250
+ const edges = [...graphResult.graph.migrationByHash.values()].map(
251
+ (e): MigrationGraphJsonEdge => ({
252
+ dirName: e.dirName,
253
+ from: e.from,
254
+ to: e.to,
255
+ migrationHash: e.migrationHash,
256
+ }),
146
257
  );
258
+ const jsonResult: MigrationGraphJsonResult = {
259
+ ok: true,
260
+ nodes,
261
+ edges,
262
+ summary: `${graphResult.graph.nodes.size} node(s), ${graphResult.graph.migrationByHash.size} edge(s)`,
263
+ };
264
+ ui.output(JSON.stringify(jsonResult, null, 2));
147
265
  } else if (!flags.quiet) {
148
- if (options.tree) {
149
- const refsByHash = new Map<string, string[]>();
150
- for (const ref of graphResult.refs) {
151
- const existing = refsByHash.get(ref.hash);
152
- refsByHash.set(ref.hash, existing ? [...existing, ref.name] : [ref.name]);
153
- }
154
- const rowModel = buildMigrationGraphRows(graphResult.graph, {
155
- ...(graphResult.contractHash !== null
156
- ? { contractHash: graphResult.contractHash }
157
- : {}),
158
- });
159
- const layout = buildMigrationGraphLayout(rowModel);
160
- const activeRef = graphResult.refs.find((ref) => ref.active);
161
- const treeOutput = renderMigrationGraphTree(layout, {
162
- refsByHash,
163
- ...(graphResult.contractHash !== null
164
- ? { contractHash: graphResult.contractHash }
165
- : {}),
166
- ...(activeRef !== undefined ? { activeRefName: activeRef.name } : {}),
167
- colorize: flags.color !== false,
168
- glyphMode: ui.resolveGlyphMode(options.ascii === true),
169
- });
170
- // Emit the rendered tree to stdout (same stream as flat `migration list`),
171
- // not through clack's `log.message` rail: the graph is the command's
172
- // result (and its own box-drawing is the only vertical structure it
173
- // should carry), not a status line that needs the prompt gutter.
174
- ui.output(treeOutput);
175
- ui.output(`\n${graphResult.summary}`);
176
- } else {
177
- const renderInput = migrationGraphToRenderInput({
178
- graph: graphResult.graph,
179
- mode: 'offline',
180
- markerHash: undefined,
181
- contractHash: graphResult.contractHash ?? EMPTY_CONTRACT_HASH,
182
- refs: graphResult.refs,
183
- activeRefHash: undefined,
184
- activeRefName: undefined,
185
- edgeStatuses: [],
186
- });
187
- const graphOutput = graphRenderer.render(renderInput.graph, {
188
- ...renderInput.options,
189
- colorize: flags.color !== false,
190
- });
191
- ui.log(graphOutput);
192
- ui.log(`\n${graphResult.summary}`);
193
- }
266
+ ui.output(formatMigrationGraphHumanOutput(graphResult));
194
267
  }
195
268
  });
196
269
  process.exit(exitCode);
@@ -2,6 +2,7 @@ import type {
2
2
  ContractSpaceAggregate,
3
3
  ContractSpaceMember,
4
4
  } from '@prisma-next/migration-tools/aggregate';
5
+ import type { MigrationGraph } from '@prisma-next/migration-tools/graph';
5
6
  import { HEAD_REF_NAME, refsByContractHash } from '@prisma-next/migration-tools/refs';
6
7
  import {
7
8
  APP_SPACE_ID,
@@ -26,10 +27,8 @@ import {
26
27
  setCommandSeeAlso,
27
28
  } from '../utils/command-helpers';
28
29
  import { buildReadAggregate } from '../utils/contract-space-aggregate-loader';
29
- import {
30
- buildMigrationListTopologyBySpace,
31
- renderMigrationListWithStyle,
32
- } from '../utils/formatters/migration-list-render';
30
+ import { renderMigrationGraphLegend } from '../utils/formatters/migration-graph-tree-render';
31
+ import { renderMigrationListWithStyle } from '../utils/formatters/migration-list-render';
33
32
  import { createAnsiMigrationListStyler } from '../utils/formatters/migration-list-styler';
34
33
  import type {
35
34
  MigrationListEntry,
@@ -40,6 +39,7 @@ import { formatStyledHeader } from '../utils/formatters/styled';
40
39
  import type { CommonCommandOptions } from '../utils/global-flags';
41
40
  import { type GlobalFlags, parseGlobalFlagsOrExit } from '../utils/global-flags';
42
41
  import type { GlyphMode } from '../utils/glyph-mode';
42
+ import { shouldShowLegend, validateLegendOptions } from '../utils/legend';
43
43
  import { handleResult } from '../utils/result-handler';
44
44
  import { createTerminalUI, type TerminalUI } from '../utils/terminal-ui';
45
45
 
@@ -65,7 +65,7 @@ function compareDirNamesDescending(a: MigrationListEntry, b: MigrationListEntry)
65
65
  * keep that output. The app space synthesises its head, so it carries
66
66
  * no on-disk `head` ref to restore.
67
67
  */
68
- function listRefsByContractHash(
68
+ export function listRefsByContractHash(
69
69
  member: ContractSpaceMember,
70
70
  ): ReadonlyMap<string, readonly string[]> {
71
71
  const byHash = new Map(refsByContractHash(member.refs));
@@ -131,11 +131,20 @@ interface MigrationListOptions extends CommonCommandOptions {
131
131
  readonly config?: string;
132
132
  readonly space?: string;
133
133
  readonly ascii?: boolean;
134
+ readonly legend?: boolean;
135
+ }
136
+
137
+ export interface MigrationListExecuteResult {
138
+ readonly list: MigrationListResult;
139
+ readonly liveContractHash: string;
140
+ readonly aggregate: ContractSpaceAggregate;
134
141
  }
135
142
 
136
143
  export interface MigrationListHumanRenderOptions {
137
144
  readonly glyphMode: GlyphMode;
138
145
  readonly useColor: boolean;
146
+ readonly liveContractHash: string;
147
+ readonly graphForSpace: (spaceId: string) => MigrationGraph | undefined;
139
148
  }
140
149
 
141
150
  export function renderMigrationListHumanOutput(
@@ -143,8 +152,11 @@ export function renderMigrationListHumanOutput(
143
152
  options: MigrationListHumanRenderOptions,
144
153
  ): string {
145
154
  const styler = createAnsiMigrationListStyler({ useColor: options.useColor });
146
- const topologyBySpaceId = buildMigrationListTopologyBySpace(result);
147
- return renderMigrationListWithStyle(result, styler, options.glyphMode, topologyBySpaceId);
155
+ return renderMigrationListWithStyle(result, styler, options.glyphMode, {
156
+ colorize: options.useColor,
157
+ liveContractHash: options.liveContractHash,
158
+ graphForSpace: options.graphForSpace,
159
+ });
148
160
  }
149
161
 
150
162
  /**
@@ -212,7 +224,7 @@ export async function executeMigrationListCommand(
212
224
  options: MigrationListOptions,
213
225
  flags: GlobalFlags,
214
226
  ui: TerminalUI,
215
- ): Promise<Result<MigrationListResult, CliStructuredError>> {
227
+ ): Promise<Result<MigrationListExecuteResult, CliStructuredError>> {
216
228
  const config = await loadConfig(options.config);
217
229
  const { configPath, migrationsDir, migrationsRelative } = resolveMigrationPaths(
218
230
  options.config,
@@ -222,7 +234,7 @@ export async function executeMigrationListCommand(
222
234
  if (!flags.json && !flags.quiet) {
223
235
  const header = formatStyledHeader({
224
236
  command: 'migration list',
225
- description: 'List on-disk migrations, latest first, per contract space',
237
+ description: 'List on-disk migrations per contract space',
226
238
  details: [
227
239
  { label: 'config', value: configPath },
228
240
  { label: 'migrations', value: migrationsRelative },
@@ -231,6 +243,15 @@ export async function executeMigrationListCommand(
231
243
  flags,
232
244
  });
233
245
  ui.stderr(header);
246
+ if (shouldShowLegend(options, flags)) {
247
+ ui.stderr(
248
+ renderMigrationGraphLegend({
249
+ colorize: flags.color !== false,
250
+ glyphMode: ui.resolveGlyphMode(options.ascii === true),
251
+ }),
252
+ );
253
+ ui.stderr('');
254
+ }
234
255
  }
235
256
 
236
257
  const loaded = await buildReadAggregate(config, { migrationsDir });
@@ -238,35 +259,37 @@ export async function executeMigrationListCommand(
238
259
  return notOk(loaded.failure);
239
260
  }
240
261
 
241
- const spaces = await migrationSpaceListEntriesFromAggregate(
242
- loaded.value.aggregate,
243
- migrationsDir,
244
- );
262
+ const { aggregate, contractHash: liveContractHash } = loaded.value;
245
263
 
246
- return runMigrationList({
264
+ const spaces = await migrationSpaceListEntriesFromAggregate(aggregate, migrationsDir);
265
+
266
+ const listResult = runMigrationList({
247
267
  spaces,
248
268
  ...ifDefined('spaceFilter', options.space),
249
269
  });
270
+ if (!listResult.ok) {
271
+ return listResult;
272
+ }
273
+ return ok({ list: listResult.value, liveContractHash, aggregate });
250
274
  }
251
275
 
252
276
  export function createMigrationListCommand(): Command {
253
277
  const command = new Command('list');
254
278
  setCommandDescriptions(
255
279
  command,
256
- 'List on-disk migrations, latest first, per contract space',
280
+ 'List on-disk migrations per contract space',
257
281
  'Enumerates every on-disk migration under migrations/<space>/ for every\n' +
258
- 'contract space found on disk, latest first. Offline — does not consult\n' +
259
- 'the database. Each row leads with a kind glyph (* forward, ↩ rollback,\n' +
260
- ' self), then dirName, then source destination contract hashes\n' +
261
- '(7-char git-style). Self-edges show a single hash. Invariants render as\n' +
262
- '{...}; refs on the destination as (production, db). Pass --space <id>\n' +
263
- 'to narrow to one contract space. --ascii forces ASCII kind glyphs\n' +
264
- '(orthogonal to --no-color).',
282
+ 'contract space found on disk. Offline — does not consult the database.\n' +
283
+ 'Human output draws the shared migration graph tree with operation counts,\n' +
284
+ 'invariants on each migration row, and refs on destination contract nodes.\n' +
285
+ 'Pass --space <id> to narrow to one contract space. --ascii forces ASCII\n' +
286
+ 'tree glyphs (orthogonal to --no-color).',
265
287
  );
266
288
  setCommandExamples(command, [
267
289
  'prisma-next migration list',
268
290
  'prisma-next migration list --space app',
269
291
  'prisma-next migration list --ascii',
292
+ 'prisma-next migration list --legend',
270
293
  'prisma-next migration list --json',
271
294
  ]);
272
295
  setCommandSeeAlso(command, [
@@ -279,18 +302,25 @@ export function createMigrationListCommand(): Command {
279
302
  .option('--config <path>', 'Path to prisma-next.config.ts')
280
303
  .option('--space <id>', 'Narrow output to a single contract space')
281
304
  .option('--ascii', 'Use ASCII kind glyphs (pipe-friendly)')
305
+ .option('--legend', 'Print a key for the tree glyphs and lane colors')
282
306
  .action(async (options: MigrationListOptions) => {
283
307
  const flags = parseGlobalFlagsOrExit(options);
284
308
  const ui = createTerminalUI(flags);
309
+ const legendValidation = validateLegendOptions(options, flags);
310
+ if (!legendValidation.ok) {
311
+ process.exit(handleResult(legendValidation, flags, ui));
312
+ }
285
313
  const result = await executeMigrationListCommand(options, flags, ui);
286
- const exitCode = handleResult(result, flags, ui, (listResult) => {
314
+ const exitCode = handleResult(result, flags, ui, ({ list, liveContractHash, aggregate }) => {
287
315
  if (flags.json) {
288
- ui.output(JSON.stringify(listResult, null, 2));
316
+ ui.output(JSON.stringify(list, null, 2));
289
317
  } else if (!flags.quiet) {
290
318
  ui.output(
291
- renderMigrationListHumanOutput(listResult, {
319
+ renderMigrationListHumanOutput(list, {
292
320
  glyphMode: ui.resolveGlyphMode(options.ascii === true),
293
321
  useColor: ui.useColor,
322
+ liveContractHash,
323
+ graphForSpace: (spaceId) => aggregate.space(spaceId)?.graph(),
294
324
  }),
295
325
  );
296
326
  }