@prisma/composer-prisma-cloud 0.14.0-dev.1 → 0.14.0-dev.3

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.
@@ -472,7 +472,7 @@ function mintKeyPair() {
472
472
  };
473
473
  }
474
474
  //#endregion
475
- //#region ../../1-prisma-cloud/1-extensions/target/dist/s3-credentials-resource-BUsjCFtj.mjs
475
+ //#region ../../1-prisma-cloud/1-extensions/target/dist/s3-credentials-resource-C0A8Q7aA.mjs
476
476
  const PRISMA_CLOUD_EXTENSION_ID = "@prisma/composer-prisma-cloud";
477
477
  /** Accepts exactly what Alchemy's own `--stage` validation accepts (pinned 2.0.0-beta.59, `Cli/commands/_shared.ts`), rewritten without overlapping quantifiers so it cannot backtrack catastrophically. Asserted before a Branch id is exposed as a stage. */
478
478
  const ALCHEMY_STAGE_PATTERN = /^[a-z0-9][-_a-z0-9]*$/i;
@@ -758,7 +758,7 @@ const PgWarmProvider = () => Provider.effect(PgWarm, Effect.succeed(pgWarmProvid
758
758
  /**
759
759
  * Resolves a `pnPostgres` resource's `prisma-next.config.ts` path to the
760
760
  * project facts the deploy needs (ADR-0022, slice 2): the on-disk migrations
761
- * directory the control client's `migrate`/`dbInit` read, and the declared
761
+ * directory the control client's `migrate` reads, and the declared
762
762
  * extension packs. Deploy-time only: loads PN's config (via c12) and applies
763
763
  * PN's own convention — `migrations.dir`, or the default `migrations/`,
764
764
  * relative to the config file's directory (mirrors the CLI's
@@ -808,19 +808,21 @@ function packHeadRefHashes(packs) {
808
808
  * A→A self-edge the deploy wrongly skips. The decision, given the live marker
809
809
  * and the target ref (see {@link decideMigrationAction}):
810
810
  * - marker at ref.hash AND ref.invariants ⊆ marker.invariants → no-op
811
- * - no marker (fresh DB) AND no required invariants → `dbInit`
812
811
  * - otherwise → `migrate`
813
812
  *
814
- * `dbInit` is additive-only synthesis it NEVER runs app-space data steps
815
- * so it is only correct when the ref requires no invariants; a fresh DB whose
816
- * target carries invariants goes through `migrate`, which walks the AUTHORED
817
- * graph (including the invariant-bearing data migrations) from empty.
818
- *
819
- * Never `dbUpdate`: synthesized diff-and-apply plans are never run against a
820
- * deployed database. A no-authored-path (`MIGRATION_PATH_NOT_FOUND`) or a
821
- * runner failure fails the deploy as a typed `PnMigrationError` (not swallowed).
822
- * PN applies each migration in its own transaction, so a failed apply is atomic
823
- * and resume-safe the marker and schema are left as the last committed step.
813
+ * Replay-only (ADR-0022 as revised): the pipeline replays what was authored,
814
+ * it never authors. A fresh database (no marker) is not special its start
815
+ * point is empty and `migrate` walks the AUTHORED graph from empty to the
816
+ * target, so the first deploy applies the committed baseline like any other
817
+ * migration. No synthesis of any kind runs at deploy: never `dbInit` (schema
818
+ * synthesized from the contract) and never `dbUpdate` (synthesized
819
+ * diff-and-apply). A missing authored path (`MIGRATION_PATH_NOT_FOUND`) is a
820
+ * structured refusal whose message names the two exits `prisma db update`
821
+ * for local iteration, `prisma contract emit && prisma migration plan` to
822
+ * author the path for shipping. A runner failure fails the deploy as a typed
823
+ * `PnMigrationError` (not swallowed). PN applies each migration in its own
824
+ * transaction, so a failed apply is atomic and resume-safe — the marker and
825
+ * schema are left as the last committed step.
824
826
  */
825
827
  /** A deploy-failing migration error — surfaced, never swallowed. */
826
828
  var PnMigrationError = class extends Error {
@@ -835,6 +837,16 @@ var PnMigrationError = class extends Error {
835
837
  }
836
838
  };
837
839
  /**
840
+ * The replay-only refusal for a missing authored path. The pipeline never
841
+ * authors schema, so the only fix is to bring one of the two sides along:
842
+ * update the database directly (local iteration) or author and commit the
843
+ * missing migrations (shipping). The same message serves a deploy against a
844
+ * cloud database and a `dev` run against the local emulator database.
845
+ */
846
+ function noPathRefusal(summary, markerHashBefore, aggregate) {
847
+ return `${aggregate ? "The committed migrations/ directory has no authored path to the target in every declared migration space" : markerHashBefore === null ? "The database carries no schema marker and the committed migrations/ directory has no authored path from empty to the target" : `The committed migrations/ directory has no authored path from the database's current schema (${markerHashBefore}) to the target`} — the deploy pipeline only replays authored migrations, it never creates schema itself. Iterating locally? Bring the database along with \`prisma db update\`. Shipping? Author the migration path — \`prisma contract emit && prisma migration plan --name <slug>\` (baseline first if the migration graph is empty) — and commit migrations/. (${summary})`;
848
+ }
849
+ /**
838
850
  * The target `storageHash` a contract heads to — `contractJson.storage.storageHash`.
839
851
  * Read defensively: `contractJson` crosses the boundary as `unknown`.
840
852
  */
@@ -846,7 +858,7 @@ function targetStorageHash(contractJson) {
846
858
  if (typeof hash === "string" && hash.length > 0) return hash;
847
859
  }
848
860
  }
849
- throw new PnMigrationError("INIT_FAILED", "the contract has no storage.storageHash — cannot determine the target schema version");
861
+ throw new PnMigrationError("CONTRACT_INVALID", "the contract has no storage.storageHash — cannot determine the target schema version");
850
862
  }
