@prisma/orm-toolchain 8.0.0-rc.9-dev.11 → 8.0.0-rc.9-dev.13

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/cli.mjs CHANGED
@@ -1,8 +1,10 @@
1
1
  import { r as getEmittedArtifactPaths } from "./exports-CE6OD63o-4Qpqr2W7.mjs";
2
+ import { t as MigrationToolsError } from "./errors-SoLLYLtw-DMxVbVs9.mjs";
2
3
  import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
4
+ import { r as readRef } from "./refs-BpSpzdYB-BcDelHGt.mjs";
3
5
  import { c as spaceMigrationDirectory } from "./verify-contract-spaces-CrxvgpwD-D5LLXGci.mjs";
4
6
  import { i as createScaffoldSpecifierResolver } from "./import-roots-BHOrDJbI.mjs";
5
- import { $ as loadContractRawSafely, A as errorMigrationPlanningFailed, At as statusForMigrationHash, C as errorDestructiveChanges, Ct as resolveRefAdvancementFields, D as errorLegendHumanOnly, Dt as runMigrationCheck, E as errorHashMismatch, F as errorTargetMigrationNotSupported, H as executeMigrateShowPlan, I as errorTargetMismatch, J as executeRefSetCommand, K as executeRefDeleteCommand, L as errorUnexpected, M as errorPathUnreachable, Mt as toDeclaredExtensionsFromRaw, N as errorRunnerFailed, O as errorMarkerMissing, Ot as runMigrationList, P as errorRuntime, Q as loadAggregateIntegrityViolations, R as executeContractEmit, S as errorDatabaseConnectionRequired, St as resolveMigrationRef, T as errorFileNotFound, Tt as runCommandAction, U as executeMigrationNewCommand, W as executeMigrationPlanCommand, X as hasMigrationPath, Y as findPackageByDirPath, Z as listRefsByContractHash, _ as enumerateCheckSpaces, _t as requireLiveDatabase, at as maskConnectionUrl, b as errorContractArgConflict, bt as resolveContractRefToSnapshot, ct as readContractEnvelope, d as closeQuietly, dt as refuseContractSpaceIntegrity, et as loadContractSpaceAggregateForCli, gt as refuseUnknownInvariants, ht as refusePackageCorruptionOnAggregate, i as appliedHashesFromLedger, j as errorNoMigrations, jt as targetSupportsMigrations, k as errorMigrationPackageNotFound, kt as sanitizeErrorMessage, l as checkSingleTarget, lt as readContractIR, m as deriveStatusEdgeAnnotations, mt as refuseMissingInvariantPath, n as advanceRefSafely, nt as mapCaughtMigrationError, o as buildMigrationSpaceGraphEntries, ot as migrationSpaceListEntriesFromAggregate, p as createControlClient, pt as refuseMarkerOutsideGraph, q as executeRefListCommand, rt as mapContractAtError, s as buildReadAggregate, st as originHashForStatus, t as CliStructuredError$1$1, tt as looksLikePath, u as chooseAction, ut as readMigrationRefs, v as errorConfigValidation$1, vt as resolveAppTargetPath, w as errorDriverRequired, x as errorContractValidationFailed, y as errorConsentPlanMismatch, yt as resolveContractRef$1 } from "./ref-BPBIUGrB-BQt8iSyJ.mjs";
7
+ import { $ as loadAggregateIntegrityViolations, A as errorMigrationPackageNotFound, At as runMigrationList, C as errorDatabaseConnectionRequired, D as errorHashMismatch, Dt as runCommandAction, E as errorFileNotFound, F as errorRuntime, G as executeMigrationPlanCommand, I as errorTargetMigrationNotSupported, J as executeRefListCommand, L as errorTargetMismatch, M as errorNoMigrations, Mt as statusForMigrationHash, N as errorPathUnreachable, Nt as targetSupportsMigrations, O as errorLegendHumanOnly, P as errorRunnerFailed, Pt as toDeclaredExtensionsFromRaw, Q as listRefsByContractHash, R as errorUnexpected, S as errorContractValidationFailed, St as resolveContractRefToSnapshot, T as errorDriverRequired, Tt as resolveRefAdvancementFields, U as executeMigrateShowPlan, W as executeMigrationNewCommand, X as findPackageByDirPath, Y as executeRefSetCommand, Z as hasMigrationPath, _ as enumerateCheckSpaces, _t as refusePackageCorruptionOnAggregate, b as errorConsentPlanMismatch, bt as resolveAppTargetPath, ct as originHashForStatus, d as closeQuietly, dt as readContractIR, et as loadContractRawSafely, ft as readMigrationRefs, gt as refuseMissingInvariantPath, ht as refuseMarkerOutsideGraph, i as appliedHashesFromLedger, it as mapContractAtError, j as errorMigrationPlanningFailed, jt as sanitizeErrorMessage, k as errorMarkerMissing, kt as runMigrationCheck, l as checkSingleTarget, lt as preflightRefAdvancement, m as deriveStatusEdgeAnnotations, n as advanceRefSafely, nt as looksLikePath, o as buildMigrationSpaceGraphEntries, ot as maskConnectionUrl, p as createControlClient, pt as refuseContractSpaceIntegrity, q as executeRefDeleteCommand, rt as mapCaughtMigrationError, s as buildReadAggregate, st as migrationSpaceListEntriesFromAggregate, t as CliStructuredError$1$1, tt as loadContractSpaceAggregateForCli, u as chooseAction, ut as readContractEnvelope, v as errorAdvanceRefArgConflict, vt as refuseUnknownInvariants, w as errorDestructiveChanges, wt as resolveMigrationRef, x as errorContractArgConflict, xt as resolveContractRef$1, y as errorConfigValidation$1, yt as requireLiveDatabase, z as executeContractEmit } from "./ref-DcqFmceq-QaUjgZeM.mjs";
6
8
  import { n as buildNextSteps, t as InitOutputSchema } from "./output-D83nTTpC-XlvN30yS.mjs";
