@prisma/orm-toolchain 8.0.0-rc.24-dev.42 → 8.0.0-rc.24-dev.44
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-BAt9Aj73.mjs → aggregate-B2D5REGs.mjs} +9 -9
- package/dist/{aggregate-BAt9Aj73.mjs.map → aggregate-B2D5REGs.mjs.map} +1 -1
- package/dist/{aggregate-DgWdbWNs.d.mts → aggregate-CvDNKQbR.d.mts} +5 -5
- package/dist/{aggregate-DgWdbWNs.d.mts.map → aggregate-CvDNKQbR.d.mts.map} +1 -1
- package/dist/{caught-errors-D_pbHqmS-B-4jRN6g.mjs → caught-errors-DZXnK8Ls-zVmM4nr3.mjs} +590 -49
- package/dist/caught-errors-DZXnK8Ls-zVmM4nr3.mjs.map +1 -0
- package/dist/cli-telemetry.mjs +1 -1
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +342 -106
- package/dist/cli.mjs.map +1 -1
- package/dist/cli__control-api.d.mts +13 -60
- 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__migration-cli.mjs +4 -4
- package/dist/cli__migration-cli.mjs.map +1 -1
- package/dist/config-loader.mjs +1 -1
- package/dist/contract-snapshot-store-D-s2aKZY.d.mts +2 -0
- package/dist/{contract-snapshot-store-xDOQSwJh-YNdzKU85.d.mts → contract-snapshot-store-DRAG5XXy-ChW4hBLb.d.mts} +6 -4
- package/dist/contract-snapshot-store-DRAG5XXy-ChW4hBLb.d.mts.map +1 -0
- package/dist/{contract-snapshot-store-B0fRbVHB-BN2g8BKh.mjs → contract-snapshot-store-Dl6v-Uxr-CwhnMsgc.mjs} +10 -6
- package/dist/contract-snapshot-store-Dl6v-Uxr-CwhnMsgc.mjs.map +1 -0
- package/dist/{db-sign-DLIR5swa-DQ0aN1nU.d.mts → db-sign-BQMw6RX9-Stp7Gjj7.d.mts} +187 -18
- package/dist/db-sign-BQMw6RX9-Stp7Gjj7.d.mts.map +1 -0
- package/dist/{domain-type-generation-BGcbGgHJ-Cdw5RNaZ.mjs → domain-type-generation-BGcbGgHJ-SB6n89eE.mjs} +3 -3
- package/dist/{domain-type-generation-BGcbGgHJ-Cdw5RNaZ.mjs.map → domain-type-generation-BGcbGgHJ-SB6n89eE.mjs.map} +1 -1
- package/dist/emitter.mjs +2 -2
- package/dist/emitter__domain-type-generation.mjs +1 -1
- package/dist/{errors-BMq40nYH-Cg8PBect.mjs → errors-BlaB9AFz-CZDOC0mV.mjs} +8 -10
- package/dist/{errors-BMq40nYH-Cg8PBect.mjs.map → errors-BlaB9AFz-CZDOC0mV.mjs.map} +1 -1
- package/dist/{exports-BiXPktAF.mjs → exports-B0yFVod3.mjs} +3 -3
- package/dist/{exports-BiXPktAF.mjs.map → exports-B0yFVod3.mjs.map} +1 -1
- package/dist/{exports-CCuYD8dO-yw1GizAT.mjs → exports-CCuYD8dO-fFXwpizm.mjs} +3 -3
- package/dist/{exports-CCuYD8dO-yw1GizAT.mjs.map → exports-CCuYD8dO-fFXwpizm.mjs.map} +1 -1
- package/dist/{exports-CZ6dPu-O.mjs → exports-DNFYCa6U.mjs} +3 -3
- package/dist/{exports-CZ6dPu-O.mjs.map → exports-DNFYCa6U.mjs.map} +1 -1
- package/dist/{graph-membership-D7m41lWA-B68g1CRS.mjs → graph-membership-ClCmhVjf-8XCns4rf.mjs} +3 -3
- package/dist/{graph-membership-D7m41lWA-B68g1CRS.mjs.map → graph-membership-ClCmhVjf-8XCns4rf.mjs.map} +1 -1
- package/dist/hash-DcBt3lpO.d.mts +1 -0
- package/dist/{hash-DclMqd7S-WBvXJ_4C.d.mts → hash-DclMqd7S-Dddl_NeA.d.mts} +2 -2
- package/dist/{hash-DclMqd7S-WBvXJ_4C.d.mts.map → hash-DclMqd7S-Dddl_NeA.d.mts.map} +1 -1
- package/dist/{invariants-DxCj82g2-DhGkStla.mjs → invariants-c9W7-6DY-CzSdi8Vp.mjs} +3 -3
- package/dist/{invariants-DxCj82g2-DhGkStla.mjs.map → invariants-c9W7-6DY-CzSdi8Vp.mjs.map} +1 -1
- package/dist/io-BalYebmm.d.mts +1 -0
- package/dist/{io-B39zsxMm-D5Wcf6cf.mjs → io-DUsSXBRO-BqRNb69U.mjs} +5 -5
- package/dist/{io-B39zsxMm-D5Wcf6cf.mjs.map → io-DUsSXBRO-BqRNb69U.mjs.map} +1 -1
- package/dist/{io-BzVNzfsY-DE_ev9K6.d.mts → io-DpAplMzQ-ZTJi-tTr.d.mts} +3 -3
- package/dist/{io-BzVNzfsY-DE_ev9K6.d.mts.map → io-DpAplMzQ-ZTJi-tTr.d.mts.map} +1 -1
- package/dist/{migration-DTmtOJ0n.mjs → migration-C1l4_CWi.mjs} +3 -3
- package/dist/{migration-DTmtOJ0n.mjs.map → migration-C1l4_CWi.mjs.map} +1 -1
- package/dist/{migration-graph-BoiiZAaU-DLht12k7.mjs → migration-graph-DBJAol1y-DX61Ss3X.mjs} +19 -3
- package/dist/{migration-graph-BoiiZAaU-DLht12k7.mjs.map → migration-graph-DBJAol1y-DX61Ss3X.mjs.map} +1 -1
- package/dist/{migration-graph-D8IuOkZb-pSI7-k4_.d.mts → migration-graph-DCIdjMtC-CAs3pm1A.d.mts} +10 -3
- package/dist/{migration-graph-D8IuOkZb-pSI7-k4_.d.mts.map → migration-graph-DCIdjMtC-CAs3pm1A.d.mts.map} +1 -1
- package/dist/{migration-graph-Dra4CcyN.d.mts → migration-graph-GiSYbAc8.d.mts} +2 -2
- package/dist/{migration-graph-Dra4CcyN.d.mts.map → migration-graph-GiSYbAc8.d.mts.map} +1 -1
- package/dist/migration-tools.d.mts +14 -14
- package/dist/migration-tools.mjs +13 -13
- package/dist/migration-tools__aggregate.d.mts +1 -1
- package/dist/migration-tools__aggregate.mjs +1 -1
- package/dist/migration-tools__contract-snapshot-store.d.mts +4 -4
- package/dist/migration-tools__contract-snapshot-store.mjs +2 -2
- package/dist/migration-tools__errors.mjs +1 -1
- package/dist/migration-tools__hash.d.mts +2 -2
- package/dist/migration-tools__invariants.mjs +1 -1
- package/dist/migration-tools__io.d.mts +2 -2
- package/dist/migration-tools__io.mjs +1 -1
- package/dist/migration-tools__migration-graph.d.mts +3 -3
- package/dist/migration-tools__migration-graph.mjs +3 -3
- package/dist/migration-tools__migration.mjs +1 -1
- package/dist/migration-tools__ref-resolution.mjs +1 -1
- package/dist/migration-tools__refs.mjs +1 -1
- package/dist/migration-tools__spaces.mjs +2 -2
- package/dist/{ref-Ba6Mk6Rg-DKaPWk2l.mjs → ref-C7TozKnq-C4UYYbRT.mjs} +398 -162
- package/dist/ref-C7TozKnq-C4UYYbRT.mjs.map +1 -0
- package/dist/{ref-resolution-C0xsiRig.mjs → ref-resolution-533MGMov.mjs} +2 -2
- package/dist/{ref-resolution-C0xsiRig.mjs.map → ref-resolution-533MGMov.mjs.map} +1 -1
- package/dist/{refs-t_JbIjGo-BVCqKpXd.mjs → refs-BE6yEgSV-CbpqGnbl.mjs} +3 -3
- package/dist/{refs-t_JbIjGo-BVCqKpXd.mjs.map → refs-BE6yEgSV-CbpqGnbl.mjs.map} +1 -1
- package/dist/{spaces-OVZ0QzWJ.mjs → spaces-Cj_GYpmM.mjs} +7 -7
- package/dist/{spaces-OVZ0QzWJ.mjs.map → spaces-Cj_GYpmM.mjs.map} +1 -1
- package/dist/{verify-contract-spaces-BOnqhfQs-BBq5YOKo.mjs → verify-contract-spaces-DvU9lE0Y-Y1WwEsPA.mjs} +4 -4
- package/dist/{verify-contract-spaces-BOnqhfQs-BBq5YOKo.mjs.map → verify-contract-spaces-DvU9lE0Y-Y1WwEsPA.mjs.map} +1 -1
- package/dist/vite-plugin-contract-emit.mjs +3 -3
- package/package.json +11 -11
- package/dist/caught-errors-D_pbHqmS-B-4jRN6g.mjs.map +0 -1
- package/dist/contract-snapshot-store-B0fRbVHB-BN2g8BKh.mjs.map +0 -1
- package/dist/contract-snapshot-store-DXFizCe8.d.mts +0 -2
- package/dist/contract-snapshot-store-xDOQSwJh-YNdzKU85.d.mts.map +0 -1
- package/dist/db-sign-DLIR5swa-DQ0aN1nU.d.mts.map +0 -1
- package/dist/hash-CwWGlFWV.d.mts +0 -1
- package/dist/io--BGERFnD.d.mts +0 -1
- package/dist/ref-Ba6Mk6Rg-DKaPWk2l.mjs.map +0 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { a as expandContractInputs, c as globContractInputMatching, d as loadConfigFiles, g as requireConfigSections, h as ormConfigSection, i as evaluateConfigModule, r as buildLoadedConfig } from "./exports-
|
|
1
|
+
import { a as expandContractInputs, c as globContractInputMatching, d as loadConfigFiles, g as requireConfigSections, h as ormConfigSection, i as evaluateConfigModule, r as buildLoadedConfig } from "./exports-DNFYCa6U.mjs";
|
|
2
2
|
import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
|
|
3
|
-
import { t as MigrationToolsError } from "./errors-
|
|
4
|
-
import {
|
|
5
|
-
import { s as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { a as
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
3
|
+
import { b as errorInvalidRefName, t as MigrationToolsError } from "./errors-BlaB9AFz-CZDOC0mV.mjs";
|
|
4
|
+
import { r as isInSpaceHistory } from "./graph-membership-ClCmhVjf-8XCns4rf.mjs";
|
|
5
|
+
import { s as reconstructGraph } from "./migration-graph-DBJAol1y-DX61Ss3X.mjs";
|
|
6
|
+
import { i as hasContractSnapshot, t as contractSnapshotDir } from "./contract-snapshot-store-Dl6v-Uxr-CwhnMsgc.mjs";
|
|
7
|
+
import { s as readMigrationsDir } from "./io-DUsSXBRO-BqRNb69U.mjs";
|
|
8
|
+
import { a as readRefs, i as readRef, n as advanceRef, u as validateRefName } from "./refs-BE6yEgSV-CbpqGnbl.mjs";
|
|
9
|
+
import { l as spaceMigrationDirectory, u as spaceRefsDirectory } from "./verify-contract-spaces-DvU9lE0Y-Y1WwEsPA.mjs";
|
|
10
|
+
import { a as contractHashAtMarker } from "./aggregate-B2D5REGs.mjs";
|
|
11
|
+
import { $ as errorSignRefsNotWritten, A as errorContractValidationFailed, At as redactUrlCredentials, C as errorAdvanceRefArgConflict, D as errorContractArgConflict, Dt as printedWayToTarget, E as errorConsentUnused, Et as printedPlan, F as errorFromCaught, Ft as runCommandAction, I as errorHashMismatch, It as selfEmitCommand, Lt as shellQuoted, M as errorDatabaseConnectionRequired, Mt as rerunFlags, N as errorDriverRequired, O as errorContractConfigMissing, Ot as quotedPlan, P as errorFileNotFound, Q as errorRuntime, R as errorLegendHumanOnly, Rt as statementFlag, St as migrationsDirFor, T as errorConfigValidation$1, U as errorNoMigrations, V as errorMigrationPackageNotFound, Z as errorRefTargetEmpty, _ as databasePositionOf, _t as migrationPlanChoice, a as appMigrationsDirFor, at as errorStatementNeedsMigrationFile, b as dbUpdateRerun, c as baseDirFor, ct as errorTargetMigrationNotSupported, f as cliInvocation, ft as hasMigrationPath, gt as migrationPlanArguments, h as contractPathFor, j as errorConvertAndDelete, jt as requireLiveDatabase, kt as readContractEnvelope, l as chooseAction, lt as errorTargetMismatch, mt as maskConnectionUrl, o as appRefsDirFor, p as closeQuietly, r as CliStructuredError$1$1, u as cliCommand, vt as migrationPlanForDatabase, x as displayPath, xt as migrationPlanTo, z as errorMarkerMissing, zt as targetSupportsMigrations } from "./caught-errors-DZXnK8Ls-zVmM4nr3.mjs";
|
|
12
|
+
import { r as getEmittedArtifactPaths } from "./exports-CCuYD8dO-fFXwpizm.mjs";
|
|
13
|
+
import { o as isLiveMarkerRef } from "./ref-resolution-533MGMov.mjs";
|
|
14
|
+
import { $ as preflightRefAdvancement, A as executeMigrationNewCommand, B as listRefsByContractHash, C as errorPermitPolicyChangeNeedsRef, Ct as toDeclaredExtensionsFromRaw, Et as writeAdvancedRef, F as executeRefSetCommand, G as loadContractSourceWithStack, H as loadAggregateIntegrityViolations, I as findPackageByDirPath, J as mapContractAtError, K as loadContractSpaceAggregateForCli, L as formatSourceDiagnostic, N as executeRefDeleteCommand, P as executeRefListCommand, Q as planEverySpace, R as isStatementVerb, S as enumerateCheckSpaces, St as statusForMigrationHash, Tt as withWarningFindings, U as loadContractRawSafely, V as liveMarkerUse, W as loadContractSource, X as matchConsents, Z as migrationSpaceListEntriesFromAggregate, _ as databasePoliciesInForce, _t as runMigrationCheck, a as advanceRefSafely, at as refuseUnknownInvariants, bt as snapshotVerifierFor, ct as resolveAppTargetPath, d as buildRefAdvancementFields, et as readMigrationRefs, f as checkSingleTarget, ft as resolveMigrationRef, g as createControlClient, h as convertAndDelete, ht as retryCommandFor, i as RECORDED_OR_EMPTY_CONTRACT_REF_FORMS, it as refusePackageCorruptionOnAggregate, j as executeMigrationPlanCommand, k as executeMigrateShowPlan, l as buildMigrationSpaceGraphEntries, lt as resolveContractRef$1, m as contractValidationMeta, n as NO_REF_ADVANCEMENT, ot as renamedAndDeleted, p as computeRefAdvancementName, q as looksLikePath, r as RECORDED_CONTRACT_REF_FORMS, rt as refuseMissingInvariantPath, s as appliedHashesFromLedger, st as requireDatabaseForLiveMarkerUse, t as ALL_CONTRACT_REF_FORMS, tt as refuseContractSpaceIntegrity, u as buildReadAggregate, ut as resolveContractRefToSnapshot, v as declaredSettingsText, vt as runMigrationList, w as executeContractEmit, wt as validateLoadedContract, xt as sourceWarningDiagnostic, y as deriveStatusEdgeAnnotations, yt as skippedOperationsText, z as labelsText } from "./ref-C7TozKnq-C4UYYbRT.mjs";
|
|
14
15
|
import { a as PRISMA7_QUICK_REFERENCE_STEP, i as PRISMA7_LOOP_STEP, n as InitOutputSchema, o as buildNextSteps, r as NEXT_STEPS_BEFORE_SCAFFOLD, t as DB_SIGN_STEP } from "./output-BV7p64ql-nFpstc7l.mjs";
|
|
15
16
|
import { a as resolveGating, i as readUserConfig, r as ensureInstallationId, s as runTelemetry, u as userConfigPath } from "./exports-DwuO4y2c.mjs";
|
|
16
17
|
import { createRequire } from "node:module";
|
|
@@ -21,10 +22,10 @@ import { InternalError, isInternalError } from "@prisma/orm-framework/utils/inte
|
|
|
21
22
|
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
22
23
|
import { DOCS_BASE, docsUrlFor, isStructuredError, isStructuredErrorCode } from "@prisma/orm-framework/utils/structured-error";
|
|
23
24
|
import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve } from "pathe";
|
|
24
|
-
import { errorMarkerPoliciesCorrupt } from "@prisma/orm-framework/errors/execution";
|
|
25
|
-
import { mkdir, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
26
25
|
import { blindCast, castAs } from "@prisma/orm-framework/utils/casts";
|
|
26
|
+
import { mkdir, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
27
27
|
import { type } from "arktype";
|
|
28
|
+
import { errorMarkerPoliciesCorrupt } from "@prisma/orm-framework/errors/execution";
|
|
28
29
|
import { existsSync, fstatSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
29
30
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
30
31
|
import { createCli, defineCommand, defineCommandFamily, defineServerCommand, flag, noDataLines, positional, telemetryCommandGroup } from "@prisma/cli-engine";
|
|
@@ -42,8 +43,8 @@ import stringWidth from "string-width";
|
|
|
42
43
|
import { bold, createColors, cyan, cyanBright, dim, green, yellow } from "colorette";
|
|
43
44
|
import { isCI } from "ci-info";
|
|
44
45
|
import { build } from "esbuild";
|
|
45
|
-
//#region ../../../1-framework/3-tooling/cli/dist/cli-
|
|
46
|
-
var version = "8.0.0-rc.24-dev.
|
|
46
|
+
//#region ../../../1-framework/3-tooling/cli/dist/cli-D0IHPTEs.mjs
|
|
47
|
+
var version = "8.0.0-rc.24-dev.44";
|
|
47
48
|
const ESCAPES = {
|
|
48
49
|
"\\": "\\\\",
|
|
49
50
|
" ": "\\t",
|
|
@@ -954,16 +955,31 @@ function previewBlocks$2(preview) {
|
|
|
954
955
|
lines: statements
|
|
955
956
|
}];
|
|
956
957
|
}
|
|
957
|
-
/**
|
|
958
|
-
|
|
958
|
+
/**
|
|
959
|
+
* The new required fields whose existing rows get a temporary value, and how to choose the value:
|
|
960
|
+
* before the run, with `migrationPlan` instead; after it, by updating
|
|
961
|
+
* the rows, since the database already has the new contract.
|
|
962
|
+
*/
|
|
963
|
+
function temporaryValueBlocks$1(result, invocation, migrationPlan) {
|
|
964
|
+
const choose = (field) => {
|
|
965
|
+
if (result.mode === "apply") return " To choose another value, update those rows.";
|
|
966
|
+
if (migrationPlan === void 0) return "";
|
|
967
|
+
const plan = printedWayToTarget(invocation, migrationPlan, [statementFlag({
|
|
968
|
+
verb: "backfill",
|
|
969
|
+
text: field
|
|
970
|
+
})]);
|
|
971
|
+
switch (plan.kind) {
|
|
972
|
+
case "on-disk": return ` ${plan.reason}. To fill the rows as they do, apply them with \`${plan.apply}\` instead.`;
|
|
973
|
+
case "none":
|
|
974
|
+
case "at-target": return ` No migration can be planned to choose it. ${plan.reason}.`;
|
|
975
|
+
default: return ` To choose the value instead, plan a migration with ${quotedPlan(plan)}, ${plan.afterPlan}.`;
|
|
976
|
+
}
|
|
977
|
+
};
|
|
959
978
|
const get = result.mode === "plan" ? "would get" : "got";
|
|
960
979
|
return (result.temporaryValues ?? []).map(({ field, value }) => ({
|
|
961
980
|
kind: "summary",
|
|
962
981
|
status: "warn",
|
|
963
|
-
text: `Field "${field}" ${get} the temporary value ${value} where existing data has none
|
|
964
|
-
verb: "backfill",
|
|
965
|
-
text: field
|
|
966
|
-
})])} instead.`
|
|
982
|
+
text: `Field "${field}" ${get} the temporary value ${value} where existing data has none.${choose(field)}`
|
|
967
983
|
}));
|
|
968
984
|
}
|
|
969
985
|
function planSummaryText(result) {
|
|
@@ -1035,7 +1051,7 @@ function questionBlocks(result) {
|
|
|
1035
1051
|
}]
|
|
1036
1052
|
}];
|
|
1037
1053
|
}
|
|
1038
|
-
function planBlocks$1(result, invocation,
|
|
1054
|
+
function planBlocks$1(result, invocation, migrationPlan) {
|
|
1039
1055
|
const planned = result.plannedAdvanceRef;
|
|
1040
1056
|
return [
|
|
1041
1057
|
{
|
|
@@ -1045,7 +1061,7 @@ function planBlocks$1(result, invocation, databaseStorageHash) {
|
|
|
1045
1061
|
},
|
|
1046
1062
|
...plannerWarningBlocks(result),
|
|
1047
1063
|
...operationBlocks$2(result),
|
|
1048
|
-
...temporaryValueBlocks$1(result, invocation,
|
|
1064
|
+
...temporaryValueBlocks$1(result, invocation, migrationPlan),
|
|
1049
1065
|
...appliedStatementBlocks(result.appliedStatements ?? []),
|
|
1050
1066
|
...questionBlocks(result),
|
|
1051
1067
|
{
|
|
@@ -1121,7 +1137,7 @@ function permittedStatementBlocks(result) {
|
|
|
1121
1137
|
}] : [];
|
|
1122
1138
|
});
|
|
1123
1139
|
}
|
|
1124
|
-
function applyBlocks(result, invocation,
|
|
1140
|
+
function applyBlocks(result, invocation, migrationPlan) {
|
|
1125
1141
|
const advanced = result.advancedRef;
|
|
1126
1142
|
return [
|
|
1127
1143
|
{
|
|
@@ -1131,7 +1147,7 @@ function applyBlocks(result, invocation, databaseStorageHash) {
|
|
|
1131
1147
|
},
|
|
1132
1148
|
...plannerWarningBlocks(result),
|
|
1133
1149
|
...operationBlocks$2(result),
|
|
1134
|
-
...temporaryValueBlocks$1(result, invocation,
|
|
1150
|
+
...temporaryValueBlocks$1(result, invocation, migrationPlan),
|
|
1135
1151
|
...appliedStatementBlocks(result.appliedStatements ?? []),
|
|
1136
1152
|
...permittedStatementBlocks(result),
|
|
1137
1153
|
...fallbackMarkerBlocks(result),
|
|
@@ -1147,11 +1163,11 @@ function applyBlocks(result, invocation, databaseStorageHash) {
|
|
|
1147
1163
|
}
|
|
1148
1164
|
/**
|
|
1149
1165
|
* What a `db init` / `db update` result looks like in human mode. Printed commands repeat
|
|
1150
|
-
* `invocation`, and a printed `migration plan`
|
|
1151
|
-
*
|
|
1166
|
+
* `invocation`, and a printed `migration plan` is `migrationPlan`, which `db init`
|
|
1167
|
+
* does not give.
|
|
1152
1168
|
*/
|
|
1153
|
-
function migrationResultBlocks(result, invocation,
|
|
1154
|
-
return result.mode === "plan" ? planBlocks$1(result, invocation,
|
|
1169
|
+
function migrationResultBlocks(result, invocation, migrationPlan) {
|
|
1170
|
+
return result.mode === "plan" ? planBlocks$1(result, invocation, migrationPlan) : applyBlocks(result, invocation, migrationPlan);
|
|
1155
1171
|
}
|
|
1156
1172
|
/** Where the user goes next, as typed actions rather than trailing prose. */
|
|
1157
1173
|
function migrationResultNextActions(result, invocation, applyCommand) {
|
|
@@ -1658,7 +1674,7 @@ const FINDINGS_EXIT_CODE$2 = 4;
|
|
|
1658
1674
|
* normally done against the real database via `--db`. Only `--no-advance-ref`
|
|
1659
1675
|
* suppresses it.
|
|
1660
1676
|
*/
|
|
1661
|
-
const DEFAULT_ADVANCE_REF = "db";
|
|
1677
|
+
const DEFAULT_ADVANCE_REF$1 = "db";
|
|
1662
1678
|
const CONTRACT_REF_BRIEF = `Contract reference (${RECORDED_CONTRACT_REF_FORMS})`;
|
|
1663
1679
|
const NO_PREVIOUS_HASH_CODES = /* @__PURE__ */ new Set([
|
|
1664
1680
|
"MIGRATION.UNKNOWN_REF",
|
|
@@ -1865,7 +1881,7 @@ function signPresentations(inputs) {
|
|
|
1865
1881
|
kind: "summary",
|
|
1866
1882
|
status: "info",
|
|
1867
1883
|
tone: "muted",
|
|
1868
|
-
text: `Left ref "${DEFAULT_ADVANCE_REF}" untouched (--no-advance-ref)`
|
|
1884
|
+
text: `Left ref "${DEFAULT_ADVANCE_REF$1}" untouched (--no-advance-ref)`
|
|
1869
1885
|
}] : inputs.advanced.map((advanced) => ({
|
|
1870
1886
|
kind: "summary",
|
|
1871
1887
|
status: "ok",
|
|
@@ -2013,7 +2029,7 @@ function createDbSignCommand(createClient = createControlClient) {
|
|
|
2013
2029
|
...ifDefined("driver", ctx.config.driver),
|
|
2014
2030
|
extensions: ctx.config.extensions ?? []
|
|
2015
2031
|
});
|
|
2016
|
-
const refName = args.flags.noAdvanceRef ? null : args.flags.advanceRef ?? DEFAULT_ADVANCE_REF;
|
|
2032
|
+
const refName = args.flags.noAdvanceRef ? null : args.flags.advanceRef ?? DEFAULT_ADVANCE_REF$1;
|
|
2017
2033
|
let advancement = null;
|
|
2018
2034
|
if (refName !== null) {
|
|
2019
2035
|
const preflight = await preflightRefAdvancement({
|
|
@@ -2389,7 +2405,7 @@ function updatePresentations(inputs) {
|
|
|
2389
2405
|
value: "dry run"
|
|
2390
2406
|
}] : []
|
|
2391
2407
|
]
|
|
2392
|
-
}, ...migrationResultBlocks(document, inputs.invocation, inputs.
|
|
2408
|
+
}, ...migrationResultBlocks(document, inputs.invocation, inputs.migrationPlan)],
|
|
2393
2409
|
json: () => document,
|
|
2394
2410
|
next: () => migrationResultNextActions(document, inputs.invocation, dbUpdateRerun(inputs.invocation, inputs.statements.map(statementFlag)))
|
|
2395
2411
|
};
|
|
@@ -2540,15 +2556,33 @@ function createDbUpdateCommand(createClient) {
|
|
|
2540
2556
|
text
|
|
2541
2557
|
})));
|
|
2542
2558
|
const cannotBeVariantConverts = fieldStatements.filter(({ verb, text }) => verb === "backfill" || text.split(".").length === 3);
|
|
2559
|
+
let destination;
|
|
2560
|
+
if (args.flags.to !== void 0) {
|
|
2561
|
+
const resolved = await resolveContractRefToSnapshot({
|
|
2562
|
+
config: ctx.config,
|
|
2563
|
+
migrationsDir: migrationsDirFor(ctx.config),
|
|
2564
|
+
refInput: args.flags.to,
|
|
2565
|
+
argument: "--to",
|
|
2566
|
+
fallbackToEmitted: false
|
|
2567
|
+
});
|
|
2568
|
+
if (!resolved.ok) return notOk$1(normalizeError(resolved.failure));
|
|
2569
|
+
destination = resolved.value;
|
|
2570
|
+
}
|
|
2543
2571
|
if (cannotBeVariantConverts.length > 0) {
|
|
2544
|
-
const
|
|
2572
|
+
const migrationPlan = await migrationPlanIfReachable({
|
|
2545
2573
|
config: ctx.config,
|
|
2546
2574
|
cwd: ctx.cwd,
|
|
2547
2575
|
db: args.flags.db,
|
|
2548
2576
|
commandName: "db update",
|
|
2549
2577
|
createClient
|
|
2550
|
-
});
|
|
2551
|
-
return notOk$1(normalizeError(errorStatementNeedsMigrationFile(given, cannotBeVariantConverts,
|
|
2578
|
+
}, destination);
|
|
2579
|
+
return notOk$1(normalizeError(errorStatementNeedsMigrationFile(given, cannotBeVariantConverts, {
|
|
2580
|
+
...cliInvocation(ctx, args.flags.db),
|
|
2581
|
+
rerunArgs: rerunFlags({
|
|
2582
|
+
...args.flags,
|
|
2583
|
+
noAdvanceRef: void 0
|
|
2584
|
+
})
|
|
2585
|
+
}, migrationPlan)));
|
|
2552
2586
|
}
|
|
2553
2587
|
const planned = [...ctx.statements.take("rename").map(({ text }) => ({
|
|
2554
2588
|
verb: "rename",
|
|
@@ -2561,18 +2595,6 @@ function createDbUpdateCommand(createClient) {
|
|
|
2561
2595
|
verb: "allow",
|
|
2562
2596
|
text
|
|
2563
2597
|
}))] : [];
|
|
2564
|
-
let destination;
|
|
2565
|
-
if (args.flags.to !== void 0) {
|
|
2566
|
-
const resolved = await resolveContractRefToSnapshot({
|
|
2567
|
-
config: ctx.config,
|
|
2568
|
-
migrationsDir: migrationsDirFor(ctx.config),
|
|
2569
|
-
refInput: args.flags.to,
|
|
2570
|
-
argument: "--to",
|
|
2571
|
-
fallbackToEmitted: false
|
|
2572
|
-
});
|
|
2573
|
-
if (!resolved.ok) return notOk$1(normalizeError(resolved.failure));
|
|
2574
|
-
destination = resolved.value;
|
|
2575
|
-
}
|
|
2576
2598
|
if (args.flags.permitPolicyChange === true && destination?.ref === void 0) return notOk$1(normalizeError(errorPermitPolicyChangeNeedsRef({
|
|
2577
2599
|
command: "db update",
|
|
2578
2600
|
to: args.flags.to
|
|
@@ -2585,7 +2607,10 @@ function createDbUpdateCommand(createClient) {
|
|
|
2585
2607
|
createClient,
|
|
2586
2608
|
retryCommand: () => retryCommandFor({
|
|
2587
2609
|
commandName: args.flags.dryRun ? "db update --dry-run" : "db update",
|
|
2588
|
-
rerunArgs: [...rerunFlags(
|
|
2610
|
+
rerunArgs: [...rerunFlags({
|
|
2611
|
+
...args.flags,
|
|
2612
|
+
noAdvanceRef: void 0
|
|
2613
|
+
}), ...[
|
|
2589
2614
|
...planned,
|
|
2590
2615
|
...previewConsents,
|
|
2591
2616
|
...unansweredConsents(ctx.statements)
|
|
@@ -2618,7 +2643,7 @@ function createDbUpdateCommand(createClient) {
|
|
|
2618
2643
|
}
|
|
2619
2644
|
const mode = args.flags.dryRun ? "plan" : "apply";
|
|
2620
2645
|
let document;
|
|
2621
|
-
let
|
|
2646
|
+
let migrationPlan;
|
|
2622
2647
|
try {
|
|
2623
2648
|
await client.connect(dbConnection);
|
|
2624
2649
|
const plannerWarnings = plannerWarningsCollector(ctx.report);
|
|
@@ -2637,9 +2662,13 @@ function createDbUpdateCommand(createClient) {
|
|
|
2637
2662
|
answerQuestions: promptPlanQuestions(ctx.prompt, ctx.statements),
|
|
2638
2663
|
invocation: {
|
|
2639
2664
|
...cliInvocation(ctx, args.flags.db),
|
|
2640
|
-
rerunArgs: rerunFlags(
|
|
2665
|
+
rerunArgs: rerunFlags({
|
|
2666
|
+
...args.flags,
|
|
2667
|
+
noAdvanceRef: void 0
|
|
2668
|
+
}),
|
|
2641
2669
|
statementArgs
|
|
2642
2670
|
},
|
|
2671
|
+
...ifDefined("emittedContractHash", storageHashOf(prepared.value.contractJson)),
|
|
2643
2672
|
onPlannerWarnings: plannerWarnings.onPlannerWarnings,
|
|
2644
2673
|
onProgress: controlProgressReporter(ctx.report)
|
|
2645
2674
|
});
|
|
@@ -2657,7 +2686,7 @@ function createDbUpdateCommand(createClient) {
|
|
|
2657
2686
|
hash: advancementHash
|
|
2658
2687
|
});
|
|
2659
2688
|
if (!advanced.ok) return notOk$1(normalizeError(advanced.failure));
|
|
2660
|
-
|
|
2689
|
+
migrationPlan = result.value.migrationPlan;
|
|
2661
2690
|
document = updateDocument({
|
|
2662
2691
|
value: result.value,
|
|
2663
2692
|
targetId: ctx.config.target.targetId,
|
|
@@ -2686,9 +2715,12 @@ function createDbUpdateCommand(createClient) {
|
|
|
2686
2715
|
document,
|
|
2687
2716
|
invocation: {
|
|
2688
2717
|
...cliInvocation(ctx, args.flags.db),
|
|
2689
|
-
rerunArgs: rerunFlags(
|
|
2718
|
+
rerunArgs: rerunFlags({
|
|
2719
|
+
...args.flags,
|
|
2720
|
+
noAdvanceRef: void 0
|
|
2721
|
+
})
|
|
2690
2722
|
},
|
|
2691
|
-
|
|
2723
|
+
migrationPlan,
|
|
2692
2724
|
contractPath: prepared.value.contractDisplayPath,
|
|
2693
2725
|
database: prepared.value.database,
|
|
2694
2726
|
to: args.flags.to,
|
|
@@ -2700,28 +2732,80 @@ function createDbUpdateCommand(createClient) {
|
|
|
2700
2732
|
}
|
|
2701
2733
|
const dbUpdateCommand = createDbUpdateCommand(createControlClient);
|
|
2702
2734
|
/**
|
|
2703
|
-
* The
|
|
2704
|
-
*
|
|
2705
|
-
*
|
|
2706
|
-
* never creates a database to read the marker.
|
|
2735
|
+
* The `migration plan` that takes the database where `db update` goes: to `destination`, the
|
|
2736
|
+
* contract `--to` named, or else the emitted contract. The migrations and refs are read offline;
|
|
2737
|
+
* when the database cannot be read, the user chooses where the plan starts, told why.
|
|
2707
2738
|
*/
|
|
2708
|
-
async function
|
|
2739
|
+
async function migrationPlanIfReachable(inputs, destination) {
|
|
2740
|
+
const end = destination === void 0 ? { kind: "emitted" } : destination.ref !== void 0 ? {
|
|
2741
|
+
kind: "ref",
|
|
2742
|
+
name: destination.ref.name
|
|
2743
|
+
} : {
|
|
2744
|
+
kind: "contract",
|
|
2745
|
+
hash: destination.hash
|
|
2746
|
+
};
|
|
2709
2747
|
const prepared = await prepareMigrationRun(inputs);
|
|
2710
|
-
if (!prepared.ok) return
|
|
2748
|
+
if (!prepared.ok) return {
|
|
2749
|
+
from: migrationPlanChoice(void 0, "The CLI could not prepare a connection to the database from the config"),
|
|
2750
|
+
to: migrationPlanTo(NO_MIGRATIONS, end)
|
|
2751
|
+
};
|
|
2711
2752
|
const { client, dbConnection, migrationsDir } = prepared.value;
|
|
2712
|
-
const
|
|
2753
|
+
const emittedHash = storageHashOf(prepared.value.contractJson);
|
|
2754
|
+
const space = await readPlanSpace(migrationsDir, emittedHash).catch(() => void 0);
|
|
2755
|
+
const readMarker = async () => {
|
|
2713
2756
|
await client.connect(dbConnection, {
|
|
2714
2757
|
existingDatabaseOnly: true,
|
|
2715
2758
|
connectTimeoutMs: MARKER_READ_TIMEOUT_MS
|
|
2716
2759
|
});
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2760
|
+
return {
|
|
2761
|
+
kind: "read",
|
|
2762
|
+
marker: await client.readMarker()
|
|
2763
|
+
};
|
|
2764
|
+
};
|
|
2765
|
+
const read = await settledWithin(readMarker().catch((error) => ({
|
|
2766
|
+
kind: "failed",
|
|
2767
|
+
cause: causeText(error)
|
|
2768
|
+
})).finally(() => closeQuietly(client)), MARKER_READ_TIMEOUT_MS);
|
|
2769
|
+
const position = read === void 0 ? {
|
|
2770
|
+
kind: "unknown",
|
|
2771
|
+
reason: `The CLI could not read the database within ${MARKER_READ_TIMEOUT_MS / 1e3} seconds to find the contract it is at`
|
|
2772
|
+
} : read.kind === "failed" ? {
|
|
2773
|
+
kind: "unknown",
|
|
2774
|
+
reason: `The CLI could not read the database: ${read.cause}`
|
|
2775
|
+
} : databasePositionOf(read.marker?.storageHash);
|
|
2776
|
+
if (space !== void 0) return read?.kind === "read" ? migrationPlanForDatabase(space, read.marker, end) : migrationPlanArguments(space, position, end);
|
|
2777
|
+
return {
|
|
2778
|
+
from: migrationPlanChoice(void 0, position.kind === "unknown" ? position.reason : "The CLI could not read the migrations"),
|
|
2779
|
+
to: migrationPlanTo({
|
|
2780
|
+
...NO_MIGRATIONS,
|
|
2781
|
+
...ifDefined("emittedHash", emittedHash)
|
|
2782
|
+
}, end)
|
|
2721
2783
|
};
|
|
2722
|
-
return settledWithin(read().catch(() => void 0).finally(() => closeQuietly(client)), MARKER_READ_TIMEOUT_MS);
|
|
2723
2784
|
}
|
|
2724
|
-
/**
|
|
2785
|
+
/** A space read as having no migrations and no refs, for when the migrations cannot be read. */
|
|
2786
|
+
const NO_MIGRATIONS = {
|
|
2787
|
+
graph: reconstructGraph([]),
|
|
2788
|
+
refs: {}
|
|
2789
|
+
};
|
|
2790
|
+
function storageHashOf(contractJson) {
|
|
2791
|
+
const storage = contractJson["storage"];
|
|
2792
|
+
if (typeof storage !== "object" || storage === null) return void 0;
|
|
2793
|
+
const hash = "storageHash" in storage ? storage.storageHash : void 0;
|
|
2794
|
+
return typeof hash === "string" ? hash : void 0;
|
|
2795
|
+
}
|
|
2796
|
+
function causeText(error) {
|
|
2797
|
+
return error instanceof Error ? error.message : String(error);
|
|
2798
|
+
}
|
|
2799
|
+
async function readPlanSpace(migrationsDir, emittedHash) {
|
|
2800
|
+
const appDir = spaceMigrationDirectory(migrationsDir, APP_SPACE_ID);
|
|
2801
|
+
const { packages } = await readMigrationsDir(appDir, { migrationsDir });
|
|
2802
|
+
return {
|
|
2803
|
+
graph: reconstructGraph(packages),
|
|
2804
|
+
refs: await readRefs(spaceRefsDirectory(appDir)),
|
|
2805
|
+
...ifDefined("emittedHash", emittedHash)
|
|
2806
|
+
};
|
|
2807
|
+
}
|
|
2808
|
+
/** How long the refusal waits for the database before it leaves the plan's origin to the user. */
|
|
2725
2809
|
const MARKER_READ_TIMEOUT_MS = 3e3;
|
|
2726
2810
|
function settledWithin(promise, ms) {
|
|
2727
2811
|
return new Promise((resolve) => {
|
|
@@ -7646,7 +7730,7 @@ const lspCommand = defineServerCommand({
|
|
|
7646
7730
|
} },
|
|
7647
7731
|
handler: async (args, io) => {
|
|
7648
7732
|
const exitCode = await withoutClientProcessIdInArgv(async () => {
|
|
7649
|
-
const { startServer } = await import("./exports-
|
|
7733
|
+
const { startServer } = await import("./exports-B0yFVod3.mjs");
|
|
7650
7734
|
return startServer({
|
|
7651
7735
|
stdin: io.stdin,
|
|
7652
7736
|
stdout: io.stdout,
|
|
@@ -9881,6 +9965,91 @@ function migrateShowRunListRows(migrations, rendering, options) {
|
|
|
9881
9965
|
function statusAction(invocation) {
|
|
9882
9966
|
return runCommandAction("Check every space against the database", cliCommand(invocation, "migration status"));
|
|
9883
9967
|
}
|
|
9968
|
+
const DEFAULT_ADVANCE_REF = "db";
|
|
9969
|
+
/**
|
|
9970
|
+
* Which ref a run advances: `db` when the connection comes from the config outside CI, the named
|
|
9971
|
+
* ref in every case, nothing under `--db` or `--no-advance-ref`. A named ref that could never be
|
|
9972
|
+
* written, because its name is invalid or the target is the empty contract, is refused; `db` is
|
|
9973
|
+
* left where it is.
|
|
9974
|
+
*/
|
|
9975
|
+
function refAdvancementDecision(flags, inCI, targetHash) {
|
|
9976
|
+
const toEmpty = targetHash === EMPTY_CONTRACT_HASH;
|
|
9977
|
+
if (flags.noAdvanceRef === true || flags.advanceRef === void 0 && flags.db !== void 0) return {
|
|
9978
|
+
kind: "none",
|
|
9979
|
+
reason: "flag"
|
|
9980
|
+
};
|
|
9981
|
+
if (flags.advanceRef !== void 0) {
|
|
9982
|
+
if (!validateRefName(flags.advanceRef)) return {
|
|
9983
|
+
kind: "refuse-invalid-name",
|
|
9984
|
+
name: flags.advanceRef
|
|
9985
|
+
};
|
|
9986
|
+
return toEmpty ? {
|
|
9987
|
+
kind: "refuse-empty-target",
|
|
9988
|
+
name: flags.advanceRef
|
|
9989
|
+
} : {
|
|
9990
|
+
kind: "advance",
|
|
9991
|
+
name: flags.advanceRef
|
|
9992
|
+
};
|
|
9993
|
+
}
|
|
9994
|
+
if (toEmpty) return {
|
|
9995
|
+
kind: "none",
|
|
9996
|
+
reason: "empty-target"
|
|
9997
|
+
};
|
|
9998
|
+
return inCI ? {
|
|
9999
|
+
kind: "none",
|
|
10000
|
+
reason: "ci"
|
|
10001
|
+
} : {
|
|
10002
|
+
kind: "advance",
|
|
10003
|
+
name: DEFAULT_ADVANCE_REF
|
|
10004
|
+
};
|
|
10005
|
+
}
|
|
10006
|
+
/**
|
|
10007
|
+
* The command that writes the ref later. `migration ref set` needs the snapshot in the store, so
|
|
10008
|
+
* without it the advice is the same `db migrate` again, which writes both.
|
|
10009
|
+
*/
|
|
10010
|
+
function refNotWrittenDiagnostic(ref, failure, invocation, rerunWithRef) {
|
|
10011
|
+
const rerun = cliCommand(invocation, "db migrate", rerunWithRef);
|
|
10012
|
+
const nextAction = {
|
|
10013
|
+
pointer: runCommandAction(`Point ref "${ref.name}" at the contract the database is at`, cliCommand(invocation, "migration ref set", [shellQuoted(ref.name), ref.hash])),
|
|
10014
|
+
snapshot: runCommandAction(`Write ref "${ref.name}" and its snapshot once the directory is writable`, rerun),
|
|
10015
|
+
"store-check": chooseAction(`Repair the snapshot store entry for ${ref.hash}, which could not be read, then run \`${rerun}\``)
|
|
10016
|
+
}[failure.failedAt];
|
|
10017
|
+
return {
|
|
10018
|
+
code: "MIGRATION.REF_NOT_WRITTEN",
|
|
10019
|
+
severity: "warn",
|
|
10020
|
+
summary: `Migrations applied, but ref "${ref.name}" was not written`,
|
|
10021
|
+
why: `The database is at contract ${ref.hash}, and ref "${ref.name}" could not be moved there: ${failure.reason}`,
|
|
10022
|
+
nextActions: [nextAction],
|
|
10023
|
+
meta: {
|
|
10024
|
+
name: ref.name,
|
|
10025
|
+
hash: ref.hash,
|
|
10026
|
+
reason: failure.reason,
|
|
10027
|
+
...ifDefined("causeCode", failure.causeCode)
|
|
10028
|
+
}
|
|
10029
|
+
};
|
|
10030
|
+
}
|
|
10031
|
+
function refNotAdvancedInCIDiagnostic(invocation, rerunWithRef) {
|
|
10032
|
+
return {
|
|
10033
|
+
code: "MIGRATION.REF_NOT_ADVANCED_IN_CI",
|
|
10034
|
+
severity: "info",
|
|
10035
|
+
summary: `Ref "${DEFAULT_ADVANCE_REF}" was not advanced: the CLI detected CI`,
|
|
10036
|
+
why: "db migrate advances the db ref only outside CI. Unless the CI variable is false, which turns detection off whatever else is set, the CLI detects CI when CI is set or when a variable that CI services set is present, such as BUILD_NUMBER, BUILD_ID or GITHUB_ACTIONS. In a pipeline this is expected, and --no-advance-ref silences this notice. If this is your development machine, a variable in your shell or in a .env file that prisma.config.ts loads turned advancement off.",
|
|
10037
|
+
nextActions: [
|
|
10038
|
+
chooseAction("If this is your development machine and not CI: unset the variable that made the CLI detect CI, or set CI=false, so later runs advance the db ref"),
|
|
10039
|
+
runCommandAction(`If this is your development machine and not CI: advance ref "${DEFAULT_ADVANCE_REF}" now`, cliCommand(invocation, "db migrate", rerunWithRef)),
|
|
10040
|
+
chooseAction("In a pipeline: pass --no-advance-ref to silence this notice")
|
|
10041
|
+
]
|
|
10042
|
+
};
|
|
10043
|
+
}
|
|
10044
|
+
function refNotAdvancedToEmptyDiagnostic(invocation, refHash) {
|
|
10045
|
+
return {
|
|
10046
|
+
code: "MIGRATION.REF_NOT_ADVANCED_TO_EMPTY",
|
|
10047
|
+
severity: "warn",
|
|
10048
|
+
summary: `Ref "${DEFAULT_ADVANCE_REF}" still names ${refHash}, but the database is now at the empty contract`,
|
|
10049
|
+
why: `The empty contract is where the planner starts, not a contract a ref can name, so db migrate neither moved ref "${DEFAULT_ADVANCE_REF}" nor deleted it. The next migration plan starts from the contract the ref names.`,
|
|
10050
|
+
nextActions: [runCommandAction(`If this is your development database: remove ref "${DEFAULT_ADVANCE_REF}", so the next migration plan asks where to start`, cliCommand(invocation, "migration ref delete", [DEFAULT_ADVANCE_REF]))]
|
|
10051
|
+
};
|
|
10052
|
+
}
|
|
9884
10053
|
function fromField(from) {
|
|
9885
10054
|
return from === "empty" ? void 0 : from;
|
|
9886
10055
|
}
|
|
@@ -10043,14 +10212,15 @@ function liveMarkerTarget(appMarker) {
|
|
|
10043
10212
|
refName: void 0
|
|
10044
10213
|
};
|
|
10045
10214
|
}
|
|
10046
|
-
function createMigrateCommand(createClient) {
|
|
10215
|
+
function createMigrateCommand(createClient, writeRefPointer = advanceRef) {
|
|
10047
10216
|
return defineOrmCommand({
|
|
10048
10217
|
help: {
|
|
10049
10218
|
summary: "Apply planned migrations to advance the database",
|
|
10050
|
-
description: "Walks every contract space (app + extensions) and applies pending on-disk\nmigrations in canonical order (extensions alphabetically, then app). It\nreplays the on-disk migration graph and never invents an edge. Use --to to\ntarget a specific contract and --show for a read-only preview of the route\nit would take.",
|
|
10219
|
+
description: "Walks every contract space (app + extensions) and applies pending on-disk\nmigrations in canonical order (extensions alphabetically, then app). It\nreplays the on-disk migration graph and never invents an edge. Use --to to\ntarget a specific contract and --show for a read-only preview of the route\nit would take.\nAfter a successful apply it advances the db ref to the database's new\ncontract, so the next migration plan starts there. It does so only when\nthe connection comes from prisma.config.ts and the CLI does not detect CI:\nnever with --db, and never in CI. Unless CI=false, which wins over\neverything else, the CLI detects CI when CI is set or when a variable that\nCI services set is present, such as BUILD_NUMBER or GITHUB_ACTIONS; it then\nsays so.\n--advance-ref <name> advances that ref instead, also with --db and in CI;\n--no-advance-ref advances none. No ref advances to the empty contract. A ref\nthat cannot be written is a warning: the migrations have already applied.",
|
|
10051
10220
|
examples: [
|
|
10052
10221
|
"db migrate",
|
|
10053
10222
|
"db migrate --db $DATABASE_URL",
|
|
10223
|
+
"db migrate --no-advance-ref",
|
|
10054
10224
|
"db migrate --to production",
|
|
10055
10225
|
"db migrate --show",
|
|
10056
10226
|
"db migrate --show --from @contract --to production"
|
|
@@ -10063,9 +10233,10 @@ function createMigrateCommand(createClient) {
|
|
|
10063
10233
|
placeholder: "contract"
|
|
10064
10234
|
}),
|
|
10065
10235
|
advanceRef: flag.string({
|
|
10066
|
-
brief: "Advance the named ref to the post-apply marker after success",
|
|
10236
|
+
brief: "Advance the named ref, instead of db, to the post-apply marker after success",
|
|
10067
10237
|
placeholder: "name"
|
|
10068
10238
|
}),
|
|
10239
|
+
noAdvanceRef: flag.boolean({ brief: "Apply without advancing any ref (no ref file or snapshot is written)" }),
|
|
10069
10240
|
show: flag.boolean({ brief: "Preview the migration route without applying (read-only)" }),
|
|
10070
10241
|
permitPolicyChange: permitPolicyChangeFlag,
|
|
10071
10242
|
from: flag.string({
|
|
@@ -10075,6 +10246,7 @@ function createMigrateCommand(createClient) {
|
|
|
10075
10246
|
} },
|
|
10076
10247
|
needs: { config: ormConfigSection },
|
|
10077
10248
|
handler: async (args, ctx) => {
|
|
10249
|
+
if (args.flags.noAdvanceRef && args.flags.advanceRef !== void 0) return notOk$1(normalizeError(errorAdvanceRefArgConflict({ advanceRef: args.flags.advanceRef })));
|
|
10078
10250
|
const migrationsRelative = displayPath(migrationsDirFor(ctx.config), ctx.cwd);
|
|
10079
10251
|
if (args.flags.show) {
|
|
10080
10252
|
const planned = await executeMigrateShowPlan({
|
|
@@ -10167,6 +10339,7 @@ function createMigrateCommand(createClient) {
|
|
|
10167
10339
|
to: args.flags.to
|
|
10168
10340
|
})));
|
|
10169
10341
|
let document;
|
|
10342
|
+
const diagnostics = [];
|
|
10170
10343
|
try {
|
|
10171
10344
|
await client.connect(dbConnection);
|
|
10172
10345
|
const appGraph = aggregate.app.graph();
|
|
@@ -10216,10 +10389,27 @@ function createMigrateCommand(createClient) {
|
|
|
10216
10389
|
throw error;
|
|
10217
10390
|
}
|
|
10218
10391
|
}
|
|
10392
|
+
const targetHash = refEntry?.hash ?? appContract.storage.storageHash;
|
|
10393
|
+
const decision = refAdvancementDecision(args.flags, ctx.isCI, targetHash);
|
|
10394
|
+
const rerunWith = (refFlags) => rerunFlags({
|
|
10395
|
+
...args.flags,
|
|
10396
|
+
advanceRef: void 0,
|
|
10397
|
+
noAdvanceRef: void 0,
|
|
10398
|
+
...refFlags
|
|
10399
|
+
});
|
|
10400
|
+
if (decision.kind === "refuse-invalid-name") return notOk$1(normalizeError(errorInvalidRefName(decision.name)));
|
|
10401
|
+
if (decision.kind === "refuse-empty-target") return notOk$1(normalizeError(errorRefTargetEmpty({
|
|
10402
|
+
name: decision.name,
|
|
10403
|
+
rerunWithoutRef: cliCommand(cliInvocation(ctx, args.flags.db), "db migrate", rerunWith({ noAdvanceRef: true }))
|
|
10404
|
+
})));
|
|
10219
10405
|
let advancement = null;
|
|
10220
|
-
if (
|
|
10406
|
+
if (decision.kind === "advance") if (await hasContractSnapshot(migrationsDir, targetHash)) advancement = {
|
|
10407
|
+
name: decision.name,
|
|
10408
|
+
snapshot: { kind: "stored" }
|
|
10409
|
+
};
|
|
10410
|
+
else {
|
|
10221
10411
|
const preflight = await preflightRefAdvancement({
|
|
10222
|
-
name:
|
|
10412
|
+
name: decision.name,
|
|
10223
10413
|
contractJson: snapshotContractJson,
|
|
10224
10414
|
contractJsonPath: snapshotContractPath,
|
|
10225
10415
|
config: ctx.config,
|
|
@@ -10227,8 +10417,11 @@ function createMigrateCommand(createClient) {
|
|
|
10227
10417
|
});
|
|
10228
10418
|
if (!preflight.ok) return notOk$1(normalizeError(preflight.failure));
|
|
10229
10419
|
advancement = {
|
|
10230
|
-
name:
|
|
10231
|
-
|
|
10420
|
+
name: decision.name,
|
|
10421
|
+
snapshot: {
|
|
10422
|
+
kind: "render",
|
|
10423
|
+
contractIR: preflight.value
|
|
10424
|
+
}
|
|
10232
10425
|
};
|
|
10233
10426
|
}
|
|
10234
10427
|
const applied = await client.migrate({
|
|
@@ -10236,7 +10429,8 @@ function createMigrateCommand(createClient) {
|
|
|
10236
10429
|
migrationsDir,
|
|
10237
10430
|
invocation: {
|
|
10238
10431
|
...cliInvocation(ctx, args.flags.db),
|
|
10239
|
-
rerunArgs: rerunFlags(args.flags)
|
|
10432
|
+
rerunArgs: rerunFlags(args.flags),
|
|
10433
|
+
...ifDefined("targetRef", target.refName)
|
|
10240
10434
|
},
|
|
10241
10435
|
onProgress: controlProgressReporter(ctx.report),
|
|
10242
10436
|
...ifDefined("target", migrateTargetOf(target)),
|
|
@@ -10245,20 +10439,24 @@ function createMigrateCommand(createClient) {
|
|
|
10245
10439
|
if (!applied.ok) return notOk$1(normalizeError(applied.failure));
|
|
10246
10440
|
const { value } = applied;
|
|
10247
10441
|
let advancedRef = null;
|
|
10442
|
+
const invocation = cliInvocation(ctx, args.flags.db);
|
|
10248
10443
|
if (advancement !== null) {
|
|
10249
|
-
const
|
|
10250
|
-
refsDir,
|
|
10251
|
-
migrationsDir,
|
|
10444
|
+
const ref = {
|
|
10252
10445
|
name: advancement.name,
|
|
10253
|
-
hash: value.markerHash
|
|
10254
|
-
contractIR: advancement.contractIR
|
|
10255
|
-
});
|
|
10256
|
-
if (!advanced.ok) return notOk$1(normalizeError(advanced.failure));
|
|
10257
|
-
advancedRef = {
|
|
10258
|
-
name: advanced.value.name,
|
|
10259
|
-
hash: advanced.value.hash
|
|
10446
|
+
hash: value.markerHash
|
|
10260
10447
|
};
|
|
10448
|
+
const written = await writeAdvancedRef({
|
|
10449
|
+
refsDir,
|
|
10450
|
+
migrationsDir,
|
|
10451
|
+
...ref,
|
|
10452
|
+
snapshot: advancement.snapshot
|
|
10453
|
+
}, writeRefPointer);
|
|
10454
|
+
if (written.ok) advancedRef = ref;
|
|
10455
|
+
else diagnostics.push(refNotWrittenDiagnostic(ref, written.failure, invocation, rerunWith({ advanceRef: ref.name })));
|
|
10261
10456
|
}
|
|
10457
|
+
if (decision.kind === "none" && decision.reason === "ci") diagnostics.push(refNotAdvancedInCIDiagnostic(invocation, rerunWith({ advanceRef: DEFAULT_ADVANCE_REF })));
|
|
10458
|
+
const staleDbRef = aggregate.app.refs[DEFAULT_ADVANCE_REF];
|
|
10459
|
+
if (decision.kind === "none" && decision.reason === "empty-target" && staleDbRef !== void 0) diagnostics.push(refNotAdvancedToEmptyDiagnostic(invocation, staleDbRef.hash));
|
|
10262
10460
|
document = {
|
|
10263
10461
|
ok: true,
|
|
10264
10462
|
migrationsApplied: value.migrationsApplied,
|
|
@@ -10282,7 +10480,10 @@ function createMigrateCommand(createClient) {
|
|
|
10282
10480
|
severity: "verbose",
|
|
10283
10481
|
text: `Total time: ${document.timings.total}ms`
|
|
10284
10482
|
});
|
|
10285
|
-
return ok$1(ctx.present({
|
|
10483
|
+
return ok$1(ctx.present({
|
|
10484
|
+
data: document,
|
|
10485
|
+
...diagnostics.length === 0 ? {} : { diagnostics }
|
|
10486
|
+
}, applyPresentations({
|
|
10286
10487
|
document,
|
|
10287
10488
|
migrationsDir: migrationsRelative,
|
|
10288
10489
|
database: prepared.value.database,
|
|
@@ -11061,6 +11262,7 @@ function createMigrationNewCommand(createClient) {
|
|
|
11061
11262
|
const scaffolded = await executeMigrationNewCommand({
|
|
11062
11263
|
config: ctx.config,
|
|
11063
11264
|
cwd: ctx.cwd,
|
|
11265
|
+
...ifDefined("configPath", ctx.configPath),
|
|
11064
11266
|
...ifDefined("name", args.flags.name),
|
|
11065
11267
|
...ifDefined("from", args.flags.from),
|
|
11066
11268
|
client: createClient({
|
|
@@ -11793,13 +11995,41 @@ function describeOrigin(origin) {
|
|
|
11793
11995
|
if (origin.kind === "offline") return `the --from contract (${shortDisplayHash(origin.hash)})`;
|
|
11794
11996
|
return origin.marker !== void 0 ? `the database state (${shortDisplayHash(origin.marker.storageHash)})` : "the database state";
|
|
11795
11997
|
}
|
|
11998
|
+
/** Where `migration status` aims, as `migration plan` would end there: a ref, or a contract by its hash. */
|
|
11999
|
+
function statusPlanEnd(refName, targetHash) {
|
|
12000
|
+
return refName === void 0 ? {
|
|
12001
|
+
kind: "contract",
|
|
12002
|
+
hash: targetHash
|
|
12003
|
+
} : {
|
|
12004
|
+
kind: "ref",
|
|
12005
|
+
name: refName
|
|
12006
|
+
};
|
|
12007
|
+
}
|
|
12008
|
+
/** The summary with no migrations: the `migration plan` that writes the first, or why none can. */
|
|
12009
|
+
function firstPlanText(plan) {
|
|
12010
|
+
if (plan === void 0) return "No migrations found";
|
|
12011
|
+
switch (plan.kind) {
|
|
12012
|
+
case "runs": return `No migrations found. Run \`${plan.command}\` to author the first.`;
|
|
12013
|
+
case "fill": return `No migrations found. Run \`${plan.command}\` to author the first. ${plan.fill}.`;
|
|
12014
|
+
case "none": return `No migrations found, and no migration plan can author the first. ${plan.reason}.`;
|
|
12015
|
+
}
|
|
12016
|
+
}
|
|
12017
|
+
/** How the summary says to author the missing path, or why no `migration plan` can. */
|
|
12018
|
+
function authorText(target) {
|
|
12019
|
+
const { plan } = target;
|
|
12020
|
+
switch (plan.kind) {
|
|
12021
|
+
case "runs": return `Run \`${plan.command}\` to author one`;
|
|
12022
|
+
case "fill": return `Run \`${plan.command}\` to author one. ${plan.fill}`;
|
|
12023
|
+
case "none": return `No migration plan can author one. ${plan.reason}. Inspect the graph with \`${target.listCommand}\``;
|
|
12024
|
+
}
|
|
12025
|
+
}
|
|
11796
12026
|
function buildNoPathSummary(args) {
|
|
11797
12027
|
const markerPart = describeOrigin(args.origin);
|
|
11798
12028
|
const targetShort = shortDisplayHash(args.targetHash);
|
|
11799
12029
|
const { target } = args;
|
|
11800
12030
|
if (target.kind === "extension") return `No migration path from ${markerPart} to the head of extension space \`${target.spaceId}\` (${targetShort}).`;
|
|
11801
|
-
if (!target.explicitTarget) return `No migration path from ${markerPart} to the application's contract (${targetShort}).
|
|
11802
|
-
return `No migration path from ${markerPart} to ${target.refName !== void 0 ? `the target (${targetShort} via \`${target.refName}\`)` : `the target (${targetShort})`}.
|
|
12031
|
+
if (!target.explicitTarget) return `No migration path from ${markerPart} to the application's contract (${targetShort}). ${authorText(target)}.`;
|
|
12032
|
+
return `No migration path from ${markerPart} to ${target.refName !== void 0 ? `the target (${targetShort} via \`${target.refName}\`)` : `the target (${targetShort})`}. ${authorText(target)}, or pass \`--to <contract>\` to pick a reachable target.`;
|
|
11803
12033
|
}
|
|
11804
12034
|
function buildStatusHeadline(args) {
|
|
11805
12035
|
if (args.markerDiverged && args.markerHash !== void 0) return `Database marker ${shortDisplayHash(args.markerHash)} is not in the on-disk migration graph`;
|
|
@@ -11959,6 +12189,7 @@ const migrationStatusCommand = defineOrmCommand({
|
|
|
11959
12189
|
if (corruption) return notOk$1(normalizeError(corruption));
|
|
11960
12190
|
}
|
|
11961
12191
|
const appGraph = aggregate.app.graph();
|
|
12192
|
+
const invocation = cliInvocation(ctx, void 0);
|
|
11962
12193
|
const refContext = {
|
|
11963
12194
|
graph: appGraph,
|
|
11964
12195
|
refs,
|
|
@@ -12020,6 +12251,7 @@ const migrationStatusCommand = defineOrmCommand({
|
|
|
12020
12251
|
const emptySpaces = [];
|
|
12021
12252
|
let divergedMarker;
|
|
12022
12253
|
let noPath;
|
|
12254
|
+
let firstPlan;
|
|
12023
12255
|
let headlineTargetHash = activeRefHash ?? contractHash;
|
|
12024
12256
|
let totalPending = 0;
|
|
12025
12257
|
let reportedUnreadablePolicies = false;
|
|
@@ -12040,6 +12272,11 @@ const migrationStatusCommand = defineOrmCommand({
|
|
|
12040
12272
|
const space = aggregate.space(entry.space);
|
|
12041
12273
|
if (space === void 0) continue;
|
|
12042
12274
|
const graph = space.graph();
|
|
12275
|
+
const planSpace = {
|
|
12276
|
+
graph,
|
|
12277
|
+
refs: space.refs,
|
|
12278
|
+
emittedHash: contractHash
|
|
12279
|
+
};
|
|
12043
12280
|
const spaceContractHash = space.contract().storage.storageHash;
|
|
12044
12281
|
const isAppSpace = entry.space === aggregate.app.spaceId;
|
|
12045
12282
|
const targetHash = isAppSpace ? activeRefHash ?? spaceContractHash : spaceContractHash;
|
|
@@ -12052,6 +12289,11 @@ const migrationStatusCommand = defineOrmCommand({
|
|
|
12052
12289
|
hash: fromOverrideHash
|
|
12053
12290
|
} : void 0;
|
|
12054
12291
|
const originHash = originHashOf(origin);
|
|
12292
|
+
const appPlan = () => printedPlan(invocation, migrationPlanArguments(planSpace, origin === void 0 ? {
|
|
12293
|
+
kind: "unknown",
|
|
12294
|
+
reason: "migration status read no database to find where it is"
|
|
12295
|
+
} : databasePositionOf(origin.kind === "offline" ? origin.hash : origin.marker?.storageHash), statusPlanEnd(activeRefName, targetHash)), ["--name", "<name>"]);
|
|
12296
|
+
if (isAppSpace && originHash !== targetHash && graph.nodes.size === 0) firstPlan = appPlan();
|
|
12055
12297
|
const markerRead = origin?.kind === "database" || isAppSpace && liveTarget;
|
|
12056
12298
|
const readMarker = origin?.kind === "database" ? origin.marker : markerRead ? appMarker : void 0;
|
|
12057
12299
|
const markerDiverged = readMarker !== void 0 && !isInSpaceHistory(readMarker.storageHash, {
|
|
@@ -12071,7 +12313,9 @@ const migrationStatusCommand = defineOrmCommand({
|
|
|
12071
12313
|
target: isAppSpace ? {
|
|
12072
12314
|
kind: "app",
|
|
12073
12315
|
explicitTarget: to !== void 0,
|
|
12074
|
-
refName: activeRefName
|
|
12316
|
+
refName: activeRefName,
|
|
12317
|
+
plan: appPlan(),
|
|
12318
|
+
listCommand: cliCommand(invocation, "migration list")
|
|
12075
12319
|
} : {
|
|
12076
12320
|
kind: "extension",
|
|
12077
12321
|
spaceId: entry.space
|
|
@@ -12149,7 +12393,7 @@ const migrationStatusCommand = defineOrmCommand({
|
|
|
12149
12393
|
showHeading: showSpaceHeadings
|
|
12150
12394
|
};
|
|
12151
12395
|
});
|
|
12152
|
-
const pathSummary = scopedSpaces.every((entry) => entry.migrations.length === 0) ?
|
|
12396
|
+
const pathSummary = scopedSpaces.every((entry) => entry.migrations.length === 0) ? firstPlanText(firstPlan) : noPath !== void 0 ? buildNoPathSummary(noPath) : buildStatusHeadline({
|
|
12153
12397
|
pendingCount: totalPending,
|
|
12154
12398
|
targetHash: headlineTargetHash,
|
|
12155
12399
|
refName: activeRefName,
|
|
@@ -12442,10 +12686,10 @@ const ormCommandFamily = defineCommandFamily({
|
|
|
12442
12686
|
v7Command("migrate dev", {
|
|
12443
12687
|
replacement: [
|
|
12444
12688
|
"{bin} contract emit",
|
|
12445
|
-
"{bin} migration
|
|
12446
|
-
"{bin} db migrate
|
|
12689
|
+
"{bin} migration status",
|
|
12690
|
+
"{bin} db migrate"
|
|
12447
12691
|
],
|
|
12448
|
-
reason: "Prisma 8 emits the contract, plans the migration and applies it in separate steps: run `contract emit`, then `migration plan
|
|
12692
|
+
reason: "Prisma 8 emits the contract, plans the migration and applies it in separate steps: run `contract emit`, then `migration status`, which prints the `migration plan` that plans it from where the database is, and run that plan, fill in any placeholders it leaves and run the `node` command it prints (for `--create-only`, stop here), then `db migrate`. When migrations on disk already lead to the new contract, `migration status` prints no plan, and `db migrate` applies them.",
|
|
12449
12693
|
whileMigrationsStayOnPrisma7: true,
|
|
12450
12694
|
help: "contract emit"
|
|
12451
12695
|
}),
|
|
@@ -12587,17 +12831,9 @@ const runPackageManager = (request) => new Promise((resolve) => {
|
|
|
12587
12831
|
child.on("close", (code) => settle(code ?? LAUNCH_FAILURE_EXIT_CODE));
|
|
12588
12832
|
});
|
|
12589
12833
|
/**
|
|
12590
|
-
*
|
|
12591
|
-
*
|
|
12592
|
-
*
|
|
12593
|
-
* this helper, so neither path drifts from the other when a new CI provider
|
|
12594
|
-
* is added upstream.
|
|
12595
|
-
*
|
|
12596
|
-
* `ci-info` checks the standard `CI=true` marker plus dozens of
|
|
12597
|
-
* provider-specific environment variables (Buildkite, Jenkins, Drone,
|
|
12598
|
-
* Bitbucket Pipelines, Azure Pipelines, AWS CodeBuild, …) that the raw
|
|
12599
|
-
* `process.env.CI` read misses.
|
|
12600
|
-
*
|
|
12834
|
+
* Whether `process.env` is a CI environment by `ci-info`'s rules. Telemetry reads this. Command
|
|
12835
|
+
* handlers read the CLI engine's `ctx.isCI` instead, which applies the same rules to the
|
|
12836
|
+
* environment the engine was given, so a test can set it.
|
|
12601
12837
|
*/
|
|
12602
12838
|
function isCI$1() {
|
|
12603
12839
|
return isCI;
|