@prisma-next/target-postgres 0.15.0 → 0.16.0-dev.10

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 (194) hide show
  1. package/dist/{authoring-BtsOWgI3.mjs → authoring-34L18kA1.mjs} +18 -8
  2. package/dist/authoring-34L18kA1.mjs.map +1 -0
  3. package/dist/canonicalize-D1F4vUnP.d.mts.map +1 -1
  4. package/dist/{codec-ids-CI144z7g.d.mts → codec-ids-BswpvvND.d.mts} +3 -3
  5. package/dist/codec-ids-BswpvvND.d.mts.map +1 -0
  6. package/dist/{codec-ids-B10ZZHzw.mjs → codec-ids-D3G8K0YM.mjs} +3 -2
  7. package/dist/codec-ids-D3G8K0YM.mjs.map +1 -0
  8. package/dist/codec-ids.d.mts +2 -2
  9. package/dist/codec-ids.mjs +2 -2
  10. package/dist/{codec-types-CTfT4U4O.d.mts → codec-types-CQ07nOz-.d.mts} +4 -5
  11. package/dist/codec-types-CQ07nOz-.d.mts.map +1 -0
  12. package/dist/codec-types.d.mts +1 -1
  13. package/dist/{codecs-D7W9O0Xx.d.mts → codecs-G4DTY0F_.d.mts} +35 -7
  14. package/dist/codecs-G4DTY0F_.d.mts.map +1 -0
  15. package/dist/{codecs-DRbb26Or.mjs → codecs-TCsGgW-Y.mjs} +77 -5
  16. package/dist/codecs-TCsGgW-Y.mjs.map +1 -0
  17. package/dist/codecs.d.mts +2 -3
  18. package/dist/codecs.d.mts.map +1 -1
  19. package/dist/codecs.mjs +2 -2
  20. package/dist/contract-free.d.mts +2 -3
  21. package/dist/contract-free.d.mts.map +1 -1
  22. package/dist/contract-free.mjs +3 -3
  23. package/dist/{control-policy-DtbkLLGv.mjs → control-policy-S7XBe07W.mjs} +44 -75
  24. package/dist/control-policy-S7XBe07W.mjs.map +1 -0
  25. package/dist/control.d.mts +0 -1
  26. package/dist/control.d.mts.map +1 -1
  27. package/dist/control.mjs +75 -25
  28. package/dist/control.mjs.map +1 -1
  29. package/dist/data-transform-BOWpliq8.mjs.map +1 -1
  30. package/dist/{data-transform-DPzwBMhW.d.mts → data-transform-CGvE8yGx.d.mts} +1 -2
  31. package/dist/data-transform-CGvE8yGx.d.mts.map +1 -0
  32. package/dist/data-transform.d.mts +1 -1
  33. package/dist/{ddl-GTTOvjx_.mjs → ddl-DHXKzQ99.mjs} +3 -3
  34. package/dist/{ddl-GTTOvjx_.mjs.map → ddl-DHXKzQ99.mjs.map} +1 -1
  35. package/dist/ddl.d.mts +1 -1
  36. package/dist/default-normalizer-B9ZUiyUE.mjs +264 -0
  37. package/dist/default-normalizer-B9ZUiyUE.mjs.map +1 -0
  38. package/dist/default-normalizer.d.mts +14 -2
  39. package/dist/default-normalizer.d.mts.map +1 -1
  40. package/dist/default-normalizer.mjs +2 -248
  41. package/dist/{descriptor-meta-CFQKLXl_.mjs → descriptor-meta-qubYaxQA.mjs} +9 -4
  42. package/dist/descriptor-meta-qubYaxQA.mjs.map +1 -0
  43. package/dist/{diff-database-schema-GncqMuSI.mjs → diff-database-schema-BRxq7l98.mjs} +92 -26
  44. package/dist/diff-database-schema-BRxq7l98.mjs.map +1 -0
  45. package/dist/diff-database-schema.d.mts +4 -13
  46. package/dist/diff-database-schema.d.mts.map +1 -1
  47. package/dist/diff-database-schema.mjs +1 -1
  48. package/dist/{errors-DO-w0EUS.mjs → errors-ByDS0xJL.mjs} +6 -6
  49. package/dist/errors-ByDS0xJL.mjs.map +1 -0
  50. package/dist/errors.d.mts +4 -4
  51. package/dist/errors.d.mts.map +1 -1
  52. package/dist/errors.mjs +1 -1
  53. package/dist/issue-planner.d.mts +1 -2
  54. package/dist/issue-planner.d.mts.map +1 -1
  55. package/dist/issue-planner.mjs +1 -1
  56. package/dist/migration.d.mts +3 -4
  57. package/dist/migration.d.mts.map +1 -1
  58. package/dist/migration.mjs +2 -2
  59. package/dist/native-type-normalizer.d.mts.map +1 -1
  60. package/dist/{nodes-Dv5eCSq9.d.mts → nodes-CQzM2hR0.d.mts} +1 -2
  61. package/dist/nodes-CQzM2hR0.d.mts.map +1 -0
  62. package/dist/{op-factory-call-C38NzvQD.mjs → op-factory-call-Ci3H6InB.mjs} +37 -21
  63. package/dist/op-factory-call-Ci3H6InB.mjs.map +1 -0
  64. package/dist/{op-factory-call-Bn9zDx4_.d.mts → op-factory-call-DT7kdjVP.d.mts} +10 -7
  65. package/dist/op-factory-call-DT7kdjVP.d.mts.map +1 -0
  66. package/dist/op-factory-call.d.mts +2 -2
  67. package/dist/op-factory-call.mjs +2 -2
  68. package/dist/pack.d.mts +122 -6
  69. package/dist/pack.d.mts.map +1 -1
  70. package/dist/pack.mjs +1 -1
  71. package/dist/{planner-kql24i_F.mjs → planner-BpL7uktH.mjs} +15 -15
  72. package/dist/planner-BpL7uktH.mjs.map +1 -0
  73. package/dist/planner-ddl-builders.d.mts +1 -2
  74. package/dist/planner-ddl-builders.d.mts.map +1 -1
  75. package/dist/planner-identity-values.d.mts +0 -1
  76. package/dist/planner-identity-values.d.mts.map +1 -1
  77. package/dist/{planner-produced-postgres-migration-BEY1T0Xm.d.mts → planner-produced-postgres-migration-8QP8eMph.d.mts} +3 -4
  78. package/dist/planner-produced-postgres-migration-8QP8eMph.d.mts.map +1 -0
  79. package/dist/{planner-produced-postgres-migration-D7y-PEHK.mjs → planner-produced-postgres-migration-D8exrrxA.mjs} +8 -5
  80. package/dist/planner-produced-postgres-migration-D8exrrxA.mjs.map +1 -0
  81. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  82. package/dist/planner-produced-postgres-migration.mjs +1 -1
  83. package/dist/planner-schema-lookup.d.mts +0 -1
  84. package/dist/planner-schema-lookup.d.mts.map +1 -1
  85. package/dist/{planner-sql-checks-zqNfs2XZ.mjs → planner-sql-checks-BuB877wH.mjs} +2 -2
  86. package/dist/{planner-sql-checks-zqNfs2XZ.mjs.map → planner-sql-checks-BuB877wH.mjs.map} +1 -1
  87. package/dist/planner-sql-checks.d.mts +0 -1
  88. package/dist/planner-sql-checks.d.mts.map +1 -1
  89. package/dist/planner-sql-checks.mjs +1 -1
  90. package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -1
  91. package/dist/planner.d.mts +9 -4
  92. package/dist/planner.d.mts.map +1 -1
  93. package/dist/planner.mjs +2 -2
  94. package/dist/{postgres-contract-view-C9j5cqP0.d.mts → postgres-contract-view-CeU7FJjW.d.mts} +4 -3
  95. package/dist/postgres-contract-view-CeU7FJjW.d.mts.map +1 -0
  96. package/dist/{postgres-contract-view-DM8sN1Ot.mjs → postgres-contract-view-DebHMqGR.mjs} +4 -4
  97. package/dist/{postgres-contract-view-DM8sN1Ot.mjs.map → postgres-contract-view-DebHMqGR.mjs.map} +1 -1
  98. package/dist/{postgres-database-schema-node-CJv5bfbs.d.mts → postgres-database-schema-node-DMXsIwAb.d.mts} +12 -4
  99. package/dist/postgres-database-schema-node-DMXsIwAb.d.mts.map +1 -0
  100. package/dist/{postgres-migration-arMSWU9b.mjs → postgres-migration-Bn3fj1I4.mjs} +22 -6
  101. package/dist/postgres-migration-Bn3fj1I4.mjs.map +1 -0
  102. package/dist/{postgres-migration-DbckK1su.d.mts → postgres-migration-DLIvzHjX.d.mts} +31 -7
  103. package/dist/postgres-migration-DLIvzHjX.d.mts.map +1 -0
  104. package/dist/{postgres-rls-policy--CSddvMR.d.mts → postgres-rls-policy-CYXdqG9B.d.mts} +1 -2
  105. package/dist/postgres-rls-policy-CYXdqG9B.d.mts.map +1 -0
  106. package/dist/{postgres-role-schema-node-Cm-j0ZGM.mjs → postgres-role-schema-node-bg32e7I-.mjs} +3 -2
  107. package/dist/postgres-role-schema-node-bg32e7I-.mjs.map +1 -0
  108. package/dist/{postgres-schema-Cm4DtiGA.mjs → postgres-schema-CewLYHB7.mjs} +2 -2
  109. package/dist/{postgres-schema-Cm4DtiGA.mjs.map → postgres-schema-CewLYHB7.mjs.map} +1 -1
  110. package/dist/{postgres-schema-DKq6s1P3.d.mts → postgres-schema-FdKRwe7X.d.mts} +3 -4
  111. package/dist/postgres-schema-FdKRwe7X.d.mts.map +1 -0
  112. package/dist/render-ops.d.mts +0 -1
  113. package/dist/render-ops.d.mts.map +1 -1
  114. package/dist/{render-typescript-7yqILcwr.mjs → render-typescript-Ta7_6CGf.mjs} +20 -8
  115. package/dist/render-typescript-Ta7_6CGf.mjs.map +1 -0
  116. package/dist/render-typescript.d.mts +2 -1
  117. package/dist/render-typescript.d.mts.map +1 -1
  118. package/dist/render-typescript.mjs +1 -1
  119. package/dist/{resolve-ddl-schema-XyBaaenM.mjs → resolve-ddl-schema-D0wi_P9Q.mjs} +2 -2
  120. package/dist/{resolve-ddl-schema-XyBaaenM.mjs.map → resolve-ddl-schema-D0wi_P9Q.mjs.map} +1 -1
  121. package/dist/rls-canonicalize.d.mts +0 -1
  122. package/dist/rls-canonicalize.d.mts.map +1 -1
  123. package/dist/runtime.d.mts +1 -2
  124. package/dist/runtime.d.mts.map +1 -1
  125. package/dist/runtime.mjs +1 -1
  126. package/dist/schema-ir-annotations.d.mts +0 -1
  127. package/dist/schema-ir-annotations.d.mts.map +1 -1
  128. package/dist/schema-ir-annotations.mjs +1 -1
  129. package/dist/schema-node-kinds-DxvWh2Ic.d.mts +29 -0
  130. package/dist/schema-node-kinds-DxvWh2Ic.d.mts.map +1 -0
  131. package/dist/sql-utils.d.mts.map +1 -1
  132. package/dist/{table-source-BvFo7gVs.d.mts → table-source-D5c2fxAQ.d.mts} +1 -2
  133. package/dist/table-source-D5c2fxAQ.d.mts.map +1 -0
  134. package/dist/{types-BDKkx8MA.d.mts → types-D2MLzLBD.d.mts} +1 -2
  135. package/dist/types-D2MLzLBD.d.mts.map +1 -0
  136. package/dist/types.d.mts +6 -5
  137. package/dist/types.mjs +4 -4
  138. package/package.json +21 -21
  139. package/src/core/authoring.ts +18 -5
  140. package/src/core/codec-helpers.ts +53 -1
  141. package/src/core/codec-ids.ts +1 -0
  142. package/src/core/codecs.ts +56 -3
  143. package/src/core/default-normalizer.ts +22 -0
  144. package/src/core/descriptor-meta.ts +2 -0
  145. package/src/core/errors.ts +5 -5
  146. package/src/core/index-types.ts +15 -0
  147. package/src/core/migrations/contract-to-postgres-database-schema-node.ts +99 -19
  148. package/src/core/migrations/control-policy.ts +4 -3
  149. package/src/core/migrations/diff-database-schema.ts +6 -3
  150. package/src/core/migrations/issue-planner.ts +41 -80
  151. package/src/core/migrations/op-factory-call.ts +41 -22
  152. package/src/core/migrations/operations/data-transform.ts +2 -2
  153. package/src/core/migrations/planner-produced-postgres-migration.ts +9 -2
  154. package/src/core/migrations/planner-strategies.ts +6 -6
  155. package/src/core/migrations/planner.ts +13 -4
  156. package/src/core/migrations/postgres-migration.ts +62 -2
  157. package/src/core/migrations/render-typescript.ts +20 -8
  158. package/src/core/migrations/runner.ts +12 -11
  159. package/src/core/migrations/verify-postgres-namespaces.ts +0 -1
  160. package/src/core/psl-infer/infer-psl-contract.ts +130 -12
  161. package/src/core/schema-ir/postgres-policy-schema-node.ts +12 -2
  162. package/src/exports/codecs.ts +2 -0
  163. package/src/exports/control.ts +2 -0
  164. package/src/exports/default-normalizer.ts +1 -1
  165. package/src/exports/op-factory-call.ts +5 -0
  166. package/src/exports/types.ts +1 -0
  167. package/dist/authoring-BtsOWgI3.mjs.map +0 -1
  168. package/dist/codec-ids-B10ZZHzw.mjs.map +0 -1
  169. package/dist/codec-ids-CI144z7g.d.mts.map +0 -1
  170. package/dist/codec-types-CTfT4U4O.d.mts.map +0 -1
  171. package/dist/codecs-D7W9O0Xx.d.mts.map +0 -1
  172. package/dist/codecs-DRbb26Or.mjs.map +0 -1
  173. package/dist/control-policy-DtbkLLGv.mjs.map +0 -1
  174. package/dist/data-transform-DPzwBMhW.d.mts.map +0 -1
  175. package/dist/default-normalizer.mjs.map +0 -1
  176. package/dist/descriptor-meta-CFQKLXl_.mjs.map +0 -1
  177. package/dist/diff-database-schema-GncqMuSI.mjs.map +0 -1
  178. package/dist/errors-DO-w0EUS.mjs.map +0 -1
  179. package/dist/nodes-Dv5eCSq9.d.mts.map +0 -1
  180. package/dist/op-factory-call-Bn9zDx4_.d.mts.map +0 -1
  181. package/dist/op-factory-call-C38NzvQD.mjs.map +0 -1
  182. package/dist/planner-kql24i_F.mjs.map +0 -1
  183. package/dist/planner-produced-postgres-migration-BEY1T0Xm.d.mts.map +0 -1
  184. package/dist/planner-produced-postgres-migration-D7y-PEHK.mjs.map +0 -1
  185. package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +0 -1
  186. package/dist/postgres-database-schema-node-CJv5bfbs.d.mts.map +0 -1
  187. package/dist/postgres-migration-DbckK1su.d.mts.map +0 -1
  188. package/dist/postgres-migration-arMSWU9b.mjs.map +0 -1
  189. package/dist/postgres-rls-policy--CSddvMR.d.mts.map +0 -1
  190. package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs.map +0 -1
  191. package/dist/postgres-schema-DKq6s1P3.d.mts.map +0 -1
  192. package/dist/render-typescript-7yqILcwr.mjs.map +0 -1
  193. package/dist/table-source-BvFo7gVs.d.mts.map +0 -1
  194. package/dist/types-BDKkx8MA.d.mts.map +0 -1