7
9
  import { r as loadConfig, t as finalizeConfig } from "./exports-BXXeNWlj.mjs";
8
10
  import { createRequire } from "node:module";
@@ -33,7 +35,7 @@ import { applyEdits, modify, parse, printParseErrorCode } from "jsonc-parser";
33
35
  import stringWidth from "string-width";
34
36
  import { bold, createColors, cyan, cyanBright, dim, green, yellow } from "colorette";
35
37
  import { build } from "esbuild";
36
- //#region ../../../1-framework/3-tooling/cli/dist/load-config-CWwenkv5.mjs
38
+ //#region ../../../1-framework/3-tooling/cli/dist/load-config-Dg1SXbzd.mjs
37
39
  const MISSING_CONFIG_ACTION = {
38
40
  kind: "run-command",
39
41
  label: "Create a config file",
@@ -1303,8 +1305,10 @@ async function readEmittedContract(inputs) {
1303
1305
  }
1304
1306
  const familyInstance = inputs.config.family.create(createControlStack(inputs.config));
1305
1307
  try {
1308
+ const json = castAs(JSON.parse(content));
1306
1309
  return ok$1({
1307
- contract: familyInstance.deserializeContract(castAs(JSON.parse(content))),
1310
+ contract: familyInstance.deserializeContract(json),
1311
+ json,
1308
1312
  path,
1309
1313
  displayPath: relativePath
1310
1314
  });
@@ -1456,6 +1460,30 @@ function schemaVerdictDiagnostic(inputs) {
1456
1460
  const FINDINGS_EXIT_CODE$2 = 4;
1457
1461
  /** The config file this bin reads; the handler is not told which one was loaded. */
1458
1462
  const CONFIG_DISPLAY_PATH = "prisma.config.ts";
1463
+ /**
1464
+ * The ref a signature checkpoints. Unlike `db init` / `db update`, `--db` does
1465
+ * not suppress the write: signing does not touch the schema, and adoption is
1466
+ * normally done against the real database via `--db`. Only `--no-advance-ref`
1467
+ * suppresses it.
1468
+ */
1469
+ const DEFAULT_ADVANCE_REF = "db";
1470
+ const NO_PREVIOUS_HASH_CODES = /* @__PURE__ */ new Set([
1471
+ "MIGRATION.UNKNOWN_REF",
1472
+ "MIGRATION.INVALID_REF_FILE",
1473
+ "MIGRATION.INVALID_REF_NAME"
1474
+ ]);
1475
+ /**
1476
+ * The hash the ref held before the signature, read from that one ref file so a
1477
+ * corrupt sibling cannot fail a signature already written.
1478
+ */
1479
+ async function previousRefHash(refsDir, name) {
1480
+ try {
1481
+ return (await readRef(refsDir, name)).hash;
1482
+ } catch (error) {
1483
+ if (MigrationToolsError.is(error) && NO_PREVIOUS_HASH_CODES.has(error.code)) return;
1484
+ throw error;
1485
+ }
1486
+ }
1459
1487
  function headerBlock$1(inputs) {
1460
1488
  return {
1461
1489
  kind: "fields",
@@ -1469,6 +1497,41 @@ function headerBlock$1(inputs) {
1469
1497
  }]
1470
1498
  };
1471
1499
  }
1500
+ function advancedRefSpans(advanced) {
1501
+ return [
1502
+ { text: `Advanced ref "${advanced.name}" → ` },
1503
+ {
1504
+ text: advanced.hash,
1505
+ tone: "identifier"
1506
+ },
1507
+ ...advanced.previousHash === void 0 ? [] : [
1508
+ {
1509
+ text: " (was ",
1510
+ tone: "muted"
1511
+ },
1512
+ {
1513
+ text: advanced.previousHash,
1514
+ tone: "identifier"
1515
+ },
1516
+ {
1517
+ text: ")",
1518
+ tone: "muted"
1519
+ }
1520
+ ]
1521
+ ];
1522
+ }
1523
+ function refOutcomeBlock(advanced) {
1524
+ return advanced === null ? {
1525
+ kind: "summary",
1526
+ status: "info",
1527
+ tone: "muted",
1528
+ text: `Left ref "${DEFAULT_ADVANCE_REF}" untouched (--no-advance-ref)`
1529
+ } : {
1530
+ kind: "summary",
1531
+ status: "ok",
1532
+ text: advancedRefSpans(advanced)
1533
+ };
1534
+ }
1472
1535
  function signPresentations(inputs) {
1473
1536
  const marker = inputs.document.marker;
1474
1537
  return {
@@ -1499,7 +1562,8 @@ function signPresentations(inputs) {
1499
1562
  tone: "identifier"
1500
1563
  }]
1501
1564
  }]
1502
- }
1565
+ },
1566
+ refOutcomeBlock(inputs.advanced)
1503
1567
  ],
