@prisma-next/target-postgres 0.14.0-dev.7 → 0.14.0-dev.71

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 (265) hide show
  1. package/dist/authoring-Bi9aa8zG.mjs +574 -0
  2. package/dist/authoring-Bi9aa8zG.mjs.map +1 -0
  3. package/dist/canonicalize-CAbXtVtB.d.mts +37 -0
  4. package/dist/canonicalize-CAbXtVtB.d.mts.map +1 -0
  5. package/dist/{codec-ids-CnXu9Qy3.d.mts → codec-ids-BzrFF-I4.d.mts} +3 -2
  6. package/dist/codec-ids-BzrFF-I4.d.mts.map +1 -0
  7. package/dist/{codec-ids-BvytN2P8.mjs → codec-ids-C_-Hj6bL.mjs} +3 -2
  8. package/dist/codec-ids-C_-Hj6bL.mjs.map +1 -0
  9. package/dist/codec-ids.d.mts +2 -2
  10. package/dist/codec-ids.mjs +2 -2
  11. package/dist/{codec-types-DHCkwPKE.d.mts → codec-types-BiIWziRO.d.mts} +3 -2
  12. package/dist/codec-types-BiIWziRO.d.mts.map +1 -0
  13. package/dist/codec-types.d.mts +1 -1
  14. package/dist/codecs-Cl_hQHg-.mjs +913 -0
  15. package/dist/codecs-Cl_hQHg-.mjs.map +1 -0
  16. package/dist/{codecs--0A5_4Bq.d.mts → codecs-Cm-nS4mQ.d.mts} +111 -4
  17. package/dist/codecs-Cm-nS4mQ.d.mts.map +1 -0
  18. package/dist/codecs.d.mts +2 -2
  19. package/dist/codecs.mjs +3 -757
  20. package/dist/codecs.mjs.map +1 -1
  21. package/dist/contract-free.d.mts +33 -3
  22. package/dist/contract-free.d.mts.map +1 -1
  23. package/dist/contract-free.mjs +23 -7
  24. package/dist/contract-free.mjs.map +1 -1
  25. package/dist/control-policy-CuUhjWnn.mjs +1258 -0
  26. package/dist/control-policy-CuUhjWnn.mjs.map +1 -0
  27. package/dist/control.d.mts +2 -2
  28. package/dist/control.d.mts.map +1 -1
  29. package/dist/control.mjs +866 -36
  30. package/dist/control.mjs.map +1 -1
  31. package/dist/data-transform-BOWpliq8.mjs.map +1 -1
  32. package/dist/{data-transform-DDgWdB5o.d.mts → data-transform-DPzwBMhW.d.mts} +3 -3
  33. package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-DPzwBMhW.d.mts.map} +1 -1
  34. package/dist/data-transform.d.mts +1 -1
  35. package/dist/{ddl-QDyOSeLc.mjs → ddl-Dqgs-bDc.mjs} +93 -6
  36. package/dist/ddl-Dqgs-bDc.mjs.map +1 -0
  37. package/dist/ddl.d.mts +3 -2
  38. package/dist/ddl.mjs +2 -2
  39. package/dist/default-normalizer.d.mts +1 -1
  40. package/dist/default-normalizer.d.mts.map +1 -1
  41. package/dist/default-normalizer.mjs +247 -1
  42. package/dist/default-normalizer.mjs.map +1 -0
  43. package/dist/descriptor-meta-UugzVM-U.mjs +22 -0
  44. package/dist/descriptor-meta-UugzVM-U.mjs.map +1 -0
  45. package/dist/descriptor-meta-runtime-UwYdV8fD.mjs +12 -0
  46. package/dist/descriptor-meta-runtime-UwYdV8fD.mjs.map +1 -0
  47. package/dist/diff-database-schema-ClN3bkRS.mjs +305 -0
  48. package/dist/diff-database-schema-ClN3bkRS.mjs.map +1 -0
  49. package/dist/diff-database-schema.d.mts +46 -0
  50. package/dist/diff-database-schema.d.mts.map +1 -0
  51. package/dist/diff-database-schema.mjs +2 -0
  52. package/dist/errors-DO-w0EUS.mjs +35 -0
  53. package/dist/errors-DO-w0EUS.mjs.map +1 -0
  54. package/dist/errors.d.mts +11 -9
  55. package/dist/errors.d.mts.map +1 -1
  56. package/dist/errors.mjs +1 -1
  57. package/dist/issue-planner.d.mts +35 -11
  58. package/dist/issue-planner.d.mts.map +1 -1
  59. package/dist/issue-planner.mjs +2 -2
  60. package/dist/migration.d.mts +5 -5
  61. package/dist/migration.d.mts.map +1 -1
  62. package/dist/migration.mjs +4 -4
  63. package/dist/namespace-ids-xtp_ZY86.mjs +7 -0
  64. package/dist/namespace-ids-xtp_ZY86.mjs.map +1 -0
  65. package/dist/native-type-normalizer.mjs +37 -1
  66. package/dist/native-type-normalizer.mjs.map +1 -0
  67. package/dist/nodes-Bc2N3tMy.d.mts +170 -0
  68. package/dist/nodes-Bc2N3tMy.d.mts.map +1 -0
  69. package/dist/nodes-DJC5B8Id.mjs +192 -0
  70. package/dist/nodes-DJC5B8Id.mjs.map +1 -0
  71. package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-CSIg5XDu.d.mts} +91 -15
  72. package/dist/op-factory-call-CSIg5XDu.d.mts.map +1 -0
  73. package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-DtVSP_7Y.mjs} +400 -32
  74. package/dist/op-factory-call-DtVSP_7Y.mjs.map +1 -0
  75. package/dist/op-factory-call.d.mts +2 -2
  76. package/dist/op-factory-call.mjs +2 -2
  77. package/dist/pack.d.mts +300 -3
  78. package/dist/pack.d.mts.map +1 -1
  79. package/dist/pack.mjs +1 -1
  80. package/dist/planner-ChVasl04.mjs +390 -0
  81. package/dist/planner-ChVasl04.mjs.map +1 -0
  82. package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-BKlmGDJl.mjs} +17 -28
  83. package/dist/planner-ddl-builders-BKlmGDJl.mjs.map +1 -0
  84. package/dist/planner-ddl-builders.d.mts +4 -6
  85. package/dist/planner-ddl-builders.d.mts.map +1 -1
  86. package/dist/planner-ddl-builders.mjs +2 -2
  87. package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -1
  88. package/dist/planner-identity-values.d.mts +8 -2
  89. package/dist/planner-identity-values.d.mts.map +1 -1
  90. package/dist/planner-identity-values.mjs +2 -2
  91. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-CXue-6M9.d.mts} +4 -4
  92. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-CXue-6M9.d.mts.map} +1 -1
  93. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-qpU05c__.mjs} +3 -3
  94. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-qpU05c__.mjs.map} +1 -1
  95. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  96. package/dist/planner-produced-postgres-migration.mjs +1 -1
  97. package/dist/{planner-sql-checks-jqUUGyQR.mjs → planner-sql-checks-CDXn2uaS.mjs} +5 -5
  98. package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-CDXn2uaS.mjs.map} +1 -1
  99. package/dist/planner-sql-checks.d.mts +2 -2
  100. package/dist/planner-sql-checks.d.mts.map +1 -1
  101. package/dist/planner-sql-checks.mjs +1 -1
  102. package/dist/{planner-target-details-CIY6tLeo.d.mts → planner-target-details-HkP4RrRO.d.mts} +2 -2
  103. package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -0
  104. package/dist/planner-target-details.d.mts +1 -1
  105. package/dist/planner.d.mts +72 -17
  106. package/dist/planner.d.mts.map +1 -1
  107. package/dist/planner.mjs +3 -2
  108. package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-C3LPCLP_.mjs} +45 -41
  109. package/dist/postgres-contract-view-C3LPCLP_.mjs.map +1 -0
  110. package/dist/postgres-contract-view-C9j5cqP0.d.mts +34 -0
  111. package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
  112. package/dist/postgres-database-schema-node-CJv5bfbs.d.mts +262 -0
  113. package/dist/postgres-database-schema-node-CJv5bfbs.d.mts.map +1 -0
  114. package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-DkmgGNcv.d.mts} +47 -9
  115. package/dist/postgres-migration-DkmgGNcv.d.mts.map +1 -0
  116. package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-fndp3Mbm.mjs} +69 -45
  117. package/dist/postgres-migration-fndp3Mbm.mjs.map +1 -0
  118. package/dist/postgres-native-enum-BwVNf0Ku.mjs +45 -0
  119. package/dist/postgres-native-enum-BwVNf0Ku.mjs.map +1 -0
  120. package/dist/postgres-rls-policy--CSddvMR.d.mts +52 -0
  121. package/dist/postgres-rls-policy--CSddvMR.d.mts.map +1 -0
  122. package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs +190 -0
  123. package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs.map +1 -0
  124. package/dist/postgres-schema-DKq6s1P3.d.mts +269 -0
  125. package/dist/postgres-schema-DKq6s1P3.d.mts.map +1 -0
  126. package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-DYATroNx.mjs} +200 -11
  127. package/dist/postgres-schema-DYATroNx.mjs.map +1 -0
  128. package/dist/postgres-table-schema-node-D6LvInCe.mjs +216 -0
  129. package/dist/postgres-table-schema-node-D6LvInCe.mjs.map +1 -0
  130. package/dist/render-ops.d.mts +1 -1
  131. package/dist/{render-typescript-KMgosran.mjs → render-typescript-7yqILcwr.mjs} +45 -16
  132. package/dist/render-typescript-7yqILcwr.mjs.map +1 -0
  133. package/dist/render-typescript.mjs +1 -1
  134. package/dist/resolve-ddl-schema-DpGte50u.mjs +22 -0
  135. package/dist/resolve-ddl-schema-DpGte50u.mjs.map +1 -0
  136. package/dist/rls-canonicalize.d.mts +20 -0
  137. package/dist/rls-canonicalize.d.mts.map +1 -0
  138. package/dist/rls-canonicalize.mjs +2 -0
  139. package/dist/runtime.d.mts +6 -8
  140. package/dist/runtime.d.mts.map +1 -1
  141. package/dist/runtime.mjs +3 -3
  142. package/dist/runtime.mjs.map +1 -1
  143. package/dist/schema-ir-annotations.d.mts +15 -0
  144. package/dist/schema-ir-annotations.d.mts.map +1 -0
  145. package/dist/schema-ir-annotations.mjs +2 -0
  146. package/dist/{sql-utils-DcfMz4MQ.mjs → sql-utils-SU4FDvIV.mjs} +12 -3
  147. package/dist/{sql-utils-DcfMz4MQ.mjs.map → sql-utils-SU4FDvIV.mjs.map} +1 -1
  148. package/dist/sql-utils.d.mts +8 -1
  149. package/dist/sql-utils.d.mts.map +1 -1
  150. package/dist/sql-utils.mjs +2 -2
  151. package/dist/types.d.mts +4 -140
  152. package/dist/types.mjs +5 -2
  153. package/dist/wire-name-rHHtr1h0.mjs +75 -0
  154. package/dist/wire-name-rHHtr1h0.mjs.map +1 -0
  155. package/package.json +26 -20
  156. package/src/contract-free/checks.ts +73 -0
  157. package/src/contract-free/control-bootstrap.ts +20 -3
  158. package/src/contract-free/ddl.ts +98 -1
  159. package/src/core/authoring.ts +509 -2
  160. package/src/core/codec-ids.ts +1 -0
  161. package/src/core/codec-type-map.ts +2 -0
  162. package/src/core/codecs.ts +180 -1
  163. package/src/core/ddl/nodes.ts +185 -2
  164. package/src/core/default-normalizer.ts +122 -2
  165. package/src/core/descriptor-meta.ts +10 -1
  166. package/src/core/entity-kinds.ts +41 -0
  167. package/src/core/errors.ts +14 -12
  168. package/src/core/migrations/bound-schema.ts +10 -0
  169. package/src/core/migrations/column-ddl-rendering.ts +117 -0
  170. package/src/core/migrations/contract-to-postgres-database-schema-node.ts +189 -0
  171. package/src/core/migrations/control-policy.ts +217 -65
  172. package/src/core/migrations/diff-database-schema.ts +252 -0
  173. package/src/core/migrations/issue-planner.ts +769 -656
  174. package/src/core/migrations/op-factory-call.ts +273 -21
  175. package/src/core/migrations/operations/columns.ts +24 -12
  176. package/src/core/migrations/operations/constraints.ts +1 -1
  177. package/src/core/migrations/operations/data-transform.ts +6 -0
  178. package/src/core/migrations/operations/dependencies.ts +2 -1
  179. package/src/core/migrations/operations/native-enum-types.ts +62 -0
  180. package/src/core/migrations/operations/rls.ts +187 -0
  181. package/src/core/migrations/operations/shared.ts +0 -30
  182. package/src/core/migrations/planner-ddl-builders.ts +31 -59
  183. package/src/core/migrations/planner-identity-values.ts +1 -1
  184. package/src/core/migrations/planner-recipes.ts +31 -13
  185. package/src/core/migrations/planner-sql-checks.ts +1 -1
  186. package/src/core/migrations/planner-strategies.ts +248 -216
  187. package/src/core/migrations/planner-target-details.ts +3 -1
  188. package/src/core/migrations/planner.ts +357 -67
  189. package/src/core/migrations/postgres-migration.ts +101 -86
  190. package/src/core/migrations/render-typescript.ts +42 -15
  191. package/src/core/migrations/resolve-ddl-schema.ts +26 -0
  192. package/src/core/migrations/runner.ts +11 -16
  193. package/src/core/migrations/verify-postgres-namespaces.ts +46 -31
  194. package/src/core/namespace-ids.ts +3 -0
  195. package/src/core/postgres-contract-serializer.ts +46 -71
  196. package/src/core/postgres-contract-view.ts +48 -0
  197. package/src/core/postgres-native-enum.ts +61 -0
  198. package/src/core/postgres-rls-enablement.ts +34 -0
  199. package/src/core/postgres-rls-policy.ts +64 -0
  200. package/src/core/postgres-role.ts +59 -0
  201. package/src/core/postgres-schema-verifier.ts +10 -7
  202. package/src/core/postgres-schema.ts +85 -15
  203. package/src/core/postgres-validators.ts +34 -0
  204. package/src/core/psl-infer/infer-psl-contract.ts +1273 -0
  205. package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
  206. package/src/core/psl-infer/postgres-type-map.ts +128 -0
  207. package/src/core/rls/canonicalize.ts +48 -0
  208. package/src/core/rls/wire-name.ts +33 -0
  209. package/src/core/schema-ir/node-storage-coordinate.ts +26 -0
  210. package/src/core/schema-ir/postgres-database-schema-node.ts +61 -0
  211. package/src/core/schema-ir/postgres-namespace-schema-node.ts +70 -0
  212. package/src/core/schema-ir/postgres-native-enum-schema-node.ts +83 -0
  213. package/src/core/schema-ir/postgres-policy-schema-node.ts +90 -0
  214. package/src/core/schema-ir/postgres-role-schema-node.ts +65 -0
  215. package/src/core/schema-ir/postgres-table-schema-node.ts +140 -0
  216. package/src/core/schema-ir/schema-node-kinds.ts +122 -0
  217. package/src/core/sql-utils.ts +15 -2
  218. package/src/exports/codecs.ts +3 -0
  219. package/src/exports/contract-free.ts +11 -1
  220. package/src/exports/control.ts +27 -33
  221. package/src/exports/ddl.ts +8 -0
  222. package/src/exports/diff-database-schema.ts +7 -0
  223. package/src/exports/issue-planner.ts +1 -1
  224. package/src/exports/migration.ts +1 -0
  225. package/src/exports/op-factory-call.ts +3 -0
  226. package/src/exports/planner-ddl-builders.ts +0 -2
  227. package/src/exports/planner-identity-values.ts +4 -1
  228. package/src/exports/planner.ts +1 -0
  229. package/src/exports/rls-canonicalize.ts +7 -0
  230. package/src/exports/runtime.ts +1 -0
  231. package/src/exports/schema-ir-annotations.ts +1 -0
  232. package/src/exports/sql-utils.ts +1 -0
  233. package/src/exports/types.ts +37 -0
  234. package/dist/codec-ids-BvytN2P8.mjs.map +0 -1
  235. package/dist/codec-ids-CnXu9Qy3.d.mts.map +0 -1
  236. package/dist/codec-types-DHCkwPKE.d.mts.map +0 -1
  237. package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
  238. package/dist/ddl-QDyOSeLc.mjs.map +0 -1
  239. package/dist/default-normalizer-DyyCHQWs.mjs +0 -131
  240. package/dist/default-normalizer-DyyCHQWs.mjs.map +0 -1
  241. package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
  242. package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
  243. package/dist/errors-CUk87ByX.mjs +0 -33
  244. package/dist/errors-CUk87ByX.mjs.map +0 -1
  245. package/dist/issue-planner-DL6g3CmE.mjs +0 -824
  246. package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
  247. package/dist/native-type-normalizer-Bc9XJzWC.mjs +0 -38
  248. package/dist/native-type-normalizer-Bc9XJzWC.mjs.map +0 -1
  249. package/dist/nodes-Bbhs2rwj.mjs +0 -76
  250. package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
  251. package/dist/nodes-pLeLgdis.d.mts +0 -67
  252. package/dist/nodes-pLeLgdis.d.mts.map +0 -1
  253. package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
  254. package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
  255. package/dist/planner-Bs_baQax.mjs +0 -324
  256. package/dist/planner-Bs_baQax.mjs.map +0 -1
  257. package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
  258. package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
  259. package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
  260. package/dist/postgres-migration-B5jKrXv3.mjs.map +0 -1
  261. package/dist/postgres-migration-Y4YBJqkS.d.mts.map +0 -1
  262. package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
  263. package/dist/render-typescript-KMgosran.mjs.map +0 -1
  264. package/dist/types.d.mts.map +0 -1
  265. package/src/core/postgres-enum-type-schema.ts +0 -17
