@prisma/orm-toolchain 8.0.0-rc.18-dev.13 → 8.0.0-rc.18-dev.14

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
@@ -11,7 +11,7 @@ import { d as writeRef, r as readRef } from "./refs-CS997f-J-BxkRLuCE.mjs";
11
11
  import { a as contractHashAtMarker } from "./aggregate-CJjYCgNP.mjs";
12
12
  import { i as createScaffoldSpecifierResolver } from "./import-roots-DXD7fung.mjs";
13
13
  import { o as isLiveMarkerRef } from "./ref-resolution-kNMjYJ26.mjs";
14
- import { $ as refuseMissingInvariantPath, A as executeRefDeleteCommand, B as loadContractRawSafely, D as executeMigrationNewCommand, E as executeMigrateShowPlan, F as hasMigrationPath, G as mapContractAtError, H as loadContractSourceWithStack, I as isStatementVerb, J as preflightRefAdvancement, L as listRefsByContractHash, M as executeRefSetCommand, N as findPackageByDirPath, O as executeMigrationPlanCommand, P as formatSourceDiagnostic, Q as refuseMarkerOutsideGraph, R as liveMarkerUse, U as loadContractSpaceAggregateForCli, V as loadContractSource, W as looksLikePath, X as refuseContractSpaceIntegrity, Y as readMigrationRefs, _ as deriveStatusEdgeAnnotations, _t as toDeclaredExtensionsFromRaw, a as RECORDED_OR_EMPTY_CONTRACT_REF_FORMS, at as resolveContractRefToSnapshot, b as enumerateCheckSpaces, c as appliedHashesFromLedger, d as buildReadAggregate, et as refusePackageCorruptionOnAggregate, f as buildRefAdvancementFields, ft as runMigrationCheck, g as createControlClient, gt as statusForMigrationHash, h as convertAndDelete, ht as sourceWarningDiagnostic, i as RECORDED_CONTRACT_REF_FORMS, it as resolveContractRef$1, j as executeRefListCommand, m as computeRefAdvancementName, mt as snapshotVerifierFor, n as DB_UPDATE_POLICY, nt as requireDatabaseForLiveMarkerUse, o as advanceRefSafely, p as checkSingleTarget, pt as runMigrationList, q as migrationSpaceListEntriesFromAggregate, r as NO_REF_ADVANCEMENT, rt as resolveAppTargetPath, st as resolveMigrationRef, t as ALL_CONTRACT_REF_FORMS, tt as refuseUnknownInvariants, u as buildMigrationSpaceGraphEntries, ut as retryCommandFor, vt as validateLoadedContract, x as executeContractEmit, z as loadAggregateIntegrityViolations } from "./ref-D0TsCUZG-jEQXQOEL.mjs";
14
+ import { $ as refuseMissingInvariantPath, A as executeRefDeleteCommand, B as loadContractRawSafely, D as executeMigrationNewCommand, E as executeMigrateShowPlan, F as hasMigrationPath, G as mapContractAtError, H as loadContractSourceWithStack, I as isStatementVerb, J as preflightRefAdvancement, L as listRefsByContractHash, M as executeRefSetCommand, N as findPackageByDirPath, O as executeMigrationPlanCommand, P as formatSourceDiagnostic, Q as refuseMarkerOutsideGraph, R as liveMarkerUse, U as loadContractSpaceAggregateForCli, V as loadContractSource, W as looksLikePath, X as refuseContractSpaceIntegrity, Y as readMigrationRefs, _ as deriveStatusEdgeAnnotations, _t as toDeclaredExtensionsFromRaw, a as RECORDED_OR_EMPTY_CONTRACT_REF_FORMS, at as resolveContractRefToSnapshot, b as enumerateCheckSpaces, c as appliedHashesFromLedger, d as buildReadAggregate, et as refusePackageCorruptionOnAggregate, f as buildRefAdvancementFields, ft as runMigrationCheck, g as createControlClient, gt as statusForMigrationHash, h as convertAndDelete, ht as sourceWarningDiagnostic, i as RECORDED_CONTRACT_REF_FORMS, it as resolveContractRef$1, j as executeRefListCommand, m as computeRefAdvancementName, mt as snapshotVerifierFor, n as DB_UPDATE_POLICY, nt as requireDatabaseForLiveMarkerUse, o as advanceRefSafely, p as checkSingleTarget, pt as runMigrationList, q as migrationSpaceListEntriesFromAggregate, r as NO_REF_ADVANCEMENT, rt as resolveAppTargetPath, st as resolveMigrationRef, t as ALL_CONTRACT_REF_FORMS, tt as refuseUnknownInvariants, u as buildMigrationSpaceGraphEntries, ut as retryCommandFor, vt as validateLoadedContract, x as executeContractEmit, z as loadAggregateIntegrityViolations } from "./ref-CPPMhLAs-Bxf2BJcA.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 { createRequire } from "node:module";
17
17
  import { ifDefined } from "@prisma/orm-framework/utils/defined";
