@prisma-next/target-postgres 0.12.0-dev.4 → 0.12.0-dev.40

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.
Files changed (158) hide show
  1. package/dist/{codec-ids-DliyCWPY.d.mts → codec-ids-Cx7C07Y_.d.mts} +3 -2
  2. package/dist/codec-ids-Cx7C07Y_.d.mts.map +1 -0
  3. package/dist/{codec-ids-C5qzBqus.mjs → codec-ids-DTqscwN9.mjs} +3 -2
  4. package/dist/codec-ids-DTqscwN9.mjs.map +1 -0
  5. package/dist/codec-ids.d.mts +2 -2
  6. package/dist/codec-ids.mjs +2 -2
  7. package/dist/{codec-types-BF1DXTPs.d.mts → codec-types-BoxMGJk-.d.mts} +2 -2
  8. package/dist/{codec-types-BF1DXTPs.d.mts.map → codec-types-BoxMGJk-.d.mts.map} +1 -1
  9. package/dist/codec-types.d.mts +1 -1
  10. package/dist/{codecs-DuP3d9Au.d.mts → codecs-DCSyTOCb.d.mts} +2 -2
  11. package/dist/codecs-DCSyTOCb.d.mts.map +1 -0
  12. package/dist/codecs.d.mts +1 -1
  13. package/dist/codecs.mjs +37 -2
  14. package/dist/codecs.mjs.map +1 -1
  15. package/dist/column-type-compatibility-Dzxz_CkP.mjs +11 -0
  16. package/dist/column-type-compatibility-Dzxz_CkP.mjs.map +1 -0
  17. package/dist/column-type-compatibility.d.mts +5 -0
  18. package/dist/column-type-compatibility.d.mts.map +1 -0
  19. package/dist/column-type-compatibility.mjs +2 -0
  20. package/dist/contract-free.d.mts +75 -0
  21. package/dist/contract-free.d.mts.map +1 -0
  22. package/dist/contract-free.mjs +139 -0
  23. package/dist/contract-free.mjs.map +1 -0
  24. package/dist/control.d.mts +1 -1
  25. package/dist/control.mjs +64 -36
  26. package/dist/control.mjs.map +1 -1
  27. package/dist/{data-transform-CAPmAdxS.d.mts → data-transform-5gLOgP68.d.mts} +2 -2
  28. package/dist/{data-transform-CAPmAdxS.d.mts.map → data-transform-5gLOgP68.d.mts.map} +1 -1
  29. package/dist/{data-transform-CRkv2T_U.mjs → data-transform-DIYwbe4S.mjs} +1 -1
  30. package/dist/{data-transform-CRkv2T_U.mjs.map → data-transform-DIYwbe4S.mjs.map} +1 -1
  31. package/dist/data-transform.d.mts +1 -1
  32. package/dist/data-transform.mjs +1 -1
  33. package/dist/ddl.d.mts +2 -0
  34. package/dist/ddl.mjs +2 -0
  35. package/dist/{default-normalizer-DaAhmzBV.mjs → default-normalizer-DFHtpCPH.mjs} +1 -1
  36. package/dist/{default-normalizer-DaAhmzBV.mjs.map → default-normalizer-DFHtpCPH.mjs.map} +1 -1
  37. package/dist/default-normalizer.mjs +1 -1
  38. package/dist/{descriptor-meta-Uu8QaClr.mjs → descriptor-meta-BqATo5Dz.mjs} +3 -2
  39. package/dist/descriptor-meta-BqATo5Dz.mjs.map +1 -0
  40. package/dist/{descriptor-meta-runtime-DMRX39kp.mjs → descriptor-meta-runtime-BBL7VdnR.mjs} +2 -2
  41. package/dist/{descriptor-meta-runtime-DMRX39kp.mjs.map → descriptor-meta-runtime-BBL7VdnR.mjs.map} +1 -1
  42. package/dist/{enum-planning-DRA9LaMU.mjs → enum-planning-Nt9TYPHe.mjs} +0 -0
  43. package/dist/{enum-planning-DRA9LaMU.mjs.map → enum-planning-Nt9TYPHe.mjs.map} +1 -1
  44. package/dist/enum-planning.d.mts +1 -1
  45. package/dist/enum-planning.mjs +1 -1
  46. package/dist/{errors-BbnITmAD.mjs → errors-De185dnO.mjs} +1 -1
  47. package/dist/{errors-BbnITmAD.mjs.map → errors-De185dnO.mjs.map} +1 -1
  48. package/dist/errors.mjs +1 -1
  49. package/dist/{issue-planner-BtaL6OfW.mjs → issue-planner-SUBi9fH8.mjs} +10 -10
  50. package/dist/{issue-planner-BtaL6OfW.mjs.map → issue-planner-SUBi9fH8.mjs.map} +1 -1
  51. package/dist/issue-planner.d.mts +1 -1
  52. package/dist/issue-planner.mjs +1 -1
  53. package/dist/migration.d.mts +3 -3
  54. package/dist/migration.mjs +3 -3
  55. package/dist/{native-type-normalizer-BNEQ9VDs.mjs → native-type-normalizer-BUUe8USD.mjs} +1 -1
  56. package/dist/{native-type-normalizer-BNEQ9VDs.mjs.map → native-type-normalizer-BUUe8USD.mjs.map} +1 -1
  57. package/dist/native-type-normalizer.mjs +1 -1
  58. package/dist/nodes-DCC8-DhV.mjs +42 -0
  59. package/dist/nodes-DCC8-DhV.mjs.map +1 -0
  60. package/dist/nodes-DflxwrE8.d.mts +38 -0
  61. package/dist/nodes-DflxwrE8.d.mts.map +1 -0
  62. package/dist/{op-factory-call-CDlImOF_.d.mts → op-factory-call-B-HEOf41.d.mts} +3 -3
  63. package/dist/{op-factory-call-CDlImOF_.d.mts.map → op-factory-call-B-HEOf41.d.mts.map} +1 -1
  64. package/dist/{op-factory-call-ewOd5q6L.mjs → op-factory-call-D8XePTfV.mjs} +2 -2
  65. package/dist/{op-factory-call-ewOd5q6L.mjs.map → op-factory-call-D8XePTfV.mjs.map} +1 -1
  66. package/dist/op-factory-call.d.mts +1 -1
  67. package/dist/op-factory-call.mjs +1 -1
  68. package/dist/pack.d.mts +3 -2
  69. package/dist/pack.d.mts.map +1 -1
  70. package/dist/pack.mjs +1 -1
  71. package/dist/planner-BruD4_LM.mjs +342 -0
  72. package/dist/planner-BruD4_LM.mjs.map +1 -0
  73. package/dist/{planner-ddl-builders-BNMfSE9r.mjs → planner-ddl-builders-BcRMeGgx.mjs} +3 -3
  74. package/dist/{planner-ddl-builders-BNMfSE9r.mjs.map → planner-ddl-builders-BcRMeGgx.mjs.map} +1 -1
  75. package/dist/planner-ddl-builders.d.mts +1 -1
  76. package/dist/planner-ddl-builders.mjs +1 -1
  77. package/dist/{planner-identity-values-nhVj0hp-.mjs → planner-identity-values-DmwlJe_z.mjs} +1 -1
  78. package/dist/{planner-identity-values-nhVj0hp-.mjs.map → planner-identity-values-DmwlJe_z.mjs.map} +1 -1
  79. package/dist/planner-identity-values.mjs +1 -1
  80. package/dist/{planner-produced-postgres-migration-D02NOhVQ.d.mts → planner-produced-postgres-migration-Co71_VbU.d.mts} +3 -3
  81. package/dist/{planner-produced-postgres-migration-D02NOhVQ.d.mts.map → planner-produced-postgres-migration-Co71_VbU.d.mts.map} +1 -1
  82. package/dist/{planner-produced-postgres-migration-D_nsXbhl.mjs → planner-produced-postgres-migration-D6KXC2DH.mjs} +4 -4
  83. package/dist/{planner-produced-postgres-migration-D_nsXbhl.mjs.map → planner-produced-postgres-migration-D6KXC2DH.mjs.map} +1 -1
  84. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  85. package/dist/planner-produced-postgres-migration.mjs +1 -1
  86. package/dist/{planner-schema-lookup-CGxxYfnD.mjs → planner-schema-lookup-Bm4S3LvB.mjs} +1 -1
  87. package/dist/{planner-schema-lookup-CGxxYfnD.mjs.map → planner-schema-lookup-Bm4S3LvB.mjs.map} +1 -1
  88. package/dist/planner-schema-lookup.mjs +1 -1
  89. package/dist/{planner-sql-checks-CfEiTXoQ.mjs → planner-sql-checks-lxWZQCFz.mjs} +3 -3
  90. package/dist/{planner-sql-checks-CfEiTXoQ.mjs.map → planner-sql-checks-lxWZQCFz.mjs.map} +1 -1
  91. package/dist/planner-sql-checks.mjs +1 -1
  92. package/dist/{planner-target-details-a_wuOiYf.d.mts → planner-target-details-Dv5N6x6k.d.mts} +1 -1
  93. package/dist/{planner-target-details-a_wuOiYf.d.mts.map → planner-target-details-Dv5N6x6k.d.mts.map} +1 -1
  94. package/dist/planner-target-details.d.mts +1 -1
  95. package/dist/planner.d.mts +3 -2
  96. package/dist/planner.d.mts.map +1 -1
  97. package/dist/planner.mjs +1 -1
  98. package/dist/{postgres-contract-serializer-BnOboPWs.mjs → postgres-contract-serializer-OfORJ-GY.mjs} +3 -3
  99. package/dist/{postgres-contract-serializer-BnOboPWs.mjs.map → postgres-contract-serializer-OfORJ-GY.mjs.map} +1 -1
  100. package/dist/{postgres-enum-type-CSzsvXrO.d.mts → postgres-enum-type-CWwVGBNK.d.mts} +1 -1
  101. package/dist/{postgres-enum-type-CSzsvXrO.d.mts.map → postgres-enum-type-CWwVGBNK.d.mts.map} +1 -1
  102. package/dist/{postgres-enum-type-BMgyxNyy.mjs → postgres-enum-type-CaGZ2mfI.mjs} +1 -1
  103. package/dist/{postgres-enum-type-BMgyxNyy.mjs.map → postgres-enum-type-CaGZ2mfI.mjs.map} +1 -1
  104. package/dist/{postgres-migration-DRY8V-bQ.d.mts → postgres-migration-BcKS2Lqq.d.mts} +3 -3
  105. package/dist/{postgres-migration-DRY8V-bQ.d.mts.map → postgres-migration-BcKS2Lqq.d.mts.map} +1 -1
  106. package/dist/{postgres-migration-BatbEvU6.mjs → postgres-migration-BnDg_Nj0.mjs} +3 -3
  107. package/dist/{postgres-migration-BatbEvU6.mjs.map → postgres-migration-BnDg_Nj0.mjs.map} +1 -1
  108. package/dist/{postgres-schema-BxAuNFX0.mjs → postgres-schema-Dky_Jff8.mjs} +3 -3
  109. package/dist/{postgres-schema-BxAuNFX0.mjs.map → postgres-schema-Dky_Jff8.mjs.map} +1 -1
  110. package/dist/{render-ops-XhICjX_P.mjs → render-ops-BpU-Qv06.mjs} +1 -1
  111. package/dist/{render-ops-XhICjX_P.mjs.map → render-ops-BpU-Qv06.mjs.map} +1 -1
  112. package/dist/render-ops.d.mts +1 -1
  113. package/dist/render-ops.mjs +1 -1
  114. package/dist/{render-typescript-K125n-RZ.mjs → render-typescript-D9O7aOS_.mjs} +1 -1
  115. package/dist/{render-typescript-K125n-RZ.mjs.map → render-typescript-D9O7aOS_.mjs.map} +1 -1
  116. package/dist/render-typescript.mjs +1 -1
  117. package/dist/runtime.mjs +2 -2
  118. package/dist/{shared-Do_a5ymU.d.mts → shared-CMqM-2BA.d.mts} +2 -2
  119. package/dist/{shared-Do_a5ymU.d.mts.map → shared-CMqM-2BA.d.mts.map} +1 -1
  120. package/dist/{sql-utils-CggjWNij.mjs → sql-utils-DR_F9aHR.mjs} +1 -1
  121. package/dist/{sql-utils-CggjWNij.mjs.map → sql-utils-DR_F9aHR.mjs.map} +1 -1
  122. package/dist/sql-utils.mjs +1 -1
  123. package/dist/{tables-DoA39Yqo.mjs → tables-Cuy4VIgu.mjs} +3 -3
  124. package/dist/{tables-DoA39Yqo.mjs.map → tables-Cuy4VIgu.mjs.map} +1 -1
  125. package/dist/{types-O40IcFV9.d.mts → types-kggVJs6C.d.mts} +1 -1
  126. package/dist/types-kggVJs6C.d.mts.map +1 -0
  127. package/dist/types.d.mts +2 -2
  128. package/dist/types.mjs +2 -2
  129. package/package.json +20 -18
  130. package/src/contract-free/columns.ts +49 -0
  131. package/src/contract-free/control-bootstrap.ts +55 -0
  132. package/src/contract-free/ddl.ts +32 -0
  133. package/src/core/ast/table-source.ts +23 -0
  134. package/src/core/codec-ids.ts +1 -0
  135. package/src/core/codecs.ts +44 -0
  136. package/src/core/column-type-compatibility.ts +13 -0
  137. package/src/core/ddl/nodes.ts +59 -0
  138. package/src/core/descriptor-meta.ts +1 -0
  139. package/src/core/migrations/control-policy.ts +235 -0
  140. package/src/core/migrations/planner.ts +57 -6
  141. package/src/core/migrations/runner.ts +78 -45
  142. package/src/exports/column-type-compatibility.ts +1 -0
  143. package/src/exports/contract-free.ts +7 -0
  144. package/src/exports/ddl.ts +7 -0
  145. package/dist/codec-ids-C5qzBqus.mjs.map +0 -1
  146. package/dist/codec-ids-DliyCWPY.d.mts.map +0 -1
  147. package/dist/codecs-DuP3d9Au.d.mts.map +0 -1
  148. package/dist/descriptor-meta-Uu8QaClr.mjs.map +0 -1
  149. package/dist/planner-Bjz5pnLa.mjs +0 -177
  150. package/dist/planner-Bjz5pnLa.mjs.map +0 -1
  151. package/dist/statement-builders-DVI5IVAa.mjs +0 -131
  152. package/dist/statement-builders-DVI5IVAa.mjs.map +0 -1
  153. package/dist/statement-builders.d.mts +0 -51
  154. package/dist/statement-builders.d.mts.map +0 -1
  155. package/dist/statement-builders.mjs +0 -2
  156. package/dist/types-O40IcFV9.d.mts.map +0 -1
  157. package/src/core/migrations/statement-builders.ts +0 -183
  158. package/src/exports/statement-builders.ts +0 -8
