@prisma-next/cli 0.12.0-dev.3 → 0.12.0-dev.30

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 (149) hide show
  1. package/dist/cli.mjs +180 -163
  2. package/dist/cli.mjs.map +1 -1
  3. package/dist/{client-KgJorIvG.mjs → client-xeWpMlq1.mjs} +39 -15
  4. package/dist/client-xeWpMlq1.mjs.map +1 -0
  5. package/dist/{command-helpers-Bbw1GbwL.mjs → command-helpers-DK_5ItoJ.mjs} +284 -24
  6. package/dist/command-helpers-DK_5ItoJ.mjs.map +1 -0
  7. package/dist/commands/contract-emit.mjs +1 -1
  8. package/dist/commands/contract-infer.mjs +1 -1
  9. package/dist/commands/db-init.mjs +4 -5
  10. package/dist/commands/db-init.mjs.map +1 -1
  11. package/dist/commands/db-schema.mjs +3 -3
  12. package/dist/commands/db-sign.mjs +4 -4
  13. package/dist/commands/db-update.d.mts.map +1 -1
  14. package/dist/commands/db-update.mjs +10 -7
  15. package/dist/commands/db-update.mjs.map +1 -1
  16. package/dist/commands/db-verify.mjs +1 -1
  17. package/dist/commands/migrate.d.mts +1 -1
  18. package/dist/commands/migrate.mjs +5 -6
  19. package/dist/commands/migrate.mjs.map +1 -1
  20. package/dist/commands/migration-check.mjs +1 -1
  21. package/dist/commands/migration-graph.d.mts +13 -7
  22. package/dist/commands/migration-graph.d.mts.map +1 -1
  23. package/dist/commands/migration-graph.mjs +171 -2
  24. package/dist/commands/migration-graph.mjs.map +1 -0
  25. package/dist/commands/migration-list.d.mts +24 -26
  26. package/dist/commands/migration-list.d.mts.map +1 -1
  27. package/dist/commands/migration-list.mjs +2 -190
  28. package/dist/commands/migration-log.d.mts +6 -18
  29. package/dist/commands/migration-log.d.mts.map +1 -1
  30. package/dist/commands/migration-log.mjs +1 -137
  31. package/dist/commands/migration-new.mjs +3 -3
  32. package/dist/commands/migration-plan.d.mts +1 -1
  33. package/dist/commands/migration-plan.mjs +1 -1
  34. package/dist/commands/migration-show.d.mts +1 -1
  35. package/dist/commands/migration-show.mjs +3 -4
  36. package/dist/commands/migration-show.mjs.map +1 -1
  37. package/dist/commands/migration-status.d.mts +41 -141
  38. package/dist/commands/migration-status.d.mts.map +1 -1
  39. package/dist/commands/migration-status.mjs +2 -759
  40. package/dist/commands/ref.d.mts +1 -1
  41. package/dist/commands/ref.mjs +3 -3
  42. package/dist/commands/telemetry/index.d.mts +7 -0
  43. package/dist/commands/telemetry/index.d.mts.map +1 -0
  44. package/dist/commands/telemetry/index.mjs +2 -0
  45. package/dist/{contract-at-errors-BxP-TOMl.mjs → contract-at-errors-DG3kjgoz.mjs} +2 -2
  46. package/dist/{contract-at-errors-BxP-TOMl.mjs.map → contract-at-errors-DG3kjgoz.mjs.map} +1 -1
  47. package/dist/{contract-emit-D-4jrNve.mjs → contract-emit-BO0l6fnT.mjs} +3 -3
  48. package/dist/{contract-emit-D-4jrNve.mjs.map → contract-emit-BO0l6fnT.mjs.map} +1 -1
  49. package/dist/{contract-emit-DxcGl4Uq.mjs → contract-emit-C0Bs0VRj.mjs} +3 -3
  50. package/dist/{contract-emit-DxcGl4Uq.mjs.map → contract-emit-C0Bs0VRj.mjs.map} +1 -1
  51. package/dist/{contract-infer-D8uEbJuu.mjs → contract-infer-2wtPflGH.mjs} +3 -3
  52. package/dist/{contract-infer-D8uEbJuu.mjs.map → contract-infer-2wtPflGH.mjs.map} +1 -1
  53. package/dist/{contract-space-aggregate-loader-DvZwdkrr.mjs → contract-space-aggregate-loader-Dbr3-jHF.mjs} +4 -4
  54. package/dist/{contract-space-aggregate-loader-DvZwdkrr.mjs.map → contract-space-aggregate-loader-Dbr3-jHF.mjs.map} +1 -1
  55. package/dist/{db-verify-v_vUKXTU.mjs → db-verify-CxHiSiTG.mjs} +4 -4
  56. package/dist/{db-verify-v_vUKXTU.mjs.map → db-verify-CxHiSiTG.mjs.map} +1 -1
  57. package/dist/exports/control-api.d.mts +1 -1
  58. package/dist/exports/control-api.d.mts.map +1 -1
  59. package/dist/exports/control-api.mjs +2 -2
  60. package/dist/exports/index.mjs +1 -1
  61. package/dist/exports/init-output.mjs +1 -1
  62. package/dist/{framework-components-fYXjz_in.mjs → framework-components-CxOVKAAh.mjs} +2 -2
  63. package/dist/{framework-components-fYXjz_in.mjs.map → framework-components-CxOVKAAh.mjs.map} +1 -1
  64. package/dist/{global-flags-DEHjV8_s.d.mts → global-flags-DG4uY5tV.d.mts} +1 -1
  65. package/dist/{global-flags-DEHjV8_s.d.mts.map → global-flags-DG4uY5tV.d.mts.map} +1 -1
  66. package/dist/{init-Cv9UzWL5.mjs → init-R272pxux.mjs} +5 -58
  67. package/dist/init-R272pxux.mjs.map +1 -0
  68. package/dist/{inspect-live-schema-C6ohV_oQ.mjs → inspect-live-schema-RekOwfi5.mjs} +3 -3
  69. package/dist/{inspect-live-schema-C6ohV_oQ.mjs.map → inspect-live-schema-RekOwfi5.mjs.map} +1 -1
  70. package/dist/{migration-check-BiBJoYYW.mjs → migration-check-Dc0cOhKH.mjs} +2 -2
  71. package/dist/{migration-check-BiBJoYYW.mjs.map → migration-check-Dc0cOhKH.mjs.map} +1 -1
  72. package/dist/{migration-command-scaffold-CjvwO6at.mjs → migration-command-scaffold-ApB3NxWY.mjs} +3 -3
  73. package/dist/{migration-command-scaffold-CjvwO6at.mjs.map → migration-command-scaffold-ApB3NxWY.mjs.map} +1 -1
  74. package/dist/migration-graph-space-render-dmLLWift.mjs +1966 -0
  75. package/dist/migration-graph-space-render-dmLLWift.mjs.map +1 -0
  76. package/dist/migration-list-C5sXrl0U.mjs +228 -0
  77. package/dist/migration-list-C5sXrl0U.mjs.map +1 -0
  78. package/dist/migration-list-types-DS63IdFd.d.mts +23 -0
  79. package/dist/migration-list-types-DS63IdFd.d.mts.map +1 -0
  80. package/dist/migration-log-DD_vCbYW.mjs +203 -0
  81. package/dist/migration-log-DD_vCbYW.mjs.map +1 -0
  82. package/dist/{migration-plan-9DJ7q7_z.mjs → migration-plan-CeTjQOIG.mjs} +5 -5
  83. package/dist/{migration-plan-9DJ7q7_z.mjs.map → migration-plan-CeTjQOIG.mjs.map} +1 -1
  84. package/dist/migration-status-qV8ctwPy.mjs +432 -0
  85. package/dist/migration-status-qV8ctwPy.mjs.map +1 -0
  86. package/dist/{output-B60Gw5fu.mjs → output-CF_hqzI-.mjs} +1 -1
  87. package/dist/{output-B60Gw5fu.mjs.map → output-CF_hqzI-.mjs.map} +1 -1
  88. package/dist/{ref-advancement-DUZqsue6.mjs → ref-advancement-V1o-9LVK.mjs} +1 -1
  89. package/dist/{ref-advancement-DUZqsue6.mjs.map → ref-advancement-V1o-9LVK.mjs.map} +1 -1
  90. package/dist/telemetry-S-NGi9U6.mjs +122 -0
  91. package/dist/telemetry-S-NGi9U6.mjs.map +1 -0
  92. package/dist/{types-Dt_SfqFm.d.mts → types-Mh7mdPHM.d.mts} +13 -2
  93. package/dist/types-Mh7mdPHM.d.mts.map +1 -0
  94. package/dist/{verify-DCA9Sldu.mjs → verify-BdI-BgYi.mjs} +2 -2
  95. package/dist/{verify-DCA9Sldu.mjs.map → verify-BdI-BgYi.mjs.map} +1 -1
  96. package/package.json +22 -19
  97. package/src/cli.ts +5 -0
  98. package/src/commands/db-update.ts +7 -1
  99. package/src/commands/init/index.ts +6 -35
  100. package/src/commands/init/init.ts +1 -14
  101. package/src/commands/init/inputs.ts +0 -75
  102. package/src/commands/migration-graph.ts +143 -82
  103. package/src/commands/migration-list.ts +55 -25
  104. package/src/commands/migration-log.ts +23 -89
  105. package/src/commands/migration-status-overlay.ts +61 -0
  106. package/src/commands/migration-status.ts +431 -1055
  107. package/src/commands/telemetry/index.ts +107 -0
  108. package/src/commands/telemetry/status.ts +67 -0
  109. package/src/control-api/client.ts +11 -1
  110. package/src/control-api/operations/apply.ts +1 -0
  111. package/src/control-api/operations/db-apply.ts +24 -1
  112. package/src/control-api/operations/migration-apply.ts +10 -3
  113. package/src/control-api/types.ts +16 -1
  114. package/src/utils/cli-errors.ts +17 -0
  115. package/src/utils/formatters/errors.ts +11 -0
  116. package/src/utils/formatters/migration-graph-lane-colors.ts +194 -0
  117. package/src/utils/formatters/migration-graph-layout.ts +51 -7
  118. package/src/utils/formatters/migration-graph-rows.ts +128 -15
  119. package/src/utils/formatters/migration-graph-space-render.ts +138 -0
  120. package/src/utils/formatters/migration-graph-tree-render.ts +405 -77
  121. package/src/utils/formatters/migration-list-data-column.ts +4 -91
  122. package/src/utils/formatters/migration-list-graph-topology.ts +68 -90
  123. package/src/utils/formatters/migration-list-render.ts +122 -70
  124. package/src/utils/formatters/migration-list-styler.ts +48 -5
  125. package/src/utils/formatters/migration-log-table.ts +190 -0
  126. package/src/utils/formatters/migrations.ts +25 -1
  127. package/src/utils/global-flags.ts +35 -0
  128. package/src/utils/legend.ts +38 -0
  129. package/src/utils/telemetry.ts +68 -32
  130. package/dist/client-KgJorIvG.mjs.map +0 -1
  131. package/dist/command-helpers-Bbw1GbwL.mjs.map +0 -1
  132. package/dist/commands/migration-list.mjs.map +0 -1
  133. package/dist/commands/migration-log.mjs.map +0 -1
  134. package/dist/commands/migration-status.mjs.map +0 -1
  135. package/dist/graph-render-rFAqZujX.mjs +0 -1081
  136. package/dist/graph-render-rFAqZujX.mjs.map +0 -1
  137. package/dist/init-Cv9UzWL5.mjs.map +0 -1
  138. package/dist/migration-graph-D7DVUElV.mjs +0 -1232
  139. package/dist/migration-graph-D7DVUElV.mjs.map +0 -1
  140. package/dist/migration-list-styler-BRwF4-gy.mjs +0 -399
  141. package/dist/migration-list-styler-BRwF4-gy.mjs.map +0 -1
  142. package/dist/migration-types-D2FW63pr.d.mts +0 -15
  143. package/dist/migration-types-D2FW63pr.d.mts.map +0 -1
  144. package/dist/migrations-Cv2jxNNK.mjs +0 -228
  145. package/dist/migrations-Cv2jxNNK.mjs.map +0 -1
  146. package/dist/types-Dt_SfqFm.d.mts.map +0 -1
  147. package/src/utils/formatters/graph-migration-mapper.ts +0 -235
  148. package/src/utils/formatters/graph-render.ts +0 -1323
  149. package/src/utils/formatters/graph-types.ts +0 -120