@@ -40,7 +40,7 @@ import { applyEdits, modify, parse, printParseErrorCode } from "jsonc-parser";
40
40
  import stringWidth from "string-width";
41
41
  import { bold, createColors, cyan, cyanBright, dim, green, yellow } from "colorette";
42
42
  import { build } from "esbuild";
43
- //#region ../../../1-framework/3-tooling/cli/dist/load-config-Cu_HSms3.mjs
43
+ //#region ../../../1-framework/3-tooling/cli/dist/load-config-DfeXWusU.mjs
44
44
  /**
45
45
  * `isStructuredError` is the repo's own check, and it is the one that matters here: it holds the
46
46
  * regular expression for a dotted `NAMESPACE.SUBCODE`, so only a code the protocol accepts
@@ -766,6 +766,45 @@ function createContractPrintCommand({ printPsl }) {
766
766
  });
767
767
  }
768
768
  const contractPrintCommand = createContractPrintCommand({ printPsl });
769
+ const ABSENT = /^(?:ensure )?(.+?) (?:does not (?:already )?exist|is missing)( on .+)?$/;
770
+ const ABSENT_FROM = /^(?:ensure )?(.+?) is absent from (.+)$/;
771
+ const PRESENT = /^(?:ensure )?(.+?) exists( on .+)?$/;
772
+ /**
773
+ * Reads a check description, as the targets write it into an operation's precheck, for whether it expects an object absent or present, so the advice for a failed check can say what it means: `ensure index "x" does not exist`, `ensure column "y" does not exist on "item"`, `collection users does not exist`, `ensure column "x" is missing` and `ensure value "b" is absent from enum type "Mood"` expect it absent; `ensure table "x" exists` and `index exists on users` present. Any other description, `undefined`.
774
+ */
775
+ function readCheckDescription(description) {
776
+ const absent = ABSENT.exec(description);
777
+ if (absent?.[1] !== void 0) return {
778
+ expects: "absent",
779
+ object: `${absent[1]}${absent[2] ?? ""}`
780
+ };
781
+ const absentFrom = ABSENT_FROM.exec(description);
782
+ if (absentFrom?.[1] !== void 0 && absentFrom[2] !== void 0) return {
783
+ expects: "absent",
784
+ object: `${absentFrom[1]} in ${absentFrom[2]}`
785
+ };
786
+ const present = PRESENT.exec(description);
787
+ if (present?.[1] !== void 0) return {
788
+ expects: "present",
789
+ object: `${present[1]}${present[2] ?? ""}`
790
+ };
791
+ }
792
+ /** What a failed check before an operation means, in words: which check failed, and what that says of the database. */
793
+ function failedPrecheckWhy(report) {
794
+ const checked = `Before operation ${report.operationId} runs, it checks: ${report.description}.`;
795
+ const reading = readCheckDescription(report.description);
796
+ if (reading === void 0) return `${checked} That check failed on this database.`;
797
+ return reading.expects === "absent" ? `${checked} That check failed: the database already has ${reading.object}.` : `${checked} That check failed: the database has no ${reading.object}.`;
798
+ }
799
+ /** The way out of a failed check before an operation of `db migrate`. */
800
+ function migrateFailedPrecheckFix(report, invocation) {
801
+ const migrate = `\`${cliCommand(invocation, "db migrate")}\``;
802
+ return report.planStartsFromMarker ? `The database has drifted from its migration history: it is not in the state the migrations before this one leave. See how it differs from the contract with \`${cliCommand(invocation, "db verify")}\`, change the database or the migration so they agree, and run ${migrate} again.` : `The database has no migration marker, so ${migrate} applies every migration from the first, and the database may already be ahead of this one. If its schema already matches the contract, adopt it with \`${cliCommand(invocation, "db sign")}\` instead.`;
803
+ }
804
+ /** The way out of a failed check before an operation of `db init`, which runs only on a database with no marker. */
805
+ function dbInitFailedPrecheckFix(invocation) {
806
+ return `The database already holds part of the schema \`${cliCommand(invocation, "db init")}\` would create. If its schema already matches the contract, adopt it with \`${cliCommand(invocation, "db sign")}\` instead.`;
807
+ }
769
808
  /** What a runner failure says of a type change that failed: who converted the values, and how it failed. */
