@prisma-next/cli 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -9
- package/dist/cli.mjs +259 -12
- package/dist/cli.mjs.map +1 -1
- package/dist/{client-oXO2WCPD.mjs → client-KgJorIvG.mjs} +72 -60
- package/dist/client-KgJorIvG.mjs.map +1 -0
- package/dist/{command-helpers-BSb0tRC8.mjs → command-helpers-Bbw1GbwL.mjs} +646 -46
- package/dist/command-helpers-Bbw1GbwL.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts.map +1 -1
- package/dist/commands/contract-emit.mjs +1 -1
- package/dist/commands/contract-infer.d.mts.map +1 -1
- package/dist/commands/contract-infer.mjs +1 -1
- package/dist/commands/db-init.d.mts.map +1 -1
- package/dist/commands/db-init.mjs +32 -7
- package/dist/commands/db-init.mjs.map +1 -1
- package/dist/commands/db-schema.d.mts.map +1 -1
- package/dist/commands/db-schema.mjs +3 -4
- package/dist/commands/db-schema.mjs.map +1 -1
- package/dist/commands/db-sign.d.mts.map +1 -1
- package/dist/commands/db-sign.mjs +12 -10
- package/dist/commands/db-sign.mjs.map +1 -1
- package/dist/commands/db-update.d.mts.map +1 -1
- package/dist/commands/db-update.mjs +41 -11
- package/dist/commands/db-update.mjs.map +1 -1
- package/dist/commands/db-verify.d.mts.map +1 -1
- package/dist/commands/db-verify.mjs +1 -1
- package/dist/commands/migrate.d.mts +6 -2
- package/dist/commands/migrate.d.mts.map +1 -1
- package/dist/commands/migrate.mjs +75 -40
- package/dist/commands/migrate.mjs.map +1 -1
- package/dist/commands/migration-check.d.mts +4 -3
- package/dist/commands/migration-check.d.mts.map +1 -1
- package/dist/commands/migration-check.mjs +1 -280
- package/dist/commands/migration-graph.d.mts +13 -2
- package/dist/commands/migration-graph.d.mts.map +1 -1
- package/dist/commands/migration-graph.mjs +2 -137
- package/dist/commands/migration-list.d.mts +64 -4
- package/dist/commands/migration-list.d.mts.map +1 -1
- package/dist/commands/migration-list.mjs +143 -56
- package/dist/commands/migration-list.mjs.map +1 -1
- package/dist/commands/migration-log.d.mts +10 -1
- package/dist/commands/migration-log.d.mts.map +1 -1
- package/dist/commands/migration-log.mjs +10 -15
- package/dist/commands/migration-log.mjs.map +1 -1
- package/dist/commands/migration-new.d.mts.map +1 -1
- package/dist/commands/migration-new.mjs +32 -38
- package/dist/commands/migration-new.mjs.map +1 -1
- package/dist/commands/migration-plan.d.mts +3 -2
- package/dist/commands/migration-plan.d.mts.map +1 -1
- package/dist/commands/migration-plan.mjs +1 -1
- package/dist/commands/migration-show.d.mts +4 -55
- package/dist/commands/migration-show.d.mts.map +1 -1
- package/dist/commands/migration-show.mjs +61 -153
- package/dist/commands/migration-show.mjs.map +1 -1
- package/dist/commands/migration-status.d.mts +12 -49
- package/dist/commands/migration-status.d.mts.map +1 -1
- package/dist/commands/migration-status.mjs +85 -81
- package/dist/commands/migration-status.mjs.map +1 -1
- package/dist/commands/ref.d.mts +1 -1
- package/dist/commands/ref.d.mts.map +1 -1
- package/dist/commands/ref.mjs +38 -10
- package/dist/commands/ref.mjs.map +1 -1
- package/dist/config-loader-B6sJjXTv.mjs.map +1 -1
- package/dist/config-loader.d.mts.map +1 -1
- package/dist/contract-at-errors-BxP-TOMl.mjs +42 -0
- package/dist/contract-at-errors-BxP-TOMl.mjs.map +1 -0
- package/dist/{contract-emit-bcrpT-wD.mjs → contract-emit-D-4jrNve.mjs} +25 -10
- package/dist/contract-emit-D-4jrNve.mjs.map +1 -0
- package/dist/{contract-emit-r4y8Zhf1.mjs → contract-emit-DxcGl4Uq.mjs} +19 -14
- package/dist/contract-emit-DxcGl4Uq.mjs.map +1 -0
- package/dist/{contract-enrichment-Dani0mMW.mjs → contract-enrichment-a0V5Y_mL.mjs} +4 -25
- package/dist/contract-enrichment-a0V5Y_mL.mjs.map +1 -0
- package/dist/{contract-infer-BmySmqVT.mjs → contract-infer-D8uEbJuu.mjs} +4 -5
- package/dist/{contract-infer-BmySmqVT.mjs.map → contract-infer-D8uEbJuu.mjs.map} +1 -1
- package/dist/contract-space-aggregate-loader-DvZwdkrr.mjs +247 -0
- package/dist/contract-space-aggregate-loader-DvZwdkrr.mjs.map +1 -0
- package/dist/{db-verify-BClPs3ph.mjs → db-verify-v_vUKXTU.mjs} +5 -7
- package/dist/{db-verify-BClPs3ph.mjs.map → db-verify-v_vUKXTU.mjs.map} +1 -1
- package/dist/exports/control-api.d.mts +3 -3
- package/dist/exports/control-api.d.mts.map +1 -1
- package/dist/exports/control-api.mjs +3 -3
- package/dist/exports/index.d.mts.map +1 -1
- package/dist/exports/index.mjs +1 -1
- package/dist/exports/index.mjs.map +1 -1
- package/dist/exports/init-output.d.mts.map +1 -1
- package/dist/exports/init-output.mjs +1 -1
- package/dist/extension-pack-inputs-IDvjRCi3.mjs +62 -0
- package/dist/extension-pack-inputs-IDvjRCi3.mjs.map +1 -0
- package/dist/{framework-components-65gOHkHB.mjs → framework-components-fYXjz_in.mjs} +2 -2
- package/dist/{framework-components-65gOHkHB.mjs.map → framework-components-fYXjz_in.mjs.map} +1 -1
- package/dist/global-flags-DEHjV8_s.d.mts +34 -0
- package/dist/global-flags-DEHjV8_s.d.mts.map +1 -0
- package/dist/{graph-render-DJVv0_uf.mjs → graph-render-rFAqZujX.mjs} +2 -2
- package/dist/{graph-render-DJVv0_uf.mjs.map → graph-render-rFAqZujX.mjs.map} +1 -1
- package/dist/{init-BCJZPWE1.mjs → init-Cv9UzWL5.mjs} +20 -269
- package/dist/init-Cv9UzWL5.mjs.map +1 -0
- package/dist/{inspect-live-schema-DSRbFoOL.mjs → inspect-live-schema-C6ohV_oQ.mjs} +4 -5
- package/dist/{inspect-live-schema-DSRbFoOL.mjs.map → inspect-live-schema-C6ohV_oQ.mjs.map} +1 -1
- package/dist/migration-check-BiBJoYYW.mjs +341 -0
- package/dist/migration-check-BiBJoYYW.mjs.map +1 -0
- package/dist/migration-cli.d.mts.map +1 -1
- package/dist/migration-cli.mjs +4 -4
- package/dist/migration-cli.mjs.map +1 -1
- package/dist/{migration-command-scaffold-Bzd9La5c.mjs → migration-command-scaffold-CjvwO6at.mjs} +4 -5
- package/dist/{migration-command-scaffold-Bzd9La5c.mjs.map → migration-command-scaffold-CjvwO6at.mjs.map} +1 -1
- package/dist/migration-graph-D7DVUElV.mjs +1232 -0
- package/dist/migration-graph-D7DVUElV.mjs.map +1 -0
- package/dist/migration-list-styler-BRwF4-gy.mjs +399 -0
- package/dist/migration-list-styler-BRwF4-gy.mjs.map +1 -0
- package/dist/{migration-plan-CFwqw3Gk.mjs → migration-plan-9DJ7q7_z.mjs} +372 -133
- package/dist/migration-plan-9DJ7q7_z.mjs.map +1 -0
- package/dist/{migration-types-BXWvz12q.d.mts → migration-types-D2FW63pr.d.mts} +1 -1
- package/dist/{migration-types-BXWvz12q.d.mts.map → migration-types-D2FW63pr.d.mts.map} +1 -1
- package/dist/{migrations-CwZMa1Ck.mjs → migrations-Cv2jxNNK.mjs} +12 -13
- package/dist/migrations-Cv2jxNNK.mjs.map +1 -0
- package/dist/{output-BlsrGMEF.mjs → output-B60Gw5fu.mjs} +1 -1
- package/dist/{output-BlsrGMEF.mjs.map → output-B60Gw5fu.mjs.map} +1 -1
- package/dist/{progress-adapter-DFfvZcYL.mjs → progress-adapter-C644QK8l.mjs} +1 -1
- package/dist/{progress-adapter-DFfvZcYL.mjs.map → progress-adapter-C644QK8l.mjs.map} +1 -1
- package/dist/ref-advancement-DUZqsue6.mjs +50 -0
- package/dist/ref-advancement-DUZqsue6.mjs.map +1 -0
- package/dist/terminal-ui-5Y6mrg93.d.mts +133 -0
- package/dist/terminal-ui-5Y6mrg93.d.mts.map +1 -0
- package/dist/{types--CqjMdk0.d.mts → types-Dt_SfqFm.d.mts} +28 -28
- package/dist/types-Dt_SfqFm.d.mts.map +1 -0
- package/dist/{verify-Bom75OYI.mjs → verify-DCA9Sldu.mjs} +2 -2
- package/dist/{verify-Bom75OYI.mjs.map → verify-DCA9Sldu.mjs.map} +1 -1
- package/package.json +35 -24
- package/src/commands/contract-emit.ts +19 -7
- package/src/commands/contract-infer.ts +1 -1
- package/src/commands/db-init.ts +48 -2
- package/src/commands/db-sign.ts +9 -5
- package/src/commands/db-update.ts +54 -8
- package/src/commands/init/hygiene-gitattributes.ts +2 -2
- package/src/commands/init/index.ts +2 -1
- package/src/commands/init/templates/code-templates.ts +4 -2
- package/src/commands/init/templates/env.ts +13 -14
- package/src/commands/migrate.ts +125 -44
- package/src/commands/migration-check.ts +43 -83
- package/src/commands/migration-graph.ts +75 -60
- package/src/commands/migration-list.ts +220 -74
- package/src/commands/migration-log.ts +8 -14
- package/src/commands/migration-new.ts +44 -48
- package/src/commands/migration-plan.ts +412 -197
- package/src/commands/migration-show.ts +65 -284
- package/src/commands/migration-status.ts +127 -124
- package/src/commands/ref.ts +53 -8
- package/src/control-api/client.ts +0 -1
- package/src/control-api/contract-enrichment.ts +6 -42
- package/src/control-api/operations/{apply-aggregate.ts → apply.ts} +44 -75
- package/src/control-api/operations/contract-emit.ts +14 -6
- package/src/control-api/operations/{db-apply-aggregate.ts → db-apply.ts} +19 -19
- package/src/control-api/operations/db-init.ts +4 -4
- package/src/control-api/operations/db-update.ts +4 -4
- package/src/control-api/operations/db-verify.ts +15 -11
- package/src/control-api/operations/migration-apply.ts +56 -47
- package/src/control-api/types.ts +26 -27
- package/src/migration-cli.ts +4 -4
- package/src/utils/cli-errors.ts +234 -0
- package/src/utils/command-helpers.ts +9 -24
- package/src/utils/contract-at-errors.ts +96 -0
- package/src/utils/contract-space-aggregate-loader.ts +336 -117
- package/src/utils/formatters/migration-graph-layout.ts +1119 -0
- package/src/utils/formatters/migration-graph-rows.ts +336 -0
- package/src/utils/formatters/migration-graph-tree-render.ts +459 -0
- package/src/utils/formatters/migration-list-data-column.ts +115 -0
- package/src/utils/formatters/migration-list-graph-topology.ts +368 -0
- package/src/utils/formatters/migration-list-render.ts +191 -0
- package/src/utils/formatters/migration-list-styler.ts +63 -0
- package/src/utils/formatters/migration-list-types.ts +21 -0
- package/src/utils/formatters/migrations.ts +37 -46
- package/src/utils/glyph-mode.ts +22 -0
- package/src/utils/integrity-violation-to-check-failure.ts +130 -0
- package/src/utils/plan-resolution.ts +258 -0
- package/src/utils/ref-advancement.ts +68 -0
- package/src/utils/terminal-ui.ts +42 -1
- package/dist/cli-errors-Czmx92Zy.d.mts +0 -3
- package/dist/cli-errors-Djtz98Vm.mjs +0 -71
- package/dist/cli-errors-Djtz98Vm.mjs.map +0 -1
- package/dist/client-oXO2WCPD.mjs.map +0 -1
- package/dist/command-helpers-BSb0tRC8.mjs.map +0 -1
- package/dist/commands/migration-check.mjs.map +0 -1
- package/dist/commands/migration-graph.mjs.map +0 -1
- package/dist/contract-emit-bcrpT-wD.mjs.map +0 -1
- package/dist/contract-emit-r4y8Zhf1.mjs.map +0 -1
- package/dist/contract-enrichment-Dani0mMW.mjs.map +0 -1
- package/dist/contract-space-aggregate-loader-BmNQwlws.mjs +0 -160
- package/dist/contract-space-aggregate-loader-BmNQwlws.mjs.map +0 -1
- package/dist/global-flags-CdE7M0d9.d.mts +0 -15
- package/dist/global-flags-CdE7M0d9.d.mts.map +0 -1
- package/dist/init-BCJZPWE1.mjs.map +0 -1
- package/dist/migration-plan-CFwqw3Gk.mjs.map +0 -1
- package/dist/migrations-CwZMa1Ck.mjs.map +0 -1
- package/dist/rolldown-runtime-twds-ZHy.mjs +0 -14
- package/dist/terminal-ui-BiB_8KNo.mjs +0 -379
- package/dist/terminal-ui-BiB_8KNo.mjs.map +0 -1
- package/dist/types--CqjMdk0.d.mts.map +0 -1
package/src/utils/cli-errors.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
import { errorRuntime } from '@prisma-next/errors/execution';
|
|
29
29
|
import type { MigrationToolsError } from '@prisma-next/migration-tools/errors';
|
|
30
30
|
import type { RefResolutionError } from '@prisma-next/migration-tools/ref-resolution';
|
|
31
|
+
import type { MigrationApplyFailure } from '../control-api/types';
|
|
31
32
|
|
|
32
33
|
export {
|
|
33
34
|
ERROR_CODE_DESTRUCTIVE_CHANGES,
|
|
@@ -68,6 +69,239 @@ export {
|
|
|
68
69
|
errorUnexpected,
|
|
69
70
|
};
|
|
70
71
|
|
|
72
|
+
export function errorRefSetHashNotInGraph(
|
|
73
|
+
resolvedHash: string,
|
|
74
|
+
reachableHashes: readonly string[],
|
|
75
|
+
graphTipHash: string | null,
|
|
76
|
+
): CliStructuredError {
|
|
77
|
+
const reachableList =
|
|
78
|
+
reachableHashes.length > 0 ? reachableHashes.join(', ') : '(none — migration graph is empty)';
|
|
79
|
+
const fix =
|
|
80
|
+
reachableHashes.length > 0
|
|
81
|
+
? graphTipHash !== null
|
|
82
|
+
? `Set the ref to a graph-node hash such as ${graphTipHash}, or run \`prisma-next migration plan\` to extend the graph.`
|
|
83
|
+
: 'Set the ref to a hash that appears in the migration graph.'
|
|
84
|
+
: 'Run `prisma-next migration plan` first.';
|
|
85
|
+
return errorRuntime(`Resolved contract hash is not in the migration graph: ${resolvedHash}`, {
|
|
86
|
+
why:
|
|
87
|
+
reachableHashes.length > 0
|
|
88
|
+
? `The migration graph reaches ${reachableList}; resolved ${resolvedHash} isn't a graph node.`
|
|
89
|
+
: 'The migration graph is empty — no hashes reachable.',
|
|
90
|
+
fix,
|
|
91
|
+
meta: {
|
|
92
|
+
code: 'MIGRATION.HASH_NOT_IN_GRAPH',
|
|
93
|
+
resolvedHash,
|
|
94
|
+
reachableHashes: [...reachableHashes],
|
|
95
|
+
...(graphTipHash !== null ? { graphTipHash } : {}),
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function errorRefSetEmptySentinel(hash: string): CliStructuredError {
|
|
101
|
+
return errorRuntime(`Cannot set ref to the empty-database sentinel: ${hash}`, {
|
|
102
|
+
why: 'The empty-database sentinel is a planner internal; it is not a valid ref target.',
|
|
103
|
+
fix: 'Set the ref to a contract hash from the migration graph, or use another ref name.',
|
|
104
|
+
meta: {
|
|
105
|
+
code: 'MIGRATION.REF_SET_EMPTY_SENTINEL',
|
|
106
|
+
hash,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* `--space <id>` was given a value that doesn't satisfy the contract-space
|
|
113
|
+
* naming rule (`[a-z][a-z0-9_-]{0,63}` per `isValidSpaceId`). Fires before
|
|
114
|
+
* any fs work — the input is syntactically rejected the same way an on-disk
|
|
115
|
+
* directory with that name would be skipped by the enumerator.
|
|
116
|
+
*/
|
|
117
|
+
export function errorInvalidSpaceId(spaceId: string): CliStructuredError {
|
|
118
|
+
return errorRuntime(`Invalid contract space id: ${spaceId}`, {
|
|
119
|
+
why: 'Contract space ids must match [a-z][a-z0-9_-]{0,63} (lowercase, starts with a letter, max 64 characters — the rule applied to every on-disk space directory).',
|
|
120
|
+
fix: 'Pass a space id that matches the directory naming rule, or omit --space to list every space.',
|
|
121
|
+
meta: {
|
|
122
|
+
code: 'MIGRATION.INVALID_SPACE_ID',
|
|
123
|
+
spaceId,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* `migration list --space <id>` was given a contract-space id that has no
|
|
130
|
+
* directory under `migrations/`. Distinct from "the space exists but is
|
|
131
|
+
* empty" — that path renders the empty-state line and exits 0 per the
|
|
132
|
+
* slice spec § Empty-state. This error fires only when `<projectMigrationsDir>/<spaceId>`
|
|
133
|
+
* does not exist on disk.
|
|
134
|
+
*
|
|
135
|
+
* `availableSpaces` lists the contract-space directory names actually
|
|
136
|
+
* present, sorted lex-asc, so the diagnostic can suggest a near match
|
|
137
|
+
* without making the user reach for `ls`.
|
|
138
|
+
*/
|
|
139
|
+
export function errorSpaceNotFound(
|
|
140
|
+
spaceId: string,
|
|
141
|
+
availableSpaces: readonly string[],
|
|
142
|
+
): CliStructuredError {
|
|
143
|
+
const availableList =
|
|
144
|
+
availableSpaces.length > 0
|
|
145
|
+
? availableSpaces.join(', ')
|
|
146
|
+
: '(none — no contract spaces on disk yet)';
|
|
147
|
+
const fix =
|
|
148
|
+
availableSpaces.length > 0
|
|
149
|
+
? `Pick one of: ${availableList}. Run \`prisma-next migration list\` (no --space) to see every space's migrations.`
|
|
150
|
+
: 'Author a migration with `prisma-next migration new` to create the first contract-space directory.';
|
|
151
|
+
return errorRuntime(`Unknown contract space: ${spaceId}`, {
|
|
152
|
+
why: `No directory named "${spaceId}" exists under the migrations root.`,
|
|
153
|
+
fix,
|
|
154
|
+
meta: {
|
|
155
|
+
code: 'MIGRATION.SPACE_NOT_FOUND',
|
|
156
|
+
spaceId,
|
|
157
|
+
availableSpaces: [...availableSpaces],
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function errorRefSetBundleNotFound(hash: string): CliStructuredError {
|
|
163
|
+
return errorRuntime(`No migration bundle matches graph-node hash ${hash}`, {
|
|
164
|
+
why: `The hash is a graph node but no on-disk bundle has metadata.to = ${hash}.`,
|
|
165
|
+
fix: 'Run `pnpm fixtures:check`, or re-emit the migration that produces this hash so its bundle is restored.',
|
|
166
|
+
meta: {
|
|
167
|
+
code: 'MIGRATION.REF_SET_BUNDLE_NOT_FOUND',
|
|
168
|
+
hash,
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function errorPlanForgotTheFlag(
|
|
174
|
+
resolvedHash: string,
|
|
175
|
+
reachableRefs: ReadonlyArray<{ readonly name: string; readonly hash: string }>,
|
|
176
|
+
graphTipHash: string | null,
|
|
177
|
+
): CliStructuredError {
|
|
178
|
+
const reachableList =
|
|
179
|
+
reachableRefs.length > 0
|
|
180
|
+
? reachableRefs.map((r) => `${r.name} (${r.hash})`).join(', ')
|
|
181
|
+
: '(none)';
|
|
182
|
+
const refFix =
|
|
183
|
+
reachableRefs.length > 0
|
|
184
|
+
? `Run migration plan with ${reachableRefs.map((r) => `--from ${r.name}`).join(' or ')}.`
|
|
185
|
+
: graphTipHash !== null
|
|
186
|
+
? `Run migration plan --from ${graphTipHash}.`
|
|
187
|
+
: 'Commit pending migrations first, then run migration plan.';
|
|
188
|
+
return errorRuntime(`Resolved from-hash is not in the migration graph: ${resolvedHash}`, {
|
|
189
|
+
why: `The migration graph reaches ${reachableList}; resolved ${resolvedHash} isn't a graph node.`,
|
|
190
|
+
fix: refFix,
|
|
191
|
+
meta: {
|
|
192
|
+
code: 'MIGRATION.HASH_NOT_IN_GRAPH',
|
|
193
|
+
resolvedHash,
|
|
194
|
+
reachableRefs: reachableRefs.map((r) => r.name),
|
|
195
|
+
...(graphTipHash !== null ? { graphTipHash } : {}),
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function errorSnapshotMissing(
|
|
201
|
+
identifier: string,
|
|
202
|
+
options?: { readonly viaRef?: boolean },
|
|
203
|
+
): CliStructuredError {
|
|
204
|
+
const viaRef = options?.viaRef !== false;
|
|
205
|
+
const fix = viaRef
|
|
206
|
+
? `Run "prisma-next db update --advance-ref ${identifier}" to repopulate the snapshot, or "prisma-next ref delete ${identifier}" to clear the orphan pointer.`
|
|
207
|
+
: `No contract source exists for hash "${identifier}" on an empty migration graph. Use --from with a ref name that has a paired snapshot, or run db update first.`;
|
|
208
|
+
return errorRuntime(
|
|
209
|
+
viaRef
|
|
210
|
+
? `Ref "${identifier}" has no paired contract snapshot`
|
|
211
|
+
: `No contract source for from-hash "${identifier}"`,
|
|
212
|
+
{
|
|
213
|
+
why: viaRef
|
|
214
|
+
? `Ref "${identifier}" exists but its paired snapshot files are missing.`
|
|
215
|
+
: `Hash "${identifier}" is not a graph node and no paired ref snapshot supplies a contract.`,
|
|
216
|
+
fix,
|
|
217
|
+
meta: {
|
|
218
|
+
code: 'MIGRATION.SNAPSHOT_MISSING',
|
|
219
|
+
identifier,
|
|
220
|
+
viaRef,
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function errorMarkerMismatch(
|
|
227
|
+
markerHash: string,
|
|
228
|
+
reachableHashes: readonly string[],
|
|
229
|
+
graphTip: string | null,
|
|
230
|
+
): CliStructuredError {
|
|
231
|
+
const reachableList =
|
|
232
|
+
reachableHashes.length > 0 ? reachableHashes.join(', ') : '(none — migration graph is empty)';
|
|
233
|
+
const planFromFix =
|
|
234
|
+
graphTip !== null
|
|
235
|
+
? `Run \`prisma-next migration plan --from ${graphTip}\` if the live marker is canonical and the on-disk graph needs catching up.`
|
|
236
|
+
: 'Run `prisma-next migration plan` if the live marker is canonical and the on-disk graph needs catching up.';
|
|
237
|
+
return errorRuntime('Database marker is not reachable in the on-disk migration graph', {
|
|
238
|
+
why: `DB marker is ${markerHash}, but the on-disk migration graph reaches: ${reachableList}.`,
|
|
239
|
+
fix: [
|
|
240
|
+
planFromFix,
|
|
241
|
+
`Run \`prisma-next ref set db ${markerHash}\` if the on-disk graph is canonical and the local \`db\` ref drifted.`,
|
|
242
|
+
'Investigate whether the database was migrated by an out-of-band process.',
|
|
243
|
+
].join('\n'),
|
|
244
|
+
meta: {
|
|
245
|
+
code: 'MIGRATION.MARKER_MISMATCH',
|
|
246
|
+
markerHash,
|
|
247
|
+
reachableHashes: [...reachableHashes],
|
|
248
|
+
...(graphTip !== null ? { graphTip } : {}),
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function errorPathUnreachable(failure: MigrationApplyFailure): CliStructuredError {
|
|
254
|
+
const meta = failure.meta ?? {};
|
|
255
|
+
const fromHashMeta = typeof meta['fromHash'] === 'string' ? meta['fromHash'] : null;
|
|
256
|
+
// `buildPathNotFoundFailure` uses this sentinel in meta when the live marker is null.
|
|
257
|
+
const planFromHash = fromHashMeta === '<empty>' ? null : fromHashMeta;
|
|
258
|
+
const targetHash =
|
|
259
|
+
typeof meta['targetHash'] === 'string'
|
|
260
|
+
? meta['targetHash']
|
|
261
|
+
: typeof meta['target'] === 'string'
|
|
262
|
+
? meta['target']
|
|
263
|
+
: null;
|
|
264
|
+
const deadEnds = meta['deadEnds'];
|
|
265
|
+
const deadEndsSuffix =
|
|
266
|
+
Array.isArray(deadEnds) && deadEnds.length > 0
|
|
267
|
+
? ` Dead-ends: ${deadEnds.map(String).join(', ')}.`
|
|
268
|
+
: '';
|
|
269
|
+
// Plan-then-apply recovery. The planner destination is the missing edge's
|
|
270
|
+
// target; `migration plan --to` (built for arbitrary targets) makes this a
|
|
271
|
+
// real command, so the diagnostic that sends you here is now honest.
|
|
272
|
+
const planCommand = (() => {
|
|
273
|
+
if (planFromHash !== null && targetHash !== null) {
|
|
274
|
+
return `prisma-next migration plan --from ${planFromHash} --to ${targetHash} --name <slug>`;
|
|
275
|
+
}
|
|
276
|
+
if (targetHash !== null) {
|
|
277
|
+
return `prisma-next migration plan --to ${targetHash} --name <slug>`;
|
|
278
|
+
}
|
|
279
|
+
if (planFromHash !== null) {
|
|
280
|
+
return `prisma-next migration plan --from ${planFromHash} --name <slug>`;
|
|
281
|
+
}
|
|
282
|
+
return 'prisma-next migration plan';
|
|
283
|
+
})();
|
|
284
|
+
const applyCommand =
|
|
285
|
+
targetHash !== null ? `prisma-next migrate --to ${targetHash}` : 'prisma-next migrate';
|
|
286
|
+
return errorRuntime(failure.summary, {
|
|
287
|
+
why:
|
|
288
|
+
failure.why ??
|
|
289
|
+
`Cannot reach target "${targetHash ?? '<unknown>'}" from current marker "${fromHashMeta ?? '<unknown>'}".${deadEndsSuffix}`,
|
|
290
|
+
fix: [
|
|
291
|
+
'Plan the missing edge, then apply it:',
|
|
292
|
+
` 1. ${planCommand}`,
|
|
293
|
+
` 2. ${applyCommand}`,
|
|
294
|
+
'A rollback (reverse) plan is expected to contain destructive (DROP) operations — review them before applying.',
|
|
295
|
+
'Narrower cases (rename inference, re-adding a NOT NULL column without a safe default, or a type change that needs data) may additionally need a hint in the planned migration.',
|
|
296
|
+
'Inspect the on-disk graph with `prisma-next migration list`, or `prisma-next migration show <bundle>` for any bundle in the path you expected.',
|
|
297
|
+
].join('\n'),
|
|
298
|
+
meta: {
|
|
299
|
+
...meta,
|
|
300
|
+
code: 'MIGRATION.PATH_UNREACHABLE',
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
71
305
|
/**
|
|
72
306
|
* Maps a `MigrationToolsError` raised by the migration-tools loader/graph
|
|
73
307
|
* surface (`readMigrationPackage`, `readMigrationsDir`, `readRefs`,
|
|
@@ -3,14 +3,12 @@ import type { ControlTargetDescriptor } from '@prisma-next/framework-components/
|
|
|
3
3
|
import { hasMigrations } from '@prisma-next/framework-components/control';
|
|
4
4
|
import type { NoInvariantPathStructuralEdge } from '@prisma-next/migration-tools/errors';
|
|
5
5
|
import type { MigrationEdge, MigrationGraph } from '@prisma-next/migration-tools/graph';
|
|
6
|
-
import { readMigrationsDir } from '@prisma-next/migration-tools/io';
|
|
7
6
|
import type { PathDecision } from '@prisma-next/migration-tools/migration-graph';
|
|
8
|
-
import { reconstructGraph } from '@prisma-next/migration-tools/migration-graph';
|
|
9
|
-
import type { OnDiskMigrationPackage } from '@prisma-next/migration-tools/package';
|
|
10
7
|
import { APP_SPACE_ID, spaceMigrationDirectory } from '@prisma-next/migration-tools/spaces';
|
|
11
8
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
12
9
|
import type { Command } from 'commander';
|
|
13
10
|
import { relative, resolve } from 'pathe';
|
|
11
|
+
import { errorRuntime } from './cli-errors';
|
|
14
12
|
import { formatCommandHelp } from './formatters/help';
|
|
15
13
|
import type { CommonCommandOptions } from './global-flags';
|
|
16
14
|
import { parseGlobalFlags } from './global-flags';
|
|
@@ -94,12 +92,15 @@ export interface MigrationCommandOptions extends CommonCommandOptions {
|
|
|
94
92
|
|
|
95
93
|
/**
|
|
96
94
|
* Resolves the absolute path to contract.json from the config.
|
|
97
|
-
* Centralises the fallback logic shared by every command that reads the contract.
|
|
98
95
|
*/
|
|
99
96
|
export function resolveContractPath(config: { contract?: { output?: string } }): string {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
if (config.contract?.output === undefined) {
|
|
98
|
+
throw errorRuntime('config.contract.output is required to resolve the contract path', {
|
|
99
|
+
why: 'CLI commands read the emitted contract from config.contract.output; the config has no value to read.',
|
|
100
|
+
fix: 'Ensure your prisma-next.config.ts goes through `defineConfig()`, which normalises a default output when the provider supplies an input path, or set `contract.output` explicitly.',
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return resolve(config.contract.output);
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
/**
|
|
@@ -150,7 +151,7 @@ export function resolveMigrationPaths(
|
|
|
150
151
|
|
|
151
152
|
/**
|
|
152
153
|
* Slim representation of a PathDecision for CLI JSON output.
|
|
153
|
-
* Strips internal fields (createdAt
|
|
154
|
+
* Strips internal fields (createdAt) from path entries.
|
|
154
155
|
*/
|
|
155
156
|
export interface PathDecisionResult {
|
|
156
157
|
readonly fromHash: string;
|
|
@@ -227,22 +228,6 @@ export function getTargetMigrations(target: ControlTargetDescriptor<string, stri
|
|
|
227
228
|
return hasMigrations(target) ? target.migrations : undefined;
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
/**
|
|
231
|
-
* Reads the migrations directory and builds the migration graph from all
|
|
232
|
-
* packages. Throws on I/O or graph errors — callers handle error mapping.
|
|
233
|
-
*
|
|
234
|
-
* Every on-disk package is content-addressed (`migrationHash` is always a
|
|
235
|
-
* string); there is no draft state to filter out.
|
|
236
|
-
*/
|
|
237
|
-
export async function loadMigrationPackages(migrationsDir: string): Promise<{
|
|
238
|
-
bundles: readonly OnDiskMigrationPackage[];
|
|
239
|
-
graph: MigrationGraph;
|
|
240
|
-
}> {
|
|
241
|
-
const bundles = await readMigrationsDir(migrationsDir);
|
|
242
|
-
const graph = reconstructGraph(bundles);
|
|
243
|
-
return { bundles, graph };
|
|
244
|
-
}
|
|
245
|
-
|
|
246
231
|
/**
|
|
247
232
|
* The subset of the emitted contract.json that the framework layer can
|
|
248
233
|
* safely type. The emitter adds these fields on top of the family-specific
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { MigrationToolsError } from '@prisma-next/migration-tools/errors';
|
|
2
|
+
import { notOk, type Result } from '@prisma-next/utils/result';
|
|
3
|
+
import { join } from 'pathe';
|
|
4
|
+
import {
|
|
5
|
+
CliStructuredError,
|
|
6
|
+
errorContractValidationFailed,
|
|
7
|
+
errorFileNotFound,
|
|
8
|
+
errorSnapshotMissing,
|
|
9
|
+
errorUnexpected,
|
|
10
|
+
mapMigrationToolsError,
|
|
11
|
+
} from './cli-errors';
|
|
12
|
+
|
|
13
|
+
export function mapContractAtError(
|
|
14
|
+
error: unknown,
|
|
15
|
+
options?: { readonly artifactRole?: 'from' | 'to' },
|
|
16
|
+
): Result<never, CliStructuredError> {
|
|
17
|
+
if (MigrationToolsError.is(error)) {
|
|
18
|
+
switch (error.code) {
|
|
19
|
+
case 'MIGRATION.SNAPSHOT_MISSING': {
|
|
20
|
+
const refName =
|
|
21
|
+
typeof error.details?.['refName'] === 'string'
|
|
22
|
+
? error.details['refName']
|
|
23
|
+
: typeof error.details?.['identifier'] === 'string'
|
|
24
|
+
? error.details['identifier']
|
|
25
|
+
: 'unknown';
|
|
26
|
+
return notOk(errorSnapshotMissing(refName));
|
|
27
|
+
}
|
|
28
|
+
case 'MIGRATION.CONTRACT_DESERIALIZATION_FAILED': {
|
|
29
|
+
const filePath =
|
|
30
|
+
typeof error.details?.['filePath'] === 'string'
|
|
31
|
+
? error.details['filePath']
|
|
32
|
+
: 'ref-snapshot';
|
|
33
|
+
const message =
|
|
34
|
+
typeof error.details?.['message'] === 'string' ? error.details['message'] : error.message;
|
|
35
|
+
const isRefSnapshot = filePath.endsWith('.contract.json');
|
|
36
|
+
return notOk(
|
|
37
|
+
errorContractValidationFailed(
|
|
38
|
+
isRefSnapshot
|
|
39
|
+
? `Ref snapshot contract failed to deserialize: ${message}`
|
|
40
|
+
: `Predecessor contract at ${filePath} failed to deserialize: ${message}`,
|
|
41
|
+
{ where: { path: isRefSnapshot ? 'ref-snapshot' : filePath } },
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
case 'MIGRATION.INVALID_JSON': {
|
|
46
|
+
const filePath =
|
|
47
|
+
typeof error.details?.['filePath'] === 'string' ? error.details['filePath'] : 'unknown';
|
|
48
|
+
const message =
|
|
49
|
+
typeof error.details?.['parseError'] === 'string'
|
|
50
|
+
? error.details['parseError']
|
|
51
|
+
: error.message;
|
|
52
|
+
const role = options?.artifactRole ?? 'from';
|
|
53
|
+
return notOk(
|
|
54
|
+
errorContractValidationFailed(
|
|
55
|
+
role === 'to'
|
|
56
|
+
? `Target contract at ${filePath} failed to deserialize: ${message}`
|
|
57
|
+
: `Predecessor contract at ${filePath} failed to deserialize: ${message}`,
|
|
58
|
+
{ where: { path: filePath } },
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
case 'MIGRATION.BUNDLE_NOT_FOUND_FOR_GRAPH_NODE':
|
|
63
|
+
return notOk(
|
|
64
|
+
errorUnexpected(error.message, {
|
|
65
|
+
why: error.why,
|
|
66
|
+
fix: error.fix,
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
case 'MIGRATION.FILE_MISSING': {
|
|
70
|
+
const file =
|
|
71
|
+
typeof error.details?.['file'] === 'string' ? error.details['file'] : 'end-contract.json';
|
|
72
|
+
const dir = typeof error.details?.['dir'] === 'string' ? error.details['dir'] : '';
|
|
73
|
+
const jsonPath = dir ? join(dir, 'end-contract.json') : file;
|
|
74
|
+
const role = options?.artifactRole ?? 'from';
|
|
75
|
+
return notOk(
|
|
76
|
+
errorFileNotFound(jsonPath, {
|
|
77
|
+
why:
|
|
78
|
+
role === 'to'
|
|
79
|
+
? `Target migration is missing its destination contract snapshot at ${jsonPath}`
|
|
80
|
+
: `Predecessor migration is missing its destination contract snapshot at ${jsonPath}`,
|
|
81
|
+
fix:
|
|
82
|
+
role === 'to'
|
|
83
|
+
? 'Re-emit the target migration so its sibling `end-contract.json` / `end-contract.d.ts` are restored, then re-run this command.'
|
|
84
|
+
: 'Re-emit the predecessor migration (`prisma-next migration plan` from its source) so its sibling `end-contract.json` is restored, then re-run this command.',
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
return notOk(mapMigrationToolsError(error));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (CliStructuredError.is(error)) {
|
|
93
|
+
return notOk(error);
|
|
94
|
+
}
|
|
95
|
+
throw error;
|
|
96
|
+
}
|