@prisma-next/cli 0.16.0-dev.3 → 0.16.0-dev.31
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 +44 -45
- package/dist/cli.mjs +13 -13
- package/dist/{client-KuBQftxz.mjs → client-B1UjQc_x.mjs} +50 -58
- package/dist/client-B1UjQc_x.mjs.map +1 -0
- package/dist/{command-helpers-Cpq44aVa.mjs → command-helpers-D-jBl0Qt.mjs} +16 -8
- package/dist/command-helpers-D-jBl0Qt.mjs.map +1 -0
- package/dist/commands/contract-emit.mjs +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 +8 -6
- package/dist/commands/db-init.mjs.map +1 -1
- package/dist/commands/db-schema.mjs +3 -3
- package/dist/commands/db-sign.d.mts.map +1 -1
- package/dist/commands/db-sign.mjs +11 -12
- 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 +14 -15
- package/dist/commands/db-update.mjs.map +1 -1
- package/dist/commands/db-verify.mjs +1 -1
- package/dist/commands/migrate.d.mts +1 -1
- package/dist/commands/migrate.d.mts.map +1 -1
- package/dist/commands/migrate.mjs +13 -13
- package/dist/commands/migrate.mjs.map +1 -1
- package/dist/commands/migration-check.d.mts +4 -2
- package/dist/commands/migration-check.d.mts.map +1 -1
- package/dist/commands/migration-check.mjs +1 -1
- package/dist/commands/migration-graph.d.mts +1 -1
- package/dist/commands/migration-graph.mjs +4 -4
- package/dist/commands/migration-list.d.mts +1 -1
- package/dist/commands/migration-list.d.mts.map +1 -1
- package/dist/commands/migration-list.mjs +1 -1
- package/dist/commands/migration-log.d.mts +1 -1
- package/dist/commands/migration-log.mjs +1 -1
- package/dist/commands/migration-new.d.mts.map +1 -1
- package/dist/commands/migration-new.mjs +16 -40
- package/dist/commands/migration-new.mjs.map +1 -1
- package/dist/commands/migration-plan.d.mts +3 -4
- package/dist/commands/migration-plan.d.mts.map +1 -1
- package/dist/commands/migration-plan.mjs +1 -1
- package/dist/commands/migration-show.mjs +5 -5
- package/dist/commands/migration-show.mjs.map +1 -1
- package/dist/commands/migration-status.d.mts +1 -1
- package/dist/commands/migration-status.d.mts.map +1 -1
- package/dist/commands/migration-status.mjs +1 -1
- package/dist/commands/ref.d.mts +1 -1
- package/dist/commands/ref.d.mts.map +1 -1
- package/dist/commands/ref.mjs +13 -18
- package/dist/commands/ref.mjs.map +1 -1
- package/dist/commands/telemetry/index.mjs +1 -1
- package/dist/contract-at-errors-DvZ_DzJK.mjs +36 -0
- package/dist/contract-at-errors-DvZ_DzJK.mjs.map +1 -0
- package/dist/{contract-emit-CgnXSANN.mjs → contract-emit-BT46Mu8Q.mjs} +3 -3
- package/dist/{contract-emit-CgnXSANN.mjs.map → contract-emit-BT46Mu8Q.mjs.map} +1 -1
- package/dist/{contract-emit-cJQBlvGb.mjs → contract-emit-hVdlaF2U.mjs} +6 -7
- package/dist/{contract-emit-cJQBlvGb.mjs.map → contract-emit-hVdlaF2U.mjs.map} +1 -1
- package/dist/{contract-enrichment-gn9sWbPw.mjs → contract-enrichment-JUhLv-BX.mjs} +8 -8
- package/dist/{contract-enrichment-gn9sWbPw.mjs.map → contract-enrichment-JUhLv-BX.mjs.map} +1 -1
- package/dist/{contract-infer-Cg8evbeg.mjs → contract-infer-DpqTQECL.mjs} +3 -3
- package/dist/{contract-infer-Cg8evbeg.mjs.map → contract-infer-DpqTQECL.mjs.map} +1 -1
- package/dist/{contract-space-aggregate-loader-D_3VeHVb.mjs → contract-space-aggregate-loader-CNd-ZB6C.mjs} +14 -14
- package/dist/contract-space-aggregate-loader-CNd-ZB6C.mjs.map +1 -0
- package/dist/{db-verify-BEclUzki.mjs → db-verify-FEN6k1m7.mjs} +10 -8
- package/dist/db-verify-FEN6k1m7.mjs.map +1 -0
- package/dist/exports/control-api.d.mts +4 -4
- package/dist/exports/control-api.d.mts.map +1 -1
- package/dist/exports/control-api.mjs +3 -3
- package/dist/exports/index.d.mts +2 -1
- package/dist/exports/index.d.mts.map +1 -1
- package/dist/exports/index.mjs +61 -21
- 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/{format-DAUAZqPt.mjs → format-DI5qVr22.mjs} +8 -7
- package/dist/format-DI5qVr22.mjs.map +1 -0
- package/dist/{framework-components-CnbUbiJw.mjs → framework-components-C4XACYNB.mjs} +3 -3
- package/dist/framework-components-C4XACYNB.mjs.map +1 -0
- package/dist/{init-C3JhkHg-.mjs → init-ClrRkbwd.mjs} +77 -67
- package/dist/init-ClrRkbwd.mjs.map +1 -0
- package/dist/{inspect-live-schema-CX7EA5C3.mjs → inspect-live-schema-C0Rgdtw_.mjs} +4 -4
- package/dist/{inspect-live-schema-CX7EA5C3.mjs.map → inspect-live-schema-C0Rgdtw_.mjs.map} +1 -1
- package/dist/{migration-check-MHT3w7_v.mjs → migration-check-zEkHpPDT.mjs} +58 -30
- package/dist/migration-check-zEkHpPDT.mjs.map +1 -0
- package/dist/{migration-command-scaffold-CRyYrHZ9.mjs → migration-command-scaffold-CkNsp9g1.mjs} +4 -4
- package/dist/{migration-command-scaffold-CRyYrHZ9.mjs.map → migration-command-scaffold-CkNsp9g1.mjs.map} +1 -1
- package/dist/{migration-graph-command-render-B83xrnNy.mjs → migration-graph-command-render-DEwFpx-w.mjs} +5 -4
- package/dist/migration-graph-command-render-DEwFpx-w.mjs.map +1 -0
- package/dist/{migration-list-BAKujUjh.mjs → migration-list-BkafFVXS.mjs} +6 -6
- package/dist/migration-list-BkafFVXS.mjs.map +1 -0
- package/dist/{migration-log-C_xam2HZ.mjs → migration-log-BxhAtbhA.mjs} +5 -5
- package/dist/{migration-log-C_xam2HZ.mjs.map → migration-log-BxhAtbhA.mjs.map} +1 -1
- package/dist/{migration-path-target-DpPTsRCg.mjs → migration-path-target-B5HkjSTO.mjs} +2 -2
- package/dist/{migration-path-target-DpPTsRCg.mjs.map → migration-path-target-B5HkjSTO.mjs.map} +1 -1
- package/dist/{migration-plan-CreSVtWZ.mjs → migration-plan-Bk2pbPQH.mjs} +64 -74
- package/dist/migration-plan-Bk2pbPQH.mjs.map +1 -0
- package/dist/{migration-status-YgEvXf-u.mjs → migration-status-BzlARseq.mjs} +13 -12
- package/dist/migration-status-BzlARseq.mjs.map +1 -0
- package/dist/{output-mEQ74_nd.mjs → output-DWNYqZGc.mjs} +5 -6
- package/dist/output-DWNYqZGc.mjs.map +1 -0
- package/dist/{ref-advancement-BkXlikCA.mjs → ref-advancement-BCz7X7qJ.mjs} +13 -6
- package/dist/ref-advancement-BCz7X7qJ.mjs.map +1 -0
- package/dist/{telemetry-DVr6RFnq.mjs → telemetry-BbniBUbP.mjs} +2 -2
- package/dist/{telemetry-DVr6RFnq.mjs.map → telemetry-BbniBUbP.mjs.map} +1 -1
- package/dist/{types-D4r_HI9-.d.mts → types-DgXprE3w.d.mts} +3 -3
- package/dist/types-DgXprE3w.d.mts.map +1 -0
- package/dist/{verify-CgDVZjhc.mjs → verify-BSaNeaSL.mjs} +2 -2
- package/dist/{verify-CgDVZjhc.mjs.map → verify-BSaNeaSL.mjs.map} +1 -1
- package/package.json +21 -21
- package/src/commands/db-init.ts +5 -3
- package/src/commands/db-sign.ts +9 -7
- package/src/commands/db-update.ts +18 -9
- package/src/commands/db-verify.ts +4 -4
- package/src/commands/format.ts +1 -1
- package/src/commands/init/hygiene-gitattributes.ts +37 -21
- package/src/commands/init/init.ts +6 -6
- package/src/commands/init/output.ts +4 -5
- package/src/commands/init/probe-db.ts +9 -2
- package/src/commands/init/reinit-cleanup.ts +16 -17
- package/src/commands/init/templates/render.ts +2 -1
- package/src/commands/inspect-live-schema.ts +1 -1
- package/src/commands/migrate.ts +6 -5
- package/src/commands/migration-check.ts +72 -34
- package/src/commands/migration-list.ts +1 -5
- package/src/commands/migration-log.ts +1 -1
- package/src/commands/migration-new.ts +17 -41
- package/src/commands/migration-plan.ts +64 -88
- package/src/commands/migration-show.ts +2 -2
- package/src/commands/migration-status.ts +6 -7
- package/src/commands/ref.ts +19 -14
- package/src/control-api/client.ts +43 -25
- package/src/control-api/contract-enrichment.ts +7 -7
- package/src/control-api/operations/contract-emit.ts +2 -3
- package/src/control-api/operations/db-init.ts +3 -3
- package/src/control-api/operations/db-run.ts +8 -7
- package/src/control-api/operations/db-update.ts +2 -2
- package/src/control-api/operations/db-verify.ts +4 -4
- package/src/control-api/operations/format.ts +5 -4
- package/src/control-api/operations/migrate.ts +6 -5
- package/src/control-api/operations/run-migration.ts +2 -1
- package/src/control-api/types.ts +1 -1
- package/src/load-ts-contract.ts +81 -16
- package/src/utils/cli-errors.ts +15 -7
- package/src/utils/combine-verify-results.ts +2 -1
- package/src/utils/command-helpers.ts +15 -5
- package/src/utils/contract-at-errors.ts +13 -22
- package/src/utils/contract-space-aggregate-loader.ts +8 -8
- package/src/utils/contract-space-seed-phase.ts +11 -9
- package/src/utils/extension-pack-inputs.ts +8 -8
- package/src/utils/formatters/migration-graph-grid-layout.ts +2 -1
- package/src/utils/formatters/migration-graph-labels.ts +1 -2
- package/src/utils/formatters/migration-list-data-column.ts +1 -2
- package/src/utils/framework-components.ts +9 -9
- package/src/utils/integrity-violation-to-check-failure.ts +3 -3
- package/src/utils/migration-command-scaffold.ts +1 -1
- package/src/utils/plan-resolution.ts +7 -10
- package/src/utils/ref-advancement.ts +22 -3
- package/dist/client-KuBQftxz.mjs.map +0 -1
- package/dist/command-helpers-Cpq44aVa.mjs.map +0 -1
- package/dist/contract-at-errors-D9gEjYtg.mjs +0 -42
- package/dist/contract-at-errors-D9gEjYtg.mjs.map +0 -1
- package/dist/contract-space-aggregate-loader-D_3VeHVb.mjs.map +0 -1
- package/dist/db-verify-BEclUzki.mjs.map +0 -1
- package/dist/format-DAUAZqPt.mjs.map +0 -1
- package/dist/framework-components-CnbUbiJw.mjs.map +0 -1
- package/dist/init-C3JhkHg-.mjs.map +0 -1
- package/dist/migration-check-MHT3w7_v.mjs.map +0 -1
- package/dist/migration-graph-command-render-B83xrnNy.mjs.map +0 -1
- package/dist/migration-list-BAKujUjh.mjs.map +0 -1
- package/dist/migration-plan-CreSVtWZ.mjs.map +0 -1
- package/dist/migration-status-YgEvXf-u.mjs.map +0 -1
- package/dist/output-mEQ74_nd.mjs.map +0 -1
- package/dist/ref-advancement-BkXlikCA.mjs.map +0 -1
- package/dist/types-D4r_HI9-.d.mts.map +0 -1
- package/src/control-api/errors.ts +0 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { loadConfig } from '@prisma-next/config-loader';
|
|
3
3
|
import type { Contract } from '@prisma-next/contract/types';
|
|
4
4
|
import { getEmittedArtifactPaths } from '@prisma-next/emitter';
|
|
@@ -9,15 +9,14 @@ import {
|
|
|
9
9
|
type OperationPreview,
|
|
10
10
|
type SchemaOwnership,
|
|
11
11
|
} from '@prisma-next/framework-components/control';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
snapshotsImportPathFrom,
|
|
14
|
+
writeContractSnapshot,
|
|
15
|
+
} from '@prisma-next/migration-tools/contract-snapshot-store';
|
|
13
16
|
import { MigrationToolsError } from '@prisma-next/migration-tools/errors';
|
|
14
17
|
import { computeMigrationHash } from '@prisma-next/migration-tools/hash';
|
|
15
18
|
import { deriveProvidedInvariants } from '@prisma-next/migration-tools/invariants';
|
|
16
|
-
import {
|
|
17
|
-
copyFilesWithRename,
|
|
18
|
-
formatMigrationDirName,
|
|
19
|
-
writeMigrationPackage,
|
|
20
|
-
} from '@prisma-next/migration-tools/io';
|
|
19
|
+
import { formatMigrationDirName, writeMigrationPackage } from '@prisma-next/migration-tools/io';
|
|
21
20
|
import type { MigrationMetadata } from '@prisma-next/migration-tools/metadata';
|
|
22
21
|
import { writeMigrationTs } from '@prisma-next/migration-tools/migration-ts';
|
|
23
22
|
import { notOk, ok, type Result } from '@prisma-next/utils/result';
|
|
@@ -62,27 +61,6 @@ interface MigrationPlanOptions extends CommonCommandOptions {
|
|
|
62
61
|
readonly to?: string;
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
async function writeSnapshotContractArtifacts(
|
|
66
|
-
packageDir: string,
|
|
67
|
-
contractJson: unknown,
|
|
68
|
-
contractDts: string,
|
|
69
|
-
artifactBasename: 'start-contract' | 'end-contract',
|
|
70
|
-
): Promise<void> {
|
|
71
|
-
await mkdir(packageDir, { recursive: true });
|
|
72
|
-
const jsonContent = `${canonicalizeJson(contractJson)}\n`;
|
|
73
|
-
const dtsContent = contractDts.endsWith('\n') ? contractDts : `${contractDts}\n`;
|
|
74
|
-
await writeFile(join(packageDir, `${artifactBasename}.json`), jsonContent);
|
|
75
|
-
await writeFile(join(packageDir, `${artifactBasename}.d.ts`), dtsContent);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async function writeSnapshotStartContract(
|
|
79
|
-
packageDir: string,
|
|
80
|
-
contractJson: unknown,
|
|
81
|
-
contractDts: string,
|
|
82
|
-
): Promise<void> {
|
|
83
|
-
await writeSnapshotContractArtifacts(packageDir, contractJson, contractDts, 'start-contract');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
64
|
type PlannerSuccess = {
|
|
87
65
|
readonly plannedOps: readonly MigrationPlanOperation[];
|
|
88
66
|
readonly migrationTsContent: string;
|
|
@@ -99,6 +77,7 @@ async function runPlannerLeg(
|
|
|
99
77
|
fromContract: Contract | null,
|
|
100
78
|
spaceId: string,
|
|
101
79
|
ownership: SchemaOwnership,
|
|
80
|
+
snapshotsImportPath: string,
|
|
102
81
|
): Promise<Result<PlannerSuccess, CliStructuredError>> {
|
|
103
82
|
const fromSchema = migrations.contractToSchema(fromContract, frameworkComponents);
|
|
104
83
|
const plannerResult = planner.plan({
|
|
@@ -114,6 +93,7 @@ async function runPlannerLeg(
|
|
|
114
93
|
// space in the aggregate, so it stays a genuine drop; a table another
|
|
115
94
|
// space owns is never dropped.
|
|
116
95
|
ownership,
|
|
96
|
+
snapshotsImportPath,
|
|
117
97
|
});
|
|
118
98
|
if (plannerResult.kind === 'failure') {
|
|
119
99
|
return notOk(
|
|
@@ -309,21 +289,25 @@ async function executeMigrationPlanCommand(
|
|
|
309
289
|
let toStorageHash: string = rawStorageHash;
|
|
310
290
|
|
|
311
291
|
// When `--to <ref>` resolves a non-default destination, these carry its raw
|
|
312
|
-
// artifacts so the planned package's
|
|
313
|
-
// resolved target rather than copied from the emitted
|
|
292
|
+
// artifacts so the planned package's destination snapshot store entry is
|
|
293
|
+
// written from the resolved target rather than copied from the emitted
|
|
294
|
+
// `contract.json`.
|
|
314
295
|
let toArtifacts: { contractJson: unknown; contractDts: string } | null = null;
|
|
315
296
|
|
|
316
297
|
let fromContract: Contract | null = null;
|
|
317
298
|
let fromHash: string | null = null;
|
|
318
|
-
let
|
|
319
|
-
|
|
299
|
+
let snapshotStartContract: {
|
|
300
|
+
readonly fromHash: string;
|
|
301
|
+
readonly contractJson: unknown;
|
|
302
|
+
readonly contractDts: string;
|
|
303
|
+
} | null = null;
|
|
320
304
|
let isAutoBaseline = false;
|
|
321
305
|
|
|
322
306
|
const tolerantAggregateResult = await loadContractSpaceAggregateForCli({
|
|
323
307
|
targetId: config.target.targetId,
|
|
324
308
|
migrationsDir,
|
|
325
309
|
appContract: toContract,
|
|
326
|
-
|
|
310
|
+
extensions: config.extensions ?? [],
|
|
327
311
|
deserializeContract: (json: unknown) => familyInstance.deserializeContract(json),
|
|
328
312
|
});
|
|
329
313
|
if (!tolerantAggregateResult.ok) {
|
|
@@ -346,12 +330,12 @@ async function executeMigrationPlanCommand(
|
|
|
346
330
|
case 'graph-node':
|
|
347
331
|
fromHash = resolutionResult.value.fromHash;
|
|
348
332
|
fromContract = resolutionResult.value.fromContract;
|
|
349
|
-
fromContractSourceDir = resolutionResult.value.sourceDir;
|
|
350
333
|
break;
|
|
351
|
-
case '
|
|
334
|
+
case 'ref':
|
|
352
335
|
fromHash = resolutionResult.value.fromHash;
|
|
353
336
|
fromContract = resolutionResult.value.fromContract;
|
|
354
337
|
snapshotStartContract = {
|
|
338
|
+
fromHash: resolutionResult.value.fromHash,
|
|
355
339
|
contractJson: resolutionResult.value.contractJson,
|
|
356
340
|
contractDts: resolutionResult.value.contractDts,
|
|
357
341
|
};
|
|
@@ -360,6 +344,7 @@ async function executeMigrationPlanCommand(
|
|
|
360
344
|
fromHash = resolutionResult.value.fromHash;
|
|
361
345
|
fromContract = resolutionResult.value.fromContract;
|
|
362
346
|
snapshotStartContract = {
|
|
347
|
+
fromHash: resolutionResult.value.fromHash,
|
|
363
348
|
contractJson: resolutionResult.value.contractJson,
|
|
364
349
|
contractDts: resolutionResult.value.contractDts,
|
|
365
350
|
};
|
|
@@ -369,7 +354,7 @@ async function executeMigrationPlanCommand(
|
|
|
369
354
|
|
|
370
355
|
// `--to <ref>` swaps the planner destination to an arbitrary resolved
|
|
371
356
|
// contract (e.g. an ancestor / rollback target). The from-side resolution
|
|
372
|
-
// above is untouched; only the destination + its
|
|
357
|
+
// above is untouched; only the destination + its snapshot store entry
|
|
373
358
|
// change.
|
|
374
359
|
if (options.to !== undefined) {
|
|
375
360
|
const toResolution = await resolveToForPlan(options.to, {
|
|
@@ -386,15 +371,15 @@ async function executeMigrationPlanCommand(
|
|
|
386
371
|
};
|
|
387
372
|
}
|
|
388
373
|
|
|
389
|
-
// Phase 1 — seed: unconditionally re-emit per-space pinned
|
|
374
|
+
// Phase 1 — seed: unconditionally re-emit per-space pinned artifacts
|
|
390
375
|
// (contract.json / contract.d.ts / refs/head.json) and materialise any
|
|
391
376
|
// descriptor-shipped migration packages not yet on disk. Runs before
|
|
392
377
|
// the no-op check so that an extension bump alone (with no structural
|
|
393
|
-
// app-space change) still re-pins extension
|
|
394
|
-
const canonicalExtensionInputs = toExtensionInputs(config.
|
|
378
|
+
// app-space change) still re-pins extension artifacts on disk.
|
|
379
|
+
const canonicalExtensionInputs = toExtensionInputs(config.extensions ?? []);
|
|
395
380
|
const seedResult = await runContractSpaceSeedPhase({
|
|
396
381
|
migrationsDir,
|
|
397
|
-
|
|
382
|
+
extensions: canonicalExtensionInputs,
|
|
398
383
|
});
|
|
399
384
|
if (!flags.json && !flags.quiet) {
|
|
400
385
|
for (const record of seedResult.seeded) {
|
|
@@ -449,7 +434,7 @@ async function executeMigrationPlanCommand(
|
|
|
449
434
|
targetId: config.target.targetId,
|
|
450
435
|
migrationsDir,
|
|
451
436
|
appContract: toContract,
|
|
452
|
-
|
|
437
|
+
extensions: config.extensions ?? [],
|
|
453
438
|
deserializeContract: (json: unknown) => familyInstance.deserializeContract(json),
|
|
454
439
|
});
|
|
455
440
|
if (!aggregateResult.ok) {
|
|
@@ -460,27 +445,29 @@ async function executeMigrationPlanCommand(
|
|
|
460
445
|
const frameworkComponents = assertFrameworkComponentsCompatible(
|
|
461
446
|
config.family.familyId,
|
|
462
447
|
config.target.targetId,
|
|
463
|
-
[config.target, config.adapter, ...(config.
|
|
448
|
+
[config.target, config.adapter, ...(config.extensions ?? [])],
|
|
464
449
|
);
|
|
465
450
|
|
|
466
|
-
// Write the planned package's destination
|
|
467
|
-
// resolved target's raw artifacts are written; otherwise
|
|
468
|
-
// `contract.json` / `contract.d.ts` are
|
|
469
|
-
async function
|
|
451
|
+
// Write the planned package's destination contract into the snapshot store.
|
|
452
|
+
// With `--to`, the resolved target's raw artifacts are written; otherwise
|
|
453
|
+
// the emitted `contract.json` / `contract.d.ts` are read from disk.
|
|
454
|
+
async function writeDestinationSnapshot(destHash: string): Promise<void> {
|
|
470
455
|
if (toArtifacts !== null) {
|
|
471
|
-
await
|
|
472
|
-
|
|
473
|
-
toArtifacts.
|
|
474
|
-
|
|
475
|
-
'end-contract',
|
|
476
|
-
);
|
|
456
|
+
await writeContractSnapshot(migrationsDir, destHash, {
|
|
457
|
+
contractJson: toArtifacts.contractJson,
|
|
458
|
+
contractDts: toArtifacts.contractDts,
|
|
459
|
+
});
|
|
477
460
|
return;
|
|
478
461
|
}
|
|
479
462
|
const destinationArtifacts = getEmittedArtifactPaths(contractPathAbsolute);
|
|
480
|
-
await
|
|
481
|
-
|
|
482
|
-
|
|
463
|
+
const [contractJsonRaw, contractDts] = await Promise.all([
|
|
464
|
+
readFile(destinationArtifacts.jsonPath, 'utf-8'),
|
|
465
|
+
readFile(destinationArtifacts.dtsPath, 'utf-8'),
|
|
483
466
|
]);
|
|
467
|
+
await writeContractSnapshot(migrationsDir, destHash, {
|
|
468
|
+
contractJson: JSON.parse(contractJsonRaw) as unknown,
|
|
469
|
+
contractDts,
|
|
470
|
+
});
|
|
484
471
|
}
|
|
485
472
|
|
|
486
473
|
try {
|
|
@@ -507,6 +494,7 @@ async function executeMigrationPlanCommand(
|
|
|
507
494
|
null,
|
|
508
495
|
aggregate.app.spaceId,
|
|
509
496
|
aggregate,
|
|
497
|
+
snapshotsImportPathFrom(baselinePackageDir, migrationsDir),
|
|
510
498
|
);
|
|
511
499
|
if (!baselineLeg.ok) {
|
|
512
500
|
return notOk(baselineLeg.failure);
|
|
@@ -519,12 +507,10 @@ async function executeMigrationPlanCommand(
|
|
|
519
507
|
baselineTimestamp,
|
|
520
508
|
baselineLeg.value,
|
|
521
509
|
);
|
|
522
|
-
await
|
|
523
|
-
|
|
524
|
-
snapshotStartContract.
|
|
525
|
-
|
|
526
|
-
'end-contract',
|
|
527
|
-
);
|
|
510
|
+
await writeContractSnapshot(migrationsDir, fromHash, {
|
|
511
|
+
contractJson: snapshotStartContract.contractJson,
|
|
512
|
+
contractDts: snapshotStartContract.contractDts,
|
|
513
|
+
});
|
|
528
514
|
|
|
529
515
|
if (fromHash === toStorageHash) {
|
|
530
516
|
const baselineOps = baselineLeg.value.hasPlaceholders ? [] : baselineLeg.value.plannedOps;
|
|
@@ -577,6 +563,7 @@ async function executeMigrationPlanCommand(
|
|
|
577
563
|
fromContract,
|
|
578
564
|
aggregate.app.spaceId,
|
|
579
565
|
aggregate,
|
|
566
|
+
snapshotsImportPathFrom(deltaPackageDir, migrationsDir),
|
|
580
567
|
);
|
|
581
568
|
if (!deltaLeg.ok) {
|
|
582
569
|
return notOk(deltaLeg.failure);
|
|
@@ -589,12 +576,11 @@ async function executeMigrationPlanCommand(
|
|
|
589
576
|
deltaTimestamp,
|
|
590
577
|
deltaLeg.value,
|
|
591
578
|
);
|
|
592
|
-
await
|
|
593
|
-
await
|
|
594
|
-
|
|
595
|
-
snapshotStartContract.
|
|
596
|
-
|
|
597
|
-
);
|
|
579
|
+
await writeDestinationSnapshot(toStorageHash);
|
|
580
|
+
await writeContractSnapshot(migrationsDir, fromHash, {
|
|
581
|
+
contractJson: snapshotStartContract.contractJson,
|
|
582
|
+
contractDts: snapshotStartContract.contractDts,
|
|
583
|
+
});
|
|
598
584
|
|
|
599
585
|
const deltaOps = deltaLeg.value.hasPlaceholders ? [] : deltaLeg.value.plannedOps;
|
|
600
586
|
if (deltaLeg.value.hasPlaceholders) {
|
|
@@ -651,6 +637,7 @@ async function executeMigrationPlanCommand(
|
|
|
651
637
|
fromContract,
|
|
652
638
|
aggregate.app.spaceId,
|
|
653
639
|
aggregate,
|
|
640
|
+
snapshotsImportPathFrom(packageDir, migrationsDir),
|
|
654
641
|
);
|
|
655
642
|
if (!deltaLeg.ok) {
|
|
656
643
|
return notOk(deltaLeg.failure);
|
|
@@ -663,21 +650,12 @@ async function executeMigrationPlanCommand(
|
|
|
663
650
|
timestamp,
|
|
664
651
|
deltaLeg.value,
|
|
665
652
|
);
|
|
666
|
-
await
|
|
667
|
-
if (
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
{ sourcePath: sourceArtifacts.jsonPath, destName: 'start-contract.json' },
|
|
673
|
-
{ sourcePath: sourceArtifacts.dtsPath, destName: 'start-contract.d.ts' },
|
|
674
|
-
]);
|
|
675
|
-
} else if (snapshotStartContract !== null) {
|
|
676
|
-
await writeSnapshotStartContract(
|
|
677
|
-
packageDir,
|
|
678
|
-
snapshotStartContract.contractJson,
|
|
679
|
-
snapshotStartContract.contractDts,
|
|
680
|
-
);
|
|
653
|
+
await writeDestinationSnapshot(toStorageHash);
|
|
654
|
+
if (snapshotStartContract !== null) {
|
|
655
|
+
await writeContractSnapshot(migrationsDir, snapshotStartContract.fromHash, {
|
|
656
|
+
contractJson: snapshotStartContract.contractJson,
|
|
657
|
+
contractDts: snapshotStartContract.contractDts,
|
|
658
|
+
});
|
|
681
659
|
}
|
|
682
660
|
|
|
683
661
|
if (deltaLeg.value.hasPlaceholders) {
|
|
@@ -953,10 +931,9 @@ export type PrefixResolutionFailure =
|
|
|
953
931
|
*
|
|
954
932
|
* Note: matches `metadata.to` (the contract hash this migration produces),
|
|
955
933
|
* not `metadata.migrationHash` (the package's content-addressed identity).
|
|
956
|
-
* Tries exact match first, then prefix match
|
|
957
|
-
*
|
|
958
|
-
*
|
|
959
|
-
* not found.
|
|
934
|
+
* Tries exact match first, then prefix match. Returns the matched package on
|
|
935
|
+
* success, or a discriminated failure indicating whether the prefix was
|
|
936
|
+
* ambiguous or simply not found.
|
|
960
937
|
*
|
|
961
938
|
* @internal Exported for testing only.
|
|
962
939
|
*/
|
|
@@ -967,8 +944,7 @@ export function resolveBundleByPrefix<T extends { metadata: { to: string } }>(
|
|
|
967
944
|
const exact = bundles.find((p) => p.metadata.to === needle);
|
|
968
945
|
if (exact) return ok(exact);
|
|
969
946
|
|
|
970
|
-
const
|
|
971
|
-
const candidates = bundles.filter((p) => p.metadata.to.startsWith(prefixWithScheme));
|
|
947
|
+
const candidates = bundles.filter((p) => p.metadata.to.startsWith(needle));
|
|
972
948
|
|
|
973
949
|
if (candidates.length === 1) return ok(candidates[0]!);
|
|
974
950
|
if (candidates.length > 1) return notOk({ reason: 'ambiguous', count: candidates.length });
|
|
@@ -119,7 +119,7 @@ async function executeMigrationShowCommand(
|
|
|
119
119
|
target: config.target,
|
|
120
120
|
adapter: config.adapter,
|
|
121
121
|
...ifDefined('driver', config.driver),
|
|
122
|
-
|
|
122
|
+
extensions: config.extensions ?? [],
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
let contractJsonContent: string;
|
|
@@ -228,7 +228,7 @@ export function createMigrationShowCommand(): Command {
|
|
|
228
228
|
);
|
|
229
229
|
setCommandExamples(command, [
|
|
230
230
|
'prisma-next migration show 20260101_100000_add_user',
|
|
231
|
-
'prisma-next migration show
|
|
231
|
+
'prisma-next migration show a1b2c3',
|
|
232
232
|
'prisma-next migration show 20260101_100000_add_user --json',
|
|
233
233
|
]);
|
|
234
234
|
setCommandSeeAlso(command, [
|
|
@@ -111,8 +111,7 @@ interface MigrationStatusCommandResult {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
function shortDisplayHash(hash: string): string {
|
|
114
|
-
|
|
115
|
-
return stripped.slice(0, 12);
|
|
114
|
+
return hash.slice(0, 12);
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
function resolveTarget(contractHash: string, activeRefHash: string | undefined): string {
|
|
@@ -421,7 +420,7 @@ export async function executeMigrationStatusCommand(
|
|
|
421
420
|
target: config.target,
|
|
422
421
|
adapter: config.adapter,
|
|
423
422
|
driver: config.driver,
|
|
424
|
-
|
|
423
|
+
extensions: config.extensions ?? [],
|
|
425
424
|
});
|
|
426
425
|
try {
|
|
427
426
|
await client.connect(dbConnection);
|
|
@@ -660,10 +659,10 @@ export function createMigrationStatusCommand(): Command {
|
|
|
660
659
|
setCommandExamples(command, [
|
|
661
660
|
'prisma-next migration status --db $DATABASE_URL',
|
|
662
661
|
'prisma-next migration status --to production --db $DATABASE_URL',
|
|
663
|
-
'prisma-next migration status --from
|
|
664
|
-
'prisma-next migration status --from
|
|
665
|
-
'prisma-next migration status --ascii --from
|
|
666
|
-
'prisma-next migration status --legend --from
|
|
662
|
+
'prisma-next migration status --from abc123 --to production',
|
|
663
|
+
'prisma-next migration status --from abc123 --to production --json',
|
|
664
|
+
'prisma-next migration status --ascii --from abc123 --to production',
|
|
665
|
+
'prisma-next migration status --legend --from abc123 --to production',
|
|
667
666
|
]);
|
|
668
667
|
setCommandSeeAlso(command, [
|
|
669
668
|
{ verb: 'migration log', oneLiner: 'Show executed migration history' },
|
package/src/commands/ref.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
1
|
import { loadConfig } from '@prisma-next/config-loader';
|
|
3
2
|
import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';
|
|
3
|
+
import {
|
|
4
|
+
contractSnapshotDir,
|
|
5
|
+
readContractSnapshotJson,
|
|
6
|
+
} from '@prisma-next/migration-tools/contract-snapshot-store';
|
|
4
7
|
import { MigrationToolsError } from '@prisma-next/migration-tools/errors';
|
|
5
8
|
import { findLatestMigration, isGraphNode } from '@prisma-next/migration-tools/migration-graph';
|
|
6
9
|
import { parseContractRef } from '@prisma-next/migration-tools/ref-resolution';
|
|
7
10
|
import type { RefEntry } from '@prisma-next/migration-tools/refs';
|
|
8
11
|
import {
|
|
9
|
-
|
|
12
|
+
deleteRef,
|
|
10
13
|
readRefs,
|
|
11
14
|
validateRefName,
|
|
12
15
|
validateRefValue,
|
|
13
|
-
|
|
16
|
+
writeRef,
|
|
14
17
|
} from '@prisma-next/migration-tools/refs';
|
|
15
18
|
import { notOk, ok, type Result } from '@prisma-next/utils/result';
|
|
16
19
|
import { Command } from 'commander';
|
|
@@ -34,7 +37,6 @@ import {
|
|
|
34
37
|
import { buildReadAggregate } from '../utils/contract-space-aggregate-loader';
|
|
35
38
|
import { formatCommandHelp } from '../utils/formatters/help';
|
|
36
39
|
import { parseGlobalFlags, parseGlobalFlagsOrExit } from '../utils/global-flags';
|
|
37
|
-
import { readContractIR } from '../utils/ref-advancement';
|
|
38
40
|
import { handleResult } from '../utils/result-handler';
|
|
39
41
|
import { createTerminalUI } from '../utils/terminal-ui';
|
|
40
42
|
|
|
@@ -114,26 +116,29 @@ export async function executeRefSetCommand(
|
|
|
114
116
|
return notOk(errorRefSetBundleNotFound(resolvedHash));
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
const contractJsonPath = join(
|
|
118
|
-
|
|
119
|
+
const contractJsonPath = join(
|
|
120
|
+
contractSnapshotDir(migrationsDir, resolvedHash),
|
|
121
|
+
'contract.json',
|
|
122
|
+
);
|
|
119
123
|
try {
|
|
120
|
-
|
|
121
|
-
contractJson = JSON.parse(raw) as Record<string, unknown>;
|
|
124
|
+
await readContractSnapshotJson(migrationsDir, resolvedHash);
|
|
122
125
|
} catch (readError) {
|
|
123
|
-
if (
|
|
126
|
+
if (
|
|
127
|
+
MigrationToolsError.is(readError) &&
|
|
128
|
+
readError.code === 'MIGRATION.CONTRACT_SNAPSHOT_MISSING'
|
|
129
|
+
) {
|
|
124
130
|
return notOk(
|
|
125
131
|
errorFileNotFound(contractJsonPath, {
|
|
126
|
-
why: `Migration bundle for hash ${resolvedHash} is missing its
|
|
127
|
-
fix: '
|
|
132
|
+
why: `Migration bundle for hash ${resolvedHash} is missing its contract snapshot at ${contractJsonPath}`,
|
|
133
|
+
fix: 'Restore migrations/snapshots/ from version control, or re-run the command that produced this migration to regenerate its snapshot.',
|
|
128
134
|
}),
|
|
129
135
|
);
|
|
130
136
|
}
|
|
131
137
|
throw readError;
|
|
132
138
|
}
|
|
133
139
|
|
|
134
|
-
const contractIR = await readContractIR(contractJson, contractJsonPath);
|
|
135
140
|
const entry: RefEntry = { hash: resolvedHash, invariants: [] };
|
|
136
|
-
await
|
|
141
|
+
await writeRef(refsDir, name, entry);
|
|
137
142
|
return ok({ ok: true as const, ref: name, hash: resolvedHash, invariants: [] });
|
|
138
143
|
} catch (error) {
|
|
139
144
|
if (error instanceof CliStructuredError) return notOk(error);
|
|
@@ -148,7 +153,7 @@ export async function executeRefDeleteCommand(
|
|
|
148
153
|
try {
|
|
149
154
|
const config = await loadConfig(options.config);
|
|
150
155
|
const { refsDir } = resolveMigrationPaths(options.config, config);
|
|
151
|
-
await
|
|
156
|
+
await deleteRef(refsDir, name);
|
|
152
157
|
return ok({ ok: true as const, ref: name, deleted: true as const });
|
|
153
158
|
} catch (error) {
|
|
154
159
|
if (error instanceof CliStructuredError) return notOk(error);
|