@@ -40,8 +40,10 @@ import { blindCast } from '@prisma-next/utils/casts';
40
40
  import { ifDefined } from '@prisma-next/utils/defined';
41
41
  import { columnExistsAst, tableExistsAst } from '../../contract-free/checks';
42
42
  import * as contractFreeDdl from '../../contract-free/ddl';
43
+ import type { PostgresRlsPolicy } from '../postgres-rls-policy';
43
44
  import { escapeLiteral, quoteIdentifier } from '../sql-utils';
44
45
  import type { PostgresColumnDefault } from '../types';
46
+ import { boundSchema } from './bound-schema';
45
47
  import {
46
48
  addNotNullColumnDirect,
47
49
  alterColumnType,
@@ -61,6 +63,14 @@ import {
61
63
  } from './operations/constraints';
62
64
  import { createExtension } from './operations/dependencies';
63
65
  import { createIndex, dropIndex } from './operations/indexes';
66
+ import { createNativeEnumType, dropNativeEnumType } from './operations/native-enum-types';
67
+ import {
68
+ createRlsPolicy,
69
+ disableRowLevelSecurity,
70
+ dropRlsPolicy,
71
+ enableRowLevelSecurity,
72
+ renameRlsPolicy,
73
+ } from './operations/rls';
64
74
  import type { ForeignKeySpec } from './operations/shared';
65
75
  import { step, targetDetails } from './operations/shared';
66
76
  import { dropTable } from './operations/tables';
@@ -83,10 +93,6 @@ type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
83
93
  // transitive package on disk.
84
94
  const POSTGRES_MIGRATION_FACADE = '@prisma-next/postgres/migration';
85
95
 
86
- function boundSchema(schemaName: string): string | undefined {
87
- return schemaName === UNBOUND_NAMESPACE_ID ? undefined : schemaName;
88
- }
89
-
90
96
  abstract class PostgresOpFactoryCallNode extends TsExpression implements FrameworkOpFactoryCall {
91
97
  abstract readonly factoryName: string;
92
98
  abstract readonly operationClass: MigrationOperationClass;
@@ -169,6 +175,8 @@ function renderDdlConstraintAsTsCall(constraint: DdlTableConstraint): string {
169
175
  const nameOpt = constraint.name ? `, { name: ${jsonToTsSource(constraint.name)} }` : '';
170
176
  return `unique(${jsonToTsSource(constraint.columns)}${nameOpt})`;
171
177
  }
178
+ case 'check-expression':
179
+ return `checkExpression(${jsonToTsSource(constraint.name)}, ${jsonToTsSource(constraint.expression)})`;
172
180
  }
173
181
  }