@@ -1,9 +1,6 @@
1
- import type { MigrationPlanOperation } from '@prisma-next/framework-components/control';
2
- import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';
1
+ import type { LedgerEntryRecord } from '@prisma-next/contract/types';
3
2
  import { MigrationToolsError } from '@prisma-next/migration-tools/errors';
4
- import { findPath } from '@prisma-next/migration-tools/migration-graph';
5
3
  import { notOk, ok, type Result } from '@prisma-next/utils/result';
6
- import { cyan, dim } from 'colorette';
7
4
  import { Command } from 'commander';
8
5
  import { loadConfig } from '../config-loader';
9
6
  import { createControlClient } from '../control-api/client';
@@ -23,7 +20,12 @@ import {
23
20
  setCommandSeeAlso,
24
21
  targetSupportsMigrations,
25
22
  } from '../utils/command-helpers';
26
- import { buildReadAggregate } from '../utils/contract-space-aggregate-loader';
23
+ import { createAnsiMigrationListStyler } from '../utils/formatters/migration-list-styler';
24
+ import {
25
+ MIGRATION_LOG_EMPTY_MESSAGE,
26
+ renderMigrationLogTable,
27
+ serializeLedgerEntriesForJson,
28
+ } from '../utils/formatters/migration-log-table';
27
29
  import { formatStyledHeader } from '../utils/formatters/styled';
