@prisma/orm-toolchain 8.0.0-rc.17-dev.37 → 8.0.0-rc.17-dev.38
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/{aggregate-C0Kci0iw.mjs → aggregate-CJjYCgNP.mjs} +6 -2
- package/dist/aggregate-CJjYCgNP.mjs.map +1 -0
- package/dist/{aggregate-C23h_Ybm.d.mts → aggregate-MAVa_CD0.d.mts} +6 -2
- package/dist/{aggregate-C23h_Ybm.d.mts.map → aggregate-MAVa_CD0.d.mts.map} +1 -1
- package/dist/{caught-errors-DUV-u8yQ-DuPp394m.mjs → caught-errors-olsx_RBn-Cg0ilJtv.mjs} +133 -8
- package/dist/caught-errors-olsx_RBn-Cg0ilJtv.mjs.map +1 -0
- package/dist/cli.mjs +368 -93
- package/dist/cli.mjs.map +1 -1
- package/dist/cli__control-api.d.mts +14 -9
- package/dist/cli__control-api.d.mts.map +1 -1
- package/dist/cli__control-api.mjs +2 -2
- package/dist/cli__control-api__testing.d.mts +1 -1
- package/dist/cli__control-api__testing.mjs +1 -0
- package/dist/cli__control-api__testing.mjs.map +1 -1
- package/dist/cli__migration-cli.mjs +2 -2
- package/dist/cli__migration-cli.mjs.map +1 -1
- package/dist/{db-sign-DvCsMwUF-D5UIkRXD.d.mts → db-sign-D90hPxFE-B-YLAvFQ.d.mts} +77 -22
- package/dist/db-sign-D90hPxFE-B-YLAvFQ.d.mts.map +1 -0
- package/dist/migration-tools.d.mts +1 -1
- package/dist/migration-tools.mjs +1 -1
- package/dist/migration-tools__aggregate.d.mts +1 -1
- package/dist/migration-tools__aggregate.mjs +1 -1
- package/dist/{ref-BITTabCb-DT5r3Y3B.mjs → ref-BMhPu-wB-DU1LW2lb.mjs} +439 -160
- package/dist/ref-BMhPu-wB-DU1LW2lb.mjs.map +1 -0
- package/dist/vite-plugin-contract-emit.mjs +1 -1
- package/package.json +12 -12
- package/dist/aggregate-C0Kci0iw.mjs.map +0 -1
- package/dist/caught-errors-DUV-u8yQ-DuPp394m.mjs.map +0 -1
- package/dist/db-sign-DvCsMwUF-D5UIkRXD.d.mts.map +0 -1
- package/dist/ref-BITTabCb-DT5r3Y3B.mjs.map +0 -1
|
@@ -8,18 +8,18 @@ import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
|
|
|
8
8
|
import { i as findPathWithDecision, r as findPath } from "./migration-graph-BoiiZAaU-DLht12k7.mjs";
|
|
9
9
|
import { a as isValidSpaceId, c as spaceMigrationDirectory, l as spaceRefsDirectory, o as listContractSpaceDirectories, s as readContractSpaceHeadRef, t as APP_SPACE_ID$1 } from "./verify-contract-spaces-sL5mlmCX-K2P69KDp.mjs";
|
|
10
10
|
import { i as emitContractSpaceArtifacts, o as planAllSpaces } from "./spaces-CtxjvIS0.mjs";
|
|
11
|
-
import {
|
|
11
|
+
import { $ as errorUnexpected, C as errorFileNotFound, E as errorInvalidSpaceId, F as errorPlanOriginUnknown, G as errorStatementAnswersNoQuestion, I as errorPlanProducedNoOperations, J as errorStatementNeedsMigrationFile, K as errorStatementDidNotResolveLoss, L as errorRefSetBundleNotFound, N as errorPathUnreachable, O as errorMarkerMismatch, P as errorPlanForgotTheFlag, R as errorRefSetEmptySentinel, U as errorSnapshotMissing, V as errorRuntime, W as errorSpaceNotFound, X as errorStatementUnresolved, Y as errorStatementOriginUnknown, Z as errorTargetMigrationNotSupported, ct as requireLiveDatabase, d as collectDeclaredInvariants, dt as runCommandAction, et as getTargetMigrations, ft as selfEmitCommand, g as errorConfigValidation$1, gt as toStructuralEdge, h as errorAmbiguousMigrationRef, j as errorMigrationPlanningFailed, lt as resolveContractPath, mt as statementFlag, n as CliStructuredError$1, ot as readContractEnvelope, q as errorStatementInvalid, r as STORE_ORIGIN_SNAPSHOT_STEPS, s as chooseAction, tt as mapRefResolutionError, u as closeQuietly, ut as resolveMigrationPaths, v as errorContractConfigMissing, w as errorFromCaught, y as errorContractValidationFailed, z as errorRefSetHashNotInGraph } from "./caught-errors-olsx_RBn-Cg0ilJtv.mjs";
|
|
12
12
|
import { r as getEmittedArtifactPaths, t as emit } from "./exports-BP5EU7G8-CdTO3MPb.mjs";
|
|
13
13
|
import { n as isGraphNode, t as assertHashIsGraphNode } from "./graph-membership-C-5WMh1R-BUtW54H2.mjs";
|
|
14
14
|
import { d as writeRef, i as readRefs, l as validateRefName, n as deleteRef, o as refsByContractHash, t as HEAD_REF_NAME, u as validateRefValue } from "./refs-CS997f-J-BxkRLuCE.mjs";
|
|
15
|
-
import { a as contractHashAtMarker, c as loadContractSpaceAggregate, d as requireHeadRef, f as resolveRecordedPath, m as verifyMigration, n as buildFabricatedMigrationEdge, p as spacesInApplyOrder, r as collectAggregateNamespaces, t as allStorageElementsExternal, u as planMigration } from "./aggregate-
|
|
15
|
+
import { a as contractHashAtMarker, c as loadContractSpaceAggregate, d as requireHeadRef, f as resolveRecordedPath, m as verifyMigration, n as buildFabricatedMigrationEdge, p as spacesInApplyOrder, r as collectAggregateNamespaces, t as allStorageElementsExternal, u as planMigration } from "./aggregate-CJjYCgNP.mjs";
|
|
16
16
|
import { c as internalImportRoot, o as importRootForDependencies, r as createImportSpecifierResolver, t as ImportRootError } from "./import-roots-B6vrm5bT.mjs";
|
|
17
17
|
import { c as parseContractRef, l as parseMigrationRef, o as isLiveMarkerRef, r as RESERVED_CONTRACT_REFS, s as isReservedContractRef, t as EMPTY_CONTRACT_REF } from "./ref-resolution-kNMjYJ26.mjs";
|
|
18
18
|
import { a as writeMigrationTs } from "./migration-ts-DDgjsR1O.mjs";
|
|
19
19
|
import { createRequire } from "node:module";
|
|
20
20
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
21
21
|
import { CliStructuredError } from "@prisma/orm-framework/errors/control";
|
|
22
|
-
import { APP_SPACE_ID, CONTRACT_SNAPSHOTS_DIRNAME, createControlStack, describeMigrationStatement, hasMigrations, hasOperationPreview, hasPslContractInfer, hasSchemaSubjectClassifier, hasSchemaView, isStorageHashHex, migrationStatementJson, migrationSubjectJson, migrationSubjectKey, modelDisplayName, planOriginOf } from "@prisma/orm-framework/components/control";
|
|
22
|
+
import { APP_SPACE_ID, CONTRACT_SNAPSHOTS_DIRNAME, createControlStack, describeMigrationStatement, fieldStatementText, hasMigrations, hasOperationPreview, hasPslContractInfer, hasSchemaSubjectClassifier, hasSchemaView, isStorageHashHex, migrationStatementJson, migrationSubjectJson, migrationSubjectKey, modelDisplayName, modelStatementText, planOriginOf } from "@prisma/orm-framework/components/control";
|
|
23
23
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
24
24
|
import { isStructuredErrorCode, structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
25
25
|
import { basename, dirname, isAbsolute, join, relative, resolve } from "pathe";
|
|
@@ -31,9 +31,10 @@ import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
|
|
|
31
31
|
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
32
32
|
import { mergeCapabilityMatrices } from "@prisma/orm-framework/components/components";
|
|
33
33
|
import { asNamespaceId } from "@prisma/orm-framework/contract/types";
|
|
34
|
+
import { isDeepStrictEqual } from "node:util";
|
|
34
35
|
import { abortable } from "@prisma/orm-framework/utils/abortable";
|
|
35
36
|
import { resolve as resolve$1 } from "node:path";
|
|
36
|
-
//#region ../../../1-framework/3-tooling/cli/dist/ref-
|
|
37
|
+
//#region ../../../1-framework/3-tooling/cli/dist/ref-BMhPu-wB.mjs
|
|
37
38
|
/**
|
|
38
39
|
* Asserts that all framework components are compatible with the expected family and target.
|
|
39
40
|
*
|
|
@@ -166,7 +167,7 @@ function enrichContract(ir, components) {
|
|
|
166
167
|
extensions: sortDeepTyped(extensions)
|
|
167
168
|
};
|
|
168
169
|
}
|
|
169
|
-
function formsFix(verb) {
|
|
170
|
+
function formsFix$1(verb) {
|
|
170
171
|
return verb === "delete" ? "Write the statement as --delete <name>, where the name is Model, namespace.Model, Model.field or namespace.Model.field, or the storage name the refusal gave, for example --delete Legacy or --delete User.nickname." : "Write the statement as --allow <name>, where the name is the model the refusal gave, for example --allow User.";
|
|
171
172
|
}
|
|
172
173
|
/**
|
|
@@ -176,12 +177,35 @@ function formsFix(verb) {
|
|
|
176
177
|
* may contain any character a quoted identifier can.
|
|
177
178
|
*/
|
|
178
179
|
function parseConsentStatement(statement) {
|
|
179
|
-
if (statement.text.trim() === "") return notOk(errorStatementInvalid(statement, "The statement names nothing.", formsFix(statement.verb)));
|
|
180
|
+
if (statement.text.trim() === "") return notOk(errorStatementInvalid(statement, "The statement names nothing.", formsFix$1(statement.verb)));
|
|
180
181
|
return ok({
|
|
181
182
|
verb: statement.verb,
|
|
182
183
|
text: statement.text
|
|
183
184
|
});
|
|
184
185
|
}
|
|
186
|
+
function formsFix(verb) {
|
|
187
|
+
return `Write the statement as --${verb} <field>, where the field is Model.field or namespace.Model.field as the destination contract names it, for example --${verb} User.age.`;
|
|
188
|
+
}
|
|
189
|
+
/** Parses the text of one convert or backfill statement, `Model.field` or `namespace.Model.field`. */
|
|
190
|
+
function parseFieldStatement(statement) {
|
|
191
|
+
const invalid = (why) => notOk(errorStatementInvalid(statement, why, formsFix(statement.verb)));
|
|
192
|
+
if (statement.text.includes(":")) return invalid("The statement names one field, not an old and a new name.");
|
|
193
|
+
const segments = statement.text.split(".");
|
|
194
|
+
if (segments.some((segment) => segment === "")) return invalid(`"${statement.text}" has an empty name.`);
|
|
195
|
+
const [first, second, third] = segments;
|
|
196
|
+
if (first === void 0 || second === void 0) return invalid(`"${statement.text}" names a model; a --${statement.verb} statement names a field.`);
|
|
197
|
+
if (segments.length > 3) return invalid(`"${statement.text}" has ${segments.length} names; at most three are allowed.`);
|
|
198
|
+
const field = third === void 0 ? [first, second] : [
|
|
199
|
+
first,
|
|
200
|
+
second,
|
|
201
|
+
third
|
|
202
|
+
];
|
|
203
|
+
return ok({
|
|
204
|
+
verb: statement.verb,
|
|
205
|
+
text: statement.text,
|
|
206
|
+
field
|
|
207
|
+
});
|
|
208
|
+
}
|
|
185
209
|
const MAX_SEGMENTS = 3;
|
|
186
210
|
/** The forms a statement takes, with an example of each. */
|
|
187
211
|
function statementFormsFix(verb) {
|
|
@@ -295,7 +319,8 @@ function missing(reason) {
|
|
|
295
319
|
function valueObjectRefusal(name) {
|
|
296
320
|
return {
|
|
297
321
|
reason: `"${name}" is a value object, and value object renames are not supported in this release`,
|
|
298
|
-
fix: VALUE_OBJECT_FIX
|
|
322
|
+
fix: VALUE_OBJECT_FIX,
|
|
323
|
+
valueObject: name
|
|
299
324
|
};
|
|
300
325
|
}
|
|
301
326
|
function lookupModelInNamespace(contract, namespaceId, namespace, name) {
|
|
@@ -512,6 +537,7 @@ function resolveFieldRename(state, statement, from, to) {
|
|
|
512
537
|
if (hasField(to.model, from.coordinate.field)) return notOk(errorStatementUnresolved(statement, `The field "${from.coordinate.field}" still exists on the destination model "${toModel}", so it was not renamed.`, CHECK_NAMES_FIX));
|
|
513
538
|
state.renamedFrom.add(fromKey);
|
|
514
539
|
state.renamedTo.add(toKey);
|
|
540
|
+
state.originOfRenamedField.set(qualifiedField(to.coordinate), from.coordinate);
|
|
515
541
|
return ok({
|
|
516
542
|
kind: "rename",
|
|
517
543
|
entity: "field",
|
|
@@ -557,16 +583,88 @@ function resolveStatement(state, statement, later) {
|
|
|
557
583
|
if (from.value.entity === "field" && to.value.entity === "field") return resolveFieldRename(state, statement, from.value, to.value);
|
|
558
584
|
return notOk(errorStatementInvalid(statement, "The statement names a model on one side and a field on the other.", mixedSidesFix(statement.verb, statement.from, statement.to)));
|
|
559
585
|
}
|
|
586
|
+
function typeText(type) {
|
|
587
|
+
switch (type.kind) {
|
|
588
|
+
case "scalar": return type.typeParams === void 0 ? type.codecId : `${type.codecId}(${JSON.stringify(type.typeParams)})`;
|
|
589
|
+
case "valueObject": return type.name;
|
|
590
|
+
case "union": return type.members.map(typeText).join(" | ");
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
function fieldTypeText(field) {
|
|
594
|
+
return `${typeText(field.type)}${field.many ? "[]" : ""}${field.dict ? " dict" : ""}`;
|
|
595
|
+
}
|
|
596
|
+
function sameType(origin, destination) {
|
|
597
|
+
const shape = (field) => ({
|
|
598
|
+
type: field.type,
|
|
599
|
+
many: field.many ?? false,
|
|
600
|
+
dict: field.dict ?? false
|
|
601
|
+
});
|
|
602
|
+
return isDeepStrictEqual(shape(origin), shape(destination));
|
|
603
|
+
}
|
|
560
604
|
/**
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
|
|
605
|
+
* A convert or backfill statement names a field as the destination contract names it. A convert
|
|
606
|
+
* needs the field in the origin contract, under its origin name when a rename gave it a new one,
|
|
607
|
+
* with another type. A backfill needs the field required in the destination contract and, on a
|
|
608
|
+
* model the origin has, either new or optional there.
|
|
609
|
+
*/
|
|
610
|
+
function resolveFieldStatement(state, statement) {
|
|
611
|
+
const { verb } = statement;
|
|
612
|
+
const [namespaceId, modelName, field] = statement.field.length === 3 ? statement.field : [void 0, ...statement.field];
|
|
613
|
+
const flag = statementFlag(statement);
|
|
614
|
+
const leaveOut = `Leave out ${flag}.`;
|
|
615
|
+
const refuse = (reason, fix = leaveOut) => notOk(unresolved(statement, {
|
|
616
|
+
reason,
|
|
617
|
+
fix
|
|
618
|
+
}));
|
|
619
|
+
const destination = lookupModel(state.destination, namespaceId, modelName);
|
|
620
|
+
if (destination.kind !== "found") {
|
|
621
|
+
if (destination.valueObject !== void 0) return refuse(`"${destination.valueObject}" is a value object; a --${verb} statement names a field of a model`);
|
|
622
|
+
return refuse(destination.reason, destination.kind === "missing" ? `A --${verb} statement names a field as the destination contract names it, Model.field or namespace.Model.field. Names match exactly, including case.` : destination.fix);
|
|
623
|
+
}
|
|
624
|
+
const coordinate = {
|
|
625
|
+
...destination.coordinate,
|
|
626
|
+
field
|
|
627
|
+
};
|
|
628
|
+
const name = qualifiedField(coordinate);
|
|
629
|
+
const shown = fieldStatementText(state.destination.contract, coordinate);
|
|
630
|
+
if (Object.hasOwn(destination.model.relations, field)) return refuse(`"${shown}" is a relation, which holds no values of its own to ${verb}`);
|
|
631
|
+
const destinationField = Object.hasOwn(destination.model.fields, field) ? destination.model.fields[field] : void 0;
|
|
632
|
+
if (destinationField === void 0) return refuse(`the destination model "${modelStatementText(state.destination.contract, destination.coordinate)}" has no field "${field}" (fields: ${listed(fieldNames(destination.model))})`, `A --${verb} statement names the field as the destination contract names it: after --rename User.age:User.years, write --${verb} User.years. Names match exactly, including case.`);
|
|
633
|
+
const key = `${verb}:${name}`;
|
|
634
|
+
if (state.fieldStatements.has(key)) return notOk(errorStatementInvalid(statement, `An earlier statement already ${verb}s "${shown}".`, `Give each field at most one --${verb} statement.`));
|
|
635
|
+
if (verb === "backfill" && destinationField.nullable) return refuse(`the field "${shown}" is optional in the destination contract, so no existing row needs a value`, `${leaveOut} A --backfill statement fills a required field.`);
|
|
636
|
+
const counterpart = originCounterpart(state, destination.coordinate);
|
|
637
|
+
if (counterpart === void 0) {
|
|
638
|
+
const model = modelStatementText(state.destination.contract, destination.coordinate);
|
|
639
|
+
return refuse(`the destination model "${model}" has no counterpart in the origin contract: the origin has no model "${model}" and no rename statement renames a model to it`, verb === "convert" ? `If the model was renamed, add --rename <old name>:${model}. A new model has no values to convert, so leave out ${flag}.` : `A new model has no existing rows to backfill. ${leaveOut}`);
|
|
640
|
+
}
|
|
641
|
+
const originName = state.originOfRenamedField.get(name)?.field ?? field;
|
|
642
|
+
const originField = Object.hasOwn(counterpart.model.fields, originName) ? counterpart.model.fields[originName] : void 0;
|
|
643
|
+
if (verb === "convert") {
|
|
644
|
+
if (originField === void 0) {
|
|
645
|
+
const model = statement.field.slice(0, -1).join(".");
|
|
646
|
+
return refuse(`the origin model "${modelStatementText(state.origin.contract, counterpart.coordinate)}" has no field "${field}" (fields: ${listed(fieldNames(counterpart.model))}), and no rename statement renames a field to it`, `If the field was renamed, add --rename ${model}.<old name>:${model}.${field}. A new field has no values to convert, so leave out ${flag}.`);
|
|
647
|
+
}
|
|
648
|
+
if (sameType(originField, destinationField)) return refuse(`the field "${shown}" has the same type, ${fieldTypeText(destinationField)}, in the origin and destination contracts, so it has no values to convert`);
|
|
649
|
+
} else if (originField !== void 0 && !originField.nullable) return refuse(`the field "${shown}" is already required in the origin contract, so every existing row has a value`);
|
|
650
|
+
state.fieldStatements.add(key);
|
|
651
|
+
return ok({
|
|
652
|
+
kind: verb,
|
|
653
|
+
entity: "field",
|
|
654
|
+
field: coordinate
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Resolves the statements a user gave against the origin and destination contracts. Renames
|
|
659
|
+
* resolve first, in the order given, so a convert or backfill statement can name a renamed field
|
|
660
|
+
* by its new name wherever it is given; the result keeps the order given. A delete or allow
|
|
661
|
+
* statement is checked and left out: it names what a plan would do to a subject, so it is matched
|
|
662
|
+
* against the plan, and it needs no origin contract.
|
|
566
663
|
*/
|
|
567
664
|
function resolveStatements(input) {
|
|
568
|
-
const
|
|
569
|
-
|
|
665
|
+
const renames = [];
|
|
666
|
+
const fieldStatements = [];
|
|
667
|
+
for (const [index, entry] of input.statements.entries()) {
|
|
570
668
|
if (entry.verb === "delete" || entry.verb === "allow") {
|
|
571
669
|
const statement = parseConsentStatement({
|
|
572
670
|
...entry,
|
|
@@ -576,14 +674,29 @@ function resolveStatements(input) {
|
|
|
576
674
|
continue;
|
|
577
675
|
}
|
|
578
676
|
if (input.origin.kind === "missing") return notOk(errorStatementOriginUnknown(input.origin));
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
677
|
+
if (entry.verb === "rename") {
|
|
678
|
+
const statement = parseRenameStatement({
|
|
679
|
+
...entry,
|
|
680
|
+
verb: entry.verb
|
|
681
|
+
});
|
|
682
|
+
if (!statement.ok) return statement;
|
|
683
|
+
renames.push({
|
|
684
|
+
index,
|
|
685
|
+
statement: statement.value
|
|
686
|
+
});
|
|
687
|
+
} else {
|
|
688
|
+
const statement = parseFieldStatement({
|
|
689
|
+
...entry,
|
|
690
|
+
verb: entry.verb
|
|
691
|
+
});
|
|
692
|
+
if (!statement.ok) return statement;
|
|
693
|
+
fieldStatements.push({
|
|
694
|
+
index,
|
|
695
|
+
statement: statement.value
|
|
696
|
+
});
|
|
697
|
+
}
|
|
585
698
|
}
|
|
586
|
-
if (
|
|
699
|
+
if (input.origin.kind === "missing") return ok([]);
|
|
587
700
|
const state = {
|
|
588
701
|
origin: {
|
|
589
702
|
name: "origin",
|
|
@@ -594,33 +707,77 @@ function resolveStatements(input) {
|
|
|
594
707
|
contract: input.destination
|
|
595
708
|
},
|
|
596
709
|
originOfRenamedModel: /* @__PURE__ */ new Map(),
|
|
710
|
+
originOfRenamedField: /* @__PURE__ */ new Map(),
|
|
597
711
|
renamedFrom: /* @__PURE__ */ new Set(),
|
|
598
|
-
renamedTo: /* @__PURE__ */ new Set()
|
|
712
|
+
renamedTo: /* @__PURE__ */ new Set(),
|
|
713
|
+
fieldStatements: /* @__PURE__ */ new Set()
|
|
599
714
|
};
|
|
600
715
|
const resolved = [];
|
|
601
|
-
|
|
602
|
-
|
|
716
|
+
const parsedRenames = renames.map(({ statement }) => statement);
|
|
717
|
+
for (const [position, { index, statement }] of renames.entries()) {
|
|
718
|
+
const result = resolveStatement(state, statement, parsedRenames.slice(position + 1));
|
|
603
719
|
if (!result.ok) return result;
|
|
604
|
-
resolved.push(
|
|
720
|
+
resolved.push({
|
|
721
|
+
index,
|
|
722
|
+
statement: result.value
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
for (const { index, statement } of fieldStatements) {
|
|
726
|
+
const result = resolveFieldStatement(state, statement);
|
|
727
|
+
if (!result.ok) return result;
|
|
728
|
+
resolved.push({
|
|
729
|
+
index,
|
|
730
|
+
statement: result.value
|
|
731
|
+
});
|
|
605
732
|
}
|
|
606
|
-
return ok(resolved);
|
|
733
|
+
return ok([...resolved].sort((left, right) => left.index - right.index).map(({ statement }) => statement));
|
|
734
|
+
}
|
|
735
|
+
const STATEMENT_VERBS = [
|
|
736
|
+
"rename",
|
|
737
|
+
"delete",
|
|
738
|
+
"allow",
|
|
739
|
+
"convert",
|
|
740
|
+
"backfill"
|
|
741
|
+
];
|
|
742
|
+
function isStatementVerb(verb) {
|
|
743
|
+
return STATEMENT_VERBS.includes(verb);
|
|
607
744
|
}
|
|
608
|
-
function
|
|
609
|
-
return
|
|
745
|
+
function isPlannedStatement(statement) {
|
|
746
|
+
return statement.verb === "rename" || statement.verb === "convert" || statement.verb === "backfill";
|
|
610
747
|
}
|
|
611
|
-
/** The
|
|
612
|
-
function
|
|
613
|
-
|
|
748
|
+
/** The field a `convert` and a `delete` of the same run both name, which conflict; `undefined` when none does. */
|
|
749
|
+
function convertAndDelete(statements) {
|
|
750
|
+
const deleted = new Set(statements.filter(({ verb }) => verb === "delete").map(({ text }) => text));
|
|
751
|
+
return statements.find(({ verb, text }) => verb === "convert" && deleted.has(text))?.text;
|
|
752
|
+
}
|
|
753
|
+
/** The plan's renames, resolved; empty when there are none or they do not resolve. */
|
|
754
|
+
function resolvedRenames(contracts) {
|
|
755
|
+
const renames = contracts.statements.filter((statement) => statement.verb === "rename");
|
|
756
|
+
if (contracts.destination === void 0 || renames.length === 0) return [];
|
|
614
757
|
const resolved = resolveStatements({
|
|
615
|
-
statements:
|
|
758
|
+
statements: renames,
|
|
616
759
|
origin: {
|
|
617
760
|
kind: "contract",
|
|
618
761
|
contract: contracts.origin
|
|
619
762
|
},
|
|
620
763
|
destination: contracts.destination
|
|
621
764
|
});
|
|
622
|
-
|
|
623
|
-
|
|
765
|
+
return resolved.ok ? resolved.value : [];
|
|
766
|
+
}
|
|
767
|
+
function sameModel(left, right) {
|
|
768
|
+
return left.namespaceId === right.namespaceId && left.model === right.model;
|
|
769
|
+
}
|
|
770
|
+
/** The model a rename statement of `contracts` gives `coordinate` in the destination, if any. */
|
|
771
|
+
function renamedModel(coordinate, contracts) {
|
|
772
|
+
for (const statement of resolvedRenames(contracts)) if (statement.kind === "rename" && statement.entity === "model" && sameModel(statement.from, coordinate)) return statement.to;
|
|
773
|
+
}
|
|
774
|
+
/** The field of the origin contract at `coordinate`, as the destination names it after the plan's renames. */
|
|
775
|
+
function destinationField(coordinate, contracts) {
|
|
776
|
+
for (const statement of resolvedRenames(contracts)) if (statement.kind === "rename" && statement.entity === "field" && sameModel(statement.from, coordinate) && statement.from.field === coordinate.field) return statement.to;
|
|
777
|
+
return {
|
|
778
|
+
...renamedModel(coordinate, contracts) ?? coordinate,
|
|
779
|
+
field: coordinate.field
|
|
780
|
+
};
|
|
624
781
|
}
|
|
625
782
|
/**
|
|
626
783
|
* The subject as a statement names it: `Model` or `Model.field`, with the namespace when its
|
|
@@ -630,22 +787,26 @@ function renamedModel(coordinate, contracts) {
|
|
|
630
787
|
*/
|
|
631
788
|
function subjectText(subject, contracts) {
|
|
632
789
|
switch (subject.kind) {
|
|
633
|
-
case "model": return
|
|
790
|
+
case "model": return modelStatementText(contracts.origin, subject);
|
|
634
791
|
case "field": {
|
|
635
792
|
const renamed = renamedModel(subject, contracts);
|
|
636
|
-
return `${renamed === void 0 || contracts.destination === void 0 ?
|
|
793
|
+
return `${renamed === void 0 || contracts.destination === void 0 ? modelStatementText(contracts.origin, subject) : modelStatementText(contracts.destination, renamed)}.${subject.field}`;
|
|
637
794
|
}
|
|
638
795
|
case "storage": return subject.name;
|
|
639
796
|
}
|
|
640
797
|
}
|
|
641
|
-
/**
|
|
642
|
-
|
|
643
|
-
|
|
798
|
+
/**
|
|
799
|
+
* The statement's description, written as its question names the subject: `delete field
|
|
800
|
+
* "User.nickname"`, or `accept lossy type change of field "User.age"` for a delete that answers a
|
|
801
|
+
* type change, which keeps the field and lets the database cast its values, cutting or rounding some.
|
|
802
|
+
*/
|
|
803
|
+
function consentDescription(verb, subject, text, loss) {
|
|
804
|
+
return verb === "delete" && loss === "typeChange" ? `accept lossy type change of ${subject.kind} "${text}"` : `${verb} ${subject.kind} "${text}"`;
|
|
644
805
|
}
|
|
645
|
-
function lossText(subject, text, originKnown) {
|
|
806
|
+
function lossText(subject, text, originKnown, loss) {
|
|
646
807
|
switch (subject.kind) {
|
|
647
808
|
case "model": return `would lose the data of model "${text}"`;
|
|
648
|
-
case "field": return `would lose the values of field "${text}"`;
|
|
809
|
+
case "field": return loss === "typeChange" ? `would change the type of field "${text}" and can change or lose its values` : `would lose the values of field "${text}"`;
|
|
649
810
|
case "storage": return originKnown ? `would lose the data in "${text}", which no model of the origin contract stores` : `would lose the data in "${text}", named by its storage name because the origin contract is unknown; --delete loses that data`;
|
|
650
811
|
}
|
|
651
812
|
}
|
|
@@ -657,7 +818,7 @@ function lossText(subject, text, originKnown) {
|
|
|
657
818
|
*/
|
|
658
819
|
const ORIGIN_SNAPSHOT_RECOVERY = ["If it was renamed, keep its data instead: store the snapshot of the contract the database is at, then run this command again and answer with --rename.", ...STORE_ORIGIN_SNAPSHOT_STEPS.map((step) => step.replaceAll("{bin}", "prisma"))].join("\n");
|
|
659
820
|
function sameCoordinate(statement, subject) {
|
|
660
|
-
if (subject.kind === "storage") return false;
|
|
821
|
+
if (statement.kind !== "rename" || subject.kind === "storage") return false;
|
|
661
822
|
const { from } = statement;
|
|
662
823
|
if (from.namespaceId !== subject.namespaceId || from.model !== subject.model) return false;
|
|
663
824
|
return subject.kind === "field" ? statement.entity === "field" && statement.from.field === subject.field : statement.entity === "model";
|
|
@@ -666,7 +827,7 @@ function namesSubject(verb, subject) {
|
|
|
666
827
|
return (text) => text === subject ? void 0 : `${verb} names "${subject}": --${verb} ${subject}.`;
|
|
667
828
|
}
|
|
668
829
|
function modelRenameAdvice(model, contracts) {
|
|
669
|
-
const name =
|
|
830
|
+
const name = modelStatementText(contracts.origin, model);
|
|
670
831
|
return `The destination contract has no model "${name}"; to keep the values instead, also pass --rename ${name}:<new model name>, naming the model that stores them now, and the question then offers to rename the field.`;
|
|
671
832
|
}
|
|
672
833
|
/** A rename as a statement is written: a field's new name keeps the model, `User.nickname:User.<new name>`. */
|
|
@@ -675,16 +836,8 @@ function renameForm(subject, text) {
|
|
|
675
836
|
}
|
|
676
837
|
/** Whether a rename statement of the plan already gives the subject a new name. */
|
|
677
838
|
function renamedByPlan(subject, contracts) {
|
|
678
|
-
if (subject.kind === "storage"
|
|
679
|
-
|
|
680
|
-
statements: contracts.renames,
|
|
681
|
-
origin: {
|
|
682
|
-
kind: "contract",
|
|
683
|
-
contract: contracts.origin
|
|
684
|
-
},
|
|
685
|
-
destination: contracts.destination
|
|
686
|
-
});
|
|
687
|
-
return resolved.ok && resolved.value.some((statement) => sameCoordinate(statement, subject));
|
|
839
|
+
if (subject.kind === "storage") return false;
|
|
840
|
+
return resolvedRenames(contracts).some((statement) => sameCoordinate(statement, subject));
|
|
688
841
|
}
|
|
689
842
|
/** Whether the destination still has the subject's model or field, under the name a rename gives it. */
|
|
690
843
|
function inDestination(subject, contracts) {
|
|
@@ -694,6 +847,19 @@ function inDestination(subject, contracts) {
|
|
|
694
847
|
if (destinationModel === void 0) return false;
|
|
695
848
|
return subject.kind === "model" || Object.hasOwn(destinationModel.fields, subject.field);
|
|
696
849
|
}
|
|
850
|
+
/** Checks a statement typed at a question against the plan's other statements. */
|
|
851
|
+
function resolvesWith(statement, contracts) {
|
|
852
|
+
const resolved = resolveStatements({
|
|
853
|
+
statements: [...contracts.statements, statement],
|
|
854
|
+
origin: {
|
|
855
|
+
kind: "contract",
|
|
856
|
+
contract: contracts.origin
|
|
857
|
+
},
|
|
858
|
+
destination: contracts.destination
|
|
859
|
+
});
|
|
860
|
+
if (!resolved.ok) return notOk(`${resolved.failure.message}. ${resolved.failure.why ?? ""}`.trim());
|
|
861
|
+
return ok(resolved.value.at(-1));
|
|
862
|
+
}
|
|
697
863
|
/**
|
|
698
864
|
* The model of a field subject, under the name a rename of the plan gives it, when the destination
|
|
699
865
|
* has no model of that name: a rename of the field cannot be written until a statement renames the
|
|
@@ -705,43 +871,67 @@ function missingFieldModel(subject, contracts) {
|
|
|
705
871
|
return contracts.destination.domain.namespaces[model.namespaceId]?.models[model.model] === void 0 ? model : void 0;
|
|
706
872
|
}
|
|
707
873
|
/**
|
|
708
|
-
* The question for one operation that would lose data. A
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
*
|
|
874
|
+
* The question for one operation that would lose data. A field whose type changes may be converted
|
|
875
|
+
* where the command writes a migration to fill in; the convert names the field as the destination
|
|
876
|
+
* names it. A model or field the destination no longer has, and no rename of the plan renamed, may
|
|
877
|
+
* be renamed instead of deleted; a rename is resolved against the two contracts after the plan's
|
|
878
|
+
* other renames, and its old name must be the subject. Anything else, and data no model stores,
|
|
712
879
|
* can only be deleted. A field whose model the destination names differently can be renamed only
|
|
713
|
-
* after a statement renames the model, so the question says to pass one.
|
|
880
|
+
* after a statement renames the model, so the question says to pass one. The question ends with
|
|
881
|
+
* the planner's advice on keeping the data, when it gives any.
|
|
714
882
|
*/
|
|
715
883
|
function dataLossQuestion(loss, contracts) {
|
|
716
884
|
const subject = subjectText(loss.subject, contracts);
|
|
885
|
+
const deleteNames = namesSubject("delete", subject);
|
|
717
886
|
const missingModel = missingFieldModel(loss.subject, contracts);
|
|
887
|
+
const question = [
|
|
888
|
+
`${loss.label} ${lossText(loss.subject, subject, contracts.originKnown, loss.loss)}.`,
|
|
889
|
+
...missingModel === void 0 ? [] : [modelRenameAdvice(missingModel, contracts)],
|
|
890
|
+
...loss.keepDataAdvice === void 0 ? [] : [loss.keepDataAdvice]
|
|
891
|
+
].join(" ");
|
|
892
|
+
if (loss.loss === "typeChange" && loss.subject.kind === "field") {
|
|
893
|
+
if (!contracts.canConvert) return {
|
|
894
|
+
question,
|
|
895
|
+
subject,
|
|
896
|
+
verbs: ["delete"],
|
|
897
|
+
forms: {},
|
|
898
|
+
validate: (_verb, text) => deleteNames(text)
|
|
899
|
+
};
|
|
900
|
+
const field = destinationField(loss.subject, contracts);
|
|
901
|
+
const convert = fieldStatementText(contracts.destination, field);
|
|
902
|
+
return {
|
|
903
|
+
question,
|
|
904
|
+
subject,
|
|
905
|
+
verbs: ["convert", "delete"],
|
|
906
|
+
forms: { convert },
|
|
907
|
+
validate: (verb, text) => {
|
|
908
|
+
if (verb !== "convert") return deleteNames(text);
|
|
909
|
+
if (text !== convert) return `convert names the field as the destination contract names it: ${statementFlag({
|
|
910
|
+
verb: "convert",
|
|
911
|
+
text: convert
|
|
912
|
+
})}.`;
|
|
913
|
+
const resolved = resolvesWith({
|
|
914
|
+
verb: "convert",
|
|
915
|
+
text
|
|
916
|
+
}, contracts);
|
|
917
|
+
return resolved.ok ? void 0 : resolved.failure;
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
}
|
|
718
921
|
const renamable = missingModel === void 0 && loss.subject.kind !== "storage" && !inDestination(loss.subject, contracts) && !renamedByPlan(loss.subject, contracts);
|
|
719
|
-
const deleteNames = namesSubject("delete", subject);
|
|
720
922
|
return {
|
|
721
|
-
question
|
|
722
|
-
`${loss.label} ${lossText(loss.subject, subject, contracts.originKnown)}.`,
|
|
723
|
-
...missingModel === void 0 ? [] : [modelRenameAdvice(missingModel, contracts)],
|
|
724
|
-
...loss.keepDataAdvice === void 0 ? [] : [loss.keepDataAdvice]
|
|
725
|
-
].join(" "),
|
|
923
|
+
question,
|
|
726
924
|
subject,
|
|
727
925
|
verbs: renamable ? ["rename", "delete"] : ["delete"],
|
|
728
926
|
forms: renamable ? { rename: renameForm(loss.subject, subject) } : {},
|
|
729
927
|
validate: (verb, text) => {
|
|
730
928
|
if (verb !== "rename") return deleteNames(text);
|
|
731
|
-
const resolved =
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
kind: "contract",
|
|
738
|
-
contract: contracts.origin
|
|
739
|
-
},
|
|
740
|
-
destination: contracts.destination
|
|
741
|
-
});
|
|
742
|
-
if (!resolved.ok) return `${resolved.failure.message}. ${resolved.failure.why ?? ""}`.trim();
|
|
743
|
-
const statement = resolved.value.at(-1);
|
|
744
|
-
return statement !== void 0 && sameCoordinate(statement, loss.subject) ? void 0 : `The rename's old name is not "${subject}". Write it as ${renameForm(loss.subject, subject)}.`;
|
|
929
|
+
const resolved = resolvesWith({
|
|
930
|
+
verb: "rename",
|
|
931
|
+
text
|
|
932
|
+
}, contracts);
|
|
933
|
+
if (!resolved.ok) return resolved.failure;
|
|
934
|
+
return resolved.value !== void 0 && sameCoordinate(resolved.value, loss.subject) ? void 0 : `The rename's old name is not "${subject}". Write it as ${renameForm(loss.subject, subject)}.`;
|
|
745
935
|
}
|
|
746
936
|
};
|
|
747
937
|
}
|
|
@@ -809,15 +999,15 @@ function withRecoveryOnFirstStorageQuestion(asked, recoveryApplies) {
|
|
|
809
999
|
/**
|
|
810
1000
|
* Asks about every operation of a plan that would lose data and, when `askAccess`, every one that
|
|
811
1001
|
* would widen access, until each is answered. A `delete` or `allow` text in `preAnswers`, or
|
|
812
|
-
* `consentAll` for its verb, answers its question without asking. A rename typed at the
|
|
813
|
-
* the plan did not have, so the plan is made again with
|
|
814
|
-
* gone; a loss the new plan has on the same subject, such as a
|
|
815
|
-
* is asked in the next round. The first round asks even when
|
|
816
|
-
* refused before anything is done.
|
|
1002
|
+
* `consentAll` for its verb, answers its question without asking. A rename or convert typed at the
|
|
1003
|
+
* prompt is a statement the plan did not have, so the plan is made again with every statement, and
|
|
1004
|
+
* the operation it answered must be gone; a loss the new plan has on the same subject, such as a
|
|
1005
|
+
* type change on the renamed field, is asked in the next round. The first round asks even when
|
|
1006
|
+
* nothing is in question, so a statement no question consumed is refused before anything is done.
|
|
817
1007
|
*/
|
|
818
1008
|
async function askPlanQuestions(input) {
|
|
819
1009
|
let plan = input.plan;
|
|
820
|
-
let
|
|
1010
|
+
let statements = input.statements;
|
|
821
1011
|
const consented = /* @__PURE__ */ new Map();
|
|
822
1012
|
const usedPreAnswers = /* @__PURE__ */ new Set();
|
|
823
1013
|
for (let round = 0;; round += 1) {
|
|
@@ -825,14 +1015,16 @@ async function askPlanQuestions(input) {
|
|
|
825
1015
|
origin: input.origin,
|
|
826
1016
|
originKnown: input.originKnown,
|
|
827
1017
|
destination: input.destination,
|
|
828
|
-
|
|
1018
|
+
canConvert: input.canConvert,
|
|
1019
|
+
statements
|
|
829
1020
|
};
|
|
830
1021
|
const pending = (verb, planned) => [...new Map(planned.filter((entry) => !consented.has(questionKey(verb, entry))).map((entry) => [questionKey(verb, entry), entry])).values()];
|
|
831
1022
|
const consent = (verb, entry, text) => consented.set(questionKey(verb, entry), {
|
|
832
1023
|
verb,
|
|
833
1024
|
subject: entry.subject,
|
|
834
1025
|
text,
|
|
835
|
-
operationIndex: entry.operationIndex
|
|
1026
|
+
operationIndex: entry.operationIndex,
|
|
1027
|
+
loss: verb === "delete" && "loss" in entry ? entry.loss : void 0
|
|
836
1028
|
});
|
|
837
1029
|
for (const [verb, entries] of [["delete", pending("delete", plan.dataLoss)], ["allow", input.askAccess ? pending("allow", plan.accessWidening) : []]]) for (const entry of entries) {
|
|
838
1030
|
const text = subjectText(entry.subject, contracts);
|
|
@@ -849,26 +1041,26 @@ async function askPlanQuestions(input) {
|
|
|
849
1041
|
})), !input.originKnown), ...widenings.map((widening) => accessWideningQuestion(widening, contracts))];
|
|
850
1042
|
const answers = await input.answer(questions);
|
|
851
1043
|
checkAnswers(questions, answers);
|
|
852
|
-
const
|
|
1044
|
+
const typed = [];
|
|
853
1045
|
answers.forEach((answer, index) => {
|
|
854
1046
|
const entry = [...losses, ...widenings][index];
|
|
855
1047
|
const question = questions[index];
|
|
856
1048
|
if (entry === void 0 || question === void 0) return;
|
|
857
|
-
if (answer.verb === "rename")
|
|
858
|
-
|
|
1049
|
+
if (answer.verb === "rename" || answer.verb === "convert") typed.push({
|
|
1050
|
+
statement: {
|
|
1051
|
+
verb: answer.verb,
|
|
1052
|
+
text: answer.text
|
|
1053
|
+
},
|
|
859
1054
|
loss: entry
|
|
860
1055
|
});
|
|
861
1056
|
else consent(answer.verb, entry, question.subject);
|
|
862
1057
|
});
|
|
863
|
-
if (
|
|
1058
|
+
if (typed.length === 0) {
|
|
864
1059
|
if (losses.length + widenings.length === 0) break;
|
|
865
1060
|
continue;
|
|
866
1061
|
}
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
text
|
|
870
|
-
}))];
|
|
871
|
-
const replanned = await input.replan(renames);
|
|
1062
|
+
statements = [...statements, ...typed.map(({ statement }) => statement)];
|
|
1063
|
+
const replanned = await input.replan(statements);
|
|
872
1064
|
if (!replanned.ok) return replanned;
|
|
873
1065
|
plan = replanned.value;
|
|
874
1066
|
for (const entry of plan.accessWidening) {
|
|
@@ -880,20 +1072,17 @@ async function askPlanQuestions(input) {
|
|
|
880
1072
|
}
|
|
881
1073
|
const operationOf = (entry) => `${entry.label}:${keyOf(entry)}`;
|
|
882
1074
|
const stillPlanned = new Set(plan.dataLoss.map(operationOf));
|
|
883
|
-
const unresolved =
|
|
884
|
-
if (unresolved !== void 0) return notOk(errorStatementDidNotResolveLoss(
|
|
885
|
-
verb: "rename",
|
|
886
|
-
text: unresolved.text
|
|
887
|
-
}, subjectText(unresolved.loss.subject, contracts)));
|
|
1075
|
+
const unresolved = typed.find(({ loss }) => stillPlanned.has(operationOf(loss)));
|
|
1076
|
+
if (unresolved !== void 0) return notOk(errorStatementDidNotResolveLoss(unresolved.statement, subjectText(unresolved.loss.subject, contracts)));
|
|
888
1077
|
}
|
|
889
1078
|
const unused = input.preAnswers.filter((statement) => !usedPreAnswers.has(statement));
|
|
890
1079
|
if (unused.length > 0) return notOk(errorStatementAnswersNoQuestion(unused, questionSubjects(plan, input.askAccess, {
|
|
891
1080
|
...input,
|
|
892
|
-
|
|
1081
|
+
statements
|
|
893
1082
|
})));
|
|
894
1083
|
return ok({
|
|
895
1084
|
plan,
|
|
896
|
-
|
|
1085
|
+
statements,
|
|
897
1086
|
consented: [...consented.values()]
|
|
898
1087
|
});
|
|
899
1088
|
}
|
|
@@ -904,6 +1093,7 @@ function questionSubjects(plan, askAccess, contracts) {
|
|
|
904
1093
|
/**
|
|
905
1094
|
* Refuses the `delete` and `allow` statements that name no subject a plan asks about, without
|
|
906
1095
|
* asking anything: a run that only plans still says which statements would consent to nothing.
|
|
1096
|
+
* The plan carries out its other statements, so they are not checked here.
|
|
907
1097
|
*/
|
|
908
1098
|
function refuseUnusedConsents(input) {
|
|
909
1099
|
const subjects = questionSubjects(input.plan, true, input.contracts);
|
|
@@ -912,7 +1102,7 @@ function refuseUnusedConsents(input) {
|
|
|
912
1102
|
const text = subjectText(entry.subject, input.contracts);
|
|
913
1103
|
for (const statement of givenFor(verb, text, input.statements, used)) used.add(statement);
|
|
914
1104
|
}
|
|
915
|
-
const unused = input.statements.filter((statement) => statement
|
|
1105
|
+
const unused = input.statements.filter((statement) => !isPlannedStatement(statement) && !used.has(statement));
|
|
916
1106
|
return unused.length === 0 ? ok(void 0) : notOk(errorStatementAnswersNoQuestion(unused, subjects));
|
|
917
1107
|
}
|
|
918
1108
|
/**
|
|
@@ -921,7 +1111,7 @@ function refuseUnusedConsents(input) {
|
|
|
921
1111
|
*/
|
|
922
1112
|
function reportAppliedStatements(applied, fromContract, contract, operationOffset) {
|
|
923
1113
|
return applied.map((entry) => ({
|
|
924
|
-
verb:
|
|
1114
|
+
verb: entry.statement.kind,
|
|
925
1115
|
statement: migrationStatementJson(entry.statement),
|
|
926
1116
|
operationIndexes: entry.operationIndexes.map((index) => operationOffset + index),
|
|
927
1117
|
description: describeMigrationStatement(entry.statement, fromContract ?? contract, contract)
|
|
@@ -936,9 +1126,16 @@ function reportConsentStatement(consented, operationIndexes) {
|
|
|
936
1126
|
subject: migrationSubjectJson(consented.subject)
|
|
937
1127
|
},
|
|
938
1128
|
operationIndexes,
|
|
939
|
-
description: consentDescription(consented.verb, consented.subject, consented.text)
|
|
1129
|
+
description: consentDescription(consented.verb, consented.subject, consented.text, consented.loss)
|
|
940
1130
|
};
|
|
941
1131
|
}
|
|
1132
|
+
/** The fields of `values` named as `destination` names them; a column no field stores is left out. */
|
|
1133
|
+
function reportTemporaryValues(values, destination) {
|
|
1134
|
+
return values.flatMap(({ subject, value }) => subject.kind === "field" ? [{
|
|
1135
|
+
field: fieldStatementText(destination, subject),
|
|
1136
|
+
value
|
|
1137
|
+
}] : []);
|
|
1138
|
+
}
|
|
942
1139
|
/**
|
|
943
1140
|
* Project the CLI's `Config.extensions` array into the canonical
|
|
944
1141
|
* {@link ExtensionPackInput} shape. The single `as ExtensionPackLike`
|
|
@@ -1246,6 +1443,47 @@ function stripOperations(operations) {
|
|
|
1246
1443
|
* identifier consumed by the structured-output renderer and by tests.
|
|
1247
1444
|
*/
|
|
1248
1445
|
const RUN_SPAN_ID = "apply";
|
|
1446
|
+
function edgeOfOperation(edges, operationIndex) {
|
|
1447
|
+
let end = 0;
|
|
1448
|
+
return edges.find((edge) => {
|
|
1449
|
+
end += edge.operationCount;
|
|
1450
|
+
return operationIndex < end;
|
|
1451
|
+
});
|
|
1452
|
+
}
|
|
1453
|
+
function failedTypeChangeReport(change, field) {
|
|
1454
|
+
return change.by === "cast" ? {
|
|
1455
|
+
field,
|
|
1456
|
+
by: "cast",
|
|
1457
|
+
reason: change.reason
|
|
1458
|
+
} : {
|
|
1459
|
+
field,
|
|
1460
|
+
by: "conversion",
|
|
1461
|
+
reason: change.reason
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
1464
|
+
/** What the runner said blocked the failed operation, named as the advice names it. */
|
|
1465
|
+
function failureReports(failure, resolutions) {
|
|
1466
|
+
const resolution = resolutions.find(({ spaceId }) => spaceId === failure.failingSpace);
|
|
1467
|
+
if (resolution === void 0) return {};
|
|
1468
|
+
const fieldText = (field) => subjectText(field, {
|
|
1469
|
+
origin: resolution.entry.destinationContract,
|
|
1470
|
+
statements: []
|
|
1471
|
+
});
|
|
1472
|
+
const { failedTypeChange, rowsWithoutValue } = failure;
|
|
1473
|
+
const operationIndex = failedTypeChange?.operationIndex ?? rowsWithoutValue?.[0]?.operationIndex;
|
|
1474
|
+
const edge = operationIndex === void 0 ? void 0 : edgeOfOperation(resolution.entry.migrationEdges, operationIndex);
|
|
1475
|
+
return {
|
|
1476
|
+
...ifDefined("failedTypeChange", failedTypeChange === void 0 ? void 0 : failedTypeChangeReport(failedTypeChange, fieldText(failedTypeChange.field))),
|
|
1477
|
+
...ifDefined("rowsWithoutValue", rowsWithoutValue?.map(({ field, reason }) => ({
|
|
1478
|
+
field: field === void 0 ? void 0 : fieldText(field),
|
|
1479
|
+
reason
|
|
1480
|
+
}))),
|
|
1481
|
+
...ifDefined("failedMigration", edge === void 0 ? void 0 : {
|
|
1482
|
+
spaceId: resolution.spaceId,
|
|
1483
|
+
edge
|
|
1484
|
+
})
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1249
1487
|
/**
|
|
1250
1488
|
* Runner-driving tail shared by every run caller — `db init`,
|
|
1251
1489
|
* `db update`, and `migrate`. Consumes already-resolved per-space
|
|
@@ -1301,6 +1539,7 @@ async function runMigration(inputs) {
|
|
|
1301
1539
|
failingSpace: runnerResult.failure.failingSpace,
|
|
1302
1540
|
runnerErrorCode: runnerResult.failure.code
|
|
1303
1541
|
},
|
|
1542
|
+
...failureReports(runnerResult.failure, orderedResolutions),
|
|
1304
1543
|
cause: runnerResult.failure
|
|
1305
1544
|
});
|
|
1306
1545
|
}
|
|
@@ -1504,7 +1743,8 @@ async function executeRun(options) {
|
|
|
1504
1743
|
const orderedResolutions = collectOrdered(planned.value.applyOrder, planned.value.perSpace);
|
|
1505
1744
|
const subjects = action === "dbUpdate" ? subjectsAcrossSpaces(orderedResolutions) : {
|
|
1506
1745
|
dataLoss: [],
|
|
1507
|
-
accessWidening: []
|
|
1746
|
+
accessWidening: [],
|
|
1747
|
+
temporaryValues: []
|
|
1508
1748
|
};
|
|
1509
1749
|
const operations = orderedResolutions.flatMap((r) => r.entry.displayOps);
|
|
1510
1750
|
const labelled = (entries) => entries.map((entry) => ({
|
|
@@ -1515,21 +1755,25 @@ async function executeRun(options) {
|
|
|
1515
1755
|
planned: planned.value,
|
|
1516
1756
|
orderedResolutions,
|
|
1517
1757
|
subjects,
|
|
1518
|
-
dataLoss: labelled(subjects.dataLoss)
|
|
1758
|
+
dataLoss: labelled(subjects.dataLoss).map((entry) => ({
|
|
1759
|
+
...entry,
|
|
1760
|
+
loss: entry.loss
|
|
1761
|
+
})),
|
|
1519
1762
|
accessWidening: labelled(subjects.accessWidening)
|
|
1520
1763
|
});
|
|
1521
1764
|
};
|
|
1522
1765
|
const first = await plan(statements);
|
|
1523
1766
|
if (!first.ok) return first.failure;
|
|
1524
1767
|
let run = first.value;
|
|
1525
|
-
let
|
|
1768
|
+
let plannedTexts = statementTexts.filter(isPlannedStatement);
|
|
1526
1769
|
let consented = [];
|
|
1527
1770
|
if (options.action === "dbUpdate" && mode === "apply") {
|
|
1528
1771
|
const answered = await askPlanQuestions({
|
|
1529
1772
|
plan: run,
|
|
1530
1773
|
askAccess: true,
|
|
1531
|
-
|
|
1532
|
-
|
|
1774
|
+
canConvert: false,
|
|
1775
|
+
statements: plannedTexts,
|
|
1776
|
+
preAnswers: statementTexts.filter((statement) => !isPlannedStatement(statement)),
|
|
1533
1777
|
consentAll: {
|
|
1534
1778
|
delete: options.acceptDataLoss,
|
|
1535
1779
|
allow: options.acceptAccessWidening
|
|
@@ -1538,14 +1782,14 @@ async function executeRun(options) {
|
|
|
1538
1782
|
originKnown: fromContract !== null,
|
|
1539
1783
|
destination: contract,
|
|
1540
1784
|
answer: options.answerQuestions,
|
|
1541
|
-
replan: (
|
|
1785
|
+
replan: (planned) => plan(resolveRenames(planned))
|
|
1542
1786
|
});
|
|
1543
1787
|
if (!answered.ok) {
|
|
1544
1788
|
if (CliStructuredError$1.is(answered.failure)) throw answered.failure;
|
|
1545
1789
|
return answered.failure;
|
|
1546
1790
|
}
|
|
1547
1791
|
run = answered.value.plan;
|
|
1548
|
-
|
|
1792
|
+
plannedTexts = answered.value.statements;
|
|
1549
1793
|
consented = answered.value.consented;
|
|
1550
1794
|
}
|
|
1551
1795
|
if (options.action === "dbUpdate" && mode === "plan") {
|
|
@@ -1555,7 +1799,7 @@ async function executeRun(options) {
|
|
|
1555
1799
|
contracts: {
|
|
1556
1800
|
origin: fromContract ?? EMPTY_ORIGIN$1,
|
|
1557
1801
|
destination: contract,
|
|
1558
|
-
|
|
1802
|
+
statements: plannedTexts
|
|
1559
1803
|
}
|
|
1560
1804
|
});
|
|
1561
1805
|
if (!refused.ok) throw refused.failure;
|
|
@@ -1569,15 +1813,17 @@ async function executeRun(options) {
|
|
|
1569
1813
|
const contractsAsked = {
|
|
1570
1814
|
origin: fromContract ?? EMPTY_ORIGIN$1,
|
|
1571
1815
|
destination: contract,
|
|
1572
|
-
|
|
1816
|
+
statements: plannedTexts
|
|
1573
1817
|
};
|
|
1574
1818
|
const asked = (entries) => entries.map((entry) => ({
|
|
1575
1819
|
...entry,
|
|
1576
1820
|
text: subjectText(entry.subject, contractsAsked)
|
|
1577
1821
|
}));
|
|
1822
|
+
const databaseStorageHash = action === "dbUpdate" ? recordedDatabaseContract(aggregate, markerRows) : void 0;
|
|
1578
1823
|
const subjects = action === "dbUpdate" ? {
|
|
1579
1824
|
dataLoss: asked(run.subjects.dataLoss),
|
|
1580
|
-
accessWidening: asked(run.subjects.accessWidening)
|
|
1825
|
+
accessWidening: asked(run.subjects.accessWidening),
|
|
1826
|
+
temporaryValues: reportTemporaryValues(run.subjects.temporaryValues, contract)
|
|
1581
1827
|
} : void 0;
|
|
1582
1828
|
if (mode === "plan") {
|
|
1583
1829
|
const aggregateOps = orderedResolutions.flatMap((r) => r.entry.displayOps);
|
|
@@ -1592,6 +1838,7 @@ async function executeRun(options) {
|
|
|
1592
1838
|
summary,
|
|
1593
1839
|
appliedStatements,
|
|
1594
1840
|
subjects,
|
|
1841
|
+
databaseStorageHash,
|
|
1595
1842
|
...ifDefined("warnings", plannerWarnings)
|
|
1596
1843
|
});
|
|
1597
1844
|
}
|
|
@@ -1612,6 +1859,9 @@ async function executeRun(options) {
|
|
|
1612
1859
|
...ifDefined("why", applied.failure.why),
|
|
1613
1860
|
meta: applied.failure.meta,
|
|
1614
1861
|
...ifDefined("warnings", plannerWarnings),
|
|
1862
|
+
...ifDefined("failedTypeChange", applied.failure.failedTypeChange),
|
|
1863
|
+
...ifDefined("rowsWithoutValue", applied.failure.rowsWithoutValue),
|
|
1864
|
+
...ifDefined("databaseStorageHash", databaseStorageHash),
|
|
1615
1865
|
...ifDefined("cause", applied.failure.cause)
|
|
1616
1866
|
});
|
|
1617
1867
|
const aggregateOps = applied.value.orderedResolutions.flatMap((r) => r.entry.displayOps);
|
|
@@ -1625,6 +1875,7 @@ async function executeRun(options) {
|
|
|
1625
1875
|
summary,
|
|
1626
1876
|
appliedStatements,
|
|
1627
1877
|
subjects,
|
|
1878
|
+
databaseStorageHash,
|
|
1628
1879
|
...ifDefined("warnings", plannerWarnings)
|
|
1629
1880
|
});
|
|
1630
1881
|
}
|
|
@@ -1708,7 +1959,8 @@ function subjectsAcrossSpaces(orderedResolutions) {
|
|
|
1708
1959
|
}));
|
|
1709
1960
|
return {
|
|
1710
1961
|
dataLoss: orderedResolutions.flatMap((resolution) => offset(resolution, resolution.entry.dataLoss)),
|
|
1711
|
-
accessWidening: orderedResolutions.flatMap((resolution) => offset(resolution, resolution.entry.accessWidening))
|
|
1962
|
+
accessWidening: orderedResolutions.flatMap((resolution) => offset(resolution, resolution.entry.accessWidening)),
|
|
1963
|
+
temporaryValues: orderedResolutions.flatMap((resolution) => offset(resolution, resolution.entry.temporaryValues))
|
|
1712
1964
|
};
|
|
1713
1965
|
}
|
|
1714
1966
|
function aggregatePlannerWarnings(orderedResolutions) {
|
|
@@ -1779,6 +2031,7 @@ function mapPlannerError(error) {
|
|
|
1779
2031
|
function wrapPlanResult(args) {
|
|
1780
2032
|
return ok({
|
|
1781
2033
|
mode: "plan",
|
|
2034
|
+
...ifDefined("databaseStorageHash", args.databaseStorageHash),
|
|
1782
2035
|
...ifDefined("appliedStatements", args.appliedStatements),
|
|
1783
2036
|
...args.subjects,
|
|
1784
2037
|
plan: {
|
|
@@ -1797,6 +2050,7 @@ function wrapPlanResult(args) {
|
|
|
1797
2050
|
function wrapApplyResult(args) {
|
|
1798
2051
|
return ok({
|
|
1799
2052
|
mode: "apply",
|
|
2053
|
+
...ifDefined("databaseStorageHash", args.databaseStorageHash),
|
|
1800
2054
|
...ifDefined("appliedStatements", args.appliedStatements),
|
|
1801
2055
|
...args.subjects,
|
|
1802
2056
|
plan: { operations: stripOperations(args.operations) },
|
|
@@ -1825,10 +2079,22 @@ function buildRunnerFailure(args) {
|
|
|
1825
2079
|
meta: args.meta,
|
|
1826
2080
|
conflicts: void 0,
|
|
1827
2081
|
...ifDefined("warnings", args.warnings),
|
|
2082
|
+
...ifDefined("failedTypeChange", args.failedTypeChange),
|
|
2083
|
+
...ifDefined("rowsWithoutValue", args.rowsWithoutValue),
|
|
2084
|
+
...ifDefined("databaseStorageHash", args.databaseStorageHash),
|
|
1828
2085
|
...ifDefined("cause", args.cause)
|
|
1829
2086
|
}));
|
|
1830
2087
|
}
|
|
1831
2088
|
/**
|
|
2089
|
+
* The storage hash of the contract the application space's database is at, when the migration
|
|
2090
|
+
* graph has it: `migration plan --from` then resolves it. Without a migration that ends at it,
|
|
2091
|
+
* `migration plan` starts from the `db` ref that `db update` keeps.
|
|
2092
|
+
*/
|
|
2093
|
+
function recordedDatabaseContract(aggregate, markerRows) {
|
|
2094
|
+
const hash = markerRows.get(aggregate.app.spaceId)?.storageHash;
|
|
2095
|
+
return hash !== void 0 && aggregate.app.graph().nodes.has(hash) ? hash : void 0;
|
|
2096
|
+
}
|
|
2097
|
+
/**
|
|
1832
2098
|
* Execute `db init` against the configured contract.
|
|
1833
2099
|
*
|
|
1834
2100
|
* Routes through the loader → planner → runner pipeline (sub-spec
|
|
@@ -2168,6 +2434,8 @@ const DB_UPDATE_POLICY = { allowedOperationClasses: [
|
|
|
2168
2434
|
] };
|
|
2169
2435
|
/** Execute `db update` against the configured contract. */
|
|
2170
2436
|
async function executeDbUpdate(options) {
|
|
2437
|
+
const statements = options.statements ?? [];
|
|
2438
|
+
if (statements.some(({ verb }) => verb === "convert" || verb === "backfill")) throw errorStatementNeedsMigrationFile(statements, void 0);
|
|
2171
2439
|
return await executeRun({
|
|
2172
2440
|
driver: options.driver,
|
|
2173
2441
|
adapter: options.adapter,
|
|
@@ -2526,6 +2794,9 @@ async function executeMigrate(options) {
|
|
|
2526
2794
|
summary: applied.failure.summary,
|
|
2527
2795
|
why: applied.failure.why,
|
|
2528
2796
|
meta: applied.failure.meta,
|
|
2797
|
+
...ifDefined("failedTypeChange", applied.failure.failedTypeChange),
|
|
2798
|
+
...ifDefined("rowsWithoutValue", applied.failure.rowsWithoutValue),
|
|
2799
|
+
...ifDefined("failedMigration", applied.failure.failedMigration === void 0 ? void 0 : failedMigrationOnDisk(applied.failure.failedMigration, migrationsDir)),
|
|
2529
2800
|
...ifDefined("cause", applied.failure.cause)
|
|
2530
2801
|
});
|
|
2531
2802
|
const orderedAll = canonicalOrder.filter((spaceId) => perSpacePlans.has(spaceId) || plansKeptFromRunner.has(spaceId)).map((spaceId) => {
|
|
@@ -2671,6 +2942,7 @@ function buildAtHeadResolution(args) {
|
|
|
2671
2942
|
appliedStatements: [],
|
|
2672
2943
|
dataLoss: [],
|
|
2673
2944
|
accessWidening: [],
|
|
2945
|
+
temporaryValues: [],
|
|
2674
2946
|
migrationEdges: [buildFabricatedMigrationEdge({
|
|
2675
2947
|
currentMarkerStorageHash: liveMarker?.storageHash,
|
|
2676
2948
|
destinationStorageHash: targetHash,
|
|
@@ -2776,6 +3048,12 @@ function buildPathNotFoundFailure(spaceId, marker, targetHash) {
|
|
|
2776
3048
|
}
|
|
2777
3049
|
};
|
|
2778
3050
|
}
|
|
3051
|
+
function failedMigrationOnDisk(failed, migrationsDir) {
|
|
3052
|
+
return {
|
|
3053
|
+
directory: join(migrationsDir, failed.spaceId, failed.edge.dirName),
|
|
3054
|
+
from: failed.edge.from
|
|
3055
|
+
};
|
|
3056
|
+
}
|
|
2779
3057
|
/**
|
|
2780
3058
|
* Creates a programmatic control client for Prisma ORM operations.
|
|
2781
3059
|
*
|
|
@@ -2826,13 +3104,13 @@ var ControlClientImpl = class {
|
|
|
2826
3104
|
this.frameworkComponents = assertFrameworkComponentsCompatible(this.options.family.familyId, this.options.target.targetId, rawComponents);
|
|
2827
3105
|
this.initialized = true;
|
|
2828
3106
|
}
|
|
2829
|
-
async connect(connection) {
|
|
3107
|
+
async connect(connection, options) {
|
|
2830
3108
|
this.init();
|
|
2831
3109
|
if (this.driver) throw new CliStructuredError("DRIVER.ALREADY_CONNECTED", "Already connected. Call close() before reconnecting.");
|
|
2832
3110
|
const resolvedConnection = connection ?? this.defaultConnection;
|
|
2833
3111
|
if (resolvedConnection === void 0) throw new CliStructuredError("CONFIG.DB_CONNECTION_REQUIRED", "No connection provided. Pass a connection to connect() or provide a default connection when creating the client.");
|
|
2834
3112
|
if (!this.stack?.driver) throw new CliStructuredError("CONFIG.DRIVER_REQUIRED", "Driver is not configured. Pass a driver descriptor when creating the control client to enable database operations.");
|
|
2835
|
-
this.driver = await this.stack.driver.create(blindCast(resolvedConnection));
|
|
3113
|
+
this.driver = await this.stack.driver.create(blindCast(resolvedConnection), options);
|
|
2836
3114
|
}
|
|
2837
3115
|
async close() {
|
|
2838
3116
|
if (this.driver) {
|
|
@@ -3777,20 +4055,6 @@ async function advanceRefSafely(args) {
|
|
|
3777
4055
|
throw error;
|
|
3778
4056
|
}
|
|
3779
4057
|
}
|
|
3780
|
-
const SHELL_SAFE = /^[A-Za-z0-9_.:/@%+,-]+$/;
|
|
3781
|
-
/** The value as a shell passes it through unchanged, single-quoted when needed. */
|
|
3782
|
-
function shellQuoted(value) {
|
|
3783
|
-
return SHELL_SAFE.test(value) ? value : `'${value.replaceAll("'", `'\\''`)}'`;
|
|
3784
|
-
}
|
|
3785
|
-
/**
|
|
3786
|
-
* A statement written as a flag a shell passes through unchanged: the value is single-quoted when
|
|
3787
|
-
* it has a character a shell would read, and joined with `=` when it starts with `-`, which a
|
|
3788
|
-
* parser would otherwise read as a flag.
|
|
3789
|
-
*/
|
|
3790
|
-
function statementFlag(statement) {
|
|
3791
|
-
const value = shellQuoted(statement.text);
|
|
3792
|
-
return statement.text.startsWith("-") ? `--${statement.verb}=${value}` : `--${statement.verb} ${value}`;
|
|
3793
|
-
}
|
|
3794
4058
|
const RECORDED_FORMS = [
|
|
3795
4059
|
"hash",
|
|
3796
4060
|
"prefix",
|
|
@@ -5012,10 +5276,6 @@ async function executeMigrationNewCommand(options) {
|
|
|
5012
5276
|
return notOk(errorFromCaught(error, (message) => `Failed to scaffold migration: ${message}`));
|
|
5013
5277
|
}
|
|
5014
5278
|
}
|
|
5015
|
-
/** The command that runs a `migration.ts`, repeating the `--config` the CLI was given so it loads the same config. */
|
|
5016
|
-
function selfEmitCommand(migrationTs, configPath) {
|
|
5017
|
-
return configPath === void 0 ? `node "${migrationTs}"` : `node "${migrationTs}" --config "${configPath}"`;
|
|
5018
|
-
}
|
|
5019
5279
|
/**
|
|
5020
5280
|
* Phase-1 of the two-phase `migration plan` pipeline (sub-spec § 4).
|
|
5021
5281
|
*
|
|
@@ -5112,8 +5372,16 @@ function buildPlaceholderContractDts(spaceId) {
|
|
|
5112
5372
|
function isEnoent(error) {
|
|
5113
5373
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
5114
5374
|
}
|
|
5115
|
-
function placeholderSummary(planned,
|
|
5116
|
-
return `Planned ${planned} with placeholder(s) — edit migration.ts, then run ${
|
|
5375
|
+
function placeholderSummary(planned, packageDirs, invocation) {
|
|
5376
|
+
return `Planned ${planned} with placeholder(s) — edit migration.ts, then run ${packageDirs.map((dir) => `\`${selfEmitCommand(invocation, join(dir, "migration.ts"))}\``).join(" and ")} to self-emit`;
|
|
5377
|
+
}
|
|
5378
|
+
/** The invocation the plan's printed commands repeat: `migration plan` takes no `--db`. */
|
|
5379
|
+
function invocationOf(options) {
|
|
5380
|
+
return {
|
|
5381
|
+
cwd: options.cwd,
|
|
5382
|
+
configPath: options.configPath,
|
|
5383
|
+
dbGiven: false
|
|
5384
|
+
};
|
|
5117
5385
|
}
|
|
5118
5386
|
/** The origin of a plan from an empty database: no models, so no statement resolves. */
|
|
5119
5387
|
const EMPTY_ORIGIN = { domain: { namespaces: {} } };
|
|
@@ -5165,14 +5433,12 @@ async function runPlannerLeg(planner, migrations, frameworkComponents, contract,
|
|
|
5165
5433
|
plannedOps,
|
|
5166
5434
|
migrationTsContent: plannerResult.plan.renderTypeScript(resolveImportSpecifier),
|
|
5167
5435
|
hasPlaceholders,
|
|
5168
|
-
dataLoss: plannerResult.dataLoss.map(({ operationIndex, subject, keepDataAdvice }) => ({
|
|
5436
|
+
dataLoss: plannerResult.dataLoss.map(({ operationIndex, subject, loss, label, keepDataAdvice }) => ({
|
|
5169
5437
|
operationIndex: position(operationIndex),
|
|
5170
5438
|
subject,
|
|
5171
|
-
|
|
5172
|
-
label
|
|
5173
|
-
|
|
5174
|
-
renames: []
|
|
5175
|
-
})
|
|
5439
|
+
loss,
|
|
5440
|
+
label,
|
|
5441
|
+
...ifDefined("keepDataAdvice", keepDataAdvice)
|
|
5176
5442
|
})),
|
|
5177
5443
|
appliedStatements: reportAppliedStatements(plannerResult.appliedStatements.map((applied) => ({
|
|
5178
5444
|
...applied,
|
|
@@ -5180,7 +5446,8 @@ async function runPlannerLeg(planner, migrations, frameworkComponents, contract,
|
|
|
5180
5446
|
const at = position(index);
|
|
5181
5447
|
return at === void 0 ? [] : [at];
|
|
5182
5448
|
})
|
|
5183
|
-
})), fromContract, contract, 0)
|
|
5449
|
+
})), fromContract, contract, 0),
|
|
5450
|
+
temporaryValues: reportTemporaryValues(plannerResult.temporaryValues, contract)
|
|
5184
5451
|
});
|
|
5185
5452
|
}
|
|
5186
5453
|
/**
|
|
@@ -5223,9 +5490,9 @@ async function writePlannedMigrationPackage(packageDir, fromHash, toHash, create
|
|
|
5223
5490
|
}
|
|
5224
5491
|
/**
|
|
5225
5492
|
* Asks about every operation of the planned legs that would lose data, until each is answered,
|
|
5226
|
-
* before anything is written. A delete answer consents to the loss of its subject. A rename
|
|
5227
|
-
* at the prompt is a statement the plan did not have, so the delta is planned again
|
|
5228
|
-
* the loss it answered must be gone.
|
|
5493
|
+
* before anything is written. A delete answer consents to the loss of its subject. A rename or
|
|
5494
|
+
* convert typed at the prompt is a statement the plan did not have, so the delta is planned again
|
|
5495
|
+
* with every statement, and the loss it answered must be gone.
|
|
5229
5496
|
*/
|
|
5230
5497
|
async function answerPlannedDataLoss(input) {
|
|
5231
5498
|
const legs = (delta) => ({
|
|
@@ -5236,7 +5503,8 @@ async function answerPlannedDataLoss(input) {
|
|
|
5236
5503
|
const answered = await askPlanQuestions({
|
|
5237
5504
|
plan: legs(input.delta),
|
|
5238
5505
|
askAccess: false,
|
|
5239
|
-
|
|
5506
|
+
canConvert: true,
|
|
5507
|
+
statements: input.statements,
|
|
5240
5508
|
preAnswers: input.consents,
|
|
5241
5509
|
consentAll: {
|
|
5242
5510
|
delete: false,
|
|
@@ -5246,8 +5514,8 @@ async function answerPlannedDataLoss(input) {
|
|
|
5246
5514
|
originKnown: input.originKnown,
|
|
5247
5515
|
destination: input.destination,
|
|
5248
5516
|
answer: input.answer,
|
|
5249
|
-
replan: async (
|
|
5250
|
-
const replanned = await input.planDelta(
|
|
5517
|
+
replan: async (statements) => {
|
|
5518
|
+
const replanned = await input.planDelta(statements);
|
|
5251
5519
|
return replanned.ok ? ok(legs(replanned.value)) : replanned;
|
|
5252
5520
|
}
|
|
5253
5521
|
});
|
|
@@ -5405,6 +5673,7 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
5405
5673
|
emittedExtensionDirs,
|
|
5406
5674
|
...warnings.length > 0 ? { warnings } : {},
|
|
5407
5675
|
appliedStatements: [],
|
|
5676
|
+
temporaryValues: [],
|
|
5408
5677
|
summary: "No changes detected between contracts",
|
|
5409
5678
|
timings: { total: Date.now() - startTime }
|
|
5410
5679
|
});
|
|
@@ -5441,15 +5710,15 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
5441
5710
|
const answerDataLoss = (baseline, delta, planDelta) => answerPlannedDataLoss({
|
|
5442
5711
|
baseline,
|
|
5443
5712
|
delta,
|
|
5444
|
-
|
|
5445
|
-
consents: statementTexts.filter((statement) => statement
|
|
5713
|
+
statements: statementTexts.filter(isPlannedStatement),
|
|
5714
|
+
consents: statementTexts.filter((statement) => !isPlannedStatement(statement)),
|
|
5446
5715
|
origin: fromContract ?? EMPTY_ORIGIN,
|
|
5447
5716
|
originKnown: true,
|
|
5448
5717
|
destination: toContract,
|
|
5449
5718
|
answer: options.answerQuestions,
|
|
5450
|
-
planDelta: async (
|
|
5719
|
+
planDelta: async (planned) => {
|
|
5451
5720
|
const resolved = resolveStatements({
|
|
5452
|
-
statements:
|
|
5721
|
+
statements: planned,
|
|
5453
5722
|
origin: {
|
|
5454
5723
|
kind: "contract",
|
|
5455
5724
|
contract: fromContract ?? EMPTY_ORIGIN
|
|
@@ -5504,8 +5773,10 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
5504
5773
|
emittedExtensionDirs,
|
|
5505
5774
|
...warnings.length > 0 ? { warnings } : {},
|
|
5506
5775
|
pendingPlaceholders: true,
|
|
5776
|
+
placeholderDirs: [baselineDir],
|
|
5507
5777
|
appliedStatements: [...statementsWithoutOperations, ...deletes],
|
|
5508
|
-
|
|
5778
|
+
temporaryValues: baselineLeg.value.temporaryValues,
|
|
5779
|
+
summary: placeholderSummary("baseline", [baselinePackageDir], invocationOf(options)),
|
|
5509
5780
|
timings: { total: Date.now() - startTime }
|
|
5510
5781
|
});
|
|
5511
5782
|
}
|
|
@@ -5525,6 +5796,7 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
5525
5796
|
...preview !== void 0 ? { preview } : {},
|
|
5526
5797
|
...warnings.length > 0 ? { warnings } : {},
|
|
5527
5798
|
appliedStatements: [...statementsWithoutOperations, ...deletes],
|
|
5799
|
+
temporaryValues: baselineLeg.value.temporaryValues,
|
|
5528
5800
|
summary: buildAutoBaselinePlanSummary(baselineOps.length, 0, emittedExtensionDirs.length),
|
|
5529
5801
|
timings: { total: Date.now() - startTime }
|
|
5530
5802
|
});
|
|
@@ -5548,8 +5820,10 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
5548
5820
|
emittedExtensionDirs,
|
|
5549
5821
|
...warnings.length > 0 ? { warnings } : {},
|
|
5550
5822
|
pendingPlaceholders: true,
|
|
5823
|
+
placeholderDirs: [...baselineLeg.value.hasPlaceholders ? [relative(cwd, baselinePackageDir)] : [], ...deltaLeg.value.hasPlaceholders ? [relative(cwd, deltaPackageDir)] : []],
|
|
5551
5824
|
appliedStatements: [...deltaLeg.value.appliedStatements, ...deletes],
|
|
5552
|
-
|
|
5825
|
+
temporaryValues: deltaLeg.value.temporaryValues,
|
|
5826
|
+
summary: placeholderSummary("baseline + migration", [baselinePackageDir, deltaPackageDir], invocationOf(options)),
|
|
5553
5827
|
timings: { total: Date.now() - startTime }
|
|
5554
5828
|
});
|
|
5555
5829
|
}
|
|
@@ -5575,6 +5849,7 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
5575
5849
|
...preview !== void 0 ? { preview } : {},
|
|
5576
5850
|
...warnings.length > 0 ? { warnings } : {},
|
|
5577
5851
|
appliedStatements: [...deltaLeg.value.appliedStatements, ...deletes],
|
|
5852
|
+
temporaryValues: deltaLeg.value.temporaryValues,
|
|
5578
5853
|
summary: buildAutoBaselinePlanSummary(baselineOps.length, deltaOps.length, emittedExtensionDirs.length),
|
|
5579
5854
|
timings: { total: Date.now() - startTime }
|
|
5580
5855
|
});
|
|
@@ -5597,6 +5872,7 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
5597
5872
|
emittedExtensionDirs,
|
|
5598
5873
|
...warnings.length > 0 ? { warnings } : {},
|
|
5599
5874
|
appliedStatements: [...deltaLeg.value.appliedStatements, ...deletes],
|
|
5875
|
+
temporaryValues: deltaLeg.value.temporaryValues,
|
|
5600
5876
|
summary: "No changes to plan: the statements need no operations",
|
|
5601
5877
|
timings: { total: Date.now() - startTime }
|
|
5602
5878
|
});
|
|
@@ -5614,9 +5890,11 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
5614
5890
|
emittedExtensionDirs,
|
|
5615
5891
|
...warnings.length > 0 ? { warnings } : {},
|
|
5616
5892
|
pendingPlaceholders: true,
|
|
5893
|
+
placeholderDirs: [relative(cwd, packageDir)],
|
|
5617
5894
|
...fromDefaulted ? { fromDefaulted } : {},
|
|
5618
5895
|
appliedStatements: [...deltaLeg.value.appliedStatements, ...deletes],
|
|
5619
|
-
|
|
5896
|
+
temporaryValues: deltaLeg.value.temporaryValues,
|
|
5897
|
+
summary: placeholderSummary("migration", [packageDir], invocationOf(options)),
|
|
5620
5898
|
timings: { total: Date.now() - startTime }
|
|
5621
5899
|
});
|
|
5622
5900
|
}
|
|
@@ -5638,6 +5916,7 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
5638
5916
|
...fromDefaulted ? { fromDefaulted } : {},
|
|
5639
5917
|
...warnings.length > 0 ? { warnings } : {},
|
|
5640
5918
|
appliedStatements: [...deltaLeg.value.appliedStatements, ...deletes],
|
|
5919
|
+
temporaryValues: deltaLeg.value.temporaryValues,
|
|
5641
5920
|
summary: buildPlanSummary(plannedOps.length, emittedExtensionDirs.length),
|
|
5642
5921
|
timings: { total: Date.now() - startTime }
|
|
5643
5922
|
});
|
|
@@ -5780,6 +6059,6 @@ async function executeRefListCommand(options) {
|
|
|
5780
6059
|
}
|
|
5781
6060
|
}
|
|
5782
6061
|
//#endregion
|
|
5783
|
-
export {
|
|
6062
|
+
export { refuseMissingInvariantPath as $, executeRefDeleteCommand as A, loadContractRawSafely as B, executeDbSign as C, executeMigrationNewCommand as D, executeMigrateShowPlan as E, hasMigrationPath as F, mapContractAtError as G, loadContractSourceWithStack as H, isStatementVerb as I, preflightRefAdvancement as J, mapIntegrityViolations as K, listRefsByContractHash as L, executeRefSetCommand as M, findPackageByDirPath as N, executeMigrationPlanCommand as O, formatSourceDiagnostic as P, refuseMarkerOutsideGraph as Q, liveMarkerUse as R, executeDbInit as S, executeDbVerify as T, loadContractSpaceAggregateForCli as U, loadContractSource as V, looksLikePath as W, refuseContractSpaceIntegrity as X, readMigrationRefs as Y, refuseDeclaredExtensionTargetMismatch as Z, deriveStatusEdgeAnnotations as _, toDeclaredExtensionsFromRaw as _t, RECORDED_OR_EMPTY_CONTRACT_REF_FORMS as a, resolveContractRefToSnapshot as at, enumerateCheckSpaces as b, appliedHashesFromLedger as c, resolveStatements as ct, buildReadAggregate as d, runContractSpaceSeedPhase as dt, refusePackageCorruptionOnAggregate as et, buildRefAdvancementFields as f, runMigrationCheck as ft, createControlClient as g, statusForMigrationHash as gt, convertAndDelete as h, sourceWarningDiagnostic as ht, RECORDED_CONTRACT_REF_FORMS as i, resolveContractRef$1 as it, executeRefListCommand as j, executeRefAdvancement as k, buildContractSpaceAggregate as l, resolveToForPlan as lt, computeRefAdvancementName as m, snapshotVerifierFor as mt, DB_UPDATE_POLICY as n, requireDatabaseForLiveMarkerUse as nt, advanceRefSafely as o, resolveFromForPlan as ot, checkSingleTarget as p, runMigrationList as pt, migrationSpaceListEntriesFromAggregate as q, NO_REF_ADVANCEMENT as r, resolveAppTargetPath as rt, appContractStandInFromIdentity as s, resolveMigrationRef as st, ALL_CONTRACT_REF_FORMS as t, refuseUnknownInvariants as tt, buildMigrationSpaceGraphEntries as u, retryCommandFor as ut, disposeEmitQueue as v, validateLoadedContract as vt, executeDbUpdate as w, executeContractEmit as x, enrichContract as y, loadAggregateIntegrityViolations as z };
|
|
5784
6063
|
|
|
5785
|
-
//# sourceMappingURL=ref-
|
|
6064
|
+
//# sourceMappingURL=ref-BMhPu-wB-DU1LW2lb.mjs.map
|