@prisma-next/cli 0.11.0-dev.5 → 0.11.0-dev.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-errors-DFF1LlfU.mjs +215 -0
- package/dist/cli-errors-DFF1LlfU.mjs.map +1 -0
- package/dist/cli.mjs +9 -10
- package/dist/cli.mjs.map +1 -1
- package/dist/{client-oXO2WCPD.mjs → client-5uvDppD8.mjs} +23 -21
- package/dist/client-5uvDppD8.mjs.map +1 -0
- package/dist/{command-helpers-DtavI0wJ.mjs → command-helpers-4UNsRRc4.mjs} +427 -9
- package/dist/command-helpers-4UNsRRc4.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 +33 -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 +6 -7
- 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 +36 -8
- 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 +5 -1
- package/dist/commands/migrate.d.mts.map +1 -1
- package/dist/commands/migrate.mjs +79 -39
- 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 +1 -1
- package/dist/commands/migration-graph.d.mts.map +1 -1
- package/dist/commands/migration-graph.mjs +3 -4
- package/dist/commands/migration-graph.mjs.map +1 -1
- package/dist/commands/migration-list.d.mts +63 -12
- package/dist/commands/migration-list.d.mts.map +1 -1
- package/dist/commands/migration-list.mjs +2 -103
- package/dist/commands/migration-log.d.mts.map +1 -1
- package/dist/commands/migration-log.mjs +3 -4
- 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 +33 -38
- package/dist/commands/migration-new.mjs.map +1 -1
- package/dist/commands/migration-plan.d.mts +2 -1
- 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 +62 -153
- package/dist/commands/migration-show.mjs.map +1 -1
- package/dist/commands/migration-status.d.mts +5 -40
- package/dist/commands/migration-status.d.mts.map +1 -1
- package/dist/commands/migration-status.mjs +93 -67
- 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 +34 -9
- 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-emit-o-8VmdQX.mjs → contract-emit-C-CFGZsI.mjs} +9 -6
- package/dist/{contract-emit-o-8VmdQX.mjs.map → contract-emit-C-CFGZsI.mjs.map} +1 -1
- package/dist/{contract-emit-CmsklifJ.mjs → contract-emit-CuUzzM46.mjs} +5 -6
- package/dist/{contract-emit-CmsklifJ.mjs.map → contract-emit-CuUzzM46.mjs.map} +1 -1
- package/dist/{contract-enrichment-Dani0mMW.mjs → contract-enrichment-XmUPhmsS.mjs} +4 -25
- package/dist/contract-enrichment-XmUPhmsS.mjs.map +1 -0
- package/dist/{contract-infer-pKkiCt7C.mjs → contract-infer-C98ZaRhp.mjs} +3 -4
- package/dist/{contract-infer-pKkiCt7C.mjs.map → contract-infer-C98ZaRhp.mjs.map} +1 -1
- package/dist/contract-space-aggregate-loader-CVHGuA35.mjs +170 -0
- package/dist/contract-space-aggregate-loader-CVHGuA35.mjs.map +1 -0
- package/dist/{db-verify-AoIUriL4.mjs → db-verify-BWl1Yxi-.mjs} +6 -7
- package/dist/{db-verify-AoIUriL4.mjs.map → db-verify-BWl1Yxi-.mjs.map} +1 -1
- package/dist/exports/control-api.d.mts +1 -1
- 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-BiY86HbQ.mjs +62 -0
- package/dist/extension-pack-inputs-BiY86HbQ.mjs.map +1 -0
- package/dist/{framework-components-65gOHkHB.mjs → framework-components-DTcjouhS.mjs} +2 -2
- package/dist/{framework-components-65gOHkHB.mjs.map → framework-components-DTcjouhS.mjs.map} +1 -1
- package/dist/{global-flags-CdE7M0d9.d.mts → global-flags-DWsQ6SSI.d.mts} +1 -1
- package/dist/global-flags-DWsQ6SSI.d.mts.map +1 -0
- package/dist/glyph-mode-CBB4emzO.d.mts +5 -0
- package/dist/glyph-mode-CBB4emzO.d.mts.map +1 -0
- package/dist/{graph-render-DJVv0_uf.mjs → graph-render-D2FnLpuK.mjs} +1 -1
- package/dist/{graph-render-DJVv0_uf.mjs.map → graph-render-D2FnLpuK.mjs.map} +1 -1
- package/dist/{init-Db5Itt5r.mjs → init-C7PvN163.mjs} +5 -5
- package/dist/{init-Db5Itt5r.mjs.map → init-C7PvN163.mjs.map} +1 -1
- package/dist/{inspect-live-schema-LeWvkZVz.mjs → inspect-live-schema-BRCWQ-Sr.mjs} +5 -5
- package/dist/{inspect-live-schema-LeWvkZVz.mjs.map → inspect-live-schema-BRCWQ-Sr.mjs.map} +1 -1
- package/dist/migration-check-DoskM1nB.mjs +341 -0
- package/dist/migration-check-DoskM1nB.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-BtkunvFQ.mjs → migration-command-scaffold-CXLkoIJx.mjs} +5 -5
- package/dist/{migration-command-scaffold-BtkunvFQ.mjs.map → migration-command-scaffold-CXLkoIJx.mjs.map} +1 -1
- package/dist/migration-list-B2-iQ5Jd.mjs +646 -0
- package/dist/migration-list-B2-iQ5Jd.mjs.map +1 -0
- package/dist/{migration-plan-C2jeH1J5.mjs → migration-plan-BqmIKQpZ.mjs} +341 -88
- package/dist/migration-plan-BqmIKQpZ.mjs.map +1 -0
- package/dist/{migration-types-BXWvz12q.d.mts → migration-types-q64xAI_J.d.mts} +1 -1
- package/dist/{migration-types-BXWvz12q.d.mts.map → migration-types-q64xAI_J.d.mts.map} +1 -1
- package/dist/{migrations-CwZMa1Ck.mjs → migrations-BcVTutso.mjs} +12 -13
- package/dist/migrations-BcVTutso.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-xASh41wr.mjs} +1 -1
- package/dist/{progress-adapter-DFfvZcYL.mjs.map → progress-adapter-xASh41wr.mjs.map} +1 -1
- package/dist/ref-advancement-DRh5Nquq.mjs +50 -0
- package/dist/ref-advancement-DRh5Nquq.mjs.map +1 -0
- package/dist/{types-C9FfXb1l.d.mts → types-CEtm6v6a.d.mts} +5 -11
- package/dist/types-CEtm6v6a.d.mts.map +1 -0
- package/dist/{verify-Bom75OYI.mjs → verify-DOHbbrub.mjs} +2 -2
- package/dist/{verify-Bom75OYI.mjs.map → verify-DOHbbrub.mjs.map} +1 -1
- package/package.json +20 -20
- package/src/commands/db-init.ts +48 -2
- package/src/commands/db-update.ts +45 -0
- package/src/commands/migrate.ts +120 -40
- package/src/commands/migration-check.ts +43 -83
- package/src/commands/migration-list.ts +173 -74
- package/src/commands/migration-new.ts +44 -48
- package/src/commands/migration-plan.ts +359 -128
- package/src/commands/migration-show.ts +65 -284
- package/src/commands/migration-status.ts +131 -99
- package/src/commands/ref.ts +46 -6
- package/src/control-api/client.ts +0 -1
- package/src/control-api/contract-enrichment.ts +6 -42
- package/src/control-api/operations/contract-emit.ts +7 -2
- package/src/control-api/operations/db-verify.ts +9 -5
- package/src/control-api/operations/migration-apply.ts +11 -19
- package/src/control-api/types.ts +0 -7
- package/src/migration-cli.ts +4 -4
- package/src/utils/cli-errors.ts +224 -0
- package/src/utils/command-helpers.ts +9 -4
- package/src/utils/contract-space-aggregate-loader.ts +221 -117
- package/src/utils/formatters/migration-list-data-column.ts +115 -0
- package/src/utils/formatters/migration-list-graph-layout.ts +268 -0
- package/src/utils/formatters/migration-list-graph-render.ts +314 -0
- package/src/utils/formatters/migration-list-render.ts +194 -0
- package/src/utils/formatters/migration-list-styler.ts +61 -0
- package/src/utils/formatters/migrations.ts +29 -38
- 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 +257 -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-DtavI0wJ.mjs.map +0 -1
- package/dist/commands/migration-check.mjs.map +0 -1
- package/dist/commands/migration-list.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.map +0 -1
- package/dist/migration-plan-C2jeH1J5.mjs.map +0 -1
- package/dist/migrations-CwZMa1Ck.mjs.map +0 -1
- package/dist/terminal-ui-BiB_8KNo.mjs +0 -379
- package/dist/terminal-ui-BiB_8KNo.mjs.map +0 -1
- package/dist/types-C9FfXb1l.d.mts.map +0 -1
|
@@ -12,11 +12,11 @@ import {
|
|
|
12
12
|
type ContractSpaceAggregate,
|
|
13
13
|
type ContractSpaceMember,
|
|
14
14
|
graphWalkStrategy,
|
|
15
|
+
requireHeadRef,
|
|
15
16
|
} from '@prisma-next/migration-tools/aggregate';
|
|
16
17
|
import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';
|
|
17
18
|
import { errorNoInvariantPath } from '@prisma-next/migration-tools/errors';
|
|
18
19
|
import { findPathWithDecision } from '@prisma-next/migration-tools/migration-graph';
|
|
19
|
-
import type { OnDiskMigrationPackage } from '@prisma-next/migration-tools/package';
|
|
20
20
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
21
21
|
import { notOk, ok } from '@prisma-next/utils/result';
|
|
22
22
|
import {
|
|
@@ -56,15 +56,6 @@ export interface ExecuteMigrationApplyOptions<TFamilyId extends string, TTargetI
|
|
|
56
56
|
readonly migrationsDir: string;
|
|
57
57
|
readonly extensionPacks: ReadonlyArray<ControlExtensionDescriptor<TFamilyId, TTargetId>>;
|
|
58
58
|
readonly targetId: TTargetId;
|
|
59
|
-
/**
|
|
60
|
-
* Already-loaded app-space migration packages. The CLI command
|
|
61
|
-
* loads these via `loadMigrationPackages(appMigrationsDir)`; the
|
|
62
|
-
* operation hydrates the app member's graph with them. Required
|
|
63
|
-
* because the framework-neutral aggregate loader doesn't know how
|
|
64
|
-
* to read the user's `migrations/` directory layout (it's family-
|
|
65
|
-
* aware: ops.json shape, manifest keys, etc.).
|
|
66
|
-
*/
|
|
67
|
-
readonly appMigrationPackages: ReadonlyArray<OnDiskMigrationPackage>;
|
|
68
59
|
/**
|
|
69
60
|
* Optional app-space ref override. When provided, the app member's
|
|
70
61
|
* graph-walk targets this hash instead of `member.headRef.hash`.
|
|
@@ -125,7 +116,6 @@ export async function executeMigrationApply<TFamilyId extends string, TTargetId
|
|
|
125
116
|
migrationsDir,
|
|
126
117
|
extensionPacks,
|
|
127
118
|
targetId,
|
|
128
|
-
appMigrationPackages,
|
|
129
119
|
refHash,
|
|
130
120
|
refInvariants,
|
|
131
121
|
refName,
|
|
@@ -138,7 +128,6 @@ export async function executeMigrationApply<TFamilyId extends string, TTargetId
|
|
|
138
128
|
appContract: contract,
|
|
139
129
|
extensionPacks,
|
|
140
130
|
deserializeContract: (json) => familyInstance.deserializeContract(json),
|
|
141
|
-
appMigrationPackages,
|
|
142
131
|
};
|
|
143
132
|
const loaded = await buildContractSpaceAggregate(loadInputs);
|
|
144
133
|
if (!loaded.ok) {
|
|
@@ -161,12 +150,15 @@ export async function executeMigrationApply<TFamilyId extends string, TTargetId
|
|
|
161
150
|
const atHeadResolutions = new Map<string, AggregatePerSpacePlan>();
|
|
162
151
|
for (const member of allMembers) {
|
|
163
152
|
const isAppMember = member.spaceId === aggregate.app.spaceId;
|
|
164
|
-
|
|
153
|
+
// The aggregate passed the integrity gate, so every member's head ref
|
|
154
|
+
// is resolved (the app's is synthesised from the live contract).
|
|
155
|
+
const headRef = requireHeadRef(member);
|
|
156
|
+
const targetHash = isAppMember && refHash !== undefined ? refHash : headRef.hash;
|
|
165
157
|
const liveMarker = markerRows.get(member.spaceId) ?? null;
|
|
166
158
|
|
|
167
159
|
// Empty-graph members fail loudly: replay needs an on-disk path
|
|
168
160
|
// and an empty graph means the user has never planned this space.
|
|
169
|
-
if (member.
|
|
161
|
+
if (member.graph().nodes.size === 0) {
|
|
170
162
|
// Edge case: target == EMPTY (greenfield, nothing to do) or
|
|
171
163
|
// the live marker already matches the target. Loader integrity
|
|
172
164
|
// allows this for extensions whose head ref is the empty
|
|
@@ -197,9 +189,9 @@ export async function executeMigrationApply<TFamilyId extends string, TTargetId
|
|
|
197
189
|
const targetInvariants =
|
|
198
190
|
isAppMember && refHash !== undefined && refInvariants !== undefined
|
|
199
191
|
? refInvariants
|
|
200
|
-
:
|
|
192
|
+
: headRef.invariants;
|
|
201
193
|
const targetMember: ContractSpaceMember =
|
|
202
|
-
targetHash ===
|
|
194
|
+
targetHash === headRef.hash && targetInvariants === headRef.invariants
|
|
203
195
|
? member
|
|
204
196
|
: { ...member, headRef: { hash: targetHash, invariants: targetInvariants } };
|
|
205
197
|
|
|
@@ -224,7 +216,7 @@ export async function executeMigrationApply<TFamilyId extends string, TTargetId
|
|
|
224
216
|
// is never a graph node, producing an empty `structuralPath` and
|
|
225
217
|
// a less actionable diagnostic.
|
|
226
218
|
const fromHash = liveMarker?.storageHash ?? EMPTY_CONTRACT_HASH;
|
|
227
|
-
const structural = findPathWithDecision(targetMember.
|
|
219
|
+
const structural = findPathWithDecision(targetMember.graph(), fromHash, targetHash, {
|
|
228
220
|
required: new Set<string>(),
|
|
229
221
|
});
|
|
230
222
|
const structuralPath =
|
|
@@ -369,7 +361,7 @@ function buildAtHeadResolution(args: {
|
|
|
369
361
|
providedInvariants: [],
|
|
370
362
|
},
|
|
371
363
|
displayOps: [],
|
|
372
|
-
destinationContract: member.contract,
|
|
364
|
+
destinationContract: member.contract(),
|
|
373
365
|
strategy: 'graph-walk',
|
|
374
366
|
migrationEdges: [],
|
|
375
367
|
};
|
|
@@ -407,7 +399,7 @@ function buildSuccess(args: BuildSuccessArgs): MigrationApplySuccess {
|
|
|
407
399
|
(r) => r.spaceId === args.aggregate.app.spaceId,
|
|
408
400
|
);
|
|
409
401
|
const appMarkerHash =
|
|
410
|
-
appResolution?.entry.plan.destination.storageHash ?? args.aggregate.app.
|
|
402
|
+
appResolution?.entry.plan.destination.storageHash ?? requireHeadRef(args.aggregate.app).hash;
|
|
411
403
|
|
|
412
404
|
// Per-migration entries (one per authored edge) preserve the
|
|
413
405
|
// single-space `migrationsApplied` count semantics for back-compat
|
package/src/control-api/types.ts
CHANGED
|
@@ -18,7 +18,6 @@ import type {
|
|
|
18
18
|
VerifyDatabaseSchemaResult,
|
|
19
19
|
} from '@prisma-next/framework-components/control';
|
|
20
20
|
import type { PslDocumentAst } from '@prisma-next/framework-components/psl-ast';
|
|
21
|
-
import type { OnDiskMigrationPackage } from '@prisma-next/migration-tools/package';
|
|
22
21
|
import type { Result } from '@prisma-next/utils/result';
|
|
23
22
|
import type { ExecuteDbVerifyResult } from './operations/db-verify';
|
|
24
23
|
|
|
@@ -548,12 +547,6 @@ export interface MigrationApplyOptions {
|
|
|
548
547
|
readonly contract: unknown;
|
|
549
548
|
/** Migrations root directory (`migrations/` under the project). */
|
|
550
549
|
readonly migrationsDir: string;
|
|
551
|
-
/**
|
|
552
|
-
* Already-loaded app-space migration packages. The CLI loads these
|
|
553
|
-
* via `loadMigrationPackages(appMigrationsDir)` before invoking
|
|
554
|
-
* `migrationApply`.
|
|
555
|
-
*/
|
|
556
|
-
readonly appMigrationPackages: ReadonlyArray<OnDiskMigrationPackage>;
|
|
557
550
|
/**
|
|
558
551
|
* Optional app-space ref override. When provided, the app member's
|
|
559
552
|
* graph-walk targets this hash instead of `contract.storage.storageHash`.
|
package/src/migration-cli.ts
CHANGED
|
@@ -461,8 +461,8 @@ function writeStructuredError(stream: MigrationCliWritable, err: CliStructuredEr
|
|
|
461
461
|
* `null` when the file is missing and throwing `MIGRATION.INVALID_JSON`
|
|
462
462
|
* when the file is present but cannot be parsed as JSON. The CLI feeds
|
|
463
463
|
* this into `buildMigrationArtifacts` so the pure builder can preserve
|
|
464
|
-
* fields owned by `migration plan` (contract bookends,
|
|
465
|
-
*
|
|
464
|
+
* fields owned by `migration plan` (contract bookends, `createdAt`) across
|
|
465
|
+
* re-emits.
|
|
466
466
|
*
|
|
467
467
|
* Author-time path: this loader still does not verify the manifest hash
|
|
468
468
|
* or schema — that is the apply-time loader's job. Hash mismatch is the
|
|
@@ -472,8 +472,8 @@ function writeStructuredError(stream: MigrationCliWritable, err: CliStructuredEr
|
|
|
472
472
|
* however, is now surfaced rather than swallowed: a malformed
|
|
473
473
|
* `migration.json` indicates either a hand-edit gone wrong or partial
|
|
474
474
|
* write, and silently rebuilding from `describe()` would discard the
|
|
475
|
-
* user's on-disk content (preserved bookends,
|
|
476
|
-
*
|
|
475
|
+
* user's on-disk content (preserved bookends, `createdAt`) without any
|
|
476
|
+
* indication something was wrong on disk.
|
|
477
477
|
* Apply-time consumers always route through the verifying
|
|
478
478
|
* `readMigrationPackage` in `@prisma-next/migration-tools/io` instead.
|
|
479
479
|
*/
|
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,229 @@ 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 fromHash = typeof meta['fromHash'] === 'string' ? meta['fromHash'] : null;
|
|
256
|
+
const targetHash =
|
|
257
|
+
typeof meta['targetHash'] === 'string'
|
|
258
|
+
? meta['targetHash']
|
|
259
|
+
: typeof meta['target'] === 'string'
|
|
260
|
+
? meta['target']
|
|
261
|
+
: null;
|
|
262
|
+
const deadEnds = meta['deadEnds'];
|
|
263
|
+
const deadEndsSuffix =
|
|
264
|
+
Array.isArray(deadEnds) && deadEnds.length > 0
|
|
265
|
+
? ` Dead-ends: ${deadEnds.map(String).join(', ')}.`
|
|
266
|
+
: '';
|
|
267
|
+
const planFix = (() => {
|
|
268
|
+
if (fromHash !== null && targetHash !== null) {
|
|
269
|
+
return `Run \`prisma-next migration plan --from ${fromHash} --to ${targetHash}\` to introduce the missing path.`;
|
|
270
|
+
}
|
|
271
|
+
if (targetHash !== null) {
|
|
272
|
+
return `Run \`prisma-next migration plan --to ${targetHash}\` to introduce the missing path.`;
|
|
273
|
+
}
|
|
274
|
+
if (fromHash !== null) {
|
|
275
|
+
return `Run \`prisma-next migration plan --from ${fromHash}\` to introduce the missing path.`;
|
|
276
|
+
}
|
|
277
|
+
return 'Run `prisma-next migration plan` to introduce the missing path.';
|
|
278
|
+
})();
|
|
279
|
+
return errorRuntime(failure.summary, {
|
|
280
|
+
why:
|
|
281
|
+
failure.why ??
|
|
282
|
+
`Cannot reach target "${targetHash ?? '<unknown>'}" from current marker "${fromHash ?? '<unknown>'}".${deadEndsSuffix}`,
|
|
283
|
+
fix: [
|
|
284
|
+
'Run `prisma-next migration list` to see the on-disk graph.',
|
|
285
|
+
planFix,
|
|
286
|
+
'Run `prisma-next migration show <bundle>` for any bundle in the path you expected.',
|
|
287
|
+
].join('\n'),
|
|
288
|
+
meta: {
|
|
289
|
+
...meta,
|
|
290
|
+
code: 'MIGRATION.PATH_UNREACHABLE',
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
71
295
|
/**
|
|
72
296
|
* Maps a `MigrationToolsError` raised by the migration-tools loader/graph
|
|
73
297
|
* surface (`readMigrationPackage`, `readMigrationsDir`, `readRefs`,
|
|
@@ -154,7 +154,7 @@ export function resolveMigrationPaths(
|
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
156
|
* Slim representation of a PathDecision for CLI JSON output.
|
|
157
|
-
* Strips internal fields (createdAt
|
|
157
|
+
* Strips internal fields (createdAt) from path entries.
|
|
158
158
|
*/
|
|
159
159
|
export interface PathDecisionResult {
|
|
160
160
|
readonly fromHash: string;
|
|
@@ -242,9 +242,14 @@ export async function loadMigrationPackages(migrationsDir: string): Promise<{
|
|
|
242
242
|
bundles: readonly OnDiskMigrationPackage[];
|
|
243
243
|
graph: MigrationGraph;
|
|
244
244
|
}> {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
// `readMigrationsDir` is tolerant: it retains hash-/invariant-mismatched
|
|
246
|
+
// packages and omits unparseable ones, reporting both via `problems`.
|
|
247
|
+
// This helper preserves its historical `{ bundles, graph }` contract by
|
|
248
|
+
// exposing the retained packages; callers that need to surface load
|
|
249
|
+
// problems read them from the tolerant primitive directly.
|
|
250
|
+
const { packages } = await readMigrationsDir(migrationsDir);
|
|
251
|
+
const graph = reconstructGraph(packages);
|
|
252
|
+
return { bundles: packages, graph };
|
|
248
253
|
}
|
|
249
254
|
|
|
250
255
|
/**
|