851
863
  /**
852
864
  * Resolve the deploy's target ref from the migrations dir.
@@ -886,23 +898,20 @@ async function resolveTargetRef(migrationsDir, contractJson, targetRef) {
886
898
  /**
887
899
  * The pure migration decision, mirroring PN's own verifier: the database is
888
900
  * AT the target when the marker's hash equals the ref's hash AND every ref
889
- * invariant is on the marker (marker invariants are monotonic). `dbInit` is
890
- * additive-only synthesis, so it is chosen only for a fresh DB whose
891
- * effective required invariants (`ref.invariants marker.invariants`) are
892
- * empty; anything else different hash, missing invariant (the A→A
893
- * data-only self-edge), or a fresh DB with required invariants — walks the
894
- * authored graph via `migrate`.
901
+ * invariant is on the marker (marker invariants are monotonic). Anything
902
+ * else — different hash, missing invariant (the A→A data-only self-edge),
903
+ * or a fresh DB (whose start point is empty) — walks the authored graph via
904
+ * `migrate`. The pipeline never synthesizes.
895
905
  */
896
906
  function decideMigrationAction(marker, ref) {
897
907
  const markerInvariants = new Set(marker?.invariants ?? []);
898
908
  const missing = ref.invariants.filter((id) => !markerInvariants.has(id));
899
909
  if (marker !== null && marker.storageHash === ref.hash && missing.length === 0) return "noop";
900
- if (marker === null && missing.length === 0) return "init";
901
910
  return "migrate";
902
911
  }