1504
1568
  json: () => inputs.document
1505
1569
  };
@@ -1532,12 +1596,14 @@ function createDbSignCommand(createClient = createControlClient) {
1532
1596
  return defineOrmCommand({
1533
1597
  help: {
1534
1598
  summary: "Sign the database with your contract so you can safely run queries",
1535
- description: "Verifies that your database schema satisfies the emitted contract, and if\nso, writes or updates the database signature. Idempotent and safe to run\nin CI or a deployment pipeline. The signature records that this database\ninstance is aligned with a specific contract version.\nExit codes: 0 = signed, 2 = the command could not run (unresolvable\ncontract reference, no emitted contract, unreachable database),\n4 = schema verification failed and no signature was written.",
1599
+ description: "Verifies that your database schema satisfies the emitted contract, and if\nso, writes or updates the database signature. The signature records that\nthis database instance is aligned with a specific contract version.\nIdempotent. After signing, the db ref in the checkout is advanced to the\nsigned 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),\n4 = schema verification failed and no signature was written.",
1536
1600
  examples: [
1537
1601
  "db sign",
1538
1602
  "db sign --db $DATABASE_URL",
1539
1603
  "db sign production --db $DATABASE_URL",
1540
- "db sign --contract production --db $DATABASE_URL"
1604
+ "db sign --contract production --db $DATABASE_URL",
1605
+ "db sign --db $DATABASE_URL --advance-ref production",
1606
+ "db sign --db $DATABASE_URL --no-advance-ref"
1541
1607
  ]
1542
1608
  },
1543
1609
  args: {
@@ -1550,7 +1616,12 @@ function createDbSignCommand(createClient = createControlClient) {
1550
1616
  contract: flag.string({
1551
1617
  brief: "Contract reference (hash, prefix, ref name, migration dir name, <dir>^, or ./path)",
1552
1618
  placeholder: "contract"
1553
- })
1619
+ }),
1620
+ advanceRef: flag.string({
1621
+ brief: "Advance the named ref to the post-command contract hash",
1622
+ placeholder: "name"
1623
+ }),
1624
+ noAdvanceRef: flag.boolean({ brief: "Sign without advancing any ref (no ref file or snapshot is written)" })
1554
1625
  }
1555
1626
  },
1556
1627
  needs: { config: ormConfigSection },
@@ -1563,23 +1634,47 @@ function createDbSignCommand(createClient = createControlClient) {
1563
1634
  flag: flagContract
1564
1635
  })));
1565
1636
  const contractRef = positionalContract ?? flagContract;
1637
+ if (args.flags.noAdvanceRef && args.flags.advanceRef !== void 0) return notOk$1(normalizeError(errorAdvanceRefArgConflict({ advanceRef: args.flags.advanceRef })));
1566
1638
  const emitted = await readEmittedContract({
1567
1639
  config: ctx.config,
1568
1640
  cwd: ctx.cwd,
1569
1641
  commandName: "db sign"
1570
1642
  });
1571
1643
  if (!emitted.ok) return notOk$1(emitted.failure);
1644
+ const migrationsDir = migrationsDirFor(ctx.config, ctx.cwd);
1572
1645
  let contractInput = emitted.value.contract;