28
30
  import type { CommonCommandOptions } from '../utils/global-flags';
29
31
  import { type GlobalFlags, parseGlobalFlagsOrExit } from '../utils/global-flags';
@@ -33,34 +35,16 @@ import { createTerminalUI, type TerminalUI } from '../utils/terminal-ui';
33
35
  interface MigrationLogOptions extends CommonCommandOptions {
34
36
  readonly db?: string;
35
37
  readonly config?: string;
36
- }
37
-
38
- export interface MigrationLogEntry {
39
- readonly dirName: string;
40
- readonly from: string;
41
- readonly to: string;
42
- readonly migrationHash: string;
43
- readonly operationCount: number;
44
- readonly createdAt: string;
45
- }
46
-
47
- export interface MigrationLogResult {
48
- readonly ok: true;
49
- readonly markerHash: string | null;
50
- readonly applied: readonly MigrationLogEntry[];
51
- readonly summary: string;
38
+ readonly utc?: boolean;
52
39
  }
53
40
 
54
41
  export async function executeMigrationLogCommand(
55
42
  options: MigrationLogOptions,
56
43
  flags: GlobalFlags,
57
44
  ui: TerminalUI,
58
- ): Promise<Result<MigrationLogResult, CliStructuredError>> {
45
+ ): Promise<Result<readonly LedgerEntryRecord[], CliStructuredError>> {
59
46
  const config = await loadConfig(options.config);
60
- const { configPath, appMigrationsRelative, migrationsDir } = resolveMigrationPaths(
61
- options.config,
62
- config,
63
- );
47
+ const { configPath } = resolveMigrationPaths(options.config, config);
64
48
 
65
49
  const dbConnection = options.db ?? config.db?.connection;
66
50
  if (!dbConnection) {
@@ -81,10 +65,9 @@ export async function executeMigrationLogCommand(
81
65
  if (!flags.json && !flags.quiet) {
82
66
  const header = formatStyledHeader({
83
67
  command: 'migration log',
84
- description: 'Show executed migration history',
68
+ description: 'Show executed migration history from the database ledger',
85
69
  details: [
86
70
  { label: 'config', value: configPath },
87
- { label: 'migrations', value: appMigrationsRelative },
88
71
  ...(typeof dbConnection === 'string'
89
72
  ? [{ label: 'database', value: maskConnectionUrl(dbConnection) }]
90
73
  : []),
@@ -94,13 +77,6 @@ export async function executeMigrationLogCommand(
94
77
  ui.stderr(header);
95
78
  }
96
79
 
97
- const loaded = await buildReadAggregate(config, { migrationsDir });
98
- if (!loaded.ok) {
99
- return loaded;
100
- }
101
- const graph = loaded.value.aggregate.app.graph();
102
- const bundles = loaded.value.aggregate.app.packages;
103
-
104
80
  const client = createControlClient({
105
81
  family: config.family,
106
82
  target: config.target,
@@ -111,47 +87,8 @@ export async function executeMigrationLogCommand(
111
87
 
112
88
  try {
113
89
  await client.connect(dbConnection);
114
- const marker = await client.readMarker();
115
- const markerHash = marker?.storageHash ?? null;
116
-
117
- if (!markerHash) {
118
- return ok({
119
- ok: true,
120
- markerHash: null,
121
- applied: [],
122
- summary: 'No migrations applied (database has no marker)',
123
- });
124
- }
125
-
126
- const appliedPath = findPath(graph, EMPTY_CONTRACT_HASH, markerHash);
127
- if (appliedPath === null) {
128
- return notOk(
129
- errorUnexpected('Database marker is not reachable from migration history', {
130
- why: `Marker hash ${markerHash} is not reachable from the root of the on-disk migration graph.`,
131
- fix: 'The database may have been migrated outside this project. Use `migration status` to inspect the current state.',
132
- }),
133
- );
134
- }
135
- const pkgByDirName = new Map(bundles.map((p) => [p.dirName, p]));
136
- const entries: MigrationLogEntry[] = appliedPath.map((edge) => {
137
- const pkg = pkgByDirName.get(edge.dirName);
138
- const ops = (pkg?.ops ?? []) as readonly MigrationPlanOperation[];
139
- return {
140
- dirName: edge.dirName,
141
- from: edge.from,
142
- to: edge.to,
143
- migrationHash: edge.migrationHash,
144
- operationCount: ops.length,
145
- createdAt: edge.createdAt,
146
- };
147
- });
148
-
149
- return ok({
150
- ok: true,
151
- markerHash,
152
- applied: entries,
153
- summary: `${entries.length} migration(s) applied`,
154
- });
90
+ const ledger = await client.readLedger();
91
+ return ok(ledger);
155
92
  } catch (error) {
156
93
  if (CliStructuredError.is(error)) return notOk(error);
157
94
  if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));
@@ -170,11 +107,12 @@ export function createMigrationLogCommand(): Command {
170
107
  setCommandDescriptions(
171
108
  command,
172
109
  'Show executed migration history',
173
- 'Reads the database marker and displays the applied migration chain\n' +
174
- 'from the initial state to the current marker position.',
110
+ 'Reads the database ledger and displays every applied migration edge\n' +
111
+ 'in chronological order, including rollbacks and re-applies.',
175
112
  );
176
113
  setCommandExamples(command, [
177
114
  'prisma-next migration log --db $DATABASE_URL',
115
+ 'prisma-next migration log --utc --db $DATABASE_URL',
178
116
  'prisma-next migration log --json --db $DATABASE_URL',
179
117
  ]);
180
118
  setCommandSeeAlso(command, [
@@ -186,24 +124,20 @@ export function createMigrationLogCommand(): Command {
186
124
  addGlobalOptions(command)
187
125
  .option('--db <url>', 'Database connection string')
188
126
  .option('--config <path>', 'Path to prisma-next.config.ts')
127
+ .option('--utc', 'Render human timestamps in UTC instead of local time')
189
128
  .action(async (options: MigrationLogOptions) => {
190
129
  const flags = parseGlobalFlagsOrExit(options);
191
130
  const ui = createTerminalUI(flags);
192
131
  const result = await executeMigrationLogCommand(options, flags, ui);
193
- const exitCode = handleResult(result, flags, ui, (logResult) => {
132
+ const exitCode = handleResult(result, flags, ui, (entries) => {
194
133
  if (flags.json) {
195
- ui.output(JSON.stringify(logResult, null, 2));
134
+ ui.output(JSON.stringify(serializeLedgerEntriesForJson(entries), null, 2));
196
135
  } else if (!flags.quiet) {
197
- const c = (fn: (s: string) => string, s: string) => (flags.color !== false ? fn(s) : s);
198
- if (logResult.applied.length === 0) {
199
- ui.log(logResult.summary);
136
+ if (entries.length === 0) {
137
+ ui.output(MIGRATION_LOG_EMPTY_MESSAGE);
200
138
  } else {
201
- for (const entry of logResult.applied) {
202
- ui.log(
203
- `${c(cyan, '✓')} ${entry.dirName} ${c(dim, entry.migrationHash.slice(0, 16) + '…')} ${entry.operationCount} op(s)`,
204
- );
205
- }
206
- ui.log(`\n${logResult.summary}`);
139
+ const styler = createAnsiMigrationListStyler({ useColor: ui.useColor });
140
+ ui.output(renderMigrationLogTable(entries, { utc: options.utc === true, styler }));
207
141
  }
208
142
  }
209
143
  });
@@ -0,0 +1,61 @@
1
+ import type { MigrationGraph } from '@prisma-next/migration-tools/graph';
2
+ import { findPath } from '@prisma-next/migration-tools/migration-graph';
3
+ import type { MigrationEdgeAnnotation } from '../utils/formatters/migration-graph-tree-render';
4
+
5
+ export interface DeriveStatusEdgeAnnotationsInput {
6
+ readonly graph: MigrationGraph;
7
+ readonly targetHash: string;
8
+ readonly originHash: string;
9
+ readonly appliedMigrationHashes: ReadonlySet<string>;
10
+ readonly showAppliedOverlay: boolean;
11
+ }
12
+
13
+ export function deriveStatusEdgeAnnotations(
14
+ input: DeriveStatusEdgeAnnotationsInput,
15
+ ): ReadonlyMap<string, MigrationEdgeAnnotation> {
16
+ const annotations = new Map<string, MigrationEdgeAnnotation>();
17
+
18
+ if (input.showAppliedOverlay) {
19
+ for (const edge of input.graph.migrationByHash.values()) {
20
+ if (input.appliedMigrationHashes.has(edge.migrationHash)) {
21
+ annotations.set(edge.migrationHash, { status: 'applied' });
22
+ }
23
+ }
24
+ }
25
+
26
+ if (!input.graph.nodes.has(input.originHash)) {
27
+ return annotations;
28
+ }
29
+
30
+ const pendingPath = findPath(input.graph, input.originHash, input.targetHash);
31
+ if (!pendingPath) {
32
+ return annotations;
33
+ }
34
+
35
+ for (const edge of pendingPath) {
36
+ if (input.appliedMigrationHashes.has(edge.migrationHash)) {
37
+ continue;
38
+ }
39
+ const existing = annotations.get(edge.migrationHash);
40
+ if (existing?.status === 'applied') {
41
+ continue;
42
+ }
43
+ annotations.set(edge.migrationHash, { status: 'pending' });
44
+ }
45
+
46
+ return annotations;
47
+ }
48
+
49
+ export function appliedHashesFromLedger(
50
+ ledgerEntries: ReadonlyArray<{ readonly migrationHash: string }>,
51
+ ): ReadonlySet<string> {
52
+ return new Set(ledgerEntries.map((entry) => entry.migrationHash));
53
+ }
54
+
55
+ export function statusForMigrationHash(
56
+ migrationHash: string,
57
+ annotations: ReadonlyMap<string, MigrationEdgeAnnotation>,
58
+ ): 'applied' | 'pending' | null {
59
+ const status = annotations.get(migrationHash)?.status;
60
+ return status ?? null;
61
+ }