@prisma-next/target-postgres 0.14.0-dev.6 → 0.14.0-dev.61

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 (253) hide show
  1. package/dist/authoring-BLkL4fFG.mjs +528 -0
  2. package/dist/authoring-BLkL4fFG.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-CkVQrZ4G.mjs +913 -0
  15. package/dist/codecs-CkVQrZ4G.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 +4 -4
  24. package/dist/control-policy-BpmChlAK.mjs +1151 -0
  25. package/dist/control-policy-BpmChlAK.mjs.map +1 -0
  26. package/dist/control.d.mts +2 -2
  27. package/dist/control.d.mts.map +1 -1
  28. package/dist/control.mjs +901 -35
  29. package/dist/control.mjs.map +1 -1
  30. package/dist/data-transform-BOWpliq8.mjs.map +1 -1
  31. package/dist/{data-transform-DDgWdB5o.d.mts → data-transform-DPzwBMhW.d.mts} +3 -3
  32. package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-DPzwBMhW.d.mts.map} +1 -1
  33. package/dist/data-transform.d.mts +1 -1
  34. package/dist/{ddl-QDyOSeLc.mjs → ddl-BovUVFVi.mjs} +77 -6
  35. package/dist/ddl-BovUVFVi.mjs.map +1 -0
  36. package/dist/ddl.d.mts +3 -2
  37. package/dist/ddl.mjs +2 -2
  38. package/dist/default-normalizer.d.mts +1 -1
  39. package/dist/default-normalizer.d.mts.map +1 -1
  40. package/dist/default-normalizer.mjs +247 -1
  41. package/dist/default-normalizer.mjs.map +1 -0
  42. package/dist/descriptor-meta-C1T4BXJ8.mjs +22 -0
  43. package/dist/descriptor-meta-C1T4BXJ8.mjs.map +1 -0
  44. package/dist/descriptor-meta-runtime-UwYdV8fD.mjs +12 -0
  45. package/dist/descriptor-meta-runtime-UwYdV8fD.mjs.map +1 -0
  46. package/dist/diff-database-schema-RMwnSOnz.mjs +298 -0
  47. package/dist/diff-database-schema-RMwnSOnz.mjs.map +1 -0
  48. package/dist/diff-database-schema.d.mts +46 -0
  49. package/dist/diff-database-schema.d.mts.map +1 -0
  50. package/dist/diff-database-schema.mjs +2 -0
  51. package/dist/errors-DO-w0EUS.mjs +35 -0
  52. package/dist/errors-DO-w0EUS.mjs.map +1 -0
  53. package/dist/errors.d.mts +11 -9
  54. package/dist/errors.d.mts.map +1 -1
  55. package/dist/errors.mjs +1 -1
  56. package/dist/issue-planner.d.mts +35 -11
  57. package/dist/issue-planner.d.mts.map +1 -1
  58. package/dist/issue-planner.mjs +2 -2
  59. package/dist/migration.d.mts +5 -5
  60. package/dist/migration.d.mts.map +1 -1
  61. package/dist/migration.mjs +4 -4
  62. package/dist/namespace-ids-xtp_ZY86.mjs +7 -0
  63. package/dist/namespace-ids-xtp_ZY86.mjs.map +1 -0
  64. package/dist/native-type-normalizer.mjs +37 -1
  65. package/dist/native-type-normalizer.mjs.map +1 -0
  66. package/dist/nodes-B815pj_X.mjs +162 -0
  67. package/dist/nodes-B815pj_X.mjs.map +1 -0
  68. package/dist/nodes-BtQyZha6.d.mts +146 -0
  69. package/dist/nodes-BtQyZha6.d.mts.map +1 -0
  70. package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-CI00nS4z.mjs} +300 -31
  71. package/dist/op-factory-call-CI00nS4z.mjs.map +1 -0
  72. package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-D6_7-7Vc.d.mts} +68 -15
  73. package/dist/op-factory-call-D6_7-7Vc.d.mts.map +1 -0
  74. package/dist/op-factory-call.d.mts +2 -2
  75. package/dist/op-factory-call.mjs +2 -2
  76. package/dist/pack.d.mts +287 -3
  77. package/dist/pack.d.mts.map +1 -1
  78. package/dist/pack.mjs +1 -1
  79. package/dist/planner-CAHZN1Ez.mjs +422 -0
  80. package/dist/planner-CAHZN1Ez.mjs.map +1 -0
  81. package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-B8Nn6nHN.mjs} +12 -27
  82. package/dist/planner-ddl-builders-B8Nn6nHN.mjs.map +1 -0
  83. package/dist/planner-ddl-builders.d.mts +4 -6
  84. package/dist/planner-ddl-builders.d.mts.map +1 -1
  85. package/dist/planner-ddl-builders.mjs +2 -2
  86. package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -1
  87. package/dist/planner-identity-values.d.mts +8 -2
  88. package/dist/planner-identity-values.d.mts.map +1 -1
  89. package/dist/planner-identity-values.mjs +2 -2
  90. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-a-tjfKsA.d.mts} +4 -4
  91. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-a-tjfKsA.d.mts.map} +1 -1
  92. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-flkG4Y7n.mjs} +3 -3
  93. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-flkG4Y7n.mjs.map} +1 -1
  94. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  95. package/dist/planner-produced-postgres-migration.mjs +1 -1
  96. package/dist/{planner-sql-checks-jqUUGyQR.mjs → planner-sql-checks-C1-Kk3Eu.mjs} +2 -2
  97. package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-C1-Kk3Eu.mjs.map} +1 -1
  98. package/dist/planner-sql-checks.d.mts +2 -2
  99. package/dist/planner-sql-checks.d.mts.map +1 -1
  100. package/dist/planner-sql-checks.mjs +1 -1
  101. package/dist/{planner-target-details-CIY6tLeo.d.mts → planner-target-details-HkP4RrRO.d.mts} +2 -2
  102. package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -0
  103. package/dist/planner-target-details.d.mts +1 -1
  104. package/dist/planner.d.mts +72 -17
  105. package/dist/planner.d.mts.map +1 -1
  106. package/dist/planner.mjs +3 -2
  107. package/dist/postgres-contract-view-C9j5cqP0.d.mts +34 -0
  108. package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
  109. package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-DWLNQbdR.mjs} +45 -41
  110. package/dist/postgres-contract-view-DWLNQbdR.mjs.map +1 -0
  111. package/dist/postgres-database-schema-node-BVdOffjC.d.mts +221 -0
  112. package/dist/postgres-database-schema-node-BVdOffjC.d.mts.map +1 -0
  113. package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-Bzzi0Asr.d.mts} +28 -9
  114. package/dist/postgres-migration-Bzzi0Asr.d.mts.map +1 -0
  115. package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-C92swCzd.mjs} +53 -45
  116. package/dist/postgres-migration-C92swCzd.mjs.map +1 -0
  117. package/dist/postgres-native-enum-xdiqmBf_.mjs +41 -0
  118. package/dist/postgres-native-enum-xdiqmBf_.mjs.map +1 -0
  119. package/dist/postgres-rls-policy--CSddvMR.d.mts +52 -0
  120. package/dist/postgres-rls-policy--CSddvMR.d.mts.map +1 -0
  121. package/dist/postgres-role-schema-node-BmCboEa_.mjs +198 -0
  122. package/dist/postgres-role-schema-node-BmCboEa_.mjs.map +1 -0
  123. package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-COEca21H.mjs} +188 -10
  124. package/dist/postgres-schema-COEca21H.mjs.map +1 -0
  125. package/dist/postgres-schema-DsrtYp2v.d.mts +269 -0
  126. package/dist/postgres-schema-DsrtYp2v.d.mts.map +1 -0
  127. package/dist/postgres-table-schema-node-9FCtCUz2.mjs +153 -0
  128. package/dist/postgres-table-schema-node-9FCtCUz2.mjs.map +1 -0
  129. package/dist/render-ops.d.mts +1 -1
  130. package/dist/{render-typescript-KMgosran.mjs → render-typescript-7yqILcwr.mjs} +45 -16
  131. package/dist/render-typescript-7yqILcwr.mjs.map +1 -0
  132. package/dist/render-typescript.mjs +1 -1
  133. package/dist/resolve-ddl-schema-ZkKxt2Fm.mjs +22 -0
  134. package/dist/resolve-ddl-schema-ZkKxt2Fm.mjs.map +1 -0
  135. package/dist/rls-canonicalize.d.mts +20 -0
  136. package/dist/rls-canonicalize.d.mts.map +1 -0
  137. package/dist/rls-canonicalize.mjs +2 -0
  138. package/dist/runtime.d.mts +6 -8
  139. package/dist/runtime.d.mts.map +1 -1
  140. package/dist/runtime.mjs +3 -3
  141. package/dist/runtime.mjs.map +1 -1
  142. package/dist/schema-ir-annotations.d.mts +15 -0
  143. package/dist/schema-ir-annotations.d.mts.map +1 -0
  144. package/dist/schema-ir-annotations.mjs +2 -0
  145. package/dist/types.d.mts +4 -140
  146. package/dist/types.mjs +5 -2
  147. package/dist/wire-name-rHHtr1h0.mjs +75 -0
  148. package/dist/wire-name-rHHtr1h0.mjs.map +1 -0
  149. package/package.json +23 -17
  150. package/src/contract-free/checks.ts +73 -0
  151. package/src/contract-free/ddl.ts +71 -1
  152. package/src/core/authoring.ts +467 -2
  153. package/src/core/codec-ids.ts +1 -0
  154. package/src/core/codec-type-map.ts +2 -0
  155. package/src/core/codecs.ts +180 -1
  156. package/src/core/ddl/nodes.ts +141 -2
  157. package/src/core/default-normalizer.ts +122 -2
  158. package/src/core/descriptor-meta.ts +10 -1
  159. package/src/core/entity-kinds.ts +41 -0
  160. package/src/core/errors.ts +14 -12
  161. package/src/core/migrations/bound-schema.ts +10 -0
  162. package/src/core/migrations/column-ddl-rendering.ts +117 -0
  163. package/src/core/migrations/contract-to-postgres-database-schema-node.ts +160 -0
  164. package/src/core/migrations/control-policy.ts +126 -44
  165. package/src/core/migrations/diff-database-schema.ts +253 -0
  166. package/src/core/migrations/issue-planner.ts +692 -652
  167. package/src/core/migrations/op-factory-call.ts +189 -21
  168. package/src/core/migrations/operations/columns.ts +24 -12
  169. package/src/core/migrations/operations/constraints.ts +1 -1
  170. package/src/core/migrations/operations/data-transform.ts +6 -0
  171. package/src/core/migrations/operations/dependencies.ts +2 -1
  172. package/src/core/migrations/operations/rls.ts +187 -0
  173. package/src/core/migrations/operations/shared.ts +0 -30
  174. package/src/core/migrations/planner-ddl-builders.ts +20 -58
  175. package/src/core/migrations/planner-identity-values.ts +1 -1
  176. package/src/core/migrations/planner-recipes.ts +31 -13
  177. package/src/core/migrations/planner-sql-checks.ts +1 -1
  178. package/src/core/migrations/planner-strategies.ts +248 -216
  179. package/src/core/migrations/planner-target-details.ts +3 -1
  180. package/src/core/migrations/planner.ts +386 -59
  181. package/src/core/migrations/postgres-migration.ts +70 -86
  182. package/src/core/migrations/render-typescript.ts +42 -15
  183. package/src/core/migrations/resolve-ddl-schema.ts +26 -0
  184. package/src/core/migrations/runner.ts +10 -16
  185. package/src/core/migrations/verify-postgres-namespaces.ts +47 -31
  186. package/src/core/namespace-ids.ts +3 -0
  187. package/src/core/postgres-contract-serializer.ts +46 -71
  188. package/src/core/postgres-contract-view.ts +48 -0
  189. package/src/core/postgres-native-enum.ts +51 -0
  190. package/src/core/postgres-rls-enablement.ts +34 -0
  191. package/src/core/postgres-rls-policy.ts +64 -0
  192. package/src/core/postgres-role.ts +59 -0
  193. package/src/core/postgres-schema-verifier.ts +10 -7
  194. package/src/core/postgres-schema.ts +64 -15
  195. package/src/core/postgres-validators.ts +34 -0
  196. package/src/core/psl-infer/infer-psl-contract.ts +1326 -0
  197. package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
  198. package/src/core/psl-infer/postgres-type-map.ts +128 -0
  199. package/src/core/rls/canonicalize.ts +48 -0
  200. package/src/core/rls/wire-name.ts +33 -0
  201. package/src/core/schema-ir/postgres-database-schema-node.ts +61 -0
  202. package/src/core/schema-ir/postgres-namespace-schema-node.ts +79 -0
  203. package/src/core/schema-ir/postgres-policy-schema-node.ts +90 -0
  204. package/src/core/schema-ir/postgres-role-schema-node.ts +65 -0
  205. package/src/core/schema-ir/postgres-table-schema-node.ts +140 -0
  206. package/src/core/schema-ir/schema-node-kinds.ts +113 -0
  207. package/src/exports/codecs.ts +3 -0
  208. package/src/exports/contract-free.ts +11 -1
  209. package/src/exports/control.ts +27 -33
  210. package/src/exports/ddl.ts +6 -0
  211. package/src/exports/diff-database-schema.ts +7 -0
  212. package/src/exports/issue-planner.ts +1 -1
  213. package/src/exports/migration.ts +1 -0
  214. package/src/exports/op-factory-call.ts +1 -0
  215. package/src/exports/planner-ddl-builders.ts +0 -2
  216. package/src/exports/planner-identity-values.ts +4 -1
  217. package/src/exports/planner.ts +1 -0
  218. package/src/exports/rls-canonicalize.ts +7 -0
  219. package/src/exports/runtime.ts +1 -0
  220. package/src/exports/schema-ir-annotations.ts +1 -0
  221. package/src/exports/types.ts +34 -0
  222. package/dist/codec-ids-BvytN2P8.mjs.map +0 -1
  223. package/dist/codec-ids-CnXu9Qy3.d.mts.map +0 -1
  224. package/dist/codec-types-DHCkwPKE.d.mts.map +0 -1
  225. package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
  226. package/dist/ddl-QDyOSeLc.mjs.map +0 -1
  227. package/dist/default-normalizer-DyyCHQWs.mjs +0 -131
  228. package/dist/default-normalizer-DyyCHQWs.mjs.map +0 -1
  229. package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
  230. package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
  231. package/dist/errors-CUk87ByX.mjs +0 -33
  232. package/dist/errors-CUk87ByX.mjs.map +0 -1
  233. package/dist/issue-planner-DL6g3CmE.mjs +0 -824
  234. package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
  235. package/dist/native-type-normalizer-Bc9XJzWC.mjs +0 -38
  236. package/dist/native-type-normalizer-Bc9XJzWC.mjs.map +0 -1
  237. package/dist/nodes-Bbhs2rwj.mjs +0 -76
  238. package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
  239. package/dist/nodes-pLeLgdis.d.mts +0 -67
  240. package/dist/nodes-pLeLgdis.d.mts.map +0 -1
  241. package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
  242. package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
  243. package/dist/planner-Bs_baQax.mjs +0 -324
  244. package/dist/planner-Bs_baQax.mjs.map +0 -1
  245. package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
  246. package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
  247. package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
  248. package/dist/postgres-migration-B5jKrXv3.mjs.map +0 -1
  249. package/dist/postgres-migration-Y4YBJqkS.d.mts.map +0 -1
  250. package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
  251. package/dist/render-typescript-KMgosran.mjs.map +0 -1
  252. package/dist/types.d.mts.map +0 -1
  253. 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,13 @@ import {
61
63
  } from './operations/constraints';