@@ -1,248 +1,2 @@
1
- //#region src/core/default-normalizer.ts
2
- /**
3
- * Pre-compiled regex patterns for performance.
4
- * These are compiled once at module load time rather than on each function call.
5
- */
6
- const NEXTVAL_PATTERN = /^nextval\s*\(/i;
7
- const NOW_FUNCTION_PATTERN = /^(now\s*\(\s*\)|CURRENT_TIMESTAMP)$/i;
8
- const CLOCK_TIMESTAMP_PATTERN = /^clock_timestamp\s*\(\s*\)$/i;
9
- const TIMESTAMP_CAST_SUFFIX = /::timestamp(?:tz|\s+(?:with|without)\s+time\s+zone)?$/i;
10
- const TEXT_CAST_SUFFIX = /::text$/i;
11
- const NOW_LITERAL_PATTERN = /^'now'$/i;
12
- const UUID_PATTERN = /^gen_random_uuid\s*\(\s*\)$/i;
13
- const UUID_OSSP_PATTERN = /^uuid_generate_v4\s*\(\s*\)$/i;
14
- const NULL_PATTERN = /^NULL(?:::.+)?$/i;
15
- const TRUE_PATTERN = /^true$/i;
16
- const FALSE_PATTERN = /^false$/i;
17
- const NUMERIC_PATTERN = /^-?\d+(\.\d+)?$/;
18
- const STRING_LITERAL_PATTERN = /^'((?:[^']|'')*)'(?:::(?:"[^"]+"|[\w\s]+)(?:\(\d+\))?)?$/;
19
- /**
20
- * Matches a Postgres array literal default of the form `'{...}'::elemtype[]`.
21
- * The literal body is captured in group 1; the cast (including `[]`) is optional.
22
- * Examples: `'{}'::text[]`, `'{1,2}'::integer[]`, `'{}'`
23
- */
24
- const ARRAY_LITERAL_PATTERN = /^'(\{.*\})'(?:::.+\[\])?$/;
25
- /**
26
- * Returns the canonical expression for a timestamp default function, or undefined
27
- * if the expression is not a recognized timestamp default.
28
- *
29
- * Keeps now()/CURRENT_TIMESTAMP and clock_timestamp() distinct:
30
- * - now(), CURRENT_TIMESTAMP, ('now'::text)::timestamp... → 'now()'
31
- * - clock_timestamp(), clock_timestamp()::timestamptz → 'clock_timestamp()'
32
- *
33
- * These are semantically different in Postgres: now() returns the transaction
34
- * start time (constant within a transaction), while clock_timestamp() returns
35
- * the actual wall-clock time (can differ across rows in a single INSERT).
36
- */
37
- function canonicalizeTimestampDefault(expr) {
38
- if (NOW_FUNCTION_PATTERN.test(expr)) return "now()";
39
- if (CLOCK_TIMESTAMP_PATTERN.test(expr)) return "clock_timestamp()";
40
- if (!TIMESTAMP_CAST_SUFFIX.test(expr)) return void 0;
41
- let inner = expr.replace(TIMESTAMP_CAST_SUFFIX, "").trim();
42
- if (inner.startsWith("(") && inner.endsWith(")")) inner = inner.slice(1, -1).trim();
43
- if (NOW_FUNCTION_PATTERN.test(inner)) return "now()";
44
- if (CLOCK_TIMESTAMP_PATTERN.test(inner)) return "clock_timestamp()";
45
- inner = inner.replace(TEXT_CAST_SUFFIX, "").trim();
46
- if (NOW_LITERAL_PATTERN.test(inner)) return "now()";
47
- }
48
- /**
49
- * Splits a Postgres array literal body (without the enclosing braces) into its
50
- * element tokens, honouring quoting. A comma only separates elements when it is
51
- * outside double quotes; inside a quoted element a doubled quote (`""`) or a
52
- * backslash-escaped quote (`\"`) is a literal quote, and a backslash escapes the
53
- * next character. Returns undefined if the body is malformed (e.g. an unbalanced
54
- * quote).
55
- */
56
- function splitArrayElements(inner) {
57
- const tokens = [];
58
- let current = "";
59
- let inQuotes = false;
60
- let quoted = false;
61
- for (let i = 0; i < inner.length; i++) {
62
- const char = inner[i];
63
- if (inQuotes) {
64
- if (char === "\\") {
65
- const next = inner[i + 1];
66
- if (next === void 0) return void 0;
67
- current += next;
68
- i++;
69
- continue;
70
- }
71
- if (char === "\"") {
72
- if (inner[i + 1] === "\"") {
73
- current += "\"";
74
- i++;
75
- continue;
76
- }
77
- inQuotes = false;
78
- continue;
79
- }
80
- current += char;
81
- continue;
82
- }
83
- if (char === "\"") {
84
- inQuotes = true;
85
- quoted = true;
86
- continue;
87
- }
88
- if (char === ",") {
89
- tokens.push({
90
- value: current,
91
- quoted
92
- });
93
- current = "";
94
- quoted = false;
95
- continue;
96
- }
97
- current += char;
98
- }
99
- if (inQuotes) return void 0;
100
- tokens.push({
101
- value: current,
102
- quoted
103
- });
104
- return tokens;
105
- }
106
- /**
107
- * Parses a Postgres array literal body (`{...}`) into a JS array of primitives.
108
- * Returns undefined if the body cannot be reliably parsed.
109
- *
110
- * Handles:
111
- * - `{}` → `[]`
112
- * - `{elem1,elem2,...}` → `[elem1, elem2, ...]` with numeric and string element coercion
113
- * - quoted elements that contain commas, doubled/escaped quotes, and the literal
114
- * strings `NULL`/`true`/`false` (a quoted token is always a string)
115
- */
116
- function parseArrayLiteralBody(body) {
117
- const inner = body.slice(1, -1).trim();
118
- if (inner === "") return [];
119
- const tokens = splitArrayElements(inner);
120
- if (tokens === void 0) return void 0;
121
- const result = [];
122
- for (const token of tokens) {
123
- if (token.quoted) {
124
- result.push(token.value);
125
- continue;
126
- }
127
- const el = token.value.trim();
128
- if (el.toUpperCase() === "NULL") {
129
- result.push(null);
130
- continue;
131
- }
132
- if (el === "true") {
133
- result.push(true);
134
- continue;
135
- }
136
- if (el === "false") {
137
- result.push(false);
138
- continue;
139
- }
140
- if (NUMERIC_PATTERN.test(el)) {
141
- result.push(Number(el));
142
- continue;
143
- }
144
- return;
145
- }
146
- return result;
147
- }
148
- /**
149
- * Parses a raw Postgres column default expression into a normalized ColumnDefault.
150
- * This enables semantic comparison between contract defaults and introspected schema defaults.
151
- *
152
- * Used by the migration diff layer to normalize raw database defaults during comparison,
153
- * keeping the introspection layer focused on faithful data capture.
154
- *
155
- * @param rawDefault - Raw default expression from information_schema.columns.column_default
156
- * @param nativeType - Native column type, used for type-aware parsing (array, bigint, JSON)
157
- * @returns Normalized ColumnDefault or undefined if the expression cannot be parsed
158
- */
159
- function parsePostgresDefault(rawDefault, nativeType) {
160
- const trimmed = rawDefault.trim();
161
- const normalizedType = nativeType?.toLowerCase();
162
- const isBigInt = normalizedType === "bigint" || normalizedType === "int8";
163
- const isArrayType = normalizedType?.endsWith("[]") ?? false;
164
- if (NEXTVAL_PATTERN.test(trimmed)) return {
165
- kind: "function",
166
- expression: "autoincrement()"
167
- };
168
- if (isArrayType) {
169
- const arrayMatch = trimmed.match(ARRAY_LITERAL_PATTERN);
170
- if (arrayMatch?.[1] !== void 0) {
171
- const parsed = parseArrayLiteralBody(arrayMatch[1]);
172
- if (parsed !== void 0) return {
173
- kind: "literal",
174
- value: parsed
175
- };
176
- }
177
- }
178
- const canonicalTimestamp = canonicalizeTimestampDefault(trimmed);
179
- if (canonicalTimestamp) return {
180
- kind: "function",
181
- expression: canonicalTimestamp
182
- };
183
- if (UUID_PATTERN.test(trimmed)) return {
184
- kind: "function",
185
- expression: "gen_random_uuid()"
186
- };
187
- if (UUID_OSSP_PATTERN.test(trimmed)) return {
188
- kind: "function",
189
- expression: "gen_random_uuid()"
190
- };
191
- if (NULL_PATTERN.test(trimmed)) return {
192
- kind: "literal",
193
- value: null
194
- };
195
- if (TRUE_PATTERN.test(trimmed)) return {
196
- kind: "literal",
197
- value: true
198
- };
199
- if (FALSE_PATTERN.test(trimmed)) return {
200
- kind: "literal",
201
- value: false
202
- };
203
- if (NUMERIC_PATTERN.test(trimmed)) {
204
- const num = Number(trimmed);
205
- if (!Number.isFinite(num)) return void 0;
206
- if (isBigInt && !Number.isSafeInteger(num)) return {
207
- kind: "literal",
208
- value: trimmed
209
- };
210
- return {
211
- kind: "literal",
212
- value: num
213
- };
214
- }
215
- const stringMatch = trimmed.match(STRING_LITERAL_PATTERN);
216
- if (stringMatch?.[1] !== void 0) {
217
- const unescaped = stringMatch[1].replace(/''/g, "'");
218
- if (normalizedType === "json" || normalizedType === "jsonb") try {
219
- return {
220
- kind: "literal",
221
- value: JSON.parse(unescaped)
222
- };
223
- } catch {}
224
- if (isBigInt && NUMERIC_PATTERN.test(unescaped)) {
225
- const num = Number(unescaped);
226
- if (Number.isSafeInteger(num)) return {
227
- kind: "literal",
228
- value: num
229
- };
230
- return {
231
- kind: "literal",
232
- value: unescaped
233
- };
234
- }
235
- return {
236
- kind: "literal",
237
- value: unescaped
238
- };
239
- }
240
- return {
241
- kind: "function",
242
- expression: trimmed
243
- };
244
- }
245
- //#endregion
246
- export { parsePostgresDefault };
247
-
248
- //# sourceMappingURL=default-normalizer.mjs.map
1
+ import { n as postgresResolveDefault, t as parsePostgresDefault } from "./default-normalizer-B9ZUiyUE.mjs";
2
+ export { parsePostgresDefault, postgresResolveDefault };
@@ -1,11 +1,16 @@
1
- import { E as postgresQualifyColumnType } from "./codecs-DRbb26Or.mjs";
1
+ import { D as postgresQualifyColumnType } from "./codecs-TCsGgW-Y.mjs";
2
2
  import { t as DEFAULT_NAMESPACE_ID } from "./namespace-ids-xtp_ZY86.mjs";