770
809
  function failedTypeChangeText(change) {
771
810
  if (change.by === "cast") return change.reason === "noCast" ? `The database has no cast from the old type of field "${change.field}" to its new type.` : `A value of field "${change.field}" cannot be converted to its new type by the database's cast.`;
@@ -898,6 +937,7 @@ function migrateFix(failure, invocation) {
898
937
  const failedMigration = failure.failedMigration === void 0 ? void 0 : failedMigrationText(failure.failedMigration, invocation);
899
938
  if (failure.failedTypeChange !== void 0) return migrateFailedTypeChangeFix(failure.failedTypeChange, failedMigration, invocation);
900
939
  if (failure.rowsWithoutValue !== void 0) return migrateRowsWithoutValueFix(failure.rowsWithoutValue, failedMigration, invocation);
940
+ if (failure.failedPrecheck !== void 0) return migrateFailedPrecheckFix(failure.failedPrecheck, invocation);
901
941
  return `Fix the issue and re-run \`${cliCommand(invocation, "db migrate", ["--to", "<contract>"])}\` — previously applied migrations are preserved.`;
902
942
  }
903
943
  const DB_INIT_ADDITIVE_ONLY_FIX = "`db init` applies only additive changes. Run `{bin} db update`, which also applies widening and destructive ones once you answer what each operation that would lose data means, with `--delete` or `--rename`.";
@@ -955,9 +995,9 @@ function mapDbInitFailure(failure, invocation) {
955
995
  });
956
996
  if (failure.code === "RUNNER_FAILED") {
957
997
  const runnerCode = typeof failure.meta?.["runnerErrorCode"] === "string" ? failure.meta["runnerErrorCode"] : void 0;
958
- const fix = failure.rowsWithoutValue !== void 0 ? dbInitRowsWithoutValueFix(failure.rowsWithoutValue, invocation) : runnerCode === "MIGRATION.LEGACY_MARKER_SHAPE" ? "Legacy marker-table shape detected. Drop `prisma_contract.marker` (Postgres) or `_prisma_marker` (SQLite) and re-run `{bin} db init` to recreate it with the current per-space schema." : "Fix the schema mismatch (db init is additive-only), or drop/reset the database and re-run `{bin} db init`";
998
+ const fix = failure.rowsWithoutValue !== void 0 ? dbInitRowsWithoutValueFix(failure.rowsWithoutValue, invocation) : failure.failedPrecheck !== void 0 ? dbInitFailedPrecheckFix(invocation) : runnerCode === "MIGRATION.LEGACY_MARKER_SHAPE" ? "Legacy marker-table shape detected. Drop `prisma_contract.marker` (Postgres) or `_prisma_marker` (SQLite) and re-run `{bin} db init` to recreate it with the current per-space schema." : "Fix the schema mismatch (db init is additive-only), or drop/reset the database and re-run `{bin} db init`";
959
999
  return errorRunnerFailed(failure.summary, {
960
- why: failure.why ?? "Migration runner failed",
1000
+ why: failure.why ?? (failure.failedPrecheck === void 0 ? "Migration runner failed" : failedPrecheckWhy(failure.failedPrecheck)),
961
1001
  fix,
962
1002
  ...ifDefined("meta", failure.meta),
963
1003
  ...ifDefined("cause", failure.cause)
@@ -2271,7 +2311,7 @@ function mapDbUpdateFailure(failure, invocation) {
2271
2311
  const runnerCode = typeof failure.meta?.["runnerErrorCode"] === "string" ? failure.meta["runnerErrorCode"] : void 0;
2272
2312
  const fix = failure.failedTypeChange !== void 0 ? dbUpdateFailedTypeChangeFix(failure.failedTypeChange, failure.databaseStorageHash, invocation) : failure.rowsWithoutValue !== void 0 ? dbUpdateRowsWithoutValueFix(failure.rowsWithoutValue, failure.databaseStorageHash, invocation) : runnerCode === "MIGRATION.LEGACY_MARKER_SHAPE" ? `Legacy marker-table shape detected. Drop \`prisma_contract.marker\` (Postgres) or \`_prisma_marker\` (SQLite) and re-run \`${cliCommand(invocation, "db init")}\` to recreate it with the current per-space schema.` : `Inspect the reported conflict, reconcile schema drift if needed, then re-run \`${cliCommand(invocation, "db update")}\``;
2273
2313
  return errorRunnerFailed(failure.summary, {
2274
- why: failure.why ?? "Migration runner failed",
2314
+ why: failure.why ?? (failure.failedPrecheck === void 0 ? "Migration runner failed" : failedPrecheckWhy(failure.failedPrecheck)),
2275
2315
  fix,
2276
2316
  meta: {
2277
2317
  ...failure.meta,
@@ -9399,7 +9439,7 @@ function migrateShowRunListRows(migrations, rendering, options) {
9399
9439
  function mapMigrateFailure(failure, invocation) {
9400
9440
  if (failure.code === "MIGRATION_PATH_NOT_FOUND") return errorPathUnreachable(failure);
9401
9441
  return errorRunnerFailed(failure.summary, {
9402
- why: failure.why ?? "Migration runner failed",
9442
+ why: failure.why ?? (failure.failedPrecheck === void 0 ? "Migration runner failed" : failedPrecheckWhy(failure.failedPrecheck)),
9403
9443
  fix: migrateFix(failure, invocation),
9404
9444
  meta: failure.meta ?? {},
9405
9445
  ...ifDefined("cause", failure.cause)