62
64
  import { createExtension } from './operations/dependencies';
63
65
  import { createIndex, dropIndex } from './operations/indexes';
66
+ import {
67
+ createRlsPolicy,
68
+ disableRowLevelSecurity,
69
+ dropRlsPolicy,
70
+ enableRowLevelSecurity,
71
+ renameRlsPolicy,
72
+ } from './operations/rls';
64
73
  import type { ForeignKeySpec } from './operations/shared';
65
74
  import { step, targetDetails } from './operations/shared';
66
75
  import { dropTable } from './operations/tables';
@@ -83,10 +92,6 @@ type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
83
92
  // transitive package on disk.
84
93
  const POSTGRES_MIGRATION_FACADE = '@prisma-next/postgres/migration';
85
94
 
86
- function boundSchema(schemaName: string): string | undefined {
87
- return schemaName === UNBOUND_NAMESPACE_ID ? undefined : schemaName;
88
- }
89
-
90
95
  abstract class PostgresOpFactoryCallNode extends TsExpression implements FrameworkOpFactoryCall {
91
96
  abstract readonly factoryName: string;
92
97
  abstract readonly operationClass: MigrationOperationClass;
@@ -169,6 +174,8 @@ function renderDdlConstraintAsTsCall(constraint: DdlTableConstraint): string {
169
174
  const nameOpt = constraint.name ? `, { name: ${jsonToTsSource(constraint.name)} }` : '';
170
175
  return `unique(${jsonToTsSource(constraint.columns)}${nameOpt})`;
171
176
  }
177
+ case 'check-expression':
178
+ return `checkExpression(${jsonToTsSource(constraint.name)}, ${jsonToTsSource(constraint.expression)})`;
172
179
  }