@@ -1,177 +0,0 @@
1
- import { r as isPostgresSchema } from "./postgres-schema-BxAuNFX0.mjs";
2
- import { t as createResolveExistingEnumValues } from "./enum-planning-DRA9LaMU.mjs";
3
- import { t as parsePostgresDefault } from "./default-normalizer-DaAhmzBV.mjs";
4
- import { t as normalizeSchemaNativeType } from "./native-type-normalizer-BNEQ9VDs.mjs";
5
- import { n as postgresPlannerStrategies, t as planIssues } from "./issue-planner-BtaL6OfW.mjs";
6
- import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-D_nsXbhl.mjs";
7
- import { extractCodecControlHooks, planFieldEventOperations, plannerFailure } from "@prisma-next/family-sql/control";
8
- import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
9
- import { verifySqlSchema } from "@prisma-next/family-sql/schema-verify";
10
- //#region src/core/migrations/verify-postgres-namespaces.ts
11
- /**
12
- * Resolves the live-database schema name for a given namespace
13
- * coordinate. Mirrors `resolveDdlSchemaForNamespace` in
14
- * `planner-strategies.ts` so the verifier's projection and the
15
- * planner's projection always agree — Postgres-aware namespaces (the
16
- * production path) dispatch to `ddlSchemaName(storage)`, and bare
17
- * object payloads (used by some tests) fall back to the coordinate
18
- * itself.
19
- */
20
- function resolveDdlSchemaName(storage, namespaceId) {
21
- const namespace = storage.namespaces[namespaceId];
22
- if (isPostgresSchema(namespace)) return namespace.ddlSchemaName(storage);
23
- return namespaceId;
24
- }
25
- /**
26
- * Reads the introspected list of schema names from the Postgres-flavoured
27
- * annotations slot on the schema IR. Defaults to the always-present
28
- * `public` schema when introspection did not populate the slot — a fresh
29
- * Postgres database always carries `public` (unless an operator dropped
30
- * it manually), so any verifier path that runs without an enriched
31
- * introspection still suppresses the redundant `CREATE SCHEMA "public"`.
32
- *
33
- * Production introspection (`PostgresControlAdapter.introspect`) is the
34
- * authoritative source: it queries `pg_namespace` and writes every
35
- * non-system schema into `annotations.pg.existingSchemas`. Tests that
36
- * want to assert against a richer initial state pass the slot
37
- * explicitly via the schema IR.
38
- */
39
- function existingSchemasFromSchema(schema) {
40
- const slot = schema.annotations?.pg?.existingSchemas;
41
- if (Array.isArray(slot)) return slot.filter((s) => typeof s === "string");
42
- return ["public"];
43
- }
44
- /**
45
- * Emits a `missing_schema` issue for every contract-declared Postgres
46
- * namespace whose live container does not yet exist.
47
- *
48
- * A namespace's live container is the schema returned by its
49
- * polymorphic `ddlSchemaName(storage)` method — named schemas resolve
50
- * to their own id; the unbound singleton returns `UNBOUND_NAMESPACE_ID`
51
- * and is skipped explicitly (late-bound namespaces have no fixed DDL
52
- * schema). Issues are emitted only when the resolved name is a real,
53
- * creatable schema (not the unbound sentinel) and is missing from the
54
- * introspected list. `public` is suppressed implicitly because the
55
- * introspection (or its sensible default) always carries it.
56
- *
57
- * Each emitted issue stamps `namespaceId` with the contract namespace
58
- * coordinate so the downstream `mapIssueToCall` re-resolves the DDL
59
- * schema name through the same polymorphic path — keeping the
60
- * coordinate, not the resolved name, as the issue's stable identity.
61
- */
62
- function verifyPostgresNamespacePresence(input) {
63
- const { contract, schema } = input;
64
- const existing = new Set(existingSchemasFromSchema(schema));
65
- const issues = [];
66
- const namespaceIds = Object.keys(contract.storage.namespaces).sort();
67
- for (const namespaceId of namespaceIds) {
68
- if (namespaceId === UNBOUND_NAMESPACE_ID) continue;
69
- const ddlName = resolveDdlSchemaName(contract.storage, namespaceId);
70
- if (ddlName === UNBOUND_NAMESPACE_ID) continue;
71
- if (existing.has(ddlName)) continue;
72
- issues.push({
73
- kind: "missing_schema",
74
- namespaceId,
75
- message: `Schema "${ddlName}" is missing from database`
76
- });
77
- }
78
- return issues;
79
- }
80
- //#endregion
81
- //#region src/core/migrations/planner.ts
82
- function createPostgresMigrationPlanner() {
83
- return new PostgresMigrationPlanner();
84
- }
85
- /**
86
- * Postgres migration planner — a thin wrapper over `planIssues`.
87
- *
88
- * `plan()` verifies the live schema against the target contract (producing
89
- * `SchemaIssue[]`) and delegates to `planIssues` with the unified
90
- * `postgresPlannerStrategies` list: enum-change, NOT-NULL backfill,
91
- * type-change, nullable-tightening, codec-hook storage types,
92
- * component-declared dependency installs, and shared-temp-default /
93
- * empty-table-guarded NOT-NULL add-column. The same strategy list runs for
94
- * `migration plan`, `db update`, and `db init`; behavior diverges purely on
95
- * `policy.allowedOperationClasses` (the data-safe strategies short-circuit
96
- * when `'data'` is excluded). The issue planner applies operation-class
97
- * policy gates and emits a single `PostgresOpFactoryCall[]` that drives both
98
- * the runtime-ops view (via `renderOps`) and the `renderTypeScript()`
99
- * authoring surface.
100
- */
101
- var PostgresMigrationPlanner = class {
102
- plan(options) {
103
- return this.planSql(options);
104
- }
105
- emptyMigration(context, spaceId) {
106
- return new TypeScriptRenderablePostgresMigration([], {
107
- from: context.fromHash,
108
- to: context.toHash
109
- }, spaceId);
110
- }
111
- planSql(options) {
112
- const schemaName = options.schemaName ?? Object.keys(options.contract.storage.namespaces).find((id) => id !== UNBOUND_NAMESPACE_ID) ?? UNBOUND_NAMESPACE_ID;
113
- const policyResult = this.ensureAdditivePolicy(options.policy);
114
- if (policyResult) return policyResult;
115
- const schemaIssues = this.collectSchemaIssues(options);
116
- const codecHooks = extractCodecControlHooks(options.frameworkComponents);
117
- const storageTypes = options.contract.storage.types ?? {};
118
- const result = planIssues({
119
- issues: schemaIssues,
120
- toContract: options.contract,
121
- fromContract: options.fromContract,
122
- schemaName,
123
- codecHooks,
124
- storageTypes,
125
- schema: options.schema,
126
- policy: options.policy,
127
- frameworkComponents: options.frameworkComponents,
128
- strategies: postgresPlannerStrategies
129
- });
130
- if (!result.ok) return plannerFailure(result.failure);
131
- const fieldEventOps = planFieldEventOperations({
132
- priorContract: options.fromContract,
133
- newContract: options.contract,
134
- codecHooks
135
- });
136
- const calls = [...result.value.calls, ...fieldEventOps];
137
- return Object.freeze({
138
- kind: "success",
139
- plan: new TypeScriptRenderablePostgresMigration(calls, {
140
- from: options.fromContract?.storage.storageHash ?? null,
141
- to: options.contract.storage.storageHash
142
- }, options.spaceId)
143
- });
144
- }
145
- ensureAdditivePolicy(policy) {
146
- if (!policy.allowedOperationClasses.includes("additive")) return plannerFailure([{
147
- kind: "unsupportedOperation",
148
- summary: "Migration planner requires additive operations be allowed",
149
- why: "The planner requires the \"additive\" operation class to be allowed in the policy."
150
- }]);
151
- return null;
152
- }
153
- collectSchemaIssues(options) {
154
- const allowed = options.policy.allowedOperationClasses;
155
- const strict = allowed.includes("widening") || allowed.includes("destructive");
156
- const verifyResult = verifySqlSchema({
157
- contract: options.contract,
158
- schema: options.schema,
159
- strict,
160
- typeMetadataRegistry: /* @__PURE__ */ new Map(),
161
- frameworkComponents: options.frameworkComponents,
162
- normalizeDefault: parsePostgresDefault,
163
- normalizeNativeType: normalizeSchemaNativeType,
164
- resolveExistingEnumValues: createResolveExistingEnumValues(options.contract.storage)
165
- });
166
- const namespaceIssues = verifyPostgresNamespacePresence({
167
- contract: options.contract,
168
- schema: options.schema
169
- });
170
- if (namespaceIssues.length === 0) return verifyResult.schema.issues;
171
- return [...namespaceIssues, ...verifyResult.schema.issues];
172
- }
173
- };
174
- //#endregion
175
- export { createPostgresMigrationPlanner as t };
176
-
177
- //# sourceMappingURL=planner-Bjz5pnLa.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"planner-Bjz5pnLa.mjs","names":[],"sources":["../src/core/migrations/verify-postgres-namespaces.ts","../src/core/migrations/planner.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SchemaIssue } from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { isPostgresSchema } from '../postgres-schema';\n\n/**\n * Resolves the live-database schema name for a given namespace\n * coordinate. Mirrors `resolveDdlSchemaForNamespace` in\n * `planner-strategies.ts` so the verifier's projection and the\n * planner's projection always agree — Postgres-aware namespaces (the\n * production path) dispatch to `ddlSchemaName(storage)`, and bare\n * object payloads (used by some tests) fall back to the coordinate\n * itself.\n */\nfunction resolveDdlSchemaName(storage: SqlStorage, namespaceId: string): string {\n const namespace = storage.namespaces[namespaceId];\n if (isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n\n/**\n * Reads the introspected list of schema names from the Postgres-flavoured\n * annotations slot on the schema IR. Defaults to the always-present\n * `public` schema when introspection did not populate the slot — a fresh\n * Postgres database always carries `public` (unless an operator dropped\n * it manually), so any verifier path that runs without an enriched\n * introspection still suppresses the redundant `CREATE SCHEMA \"public\"`.\n *\n * Production introspection (`PostgresControlAdapter.introspect`) is the\n * authoritative source: it queries `pg_namespace` and writes every\n * non-system schema into `annotations.pg.existingSchemas`. Tests that\n * want to assert against a richer initial state pass the slot\n * explicitly via the schema IR.\n */\nfunction existingSchemasFromSchema(schema: SqlSchemaIR): readonly string[] {\n const annotations = (schema as { annotations?: { pg?: { existingSchemas?: unknown } } })\n .annotations;\n const slot = annotations?.pg?.existingSchemas;\n if (Array.isArray(slot)) {\n return slot.filter((s): s is string => typeof s === 'string');\n }\n return ['public'];\n}\n\n/**\n * Emits a `missing_schema` issue for every contract-declared Postgres\n * namespace whose live container does not yet exist.\n *\n * A namespace's live container is the schema returned by its\n * polymorphic `ddlSchemaName(storage)` method — named schemas resolve\n * to their own id; the unbound singleton returns `UNBOUND_NAMESPACE_ID`\n * and is skipped explicitly (late-bound namespaces have no fixed DDL\n * schema). Issues are emitted only when the resolved name is a real,\n * creatable schema (not the unbound sentinel) and is missing from the\n * introspected list. `public` is suppressed implicitly because the\n * introspection (or its sensible default) always carries it.\n *\n * Each emitted issue stamps `namespaceId` with the contract namespace\n * coordinate so the downstream `mapIssueToCall` re-resolves the DDL\n * schema name through the same polymorphic path — keeping the\n * coordinate, not the resolved name, as the issue's stable identity.\n */\nexport function verifyPostgresNamespacePresence(input: {\n readonly contract: Contract<SqlStorage>;\n readonly schema: SqlSchemaIR;\n}): readonly SchemaIssue[] {\n const { contract, schema } = input;\n const existing = new Set(existingSchemasFromSchema(schema));\n const issues: SchemaIssue[] = [];\n const namespaceIds = Object.keys(contract.storage.namespaces).sort();\n for (const namespaceId of namespaceIds) {\n if (namespaceId === UNBOUND_NAMESPACE_ID) continue;\n const ddlName = resolveDdlSchemaName(contract.storage, namespaceId);\n if (ddlName === UNBOUND_NAMESPACE_ID) continue;\n if (existing.has(ddlName)) continue;\n issues.push({\n kind: 'missing_schema',\n namespaceId,\n message: `Schema \"${ddlName}\" is missing from database`,\n });\n }\n return issues;\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type {\n MigrationOperationPolicy,\n SqlMigrationPlannerPlanOptions,\n SqlPlannerFailureResult,\n} from '@prisma-next/family-sql/control';\nimport {\n extractCodecControlHooks,\n planFieldEventOperations,\n plannerFailure,\n} from '@prisma-next/family-sql/control';\nimport { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type {\n MigrationPlanner,\n MigrationPlanWithAuthoringSurface,\n MigrationScaffoldContext,\n SchemaIssue,\n} from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport { parsePostgresDefault } from '../default-normalizer';\nimport { normalizeSchemaNativeType } from '../native-type-normalizer';\nimport { createResolveExistingEnumValues } from './enum-planning';\nimport { planIssues } from './issue-planner';\nimport { TypeScriptRenderablePostgresMigration } from './planner-produced-postgres-migration';\nimport { postgresPlannerStrategies } from './planner-strategies';\nimport { verifyPostgresNamespacePresence } from './verify-postgres-namespaces';\n\ntype PlannerFrameworkComponents = SqlMigrationPlannerPlanOptions extends {\n readonly frameworkComponents: infer T;\n}\n ? T\n : ReadonlyArray<unknown>;\n\ntype PlannerOptionsWithComponents = SqlMigrationPlannerPlanOptions & {\n readonly frameworkComponents: PlannerFrameworkComponents;\n};\n\ntype VerifySqlSchemaOptionsWithComponents = Parameters<typeof verifySqlSchema>[0] & {\n readonly frameworkComponents: PlannerFrameworkComponents;\n};\n\nexport function createPostgresMigrationPlanner(): PostgresMigrationPlanner {\n return new PostgresMigrationPlanner();\n}\n\n/**\n * Result of `PostgresMigrationPlanner.plan()`. A discriminated union whose\n * success variant carries a `TypeScriptRenderablePostgresMigration` — a\n * migration object that both the CLI (via `renderTypeScript()`) and the\n * SQL-typed callers (via `operations`, `describe()`, etc.) consume\n * uniformly.\n */\nexport type PostgresPlanResult =\n | { readonly kind: 'success'; readonly plan: TypeScriptRenderablePostgresMigration }\n | SqlPlannerFailureResult;\n\n/**\n * Postgres migration planner — a thin wrapper over `planIssues`.\n *\n * `plan()` verifies the live schema against the target contract (producing\n * `SchemaIssue[]`) and delegates to `planIssues` with the unified\n * `postgresPlannerStrategies` list: enum-change, NOT-NULL backfill,\n * type-change, nullable-tightening, codec-hook storage types,\n * component-declared dependency installs, and shared-temp-default /\n * empty-table-guarded NOT-NULL add-column. The same strategy list runs for\n * `migration plan`, `db update`, and `db init`; behavior diverges purely on\n * `policy.allowedOperationClasses` (the data-safe strategies short-circuit\n * when `'data'` is excluded). The issue planner applies operation-class\n * policy gates and emits a single `PostgresOpFactoryCall[]` that drives both\n * the runtime-ops view (via `renderOps`) and the `renderTypeScript()`\n * authoring surface.\n */\nexport class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgres'> {\n plan(options: {\n readonly contract: unknown;\n readonly schema: unknown;\n readonly policy: MigrationOperationPolicy;\n /**\n * The \"from\" contract (state the planner assumes the database starts\n * at), or `null` for reconciliation flows. Only `migration plan` ever\n * supplies a non-null value; `db update` / `db init` reconcile against\n * the live schema and pass `null`. When present alongside the\n * `'data'` operation class, strategies that need from/to column-shape\n * comparisons (unsafe type change, nullability tightening) activate.\n *\n * Typed as the framework `Contract | null` to satisfy the\n * `MigrationPlanner` interface contract; `planSql` narrows to the SQL\n * shape via `SqlMigrationPlannerPlanOptions`. Used to populate\n * `describe().from` on the produced plan as\n * `fromContract?.storage.storageHash ?? null`.\n */\n readonly fromContract: Contract | null;\n readonly schemaName?: string;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n /**\n * Contract space this plan applies to. Stamped onto the produced\n * {@link TypeScriptRenderablePostgresMigration.spaceId} so the runner keys\n * the marker row by the right space.\n */\n readonly spaceId: string;\n }): PostgresPlanResult {\n return this.planSql(options as SqlMigrationPlannerPlanOptions);\n }\n\n emptyMigration(\n context: MigrationScaffoldContext,\n spaceId: string,\n ): MigrationPlanWithAuthoringSurface {\n return new TypeScriptRenderablePostgresMigration(\n [],\n {\n from: context.fromHash,\n to: context.toHash,\n },\n spaceId,\n );\n }\n\n private planSql(options: SqlMigrationPlannerPlanOptions): PostgresPlanResult {\n const schemaName =\n options.schemaName ??\n Object.keys(options.contract.storage.namespaces).find((id) => id !== UNBOUND_NAMESPACE_ID) ??\n UNBOUND_NAMESPACE_ID;\n const policyResult = this.ensureAdditivePolicy(options.policy);\n if (policyResult) {\n return policyResult;\n }\n\n const schemaIssues = this.collectSchemaIssues(options);\n const codecHooks = extractCodecControlHooks(options.frameworkComponents);\n const storageTypes = options.contract.storage.types ?? {};\n\n const result = planIssues({\n issues: schemaIssues,\n toContract: options.contract,\n // `fromContract` is only supplied by `migration plan`. It is `null` for\n // `db update` / `db init`, which means data-safety strategies needing\n // from/to comparisons (unsafe type change, nullable tightening) are\n // inapplicable there — reconciliation falls through to\n // `mapIssueToCall`'s direct destructive handlers.\n fromContract: options.fromContract,\n schemaName,\n codecHooks,\n storageTypes,\n schema: options.schema,\n policy: options.policy,\n frameworkComponents: options.frameworkComponents,\n strategies: postgresPlannerStrategies,\n });\n\n if (!result.ok) {\n return plannerFailure(result.failure);\n }\n\n // Inline `onFieldEvent`-emitted ops after structural DDL. The fixed\n // ordering is `structural → added → dropped → altered`, with\n // within-group sorting by `(tableName, fieldName)` so re-emits are\n // byte-stable. The hook fires only at the application emitter —\n // extension-space planning never reaches this helper.\n const fieldEventOps = planFieldEventOperations({\n priorContract: options.fromContract,\n newContract: options.contract,\n codecHooks,\n });\n // Codec-emitted calls already conform to `OpFactoryCall` — render +\n // toOp + importRequirements ride directly through the same emit path\n // as structural ops, no `RawSqlCall` wrap.\n const calls = [...result.value.calls, ...fieldEventOps];\n\n return Object.freeze({\n kind: 'success' as const,\n plan: new TypeScriptRenderablePostgresMigration(\n calls,\n {\n from: options.fromContract?.storage.storageHash ?? null,\n to: options.contract.storage.storageHash,\n },\n options.spaceId,\n ),\n });\n }\n\n private ensureAdditivePolicy(policy: MigrationOperationPolicy) {\n if (!policy.allowedOperationClasses.includes('additive')) {\n return plannerFailure([\n {\n kind: 'unsupportedOperation',\n summary: 'Migration planner requires additive operations be allowed',\n why: 'The planner requires the \"additive\" operation class to be allowed in the policy.',\n },\n ]);\n }\n return null;\n }\n\n private collectSchemaIssues(options: PlannerOptionsWithComponents): readonly SchemaIssue[] {\n // `db init` uses additive-only policy and intentionally ignores extra\n // schema objects. Any reconciliation-capable policy (widening or\n // destructive) must inspect extras to reconcile strict equality.\n const allowed = options.policy.allowedOperationClasses;\n const strict = allowed.includes('widening') || allowed.includes('destructive');\n const verifyOptions: VerifySqlSchemaOptionsWithComponents = {\n contract: options.contract,\n schema: options.schema,\n strict,\n typeMetadataRegistry: new Map(),\n frameworkComponents: options.frameworkComponents,\n normalizeDefault: parsePostgresDefault,\n normalizeNativeType: normalizeSchemaNativeType,\n resolveExistingEnumValues: createResolveExistingEnumValues(options.contract.storage),\n };\n const verifyResult = verifySqlSchema(verifyOptions);\n // Schema presence is a Postgres-specific concern (no equivalent in\n // SQLite / Mongo), so the issue emission lives in the target layer\n // rather than in the family verifier. Stitch it in here so a single\n // `SchemaIssue[]` flows through `planIssues` and the planner emits\n // CREATE SCHEMA in the dep bucket before any CreateTableCall.\n const namespaceIssues = verifyPostgresNamespacePresence({\n contract: options.contract,\n schema: options.schema,\n });\n if (namespaceIssues.length === 0) {\n return verifyResult.schema.issues;\n }\n return [...namespaceIssues, ...verifyResult.schema.issues];\n }\n}\n"],"mappings":"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"}
@@ -1,131 +0,0 @@
1
- import { APP_SPACE_ID as APP_SPACE_ID$1 } from "@prisma-next/framework-components/control";
2
- //#region src/core/migrations/statement-builders.ts
3
- const ensurePrismaContractSchemaStatement = {
4
- sql: "create schema if not exists prisma_contract",
5
- params: []
6
- };
7
- /**
8
- * Schema for `prisma_contract.marker`. The `space text` primary key
9
- * supports one row per loaded contract space (`'app'`,
10
- * `'<extension-id>'`, …); on a brand-new database `CREATE TABLE IF NOT
11
- * EXISTS` produces this shape directly. The migration runner detects
12
- * pre-1.0 single-row markers (no `space` column) at boot and fails with
13
- * a structured `LEGACY_MARKER_SHAPE` error rather than auto-migrating —
14
- * see `specs/framework-mechanism.spec.md § 2`.
15
- */
16
- const ensureMarkerTableStatement = {
17
- sql: `create table if not exists prisma_contract.marker (
18
- space text not null primary key default '${APP_SPACE_ID$1}',
19
- core_hash text not null,
20
- profile_hash text not null,
21
- contract_json jsonb,
22
- canonical_version int,
23
- updated_at timestamptz not null default now(),
24
- app_tag text,
25
- meta jsonb not null default '{}',
26
- invariants text[] not null default '{}'
27
- )`,
28
- params: []
29
- };
30
- const ensureLedgerTableStatement = {
31
- sql: `create table if not exists prisma_contract.ledger (
32
- id bigserial primary key,
33
- created_at timestamptz not null default now(),
34
- origin_core_hash text,
35
- origin_profile_hash text,
36
- destination_core_hash text not null,
37
- destination_profile_hash text,
38
- contract_json_before jsonb,
39
- contract_json_after jsonb,
40
- operations jsonb not null
41
- )`,
42
- params: []
43
- };
44
- function buildMergeMarkerStatements(input) {
45
- const params = [
46
- input.space,
47
- input.storageHash,
48
- input.profileHash,
49
- jsonParam(input.contractJson),
50
- input.canonicalVersion ?? null,
51
- input.appTag ?? null,
52
- jsonParam(input.meta ?? {}),
53
- input.invariants
54
- ];
55
- return {
56
- insert: {
57
- sql: `insert into prisma_contract.marker (
58
- space,
59
- core_hash,
60
- profile_hash,
61
- contract_json,
62
- canonical_version,
63
- updated_at,
64
- app_tag,
65
- meta,
66
- invariants
67
- ) values (
68
- $1,
69
- $2,
70
- $3,
71
- $4::jsonb,
72
- $5,
73
- now(),
74
- $6,
75
- $7::jsonb,
76
- $8::text[]
77
- )`,
78
- params
79
- },
80
- update: {
81
- sql: `update prisma_contract.marker set
82
- core_hash = $2,
83
- profile_hash = $3,
84
- contract_json = $4::jsonb,
85
- canonical_version = $5,
86
- updated_at = now(),
87
- app_tag = $6,
88
- meta = $7::jsonb,
89
- invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)
90
- where space = $1`,
91
- params
92
- }
93
- };
94
- }
95
- function buildLedgerInsertStatement(input) {
96
- return {
97
- sql: `insert into prisma_contract.ledger (
98
- origin_core_hash,
99
- origin_profile_hash,
100
- destination_core_hash,
101
- destination_profile_hash,
102
- contract_json_before,
103
- contract_json_after,
104
- operations
105
- ) values (
106
- $1,
107
- $2,
108
- $3,
109
- $4,
110
- $5::jsonb,
111
- $6::jsonb,
112
- $7::jsonb
113
- )`,
114
- params: [
115
- input.originStorageHash ?? null,
116
- input.originProfileHash ?? null,
117
- input.destinationStorageHash,
118
- input.destinationProfileHash ?? null,
119
- jsonParam(input.contractJsonBefore),
120
- jsonParam(input.contractJsonAfter),
121
- jsonParam(input.operations)
122
- ]
123
- };
124
- }
125
- function jsonParam(value) {
126
- return JSON.stringify(value ?? null);
127
- }
128
- //#endregion
129
- export { ensureMarkerTableStatement as a, ensureLedgerTableStatement as i, buildLedgerInsertStatement as n, ensurePrismaContractSchemaStatement as o, buildMergeMarkerStatements as r, APP_SPACE_ID$1 as t };
130
-
131
- //# sourceMappingURL=statement-builders-DVI5IVAa.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"statement-builders-DVI5IVAa.mjs","names":["APP_SPACE_ID"],"sources":["../src/core/migrations/statement-builders.ts"],"sourcesContent":["import { APP_SPACE_ID } from '@prisma-next/framework-components/control';\n\nexport { APP_SPACE_ID };\n\nexport interface SqlStatement {\n readonly sql: string;\n readonly params: readonly unknown[];\n}\n\nexport const ensurePrismaContractSchemaStatement: SqlStatement = {\n sql: 'create schema if not exists prisma_contract',\n params: [],\n};\n\n/**\n * Schema for `prisma_contract.marker`. The `space text` primary key\n * supports one row per loaded contract space (`'app'`,\n * `'<extension-id>'`, …); on a brand-new database `CREATE TABLE IF NOT\n * EXISTS` produces this shape directly. The migration runner detects\n * pre-1.0 single-row markers (no `space` column) at boot and fails with\n * a structured `LEGACY_MARKER_SHAPE` error rather than auto-migrating —\n * see `specs/framework-mechanism.spec.md § 2`.\n */\nexport const ensureMarkerTableStatement: SqlStatement = {\n sql: `create table if not exists prisma_contract.marker (\n space text not null primary key default '${APP_SPACE_ID}',\n core_hash text not null,\n profile_hash text not null,\n contract_json jsonb,\n canonical_version int,\n updated_at timestamptz not null default now(),\n app_tag text,\n meta jsonb not null default '{}',\n invariants text[] not null default '{}'\n )`,\n params: [],\n};\n\nexport const ensureLedgerTableStatement: SqlStatement = {\n sql: `create table if not exists prisma_contract.ledger (\n id bigserial primary key,\n created_at timestamptz not null default now(),\n origin_core_hash text,\n origin_profile_hash text,\n destination_core_hash text not null,\n destination_profile_hash text,\n contract_json_before jsonb,\n contract_json_after jsonb,\n operations jsonb not null\n )`,\n params: [],\n};\n\nexport interface MergeMarkerInput {\n /**\n * Logical space identifier for this marker row. Required at every\n * call site so the type system surfaces every place that needs to\n * thread the value (rather than letting an `?? APP_SPACE_ID`\n * fall-through silently collapse per-space markers onto the\n * `'app'` row). App-plan callers pass {@link APP_SPACE_ID}\n * (`'app'`); per-extension callers (planner / runner / verifier\n * extensions over contract spaces) pass the extension's space id.\n */\n readonly space: string;\n readonly storageHash: string;\n readonly profileHash: string;\n readonly contractJson?: unknown;\n readonly canonicalVersion?: number | null;\n readonly appTag?: string | null;\n readonly meta?: Record<string, unknown>;\n /**\n * Invariants to merge into `marker.invariants`. INSERT writes them as\n * the initial value (callers are expected to pass a sorted, deduped\n * array). UPDATE merges them with the existing column server-side via\n * a single atomic SQL expression.\n */\n readonly invariants: readonly string[];\n}\n\nexport function buildMergeMarkerStatements(input: MergeMarkerInput): {\n readonly insert: SqlStatement;\n readonly update: SqlStatement;\n} {\n const params: readonly unknown[] = [\n input.space,\n input.storageHash,\n input.profileHash,\n jsonParam(input.contractJson),\n input.canonicalVersion ?? null,\n input.appTag ?? null,\n jsonParam(input.meta ?? {}),\n input.invariants,\n ];\n\n return {\n insert: {\n sql: `insert into prisma_contract.marker (\n space,\n core_hash,\n profile_hash,\n contract_json,\n canonical_version,\n updated_at,\n app_tag,\n meta,\n invariants\n ) values (\n $1,\n $2,\n $3,\n $4::jsonb,\n $5,\n now(),\n $6,\n $7::jsonb,\n $8::text[]\n )`,\n params,\n },\n update: {\n // `invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)`\n // reads the current column value under the UPDATE's row lock, unions\n // with the incoming array, dedupes, and sorts ascending — single\n // statement, atomic, no read-then-write window.\n sql: `update prisma_contract.marker set\n core_hash = $2,\n profile_hash = $3,\n contract_json = $4::jsonb,\n canonical_version = $5,\n updated_at = now(),\n app_tag = $6,\n meta = $7::jsonb,\n invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)\n where space = $1`,\n params,\n },\n };\n}\n\nexport interface LedgerInsertInput {\n readonly originStorageHash?: string | null;\n readonly originProfileHash?: string | null;\n readonly destinationStorageHash: string;\n readonly destinationProfileHash?: string | null;\n readonly contractJsonBefore?: unknown;\n readonly contractJsonAfter?: unknown;\n readonly operations: unknown;\n}\n\nexport function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStatement {\n return {\n sql: `insert into prisma_contract.ledger (\n origin_core_hash,\n origin_profile_hash,\n destination_core_hash,\n destination_profile_hash,\n contract_json_before,\n contract_json_after,\n operations\n ) values (\n $1,\n $2,\n $3,\n $4,\n $5::jsonb,\n $6::jsonb,\n $7::jsonb\n )`,\n params: [\n input.originStorageHash ?? null,\n input.originProfileHash ?? null,\n input.destinationStorageHash,\n input.destinationProfileHash ?? null,\n jsonParam(input.contractJsonBefore),\n jsonParam(input.contractJsonAfter),\n jsonParam(input.operations),\n ],\n };\n}\n\nfunction jsonParam(value: unknown): string {\n return JSON.stringify(value ?? null);\n}\n"],"mappings":";;AASA,MAAa,sCAAoD;CAC/D,KAAK;CACL,QAAQ,CAAC;AACX;;;;;;;;;;AAWA,MAAa,6BAA2C;CACtD,KAAK;+CACwCA,eAAa;;;;;;;;;;CAU1D,QAAQ,CAAC;AACX;AAEA,MAAa,6BAA2C;CACtD,KAAK;;;;;;;;;;;CAWL,QAAQ,CAAC;AACX;AA4BA,SAAgB,2BAA2B,OAGzC;CACA,MAAM,SAA6B;EACjC,MAAM;EACN,MAAM;EACN,MAAM;EACN,UAAU,MAAM,YAAY;EAC5B,MAAM,oBAAoB;EAC1B,MAAM,UAAU;EAChB,UAAU,MAAM,QAAQ,CAAC,CAAC;EAC1B,MAAM;CACR;CAEA,OAAO;EACL,QAAQ;GACN,KAAK;;;;;;;;;;;;;;;;;;;;;GAqBL;EACF;EACA,QAAQ;GAKN,KAAK;;;;;;;;;;GAUL;EACF;CACF;AACF;AAYA,SAAgB,2BAA2B,OAAwC;CACjF,OAAO;EACL,KAAK;;;;;;;;;;;;;;;;;EAiBL,QAAQ;GACN,MAAM,qBAAqB;GAC3B,MAAM,qBAAqB;GAC3B,MAAM;GACN,MAAM,0BAA0B;GAChC,UAAU,MAAM,kBAAkB;GAClC,UAAU,MAAM,iBAAiB;GACjC,UAAU,MAAM,UAAU;EAC5B;CACF;AACF;AAEA,SAAS,UAAU,OAAwB;CACzC,OAAO,KAAK,UAAU,SAAS,IAAI;AACrC"}
@@ -1,51 +0,0 @@
1
- import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
2
-
3
- //#region src/core/migrations/statement-builders.d.ts
4
- interface SqlStatement {
5
- readonly sql: string;
6
- readonly params: readonly unknown[];
7
- }
8
- declare const ensurePrismaContractSchemaStatement: SqlStatement;
9
- /**
10
- * Schema for `prisma_contract.marker`. The `space text` primary key
11
- * supports one row per loaded contract space (`'app'`,
12
- * `'<extension-id>'`, …); on a brand-new database `CREATE TABLE IF NOT
13
- * EXISTS` produces this shape directly. The migration runner detects
14
- * pre-1.0 single-row markers (no `space` column) at boot and fails with
15
- * a structured `LEGACY_MARKER_SHAPE` error rather than auto-migrating —
16
- * see `specs/framework-mechanism.spec.md § 2`.
17
- */
18
- declare const ensureMarkerTableStatement: SqlStatement;
19
- declare const ensureLedgerTableStatement: SqlStatement;
20
- interface MergeMarkerInput {
21
- /**
22
- * Logical space identifier for this marker row. Required at every
23
- * call site so the type system surfaces every place that needs to
24
- * thread the value (rather than letting an `?? APP_SPACE_ID`
25
- * fall-through silently collapse per-space markers onto the
26
- * `'app'` row). App-plan callers pass {@link APP_SPACE_ID}
27
- * (`'app'`); per-extension callers (planner / runner / verifier
28
- * extensions over contract spaces) pass the extension's space id.
29
- */
30
- readonly space: string;
31
- readonly storageHash: string;
32
- readonly profileHash: string;
33
- readonly contractJson?: unknown;
34
- readonly canonicalVersion?: number | null;
35
- readonly appTag?: string | null;
36
- readonly meta?: Record<string, unknown>;
37
- /**
38
- * Invariants to merge into `marker.invariants`. INSERT writes them as
39
- * the initial value (callers are expected to pass a sorted, deduped
40
- * array). UPDATE merges them with the existing column server-side via
41
- * a single atomic SQL expression.
42
- */
43
- readonly invariants: readonly string[];
44
- }
45
- declare function buildMergeMarkerStatements(input: MergeMarkerInput): {
46
- readonly insert: SqlStatement;
47
- readonly update: SqlStatement;
48
- };
49
- //#endregion
50
- export { APP_SPACE_ID, type SqlStatement, buildMergeMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
51
- //# sourceMappingURL=statement-builders.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"statement-builders.d.mts","names":[],"sources":["../src/core/migrations/statement-builders.ts"],"mappings":";;;UAIiB,YAAA;EAAA,SACN,GAAA;EAAA,SACA,MAAM;AAAA;AAAA,cAGJ,mCAAA,EAAqC,YAGjD;AANgB;AAGjB;;;;AAGC;AAWD;;;AAjBiB,cAiBJ,0BAAA,EAA4B,YAaxC;AAAA,cAEY,0BAAA,EAA4B,YAaxC;AAAA,UAEgB,gBAAA;EAFhB;;;AAAA;AAED;;;;;EAFC,SAYU,KAAA;EAAA,SACA,WAAA;EAAA,SACA,WAAA;EAAA,SACA,YAAA;EAAA,SACA,gBAAA;EAAA,SACA,MAAA;EAAA,SACA,IAAA,GAAO,MAAM;EAOb;;AAAU;AAGrB;;;EAHW,SAAA,UAAA;AAAA;AAAA,iBAGK,0BAAA,CAA2B,KAAA,EAAO,gBAAA;EAAA,SACvC,MAAA,EAAQ,YAAA;EAAA,SACR,MAAA,EAAQ,YAAA;AAAA"}
@@ -1,2 +0,0 @@
1
- import { a as ensureMarkerTableStatement, i as ensureLedgerTableStatement, o as ensurePrismaContractSchemaStatement, r as buildMergeMarkerStatements, t as APP_SPACE_ID } from "./statement-builders-DVI5IVAa.mjs";
2
- export { APP_SPACE_ID, buildMergeMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-O40IcFV9.d.mts","names":[],"sources":["../src/core/types.ts"],"mappings":";;;KAEY,qBAAA,GACR,aAAa;EAAA,SACF,IAAA;EAAA,SAA2B,IAAA;AAAA"}
@@ -1,183 +0,0 @@
1
- import { APP_SPACE_ID } from '@prisma-next/framework-components/control';
2
-
3
- export { APP_SPACE_ID };
4
-
5
- export interface SqlStatement {
6
- readonly sql: string;
7
- readonly params: readonly unknown[];
8
- }
9
-
10
- export const ensurePrismaContractSchemaStatement: SqlStatement = {
11
- sql: 'create schema if not exists prisma_contract',
12
- params: [],
13
- };
14
-
15
- /**
16
- * Schema for `prisma_contract.marker`. The `space text` primary key
17
- * supports one row per loaded contract space (`'app'`,
18
- * `'<extension-id>'`, …); on a brand-new database `CREATE TABLE IF NOT
19
- * EXISTS` produces this shape directly. The migration runner detects
20
- * pre-1.0 single-row markers (no `space` column) at boot and fails with
21
- * a structured `LEGACY_MARKER_SHAPE` error rather than auto-migrating —
22
- * see `specs/framework-mechanism.spec.md § 2`.
23
- */
24
- export const ensureMarkerTableStatement: SqlStatement = {
25
- sql: `create table if not exists prisma_contract.marker (
26
- space text not null primary key default '${APP_SPACE_ID}',
27
- core_hash text not null,
28
- profile_hash text not null,
29
- contract_json jsonb,
30
- canonical_version int,
31
- updated_at timestamptz not null default now(),
32
- app_tag text,
33
- meta jsonb not null default '{}',
34
- invariants text[] not null default '{}'
35
- )`,
36
- params: [],
37
- };
38
-
39
- export const ensureLedgerTableStatement: SqlStatement = {
40
- sql: `create table if not exists prisma_contract.ledger (
41
- id bigserial primary key,
42
- created_at timestamptz not null default now(),
43
- origin_core_hash text,
44
- origin_profile_hash text,
45
- destination_core_hash text not null,
46
- destination_profile_hash text,
47
- contract_json_before jsonb,
48
- contract_json_after jsonb,
49
- operations jsonb not null
50
- )`,
51
- params: [],
52
- };
53
-
54
- export interface MergeMarkerInput {
55
- /**
56
- * Logical space identifier for this marker row. Required at every
57
- * call site so the type system surfaces every place that needs to
58
- * thread the value (rather than letting an `?? APP_SPACE_ID`
59
- * fall-through silently collapse per-space markers onto the
60
- * `'app'` row). App-plan callers pass {@link APP_SPACE_ID}
61
- * (`'app'`); per-extension callers (planner / runner / verifier
62
- * extensions over contract spaces) pass the extension's space id.
63
- */
64
- readonly space: string;
65
- readonly storageHash: string;
66
- readonly profileHash: string;
67
- readonly contractJson?: unknown;
68
- readonly canonicalVersion?: number | null;
69
- readonly appTag?: string | null;
70
- readonly meta?: Record<string, unknown>;
71
- /**
72
- * Invariants to merge into `marker.invariants`. INSERT writes them as
73
- * the initial value (callers are expected to pass a sorted, deduped
74
- * array). UPDATE merges them with the existing column server-side via
75
- * a single atomic SQL expression.
76
- */
77
- readonly invariants: readonly string[];
78
- }
79
-
80
- export function buildMergeMarkerStatements(input: MergeMarkerInput): {
81
- readonly insert: SqlStatement;
82
- readonly update: SqlStatement;
83
- } {
84
- const params: readonly unknown[] = [
85
- input.space,
86
- input.storageHash,
87
- input.profileHash,
88
- jsonParam(input.contractJson),
89
- input.canonicalVersion ?? null,
90
- input.appTag ?? null,
91
- jsonParam(input.meta ?? {}),
92
- input.invariants,
93
- ];
94
-
95
- return {
96
- insert: {
97
- sql: `insert into prisma_contract.marker (
98
- space,
99
- core_hash,
100
- profile_hash,
101
- contract_json,
102
- canonical_version,
103
- updated_at,
104
- app_tag,
105
- meta,
106
- invariants
107
- ) values (
108
- $1,
109
- $2,
110
- $3,
111
- $4::jsonb,
112
- $5,
113
- now(),
114
- $6,
115
- $7::jsonb,
116
- $8::text[]
117
- )`,
118
- params,
119
- },
120
- update: {
121
- // `invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)`
122
- // reads the current column value under the UPDATE's row lock, unions
123
- // with the incoming array, dedupes, and sorts ascending — single
124
- // statement, atomic, no read-then-write window.
125
- sql: `update prisma_contract.marker set
126
- core_hash = $2,
127
- profile_hash = $3,
128
- contract_json = $4::jsonb,
129
- canonical_version = $5,
130
- updated_at = now(),
131
- app_tag = $6,
132
- meta = $7::jsonb,
133
- invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)
134
- where space = $1`,
135
- params,
136
- },
137
- };
138
- }
139
-
140
- export interface LedgerInsertInput {
141
- readonly originStorageHash?: string | null;
142
- readonly originProfileHash?: string | null;
143
- readonly destinationStorageHash: string;
144
- readonly destinationProfileHash?: string | null;
145
- readonly contractJsonBefore?: unknown;
146
- readonly contractJsonAfter?: unknown;
147
- readonly operations: unknown;
148
- }
149
-
150
- export function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStatement {
151
- return {
152
- sql: `insert into prisma_contract.ledger (
153
- origin_core_hash,
154
- origin_profile_hash,
155
- destination_core_hash,
156
- destination_profile_hash,
157
- contract_json_before,
158
- contract_json_after,
159
- operations
160
- ) values (
161
- $1,
162
- $2,
163
- $3,
164
- $4,
165
- $5::jsonb,
166
- $6::jsonb,
167
- $7::jsonb
168
- )`,
169
- params: [
170
- input.originStorageHash ?? null,
171
- input.originProfileHash ?? null,
172
- input.destinationStorageHash,
173
- input.destinationProfileHash ?? null,
174
- jsonParam(input.contractJsonBefore),
175
- jsonParam(input.contractJsonAfter),
176
- jsonParam(input.operations),
177
- ],
178
- };
179
- }
180
-
181
- function jsonParam(value: unknown): string {
182
- return JSON.stringify(value ?? null);
183
- }
@@ -1,8 +0,0 @@
1
- export type { SqlStatement } from '../core/migrations/statement-builders';
2
- export {
3
- APP_SPACE_ID,
4
- buildMergeMarkerStatements,
5
- ensureLedgerTableStatement,
6
- ensureMarkerTableStatement,
7
- ensurePrismaContractSchemaStatement,
8
- } from '../core/migrations/statement-builders';