1646
+ let signedSource;
1573
1647
  if (contractRef !== void 0) {
1574
1648
  const resolvedRef = await resolveContractRefToSnapshot({
1575
1649
  config: ctx.config,
1576
- migrationsDir: migrationsDirFor(ctx.config, ctx.cwd),
1650
+ migrationsDir,
1577
1651
  refInput: contractRef,
1578
1652
  contractPathAbsolute: emitted.value.path,
1579
1653
  fallbackToEmitted: true
1580
1654
  });
1581
1655
  if (!resolvedRef.ok) return notOk$1(normalizeError(resolvedRef.failure));
1582
1656
  contractInput = resolvedRef.value.contractJson;
1657
+ signedSource = {
1658
+ json: resolvedRef.value.contractJson,
1659
+ jsonPath: resolvedRef.value.contractJsonPath
1660
+ };
1661
+ } else signedSource = {
1662
+ json: emitted.value.json,
1663
+ jsonPath: emitted.value.path
1664
+ };
1665
+ const refName = args.flags.noAdvanceRef ? null : args.flags.advanceRef ?? DEFAULT_ADVANCE_REF;
1666
+ let advancement = null;
1667
+ if (refName !== null) {
1668
+ const preflight = await preflightRefAdvancement({
1669
+ name: refName,
1670
+ contractJson: signedSource.json,
1671
+ contractJsonPath: signedSource.jsonPath
1672
+ });
1673
+ if (!preflight.ok) return notOk$1(normalizeError(preflight.failure));
1674
+ advancement = {
1675
+ name: refName,
1676
+ contractIR: preflight.value
1677
+ };
1583
1678
  }
1584
1679
  const connection = requireVerifyConnection({
1585
1680
  config: ctx.config,
@@ -1629,11 +1724,43 @@ function createDbSignCommand(createClient = createControlClient) {
1629
1724
  onProgress
1630
1725
  });
1631
1726
  if (!signed.ok) throw new InternalError(`The family returned a sign result that did not sign: ${signed.summary}`);
1727
+ if (advancement === null) {
1728
+ const document = {
1729
+ ...signed,
1730
+ advancedRef: null
1731
+ };
1732
+ return ok$1(ctx.present({
1733
+ data: document,
1734
+ exitCode: 0
1735
+ }, signPresentations({
1736
+ document,
1737
+ advanced: null,
1738
+ header
1739
+ })));
1740
+ }
1741
+ const refsDir = appRefsDirFor(ctx.config, ctx.cwd);
1742
+ const previousHash = await previousRefHash(refsDir, advancement.name);
1743
+ const advanced = await advanceRefSafely({
1744
+ refsDir,
1745
+ migrationsDir,
1746
+ name: advancement.name,
1747
+ hash: signed.contract.storageHash,
1748
+ contractIR: advancement.contractIR
1749
+ });
1750
+ if (!advanced.ok) return notOk$1(normalizeError(advanced.failure));
1751
+ const document = {
1752
+ ...signed,
1753
+ advancedRef: advanced.value
1754
+ };
1632
1755
  return ok$1(ctx.present({
1633
- data: signed,
1756
+ data: document,
1634
1757
  exitCode: 0
1635
1758
  }, signPresentations({
1636
- document: signed,
1759
+ document,
1760
+ advanced: {
1761
+ ...advanced.value,
1762
+ previousHash
1763
+ },
1637
1764
  header
1638
1765
  })));
1639
1766
  } catch (error) {
@@ -8372,6 +8499,15 @@ function previewBlocks$1(result) {
8372
8499
  lines: statements
8373
8500
  }];
8374
8501
  }
8502
+ function originNoticeBlocks(result) {
8503
+ if (result.fromDefaulted !== true) return [];
8504
+ return [{
8505
+ kind: "summary",
8506
+ status: "info",
8507
+ tone: "muted",
8508
+ text: "No db ref set — planning from an empty database. Run db init, db update, or db sign if a database already exists."
8509
+ }];
8510
+ }
8375
8511
  function planBlocks(result, migrationsRelative) {
8376
8512
  const outcome = outcomeFields(result, migrationsRelative);
8377
8513
  if (result.noOp) return [{
@@ -8379,17 +8515,22 @@ function planBlocks(result, migrationsRelative) {
8379
8515
  status: "ok",
8380
8516
  text: "No changes detected"
8381
8517
  }, outcome];
8382
- if (result.pendingPlaceholders === true) return [{
8383
- kind: "summary",
8384
- status: "warn",
8385
- text: result.summary
8386
- }, outcome];
8518
+ if (result.pendingPlaceholders === true) return [
8519
+ {
8520
+ kind: "summary",
8521
+ status: "warn",
8522
+ text: result.summary
8523
+ },
8524
+ ...originNoticeBlocks(result),
8525
+ outcome
8526
+ ];
8387
8527
  return [
8388
8528
  {
8389
8529
  kind: "summary",
8390
8530
  status: "ok",
8391
8531
  text: result.summary
8392
8532
  },
8533
+ ...originNoticeBlocks(result),
8393
8534
  ...operationBlocks$1(result),
8394
8535
  outcome,
8395
8536
  ...previewBlocks$1(result)