174
182
 
@@ -183,6 +191,7 @@ function constraintImportSymbols(constraints: readonly DdlTableConstraint[] | un
183
191
  if (c.kind === 'primary-key') symbols.add('primaryKey');
184
192
  else if (c.kind === 'foreign-key') symbols.add('foreignKey');
185
193
  else if (c.kind === 'unique') symbols.add('unique');
194
+ else if (c.kind === 'check-expression') symbols.add('checkExpression');
186
195
  }
187
196
  return [...symbols];
188
197
  }
@@ -684,10 +693,8 @@ export class DropDefaultCall extends PostgresOpFactoryCallNode {
684
693
 
685
694
  /**
686
695
  * Planner-internal call for adding a NOT NULL column (no contract default) to
687
- * a table that must be empty at migration time. Carries the raw ADD COLUMN SQL
688
- * (produced by `buildAddColumnSql` at plan time deferred from slice-7 typed
689
- * DDL) plus the parameters needed to lower the typed pre/postchecks at render
690
- * time.
696
+ * a table that must be empty at migration time. Carries the typed `DdlColumn`
697
+ * and lowers it to an ADD COLUMN execute step via the adapter at `toOp` time.
691
698
  *
692
699
  * No authored `PostgresMigration` method: this call is only emitted by the
693
700
  * planner, never hand-written by migration authors.
@@ -698,15 +705,15 @@ export class AddNotNullColumnDirectCall extends PostgresOpFactoryCallNode {
698
705
  readonly schemaName: string;
699
706
  readonly tableName: string;
700
707
  readonly columnName: string;
701
- readonly executeStepSql: string;
708
+ readonly column: DdlColumn;
702
709
  readonly label: string;
703
710
 
704
- constructor(schemaName: string, tableName: string, columnName: string, executeStepSql: string) {
711
+ constructor(schemaName: string, tableName: string, columnName: string, column: DdlColumn) {
705
712
  super();
706
713
  this.schemaName = schemaName;
707
714
  this.tableName = tableName;
708
715
  this.columnName = columnName;
709
- this.executeStepSql = executeStepSql;
716
+ this.column = column;
710
717
  this.label = `Add column ${columnName} to ${tableName}`;
711
718
  this.freeze();
712
719
  }
@@ -717,13 +724,7 @@ export class AddNotNullColumnDirectCall extends PostgresOpFactoryCallNode {
717
724
  `AddNotNullColumnDirectCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
718
725
  );
719
726
  }
720
- return addNotNullColumnDirect(
721
- this.schemaName,
722
- this.tableName,
723
- this.columnName,
724
- this.executeStepSql,
725
- lowerer,
726
- );
727
+ return addNotNullColumnDirect(this.schemaName, this.tableName, this.column, lowerer);
727
728
  }
728
729
 
729
730
  renderTypeScript(): string {
@@ -738,9 +739,9 @@ export class AddNotNullColumnDirectCall extends PostgresOpFactoryCallNode {
738
739
  /**
739
740
  * Planner-internal call for adding a NOT NULL column (no contract default)
740
741
  * using a temporary default value for non-empty tables. Carries all parameters
741
- * needed for `buildAddNotNullColumnWithTemporaryDefaultOperation`; the typed
742
- * pre/postchecks are lowered at render time via `toOp(lowerer)`. The execute
743
- * SQL (`buildAddColumnSql`) is still raw per slice-7 deferral.
742
+ * needed for `buildAddNotNullColumnWithTemporaryDefaultOperation`; both the
743
+ * typed ADD COLUMN execute step and the pre/postchecks are lowered via the
744
+ * adapter at `toOp` time.
744
745
  *
745
746
  * No authored `PostgresMigration` method: this call is only emitted by the
746
747
  * planner, never hand-written by migration authors.
@@ -1318,6 +1319,87 @@ export class CreateSchemaCall extends PostgresOpFactoryCallNode {
1318
1319
  }
1319
1320
  }
1320
1321
 
1322
+ // ============================================================================
1323
+ // Native enum types
1324
+ // ============================================================================
1325
+
1326
+ export class CreateNativeEnumTypeCall extends PostgresOpFactoryCallNode {
1327
+ readonly factoryName = 'createNativeEnumType' as const;
1328
+ readonly operationClass = 'additive' as const;
1329
+ readonly schemaName: string;
1330
+ readonly typeName: string;
1331
+ readonly members: readonly string[];
1332
+ readonly label: string;
1333
+
1334
+ constructor(schemaName: string, typeName: string, members: readonly string[]) {
1335
+ super();
1336
+ this.schemaName = schemaName;
1337
+ this.typeName = typeName;
1338
+ this.members = Object.freeze([...members]);
1339
+ this.label = `Create enum type "${typeName}"`;
1340
+ this.freeze();
1341
+ }
1342
+
1343
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1344
+ if (lowerer === undefined) {
1345
+ throw new Error(
1346
+ `CreateNativeEnumTypeCall.toOp: a DDL lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1347
+ );
1348
+ }
1349
+ return createNativeEnumType(this.schemaName, this.typeName, this.members, lowerer);
1350
+ }
1351
+
1352
+ renderTypeScript(): string {
1353
+ const opts = [
1354
+ `schema: ${jsonToTsSource(this.schemaName)}`,
1355
+ `typeName: ${jsonToTsSource(this.typeName)}`,
1356
+ `members: ${jsonToTsSource(this.members)}`,
1357
+ ];
1358
+ return `this.createNativeEnumType({ ${opts.join(', ')} })`;
1359
+ }
1360
+
1361
+ override importRequirements(): readonly ImportRequirement[] {
1362
+ return [];
1363
+ }
1364
+ }
1365
+
1366
+ export class DropNativeEnumTypeCall extends PostgresOpFactoryCallNode {
1367
+ readonly factoryName = 'dropNativeEnumType' as const;
1368
+ readonly operationClass = 'destructive' as const;
1369
+ readonly schemaName: string;
1370
+ readonly typeName: string;
1371
+ readonly label: string;
1372
+
1373
+ constructor(schemaName: string, typeName: string) {
1374
+ super();
1375
+ this.schemaName = schemaName;
1376
+ this.typeName = typeName;
1377
+ this.label = `Drop enum type "${typeName}"`;
1378
+ this.freeze();
1379
+ }
1380
+
1381
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1382
+ if (lowerer === undefined) {
1383
+ throw new Error(
1384
+ `DropNativeEnumTypeCall.toOp: a DDL lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1385
+ );
1386
+ }
1387
+ return dropNativeEnumType(this.schemaName, this.typeName, lowerer);
1388
+ }
1389
+
1390
+ renderTypeScript(): string {
1391
+ const opts = [
1392
+ `schema: ${jsonToTsSource(this.schemaName)}`,
1393
+ `typeName: ${jsonToTsSource(this.typeName)}`,
1394
+ ];
1395
+ return `this.dropNativeEnumType({ ${opts.join(', ')} })`;
1396
+ }
1397
+
1398
+ override importRequirements(): readonly ImportRequirement[] {
1399
+ return [];
1400
+ }
1401
+ }
1402
+
1321
1403
  // ============================================================================
1322
1404
  // Data transform
1323
1405
  // ============================================================================
@@ -1376,6 +1458,169 @@ export class DataTransformCall extends PostgresOpFactoryCallNode {
1376
1458
  }
1377
1459
  }
1378
1460
 
1461
+ export class CreatePostgresRlsPolicyCall extends PostgresOpFactoryCallNode {
1462
+ readonly factoryName = 'createRlsPolicy' as const;
1463
+ readonly operationClass = 'additive' as const;
1464
+ readonly schemaName: string;
1465
+ readonly tableName: string;
1466
+ readonly policy: PostgresRlsPolicy;
1467
+ readonly label: string;
1468
+
1469
+ constructor(schemaName: string, tableName: string, policy: PostgresRlsPolicy) {
1470
+ super();
1471
+ this.schemaName = schemaName;
1472
+ this.tableName = tableName;
1473
+ this.policy = policy;
1474
+ this.label = `Create RLS policy "${policy.name}" on "${tableName}"`;
1475
+ this.freeze();
1476
+ }
1477
+
1478
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1479
+ if (lowerer === undefined) {
1480
+ throw new Error(
1481
+ `CreatePostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.policy.name}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1482
+ );
1483
+ }
1484
+ return createRlsPolicy(this.schemaName, this.tableName, this.policy, lowerer);
1485
+ }
1486
+
1487
+ renderTypeScript(): string {
1488
+ return `createRlsPolicy(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.policy)})`;
1489
+ }
1490
+ }
1491
+
1492
+ export class DropPostgresRlsPolicyCall extends PostgresOpFactoryCallNode {
1493
+ readonly factoryName = 'dropRlsPolicy' as const;
1494
+ readonly operationClass = 'destructive' as const;
1495
+ readonly schemaName: string;
1496
+ readonly tableName: string;
1497
+ readonly policyName: string;
1498
+ readonly label: string;
1499
+
1500
+ constructor(schemaName: string, tableName: string, policyName: string) {
1501
+ super();
1502
+ this.schemaName = schemaName;
1503
+ this.tableName = tableName;
1504
+ this.policyName = policyName;
1505
+ this.label = `Drop RLS policy "${policyName}" on "${tableName}"`;
1506
+ this.freeze();
1507
+ }
1508
+
1509
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1510
+ if (lowerer === undefined) {
1511
+ throw new Error(
1512
+ `DropPostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.policyName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1513
+ );
1514
+ }
1515
+ return dropRlsPolicy(this.schemaName, this.tableName, this.policyName, lowerer);
1516
+ }
1517
+
1518
+ renderTypeScript(): string {
1519
+ return `dropRlsPolicy(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.policyName)})`;
1520
+ }
1521
+ }
1522
+
1523
+ export class EnableRowLevelSecurityCall extends PostgresOpFactoryCallNode {
1524
+ readonly factoryName = 'enableRowLevelSecurity' as const;
1525
+ readonly operationClass = 'additive' as const;
1526
+ readonly schemaName: string;
1527
+ readonly tableName: string;
1528
+ readonly label: string;
1529
+
1530
+ constructor(schemaName: string, tableName: string) {
1531
+ super();
1532
+ this.schemaName = schemaName;
1533
+ this.tableName = tableName;
1534
+ this.label = `Enable row-level security on "${tableName}"`;
1535
+ this.freeze();
1536
+ }
1537
+
1538
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1539
+ if (lowerer === undefined) {
1540
+ throw new Error(
1541
+ `EnableRowLevelSecurityCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1542
+ );
1543
+ }
1544
+ return enableRowLevelSecurity(this.schemaName, this.tableName, lowerer);
1545
+ }
1546
+
1547
+ renderTypeScript(): string {
1548
+ return `enableRowLevelSecurity(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)})`;
1549
+ }
1550
+ }
1551
+
1552
+ export class DisableRowLevelSecurityCall extends PostgresOpFactoryCallNode {
1553
+ readonly factoryName = 'disableRowLevelSecurity' as const;
1554
+ readonly operationClass = 'destructive' as const;
1555
+ readonly schemaName: string;
1556
+ readonly tableName: string;
1557
+ readonly label: string;
1558
+
1559
+ constructor(schemaName: string, tableName: string) {
1560
+ super();
1561
+ this.schemaName = schemaName;
1562
+ this.tableName = tableName;
1563
+ this.label = `Disable row-level security on "${tableName}"`;
1564
+ this.freeze();
1565
+ }
1566
+
1567
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1568
+ if (lowerer === undefined) {
1569
+ throw new Error(
1570
+ `DisableRowLevelSecurityCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1571
+ );
1572
+ }
1573
+ return disableRowLevelSecurity(this.schemaName, this.tableName, lowerer);
1574
+ }
1575
+
1576
+ renderTypeScript(): string {
1577
+ return `disableRowLevelSecurity(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)})`;
1578
+ }
1579
+ }
1580
+
1581
+ export class RenamePostgresRlsPolicyCall extends PostgresOpFactoryCallNode {
1582
+ readonly factoryName = 'renameRlsPolicy' as const;
1583
+ // `widening` is chosen so the rename plans under every allowance set except
1584
+ // additive-only init — a rename is neither additive-creation nor
1585
+ // destructive, and the class vocabulary has no neutral middle class. It is
1586
+ // NOT that a rename widens anything; this is the accepted typology tradeoff.
1587
+ readonly operationClass = 'widening' as const;
1588
+ readonly schemaName: string;
1589
+ readonly tableName: string;
1590
+ readonly oldPolicyName: string;
1591
+ readonly newPolicyName: string;
1592
+ readonly label: string;
1593
+
1594
+ constructor(schemaName: string, tableName: string, oldPolicyName: string, newPolicyName: string) {
1595
+ super();
1596
+ this.schemaName = schemaName;
1597
+ this.tableName = tableName;
1598
+ this.oldPolicyName = oldPolicyName;
1599
+ this.newPolicyName = newPolicyName;
1600
+ this.label = `Rename RLS policy "${oldPolicyName}" to "${newPolicyName}" on "${tableName}"`;
1601
+ this.freeze();
1602
+ }
1603
+
1604
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1605
+ if (lowerer === undefined) {
1606
+ throw new Error(
1607
+ `RenamePostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.oldPolicyName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1608
+ );
1609
+ }
1610
+ return renameRlsPolicy(
1611
+ this.schemaName,
1612
+ this.tableName,
1613
+ this.oldPolicyName,
1614
+ this.newPolicyName,
1615
+ lowerer,
1616
+ );
1617
+ }
1618
+
1619
+ renderTypeScript(): string {
1620
+ return `renameRlsPolicy(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.oldPolicyName)}, ${jsonToTsSource(this.newPolicyName)})`;
1621
+ }
1622
+ }
1623
+
1379
1624
  export type PostgresOpFactoryCall =
1380
1625
  | CreateTableCall
1381
1626
  | DropTableCall
@@ -1399,4 +1644,11 @@ export type PostgresOpFactoryCall =
1399
1644
  | RawSqlCall
1400
1645
  | CreateExtensionCall
1401
1646
  | CreateSchemaCall
1647
+ | CreateNativeEnumTypeCall
1648
+ | DropNativeEnumTypeCall
1649
+ | CreatePostgresRlsPolicyCall
1650
+ | DropPostgresRlsPolicyCall
1651
+ | EnableRowLevelSecurityCall
1652
+ | DisableRowLevelSecurityCall
1653
+ | RenamePostgresRlsPolicyCall
1402
1654
  | DataTransformCall;
@@ -1,4 +1,6 @@
1
1
  import type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';
2
+ import type { DdlColumn } from '@prisma-next/sql-relational-core/ast';
3
+ import { ifDefined } from '@prisma-next/utils/defined';
2
4
  import {
3
5
  columnDefaultAst,
4
6
  columnExistsAst,
@@ -7,7 +9,9 @@ import {
7
9
  noNullValuesAst,
8
10
  tableIsEmptyAst,
9
11
  } from '../../../contract-free/checks';
12
+ import * as contractFreeDdl from '../../../contract-free/ddl';
10
13
  import { quoteIdentifier } from '../../sql-utils';
14
+ import { boundSchema } from '../bound-schema';
11
15
  import { qualifyTableName } from '../planner-sql-checks';
12
16
  import { type Op, step, targetDetails } from './shared';
13
17
 
@@ -242,12 +246,18 @@ export async function dropDefault(
242
246
  columnName: string,
243
247
  lowerer: ExecuteRequestLowerer,
244
248
  ): Promise<Op> {
245
- const qualified = qualifyTableName(schemaName, tableName);
246
249
  const { present } = await columnExistsSteps(lowerer, {
247
250
  schema: schemaName,
248
251
  table: tableName,
249
252
  column: columnName,
250
253
  });
254
+ const dropDefaultExec = await lowerer.lowerToExecuteRequest(
255
+ contractFreeDdl.alterTable({
256
+ ...ifDefined('schema', boundSchema(schemaName)),
257
+ table: tableName,
258
+ actions: [contractFreeDdl.dropDefaultAction(columnName)],
259
+ }),
260
+ );
251
261
  const noDefault = await lowerer.lowerToExecuteRequest(
252
262
  columnDefaultAst({ schema: schemaName, table: tableName, column: columnName }).defaultAbsent(),
253
263
  );
@@ -257,12 +267,7 @@ export async function dropDefault(
257
267
  operationClass: 'destructive',
258
268
  target: targetDetails('column', columnName, schemaName, tableName),
259
269
  precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
260
- execute: [
261
- step(
262
- `drop default on "${columnName}"`,
263
- `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} DROP DEFAULT`,
264
- ),
265
- ],
270
+ execute: [step(`drop default on "${columnName}"`, dropDefaultExec.sql)],
266
271
  postcheck: [
267
272
  step(`verify column "${columnName}" has no default`, noDefault.sql, noDefault.params),
268
273
  ],
@@ -272,16 +277,23 @@ export async function dropDefault(
272
277
  /**
273
278
  * Builds the op for adding a NOT NULL column (no contract default) to a
274
279
  * non-empty table. Prechecks assert the column is absent and the table is
275
- * empty; the execute step is the raw ADD COLUMN SQL passed by the caller
276
- * (slice-7 deferred); postchecks assert the column exists and is NOT NULL.
280
+ * empty; the execute step lowers the typed `AddColumn` DDL node through the
281
+ * adapter; postchecks assert the column exists and is NOT NULL.
277
282
  */
278
283
  export async function addNotNullColumnDirect(
279
284
  schemaName: string,
280
285
  tableName: string,
281
- columnName: string,
282
- executeStepSql: string,
286
+ column: DdlColumn,
283
287
  lowerer: ExecuteRequestLowerer,
284
288
  ): Promise<Op> {
289
+ const columnName = column.name;
290
+ const addColumn = await lowerer.lowerToExecuteRequest(
291
+ contractFreeDdl.alterTable({
292
+ ...ifDefined('schema', boundSchema(schemaName)),
293
+ table: tableName,
294
+ actions: [contractFreeDdl.addColumnAction(column)],
295
+ }),
296
+ );
285
297
  const absent = await lowerer.lowerToExecuteRequest(
286
298
  columnExistsAst({ schema: schemaName, table: tableName, column: columnName }).columnAbsent(),
287
299
  );
@@ -311,7 +323,7 @@ export async function addNotNullColumnDirect(
311
323
  tableEmpty.params,
312
324
  ),
313
325
  ],
314
- execute: [step(`add column "${columnName}"`, executeStepSql)],
326
+ execute: [step(`add column "${columnName}"`, addColumn.sql)],
315
327
  postcheck: [
316
328
  step(`verify column "${columnName}" exists`, present.sql, present.params),
317
329
  step(`verify column "${columnName}" is NOT NULL`, notNullable.sql, notNullable.params),
@@ -196,7 +196,7 @@ export async function dropCheckConstraint(
196
196
  * `kind` feeds the operation's `target.details.objectType`. Descriptor-flow
197
197
  * does not carry kind information in its drop-constraint descriptor, so the
198
198
  * default is `'unique'`. The reconciliation planner passes the correct kind
199
- * (`'foreignKey'`, `'primaryKey'`, or `'unique'`) based on the `SchemaIssue`
199
+ * (`'foreignKey'`, `'primaryKey'`, or `'unique'`) based on the diff issue
200
200
  * that produced the drop.
201
201
  */
202
202
  export async function dropConstraint(
@@ -113,6 +113,12 @@ export async function dataTransform<TContract extends Contract<SqlStorage>>(
113
113
  runClosures.map((closure) => invokeAndLower(closure, contract, adapter, name)),
114
114
  );
115
115
 
116
+ // Raw remnant: the factory lowered the user's `check` plan above before
117
+ // we get a chance to wrap it, so the EXISTS lifting only has text by the
118
+ // time it runs. The fix is to rewrite the factory to defer lowering until
119
+ // after wrapping — so `cfExpr.exists(checkPlan.ast)` can produce the
120
+ // EXISTS query, then lower once at the boundary — not to grow new AST
121
+ // substrate. Out of scope for the slice that introduced this comment.
116
122
  const precheck: readonly SqlMigrationPlanOperationStep[] = checkPlan
117
123
  ? [
118
124
  {
@@ -1,5 +1,6 @@
1
1
  import type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';
2
2
  import { extensionExistsAst } from '../../../contract-free/checks';
3
+ import { DEFAULT_NAMESPACE_ID } from '../../namespace-ids';
3
4
  import { quoteIdentifier } from '../../sql-utils';
4
5
  import { type Op, step } from './shared';
5
6
 
@@ -55,7 +56,7 @@ export async function installExtension(
55
56
  invariantId,
56
57
  target: {
57
58
  id: 'postgres',
58
- details: { schema: 'public', objectType: 'dependency', name: extensionName },
59
+ details: { schema: DEFAULT_NAMESPACE_ID, objectType: 'dependency', name: extensionName },
59
60
  },
60
61
  precheck: [
61
62
  step(`verify extension "${extensionName}" is not already enabled`, absent.sql, absent.params),
@@ -0,0 +1,62 @@
1
+ import type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';
2
+ import { ifDefined } from '@prisma-next/utils/defined';
3
+ import { createType, dropType } from '../../../contract-free/ddl';
4
+ import { validateEnumValueLength } from '../../sql-utils';
5
+ import { boundSchema } from '../bound-schema';
6
+ import { type Op, step, targetDetails } from './shared';
7
+
8
+ /**
9
+ * `CREATE TYPE <qualified> AS ENUM (…)` for a managed native enum, built as a
10
+ * typed DDL node and lowered by the control adapter (the type name is quoted,
11
+ * member values render as escaped string literals in declaration order —
12
+ * Postgres enum sort order is semantic). `boundSchema` maps the unbound sentinel
13
+ * to an absent schema so the type name renders unqualified and the connection's
14
+ * `search_path` resolves the schema at runtime.
15
+ */
16
+ export async function createNativeEnumType(
17
+ schemaName: string,
18
+ typeName: string,
19
+ members: readonly string[],
20
+ lowerer: ExecuteRequestLowerer,
21
+ ): Promise<Op> {
22
+ for (const member of members) {
23
+ validateEnumValueLength(member, typeName);
24
+ }
25
+ const ddlNode = createType({
26
+ ...ifDefined('schema', boundSchema(schemaName)),
27
+ name: typeName,
28
+ values: members,
29
+ });
30
+ const statement = await lowerer.lowerToExecuteRequest(ddlNode);
31
+ return {
32
+ id: `createNativeEnumType.${typeName}`,
33
+ label: `Create enum type "${typeName}"`,
34
+ operationClass: 'additive',
35
+ target: targetDetails('type', typeName, schemaName),
36
+ precheck: [],
37
+ execute: [step(`create enum type "${typeName}"`, statement.sql, statement.params)],
38
+ postcheck: [],
39
+ };
40
+ }
41
+
42
+ /** `DROP TYPE <qualified>` for an unclaimed managed native enum, via typed DDL. */
43
+ export async function dropNativeEnumType(
44
+ schemaName: string,
45
+ typeName: string,
46
+ lowerer: ExecuteRequestLowerer,
47
+ ): Promise<Op> {
48
+ const ddlNode = dropType({
49
+ ...ifDefined('schema', boundSchema(schemaName)),
50
+ name: typeName,
51
+ });
52
+ const statement = await lowerer.lowerToExecuteRequest(ddlNode);
53
+ return {
54
+ id: `dropNativeEnumType.${typeName}`,
55
+ label: `Drop enum type "${typeName}"`,
56
+ operationClass: 'destructive',
57
+ target: targetDetails('type', typeName, schemaName),
58
+ precheck: [],
59
+ execute: [step(`drop enum type "${typeName}"`, statement.sql, statement.params)],
60
+ postcheck: [],
61
+ };
62
+ }