173
180
  }
174
181
 
@@ -183,6 +190,7 @@ function constraintImportSymbols(constraints: readonly DdlTableConstraint[] | un
183
190
  if (c.kind === 'primary-key') symbols.add('primaryKey');
184
191
  else if (c.kind === 'foreign-key') symbols.add('foreignKey');
185
192
  else if (c.kind === 'unique') symbols.add('unique');
193
+ else if (c.kind === 'check-expression') symbols.add('checkExpression');
186
194
  }
187
195
  return [...symbols];
188
196
  }
@@ -684,10 +692,8 @@ export class DropDefaultCall extends PostgresOpFactoryCallNode {
684
692
 
685
693
  /**
686
694
  * 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.
695
+ * a table that must be empty at migration time. Carries the typed `DdlColumn`
696
+ * and lowers it to an ADD COLUMN execute step via the adapter at `toOp` time.
691
697
  *
692
698
  * No authored `PostgresMigration` method: this call is only emitted by the
693
699
  * planner, never hand-written by migration authors.
@@ -698,15 +704,15 @@ export class AddNotNullColumnDirectCall extends PostgresOpFactoryCallNode {
698
704
  readonly schemaName: string;
699
705
  readonly tableName: string;
700
706
  readonly columnName: string;
701
- readonly executeStepSql: string;
707
+ readonly column: DdlColumn;
702
708
  readonly label: string;
703
709
 
704
- constructor(schemaName: string, tableName: string, columnName: string, executeStepSql: string) {
710
+ constructor(schemaName: string, tableName: string, columnName: string, column: DdlColumn) {
705
711
  super();
706
712
  this.schemaName = schemaName;
707
713
  this.tableName = tableName;
708
714
  this.columnName = columnName;
709
- this.executeStepSql = executeStepSql;
715
+ this.column = column;
710
716
  this.label = `Add column ${columnName} to ${tableName}`;
711
717
  this.freeze();
712
718
  }
@@ -717,13 +723,7 @@ export class AddNotNullColumnDirectCall extends PostgresOpFactoryCallNode {
717
723
  `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
724
  );
719
725
  }
720
- return addNotNullColumnDirect(
721
- this.schemaName,
722
- this.tableName,
723
- this.columnName,
724
- this.executeStepSql,
725
- lowerer,
726
- );
726
+ return addNotNullColumnDirect(this.schemaName, this.tableName, this.column, lowerer);
727
727
  }
728
728
 
729
729
  renderTypeScript(): string {
@@ -738,9 +738,9 @@ export class AddNotNullColumnDirectCall extends PostgresOpFactoryCallNode {
738
738
  /**
739
739
  * Planner-internal call for adding a NOT NULL column (no contract default)
740
740
  * 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.
741
+ * needed for `buildAddNotNullColumnWithTemporaryDefaultOperation`; both the
742
+ * typed ADD COLUMN execute step and the pre/postchecks are lowered via the
743
+ * adapter at `toOp` time.
744
744
  *
745
745
  * No authored `PostgresMigration` method: this call is only emitted by the
746
746
  * planner, never hand-written by migration authors.
@@ -1376,6 +1376,169 @@ export class DataTransformCall extends PostgresOpFactoryCallNode {
1376
1376
  }
1377
1377
  }
1378
1378
 
1379
+ export class CreatePostgresRlsPolicyCall extends PostgresOpFactoryCallNode {
1380
+ readonly factoryName = 'createRlsPolicy' as const;
1381
+ readonly operationClass = 'additive' as const;
1382
+ readonly schemaName: string;
1383
+ readonly tableName: string;
1384
+ readonly policy: PostgresRlsPolicy;
1385
+ readonly label: string;
1386
+
1387
+ constructor(schemaName: string, tableName: string, policy: PostgresRlsPolicy) {
1388
+ super();
1389
+ this.schemaName = schemaName;
1390
+ this.tableName = tableName;
1391
+ this.policy = policy;
1392
+ this.label = `Create RLS policy "${policy.name}" on "${tableName}"`;
1393
+ this.freeze();
1394
+ }
1395
+
1396
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1397
+ if (lowerer === undefined) {
1398
+ throw new Error(
1399
+ `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.`,
1400
+ );
1401
+ }
1402
+ return createRlsPolicy(this.schemaName, this.tableName, this.policy, lowerer);
1403
+ }
1404
+
1405
+ renderTypeScript(): string {
1406
+ return `createRlsPolicy(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.policy)})`;
1407
+ }
1408
+ }
1409
+
1410
+ export class DropPostgresRlsPolicyCall extends PostgresOpFactoryCallNode {
1411
+ readonly factoryName = 'dropRlsPolicy' as const;
1412
+ readonly operationClass = 'destructive' as const;
1413
+ readonly schemaName: string;
1414
+ readonly tableName: string;
1415
+ readonly policyName: string;
1416
+ readonly label: string;
1417
+
1418
+ constructor(schemaName: string, tableName: string, policyName: string) {
1419
+ super();
1420
+ this.schemaName = schemaName;
1421
+ this.tableName = tableName;
1422
+ this.policyName = policyName;
1423
+ this.label = `Drop RLS policy "${policyName}" on "${tableName}"`;
1424
+ this.freeze();
1425
+ }
1426
+
1427
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1428
+ if (lowerer === undefined) {
1429
+ throw new Error(
1430
+ `DropPostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.policyName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1431
+ );
1432
+ }
1433
+ return dropRlsPolicy(this.schemaName, this.tableName, this.policyName, lowerer);
1434
+ }
1435
+
1436
+ renderTypeScript(): string {
1437
+ return `dropRlsPolicy(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.policyName)})`;
1438
+ }
1439
+ }
1440
+
1441
+ export class EnableRowLevelSecurityCall extends PostgresOpFactoryCallNode {
1442
+ readonly factoryName = 'enableRowLevelSecurity' as const;
1443
+ readonly operationClass = 'additive' as const;
1444
+ readonly schemaName: string;
1445
+ readonly tableName: string;
1446
+ readonly label: string;
1447
+
1448
+ constructor(schemaName: string, tableName: string) {
1449
+ super();
1450
+ this.schemaName = schemaName;
1451
+ this.tableName = tableName;
1452
+ this.label = `Enable row-level security on "${tableName}"`;
1453
+ this.freeze();
1454
+ }
1455
+
1456
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1457
+ if (lowerer === undefined) {
1458
+ throw new Error(
1459
+ `EnableRowLevelSecurityCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1460
+ );
1461
+ }
1462
+ return enableRowLevelSecurity(this.schemaName, this.tableName, lowerer);
1463
+ }
1464
+
1465
+ renderTypeScript(): string {
1466
+ return `enableRowLevelSecurity(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)})`;
1467
+ }
1468
+ }
1469
+
1470
+ export class DisableRowLevelSecurityCall extends PostgresOpFactoryCallNode {
1471
+ readonly factoryName = 'disableRowLevelSecurity' as const;
1472
+ readonly operationClass = 'destructive' as const;
1473
+ readonly schemaName: string;
1474
+ readonly tableName: string;
1475
+ readonly label: string;
1476
+
1477
+ constructor(schemaName: string, tableName: string) {
1478
+ super();
1479
+ this.schemaName = schemaName;
1480
+ this.tableName = tableName;
1481
+ this.label = `Disable row-level security on "${tableName}"`;
1482
+ this.freeze();
1483
+ }
1484
+
1485
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1486
+ if (lowerer === undefined) {
1487
+ throw new Error(
1488
+ `DisableRowLevelSecurityCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1489
+ );
1490
+ }
1491
+ return disableRowLevelSecurity(this.schemaName, this.tableName, lowerer);
1492
+ }
1493
+
1494
+ renderTypeScript(): string {
1495
+ return `disableRowLevelSecurity(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)})`;
1496
+ }
1497
+ }
1498
+
1499
+ export class RenamePostgresRlsPolicyCall extends PostgresOpFactoryCallNode {
1500
+ readonly factoryName = 'renameRlsPolicy' as const;
1501
+ // `widening` is chosen so the rename plans under every allowance set except
1502
+ // additive-only init — a rename is neither additive-creation nor
1503
+ // destructive, and the class vocabulary has no neutral middle class. It is
1504
+ // NOT that a rename widens anything; this is the accepted typology tradeoff.
1505
+ readonly operationClass = 'widening' as const;
1506
+ readonly schemaName: string;
1507
+ readonly tableName: string;
1508
+ readonly oldPolicyName: string;
1509
+ readonly newPolicyName: string;
1510
+ readonly label: string;
1511
+
1512
+ constructor(schemaName: string, tableName: string, oldPolicyName: string, newPolicyName: string) {
1513
+ super();
1514
+ this.schemaName = schemaName;
1515
+ this.tableName = tableName;
1516
+ this.oldPolicyName = oldPolicyName;
1517
+ this.newPolicyName = newPolicyName;
1518
+ this.label = `Rename RLS policy "${oldPolicyName}" to "${newPolicyName}" on "${tableName}"`;
1519
+ this.freeze();
1520
+ }
1521
+
1522
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1523
+ if (lowerer === undefined) {
1524
+ throw new Error(
1525
+ `RenamePostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.oldPolicyName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1526
+ );
1527
+ }
1528
+ return renameRlsPolicy(
1529
+ this.schemaName,
1530
+ this.tableName,
1531
+ this.oldPolicyName,
1532
+ this.newPolicyName,
1533
+ lowerer,
1534
+ );
1535
+ }
1536
+
1537
+ renderTypeScript(): string {
1538
+ return `renameRlsPolicy(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.oldPolicyName)}, ${jsonToTsSource(this.newPolicyName)})`;
1539
+ }
1540
+ }
1541
+
1379
1542
  export type PostgresOpFactoryCall =
1380
1543
  | CreateTableCall
1381
1544
  | DropTableCall
@@ -1399,4 +1562,9 @@ export type PostgresOpFactoryCall =
1399
1562
  | RawSqlCall
1400
1563
  | CreateExtensionCall
1401
1564
  | CreateSchemaCall
1565
+ | CreatePostgresRlsPolicyCall
1566
+ | DropPostgresRlsPolicyCall
1567
+ | EnableRowLevelSecurityCall
1568
+ | DisableRowLevelSecurityCall
1569
+ | RenamePostgresRlsPolicyCall
1402
1570
  | 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,187 @@
1
+ import type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';
2
+ import { ifDefined } from '@prisma-next/utils/defined';
3
+ import { rlsEnabledAst, rlsPolicyExistsAst } from '../../../contract-free/checks';
4
+ import {
5
+ alterPolicyRename,
6
+ createPolicy,
7
+ disableRowLevelSecurity as disableRowLevelSecurityDdl,
8
+ dropPolicy,
9
+ } from '../../../contract-free/ddl';
10
+ import type { PostgresRlsPolicy } from '../../postgres-rls-policy';
11
+ import { qualifyTableName } from '../planner-sql-checks';
12
+ import { type Op, step, targetDetails } from './shared';
13
+
14
+ const PLAIN_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_$]*$/;
15
+
16
+ function validateRoleName(role: string): string {
17
+ if (!PLAIN_IDENTIFIER.test(role)) {
18
+ throw new Error(
19
+ `Invalid role name ${JSON.stringify(role)}: role names must be plain SQL identifiers matching ^[A-Za-z_][A-Za-z0-9_$]*$`,
20
+ );
21
+ }
22
+ return role;
23
+ }
24
+
25
+ export async function createRlsPolicy(
26
+ schemaName: string,
27
+ tableName: string,
28
+ policy: PostgresRlsPolicy,
29
+ lowerer: ExecuteRequestLowerer,
30
+ ): Promise<Op> {
31
+ const validatedRoles = policy.roles.map(validateRoleName);
32
+ const ddlNode = createPolicy({
33
+ schema: schemaName,
34
+ table: tableName,
35
+ name: policy.name,
36
+ permissive: policy.permissive,
37
+ operation: policy.operation,
38
+ roles: validatedRoles,
39
+ ...ifDefined('using', policy.using),
40
+ ...ifDefined('withCheck', policy.withCheck),
41
+ });
42
+ const checks = rlsPolicyExistsAst({
43
+ schema: schemaName,
44
+ table: tableName,
45
+ policyName: policy.name,
46
+ });
47
+ const absent = await lowerer.lowerToExecuteRequest(checks.policyAbsent());
48
+ const execute = await lowerer.lowerToExecuteRequest(ddlNode);
49
+ const present = await lowerer.lowerToExecuteRequest(checks.policyPresent());
50
+ return {
51
+ id: `rlsPolicy.${schemaName}.${tableName}.${policy.name}`,
52
+ label: `Create RLS policy "${policy.name}" on "${tableName}"`,
53
+ operationClass: 'additive',
54
+ target: targetDetails('rlsPolicy', policy.name, schemaName, tableName),
55
+ precheck: [
56
+ step(`ensure RLS policy "${policy.name}" does not exist`, absent.sql, absent.params),
57
+ ],
58
+ execute: [step(`create RLS policy "${policy.name}"`, execute.sql, execute.params)],
59
+ postcheck: [step(`verify RLS policy "${policy.name}" exists`, present.sql, present.params)],
60
+ };
61
+ }
62
+
63
+ export async function dropRlsPolicy(
64
+ schemaName: string,
65
+ tableName: string,
66
+ policyName: string,
67
+ lowerer: ExecuteRequestLowerer,
68
+ ): Promise<Op> {
69
+ const ddlNode = dropPolicy({ schema: schemaName, table: tableName, name: policyName });
70
+ const checks = rlsPolicyExistsAst({ schema: schemaName, table: tableName, policyName });
71
+ const present = await lowerer.lowerToExecuteRequest(checks.policyPresent());
72
+ const execute = await lowerer.lowerToExecuteRequest(ddlNode);
73
+ const absent = await lowerer.lowerToExecuteRequest(checks.policyAbsent());
74
+ return {
75
+ id: `rlsPolicy.${schemaName}.${tableName}.${policyName}.drop`,
76
+ label: `Drop RLS policy "${policyName}" on "${tableName}"`,
77
+ operationClass: 'destructive',
78
+ target: targetDetails('rlsPolicy', policyName, schemaName, tableName),
79
+ precheck: [step(`ensure RLS policy "${policyName}" exists`, present.sql, present.params)],
80
+ execute: [step(`drop RLS policy "${policyName}"`, execute.sql, execute.params)],
81
+ postcheck: [step(`verify RLS policy "${policyName}" is absent`, absent.sql, absent.params)],
82
+ };
83
+ }
84
+
85
+ export async function enableRowLevelSecurity(
86
+ schemaName: string,
87
+ tableName: string,
88
+ lowerer: ExecuteRequestLowerer,
89
+ ): Promise<Op> {
90
+ const checks = rlsEnabledAst(schemaName, tableName);
91
+ const disabled = await lowerer.lowerToExecuteRequest(checks.rlsDisabled());
92
+ const enabled = await lowerer.lowerToExecuteRequest(checks.rlsEnabled());
93
+ return {
94
+ id: `rowLevelSecurity.${schemaName}.${tableName}`,
95
+ label: `Enable row-level security on "${tableName}"`,
96
+ operationClass: 'additive',
97
+ target: targetDetails('rowLevelSecurity', tableName, schemaName),
98
+ precheck: [
99
+ step(`check RLS is not already enabled on "${tableName}"`, disabled.sql, disabled.params),
100
+ ],
101
+ execute: [
102
+ step(
103
+ `enable row-level security on "${tableName}"`,
104
+ `ALTER TABLE ${qualifyTableName(schemaName, tableName)} ENABLE ROW LEVEL SECURITY`,
105
+ ),
106
+ ],
107
+ postcheck: [
108
+ step(`verify row-level security is enabled on "${tableName}"`, enabled.sql, enabled.params),
109
+ ],
110
+ };
111
+ }
112
+
113
+ export async function disableRowLevelSecurity(
114
+ schemaName: string,
115
+ tableName: string,
116
+ lowerer: ExecuteRequestLowerer,
117
+ ): Promise<Op> {
118
+ const ddlNode = disableRowLevelSecurityDdl({ schema: schemaName, table: tableName });
119
+ const checks = rlsEnabledAst(schemaName, tableName);
120
+ const enabled = await lowerer.lowerToExecuteRequest(checks.rlsEnabled());
121
+ const execute = await lowerer.lowerToExecuteRequest(ddlNode);
122
+ const disabled = await lowerer.lowerToExecuteRequest(checks.rlsDisabled());
123
+ return {
124
+ id: `rowLevelSecurity.${schemaName}.${tableName}.disable`,
125
+ label: `Disable row-level security on "${tableName}"`,
126
+ operationClass: 'destructive',
127
+ target: targetDetails('rowLevelSecurity', tableName, schemaName),
128
+ precheck: [
129
+ step(`check RLS is currently enabled on "${tableName}"`, enabled.sql, enabled.params),
130
+ ],
131
+ execute: [step(`disable row-level security on "${tableName}"`, execute.sql, execute.params)],
132
+ postcheck: [
133
+ step(
134
+ `verify row-level security is disabled on "${tableName}"`,
135
+ disabled.sql,
136
+ disabled.params,
137
+ ),
138
+ ],
139
+ };
140
+ }
141
+
142
+ export async function renameRlsPolicy(
143
+ schemaName: string,
144
+ tableName: string,
145
+ oldPolicyName: string,
146
+ newPolicyName: string,
147
+ lowerer: ExecuteRequestLowerer,
148
+ ): Promise<Op> {
149
+ const ddlNode = alterPolicyRename({
150
+ schema: schemaName,
151
+ table: tableName,
152
+ name: oldPolicyName,
153
+ newName: newPolicyName,
154
+ });
155
+ const oldChecks = rlsPolicyExistsAst({
156
+ schema: schemaName,
157
+ table: tableName,
158
+ policyName: oldPolicyName,
159
+ });
160
+ const newChecks = rlsPolicyExistsAst({
161
+ schema: schemaName,
162
+ table: tableName,
163
+ policyName: newPolicyName,
164
+ });
165
+ const oldPresent = await lowerer.lowerToExecuteRequest(oldChecks.policyPresent());
166
+ const execute = await lowerer.lowerToExecuteRequest(ddlNode);
167
+ const newPresent = await lowerer.lowerToExecuteRequest(newChecks.policyPresent());
168
+ return {
169
+ id: `rlsPolicy.${schemaName}.${tableName}.${oldPolicyName}.rename`,
170
+ label: `Rename RLS policy "${oldPolicyName}" to "${newPolicyName}" on "${tableName}"`,
171
+ operationClass: 'widening',
172
+ target: targetDetails('rlsPolicy', newPolicyName, schemaName, tableName),
173
+ precheck: [
174
+ step(`ensure RLS policy "${oldPolicyName}" exists`, oldPresent.sql, oldPresent.params),
175
+ ],
176
+ execute: [
177
+ step(
178
+ `rename RLS policy "${oldPolicyName}" to "${newPolicyName}"`,
179
+ execute.sql,
180
+ execute.params,
181
+ ),
182
+ ],
183
+ postcheck: [
184
+ step(`verify RLS policy "${newPolicyName}" exists`, newPresent.sql, newPresent.params),
185
+ ],
186
+ };
187
+ }
@@ -1,30 +1,10 @@
1
1
  import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';
2
2
  import type { ReferentialAction } from '@prisma-next/sql-contract/types';
3
3
  import { ifDefined } from '@prisma-next/utils/defined';
4
- import { quoteIdentifier } from '../../sql-utils';
5
4
  import type { OperationClass, PostgresPlanTargetDetails } from '../planner-target-details';
6
5
 
7
6
  export type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
8
7
 
9
- /**
10
- * Literal-args shape for a column definition consumed by `addColumn` and
11
- * similar operations. Fully materialized: codec expansion and default
12
- * rendering have already happened in the wrapper.
13
- *
14
- * - `typeSql` is the column's DDL type string (e.g. `"integer"`, `"SERIAL"`,
15
- * `"varchar(100)"`), already produced by `buildColumnTypeSql` in the
16
- * call-factory wrapper.
17
- * - `defaultSql` is the full `DEFAULT …` clause (e.g. `"DEFAULT 42"`) or an
18
- * empty string when the column has no default, matching
19
- * `buildColumnDefaultSql`'s output.
20
- */
21
- export interface ColumnSpec {
22
- readonly name: string;
23
- readonly typeSql: string;
24
- readonly defaultSql: string;
25
- readonly nullable: boolean;
26
- }
27
-
28
8
  /**
29
9
  * Literal-args shape for a foreign key definition. `references.schema`
30
10
  * carries the target table's namespace (schema) coordinate so the rendered
@@ -57,13 +37,3 @@ export function targetDetails(
57
37
  details: { schema, objectType, name, ...ifDefined('table', table) },
58
38
  };
59
39
  }
60
-
61
- export function renderColumnDefinition(column: ColumnSpec): string {
62
- const parts = [
63
- quoteIdentifier(column.name),
64
- column.typeSql,
65
- column.defaultSql,
66
- column.nullable ? '' : 'NOT NULL',
67
- ].filter(Boolean);
68
- return parts.join(' ');
69
- }