@prisma/orm-toolchain 8.0.0-rc.14-dev.34 → 8.0.0-rc.14-dev.36
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-C_e9y2vI.d.mts → aggregate-5NMLDtcl.d.mts} +7 -5
- package/dist/aggregate-5NMLDtcl.d.mts.map +1 -0
- package/dist/{aggregate-By_e1Dsq.mjs → aggregate-qXuJ6w_I.mjs} +11 -8
- package/dist/aggregate-qXuJ6w_I.mjs.map +1 -0
- package/dist/{caught-errors-DnAEn1BF-QuHW5lCN.mjs → caught-errors-DUIDd-Vm-RNMiEz4x.mjs} +35 -3
- package/dist/caught-errors-DUIDd-Vm-RNMiEz4x.mjs.map +1 -0
- package/dist/cli.mjs +266 -141
- package/dist/cli.mjs.map +1 -1
- package/dist/cli__control-api.d.mts +4 -4
- package/dist/cli__control-api.mjs +3 -3
- package/dist/cli__control-api__testing.d.mts +3 -3
- package/dist/cli__control-api__testing.d.mts.map +1 -1
- package/dist/cli__control-api__testing.mjs +11 -14
- package/dist/cli__control-api__testing.mjs.map +1 -1
- package/dist/cli__migration-cli.mjs +1 -1
- package/dist/cli__migration-cli.mjs.map +1 -1
- package/dist/{db-verify-DoVihHM8-BrpF-Rnr.d.mts → db-sign-BxYV7wMQ-BB1hlVbH.d.mts} +115 -96
- package/dist/db-sign-BxYV7wMQ-BB1hlVbH.d.mts.map +1 -0
- package/dist/{import-roots-BB3GzIi-.mjs → import-roots-BeAYfehL.mjs} +2 -2
- package/dist/{import-roots-BB3GzIi-.mjs.map → import-roots-BeAYfehL.mjs.map} +1 -1
- package/dist/migration-tools.d.mts +2 -2
- package/dist/migration-tools.mjs +2 -2
- package/dist/migration-tools__aggregate.d.mts +2 -2
- package/dist/migration-tools__aggregate.mjs +2 -2
- package/dist/publish-surface.mjs +2 -2
- package/dist/publish-surface__import-roots.mjs +1 -1
- package/dist/publish-surface__shells.mjs +1 -1
- package/dist/{ref-DMcFtzRN-B1ralPE1.mjs → ref-Bcy3ShDD-S7NKefbN.mjs} +221 -136
- package/dist/ref-Bcy3ShDD-S7NKefbN.mjs.map +1 -0
- package/dist/{shells-nviMkCdc.mjs → shells-D8mbojP8.mjs} +2 -1
- package/dist/{shells-nviMkCdc.mjs.map → shells-D8mbojP8.mjs.map} +1 -1
- package/dist/vite-plugin-contract-emit.mjs +1 -1
- package/package.json +12 -12
- package/dist/aggregate-By_e1Dsq.mjs.map +0 -1
- package/dist/aggregate-C_e9y2vI.d.mts.map +0 -1
- package/dist/caught-errors-DnAEn1BF-QuHW5lCN.mjs.map +0 -1
- package/dist/db-verify-DoVihHM8-BrpF-Rnr.d.mts.map +0 -1
- package/dist/ref-DMcFtzRN-B1ralPE1.mjs.map +0 -1
package/dist/cli.mjs
CHANGED
|
@@ -2,12 +2,12 @@ import { h as requireConfigSections, i as expandContractInputs, m as ormConfigSe
|
|
|
2
2
|
import { t as MigrationToolsError } from "./errors-DD6iLGXk-6I9PqjpZ.mjs";
|
|
3
3
|
import { t as contractSnapshotDir } from "./contract-snapshot-store-1S_6vaGt-CQPNFWho.mjs";
|
|
4
4
|
import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
|
|
5
|
-
import { c as spaceMigrationDirectory } from "./verify-contract-spaces-CYjc343k-FXABEJZE.mjs";
|
|
6
|
-
import { C as errorMarkerMissing, D as errorPathUnreachable, E as errorNoMigrations,
|
|
5
|
+
import { c as spaceMigrationDirectory, l as spaceRefsDirectory } from "./verify-contract-spaces-CYjc343k-FXABEJZE.mjs";
|
|
6
|
+
import { C as errorMarkerMissing, D as errorPathUnreachable, E as errorNoMigrations, F as errorSignRefsNotWritten, G as redactUrlCredentials, K as requireLiveDatabase, N as errorRunnerFailed, P as errorRuntime, R as errorTargetMigrationNotSupported, T as errorMigrationPlanningFailed, U as maskConnectionUrl, W as readContractEnvelope, X as targetSupportsMigrations, Y as runCommandAction, _ as errorFileNotFound, a as closeQuietly, d as errorContractArgConflict, f as errorContractConfigMissing, g as errorDriverRequired, h as errorDestructiveChanges, i as chooseAction, l as errorConfigValidation$1, m as errorDatabaseConnectionRequired, n as CliStructuredError$1$1, p as errorContractValidationFailed, r as ERROR_CODE_DESTRUCTIVE_CHANGES, s as errorAdvanceRefArgConflict, t as ActionableCliError, u as errorConsentPlanMismatch, v as errorFromCaught, w as errorMigrationPackageNotFound, x as errorLegendHumanOnly, y as errorHashMismatch, z as errorTargetMismatch } from "./caught-errors-DUIDd-Vm-RNMiEz4x.mjs";
|
|
7
7
|
import { r as getEmittedArtifactPaths } from "./exports-B41NJHCo-BaEu3TXy.mjs";
|
|
8
|
-
import { r as readRef } from "./refs-qwvw4_dV-X8sR92eT.mjs";
|
|
9
|
-
import { i as createScaffoldSpecifierResolver } from "./import-roots-
|
|
10
|
-
import {
|
|
8
|
+
import { d as writeRef, r as readRef } from "./refs-qwvw4_dV-X8sR92eT.mjs";
|
|
9
|
+
import { i as createScaffoldSpecifierResolver } from "./import-roots-BeAYfehL.mjs";
|
|
10
|
+
import { $ as resolveContractRefToSnapshot, A as formatSourceDiagnostic, C as executeMigrationNewCommand, D as executeRefListCommand, E as executeRefDeleteCommand, F as loadContractSource, G as refuseContractSpaceIntegrity, H as originHashForStatus, I as loadContractSourceWithStack, J as refuseMissingInvariantPath, L as loadContractSpaceAggregateForCli, M as listRefsByContractHash, N as loadAggregateIntegrityViolations, O as executeRefSetCommand, P as loadContractRawSafely, Q as resolveContractRef$1, R as looksLikePath, S as executeMigrateShowPlan, U as preflightRefAdvancement, V as migrationSpaceListEntriesFromAggregate, W as readMigrationRefs, X as refuseUnknownInvariants, Y as refusePackageCorruptionOnAggregate, Z as resolveAppTargetPath, _ as executeContractEmit, a as appliedHashesFromLedger, at as runMigrationList, c as buildReadAggregate, ct as statusForMigrationHash, d as computeRefAdvancementName, f as createControlClient, g as enumerateCheckSpaces, it as runMigrationCheck, j as hasMigrationPath, k as findPackageByDirPath, l as buildRefAdvancementFields, lt as toDeclaredExtensionsFromRaw, n as NO_REF_ADVANCEMENT, ot as snapshotVerifierFor, p as deriveStatusEdgeAnnotations, q as refuseMarkerOutsideGraph, r as advanceRefSafely, s as buildMigrationSpaceGraphEntries, st as sourceWarningDiagnostic, t as DB_UPDATE_POLICY, tt as resolveMigrationRef, u as checkSingleTarget, ut as validateLoadedContract, w as executeMigrationPlanCommand, z as mapContractAtError } from "./ref-Bcy3ShDD-S7NKefbN.mjs";
|
|
11
11
|
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";
|
|
12
12
|
import { createRequire } from "node:module";
|
|
13
13
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
@@ -36,7 +36,7 @@ import { applyEdits, modify, parse, printParseErrorCode } from "jsonc-parser";
|
|
|
36
36
|
import stringWidth from "string-width";
|
|
37
37
|
import { bold, createColors, cyan, cyanBright, dim, green, yellow } from "colorette";
|
|
38
38
|
import { build } from "esbuild";
|
|
39
|
-
//#region ../../../1-framework/3-tooling/cli/dist/load-config-
|
|
39
|
+
//#region ../../../1-framework/3-tooling/cli/dist/load-config-3s6FxZbn.mjs
|
|
40
40
|
/**
|
|
41
41
|
* `isStructuredError` is the repo's own check, and it is the one that matters here: it holds the
|
|
42
42
|
* regular expression for a dotted `NAMESPACE.SUBCODE`, so only a code the protocol accepts
|
|
@@ -1637,8 +1637,6 @@ function schemaDriftNextActions(inputs) {
|
|
|
1637
1637
|
* diagnostic on a completed envelope rather than an error.
|
|
1638
1638
|
*/
|
|
1639
1639
|
const FINDINGS_EXIT_CODE$2 = 4;
|
|
1640
|
-
/** The config file this bin reads; the handler is not told which one was loaded. */
|
|
1641
|
-
const CONFIG_DISPLAY_PATH = "prisma.config.ts";
|
|
1642
1640
|
/**
|
|
1643
1641
|
* The ref a signature checkpoints. Unlike `db init` / `db update`, `--db` does
|
|
1644
1642
|
* not suppress the write: signing does not touch the schema, and adoption is
|
|
@@ -1676,97 +1674,202 @@ function headerBlock$1(inputs) {
|
|
|
1676
1674
|
}]
|
|
1677
1675
|
};
|
|
1678
1676
|
}
|
|
1679
|
-
function
|
|
1680
|
-
return [
|
|
1681
|
-
|
|
1677
|
+
function hashSpans(hash, previousHash) {
|
|
1678
|
+
return [{
|
|
1679
|
+
text: hash,
|
|
1680
|
+
tone: "identifier"
|
|
1681
|
+
}, ...previousHash === void 0 ? [] : [
|
|
1682
1682
|
{
|
|
1683
|
-
text:
|
|
1683
|
+
text: " (was ",
|
|
1684
|
+
tone: "muted"
|
|
1685
|
+
},
|
|
1686
|
+
{
|
|
1687
|
+
text: previousHash,
|
|
1684
1688
|
tone: "identifier"
|
|
1685
1689
|
},
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1690
|
+
{
|
|
1691
|
+
text: ")",
|
|
1692
|
+
tone: "muted"
|
|
1693
|
+
}
|
|
1694
|
+
]];
|
|
1695
|
+
}
|
|
1696
|
+
function spaceNode(outcome) {
|
|
1697
|
+
switch (outcome.status) {
|
|
1698
|
+
case "created": return {
|
|
1699
|
+
label: [
|
|
1700
|
+
{ text: `${outcome.space}: signed ` },
|
|
1701
|
+
{
|
|
1702
|
+
text: outcome.contract.storageHash,
|
|
1703
|
+
tone: "identifier"
|
|
1704
|
+
},
|
|
1705
|
+
{
|
|
1706
|
+
text: " (no marker before)",
|
|
1707
|
+
tone: "muted"
|
|
1708
|
+
}
|
|
1709
|
+
],
|
|
1710
|
+
status: "ok"
|
|
1711
|
+
};
|
|
1712
|
+
case "updated": return {
|
|
1713
|
+
label: [{ text: `${outcome.space}: signed ` }, ...hashSpans(outcome.contract.storageHash, outcome.previous.storageHash)],
|
|
1714
|
+
status: "ok"
|
|
1715
|
+
};
|
|
1716
|
+
case "unchanged": return {
|
|
1717
|
+
label: [{ text: `${outcome.space}: unchanged, already signed with ` }, {
|
|
1718
|
+
text: outcome.contract.storageHash,
|
|
1693
1719
|
tone: "identifier"
|
|
1694
|
-
},
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
}
|
|
1699
|
-
|
|
1700
|
-
|
|
1720
|
+
}],
|
|
1721
|
+
status: "ok"
|
|
1722
|
+
};
|
|
1723
|
+
case "failed": return {
|
|
1724
|
+
label: `${outcome.space}: not signed, the schema does not satisfy its contract`,
|
|
1725
|
+
status: "error",
|
|
1726
|
+
children: issueNodes(outcome.schema.schema.issues, "error")
|
|
1727
|
+
};
|
|
1728
|
+
case "conflict": return {
|
|
1729
|
+
label: `${outcome.space}: not signed, its marker changed after the schema was verified`,
|
|
1730
|
+
status: "error",
|
|
1731
|
+
children: [{
|
|
1732
|
+
label: `marker when verified: ${outcome.expected?.storageHash ?? "none"}`,
|
|
1733
|
+
status: "error"
|
|
1734
|
+
}, {
|
|
1735
|
+
label: `marker now: ${outcome.found?.storageHash ?? "none"}`,
|
|
1736
|
+
status: "error"
|
|
1737
|
+
}]
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1701
1740
|
}
|
|
1702
|
-
function
|
|
1703
|
-
return
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1741
|
+
function isSigned(outcome) {
|
|
1742
|
+
return outcome.status !== "failed" && outcome.status !== "conflict";
|
|
1743
|
+
}
|
|
1744
|
+
function quotedList(spaces) {
|
|
1745
|
+
return spaces.map((outcome) => `"${outcome.space}"`).join(", ");
|
|
1746
|
+
}
|
|
1747
|
+
function signSummary(spaces) {
|
|
1748
|
+
const failed = spaces.filter((outcome) => outcome.status === "failed");
|
|
1749
|
+
const conflicts = spaces.filter((outcome) => outcome.status === "conflict");
|
|
1750
|
+
if (failed.length === 0 && conflicts.length === 0) return "Database signed";
|
|
1751
|
+
const signed = spaces.filter(isSigned);
|
|
1752
|
+
const problems = [...failed.length === 0 ? [] : [`Database schema does not satisfy contract for ${failed.length === 1 ? "space" : "spaces"} ${quotedList(failed)}`], ...conflicts.length === 0 ? [] : [`${conflicts.length === 1 ? "marker of space" : "markers of spaces"} ${quotedList(conflicts)} changed while db sign ran`]].join("; ");
|
|
1753
|
+
const signedText = signed.length === 0 ? "signed nothing" : `signed ${quotedList(signed)}`;
|
|
1754
|
+
return `${problems.charAt(0).toUpperCase()}${problems.slice(1)}; ${signedText}`;
|
|
1755
|
+
}
|
|
1756
|
+
function rerunCommand(invocation) {
|
|
1757
|
+
return [
|
|
1758
|
+
"{bin} db sign",
|
|
1759
|
+
...invocation.contractRef === void 0 ? [] : [`--contract "${invocation.contractRef}"`],
|
|
1760
|
+
...invocation.advanceRef === void 0 ? [] : [`--advance-ref ${invocation.advanceRef}`],
|
|
1761
|
+
...invocation.noAdvanceRef ? ["--no-advance-ref"] : [],
|
|
1762
|
+
...invocation.configPath === void 0 ? [] : [`--config "${invocation.configPath}"`],
|
|
1763
|
+
...invocation.db === void 0 ? [] : ["--db <url>"]
|
|
1764
|
+
].join(" ");
|
|
1765
|
+
}
|
|
1766
|
+
function markerConflictDiagnostic(outcome, rerun) {
|
|
1767
|
+
const { expected, found } = outcome;
|
|
1768
|
+
return {
|
|
1769
|
+
code: "MIGRATION.MARKER_CAS_FAILURE",
|
|
1770
|
+
severity: "error",
|
|
1771
|
+
summary: `Marker of space "${outcome.space}" changed while db sign ran`,
|
|
1772
|
+
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.`,
|
|
1773
|
+
nextActions: [{
|
|
1774
|
+
kind: "run-command",
|
|
1775
|
+
label: "Sign again once the other process has finished",
|
|
1776
|
+
command: rerun
|
|
1777
|
+
}],
|
|
1778
|
+
meta: {
|
|
1779
|
+
space: outcome.space,
|
|
1780
|
+
expectedStorageHash: expected?.storageHash ?? null,
|
|
1781
|
+
foundStorageHash: found?.storageHash ?? null,
|
|
1782
|
+
destinationStorageHash: outcome.contract.storageHash
|
|
1783
|
+
}
|
|
1712
1784
|
};
|
|
1713
1785
|
}
|
|
1786
|
+
function advancedRefSpans(advanced) {
|
|
1787
|
+
return [{ text: advanced.space === APP_SPACE_ID ? `Advanced ref "${advanced.name}" → ` : `Advanced ref "${advanced.name}" of space "${advanced.space}" → ` }, ...hashSpans(advanced.hash, advanced.previousHash)];
|
|
1788
|
+
}
|
|
1714
1789
|
function signPresentations(inputs) {
|
|
1715
|
-
const
|
|
1790
|
+
const { document } = inputs;
|
|
1716
1791
|
return {
|
|
1717
1792
|
stdout: () => [],
|
|
1718
1793
|
next: () => [],
|
|
1719
1794
|
human: () => [
|
|
1720
1795
|
inputs.header,
|
|
1721
1796
|
{
|
|
1722
|
-
kind: "
|
|
1723
|
-
|
|
1724
|
-
text: "Database signed"
|
|
1797
|
+
kind: "tree",
|
|
1798
|
+
roots: document.spaces.map(spaceNode)
|
|
1725
1799
|
},
|
|
1726
1800
|
{
|
|
1727
|
-
kind: "
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
value: marker.previous?.storageHash === void 0 ? [{
|
|
1731
|
-
text: "none",
|
|
1732
|
-
tone: "muted"
|
|
1733
|
-
}] : [{
|
|
1734
|
-
text: marker.previous.storageHash,
|
|
1735
|
-
tone: "identifier"
|
|
1736
|
-
}]
|
|
1737
|
-
}, {
|
|
1738
|
-
label: "to",
|
|
1739
|
-
value: [{
|
|
1740
|
-
text: inputs.document.contract.storageHash,
|
|
1741
|
-
tone: "identifier"
|
|
1742
|
-
}]
|
|
1743
|
-
}]
|
|
1801
|
+
kind: "summary",
|
|
1802
|
+
status: document.ok ? "ok" : "error",
|
|
1803
|
+
text: document.summary
|
|
1744
1804
|
},
|
|
1745
|
-
|
|
1746
|
-
],
|
|
1747
|
-
json: () => inputs.document
|
|
1748
|
-
};
|
|
1749
|
-
}
|
|
1750
|
-
function refusedPresentations(inputs) {
|
|
1751
|
-
return {
|
|
1752
|
-
stdout: () => [],
|
|
1753
|
-
next: () => [],
|
|
1754
|
-
human: () => [
|
|
1755
|
-
inputs.header,
|
|
1756
|
-
...schemaFindingBlocks({
|
|
1757
|
-
result: inputs.document,
|
|
1758
|
-
unclaimed: [],
|
|
1759
|
-
strict: false
|
|
1760
|
-
}),
|
|
1761
|
-
{
|
|
1805
|
+
...inputs.advanced === null ? [{
|
|
1762
1806
|
kind: "summary",
|
|
1763
|
-
status: "
|
|
1764
|
-
|
|
1765
|
-
|
|
1807
|
+
status: "info",
|
|
1808
|
+
tone: "muted",
|
|
1809
|
+
text: `Left ref "${DEFAULT_ADVANCE_REF}" untouched (--no-advance-ref)`
|
|
1810
|
+
}] : inputs.advanced.map((advanced) => ({
|
|
1811
|
+
kind: "summary",
|
|
1812
|
+
status: "ok",
|
|
1813
|
+
text: advancedRefSpans(advanced)
|
|
1814
|
+
}))
|
|
1766
1815
|
],
|
|
1767
|
-
json: () =>
|
|
1816
|
+
json: () => document
|
|
1768
1817
|
};
|
|
1769
1818
|
}
|
|
1819
|
+
function hydrateContract(config, json, path) {
|
|
1820
|
+
try {
|
|
1821
|
+
return ok(config.family.create(createControlStack(config)).deserializeContract(json));
|
|
1822
|
+
} catch (error) {
|
|
1823
|
+
return notOk(errorContractValidationFailed(`Contract JSON is invalid: ${error instanceof Error ? error.message : String(error)}`, { where: { path } }));
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
/**
|
|
1827
|
+
* Writes the named ref of an extension space. Its contract snapshot is already in the store: the aggregate read the space's contract from it.
|
|
1828
|
+
*/
|
|
1829
|
+
async function advanceExtensionRef(args) {
|
|
1830
|
+
const refsDir = spaceRefsDirectory(spaceMigrationDirectory(args.migrationsDir, args.space));
|
|
1831
|
+
try {
|
|
1832
|
+
await writeRef(refsDir, args.name, {
|
|
1833
|
+
hash: args.hash,
|
|
1834
|
+
invariants: []
|
|
1835
|
+
});
|
|
1836
|
+
return ok(void 0);
|
|
1837
|
+
} catch (error) {
|
|
1838
|
+
if (MigrationToolsError.is(error)) return notOk(error);
|
|
1839
|
+
throw error;
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
/**
|
|
1843
|
+
* Writes one signed space's ref, and the app space's contract snapshot, after the markers are written. Any failure is returned as its message, so one ref that cannot be written does not stop the others.
|
|
1844
|
+
*/
|
|
1845
|
+
async function advanceSignedSpaceRef(args) {
|
|
1846
|
+
const isApp = args.space === APP_SPACE_ID;
|
|
1847
|
+
const refsDir = isApp ? args.appRefsDir : spaceRefsDirectory(spaceMigrationDirectory(args.migrationsDir, args.space));
|
|
1848
|
+
try {
|
|
1849
|
+
const previousHash = await previousRefHash(refsDir, args.name);
|
|
1850
|
+
const written = isApp ? await advanceRefSafely({
|
|
1851
|
+
refsDir,
|
|
1852
|
+
migrationsDir: args.migrationsDir,
|
|
1853
|
+
name: args.name,
|
|
1854
|
+
hash: args.hash,
|
|
1855
|
+
contractIR: args.contractIR
|
|
1856
|
+
}) : await advanceExtensionRef({
|
|
1857
|
+
migrationsDir: args.migrationsDir,
|
|
1858
|
+
space: args.space,
|
|
1859
|
+
name: args.name,
|
|
1860
|
+
hash: args.hash
|
|
1861
|
+
});
|
|
1862
|
+
return written.ok ? ok(previousHash) : notOk({
|
|
1863
|
+
reason: written.failure.message,
|
|
1864
|
+
cause: written.failure
|
|
1865
|
+
});
|
|
1866
|
+
} catch (error) {
|
|
1867
|
+
return notOk({
|
|
1868
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
1869
|
+
cause: error
|
|
1870
|
+
});
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1770
1873
|
/**
|
|
1771
1874
|
* Builds the command with its control-client factory injected, so tests mount
|
|
1772
1875
|
* the same tree over a fake client instead of mocking the client module.
|
|
@@ -1775,7 +1878,7 @@ function createDbSignCommand(createClient = createControlClient) {
|
|
|
1775
1878
|
return defineOrmCommand({
|
|
1776
1879
|
help: {
|
|
1777
1880
|
summary: "Sign the database with your contract so you can safely run queries",
|
|
1778
|
-
description: "Verifies that your database schema satisfies the emitted contract
|
|
1881
|
+
description: "Verifies that your database schema satisfies the emitted contract and the\ncontract of every extension that ships one, and writes or updates the\nsignature of each that does, in one transaction. A signature records that\nthis database instance is aligned with a specific contract version.\nIdempotent. After signing, the db ref of each signed space is advanced to\nits contract; pass --no-advance-ref to sign without touching any ref,\nwhich is what a CI or deployment pipeline usually wants.\nExit codes: 0 = signed, 2 = the command could not run (unresolvable\ncontract reference, no emitted contract, unreachable database), or it\nsigned the database but could not write every ref,\n4 = schema verification failed for a space,\nor its marker changed while db sign ran; its signature was not written.",
|
|
1779
1882
|
examples: [
|
|
1780
1883
|
"db sign",
|
|
1781
1884
|
"db sign --db $DATABASE_URL",
|
|
@@ -1804,7 +1907,7 @@ function createDbSignCommand(createClient = createControlClient) {
|
|
|
1804
1907
|
}
|
|
1805
1908
|
},
|
|
1806
1909
|
needs: { config: ormConfigSection },
|
|
1807
|
-
exitCodes: { 4: "schema verification failed;
|
|
1910
|
+
exitCodes: { 4: "schema verification failed for a space, or its marker changed while db sign ran; its signature was not written" },
|
|
1808
1911
|
handler: async (args, ctx) => {
|
|
1809
1912
|
const positionalContract = args.positionals.contract;
|
|
1810
1913
|
const flagContract = args.flags.contract;
|
|
@@ -1821,7 +1924,7 @@ function createDbSignCommand(createClient = createControlClient) {
|
|
|
1821
1924
|
});
|
|
1822
1925
|
if (!emitted.ok) return notOk$1(emitted.failure);
|
|
1823
1926
|
const migrationsDir = migrationsDirFor(ctx.config);
|
|
1824
|
-
let
|
|
1927
|
+
let contract = emitted.value.contract;
|
|
1825
1928
|
let signedSource;
|
|
1826
1929
|
if (contractRef !== void 0) {
|
|
1827
1930
|
const resolvedRef = await resolveContractRefToSnapshot({
|
|
@@ -1832,7 +1935,9 @@ function createDbSignCommand(createClient = createControlClient) {
|
|
|
1832
1935
|
fallbackToEmitted: true
|
|
1833
1936
|
});
|
|
1834
1937
|
if (!resolvedRef.ok) return notOk$1(normalizeError(resolvedRef.failure));
|
|
1835
|
-
|
|
1938
|
+
const hydrated = hydrateContract(ctx.config, resolvedRef.value.contractJson, resolvedRef.value.contractJsonPath);
|
|
1939
|
+
if (!hydrated.ok) return notOk$1(normalizeError(hydrated.failure));
|
|
1940
|
+
contract = hydrated.value;
|
|
1836
1941
|
signedSource = {
|
|
1837
1942
|
json: resolvedRef.value.contractJson,
|
|
1838
1943
|
jsonPath: resolvedRef.value.contractJsonPath
|
|
@@ -1871,81 +1976,101 @@ function createDbSignCommand(createClient = createControlClient) {
|
|
|
1871
1976
|
});
|
|
1872
1977
|
if (!connection.ok) return notOk$1(connection.failure);
|
|
1873
1978
|
const dbConnection = connection.value;
|
|
1979
|
+
const rerun = rerunCommand({
|
|
1980
|
+
contractRef,
|
|
1981
|
+
advanceRef: args.flags.advanceRef,
|
|
1982
|
+
noAdvanceRef: args.flags.noAdvanceRef,
|
|
1983
|
+
configPath: ctx.configPath,
|
|
1984
|
+
db: args.flags.db
|
|
1985
|
+
});
|
|
1874
1986
|
const header = headerBlock$1({
|
|
1875
1987
|
contract: contractRef ?? emitted.value.displayPath,
|
|
1876
1988
|
database: maskConnectionUrl(dbConnection)
|
|
1877
1989
|
});
|
|
1878
|
-
const onProgress = controlProgressReporter(ctx.report);
|
|
1879
1990
|
try {
|
|
1880
|
-
const
|
|
1881
|
-
contract
|
|
1882
|
-
|
|
1991
|
+
const signed = await client.dbSign({
|
|
1992
|
+
contract,
|
|
1993
|
+
migrationsDir,
|
|
1883
1994
|
connection: dbConnection,
|
|
1884
|
-
onProgress
|
|
1995
|
+
onProgress: controlProgressReporter(ctx.report)
|
|
1885
1996
|
});
|
|
1886
|
-
if (!
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1997
|
+
if (!signed.ok) return notOk$1(normalizeError(signed.failure));
|
|
1998
|
+
const spaces = signed.value.spaces;
|
|
1999
|
+
const advanced = [];
|
|
2000
|
+
const unwritten = [];
|
|
2001
|
+
if (advancement !== null) for (const outcome of spaces) {
|
|
2002
|
+
if (!isSigned(outcome)) continue;
|
|
2003
|
+
const ref = {
|
|
2004
|
+
space: outcome.space,
|
|
2005
|
+
name: advancement.name,
|
|
2006
|
+
hash: outcome.contract.storageHash
|
|
2007
|
+
};
|
|
2008
|
+
const written = await advanceSignedSpaceRef({
|
|
2009
|
+
...ref,
|
|
2010
|
+
migrationsDir,
|
|
2011
|
+
appRefsDir: appRefsDirFor(ctx.config),
|
|
2012
|
+
contractIR: advancement.contractIR
|
|
2013
|
+
});
|
|
2014
|
+
if (written.ok) advanced.push({
|
|
2015
|
+
...ref,
|
|
2016
|
+
previousHash: written.value
|
|
2017
|
+
});
|
|
2018
|
+
else unwritten.push({
|
|
2019
|
+
...ref,
|
|
2020
|
+
...written.failure
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
if (unwritten.length > 0) return notOk$1(normalizeError(errorSignRefsNotWritten({
|
|
2024
|
+
signedSpaces: spaces.filter(isSigned).map((outcome) => outcome.space),
|
|
2025
|
+
failedSpaces: spaces.filter((outcome) => outcome.status === "failed").map((outcome) => outcome.space),
|
|
2026
|
+
conflictSpaces: spaces.filter((outcome) => outcome.status === "conflict").map((outcome) => outcome.space),
|
|
2027
|
+
unwrittenRefs: unwritten.map(({ space, name, hash, reason }) => ({
|
|
2028
|
+
space,
|
|
2029
|
+
name,
|
|
2030
|
+
hash,
|
|
2031
|
+
reason
|
|
2032
|
+
})),
|
|
2033
|
+
advancedRefs: advanced.map(({ space, name, hash }) => ({
|
|
2034
|
+
space,
|
|
2035
|
+
name,
|
|
2036
|
+
hash
|
|
2037
|
+
})),
|
|
2038
|
+
rerunCommand: rerun,
|
|
2039
|
+
cause: unwritten[0]?.cause
|
|
2040
|
+
})));
|
|
2041
|
+
const unsigned = spaces.filter((outcome) => !isSigned(outcome));
|
|
2042
|
+
const document = {
|
|
2043
|
+
ok: unsigned.length === 0,
|
|
2044
|
+
summary: signSummary(spaces),
|
|
2045
|
+
spaces,
|
|
2046
|
+
advancedRefs: advanced.map(({ space, name, hash }) => ({
|
|
2047
|
+
space,
|
|
2048
|
+
name,
|
|
2049
|
+
hash
|
|
2050
|
+
}))
|
|
2051
|
+
};
|
|
2052
|
+
const diagnostics = spaces.flatMap((outcome) => {
|
|
2053
|
+
switch (outcome.status) {
|
|
2054
|
+
case "failed": return [schemaVerdictDiagnostic({
|
|
2055
|
+
result: outcome.schema,
|
|
2056
|
+
space: outcome.space,
|
|
1894
2057
|
nextActions: schemaDriftNextActions({
|
|
1895
2058
|
verb: "sign",
|
|
1896
2059
|
contractRef,
|
|
1897
|
-
issues:
|
|
2060
|
+
issues: outcome.schema.schema.issues
|
|
1898
2061
|
})
|
|
1899
|
-
})]
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
})));
|
|
1904
|
-
}
|
|
1905
|
-
const signed = await client.sign({
|
|
1906
|
-
contract: contractInput,
|
|
1907
|
-
contractPath: displayPath(emitted.value.path, ctx.cwd),
|
|
1908
|
-
configPath: CONFIG_DISPLAY_PATH,
|
|
1909
|
-
onProgress
|
|
1910
|
-
});
|
|
1911
|
-
if (!signed.ok) throw new InternalError(`The family returned a sign result that did not sign: ${signed.summary}`);
|
|
1912
|
-
if (advancement === null) {
|
|
1913
|
-
const document = {
|
|
1914
|
-
...signed,
|
|
1915
|
-
advancedRef: null
|
|
1916
|
-
};
|
|
1917
|
-
return ok$1(ctx.present({
|
|
1918
|
-
data: document,
|
|
1919
|
-
exitCode: 0
|
|
1920
|
-
}, signPresentations({
|
|
1921
|
-
document,
|
|
1922
|
-
advanced: null,
|
|
1923
|
-
header
|
|
1924
|
-
})));
|
|
1925
|
-
}
|
|
1926
|
-
const refsDir = appRefsDirFor(ctx.config);
|
|
1927
|
-
const previousHash = await previousRefHash(refsDir, advancement.name);
|
|
1928
|
-
const advanced = await advanceRefSafely({
|
|
1929
|
-
refsDir,
|
|
1930
|
-
migrationsDir,
|
|
1931
|
-
name: advancement.name,
|
|
1932
|
-
hash: signed.contract.storageHash,
|
|
1933
|
-
contractIR: advancement.contractIR
|
|
2062
|
+
})];
|
|
2063
|
+
case "conflict": return [markerConflictDiagnostic(outcome, rerun)];
|
|
2064
|
+
default: return [];
|
|
2065
|
+
}
|
|
1934
2066
|
});
|
|
1935
|
-
if (!advanced.ok) return notOk$1(normalizeError(advanced.failure));
|
|
1936
|
-
const document = {
|
|
1937
|
-
...signed,
|
|
1938
|
-
advancedRef: advanced.value
|
|
1939
|
-
};
|
|
1940
2067
|
return ok$1(ctx.present({
|
|
1941
2068
|
data: document,
|
|
1942
|
-
exitCode: 0
|
|
2069
|
+
exitCode: unsigned.length === 0 ? 0 : FINDINGS_EXIT_CODE$2,
|
|
2070
|
+
...diagnostics.length === 0 ? {} : { diagnostics }
|
|
1943
2071
|
}, signPresentations({
|
|
1944
2072
|
document,
|
|
1945
|
-
advanced:
|
|
1946
|
-
...advanced.value,
|
|
1947
|
-
previousHash
|
|
1948
|
-
},
|
|
2073
|
+
advanced: advancement === null ? null : advanced,
|
|
1949
2074
|
header
|
|
1950
2075
|
})));
|
|
1951
2076
|
} catch (error) {
|