3
- import { i as postgresCreateNamespace } from "./postgres-schema-Cm4DtiGA.mjs";
4
- import { a as postgresAuthoringTypes, i as postgresAuthoringPslBlockDescriptors, n as postgresAuthoringFieldPresets, o as postgresLowerEntityHandles, r as postgresAuthoringModelAttributes, t as postgresAuthoringEntityTypes } from "./authoring-BtsOWgI3.mjs";
3
+ import { i as postgresCreateNamespace } from "./postgres-schema-CewLYHB7.mjs";
4
+ import { a as postgresAuthoringTypes, i as postgresAuthoringPslBlockDescriptors, n as postgresAuthoringFieldPresets, o as postgresLowerEntityHandles, r as postgresAuthoringModelAttributes, t as postgresAuthoringEntityTypes } from "./authoring-34L18kA1.mjs";
5
5
  import { t as postgresTargetDescriptorMetaRuntime } from "./descriptor-meta-runtime-UwYdV8fD.mjs";
6
+ import { type } from "arktype";
7
+ import { defineIndexTypes } from "@prisma-next/sql-contract/index-types";
8
+ //#region src/core/index-types.ts
9
+ const postgresIndexTypes = defineIndexTypes().add("btree", { options: type("object") }).add("hash", { options: type("object") }).add("gin", { options: type("object") }).add("gist", { options: type("object") }).add("spgist", { options: type("object") }).add("brin", { options: type("object") });
6
10
  const postgresTargetDescriptorMeta = {
7
11
  ...postgresTargetDescriptorMetaRuntime,
8
12
  defaultNamespaceId: DEFAULT_NAMESPACE_ID,
13
+ indexTypes: postgresIndexTypes,
9
14
  authoring: {
10
15
  type: postgresAuthoringTypes,
11
16
  field: postgresAuthoringFieldPresets,
@@ -20,4 +25,4 @@ const postgresTargetDescriptorMeta = {
20
25
  //#endregion
21
26
  export { postgresTargetDescriptorMeta as t };
22
27
 
23
- //# sourceMappingURL=descriptor-meta-CFQKLXl_.mjs.map
28
+ //# sourceMappingURL=descriptor-meta-qubYaxQA.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor-meta-qubYaxQA.mjs","names":[],"sources":["../src/core/index-types.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import { defineIndexTypes } from '@prisma-next/sql-contract/index-types';\nimport { type } from 'arktype';\n\n// Postgres's built-in index access methods (`CREATE INDEX ... USING <method>`).\n// Per-method option validation (e.g. `gin` operator classes) is out of scope;\n// every method accepts any options object until a later slice narrows it.\nexport const postgresIndexTypes = defineIndexTypes()\n .add('btree', { options: type('object') })\n .add('hash', { options: type('object') })\n .add('gin', { options: type('object') })\n .add('gist', { options: type('object') })\n .add('spgist', { options: type('object') })\n .add('brin', { options: type('object') });\n\nexport type IndexTypes = typeof postgresIndexTypes.IndexTypes;\n","import type { CodecTypes } from '../exports/codec-types';\nimport {\n postgresAuthoringEntityTypes,\n postgresAuthoringFieldPresets,\n postgresAuthoringModelAttributes,\n postgresAuthoringPslBlockDescriptors,\n postgresAuthoringTypes,\n postgresLowerEntityHandles,\n} from './authoring';\nimport { postgresQualifyColumnType } from './codecs';\nimport { postgresTargetDescriptorMetaRuntime } from './descriptor-meta-runtime';\nimport { postgresIndexTypes } from './index-types';\nimport { DEFAULT_NAMESPACE_ID } from './namespace-ids';\nimport { postgresCreateNamespace } from './postgres-schema';\n\nconst postgresTargetDescriptorMetaBase = {\n ...postgresTargetDescriptorMetaRuntime,\n defaultNamespaceId: DEFAULT_NAMESPACE_ID,\n indexTypes: postgresIndexTypes,\n authoring: {\n type: postgresAuthoringTypes,\n field: postgresAuthoringFieldPresets,\n entityTypes: postgresAuthoringEntityTypes,\n pslBlockDescriptors: postgresAuthoringPslBlockDescriptors,\n modelAttributes: postgresAuthoringModelAttributes,\n createNamespace: postgresCreateNamespace,\n qualifyColumnType: postgresQualifyColumnType,\n lowerEntityHandles: postgresLowerEntityHandles,\n },\n} as const;\n\nexport const postgresTargetDescriptorMeta: typeof postgresTargetDescriptorMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = postgresTargetDescriptorMetaBase;\n"],"mappings":";;;;;;;;AAMA,MAAa,qBAAqB,iBAAiB,CAAC,CACjD,IAAI,SAAS,EAAE,SAAS,KAAK,QAAQ,EAAE,CAAC,CAAC,CACzC,IAAI,QAAQ,EAAE,SAAS,KAAK,QAAQ,EAAE,CAAC,CAAC,CACxC,IAAI,OAAO,EAAE,SAAS,KAAK,QAAQ,EAAE,CAAC,CAAC,CACvC,IAAI,QAAQ,EAAE,SAAS,KAAK,QAAQ,EAAE,CAAC,CAAC,CACxC,IAAI,UAAU,EAAE,SAAS,KAAK,QAAQ,EAAE,CAAC,CAAC,CAC1C,IAAI,QAAQ,EAAE,SAAS,KAAK,QAAQ,EAAE,CAAC;ACmB1C,MAAa,+BAET;CAjBF,GAAG;CACH,oBAAoB;CACpB,YAAY;CACZ,WAAW;EACT,MAAM;EACN,OAAO;EACP,aAAa;EACb,qBAAqB;EACrB,iBAAiB;EACjB,iBAAiB;EACjB,mBAAmB;EACnB,oBAAoB;CACtB;AAKE"}
@@ -1,16 +1,55 @@
1
- import { r as isPostgresSchema } from "./postgres-schema-Cm4DtiGA.mjs";
2
- import { a as postgresDiffSubjectGranularity, n as PostgresNativeEnumSchemaNode, t as PostgresTableSchemaNode } from "./postgres-table-schema-node-D6LvInCe.mjs";
3
- import { i as PostgresDatabaseSchemaNode, n as PostgresPolicySchemaNode, r as PostgresNamespaceSchemaNode, t as PostgresRoleSchemaNode } from "./postgres-role-schema-node-Cm-j0ZGM.mjs";
4
- import { t as resolveDdlSchemaForNamespaceStorage } from "./resolve-ddl-schema-XyBaaenM.mjs";
5
- import { i as resolvePostgresNodeIssueControlPolicySubject } from "./control-policy-DtbkLLGv.mjs";
1
+ import { n as postgresResolveDefault } from "./default-normalizer-B9ZUiyUE.mjs";
2
+ import { r as isPostgresSchema } from "./postgres-schema-CewLYHB7.mjs";
3
+ import { a as postgresDiffSubjectGranularity, n as PostgresNativeEnumSchemaNode, r as PostgresSchemaNodeKind, t as PostgresTableSchemaNode } from "./postgres-table-schema-node-D6LvInCe.mjs";
4
+ import { i as PostgresDatabaseSchemaNode, n as PostgresPolicySchemaNode, r as PostgresNamespaceSchemaNode, t as PostgresRoleSchemaNode } from "./postgres-role-schema-node-bg32e7I-.mjs";
5
+ import { t as resolveDdlSchemaForNamespaceStorage } from "./resolve-ddl-schema-D0wi_P9Q.mjs";
6
+ import { i as resolvePostgresNodeIssueControlPolicySubject } from "./control-policy-S7XBe07W.mjs";
6
7
  import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
7
8
  import { blindCast } from "@prisma-next/utils/casts";
8
9
  import { buildNativeTypeExpander, contractNamespaceToSchemaIR } from "@prisma-next/family-sql/control";
9
10
  import { ifDefined } from "@prisma-next/utils/defined";
10
- import { SqlForeignKeyIR } from "@prisma-next/sql-schema-ir/types";
11
+ import { PrimaryKey, RelationalSchemaNodeKind, SqlForeignKeyIR, SqlIndexIR, SqlUniqueIR } from "@prisma-next/sql-schema-ir/types";
11
12
  import { classifyDiffSubjectGranularity } from "@prisma-next/family-sql/diff";
12
- import { diffSchemas } from "@prisma-next/framework-components/control";
13
+ import { diffSchemas, issueOutcome } from "@prisma-next/framework-components/control";
13
14
  //#region src/core/migrations/contract-to-postgres-database-schema-node.ts
15
+ /** The database root's fixed sentinel id (`PostgresDatabaseSchemaNode#id`). */
16
+ function databaseStep() {
17
+ return {
18
+ nodeKind: PostgresSchemaNodeKind.database,
19
+ id: "database"
20
+ };
21
+ }
22
+ function tableDependsOn(namespaceId, tableName) {
23
+ return [
24
+ databaseStep(),
25
+ {
26
+ nodeKind: PostgresSchemaNodeKind.namespace,
27
+ id: namespaceId
28
+ },
29
+ {
30
+ nodeKind: PostgresSchemaNodeKind.table,
31
+ id: tableName
32
+ }
33
+ ];
34
+ }
35
+ function roleDependsOn(role) {
36
+ return [databaseStep(), {
37
+ nodeKind: PostgresSchemaNodeKind.role,
38
+ id: role
39
+ }];
40
+ }
41
+ /**
42
+ * The chains from a table-child object (foreign key, index, unique, primary
43
+ * key) to each of the own columns it is built on, in the Postgres tree.
44
+ * Dropping a covered column auto-drops the object, so the object's drop must
45
+ * precede the column's; the graph derives that direction from these edges.
46
+ */
47
+ function columnDependsOn(namespaceId, tableName, columns) {
48
+ return columns.map((column) => [...tableDependsOn(namespaceId, tableName), {
49
+ nodeKind: RelationalSchemaNodeKind.column,
50
+ id: `column:${column}`
51
+ }]);
52
+ }
14
53
  function toPolicyNode(policy, namespaceId) {
15
54
  return new PostgresPolicySchemaNode({
16
55
  name: policy.name,
@@ -21,7 +60,8 @@ function toPolicyNode(policy, namespaceId) {
21
60
  roles: [...policy.roles],
22
61
  ...ifDefined("using", policy.using),
23
62
  ...ifDefined("withCheck", policy.withCheck),
24
- permissive: policy.permissive
63
+ permissive: policy.permissive,
64
+ dependsOn: [tableDependsOn(namespaceId, policy.tableName), ...policy.roles.map(roleDependsOn)]
25
65
  });
26
66
  }
27
67
  /**
@@ -76,24 +116,48 @@ function contractToPostgresDatabaseSchemaNode(contract, options) {
76
116
  for (const tableName of Object.keys(ns.table)) {
77
117
  const sqlTable = sqlTables[tableName];
78
118
  if (sqlTable === void 0) continue;
79
- const foreignKeys = sqlTable.foreignKeys.map((fk) => new SqlForeignKeyIR({
80
- columns: fk.columns,
81
- referencedTable: fk.referencedTable,
82
- referencedColumns: fk.referencedColumns,
83
- referencedSchema: fk.referencedSchema ?? UNBOUND_NAMESPACE_ID,
84
- ...ifDefined("name", fk.name),
85
- ...ifDefined("onDelete", fk.onDelete),
86
- ...ifDefined("onUpdate", fk.onUpdate),
87
- ...ifDefined("annotations", fk.annotations),
88
- resolvedReferencedNamespace: resolveDdlSchemaForNamespaceStorage(contract.storage, fk.referencedSchema ?? UNBOUND_NAMESPACE_ID)
119
+ const foreignKeys = sqlTable.foreignKeys.map((fk) => {
120
+ const resolvedReferencedNamespace = resolveDdlSchemaForNamespaceStorage(contract.storage, fk.referencedSchema ?? UNBOUND_NAMESPACE_ID);
121
+ return new SqlForeignKeyIR({
122
+ columns: fk.columns,
123
+ referencedTable: fk.referencedTable,
124
+ referencedColumns: fk.referencedColumns,
125
+ referencedSchema: fk.referencedSchema ?? UNBOUND_NAMESPACE_ID,
126
+ ...ifDefined("name", fk.name),
127
+ ...ifDefined("onDelete", fk.onDelete),
128
+ ...ifDefined("onUpdate", fk.onUpdate),
129
+ ...ifDefined("annotations", fk.annotations),
130
+ resolvedReferencedNamespace,
131
+ dependsOn: [tableDependsOn(resolvedReferencedNamespace, fk.referencedTable), ...columnDependsOn(ddlSchema, tableName, fk.columns)]
132
+ });
133
+ });
134
+ const uniques = sqlTable.uniques.map((u) => new SqlUniqueIR({
135
+ columns: u.columns,
136
+ ...ifDefined("name", u.name),
137
+ ...ifDefined("annotations", u.annotations),
138
+ dependsOn: columnDependsOn(ddlSchema, tableName, u.columns)
139
+ }));
140
+ const indexes = sqlTable.indexes.map((i) => new SqlIndexIR({
141
+ columns: i.columns,
142
+ unique: i.unique,
143
+ ...ifDefined("name", i.name),
144
+ ...ifDefined("type", i.type),
145
+ ...ifDefined("options", i.options),
146
+ ...ifDefined("annotations", i.annotations),
147
+ dependsOn: columnDependsOn(ddlSchema, tableName, i.columns)
89
148
  }));
149
+ const primaryKey = sqlTable.primaryKey !== void 0 ? new PrimaryKey({
150
+ columns: sqlTable.primaryKey.columns,
151
+ ...ifDefined("name", sqlTable.primaryKey.name),
152
+ dependsOn: columnDependsOn(ddlSchema, tableName, sqlTable.primaryKey.columns)
153
+ }) : void 0;
90
154
  tables[tableName] = new PostgresTableSchemaNode({
91
155
  name: sqlTable.name,
92
156
  columns: sqlTable.columns,
93
157
  foreignKeys,
94
- uniques: sqlTable.uniques,
95
- indexes: sqlTable.indexes,
96
- ...ifDefined("primaryKey", sqlTable.primaryKey),
158
+ uniques,
159
+ indexes,
160
+ ...ifDefined("primaryKey", primaryKey),
97
161
  ...ifDefined("annotations", sqlTable.annotations),
98
162
  ...ifDefined("checks", sqlTable.checks),
99
163
  policies: policiesByTable.get(tableName) ?? [],
@@ -214,14 +278,15 @@ function diffPostgresSchema(input) {
214
278
  const actual = input.schema;
215
279
  const fullExpected = contractToPostgresDatabaseSchemaNode(postgresContract, {
216
280
  annotationNamespace: "pg",
217
- ...ifDefined("expandNativeType", buildNativeTypeExpander(input.frameworkComponents))
281
+ ...ifDefined("expandNativeType", buildNativeTypeExpander(input.frameworkComponents)),
282
+ resolveDefault: postgresResolveDefault
218
283
  });
219
284
  const expected = pruneTableLessNamespaces(fullExpected);
220
285
  const relationalOwned = ownedSchemaNames(expected);
221
286
  const structuralOwned = ownedSchemaNames(fullExpected);
222
287
  return {
223
288
  issues: diffSchemas(expected, actual).filter((issue) => {
224
- if (issue.reason !== "not-expected") return true;
289
+ if (issueOutcome(issue) !== "not-expected") return true;
225
290
  if (isClusterScopedIssue(issue)) return true;
226
291
  const granularity = classifyDiffSubjectGranularity(issue, postgresDiffSubjectGranularity);
227
292
  const namespaceSegment = issue.path[1];
@@ -280,7 +345,8 @@ function buildPostgresPlanDiff(input) {
280
345
  const actual = input.actualSchema;
281
346
  const fullExpected = contractToPostgresDatabaseSchemaNode(postgresContract, {
282
347
  annotationNamespace: "pg",
283
- ...ifDefined("expandNativeType", buildNativeTypeExpander(input.frameworkComponents))
348
+ ...ifDefined("expandNativeType", buildNativeTypeExpander(input.frameworkComponents)),
349
+ resolveDefault: postgresResolveDefault
284
350
  });
285
351
  const expected = pruneTableLessNamespaces(fullExpected);
286
352
  const paddedActual = padActualNamespaces(expected, actual);
@@ -290,7 +356,7 @@ function buildPostgresPlanDiff(input) {
290
356
  expected,
291
357
  actual: paddedActual,
292
358
  issues: blindCast(diffSchemas(expected, paddedActual)).filter((issue) => {
293
- if (issue.reason !== "not-expected") return true;
359
+ if (issueOutcome(issue) !== "not-expected") return true;
294
360
  if (isClusterScopedIssue(issue)) return true;
295
361
  const granularity = classifyDiffSubjectGranularity(issue, postgresDiffSubjectGranularity);
296
362
  const namespaceSegment = issue.path[1];
@@ -302,4 +368,4 @@ function buildPostgresPlanDiff(input) {
302
368
  //#endregion
303
369
  export { diffPostgresSchema as n, contractToPostgresDatabaseSchemaNode as r, buildPostgresPlanDiff as t };
304
370
 
305
- //# sourceMappingURL=diff-database-schema-GncqMuSI.mjs.map
371
+ //# sourceMappingURL=diff-database-schema-BRxq7l98.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff-database-schema-BRxq7l98.mjs","names":[],"sources":["../src/core/migrations/contract-to-postgres-database-schema-node.ts","../src/core/migrations/diff-database-schema.ts"],"sourcesContent":["import type { ContractToSchemaIROptions } from '@prisma-next/family-sql/control';\nimport { contractNamespaceToSchemaIR } from '@prisma-next/family-sql/control';\nimport type { SchemaNodeRef } from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport {\n PrimaryKey,\n RelationalSchemaNodeKind,\n SqlForeignKeyIR,\n SqlIndexIR,\n SqlUniqueIR,\n} from '@prisma-next/sql-schema-ir/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { PostgresRlsPolicy } from '../postgres-rls-policy';\nimport type { PostgresContract } from '../postgres-schema';\nimport { isPostgresSchema } from '../postgres-schema';\nimport { PostgresDatabaseSchemaNode } from '../schema-ir/postgres-database-schema-node';\nimport { PostgresNamespaceSchemaNode } from '../schema-ir/postgres-namespace-schema-node';\nimport { PostgresNativeEnumSchemaNode } from '../schema-ir/postgres-native-enum-schema-node';\nimport { PostgresPolicySchemaNode } from '../schema-ir/postgres-policy-schema-node';\nimport { PostgresRoleSchemaNode } from '../schema-ir/postgres-role-schema-node';\nimport { PostgresTableSchemaNode } from '../schema-ir/postgres-table-schema-node';\nimport { PostgresSchemaNodeKind } from '../schema-ir/schema-node-kinds';\nimport { resolveDdlSchemaForNamespaceStorage } from './resolve-ddl-schema';\n\n/** The database root's fixed sentinel id (`PostgresDatabaseSchemaNode#id`). */\nfunction databaseStep(): { readonly nodeKind: string; readonly id: string } {\n return { nodeKind: PostgresSchemaNodeKind.database, id: 'database' };\n}\n\nfunction tableDependsOn(namespaceId: string, tableName: string): SchemaNodeRef {\n return [\n databaseStep(),\n { nodeKind: PostgresSchemaNodeKind.namespace, id: namespaceId },\n { nodeKind: PostgresSchemaNodeKind.table, id: tableName },\n ];\n}\n\nfunction roleDependsOn(role: string): SchemaNodeRef {\n return [databaseStep(), { nodeKind: PostgresSchemaNodeKind.role, id: role }];\n}\n\n/**\n * The chains from a table-child object (foreign key, index, unique, primary\n * key) to each of the own columns it is built on, in the Postgres tree.\n * Dropping a covered column auto-drops the object, so the object's drop must\n * precede the column's; the graph derives that direction from these edges.\n */\nfunction columnDependsOn(\n namespaceId: string,\n tableName: string,\n columns: readonly string[],\n): readonly SchemaNodeRef[] {\n return columns.map((column) => [\n ...tableDependsOn(namespaceId, tableName),\n { nodeKind: RelationalSchemaNodeKind.column, id: `column:${column}` },\n ]);\n}\n\nfunction toPolicyNode(policy: PostgresRlsPolicy, namespaceId: string): PostgresPolicySchemaNode {\n return new PostgresPolicySchemaNode({\n name: policy.name,\n prefix: policy.prefix,\n tableName: policy.tableName,\n namespaceId,\n operation: policy.operation,\n roles: [...policy.roles],\n ...ifDefined('using', policy.using),\n ...ifDefined('withCheck', policy.withCheck),\n permissive: policy.permissive,\n dependsOn: [tableDependsOn(namespaceId, policy.tableName), ...policy.roles.map(roleDependsOn)],\n });\n}\n\n/**\n * Projects a Postgres contract into the expected schema-diff tree: a\n * `PostgresDatabaseSchemaNode` root holding one `PostgresNamespaceSchemaNode`\n * per Postgres namespace, each holding its `PostgresTableSchemaNode`s with\n * their `PostgresPolicySchemaNode`s, plus the database roles on the root.\n *\n * Not a duplicate of the family's `contractToSchemaIR`: that builds a flat,\n * single `{ tables }` map (and throws on cross-namespace name collisions, with\n * no RLS/role concept) for SQLite's single-schema world. This is the\n * Postgres-specific *tree* shape — multi-schema, RLS-policy-aware, role-aware.\n * It reuses the family's per-namespace table conversion (`contractNamespaceToSchemaIR`)\n * for column/FK/index building and only adds the Postgres tree/policy/role shape.\n *\n * Tables are grouped by their owning namespace (resolved DDL schema name) so\n * the tree mirrors Postgres's object hierarchy. The DDL schema name is\n * resolved once per namespace.\n *\n * A policy that references a table absent from its namespace is a malformed\n * contract — the loop throws rather than fabricating a stub table.\n */\nexport function contractToPostgresDatabaseSchemaNode(\n contract: PostgresContract | null,\n options: ContractToSchemaIROptions,\n): PostgresDatabaseSchemaNode {\n if (contract === null) {\n return new PostgresDatabaseSchemaNode({\n namespaces: {},\n roles: [],\n existingSchemas: [],\n pgVersion: '',\n });\n }\n\n const namespaces: Record<string, PostgresNamespaceSchemaNode> = {};\n const roles: PostgresRoleSchemaNode[] = [];\n const ownedSchemas: string[] = [];\n\n for (const ns of Object.values(contract.storage.namespaces)) {\n if (!isPostgresSchema(ns)) continue;\n\n // Role entries are root-level diff subjects: they hoist to the database\n // root from every slot and never count toward whether a namespace\n // materializes a schema node.\n for (const role of Object.values(ns.role)) {\n roles.push(new PostgresRoleSchemaNode({ name: role.name, namespaceId: role.namespaceId }));\n }\n\n // The unbound slot resolves its DDL schema to 'public', so it\n // materializes a schema node exactly when it has non-role content — a\n // late-binding contract keeps today's behavior (the slot carries the\n // tables), while a roles-only unbound slot alongside named namespaces\n // contributes only root roles and no node (which would otherwise be a\n // spurious empty 'public' node, clobbering a real bound 'public'\n // namespace's node keyed by the same resolved schema name).\n if (ns.id === UNBOUND_NAMESPACE_ID) {\n const hasNonRoleContent = Object.entries(ns.entries).some(\n ([entriesKey, slot]) => entriesKey !== 'role' && Object.keys(slot).length > 0,\n );\n if (!hasNonRoleContent) continue;\n }\n\n const ddlSchema = resolveDdlSchemaForNamespaceStorage(contract.storage, ns.id);\n ownedSchemas.push(ddlSchema);\n\n // Convert only THIS namespace's tables (passing the full storage for\n // type/value-set/enum resolution that spans namespaces), so the same table\n // name can exist in two schemas without colliding in a bare-keyed record.\n const sqlTables = contractNamespaceToSchemaIR(contract.storage, ns.id, options).tables;\n\n const policiesByTable = new Map<string, PostgresPolicySchemaNode[]>();\n for (const policy of Object.values(ns.policy)) {\n const list = policiesByTable.get(policy.tableName) ?? [];\n list.push(toPolicyNode(policy, ddlSchema));\n policiesByTable.set(policy.tableName, list);\n }\n\n const tables: Record<string, PostgresTableSchemaNode> = {};\n for (const tableName of Object.keys(ns.table)) {\n const sqlTable = sqlTables[tableName];\n if (sqlTable === undefined) continue;\n // The family conversion stamps `referencedSchema` only for bound FK\n // targets; an absent value means the FK targets the unbound namespace.\n // Postgres restores its own coordinate for that slot (the unbound\n // singleton's id) so the raw coordinate keeps qualifying REFERENCES\n // clauses, and resolves the real live DDL schema — introspected FKs\n // already carry the live schema, so this is what lets an expected FK\n // pair (by diff-node id) with its introspected counterpart.\n const foreignKeys = sqlTable.foreignKeys.map((fk) => {\n const resolvedReferencedNamespace = resolveDdlSchemaForNamespaceStorage(\n contract.storage,\n fk.referencedSchema ?? UNBOUND_NAMESPACE_ID,\n );\n return new SqlForeignKeyIR({\n columns: fk.columns,\n referencedTable: fk.referencedTable,\n referencedColumns: fk.referencedColumns,\n referencedSchema: fk.referencedSchema ?? UNBOUND_NAMESPACE_ID,\n ...ifDefined('name', fk.name),\n ...ifDefined('onDelete', fk.onDelete),\n ...ifDefined('onUpdate', fk.onUpdate),\n ...ifDefined('annotations', fk.annotations),\n resolvedReferencedNamespace,\n dependsOn: [\n tableDependsOn(resolvedReferencedNamespace, fk.referencedTable),\n ...columnDependsOn(ddlSchema, tableName, fk.columns),\n ],\n });\n });\n // The family stamped these children's own-column `dependsOn` with the\n // flat (single-schema) chain; the Postgres tree nests them under a\n // namespace, so re-stamp with the multi-schema chain that matches this\n // tree's paths. Every other field is carried through unchanged.\n const uniques = sqlTable.uniques.map(\n (u) =>\n new SqlUniqueIR({\n columns: u.columns,\n ...ifDefined('name', u.name),\n ...ifDefined('annotations', u.annotations),\n dependsOn: columnDependsOn(ddlSchema, tableName, u.columns),\n }),\n );\n const indexes = sqlTable.indexes.map(\n (i) =>\n new SqlIndexIR({\n columns: i.columns,\n unique: i.unique,\n ...ifDefined('name', i.name),\n ...ifDefined('type', i.type),\n ...ifDefined('options', i.options),\n ...ifDefined('annotations', i.annotations),\n dependsOn: columnDependsOn(ddlSchema, tableName, i.columns),\n }),\n );\n const primaryKey =\n sqlTable.primaryKey !== undefined\n ? new PrimaryKey({\n columns: sqlTable.primaryKey.columns,\n ...ifDefined('name', sqlTable.primaryKey.name),\n dependsOn: columnDependsOn(ddlSchema, tableName, sqlTable.primaryKey.columns),\n })\n : undefined;\n tables[tableName] = new PostgresTableSchemaNode({\n name: sqlTable.name,\n columns: sqlTable.columns,\n foreignKeys,\n uniques,\n indexes,\n ...ifDefined('primaryKey', primaryKey),\n ...ifDefined('annotations', sqlTable.annotations),\n ...ifDefined('checks', sqlTable.checks),\n policies: policiesByTable.get(tableName) ?? [],\n // Marker-driven, never derived from the policy set: the `rls` entry\n // is the single authored source of enablement.\n rlsEnabled: Object.hasOwn(ns.rls, tableName),\n });\n }\n\n for (const [tableName, tablePolicies] of policiesByTable) {\n if (!(tableName in tables)) {\n const policyName = tablePolicies[0]?.name ?? '(unknown)';\n throw new Error(\n `contract-to-postgres-database-schema-node: policy \"${policyName}\" references table \"${tableName}\" not present in namespace \"${ddlSchema}\"`,\n );\n }\n if (!Object.hasOwn(ns.rls, tableName)) {\n const policyPrefix = tablePolicies[0]?.prefix ?? '(unknown)';\n throw new Error(\n `contract-to-postgres-database-schema-node: policy \"${policyPrefix}\" targets table \"${tableName}\" in namespace \"${ddlSchema}\", which is not RLS-controlled. Mark the model with @@rls (entries.rls[\"${tableName}\"]) or remove the policy.`,\n );\n }\n }\n\n const nativeEnums = Object.values(ns.entries.native_enum ?? {}).map(\n (entity) =>\n new PostgresNativeEnumSchemaNode({\n typeName: entity.typeName,\n namespaceId: ddlSchema,\n members: entity.members,\n ...ifDefined('control', entity.control),\n }),\n );\n\n namespaces[ddlSchema] = new PostgresNamespaceSchemaNode({\n schemaName: ddlSchema,\n tables,\n nativeEnums,\n });\n }\n\n return new PostgresDatabaseSchemaNode({\n namespaces,\n roles,\n existingSchemas: ownedSchemas,\n pgVersion: '',\n });\n}\n","import type { Contract, ControlPolicy } from '@prisma-next/contract/types';\nimport type { SqlSchemaDiffResult } from '@prisma-next/family-sql/control';\nimport { buildNativeTypeExpander } from '@prisma-next/family-sql/control';\nimport { classifyDiffSubjectGranularity } from '@prisma-next/family-sql/diff';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type { DiffableNode, SchemaDiffIssue } from '@prisma-next/framework-components/control';\nimport { diffSchemas, issueOutcome } 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 { SqlSchemaIRNode } from '@prisma-next/sql-schema-ir/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { postgresResolveDefault } from '../default-normalizer';\nimport type { PostgresContract } from '../postgres-schema';\nimport { PostgresDatabaseSchemaNode } from '../schema-ir/postgres-database-schema-node';\nimport { PostgresNamespaceSchemaNode } from '../schema-ir/postgres-namespace-schema-node';\nimport {\n postgresDiffSubjectGranularity,\n type SqlSchemaDiffNode,\n} from '../schema-ir/schema-node-kinds';\nimport { contractToPostgresDatabaseSchemaNode } from './contract-to-postgres-database-schema-node';\nimport { resolvePostgresNodeIssueControlPolicySubject } from './control-policy';\n\n/**\n * Whether a diff issue's subject node is cluster-scoped — it carries its own\n * `namespaceId` field (only role and policy diff nodes do) and that\n * coordinate is the unbound sentinel, meaning the node is not owned by any\n * schema/namespace. A role node is always cluster-scoped (roles are\n * cluster-level objects); a policy node's `namespaceId` is always its\n * table's resolved DDL schema, never the sentinel. Namespace-ownership\n * scoping (which compares `issue.path[1]` against the set of DDL schemas\n * the contract owns) makes no sense for a cluster-scoped subject — its path\n * segment at that index is the object's own name, not a schema name — so\n * such an issue bypasses that scoping entirely.\n */\nfunction isClusterScopedIssue(issue: SchemaDiffIssue): boolean {\n const node = issue.expected ?? issue.actual;\n return node !== undefined && nodeNamespaceId(node) === UNBOUND_NAMESPACE_ID;\n}\n\nfunction nodeNamespaceId(node: DiffableNode): string | undefined {\n if (!Object.hasOwn(node, 'namespaceId')) return undefined;\n return blindCast<\n { namespaceId: string },\n 'presence of an own namespaceId field was just checked via Object.hasOwn'\n >(node).namespaceId;\n}\n\nfunction ownedSchemaNames(expected: PostgresDatabaseSchemaNode): ReadonlySet<string> {\n const policyNamespaces = Object.values(expected.namespaces).flatMap((ns) =>\n Object.values(ns.tables).flatMap((t) => t.policies.map((p) => p.namespaceId)),\n );\n return new Set([...policyNamespaces, ...expected.existingSchemas]);\n}\n\n/**\n * Drops contract namespaces that declare no tables from the verdict-diff\n * expected tree and the relational owned-schema set. The legacy relational\n * walk skipped a table-less namespace (e.g. an enums-only schema) before\n * pairing, so neither its DDL schema's absence nor that schema's live\n * relational contents ever reached the verdict — the pruned tree\n * reproduces that. The prune loses no expected policies: policies attach\n * to tables, so a table-less namespace carries none (the projection\n * throws on a policy referencing an absent table). Live policies in a\n * pruned schema remain governed via the full owned set (see\n * {@link diffPostgresSchema}).\n */\nfunction pruneTableLessNamespaces(\n expected: PostgresDatabaseSchemaNode,\n): PostgresDatabaseSchemaNode {\n const namespaces = Object.fromEntries(\n Object.entries(expected.namespaces).filter(([, ns]) => Object.keys(ns.tables).length > 0),\n );\n return new PostgresDatabaseSchemaNode({\n namespaces,\n roles: [...expected.roles],\n existingSchemas: expected.existingSchemas.filter((s) => namespaces[s] !== undefined),\n pgVersion: expected.pgVersion,\n });\n}\n\n/**\n * Resolves a verdict-diff issue's subject's declared control policy directly\n * from the contract, by delegating to the same node-typed resolver\n * ({@link resolvePostgresNodeIssueControlPolicySubject}) the planner uses to\n * gate DDL calls. `undefined` when the issue resolves to no contract subject.\n *\n * A role issue resolves through that same resolver to `external`\n * unconditionally (see its role branch), regardless of the contract's own\n * default policy: a role is referenced by the contract but not owned, and\n * `external`'s existing semantics — a missing declared subject still fails,\n * every extra is suppressed — are exactly the wanted asymmetric grading for\n * a cluster object the framework does not own.\n */\nfunction resolveControlPolicy(\n issue: SchemaDiffIssue,\n contract: Contract<SqlStorage>,\n): ControlPolicy | undefined {\n const nodeIssue = blindCast<\n SchemaDiffIssue<SqlSchemaDiffNode>,\n 'every node in a Postgres schema diff tree is a SqlSchemaDiffNode'\n >(issue);\n return resolvePostgresNodeIssueControlPolicySubject(nodeIssue, contract)\n ?.explicitNodeControlPolicy;\n}\n\n/**\n * The Postgres full-tree node diff for the family verify verdict: derive\n * the expected tree (resolved leaf values, expander threaded, FK schemas\n * resolved, table-less namespaces pruned), run the generic\n * differ over the trees as derived, and scope out `not-expected` findings under namespaces the\n * contract does not own. Ownership scoping bypasses cluster-scoped subjects\n * (roles today), mirroring the legacy decomposition: relational extras check\n * the PRUNED owned set (the legacy\n * per-namespace walk never visited a table-less namespace, so its live\n * relational contents are invisible), while `structural` extras (RLS\n * policies) check the FULL owned set (the legacy policy diff governed\n * every contract schema regardless of tables — RLS governance does not\n * shrink because a namespace declares no tables). The codec `verifyType`\n * hooks run once per contract namespace with tables against that\n * namespace's paired actual node (the hooks read namespace-scoped state\n * such as `nativeEnums`).\n */\nexport function diffPostgresSchema(input: {\n readonly contract: Contract<SqlStorage>;\n readonly schema: SqlSchemaIRNode;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n}): SqlSchemaDiffResult {\n const postgresContract = blindCast<\n PostgresContract,\n 'diffPostgresSchema is only called with a postgres contract'\n >(input.contract);\n PostgresDatabaseSchemaNode.assert(input.schema);\n const actual = input.schema;\n const expandNativeType = buildNativeTypeExpander(input.frameworkComponents);\n const fullExpected = contractToPostgresDatabaseSchemaNode(postgresContract, {\n annotationNamespace: 'pg',\n ...ifDefined('expandNativeType', expandNativeType),\n resolveDefault: postgresResolveDefault,\n });\n const expected = pruneTableLessNamespaces(fullExpected);\n const relationalOwned = ownedSchemaNames(expected);\n const structuralOwned = ownedSchemaNames(fullExpected);\n const issues = diffSchemas(expected, actual).filter((issue) => {\n if (issueOutcome(issue) !== 'not-expected') return true;\n if (isClusterScopedIssue(issue)) return true;\n const granularity = classifyDiffSubjectGranularity(issue, postgresDiffSubjectGranularity);\n const namespaceSegment = issue.path[1];\n if (namespaceSegment === undefined) return true;\n const owned = granularity === 'structural' ? structuralOwned : relationalOwned;\n return owned.has(namespaceSegment);\n });\n const namespacePairs = Object.values(expected.namespaces).map((ns) => ({\n actual: actual.namespaces[ns.schemaName],\n }));\n return {\n issues,\n resolveControlPolicy: (issue) => resolveControlPolicy(issue, postgresContract),\n namespacePairs,\n };\n}\n\n/**\n * Adds an empty namespace node to the actual tree for every expected namespace\n * absent from it. The relational plan diff pairs on namespace: a contract\n * namespace whose live schema does not exist yet must surface each of its\n * tables as `not-found` (→ `CREATE TABLE`), NOT as a single namespace\n * `not-found` that subtree-coalescing would collapse (leaving `CREATE SCHEMA`\n * with no tables). Padding makes the namespaces pair, so only table/column/\n * policy drift surfaces; `CREATE SCHEMA` comes separately from the synthesized\n * namespace-presence stitch (`verifyPostgresNamespacePresence`), never from the\n * tree diff — matching the retired per-namespace-paired relational walk, which\n * paired a missing schema against an empty namespace node.\n */\nfunction padActualNamespaces(\n expected: PostgresDatabaseSchemaNode,\n actual: PostgresDatabaseSchemaNode,\n): PostgresDatabaseSchemaNode {\n const namespaces: Record<string, PostgresNamespaceSchemaNode> = { ...actual.namespaces };\n let padded = false;\n for (const schemaName of Object.keys(expected.namespaces)) {\n if (namespaces[schemaName] === undefined) {\n namespaces[schemaName] = new PostgresNamespaceSchemaNode({\n schemaName,\n tables: {},\n });\n padded = true;\n }\n }\n if (!padded) return actual;\n return new PostgresDatabaseSchemaNode({\n namespaces,\n roles: [...actual.roles],\n existingSchemas: [...actual.existingSchemas],\n pgVersion: actual.pgVersion,\n });\n}\n\nexport interface PostgresPlanDiff {\n /** The desired (\"end\") tree — resolved leaf values (incl. `codecRef`) on every column, table-less namespaces pruned. */\n readonly expected: PostgresDatabaseSchemaNode;\n /** The live (\"start\") tree, padded with empty namespaces so a missing schema's tables pair. */\n readonly actual: PostgresDatabaseSchemaNode;\n /** The one node diff over the two trees: relational + policy drift, cluster-scope-aware ownership filtered. */\n readonly issues: readonly SchemaDiffIssue<SqlSchemaDiffNode>[];\n}\n\n/**\n * The Postgres planner's diff input: the SAME tree-building\n * `diffPostgresSchema` uses (expander threaded, FK schemas resolved,\n * table-less namespaces pruned, cluster-scope-aware ownership filter) plus\n * actual namespace padding (so a missing\n * schema's tables surface as `not-found` instead of a swallowed namespace\n * `not-found`). One differ drives both verify and plan; this is the\n * plan-side derivation. The single issue list covers tables / columns /\n * constraints / indexes / defaults AND policies — the caller splits it\n * (relational → `mapNodeIssueToCall`; policy → RLS ops) and stitches in\n * `CREATE SCHEMA` separately.\n */\nexport function buildPostgresPlanDiff(input: {\n readonly contract: Contract<SqlStorage>;\n readonly actualSchema: SqlSchemaIRNode;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n}): PostgresPlanDiff {\n const postgresContract = blindCast<\n PostgresContract,\n 'buildPostgresPlanDiff is only called with a postgres contract'\n >(input.contract);\n PostgresDatabaseSchemaNode.assert(input.actualSchema);\n const actual = input.actualSchema;\n const expandNativeType = buildNativeTypeExpander(input.frameworkComponents);\n const projectionOptions = {\n annotationNamespace: 'pg',\n ...ifDefined('expandNativeType', expandNativeType),\n resolveDefault: postgresResolveDefault,\n };\n const fullExpected = contractToPostgresDatabaseSchemaNode(postgresContract, projectionOptions);\n const expected = pruneTableLessNamespaces(fullExpected);\n const paddedActual = padActualNamespaces(expected, actual);\n const relationalOwned = ownedSchemaNames(expected);\n const structuralOwned = ownedSchemaNames(fullExpected);\n const issues = blindCast<\n readonly SchemaDiffIssue<SqlSchemaDiffNode>[],\n 'both trees are PostgresDatabaseSchemaNodes, so every diff-issue node is a SqlSchemaDiffNode'\n >(diffSchemas(expected, paddedActual)).filter((issue) => {\n if (issueOutcome(issue) !== 'not-expected') return true;\n if (isClusterScopedIssue(issue)) return true;\n const granularity = classifyDiffSubjectGranularity(issue, postgresDiffSubjectGranularity);\n const namespaceSegment = issue.path[1];\n if (namespaceSegment === undefined) return true;\n const owned = granularity === 'structural' ? structuralOwned : relationalOwned;\n return owned.has(namespaceSegment);\n });\n return { expected, actual: paddedActual, issues };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,SAAS,eAAmE;CAC1E,OAAO;EAAE,UAAU,uBAAuB;EAAU,IAAI;CAAW;AACrE;AAEA,SAAS,eAAe,aAAqB,WAAkC;CAC7E,OAAO;E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ode } from "./postgres-database-schema-node-DMXsIwAb.mjs";
2
+ import { n as SqlSchemaDiffNode } from "./schema-node-kinds-DxvWh2Ic.mjs";
2
3
  import { SqlStorage } from "@prisma-next/sql-contract/types";
4
+ import "@prisma-next/family-sql/control";
3
5
  import { SqlSchemaIRNode } from "@prisma-next/sql-schema-ir/types";
4
- import { DiffableNode, SchemaDiffIssue } from "@prisma-next/framework-components/control";
6
+ import { SchemaDiffIssue } from "@prisma-next/framework-components/control";
5
7
  import { Contract } from "@prisma-next/contract/types";
6
8
  import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
7
-
8
- //#region src/core/schema-ir/schema-node-kinds.d.ts
9
- /**
10
- * A Postgres schema-diff-tree node: a `SqlSchemaIRNode` that also implements
11
- * `DiffableNode` (the five `Postgres*SchemaNode` classes). `SqlSchemaIRNode`
12
- * alone is not a `DiffableNode` — its relational subclasses (`SqlColumnIR`, …)
13
- * carry no `id`/`isEqualTo`/`children` — so this intersection is the honest node
14
- * type the differ produces and the planner consumes (`SchemaDiff<SqlSchemaDiffNode>`).
15
- */
16
- type SqlSchemaDiffNode = SqlSchemaIRNode & DiffableNode;
17
- //#endregion
18
9
  //#region src/core/migrations/diff-database-schema.d.ts
19
10
  interface PostgresPlanDiff {
20
11
  /** The desired ("end") tree — resolved leaf values (incl. `codecRef`) on every column, table-less namespaces pruned. */
@@ -1 +1 @@
1
- {"version":3,"file":"diff-database-schema.d.mts","names":[],"sources":["../src/core/schema-ir/schema-node-kinds.ts","../src/core/migrations/diff-database-schema.ts"],"mappings":";;;;;;;;;;;;;;;KAiBY,iBAAA,GAAoB,eAAA,GAAkB,YAAY;;;UCmL7C,gBAAA;EAMW;EAAA,SAJjB,QAAA,EAAU,0BAAA;EAIwC;EAAA,SAFlD,MAAA,EAAQ,0BAAA;EAiBH;EAAA,SAfL,MAAA,WAAiB,eAAA,CAAgB,iBAAA;AAAA;;;;;;;;;;;;;iBAe5B,qBAAA,CAAsB,KAAA;EAAA,SAC3B,QAAA,EAAU,QAAA,CAAS,UAAA;EAAA,SACnB,YAAA,EAAc,eAAA;EAAA,SACd,mBAAA,EAAqB,aAAA,CAAc,8BAAA;AAAA,IAC1C,gBAAA"}
1
+ {"version":3,"file":"diff-database-schema.d.mts","names":[],"sources":["../src/core/migrations/diff-database-schema.ts"],"mappings":";;;;;;;;;UAsMiB;;WAEN,UAAU;;WAEV,QAAQ;;WAER,iBAAiB,gBAAgB;;;;;;;;;;;;;;iBAe5B,sBAAsB;WAC3B,UAAU,SAAS;WACnB,cAAc;WACd,qBAAqB,cAAc;IAC1C"}
@@ -1,2 +1,2 @@
1
- import { t as buildPostgresPlanDiff } from "./diff-database-schema-GncqMuSI.mjs";
1
+ import { t as buildPostgresPlanDiff } from "./diff-database-schema-BRxq7l98.mjs";
2
2
  export { buildPostgresPlanDiff };
@@ -12,9 +12,10 @@ import { CliStructuredError } from "@prisma-next/errors/control";
12
12
  * The `operation` argument is required so every throw site names the operation
13
13
  * that actually failed; a new operation cannot inherit a misattributed message.
14
14
  *
15
- * Distinct from `PN-MIG-2001` (placeholder not filled) and `PN-MIG-2005`
16
- * (data-transform query plan against wrong contract) because the missing
17
- * input is the stack itself, not the per-operation contract.
15
+ * Distinct from `MIGRATION.UNFILLED_PLACEHOLDER` (placeholder not filled)
16
+ * and `MIGRATION.DATA_TRANSFORM_CONTRACT_MISMATCH` (data-transform query
17
+ * plan against wrong contract) because the missing input is the stack
18
+ * itself, not the per-operation contract.
18
19
  *
19
20
  * Lives in `@prisma-next/target-postgres/errors` rather than the shared
20
21
  * framework migration errors module because the failure is target-specific:
@@ -22,8 +23,7 @@ import { CliStructuredError } from "@prisma-next/errors/control";
22
23
  * adapter, the Postgres-target stack) only exists in this package.
23
24
  */
24
25
  function errorPostgresMigrationStackMissing(operation) {
25
- return new CliStructuredError("2007", `PostgresMigration.${operation} requires a control adapter`, {
26
- domain: "MIG",
26
+ return new CliStructuredError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `PostgresMigration.${operation} requires a control adapter`, {
27
27
  why: `PostgresMigration.${operation} was invoked on an instance constructed without a ControlStack, so the stored controlAdapter is undefined and the operation cannot lower its plan.`,
28
28
  fix: "Construct the migration via the migration CLI entrypoint (which assembles a ControlStack from the loaded prisma-next.config.ts), or pass a ControlStack containing a Postgres adapter to the migration constructor in test fixtures.",
29
29
  meta: { operation }
@@ -32,4 +32,4 @@ function errorPostgresMigrationStackMissing(operation) {
32
32
  //#endregion
33
33
  export { errorPostgresMigrationStackMissing as t };
34
34
 
35
- //# sourceMappingURL=errors-DO-w0EUS.mjs.map
35
+ //# sourceMappingURL=errors-ByDS0xJL.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-ByDS0xJL.mjs","names":[],"sources":["../src/core/errors.ts"],"sourcesContent":["import { CliStructuredError } from '@prisma-next/errors/control';\n\n/**\n * A `PostgresMigration` operation that needs the materialized control adapter\n * — named by `operation` (e.g. `createTable`, `dropColumn`, `dataTransform`) —\n * was invoked, but the migration was constructed without a `ControlStack`.\n * Concrete authoring usage always goes through the migration CLI entrypoint,\n * which assembles a stack from the loaded `prisma-next.config.ts`; reaching this\n * error means a test fixture or ad-hoc consumer instantiated `PostgresMigration`\n * with the no-arg form (legal for `operations` / `describe` introspection only).\n *\n * The `operation` argument is required so every throw site names the operation\n * that actually failed; a new operation cannot inherit a misattributed message.\n *\n * Distinct from `MIGRATION.UNFILLED_PLACEHOLDER` (placeholder not filled)\n * and `MIGRATION.DATA_TRANSFORM_CONTRACT_MISMATCH` (data-transform query\n * plan against wrong contract) because the missing input is the stack\n * itself, not the per-operation contract.\n *\n * Lives in `@prisma-next/target-postgres/errors` rather than the shared\n * framework migration errors module because the failure is target-specific:\n * the contract it talks about (`PostgresMigration`, the Postgres control\n * adapter, the Postgres-target stack) only exists in this package.\n */\nexport function errorPostgresMigrationStackMissing(operation: string): CliStructuredError {\n return new CliStructuredError(\n 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',\n `PostgresMigration.${operation} requires a control adapter`,\n {\n why: `PostgresMigration.${operation} was invoked on an instance constructed without a ControlStack, so the stored controlAdapter is undefined and the operation cannot lower its plan.`,\n fix: 'Construct the migration via the migration CLI entrypoint (which assembles a ControlStack from the loaded prisma-next.config.ts), or pass a ControlStack containing a Postgres adapter to the migration constructor in test fixtures.',\n meta: { operation },\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,mCAAmC,WAAuC;CACxF,OAAO,IAAI,mBACT,4CACA,qBAAqB,UAAU,8BAC/B;EACE,KAAK,qBAAqB,UAAU;EACpC,KAAK;EACL,MAAM,EAAE,UAAU;CACpB,CACF;AACF"}
package/dist/errors.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { CliStructuredError } from "@prisma-next/errors/control";
2
-
3
2
  //#region src/core/errors.d.ts
4
3
  /**
5
4
  * A `PostgresMigration` operation that needs the materialized control adapter
@@ -13,9 +12,10 @@ import { CliStructuredError } from "@prisma-next/errors/control";
13
12
  * The `operation` argument is required so every throw site names the operation
14
13
  * that actually failed; a new operation cannot inherit a misattributed message.
15
14
  *
16
- * Distinct from `PN-MIG-2001` (placeholder not filled) and `PN-MIG-2005`
17
- * (data-transform query plan against wrong contract) because the missing
18
- * input is the stack itself, not the per-operation contract.
15
+ * Distinct from `MIGRATION.UNFILLED_PLACEHOLDER` (placeholder not filled)
16
+ * and `MIGRATION.DATA_TRANSFORM_CONTRACT_MISMATCH` (data-transform query
17
+ * plan against wrong contract) because the missing input is the stack
18
+ * itself, not the per-operation contract.
19
19
  *
20
20
  * Lives in `@prisma-next/target-postgres/errors` rather than the shared
21
21
  * framework migration errors module because the failure is target-specific:
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.mts","names":[],"sources":["../src/core/errors.ts"],"mappings":";;;;;AAuBA;;;;AAAyF;;;;;;;;;;;;;;;iBAAzE,kCAAA,CAAmC,SAAA,WAAoB,kBAAkB"}
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../src/core/errors.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;iBAwBgB,mCAAmC,oBAAoB"}
package/dist/errors.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as errorPostgresMigrationStackMissing } from "./errors-DO-w0EUS.mjs";
1
+ import { t as errorPostgresMigrationStackMissing } from "./errors-ByDS0xJL.mjs";
2
2
  export { errorPostgresMigrationStackMissing };