903
912
  /**
904
913
  * Bring the database at `url` to the target ref via PN's authored migrations.
905
- * Reads the live marker, decides no-op / init / migrate
914
+ * Reads the live marker, decides no-op / migrate
906
915
  * ({@link decideMigrationAction}), applies, and throws a typed
907
916
  * {@link PnMigrationError} on a no-path or runner failure. `migrationsDir` is
908
917
  * the on-disk migrations root and `ref` the resolved target
@@ -933,19 +942,6 @@ async function runMigration(connection, contractJson, migrationsDir, ref, refNam
933
942
  };
934
943
  action = "migrate";
935
944
  }
936
- if (action === "init") {
937
- const result = await client.dbInit({
938
- contract: contractJson,
939
- mode: "apply",
940
- migrationsDir
941
- });
942
- if (!result.ok) throw new PnMigrationError("INIT_FAILED", result.failure.summary, result.failure.why);
943
- return {
944
- action,
945
- targetHash: ref.hash,
946
- markerHashBefore
947
- };
948
- }
949
945
  const result = await client.migrate({
950
946
  contract: contractJson,
951
947
  migrationsDir,
@@ -955,7 +951,10 @@ async function runMigration(connection, contractJson, migrationsDir, ref, refNam
955
951
  refName
956
952
  } : {}
957
953
  });
958
- if (!result.ok) throw new PnMigrationError(result.failure.code === "MIGRATION_PATH_NOT_FOUND" ? "MIGRATION_PATH_NOT_FOUND" : "RUNNER_FAILED", result.failure.summary, result.failure.why);
954
+ if (!result.ok) {
955
+ if (result.failure.code === "MIGRATION_PATH_NOT_FOUND") throw new PnMigrationError("MIGRATION_PATH_NOT_FOUND", noPathRefusal(result.failure.summary, markerHashBefore, extensionPacks.length > 0), result.failure.why);
956
+ throw new PnMigrationError("RUNNER_FAILED", result.failure.summary, result.failure.why);
957
+ }
959
958
  return {
960
959
  action,
961
960
  targetHash: ref.hash,
@@ -991,7 +990,7 @@ const PnMigration = Resource("PrismaNext.Migration");
991
990
  * The `PnMigration` provider service. `reconcile` runs for both create and
992
991
  * update (Alchemy's unified lifecycle); `applyPnMigration` is idempotent via
993
992
  * the live marker read, so it is safe to run for either — the marker decides
994
- * no-op / init / migrate. A migration has nothing to enumerate (`list` → `[]`)
993
+ * no-op / migrate. A migration has nothing to enumerate (`list` → `[]`)
995
994
  * and nothing to tear down on its own (`delete` → no-op; the DB's own deletion
996
995
  * handles teardown). Exported so tests can drive `reconcile` directly, without
997
996
  * building an Effect layer.
@@ -1091,4 +1090,4 @@ const S3CredentialsProvider = () => Provider.effect(S3Credentials, Effect.succee
1091
1090
  //#endregion
1092
1091
  export { collectPages as A, appAfterEnvironment as C, RESERVED_DATABASE_URL_KEYS as D, PrismaApiError as E, fromEnv as F, managementApiBaseUrl as I, layer as M, resolveDefaultBranchId as N, call as O, PrismaCredentials as P, ServiceKeyProvider as S, ManagementClient as T, resolveTargetRef as _, PgWarmProvider as a, providers as b, PrismaCloudContainer as c, collectPreflightNames as d, containerDescriptor as f, resolvePrismaNextConfig as g, prismaCloudContainerOf as h, PgWarm as i, drivePagesAsync as j, claimDatabaseUrlKeys as k, S3Credentials as l, packHeadRefHashes as m, GeneratedParamProvider as n, PnMigration as o, deserialize as p, PRISMA_CLOUD_EXTENSION_ID as r, PnMigrationProvider as s, GeneratedParam as t, S3CredentialsProvider as u, mintKeyPair as v, isWithin as w, ServiceKey as x, Providers as y };
1093
1092
 
1094
- //# sourceMappingURL=s3-credentials-resource-BUsjCFtj-BzHGBAmT.mjs.map
1093
+ //# sourceMappingURL=s3-credentials-resource-C0A8Q7aA-Dcl7iuHj.mjs.map