@prisma/orm-toolchain 8.0.0-rc.24-dev.23 → 8.0.0-rc.24-dev.25
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-BmhAhXYL.d.mts → aggregate-C6PGBKyb.d.mts} +7 -3
- package/dist/aggregate-C6PGBKyb.d.mts.map +1 -0
- package/dist/{aggregate-BIjV2dM9.mjs → aggregate-CRIdmKmq.mjs} +12 -8
- package/dist/aggregate-CRIdmKmq.mjs.map +1 -0
- package/dist/{caught-errors-Cll-zcA1-MXR0HE1V.mjs → caught-errors-I1l50iPc-D_-F2M3t.mjs} +21 -5
- package/dist/caught-errors-I1l50iPc-D_-F2M3t.mjs.map +1 -0
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +212 -176
- package/dist/cli.mjs.map +1 -1
- package/dist/cli__control-api.d.mts +17 -5
- 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 +3 -3
- package/dist/cli__migration-cli.mjs.map +1 -1
- package/dist/{contract-snapshot-store-nWnsWPPQ-rJ94UCcE.mjs → contract-snapshot-store-B0fRbVHB-BN2g8BKh.mjs} +3 -3
- package/dist/{contract-snapshot-store-nWnsWPPQ-rJ94UCcE.mjs.map → contract-snapshot-store-B0fRbVHB-BN2g8BKh.mjs.map} +1 -1
- package/dist/{db-sign-DGSaPRQ--B_9CmDng.d.mts → db-sign-Bv-FZMAD-uQhMNCC7.d.mts} +42 -26
- package/dist/db-sign-Bv-FZMAD-uQhMNCC7.d.mts.map +1 -0
- package/dist/{errors-DXha_4l--relAaiI4.mjs → errors-BMq40nYH-Cg8PBect.mjs} +33 -4
- package/dist/errors-BMq40nYH-Cg8PBect.mjs.map +1 -0
- package/dist/{errors-CLwhWJiz.d.mts → errors-oP9FaWWm.d.mts} +5 -2
- package/dist/errors-oP9FaWWm.d.mts.map +1 -0
- package/dist/{graph-membership-DxpNgxfZ-BfqA-H7V.mjs → graph-membership-D7m41lWA-B68g1CRS.mjs} +3 -3
- package/dist/{graph-membership-DxpNgxfZ-BfqA-H7V.mjs.map → graph-membership-D7m41lWA-B68g1CRS.mjs.map} +1 -1
- package/dist/{invariants-DrF9p5Gd-BF70vGl1.mjs → invariants-DxCj82g2-DhGkStla.mjs} +3 -3
- package/dist/{invariants-DrF9p5Gd-BF70vGl1.mjs.map → invariants-DxCj82g2-DhGkStla.mjs.map} +1 -1
- package/dist/{io-4O31S6Ei-DvsFKW_Y.mjs → io-B39zsxMm-D5Wcf6cf.mjs} +5 -5
- package/dist/{io-4O31S6Ei-DvsFKW_Y.mjs.map → io-B39zsxMm-D5Wcf6cf.mjs.map} +1 -1
- package/dist/{migration-CWyjX9vz.mjs → migration-DTmtOJ0n.mjs} +3 -3
- package/dist/{migration-CWyjX9vz.mjs.map → migration-DTmtOJ0n.mjs.map} +1 -1
- package/dist/migration-tools.d.mts +6 -5
- package/dist/migration-tools.mjs +12 -12
- package/dist/migration-tools__aggregate.d.mts +1 -1
- package/dist/migration-tools__aggregate.mjs +1 -1
- package/dist/migration-tools__contract-snapshot-store.mjs +1 -1
- package/dist/migration-tools__errors.d.mts +2 -2
- package/dist/migration-tools__errors.mjs +2 -2
- package/dist/migration-tools__invariants.mjs +1 -1
- package/dist/migration-tools__io.mjs +1 -1
- package/dist/migration-tools__migration-graph.mjs +1 -1
- package/dist/migration-tools__migration.mjs +1 -1
- package/dist/migration-tools__ref-resolution.d.mts +1 -1
- package/dist/migration-tools__ref-resolution.mjs +1 -1
- package/dist/migration-tools__refs.d.mts +3 -2
- package/dist/migration-tools__refs.mjs +2 -2
- package/dist/migration-tools__spaces.mjs +2 -2
- package/dist/quick-reference-mongo.md +0 -1
- package/dist/quick-reference-postgres.md +0 -1
- package/dist/{ref-D4GWEHQU-BOqb4i_E.mjs → ref-DfuqRCA7-CPPoVHY9.mjs} +459 -101
- package/dist/ref-DfuqRCA7-CPPoVHY9.mjs.map +1 -0
- package/dist/{ref-resolution-Eo0QHp4f.mjs → ref-resolution-C9j2SSb6.mjs} +2 -2
- package/dist/{ref-resolution-Eo0QHp4f.mjs.map → ref-resolution-C9j2SSb6.mjs.map} +1 -1
- package/dist/{ref-resolution-BPhR-kta.d.mts → ref-resolution-UwnXbc9M.d.mts} +2 -2
- package/dist/{ref-resolution-BPhR-kta.d.mts.map → ref-resolution-UwnXbc9M.d.mts.map} +1 -1
- package/dist/refs-B5N_vHH7.d.mts +1 -0
- package/dist/{refs-BNCUu58Y-BIso5Jfg.d.mts → refs-CkGjbosE-CLkrSkQ4.d.mts} +18 -3
- package/dist/refs-CkGjbosE-CLkrSkQ4.d.mts.map +1 -0
- package/dist/{refs-DM3q3IZC-BC6H6P0X.mjs → refs-t_JbIjGo-CRpBRRkq.mjs} +79 -20
- package/dist/refs-t_JbIjGo-CRpBRRkq.mjs.map +1 -0
- package/dist/{spaces-BIABdklg.mjs → spaces-OVZ0QzWJ.mjs} +5 -5
- package/dist/{spaces-BIABdklg.mjs.map → spaces-OVZ0QzWJ.mjs.map} +1 -1
- package/dist/{verify-contract-spaces-BmnQiKDj-JwT2fAPh.mjs → verify-contract-spaces-BOnqhfQs-BBq5YOKo.mjs} +11 -7
- package/dist/verify-contract-spaces-BOnqhfQs-BBq5YOKo.mjs.map +1 -0
- package/dist/vite-plugin-contract-emit.mjs +1 -1
- package/package.json +12 -12
- package/dist/aggregate-BIjV2dM9.mjs.map +0 -1
- package/dist/aggregate-BmhAhXYL.d.mts.map +0 -1
- package/dist/caught-errors-Cll-zcA1-MXR0HE1V.mjs.map +0 -1
- package/dist/db-sign-DGSaPRQ--B_9CmDng.d.mts.map +0 -1
- package/dist/errors-CLwhWJiz.d.mts.map +0 -1
- package/dist/errors-DXha_4l--relAaiI4.mjs.map +0 -1
- package/dist/ref-D4GWEHQU-BOqb4i_E.mjs.map +0 -1
- package/dist/refs-BNCUu58Y-BIso5Jfg.d.mts.map +0 -1
- package/dist/refs-DM3q3IZC-BC6H6P0X.mjs.map +0 -1
- package/dist/verify-contract-spaces-BmnQiKDj-JwT2fAPh.mjs.map +0 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
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-CSVHjfwG.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 { t as contractSnapshotDir } from "./contract-snapshot-store-
|
|
5
|
-
import { s as readMigrationsDir } from "./io-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { t as MigrationToolsError } from "./errors-BMq40nYH-Cg8PBect.mjs";
|
|
4
|
+
import { t as contractSnapshotDir } from "./contract-snapshot-store-B0fRbVHB-BN2g8BKh.mjs";
|
|
5
|
+
import { s as readMigrationsDir } from "./io-B39zsxMm-D5Wcf6cf.mjs";
|
|
6
|
+
import { l as spaceMigrationDirectory, u as spaceRefsDirectory } from "./verify-contract-spaces-BOnqhfQs-BBq5YOKo.mjs";
|
|
7
|
+
import { A as errorHashMismatch, C as errorContractConfigMissing, D as errorDriverRequired, E as errorDatabaseConnectionRequired, F as errorMigrationPackageNotFound, G as errorRuntime, K as errorSignRefsNotWritten, L as errorNoMigrations, M as errorLegendHumanOnly, N as errorMarkerMissing, O as errorFileNotFound, Q as errorStatementNeedsMigrationFile, S as errorContractArgConflict, T as errorConvertAndDelete, _t as selfEmitCommand, a as appRefsDirFor, b as errorConfigValidation$1, bt as targetSupportsMigrations, c as cliCommand, d as closeQuietly, dt as redactUrlCredentials, ft as requireLiveDatabase, g as displayPath, gt as runCommandAction, h as dbUpdateRerun, i as appMigrationsDirFor, k as errorFromCaught, lt as printedPlanCommand, n as CliStructuredError$1$1, nt as errorTargetMismatch, o as baseDirFor, ot as maskConnectionUrl, p as contractPathFor, pt as rerunFlags, s as chooseAction, st as migrationsDirFor, tt as errorTargetMigrationNotSupported, u as cliInvocation, ut as readContractEnvelope, v as errorAdvanceRefArgConflict, vt as shellQuoted, w as errorContractValidationFailed, x as errorConsentUnused, yt as statementFlag } from "./caught-errors-I1l50iPc-D_-F2M3t.mjs";
|
|
8
8
|
import { r as getEmittedArtifactPaths } from "./exports-CVgs3YWV-BF4rqnxF.mjs";
|
|
9
|
-
import { r as isInSpaceHistory } from "./graph-membership-
|
|
10
|
-
import {
|
|
11
|
-
import { a as contractHashAtMarker } from "./aggregate-
|
|
9
|
+
import { r as isInSpaceHistory } from "./graph-membership-D7m41lWA-B68g1CRS.mjs";
|
|
10
|
+
import { i as readRef, n as advanceRef } from "./refs-t_JbIjGo-CRpBRRkq.mjs";
|
|
11
|
+
import { a as contractHashAtMarker } from "./aggregate-CRIdmKmq.mjs";
|
|
12
12
|
import { i as createScaffoldSpecifierResolver } from "./import-roots-Dqs1_cn4.mjs";
|
|
13
|
-
import { o as isLiveMarkerRef } from "./ref-resolution-
|
|
14
|
-
import { $ as
|
|
13
|
+
import { o as isLiveMarkerRef } from "./ref-resolution-C9j2SSb6.mjs";
|
|
14
|
+
import { $ as planEverySpace, A as executeMigrationNewCommand, B as labelsText, C as errorPermitPolicyChangeNeedsRef, Ct as statusForMigrationHash, Et as withWarningFindings, F as executeRefSetCommand, G as loadContractSource, H as liveMarkerUse, I as findPackageByDirPath, J as looksLikePath, K as loadContractSourceWithStack, L as formatSourceDiagnostic, N as executeRefDeleteCommand, P as executeRefListCommand, Q as migrationSpaceListEntriesFromAggregate, R as hasMigrationPath, S as enumerateCheckSpaces, St as sourceWarningDiagnostic, Tt as validateLoadedContract, U as loadAggregateIntegrityViolations, V as listRefsByContractHash, W as loadContractRawSafely, Y as mapContractAtError, Z as matchConsents, _ as databasePoliciesInForce, a as advanceRefSafely, at as refusePackageCorruptionOnAggregate, bt as skippedOperationsText, ct as requireDatabaseForLiveMarkerUse, d as buildRefAdvancementFields, dt as resolveContractRefToSnapshot, et as preflightRefAdvancement, f as checkSingleTarget, g as createControlClient, gt as retryCommandFor, h as convertAndDelete, i as RECORDED_OR_EMPTY_CONTRACT_REF_FORMS, it as refuseMissingInvariantPath, j as executeMigrationPlanCommand, k as executeMigrateShowPlan, l as buildMigrationSpaceGraphEntries, lt as resolveAppTargetPath, m as contractValidationMeta, n as NO_REF_ADVANCEMENT, nt as refuseContractSpaceIntegrity, ot as refuseUnknownInvariants, p as computeRefAdvancementName, pt as resolveMigrationRef, q as loadContractSpaceAggregateForCli, r as RECORDED_CONTRACT_REF_FORMS, s as appliedHashesFromLedger, st as renamedAndDeleted, t as ALL_CONTRACT_REF_FORMS, tt as readMigrationRefs, u as buildReadAggregate, ut as resolveContractRef$1, v as declaredSettingsText, vt as runMigrationCheck, w as executeContractEmit, wt as toDeclaredExtensionsFromRaw, xt as snapshotVerifierFor, y as deriveStatusEdgeAnnotations, yt as runMigrationList, z as isStatementVerb } from "./ref-DfuqRCA7-CPPoVHY9.mjs";
|
|
15
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-BcC8eB0h-C5bRd-aC.mjs";
|
|
16
16
|
import { a as resolveGating, i as readUserConfig, r as ensureInstallationId, s as runTelemetry, u as userConfigPath } from "./exports-DwuO4y2c.mjs";
|
|
17
17
|
import { createRequire } from "node:module";
|
|
18
18
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
19
19
|
import { CliStructuredError } from "@prisma/orm-framework/errors/control";
|
|
20
|
-
import { APP_SPACE_ID, VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_SCHEMA_FAILURE, VERIFY_CODE_TARGET_MISMATCH, createControlStack, hasPslContractBuild, issueLabel, migrationSubjectJson, schemaIssuesWhy } from "@prisma/orm-framework/components/control";
|
|
20
|
+
import { APP_SPACE_ID, VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_SCHEMA_FAILURE, VERIFY_CODE_TARGET_MISMATCH, createControlStack, databasePoliciesOf, databasePolicyDifferences, databasePolicyValueText, hasPslContractBuild, issueLabel, migrationSubjectJson, sameMarkerHashes, schemaIssuesWhy } from "@prisma/orm-framework/components/control";
|
|
21
21
|
import { InternalError, isInternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
22
22
|
import { DOCS_BASE, docsUrlFor, isStructuredError, isStructuredErrorCode } from "@prisma/orm-framework/utils/structured-error";
|
|
23
23
|
import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve } from "pathe";
|
|
24
|
+
import { errorMarkerPoliciesCorrupt } from "@prisma/orm-framework/errors/execution";
|
|
24
25
|
import { mkdir, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
25
26
|
import { blindCast, castAs } from "@prisma/orm-framework/utils/casts";
|
|
26
27
|
import { type } from "arktype";
|
|
@@ -43,8 +44,8 @@ import stringWidth from "string-width";
|
|
|
43
44
|
import { bold, createColors, cyan, cyanBright, dim, green, yellow } from "colorette";
|
|
44
45
|
import { isCI } from "ci-info";
|
|
45
46
|
import { build } from "esbuild";
|
|
46
|
-
//#region ../../../1-framework/3-tooling/cli/dist/cli-
|
|
47
|
-
var version = "8.0.0-rc.24-dev.
|
|
47
|
+
//#region ../../../1-framework/3-tooling/cli/dist/cli-Djh1pbUK.mjs
|
|
48
|
+
var version = "8.0.0-rc.24-dev.25";
|
|
48
49
|
const ESCAPES = {
|
|
49
50
|
"\\": "\\\\",
|
|
50
51
|
" ": "\\t",
|
|
@@ -360,6 +361,8 @@ const dbFlag = flag.string({
|
|
|
360
361
|
brief: "Database connection string",
|
|
361
362
|
placeholder: "url"
|
|
362
363
|
});
|
|
364
|
+
/** Consent for `db migrate` and `db update` to write the ref's declared policies into the database. */
|
|
365
|
+
const permitPolicyChangeFlag = flag.boolean({ brief: "Check the run against the ref's declared policies and write them into the database when it succeeds" });
|
|
363
366
|
/** The file `contract infer` writes when nothing names another. */
|
|
364
367
|
const INFERRED_CONTRACT_FILENAME = "contract.prisma";
|
|
365
368
|
/**
|
|
@@ -973,9 +976,11 @@ function applySummaryText(result) {
|
|
|
973
976
|
const planned = result.plan.operations.length;
|
|
974
977
|
const spaces = result.perSpace?.length ?? 0;
|
|
975
978
|
const across = spaces > 0 ? ` across ${spaces} contract space${spaces === 1 ? "" : "s"}` : "";
|
|
979
|
+
const policies = result.databasePoliciesUpdated;
|
|
976
980
|
if (result.changedStorageEntities !== void 0) return result.summary;
|
|
977
|
-
if (executed === 0) return `Database already matches contract${across}`;
|
|
978
|
-
|
|
981
|
+
if (executed === 0) return policies === void 0 ? `Database already matches contract${across}` : `Policies updated: ${declaredSettingsText(policies)}`;
|
|
982
|
+
const applied = executed < planned ? `Applied ${executed} of ${planned} operation(s)${across}; ${skippedOperationsText(planned - executed)}` : `Applied ${executed} operation(s)${across}`;
|
|
983
|
+
return policies === void 0 ? applied : `${applied}; policies updated: ${declaredSettingsText(policies)}`;
|
|
979
984
|
}
|
|
980
985
|
/** For each namespace the plan removes, the answers that answer all of its questions. */
|
|
981
986
|
function namespaceAnswerLines(result) {
|
|
@@ -1756,27 +1761,33 @@ function signSummary(spaces) {
|
|
|
1756
1761
|
const signedText = signed.length === 0 ? "signed nothing" : `signed ${quotedList(signed)}`;
|
|
1757
1762
|
return `${problems.charAt(0).toUpperCase()}${problems.slice(1)}; ${signedText}`;
|
|
1758
1763
|
}
|
|
1759
|
-
/** The `db sign`
|
|
1760
|
-
function
|
|
1761
|
-
return
|
|
1764
|
+
/** The arguments of `db sign` that change what it signs or where, which a re-run repeats. */
|
|
1765
|
+
function signRerunArgs(args) {
|
|
1766
|
+
return [
|
|
1762
1767
|
...args.contractRef === void 0 ? [] : ["--contract", shellQuoted(args.contractRef)],
|
|
1763
1768
|
...args.advanceRef === void 0 ? [] : ["--advance-ref", shellQuoted(args.advanceRef)],
|
|
1764
1769
|
...args.noAdvanceRef ? ["--no-advance-ref"] : []
|
|
1765
|
-
]
|
|
1770
|
+
];
|
|
1771
|
+
}
|
|
1772
|
+
/** The `db sign` command that runs this one again, with the arguments the user gave. */
|
|
1773
|
+
function rerunCommand(invocation) {
|
|
1774
|
+
return cliCommand(invocation, "db sign", invocation.rerunArgs ?? []);
|
|
1766
1775
|
}
|
|
1767
1776
|
function markerConflictDiagnostic(outcome, rerun) {
|
|
1768
1777
|
const { expected, found } = outcome;
|
|
1778
|
+
const changedBack = expected !== null && sameMarkerHashes(found, expected);
|
|
1769
1779
|
return {
|
|
1770
1780
|
code: "MIGRATION.MARKER_CAS_FAILURE",
|
|
1771
1781
|
severity: "error",
|
|
1772
1782
|
summary: `Marker of space "${outcome.space}" changed while db sign ran`,
|
|
1773
|
-
why: `Another process, such as migrate, changed the marker from ${expected?.storageHash ?? "no marker"} to ${found?.storageHash ?? "no marker"} after db sign read it, so db sign did not sign the space.`,
|
|
1783
|
+
why: changedBack ? "Another process changed the marker and changed it back while db sign was writing it, so db sign did not sign the space." : `Another process, such as migrate, changed the marker from ${expected?.storageHash ?? "no marker"} to ${found?.storageHash ?? "no marker"} after db sign read it, so db sign did not sign the space.`,
|
|
1774
1784
|
nextActions: [{
|
|
1775
1785
|
kind: "run-command",
|
|
1776
1786
|
label: "Sign again once the other process has finished",
|
|
1777
1787
|
command: rerun
|
|
1778
1788
|
}],
|
|
1779
1789
|
meta: {
|
|
1790
|
+
reason: changedBack ? "markerChanged" : "storageHash",
|
|
1780
1791
|
space: outcome.space,
|
|
1781
1792
|
expectedStorageHash: expected?.storageHash ?? null,
|
|
1782
1793
|
foundStorageHash: found?.storageHash ?? null,
|
|
@@ -1856,10 +1867,7 @@ function hydrateContract(config, json, path) {
|
|
|
1856
1867
|
async function advanceExtensionRef(args) {
|
|
1857
1868
|
const refsDir = spaceRefsDirectory(spaceMigrationDirectory(args.migrationsDir, args.space));
|
|
1858
1869
|
try {
|
|
1859
|
-
await
|
|
1860
|
-
hash: args.hash,
|
|
1861
|
-
invariants: []
|
|
1862
|
-
});
|
|
1870
|
+
await advanceRef(refsDir, args.name, args.hash);
|
|
1863
1871
|
return ok(void 0);
|
|
1864
1872
|
} catch (error) {
|
|
1865
1873
|
if (MigrationToolsError.is(error)) return notOk(error);
|
|
@@ -2004,11 +2012,15 @@ function createDbSignCommand(createClient = createControlClient) {
|
|
|
2004
2012
|
});
|
|
2005
2013
|
if (!connection.ok) return notOk$1(connection.failure);
|
|
2006
2014
|
const dbConnection = connection.value;
|
|
2007
|
-
const
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2015
|
+
const invocation = {
|
|
2016
|
+
...cliInvocation(ctx, args.flags.db),
|
|
2017
|
+
rerunArgs: signRerunArgs({
|
|
2018
|
+
contractRef,
|
|
2019
|
+
advanceRef: args.flags.advanceRef,
|
|
2020
|
+
noAdvanceRef: args.flags.noAdvanceRef
|
|
2021
|
+
})
|
|
2022
|
+
};
|
|
2023
|
+
const rerun = rerunCommand(invocation);
|
|
2012
2024
|
const header = headerBlock$1({
|
|
2013
2025
|
contract: contractRef ?? emitted.value.displayPath,
|
|
2014
2026
|
database: maskConnectionUrl(dbConnection)
|
|
@@ -2017,6 +2029,7 @@ function createDbSignCommand(createClient = createControlClient) {
|
|
|
2017
2029
|
const signed = await client.dbSign({
|
|
2018
2030
|
contract,
|
|
2019
2031
|
migrationsDir,
|
|
2032
|
+
invocation,
|
|
2020
2033
|
connection: dbConnection,
|
|
2021
2034
|
onProgress: controlProgressReporter(ctx.report)
|
|
2022
2035
|
});
|
|
@@ -2335,11 +2348,7 @@ function updatePresentations(inputs) {
|
|
|
2335
2348
|
]
|
|
2336
2349
|
}, ...migrationResultBlocks(document, inputs.invocation, inputs.databaseStorageHash)],
|
|
2337
2350
|
json: () => document,
|
|
2338
|
-
next: () => migrationResultNextActions(document, inputs.invocation,
|
|
2339
|
-
...inputs.to === void 0 ? [] : ["--to", shellQuoted(inputs.to)],
|
|
2340
|
-
...inputs.advanceRef === void 0 ? [] : ["--advance-ref", shellQuoted(inputs.advanceRef)],
|
|
2341
|
-
...inputs.statements.map(statementFlag)
|
|
2342
|
-
]))
|
|
2351
|
+
next: () => migrationResultNextActions(document, inputs.invocation, dbUpdateRerun(inputs.invocation, inputs.statements.map(statementFlag)))
|
|
2343
2352
|
};
|
|
2344
2353
|
}
|
|
2345
2354
|
/**
|
|
@@ -2422,6 +2431,7 @@ function updateDocument(inputs) {
|
|
|
2422
2431
|
} },
|
|
2423
2432
|
...ifDefined("perSpace", value.perSpace),
|
|
2424
2433
|
...ifDefined("changedStorageEntities", value.changedStorageEntities),
|
|
2434
|
+
...ifDefined("databasePoliciesUpdated", value.databasePoliciesUpdated),
|
|
2425
2435
|
appliedStatements: value.appliedStatements,
|
|
2426
2436
|
temporaryValues: value.temporaryValues,
|
|
2427
2437
|
...value.mode === "plan" ? {
|
|
@@ -2467,7 +2477,8 @@ function createDbUpdateCommand(createClient) {
|
|
|
2467
2477
|
advanceRef: flag.string({
|
|
2468
2478
|
brief: "Advance the named ref to the post-command contract hash",
|
|
2469
2479
|
placeholder: "name"
|
|
2470
|
-
})
|
|
2480
|
+
}),
|
|
2481
|
+
permitPolicyChange: permitPolicyChangeFlag
|
|
2471
2482
|
} },
|
|
2472
2483
|
statements: dbUpdateStatementVerbs,
|
|
2473
2484
|
needs: { config: ormConfigSection },
|
|
@@ -2517,6 +2528,10 @@ function createDbUpdateCommand(createClient) {
|
|
|
2517
2528
|
if (!resolved.ok) return notOk$1(normalizeError(resolved.failure));
|
|
2518
2529
|
destination = resolved.value;
|
|
2519
2530
|
}
|
|
2531
|
+
if (args.flags.permitPolicyChange === true && destination?.ref === void 0) return notOk$1(normalizeError(errorPermitPolicyChangeNeedsRef({
|
|
2532
|
+
command: "db update",
|
|
2533
|
+
to: args.flags.to
|
|
2534
|
+
})));
|
|
2520
2535
|
const prepared = await prepareMigrationRun({
|
|
2521
2536
|
config: ctx.config,
|
|
2522
2537
|
cwd: ctx.cwd,
|
|
@@ -2525,13 +2540,11 @@ function createDbUpdateCommand(createClient) {
|
|
|
2525
2540
|
createClient,
|
|
2526
2541
|
retryCommand: () => retryCommandFor({
|
|
2527
2542
|
commandName: args.flags.dryRun ? "db update --dry-run" : "db update",
|
|
2528
|
-
|
|
2529
|
-
advanceRef: args.flags.advanceRef,
|
|
2530
|
-
statements: [
|
|
2543
|
+
rerunArgs: [...rerunFlags(args.flags), ...[
|
|
2531
2544
|
...planned,
|
|
2532
2545
|
...previewConsents,
|
|
2533
2546
|
...unansweredConsents(ctx.statements)
|
|
2534
|
-
],
|
|
2547
|
+
].map(statementFlag)],
|
|
2535
2548
|
canRunOffline: false
|
|
2536
2549
|
})
|
|
2537
2550
|
});
|
|
@@ -2569,20 +2582,17 @@ function createDbUpdateCommand(createClient) {
|
|
|
2569
2582
|
...previewConsents,
|
|
2570
2583
|
...unansweredConsents(ctx.statements)
|
|
2571
2584
|
].map(statementFlag);
|
|
2572
|
-
const rerunArgs = [
|
|
2573
|
-
...args.flags.to === void 0 ? [] : ["--to", shellQuoted(args.flags.to)],
|
|
2574
|
-
...args.flags.advanceRef === void 0 ? [] : ["--advance-ref", shellQuoted(args.flags.advanceRef)],
|
|
2575
|
-
...statementArgs
|
|
2576
|
-
];
|
|
2577
2585
|
const result = await client.dbUpdate({
|
|
2578
2586
|
contract: contractJson,
|
|
2579
2587
|
mode,
|
|
2580
2588
|
migrationsDir,
|
|
2581
2589
|
statements: [...planned, ...previewConsents],
|
|
2590
|
+
...ifDefined("ref", destination?.ref),
|
|
2591
|
+
...args.flags.permitPolicyChange === true ? { permitPolicyChange: true } : {},
|
|
2582
2592
|
answerQuestions: promptPlanQuestions(ctx.prompt, ctx.statements),
|
|
2583
2593
|
invocation: {
|
|
2584
2594
|
...cliInvocation(ctx, args.flags.db),
|
|
2585
|
-
rerunArgs,
|
|
2595
|
+
rerunArgs: rerunFlags(args.flags),
|
|
2586
2596
|
statementArgs
|
|
2587
2597
|
},
|
|
2588
2598
|
onPlannerWarnings: plannerWarnings.onPlannerWarnings,
|
|
@@ -2629,13 +2639,15 @@ function createDbUpdateCommand(createClient) {
|
|
|
2629
2639
|
});
|
|
2630
2640
|
return ok$1(ctx.present({ data: document }, updatePresentations({
|
|
2631
2641
|
document,
|
|
2632
|
-
invocation:
|
|
2642
|
+
invocation: {
|
|
2643
|
+
...cliInvocation(ctx, args.flags.db),
|
|
2644
|
+
rerunArgs: rerunFlags(args.flags)
|
|
2645
|
+
},
|
|
2633
2646
|
databaseStorageHash,
|
|
2634
2647
|
contractPath: prepared.value.contractDisplayPath,
|
|
2635
2648
|
database: prepared.value.database,
|
|
2636
2649
|
to: args.flags.to,
|
|
2637
2650
|
dryRun: args.flags.dryRun,
|
|
2638
|
-
advanceRef: args.flags.advanceRef,
|
|
2639
2651
|
statements: [...planned, ...previewConsents]
|
|
2640
2652
|
})));
|
|
2641
2653
|
}
|
|
@@ -4988,63 +5000,6 @@ function prisma6SideBySideSetup(inputs) {
|
|
|
4988
5000
|
};
|
|
4989
5001
|
}
|
|
4990
5002
|
/**
|
|
4991
|
-
* pnpm error codes that mean the published artifact itself is at fault (a leaked `workspace:`
|
|
4992
|
-
* or `catalog:` specifier), not the user's environment. npm installs such an artifact, so init
|
|
4993
|
-
* falls back to it. Pinned against pnpm 10.27: a leaked `workspace:` specifier reports
|
|
4994
|
-
* `ERR_PNPM_WORKSPACE_PKG_NOT_FOUND`, a leaked `catalog:` one
|
|
4995
|
-
* `ERR_PNPM_SPEC_NOT_SUPPORTED_BY_ANY_RESOLVER`. `ERR_PNPM_NO_MATCHING_VERSION` is left out: pnpm
|
|
4996
|
-
* reports it for a version the registry does not have, which npm cannot install either.
|
|
4997
|
-
*/
|
|
4998
|
-
const FALLBACK_PNPM_ERROR_CODES = /* @__PURE__ */ new Set(["ERR_PNPM_WORKSPACE_PKG_NOT_FOUND", "ERR_PNPM_SPEC_NOT_SUPPORTED_BY_ANY_RESOLVER"]);
|
|
4999
|
-
const PNPM_ERROR_CODE = /\bERR_PNPM_[A-Z0-9_]+\b/g;
|
|
5000
|
-
/**
|
|
5001
|
-
* Whether pnpm's output names an error code that justifies the npm fallback. `init` reads it
|
|
5002
|
-
* from the output the package-manager capability returns on a failed install.
|
|
5003
|
-
*/
|
|
5004
|
-
function isRecognisedPnpmResolutionError(output) {
|
|
5005
|
-
return Array.from(output.matchAll(PNPM_ERROR_CODE), ([code]) => code).some((code) => FALLBACK_PNPM_ERROR_CODES.has(code));
|
|
5006
|
-
}
|
|
5007
|
-
function metaString(failure, key) {
|
|
5008
|
-
const value = failure.meta?.[key];
|
|
5009
|
-
return typeof value === "string" ? value : "";
|
|
5010
|
-
}
|
|
5011
|
-
/**
|
|
5012
|
-
* pnpm reported a specifier the published artifact leaked, which npm installs
|
|
5013
|
-
* happily. The engine redacts credentials out of the stderr it returns but
|
|
5014
|
-
* leaves error codes alone, which is what this reads. pnpm 10 prints its
|
|
5015
|
-
* `ERR_PNPM_*` codes on stdout, though, and the engine returns only stderr, so
|
|
5016
|
-
* this does not fire until the engine returns stdout as well.
|
|
5017
|
-
*/
|
|
5018
|
-
function pnpmLeakedASpecifier(failure) {
|
|
5019
|
-
return metaString(failure, "manager") === "pnpm" && isRecognisedPnpmResolutionError(metaString(failure, "stderrTail"));
|
|
5020
|
-
}
|
|
5021
|
-
/**
|
|
5022
|
-
* The engine redacts the stderr it hands back, and this redacts it again
|
|
5023
|
-
* before quoting it: what the engine strips is its own business, and registry
|
|
5024
|
-
* auth material is not all URL-shaped.
|
|
5025
|
-
*/
|
|
5026
|
-
function fallbackWarning(failure) {
|
|
5027
|
-
const firstLine = redactSecrets(metaString(failure, "stderrTail")).trim().split("\n")[0] ?? "";
|
|
5028
|
-
return [
|
|
5029
|
-
"pnpm could not install: a published Prisma ORM dependency leaked a `workspace:*` or `catalog:` specifier.",
|
|
5030
|
-
"Falling back to npm so init can complete.",
|
|
5031
|
-
firstLine === "" ? "" : ` pnpm error: ${firstLine}`,
|
|
5032
|
-
"Both installs ran under npm, which writes a package-lock.json beside the pnpm lockfile — delete whichever of the two you do not want to keep.",
|
|
5033
|
-
"Once the offending package republishes a clean version, re-run `pnpm install` to switch back."
|
|
5034
|
-
].filter((line) => line !== "").join("\n");
|
|
5035
|
-
}
|
|
5036
|
-
/** The pnpm failure the npm retry was meant to recover from, kept alongside the npm one. */
|
|
5037
|
-
function retriedWarning(failure) {
|
|
5038
|
-
const firstLine = redactSecrets(metaString(failure, "stderrTail")).trim().split("\n")[0] ?? "";
|
|
5039
|
-
return ["pnpm failed first with a leaked `workspace:*` or `catalog:` specifier, so init retried with npm.", firstLine === "" ? "" : ` pnpm error: ${firstLine}`].filter((line) => line !== "").join("\n");
|
|
5040
|
-
}
|
|
5041
|
-
/**
|
|
5042
|
-
* Adds the runtime and development dependencies through the engine's package
|
|
5043
|
-
* manager. The retry is `init`'s alone: the engine spells and runs the
|
|
5044
|
-
* command, and this decides — from the stderr it returned — that another
|
|
5045
|
-
* manager is worth a try.
|
|
5046
|
-
*/
|
|
5047
|
-
/**
|
|
5048
5003
|
* The engine dependency spec a fresh scaffold installs. The scaffolded
|
|
5049
5004
|
* `prisma.config.ts` imports `definePrismaConfig` from `@prisma/cli-engine`, and the
|
|
5050
5005
|
* installed `prisma` names the exact engine version it runs against — so
|
|
@@ -5066,41 +5021,20 @@ function engineDevDependencySpec(cwd) {
|
|
|
5066
5021
|
} catch {}
|
|
5067
5022
|
return "@prisma/cli-engine@latest";
|
|
5068
5023
|
}
|
|
5024
|
+
/**
|
|
5025
|
+
* Adds the runtime and development dependencies through the engine's package manager. Returns the
|
|
5026
|
+
* first failure it reports, or `undefined` when both installs succeed.
|
|
5027
|
+
*/
|
|
5069
5028
|
async function installProjectDependencies(ctx) {
|
|
5070
|
-
const
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
if (!installed.ok) return installed.failure;
|
|
5080
|
-
}
|
|
5081
|
-
};
|
|
5082
|
-
const failure = await pair();
|
|
5083
|
-
if (failure === void 0) return {
|
|
5084
|
-
failure: void 0,
|
|
5085
|
-
manager: void 0,
|
|
5086
|
-
warnings: ctx.catalogWarnings
|
|
5087
|
-
};
|
|
5088
|
-
if (!pnpmLeakedASpecifier(failure)) return {
|
|
5089
|
-
failure,
|
|
5090
|
-
manager: void 0,
|
|
5091
|
-
warnings: []
|
|
5092
|
-
};
|
|
5093
|
-
const retryFailure = await pair("npm");
|
|
5094
|
-
if (retryFailure !== void 0) return {
|
|
5095
|
-
failure: retryFailure,
|
|
5096
|
-
manager: void 0,
|
|
5097
|
-
warnings: [retriedWarning(failure)]
|
|
5098
|
-
};
|
|
5099
|
-
return {
|
|
5100
|
-
failure: void 0,
|
|
5101
|
-
manager: "npm",
|
|
5102
|
-
warnings: [fallbackWarning(failure)]
|
|
5103
|
-
};
|
|
5029
|
+
for (const [packages, dev] of [[ctx.deps, false], [ctx.devDeps, true]]) {
|
|
5030
|
+
if (packages.length === 0) continue;
|
|
5031
|
+
const installed = await ctx.packages.install({
|
|
5032
|
+
packages,
|
|
5033
|
+
cwd: ctx.cwd,
|
|
5034
|
+
...dev ? { dev } : {}
|
|
5035
|
+
});
|
|
5036
|
+
if (!installed.ok) return installed.failure;
|
|
5037
|
+
}
|
|
5104
5038
|
}
|
|
5105
5039
|
const importFromProject = async (cwd, specifier) => {
|
|
5106
5040
|
let resolved;
|
|
@@ -5116,13 +5050,11 @@ var Prisma7CheckInstallFailed = class extends Error {
|
|
|
5116
5050
|
failure;
|
|
5117
5051
|
target;
|
|
5118
5052
|
schemaPath;
|
|
5119
|
-
|
|
5120
|
-
constructor(failure, target, schemaPath, warnings) {
|
|
5053
|
+
constructor(failure, target, schemaPath) {
|
|
5121
5054
|
super(failure.message);
|
|
5122
5055
|
this.failure = failure;
|
|
5123
5056
|
this.target = target;
|
|
5124
5057
|
this.schemaPath = schemaPath;
|
|
5125
|
-
this.warnings = warnings;
|
|
5126
5058
|
this.name = "Prisma7CheckInstallFailed";
|
|
5127
5059
|
}
|
|
5128
5060
|
};
|
|
@@ -5164,20 +5096,19 @@ function createPrisma7SourceCheck(ctx) {
|
|
|
5164
5096
|
if (ctx.install) {
|
|
5165
5097
|
const deps = [packageName, "dotenv"];
|
|
5166
5098
|
const declaredBefore = declaredPackages(ctx.cwd);
|
|
5167
|
-
const
|
|
5099
|
+
const installFailure = await installProjectDependencies({
|
|
5168
5100
|
packages: ctx.packages,
|
|
5169
5101
|
cwd: ctx.cwd,
|
|
5170
5102
|
deps,
|
|
5171
|
-
devDeps: []
|
|
5172
|
-
catalogWarnings: ctx.packageManager === "pnpm" ? buildCatalogWarnings(ctx.cwd, deps) : []
|
|
5103
|
+
devDeps: []
|
|
5173
5104
|
});
|
|
5174
|
-
if (
|
|
5175
|
-
warnings.push(...
|
|
5105
|
+
if (installFailure !== void 0) throw new Prisma7CheckInstallFailed(installFailure, target, schemaPath);
|
|
5106
|
+
if (ctx.packageManager === "pnpm") warnings.push(...buildCatalogWarnings(ctx.cwd, deps));
|
|
5176
5107
|
installed = deps;
|
|
5177
5108
|
const newlyDeclared = deps.filter((dep) => !declaredBefore.has(dep));
|
|
5178
5109
|
added = newlyDeclared.length === 0 ? void 0 : {
|
|
5179
5110
|
packages: newlyDeclared,
|
|
5180
|
-
removeCommand: formatRemoveCommand(
|
|
5111
|
+
removeCommand: formatRemoveCommand(ctx.packageManager, newlyDeclared)
|
|
5181
5112
|
};
|
|
5182
5113
|
}
|
|
5183
5114
|
const undoable = async (step) => {
|
|
@@ -6994,7 +6925,6 @@ const createInitCommand = (injected) => defineOrmCommand({
|
|
|
6994
6925
|
});
|
|
6995
6926
|
} catch (error) {
|
|
6996
6927
|
if (!(error instanceof Prisma7CheckInstallFailed)) throw error;
|
|
6997
|
-
for (const warning of error.warnings) warn(warning);
|
|
6998
6928
|
const document = {
|
|
6999
6929
|
ok: true,
|
|
7000
6930
|
target: outputTarget(error.target),
|
|
@@ -7115,25 +7045,23 @@ const createInitCommand = (injected) => defineOrmCommand({
|
|
|
7115
7045
|
})));
|
|
7116
7046
|
};
|
|
7117
7047
|
if (inputs.install) {
|
|
7118
|
-
const
|
|
7048
|
+
const installFailure = await installProjectDependencies({
|
|
7119
7049
|
packages: ctx.packages,
|
|
7120
7050
|
cwd: ctx.cwd,
|
|
7121
7051
|
deps: depsToInstall,
|
|
7122
|
-
devDeps
|
|
7123
|
-
catalogWarnings: packageManager === "pnpm" ? buildCatalogWarnings(ctx.cwd, [...depsToInstall, ...devDeps]) : []
|
|
7052
|
+
devDeps
|
|
7124
7053
|
});
|
|
7125
|
-
|
|
7126
|
-
if (outcome.failure !== void 0) {
|
|
7054
|
+
if (installFailure !== void 0) {
|
|
7127
7055
|
packagesInstalled = "failed";
|
|
7128
|
-
findings.push(installFailedFinding(
|
|
7056
|
+
findings.push(installFailedFinding(installFailure, scaffold.filesWritten));
|
|
7129
7057
|
return settle(4);
|
|
7130
7058
|
}
|
|
7059
|
+
if (packageManager === "pnpm") for (const warning of buildCatalogWarnings(ctx.cwd, [...depsToInstall, ...devDeps])) warn(warning);
|
|
7131
7060
|
const engineSpec = engineDevDependencySpec(ctx.cwd);
|
|
7132
7061
|
const engineInstall = await ctx.packages.install({
|
|
7133
7062
|
packages: [engineSpec],
|
|
7134
7063
|
dev: true,
|
|
7135
|
-
cwd: ctx.cwd
|
|
7136
|
-
...ifDefined("manager", outcome.manager)
|
|
7064
|
+
cwd: ctx.cwd
|
|
7137
7065
|
});
|
|
7138
7066
|
if (!engineInstall.ok) {
|
|
7139
7067
|
packagesInstalled = "failed";
|
|
@@ -9562,6 +9490,19 @@ const EMITTED_CONTRACT_TARGET = {
|
|
|
9562
9490
|
entry: void 0,
|
|
9563
9491
|
refName: void 0
|
|
9564
9492
|
};
|
|
9493
|
+
function migrateTargetOf({ entry, refName }) {
|
|
9494
|
+
if (entry === void 0) return void 0;
|
|
9495
|
+
return refName === void 0 ? {
|
|
9496
|
+
kind: "hash",
|
|
9497
|
+
hash: entry.hash
|
|
9498
|
+
} : {
|
|
9499
|
+
kind: "ref",
|
|
9500
|
+
ref: {
|
|
9501
|
+
name: refName,
|
|
9502
|
+
...entry
|
|
9503
|
+
}
|
|
9504
|
+
};
|
|
9505
|
+
}
|
|
9565
9506
|
/**
|
|
9566
9507
|
* `--to` as a contract the app graph knows. A ref target keeps the invariants
|
|
9567
9508
|
* the ref declares; a bare hash or `@empty` carries none. An omitted `--to`
|
|
@@ -9620,6 +9561,7 @@ function createMigrateCommand(createClient) {
|
|
|
9620
9561
|
placeholder: "name"
|
|
9621
9562
|
}),
|
|
9622
9563
|
show: flag.boolean({ brief: "Preview the migration route without applying (read-only)" }),
|
|
9564
|
+
permitPolicyChange: permitPolicyChangeFlag,
|
|
9623
9565
|
from: flag.string({
|
|
9624
9566
|
brief: `From-state for the --show preview (${ALL_CONTRACT_REF_FORMS})`,
|
|
9625
9567
|
placeholder: "contract"
|
|
@@ -9636,7 +9578,8 @@ function createMigrateCommand(createClient) {
|
|
|
9636
9578
|
createClient,
|
|
9637
9579
|
...ifDefined("db", args.flags.db),
|
|
9638
9580
|
...ifDefined("to", args.flags.to),
|
|
9639
|
-
...ifDefined("from", args.flags.from)
|
|
9581
|
+
...ifDefined("from", args.flags.from),
|
|
9582
|
+
...args.flags.permitPolicyChange === true ? { permitPolicyChange: true } : {}
|
|
9640
9583
|
});
|
|
9641
9584
|
if (!planned.ok) return notOk$1(normalizeError(planned.failure));
|
|
9642
9585
|
const plan = planned.value;
|
|
@@ -9673,8 +9616,7 @@ function createMigrateCommand(createClient) {
|
|
|
9673
9616
|
createClient,
|
|
9674
9617
|
retryCommand: retryCommandFor({
|
|
9675
9618
|
commandName: "db migrate",
|
|
9676
|
-
|
|
9677
|
-
advanceRef: args.flags.advanceRef,
|
|
9619
|
+
rerunArgs: rerunFlags(args.flags),
|
|
9678
9620
|
canRunOffline: false
|
|
9679
9621
|
})
|
|
9680
9622
|
});
|
|
@@ -9711,6 +9653,10 @@ function createMigrateCommand(createClient) {
|
|
|
9711
9653
|
contractHash: aggregate.app.contract().storage.storageHash
|
|
9712
9654
|
});
|
|
9713
9655
|
if (offlineTarget !== void 0 && !offlineTarget.ok) return notOk$1(offlineTarget.failure);
|
|
9656
|
+
if (args.flags.permitPolicyChange === true && offlineTarget?.value.refName === void 0) return notOk$1(normalizeError(errorPermitPolicyChangeNeedsRef({
|
|
9657
|
+
command: "db migrate",
|
|
9658
|
+
to: args.flags.to
|
|
9659
|
+
})));
|
|
9714
9660
|
let document;
|
|
9715
9661
|
try {
|
|
9716
9662
|
await client.connect(dbConnection);
|
|
@@ -9719,6 +9665,8 @@ function createMigrateCommand(createClient) {
|
|
|
9719
9665
|
const appMarker = markers.get(aggregate.app.spaceId) ?? null;
|
|
9720
9666
|
const target = offlineTarget === void 0 ? liveMarkerTarget(appMarker) : offlineTarget.value;
|
|
9721
9667
|
const refEntry = target.entry;
|
|
9668
|
+
const permitPolicyChange = args.flags.permitPolicyChange === true;
|
|
9669
|
+
const inForce = databasePoliciesInForce(markers, aggregate.app.spaceId, familyInstance.markerLocation);
|
|
9722
9670
|
const planned = await planEverySpace({
|
|
9723
9671
|
aggregate,
|
|
9724
9672
|
markers,
|
|
@@ -9730,7 +9678,8 @@ function createMigrateCommand(createClient) {
|
|
|
9730
9678
|
storageNameOf: (operation) => familyInstance.storageNameOf(operation),
|
|
9731
9679
|
migrationsDir,
|
|
9732
9680
|
invocation: cliInvocation(ctx, args.flags.db),
|
|
9733
|
-
readLedger: (spaceId) => client.readLedger(spaceId)
|
|
9681
|
+
readLedger: (spaceId) => client.readLedger(spaceId),
|
|
9682
|
+
change: inForce.change
|
|
9734
9683
|
});
|
|
9735
9684
|
if (!planned.ok) return notOk$1(normalizeError(planned.failure));
|
|
9736
9685
|
if (refEntry !== void 0 && refEntry.invariants.length > 0) {
|
|
@@ -9777,12 +9726,11 @@ function createMigrateCommand(createClient) {
|
|
|
9777
9726
|
migrationsDir,
|
|
9778
9727
|
invocation: {
|
|
9779
9728
|
...cliInvocation(ctx, args.flags.db),
|
|
9780
|
-
rerunArgs:
|
|
9729
|
+
rerunArgs: rerunFlags(args.flags)
|
|
9781
9730
|
},
|
|
9782
9731
|
onProgress: controlProgressReporter(ctx.report),
|
|
9783
|
-
...ifDefined("
|
|
9784
|
-
...
|
|
9785
|
-
...ifDefined("refName", target.refName)
|
|
9732
|
+
...ifDefined("target", migrateTargetOf(target)),
|
|
9733
|
+
...permitPolicyChange ? { permitPolicyChange } : {}
|
|
9786
9734
|
});
|
|
9787
9735
|
if (!applied.ok) return notOk$1(normalizeError(applied.failure));
|
|
9788
9736
|
const { value } = applied;
|
|
@@ -9811,7 +9759,8 @@ function createMigrateCommand(createClient) {
|
|
|
9811
9759
|
perSpace: value.perSpace,
|
|
9812
9760
|
...ifDefined("pathDecision", value.pathDecision),
|
|
9813
9761
|
timings: { total: Date.now() - startedAt },
|
|
9814
|
-
advancedRef
|
|
9762
|
+
advancedRef,
|
|
9763
|
+
...ifDefined("databasePoliciesUpdated", value.databasePoliciesUpdated)
|
|
9815
9764
|
};
|
|
9816
9765
|
} catch (error) {
|
|
9817
9766
|
return notOk$1(normalizeError(errorFromCaught(error, (message) => `Unexpected error during migrate: ${message}`, { connection: typeof dbConnection === "string" ? dbConnection : void 0 })));
|
|
@@ -11212,22 +11161,69 @@ function contractUnreadableFinding(reason) {
|
|
|
11212
11161
|
}
|
|
11213
11162
|
};
|
|
11214
11163
|
}
|
|
11215
|
-
|
|
11164
|
+
const AUTHOR_MIGRATIONS_BACK = "This database's change policy permits only migrations: author migrations that bring it back onto the migration graph, commit them, and deploy again";
|
|
11165
|
+
/**
|
|
11166
|
+
* The marker of `space` names no contract in the migration graph. The advice follows the database's
|
|
11167
|
+
* change policy `change`; when the policies cannot be read (`undefined`), it recommends no command,
|
|
11168
|
+
* since the policy might forbid it.
|
|
11169
|
+
*/
|
|
11170
|
+
function markerNotInHistoryFinding(space, change) {
|
|
11216
11171
|
const message = `Database was updated outside the migration system (marker for space "${space}" does not match any migration)`;
|
|
11217
|
-
|
|
11172
|
+
const why = "The marker the database carries names no contract in the on-disk migration graph.";
|
|
11173
|
+
if (change === void 0) return {
|
|
11218
11174
|
document: {
|
|
11219
11175
|
code: "MIGRATION.MARKER_NOT_IN_HISTORY",
|
|
11220
11176
|
severity: "warn",
|
|
11221
11177
|
message,
|
|
11222
|
-
hints: [
|
|
11178
|
+
hints: [POLICIES_FIRST]
|
|
11223
11179
|
},
|
|
11224
11180
|
diagnostic: {
|
|
11225
11181
|
code: "MIGRATION.MARKER_NOT_IN_HISTORY",
|
|
11226
11182
|
severity: "warn",
|
|
11227
11183
|
summary: message,
|
|
11228
|
-
why:
|
|
11184
|
+
why: `${why} ${POLICIES_FIRST}.`,
|
|
11229
11185
|
meta: { space },
|
|
11230
|
-
nextActions: [
|
|
11186
|
+
nextActions: []
|
|
11187
|
+
}
|
|
11188
|
+
};
|
|
11189
|
+
const reconciles = change.includes("reconcile");
|
|
11190
|
+
return {
|
|
11191
|
+
document: {
|
|
11192
|
+
code: "MIGRATION.MARKER_NOT_IN_HISTORY",
|
|
11193
|
+
severity: "warn",
|
|
11194
|
+
message,
|
|
11195
|
+
hints: reconciles ? ["Run '{bin} db sign' to overwrite the marker if the database already matches the contract", "Run '{bin} db update' to push the current contract to the database"] : [AUTHOR_MIGRATIONS_BACK]
|
|
11196
|
+
},
|
|
11197
|
+
diagnostic: {
|
|
11198
|
+
code: "MIGRATION.MARKER_NOT_IN_HISTORY",
|
|
11199
|
+
severity: "warn",
|
|
11200
|
+
summary: message,
|
|
11201
|
+
why,
|
|
11202
|
+
meta: {
|
|
11203
|
+
space,
|
|
11204
|
+
change: [...change]
|
|
11205
|
+
},
|
|
11206
|
+
nextActions: reconciles ? [runCommandAction("Overwrite the marker if the database already matches the contract", "{bin} db sign"), runCommandAction("Or push the current contract to the database", "{bin} db update")] : [chooseAction(AUTHOR_MIGRATIONS_BACK)]
|
|
11207
|
+
}
|
|
11208
|
+
};
|
|
11209
|
+
}
|
|
11210
|
+
const POLICIES_FIRST = "The database's change policy cannot be read, so the way back onto the graph cannot be chosen: have meta.policies corrected first";
|
|
11211
|
+
/** The application space's marker records policies that cannot be read; `migration status` reports it and goes on. */
|
|
11212
|
+
function markerPoliciesUnreadableFinding(corrupt) {
|
|
11213
|
+
return {
|
|
11214
|
+
document: {
|
|
11215
|
+
code: "CONTRACT.MARKER_ROW_CORRUPT",
|
|
11216
|
+
severity: "warn",
|
|
11217
|
+
message: `${corrupt.message}: ${corrupt.why ?? ""}`,
|
|
11218
|
+
hints: corrupt.fix === void 0 ? [] : [corrupt.fix]
|
|
11219
|
+
},
|
|
11220
|
+
diagnostic: {
|
|
11221
|
+
code: "CONTRACT.MARKER_ROW_CORRUPT",
|
|
11222
|
+
severity: "warn",
|
|
11223
|
+
summary: corrupt.message,
|
|
11224
|
+
...ifDefined("why", corrupt.why),
|
|
11225
|
+
nextActions: corrupt.nextActions ?? [],
|
|
11226
|
+
...ifDefined("meta", corrupt.meta)
|
|
11231
11227
|
}
|
|
11232
11228
|
};
|
|
11233
11229
|
}
|
|
@@ -11300,7 +11296,8 @@ function buildNoPathSummary(args) {
|
|
|
11300
11296
|
function buildStatusHeadline(args) {
|
|
11301
11297
|
if (args.markerDiverged && args.markerHash !== void 0) return `Database marker ${shortDisplayHash(args.markerHash)} is not in the on-disk migration graph`;
|
|
11302
11298
|
if (args.pendingCount === 0) return "Up to date";
|
|
11303
|
-
|
|
11299
|
+
const to = args.refName === void 0 ? shortDisplayHash(args.targetHash) : shellQuoted(args.refName);
|
|
11300
|
+
return `${args.pendingCount} pending — run \`{bin} db migrate --to ${to}\``;
|
|
11304
11301
|
}
|
|
11305
11302
|
/**
|
|
11306
11303
|
* One space's section: its heading, where more than one space is in scope, on
|
|
@@ -11321,6 +11318,23 @@ function sectionBlock(section) {
|
|
|
11321
11318
|
lines: [...heading, ...body]
|
|
11322
11319
|
};
|
|
11323
11320
|
}
|
|
11321
|
+
function policyDifferenceJson(difference) {
|
|
11322
|
+
return difference.setting === "change" ? {
|
|
11323
|
+
...difference,
|
|
11324
|
+
declared: [...difference.declared],
|
|
11325
|
+
inForce: [...difference.inForce]
|
|
11326
|
+
} : difference;
|
|
11327
|
+
}
|
|
11328
|
+
/** Each policy setting the ref declares that differs from the one the database records. */
|
|
11329
|
+
function differencesBlock(differences) {
|
|
11330
|
+
return {
|
|
11331
|
+
kind: "drawing",
|
|
11332
|
+
lines: [[{
|
|
11333
|
+
text: "differences:",
|
|
11334
|
+
tone: "heading"
|
|
11335
|
+
}], ...differences.map(({ setting, declared, inForce }) => [{ text: ` ${setting}: ref declares ${databasePolicyValueText(declared)}, database has ${databasePolicyValueText(inForce)}` }])]
|
|
11336
|
+
};
|
|
11337
|
+
}
|
|
11324
11338
|
function statusPresentations(inputs) {
|
|
11325
11339
|
const legend = inputs.legend;
|
|
11326
11340
|
return {
|
|
@@ -11365,6 +11379,7 @@ function statusPresentations(inputs) {
|
|
|
11365
11379
|
lines: toneDrawing(legend)
|
|
11366
11380
|
}],
|
|
11367
11381
|
...inputs.sections.map(sectionBlock),
|
|
11382
|
+
...inputs.differences.length === 0 ? [] : [differencesBlock(inputs.differences)],
|
|
11368
11383
|
inputs.headline
|
|
11369
11384
|
],
|
|
11370
11385
|
json: () => inputs.document
|
|
@@ -11424,7 +11439,7 @@ const migrationStatusCommand = defineOrmCommand({
|
|
|
11424
11439
|
const findings = [];
|
|
11425
11440
|
const loaded = await buildReadAggregate(ctx.config, { migrationsDir });
|
|
11426
11441
|
if (!loaded.ok) return notOk$1(normalizeError(loaded.failure));
|
|
11427
|
-
const { aggregate, contractHash } = loaded.value;
|
|
11442
|
+
const { aggregate, contractHash, markerLocation } = loaded.value;
|
|
11428
11443
|
const contractConfig = { contract: ifDefined("output", contractPathFor(ctx.config)) };
|
|
11429
11444
|
try {
|
|
11430
11445
|
await readContractEnvelope(contractConfig);
|
|
@@ -11499,6 +11514,20 @@ const migrationStatusCommand = defineOrmCommand({
|
|
|
11499
11514
|
let noPath;
|
|
11500
11515
|
let headlineTargetHash = activeRefHash ?? contractHash;
|
|
11501
11516
|
let totalPending = 0;
|
|
11517
|
+
let reportedUnreadablePolicies = false;
|
|
11518
|
+
/** The database's policies, or undefined when they cannot be read, which is reported once as a finding. */
|
|
11519
|
+
const appPoliciesInForce = () => {
|
|
11520
|
+
const read = databasePoliciesOf(database.markersBySpace.get(aggregate.app.spaceId));
|
|
11521
|
+
if (read.ok) return read.value;
|
|
11522
|
+
if (!reportedUnreadablePolicies) {
|
|
11523
|
+
reportedUnreadablePolicies = true;
|
|
11524
|
+
findings.push(markerPoliciesUnreadableFinding(errorMarkerPoliciesCorrupt({
|
|
11525
|
+
why: read.failure.why,
|
|
11526
|
+
space: aggregate.app.spaceId,
|
|
11527
|
+
markerLocation
|
|
11528
|
+
})));
|
|
11529
|
+
}
|
|
11530
|
+
};
|
|
11502
11531
|
for (const entry of scopedSpaces) {
|
|
11503
11532
|
const space = aggregate.space(entry.space);
|
|
11504
11533
|
if (space === void 0) continue;
|
|
@@ -11526,7 +11555,7 @@ const migrationStatusCommand = defineOrmCommand({
|
|
|
11526
11555
|
space: entry.space,
|
|
11527
11556
|
markerHash: readMarker.storageHash
|
|
11528
11557
|
};
|
|
11529
|
-
findings.push(markerNotInHistoryFinding(entry.space));
|
|
11558
|
+
findings.push(markerNotInHistoryFinding(entry.space, appPoliciesInForce()?.change));
|
|
11530
11559
|
}
|
|
11531
11560
|
if (origin !== void 0 && !markerDiverged && originHash !== targetHash && noPath === void 0 && !hasMigrationPath(graph, originHash, targetHash)) noPath = {
|
|
11532
11561
|
origin,
|
|
@@ -11599,6 +11628,9 @@ const migrationStatusCommand = defineOrmCommand({
|
|
|
11599
11628
|
}
|
|
11600
11629
|
}
|
|
11601
11630
|
}
|
|
11631
|
+
const declaredPolicies = connects ? activeRefEntry?.policies : void 0;
|
|
11632
|
+
const policiesToCompare = declaredPolicies === void 0 ? void 0 : appPoliciesInForce();
|
|
11633
|
+
const differences = declaredPolicies === void 0 || policiesToCompare === void 0 ? void 0 : databasePolicyDifferences(declaredPolicies, policiesToCompare);
|
|
11602
11634
|
const rendered = renderMigrationGraphSpaceTrees(renderInputs);
|
|
11603
11635
|
const treesBySpace = new Map(renderInputs.map((input, index) => [input.spaceId, rendered[index] ?? ""]));
|
|
11604
11636
|
const sections = scopedSpaces.map((entry) => {
|
|
@@ -11609,20 +11641,23 @@ const migrationStatusCommand = defineOrmCommand({
|
|
|
11609
11641
|
showHeading: showSpaceHeadings
|
|
11610
11642
|
};
|
|
11611
11643
|
});
|
|
11612
|
-
const
|
|
11644
|
+
const pathSummary = scopedSpaces.every((entry) => entry.migrations.length === 0) ? "No migrations found" : noPath !== void 0 ? buildNoPathSummary(noPath) : buildStatusHeadline({
|
|
11613
11645
|
pendingCount: totalPending,
|
|
11614
11646
|
targetHash: headlineTargetHash,
|
|
11647
|
+
refName: activeRefName,
|
|
11615
11648
|
markerDiverged: divergedMarker !== void 0,
|
|
11616
11649
|
markerHash: divergedMarker?.markerHash
|
|
11617
11650
|
});
|
|
11651
|
+
const summary = differences !== void 0 && differences.length > 0 && activeRefName !== void 0 ? `${pathSummary}; policies differ from ${activeRefName}` : pathSummary;
|
|
11618
11652
|
const diagnostics = findings.map((finding) => finding.diagnostic);
|
|
11619
11653
|
const document = {
|
|
11620
11654
|
ok: true,
|
|
11621
11655
|
spaces: statusSpaces,
|
|
11622
11656
|
summary,
|
|
11623
|
-
diagnostics: findings.map((finding) => finding.document)
|
|
11657
|
+
diagnostics: findings.map((finding) => finding.document),
|
|
11658
|
+
...ifDefined("policyDifferences", differences?.map(policyDifferenceJson))
|
|
11624
11659
|
};
|
|
11625
|
-
const alarming = divergedMarker !== void 0 || totalPending > 0 || noPath !== void 0;
|
|
11660
|
+
const alarming = divergedMarker !== void 0 || totalPending > 0 || noPath !== void 0 || differences !== void 0 && differences.length > 0;
|
|
11626
11661
|
return ok$1(ctx.present({
|
|
11627
11662
|
data: document,
|
|
11628
11663
|
diagnostics
|
|
@@ -11637,6 +11672,7 @@ const migrationStatusCommand = defineOrmCommand({
|
|
|
11637
11672
|
migrationsDir: displayPath(migrationsDir, ctx.cwd),
|
|
11638
11673
|
database: connects && typeof dbConnection === "string" ? maskConnectionUrl(dbConnection) : void 0,
|
|
11639
11674
|
ref: activeRefName,
|
|
11675
|
+
differences: differences ?? [],
|
|
11640
11676
|
from: args.flags.from,
|
|
11641
11677
|
space: args.flags.space,
|
|
11642
11678
|
legend: args.flags.legend ? renderMigrationGraphLegend({
|