@prisma-next/target-postgres 0.14.0 → 0.15.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 (269) hide show
  1. package/dist/authoring-BtsOWgI3.mjs +674 -0
  2. package/dist/authoring-BtsOWgI3.mjs.map +1 -0
  3. package/dist/canonicalize-D1F4vUnP.d.mts +48 -0
  4. package/dist/canonicalize-D1F4vUnP.d.mts.map +1 -0
  5. package/dist/{codec-ids-BvytN2P8.mjs → codec-ids-B10ZZHzw.mjs} +4 -2
  6. package/dist/codec-ids-B10ZZHzw.mjs.map +1 -0
  7. package/dist/{codec-ids-CnXu9Qy3.d.mts → codec-ids-CI144z7g.d.mts} +4 -2
  8. package/dist/codec-ids-CI144z7g.d.mts.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-CTfT4U4O.d.mts} +4 -2
  12. package/dist/codec-types-CTfT4U4O.d.mts.map +1 -0
  13. package/dist/codec-types.d.mts +1 -1
  14. package/dist/{codecs--0A5_4Bq.d.mts → codecs-D7W9O0Xx.d.mts} +134 -4
  15. package/dist/codecs-D7W9O0Xx.d.mts.map +1 -0
  16. package/dist/codecs-DRbb26Or.mjs +955 -0
  17. package/dist/codecs-DRbb26Or.mjs.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-DaLdbcYE.mjs +1254 -0
  26. package/dist/control-policy-DaLdbcYE.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 +880 -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-GTTOvjx_.mjs} +128 -6
  36. package/dist/ddl-GTTOvjx_.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-CFQKLXl_.mjs +23 -0
  44. package/dist/descriptor-meta-CFQKLXl_.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-oY3brcLj.mjs +368 -0
  48. package/dist/diff-database-schema-oY3brcLj.mjs.map +1 -0
  49. package/dist/diff-database-schema.d.mts +37 -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-DJC5B8Id.mjs +192 -0
  68. package/dist/nodes-DJC5B8Id.mjs.map +1 -0
  69. package/dist/nodes-Dv5eCSq9.d.mts +170 -0
  70. package/dist/nodes-Dv5eCSq9.d.mts.map +1 -0
  71. package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-CvH0JeBW.d.mts} +119 -17
  72. package/dist/op-factory-call-CvH0JeBW.d.mts.map +1 -0
  73. package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-tBcLo_B8.mjs} +496 -38
  74. package/dist/op-factory-call-tBcLo_B8.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 +321 -3
  78. package/dist/pack.d.mts.map +1 -1
  79. package/dist/pack.mjs +1 -1
  80. package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-BKlmGDJl.mjs} +17 -28
  81. package/dist/planner-ddl-builders-BKlmGDJl.mjs.map +1 -0
  82. package/dist/planner-ddl-builders.d.mts +4 -6
  83. package/dist/planner-ddl-builders.d.mts.map +1 -1
  84. package/dist/planner-ddl-builders.mjs +2 -2
  85. package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -1
  86. package/dist/planner-identity-values.d.mts +8 -2
  87. package/dist/planner-identity-values.d.mts.map +1 -1
  88. package/dist/planner-identity-values.mjs +2 -2
  89. package/dist/planner-ootbxGty.mjs +390 -0
  90. package/dist/planner-ootbxGty.mjs.map +1 -0
  91. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-DVsaobdV.mjs} +3 -3
  92. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-DVsaobdV.mjs.map} +1 -1
  93. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-k33bb9Sm.d.mts} +4 -4
  94. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-k33bb9Sm.d.mts.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-zqNfs2XZ.mjs} +5 -5
  98. package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-zqNfs2XZ.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-view-C9j5cqP0.d.mts +34 -0
  109. package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
  110. package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-DM8sN1Ot.mjs} +45 -41
  111. package/dist/postgres-contract-view-DM8sN1Ot.mjs.map +1 -0
  112. package/dist/postgres-database-schema-node-DJOTywwQ.d.mts +271 -0
  113. package/dist/postgres-database-schema-node-DJOTywwQ.d.mts.map +1 -0
  114. package/dist/postgres-migration-Bt3sXoID.mjs +194 -0
  115. package/dist/postgres-migration-Bt3sXoID.mjs.map +1 -0
  116. package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-ulfqRGA1.d.mts} +83 -9
  117. package/dist/postgres-migration-ulfqRGA1.d.mts.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-bg32e7I-.mjs +191 -0
  123. package/dist/postgres-role-schema-node-bg32e7I-.mjs.map +1 -0
  124. package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-Cm4DtiGA.mjs} +200 -11
  125. package/dist/postgres-schema-Cm4DtiGA.mjs.map +1 -0
  126. package/dist/postgres-schema-DKq6s1P3.d.mts +269 -0
  127. package/dist/postgres-schema-DKq6s1P3.d.mts.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-XyBaaenM.mjs +22 -0
  135. package/dist/resolve-ddl-schema-XyBaaenM.mjs.map +1 -0
  136. package/dist/rls-canonicalize.d.mts +27 -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/schema-node-kinds-CrYzCR1i.d.mts +30 -0
  147. package/dist/schema-node-kinds-CrYzCR1i.d.mts.map +1 -0
  148. package/dist/{sql-utils-DcfMz4MQ.mjs → sql-utils-SU4FDvIV.mjs} +12 -3
  149. package/dist/{sql-utils-DcfMz4MQ.mjs.map → sql-utils-SU4FDvIV.mjs.map} +1 -1
  150. package/dist/sql-utils.d.mts +8 -1
  151. package/dist/sql-utils.d.mts.map +1 -1
  152. package/dist/sql-utils.mjs +2 -2
  153. package/dist/types.d.mts +5 -140
  154. package/dist/types.mjs +5 -2
  155. package/dist/wire-name-DbQ9-2RC.mjs +104 -0
  156. package/dist/wire-name-DbQ9-2RC.mjs.map +1 -0
  157. package/package.json +26 -20
  158. package/src/contract-free/checks.ts +153 -0
  159. package/src/contract-free/control-bootstrap.ts +20 -3
  160. package/src/contract-free/ddl.ts +98 -1
  161. package/src/core/authoring.ts +726 -2
  162. package/src/core/codec-helpers.ts +33 -7
  163. package/src/core/codec-ids.ts +2 -0
  164. package/src/core/codec-type-map.ts +4 -0
  165. package/src/core/codecs.ts +236 -12
  166. package/src/core/ddl/nodes.ts +185 -2
  167. package/src/core/default-normalizer.ts +122 -2
  168. package/src/core/descriptor-meta.ts +12 -1
  169. package/src/core/entity-kinds.ts +41 -0
  170. package/src/core/errors.ts +14 -12
  171. package/src/core/migrations/bound-schema.ts +10 -0
  172. package/src/core/migrations/column-ddl-rendering.ts +117 -0
  173. package/src/core/migrations/contract-to-postgres-database-schema-node.ts +269 -0
  174. package/src/core/migrations/control-policy.ts +218 -65
  175. package/src/core/migrations/diff-database-schema.ts +252 -0
  176. package/src/core/migrations/issue-planner.ts +782 -660
  177. package/src/core/migrations/op-factory-call.ts +415 -31
  178. package/src/core/migrations/operations/columns.ts +24 -12
  179. package/src/core/migrations/operations/constraints.ts +1 -1
  180. package/src/core/migrations/operations/data-transform.ts +6 -0
  181. package/src/core/migrations/operations/dependencies.ts +2 -1
  182. package/src/core/migrations/operations/native-enum-types.ts +62 -0
  183. package/src/core/migrations/operations/rls.ts +187 -0
  184. package/src/core/migrations/operations/shared.ts +0 -30
  185. package/src/core/migrations/planner-ddl-builders.ts +31 -59
  186. package/src/core/migrations/planner-identity-values.ts +1 -1
  187. package/src/core/migrations/planner-recipes.ts +31 -13
  188. package/src/core/migrations/planner-sql-checks.ts +1 -1
  189. package/src/core/migrations/planner-strategies.ts +250 -218
  190. package/src/core/migrations/planner-target-details.ts +3 -1
  191. package/src/core/migrations/planner.ts +358 -67
  192. package/src/core/migrations/postgres-migration.ts +178 -86
  193. package/src/core/migrations/render-typescript.ts +42 -15
  194. package/src/core/migrations/resolve-ddl-schema.ts +26 -0
  195. package/src/core/migrations/runner.ts +11 -16
  196. package/src/core/migrations/verify-postgres-namespaces.ts +45 -31
  197. package/src/core/namespace-ids.ts +3 -0
  198. package/src/core/postgres-contract-serializer.ts +46 -71
  199. package/src/core/postgres-contract-view.ts +48 -0
  200. package/src/core/postgres-native-enum.ts +61 -0
  201. package/src/core/postgres-rls-enablement.ts +34 -0
  202. package/src/core/postgres-rls-policy.ts +64 -0
  203. package/src/core/postgres-role.ts +59 -0
  204. package/src/core/postgres-schema-verifier.ts +10 -7
  205. package/src/core/postgres-schema.ts +85 -15
  206. package/src/core/postgres-validators.ts +34 -0
  207. package/src/core/psl-infer/infer-psl-contract.ts +1290 -0
  208. package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
  209. package/src/core/psl-infer/postgres-type-map.ts +129 -0
  210. package/src/core/rls/canonicalize.ts +65 -0
  211. package/src/core/rls/wire-name.ts +33 -0
  212. package/src/core/schema-ir/node-storage-coordinate.ts +26 -0
  213. package/src/core/schema-ir/postgres-database-schema-node.ts +61 -0
  214. package/src/core/schema-ir/postgres-namespace-schema-node.ts +70 -0
  215. package/src/core/schema-ir/postgres-native-enum-schema-node.ts +83 -0
  216. package/src/core/schema-ir/postgres-policy-schema-node.ts +100 -0
  217. package/src/core/schema-ir/postgres-role-schema-node.ts +65 -0
  218. package/src/core/schema-ir/postgres-table-schema-node.ts +140 -0
  219. package/src/core/schema-ir/schema-node-kinds.ts +122 -0
  220. package/src/core/sql-utils.ts +15 -2
  221. package/src/exports/codecs.ts +5 -0
  222. package/src/exports/contract-free.ts +11 -1
  223. package/src/exports/control.ts +27 -33
  224. package/src/exports/ddl.ts +8 -0
  225. package/src/exports/diff-database-schema.ts +7 -0
  226. package/src/exports/issue-planner.ts +1 -1
  227. package/src/exports/migration.ts +1 -0
  228. package/src/exports/op-factory-call.ts +9 -0
  229. package/src/exports/planner-ddl-builders.ts +0 -2
  230. package/src/exports/planner-identity-values.ts +4 -1
  231. package/src/exports/planner.ts +1 -0
  232. package/src/exports/rls-canonicalize.ts +12 -0
  233. package/src/exports/runtime.ts +1 -0
  234. package/src/exports/schema-ir-annotations.ts +1 -0
  235. package/src/exports/sql-utils.ts +1 -0
  236. package/src/exports/types.ts +38 -0
  237. package/dist/codec-ids-BvytN2P8.mjs.map +0 -1
  238. package/dist/codec-ids-CnXu9Qy3.d.mts.map +0 -1
  239. package/dist/codec-types-DHCkwPKE.d.mts.map +0 -1
  240. package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
  241. package/dist/ddl-QDyOSeLc.mjs.map +0 -1
  242. package/dist/default-normalizer-DyyCHQWs.mjs +0 -131
  243. package/dist/default-normalizer-DyyCHQWs.mjs.map +0 -1
  244. package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
  245. package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
  246. package/dist/errors-CUk87ByX.mjs +0 -33
  247. package/dist/errors-CUk87ByX.mjs.map +0 -1
  248. package/dist/issue-planner-DL6g3CmE.mjs +0 -824
  249. package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
  250. package/dist/native-type-normalizer-Bc9XJzWC.mjs +0 -38
  251. package/dist/native-type-normalizer-Bc9XJzWC.mjs.map +0 -1
  252. package/dist/nodes-Bbhs2rwj.mjs +0 -76
  253. package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
  254. package/dist/nodes-pLeLgdis.d.mts +0 -67
  255. package/dist/nodes-pLeLgdis.d.mts.map +0 -1
  256. package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
  257. package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
  258. package/dist/planner-Bs_baQax.mjs +0 -324
  259. package/dist/planner-Bs_baQax.mjs.map +0 -1
  260. package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
  261. package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
  262. package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
  263. package/dist/postgres-migration-B5jKrXv3.mjs +0 -145
  264. package/dist/postgres-migration-B5jKrXv3.mjs.map +0 -1
  265. package/dist/postgres-migration-Y4YBJqkS.d.mts.map +0 -1
  266. package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
  267. package/dist/render-typescript-KMgosran.mjs.map +0 -1
  268. package/dist/types.d.mts.map +0 -1
  269. package/src/core/postgres-enum-type-schema.ts +0 -17
@@ -3,6 +3,7 @@ import {
3
3
  DdlNode,
4
4
  type DdlTableConstraint,
5
5
  } from '@prisma-next/sql-relational-core/ast';
6
+ import type { RlsPolicyOperation } from '../rls/canonicalize';
6
7
 
7
8
  // ---------------------------------------------------------------------------
8
9
  // AlterTableAction — nested polymorphic hierarchy
@@ -10,6 +11,7 @@ import {
10
11
 
11
12
  export interface AlterTableActionVisitor<R> {
12
13
  addColumn(action: AddColumnAction): R;
14
+ dropDefault(action: DropDefaultAction): R;
13
15
  }
14
16
 
15
17
  export abstract class AlterTableAction {
@@ -32,7 +34,31 @@ export class AddColumnAction extends AlterTableAction {
32
34
  }
33
35
  }
34
36
 
35
- export type AnyAlterTableAction = AddColumnAction;
37
+ export class DropDefaultAction extends AlterTableAction {
38
+ readonly kind = 'drop-default' as const;
39
+ readonly columnName: string;
40
+
41
+ constructor(columnName: string) {
42
+ super();
43
+ this.columnName = columnName;
44
+ Object.freeze(this);
45
+ }
46
+
47
+ override accept<R>(visitor: AlterTableActionVisitor<R>): R {
48
+ return visitor.dropDefault(this);
49
+ }
50
+ }
51
+
52
+ /**
53
+ * The set of ALTER TABLE subactions currently expressible as typed DDL.
54
+ *
55
+ * The remaining actions — SetDefault, SetNotNull, DropNotNull,
56
+ * AlterColumnType — are still emitted as raw SQL by `operations/columns.ts`
57
+ * and join this union as they are converted to typed DDL. Until then it is
58
+ * intentionally partial: only the ALTER subactions used by the
59
+ * already-converted ops (AddColumn, DropDefault) appear here.
60
+ */
61
+ export type AnyAlterTableAction = AddColumnAction | DropDefaultAction;
36
62
 
37
63
  // ---------------------------------------------------------------------------
38
64
  // Top-level DDL visitor
@@ -41,7 +67,13 @@ export type AnyAlterTableAction = AddColumnAction;
41
67
  export interface PostgresDdlVisitor<R> {
42
68
  createTable(node: PostgresCreateTable): R;
43
69
  createSchema(node: PostgresCreateSchema): R;
70
+ createType(node: PostgresCreateType): R;
71
+ dropType(node: PostgresDropType): R;
44
72
  alterTable(node: PostgresAlterTable): R;
73
+ createPolicy(node: PostgresCreatePolicy): R;
74
+ dropPolicy(node: PostgresDropPolicy): R;
75
+ alterPolicyRename(node: PostgresAlterPolicyRename): R;
76
+ disableRowLevelSecurity(node: PostgresDisableRowLevelSecurity): R;
45
77
  }
46
78
 
47
79
  export abstract class PostgresDdlNode extends DdlNode {
@@ -104,6 +136,46 @@ export class PostgresCreateSchema extends PostgresDdlNode {
104
136
  }
105
137
  }
106
138
 
139
+ export class PostgresCreateType extends PostgresDdlNode {
140
+ readonly kind = 'create-type' as const;
141
+ readonly schema: string | undefined;
142
+ readonly name: string;
143
+ readonly values: ReadonlyArray<string>;
144
+
145
+ constructor(options: {
146
+ readonly schema?: string;
147
+ readonly name: string;
148
+ readonly values: readonly string[];
149
+ }) {
150
+ super();
151
+ this.schema = options.schema;
152
+ this.name = options.name;
153
+ this.values = Object.freeze([...options.values]);
154
+ this.freeze();
155
+ }
156
+
157
+ override accept<R>(visitor: PostgresDdlVisitor<R>): R {
158
+ return visitor.createType(this);
159
+ }
160
+ }
161
+
162
+ export class PostgresDropType extends PostgresDdlNode {
163
+ readonly kind = 'drop-type' as const;
164
+ readonly schema: string | undefined;
165
+ readonly name: string;
166
+
167
+ constructor(options: { readonly schema?: string; readonly name: string }) {
168
+ super();
169
+ this.schema = options.schema;
170
+ this.name = options.name;
171
+ this.freeze();
172
+ }
173
+
174
+ override accept<R>(visitor: PostgresDdlVisitor<R>): R {
175
+ return visitor.dropType(this);
176
+ }
177
+ }
178
+
107
179
  export class PostgresAlterTable extends PostgresDdlNode {
108
180
  readonly kind = 'alter-table' as const;
109
181
  readonly table: string;
@@ -127,4 +199,115 @@ export class PostgresAlterTable extends PostgresDdlNode {
127
199
  }
128
200
  }
129
201
 
130
- export type AnyPostgresDdlNode = PostgresCreateTable | PostgresCreateSchema | PostgresAlterTable;
202
+ export type { RlsPolicyOperation };
203
+
204
+ export class PostgresCreatePolicy extends PostgresDdlNode {
205
+ readonly kind = 'create-policy' as const;
206
+ readonly schema: string;
207
+ readonly table: string;
208
+ readonly name: string;
209
+ readonly permissive: boolean;
210
+ readonly operation: RlsPolicyOperation;
211
+ readonly roles: ReadonlyArray<string>;
212
+ readonly using: string | undefined;
213
+ readonly withCheck: string | undefined;
214
+
215
+ constructor(options: {
216
+ readonly schema: string;
217
+ readonly table: string;
218
+ readonly name: string;
219
+ readonly permissive: boolean;
220
+ readonly operation: RlsPolicyOperation;
221
+ readonly roles: readonly string[];
222
+ readonly using?: string;
223
+ readonly withCheck?: string;
224
+ }) {
225
+ super();
226
+ this.schema = options.schema;
227
+ this.table = options.table;
228
+ this.name = options.name;
229
+ this.permissive = options.permissive;
230
+ this.operation = options.operation;
231
+ this.roles = Object.freeze([...options.roles]);
232
+ this.using = options.using;
233
+ this.withCheck = options.withCheck;
234
+ this.freeze();
235
+ }
236
+
237
+ override accept<R>(visitor: PostgresDdlVisitor<R>): R {
238
+ return visitor.createPolicy(this);
239
+ }
240
+ }
241
+
242
+ export class PostgresDropPolicy extends PostgresDdlNode {
243
+ readonly kind = 'drop-policy' as const;
244
+ readonly schema: string;
245
+ readonly table: string;
246
+ readonly name: string;
247
+
248
+ constructor(options: { readonly schema: string; readonly table: string; readonly name: string }) {
249
+ super();
250
+ this.schema = options.schema;
251
+ this.table = options.table;
252
+ this.name = options.name;
253
+ this.freeze();
254
+ }
255
+
256
+ override accept<R>(visitor: PostgresDdlVisitor<R>): R {
257
+ return visitor.dropPolicy(this);
258
+ }
259
+ }
260
+
261
+ export class PostgresAlterPolicyRename extends PostgresDdlNode {
262
+ readonly kind = 'alter-policy-rename' as const;
263
+ readonly schema: string;
264
+ readonly table: string;
265
+ readonly name: string;
266
+ readonly newName: string;
267
+
268
+ constructor(options: {
269
+ readonly schema: string;
270
+ readonly table: string;
271
+ readonly name: string;
272
+ readonly newName: string;
273
+ }) {
274
+ super();
275
+ this.schema = options.schema;
276
+ this.table = options.table;
277
+ this.name = options.name;
278
+ this.newName = options.newName;
279
+ this.freeze();
280
+ }
281
+
282
+ override accept<R>(visitor: PostgresDdlVisitor<R>): R {
283
+ return visitor.alterPolicyRename(this);
284
+ }
285
+ }
286
+
287
+ export class PostgresDisableRowLevelSecurity extends PostgresDdlNode {
288
+ readonly kind = 'disable-row-level-security' as const;
289
+ readonly schema: string;
290
+ readonly table: string;
291
+
292
+ constructor(options: { readonly schema: string; readonly table: string }) {
293
+ super();
294
+ this.schema = options.schema;
295
+ this.table = options.table;
296
+ this.freeze();
297
+ }
298
+
299
+ override accept<R>(visitor: PostgresDdlVisitor<R>): R {
300
+ return visitor.disableRowLevelSecurity(this);
301
+ }
302
+ }
303
+
304
+ export type AnyPostgresDdlNode =
305
+ | PostgresCreateTable
306
+ | PostgresCreateSchema
307
+ | PostgresCreateType
308
+ | PostgresDropType
309
+ | PostgresAlterTable
310
+ | PostgresCreatePolicy
311
+ | PostgresDropPolicy
312
+ | PostgresAlterPolicyRename
313
+ | PostgresDisableRowLevelSecurity;
@@ -1,4 +1,4 @@
1
- import type { ColumnDefault } from '@prisma-next/contract/types';
1
+ import type { ColumnDefault, JsonValue } from '@prisma-next/contract/types';
2
2
 
3
3
  /**
4
4
  * Pre-compiled regex patterns for performance.
@@ -18,6 +18,13 @@ const FALSE_PATTERN = /^false$/i;
18
18
  const NUMERIC_PATTERN = /^-?\d+(\.\d+)?$/;
19
19
  const STRING_LITERAL_PATTERN = /^'((?:[^']|'')*)'(?:::(?:"[^"]+"|[\w\s]+)(?:\(\d+\))?)?$/;
20
20
 
21
+ /**
22
+ * Matches a Postgres array literal default of the form `'{...}'::elemtype[]`.
23
+ * The literal body is captured in group 1; the cast (including `[]`) is optional.
24
+ * Examples: `'{}'::text[]`, `'{1,2}'::integer[]`, `'{}'`
25
+ */
26
+ const ARRAY_LITERAL_PATTERN = /^'(\{.*\})'(?:::.+\[\])?$/;
27
+
21
28
  /**
22
29
  * Returns the canonical expression for a timestamp default function, or undefined
23
30
  * if the expression is not a recognized timestamp default.
@@ -51,6 +58,108 @@ function canonicalizeTimestampDefault(expr: string): string | undefined {
51
58
  return undefined;
52
59
  }
53
60
 
61
+ type ArrayElementToken = { readonly value: string; readonly quoted: boolean };
62
+
63
+ /**
64
+ * Splits a Postgres array literal body (without the enclosing braces) into its
65
+ * element tokens, honouring quoting. A comma only separates elements when it is
66
+ * outside double quotes; inside a quoted element a doubled quote (`""`) or a
67
+ * backslash-escaped quote (`\"`) is a literal quote, and a backslash escapes the
68
+ * next character. Returns undefined if the body is malformed (e.g. an unbalanced
69
+ * quote).
70
+ */
71
+ function splitArrayElements(inner: string): readonly ArrayElementToken[] | undefined {
72
+ const tokens: ArrayElementToken[] = [];
73
+ let current = '';
74
+ let inQuotes = false;
75
+ let quoted = false;
76
+
77
+ for (let i = 0; i < inner.length; i++) {
78
+ const char = inner[i];
79
+ if (inQuotes) {
80
+ if (char === '\\') {
81
+ const next = inner[i + 1];
82
+ if (next === undefined) return undefined;
83
+ current += next;
84
+ i++;
85
+ continue;
86
+ }
87
+ if (char === '"') {
88
+ if (inner[i + 1] === '"') {
89
+ current += '"';
90
+ i++;
91
+ continue;
92
+ }
93
+ inQuotes = false;
94
+ continue;
95
+ }
96
+ current += char;
97
+ continue;
98
+ }
99
+ if (char === '"') {
100
+ inQuotes = true;
101
+ quoted = true;
102
+ continue;
103
+ }
104
+ if (char === ',') {
105
+ tokens.push({ value: current, quoted });
106
+ current = '';
107
+ quoted = false;
108
+ continue;
109
+ }
110
+ current += char;
111
+ }
112
+
113
+ if (inQuotes) return undefined;
114
+ tokens.push({ value: current, quoted });
115
+ return tokens;
116
+ }
117
+
118
+ /**
119
+ * Parses a Postgres array literal body (`{...}`) into a JS array of primitives.
120
+ * Returns undefined if the body cannot be reliably parsed.
121
+ *
122
+ * Handles:
123
+ * - `{}` → `[]`
124
+ * - `{elem1,elem2,...}` → `[elem1, elem2, ...]` with numeric and string element coercion
125
+ * - quoted elements that contain commas, doubled/escaped quotes, and the literal
126
+ * strings `NULL`/`true`/`false` (a quoted token is always a string)
127
+ */
128
+ function parseArrayLiteralBody(body: string): readonly JsonValue[] | undefined {
129
+ const inner = body.slice(1, -1).trim();
130
+ if (inner === '') return [];
131
+ const tokens = splitArrayElements(inner);
132
+ if (tokens === undefined) return undefined;
133
+ const result: JsonValue[] = [];
134
+ for (const token of tokens) {
135
+ if (token.quoted) {
136
+ // A quoted token is always a string — `"NULL"`, `"true"`, `"1"` are the
137
+ // literal text, never the keyword/number.
138
+ result.push(token.value);
139
+ continue;
140
+ }
141
+ const el = token.value.trim();
142
+ if (el.toUpperCase() === 'NULL') {
143
+ result.push(null);
144
+ continue;
145
+ }
146
+ if (el === 'true') {
147
+ result.push(true);
148
+ continue;
149
+ }
150
+ if (el === 'false') {
151
+ result.push(false);
152
+ continue;
153
+ }
154
+ if (NUMERIC_PATTERN.test(el)) {
155
+ result.push(Number(el));
156
+ continue;
157
+ }
158
+ return undefined;
159
+ }
160
+ return result;
161
+ }
162
+
54
163
  /**
55
164
  * Parses a raw Postgres column default expression into a normalized ColumnDefault.
56
165
  * This enables semantic comparison between contract defaults and introspected schema defaults.
@@ -59,7 +168,7 @@ function canonicalizeTimestampDefault(expr: string): string | undefined {
59
168
  * keeping the introspection layer focused on faithful data capture.
60
169
  *
61
170
  * @param rawDefault - Raw default expression from information_schema.columns.column_default
62
- * @param nativeType - Native column type, used for type-aware parsing (bigint tagging, JSON detection)
171
+ * @param nativeType - Native column type, used for type-aware parsing (array, bigint, JSON)
63
172
  * @returns Normalized ColumnDefault or undefined if the expression cannot be parsed
64
173
  */
65
174
  export function parsePostgresDefault(
@@ -69,11 +178,22 @@ export function parsePostgresDefault(
69
178
  const trimmed = rawDefault.trim();
70
179
  const normalizedType = nativeType?.toLowerCase();
71
180
  const isBigInt = normalizedType === 'bigint' || normalizedType === 'int8';
181
+ const isArrayType = normalizedType?.endsWith('[]') ?? false;
72
182
 
73
183
  if (NEXTVAL_PATTERN.test(trimmed)) {
74
184
  return { kind: 'function', expression: 'autoincrement()' };
75
185
  }
76
186
 
187
+ if (isArrayType) {
188
+ const arrayMatch = trimmed.match(ARRAY_LITERAL_PATTERN);
189
+ if (arrayMatch?.[1] !== undefined) {
190
+ const parsed = parseArrayLiteralBody(arrayMatch[1]);
191
+ if (parsed !== undefined) {
192
+ return { kind: 'literal', value: parsed };
193
+ }
194
+ }
195
+ }
196
+
77
197
  const canonicalTimestamp = canonicalizeTimestampDefault(trimmed);
78
198
  if (canonicalTimestamp) {
79
199
  return { kind: 'function', expression: canonicalTimestamp };
@@ -2,17 +2,28 @@ import type { CodecTypes } from '../exports/codec-types';
2
2
  import {
3
3
  postgresAuthoringEntityTypes,
4
4
  postgresAuthoringFieldPresets,
5
+ postgresAuthoringModelAttributes,
6
+ postgresAuthoringPslBlockDescriptors,
5
7
  postgresAuthoringTypes,
8
+ postgresLowerEntityHandles,
6
9
  } from './authoring';
10
+ import { postgresQualifyColumnType } from './codecs';
7
11
  import { postgresTargetDescriptorMetaRuntime } from './descriptor-meta-runtime';
12
+ import { DEFAULT_NAMESPACE_ID } from './namespace-ids';
13
+ import { postgresCreateNamespace } from './postgres-schema';
8
14
 
9
15
  const postgresTargetDescriptorMetaBase = {
10
16
  ...postgresTargetDescriptorMetaRuntime,
11
- defaultNamespaceId: 'public',
17
+ defaultNamespaceId: DEFAULT_NAMESPACE_ID,
12
18
  authoring: {
13
19
  type: postgresAuthoringTypes,
14
20
  field: postgresAuthoringFieldPresets,
15
21
  entityTypes: postgresAuthoringEntityTypes,
22
+ pslBlockDescriptors: postgresAuthoringPslBlockDescriptors,
23
+ modelAttributes: postgresAuthoringModelAttributes,
24
+ createNamespace: postgresCreateNamespace,
25
+ qualifyColumnType: postgresQualifyColumnType,
26
+ lowerEntityHandles: postgresLowerEntityHandles,
16
27
  },
17
28
  } as const;
18
29
 
@@ -0,0 +1,41 @@
1
+ import type { EntityKindDescriptor } from '@prisma-next/framework-components/ir';
2
+ import { PostgresNativeEnum, type PostgresNativeEnumInput } from './postgres-native-enum';
3
+ import { PostgresRlsEnablement, type PostgresRlsEnablementInput } from './postgres-rls-enablement';
4
+ import { PostgresRlsPolicy, type PostgresRlsPolicyInput } from './postgres-rls-policy';
5
+ import { PostgresRole, type PostgresRoleInput } from './postgres-role';
6
+ import {
7
+ PostgresNativeEnumSchema,
8
+ PostgresRlsEnablementSchema,
9
+ PostgresRlsPolicySchema,
10
+ PostgresRoleSchema,
11
+ } from './postgres-validators';
12
+
13
+ export const policyEntityKind: EntityKindDescriptor<PostgresRlsPolicyInput, PostgresRlsPolicy> = {
14
+ kind: 'policy',
15
+ schema: PostgresRlsPolicySchema,
16
+ construct: (input) => new PostgresRlsPolicy(input),
17
+ };
18
+
19
+ export const roleEntityKind: EntityKindDescriptor<PostgresRoleInput, PostgresRole> = {
20
+ kind: 'role',
21
+ schema: PostgresRoleSchema,
22
+ construct: (input) => new PostgresRole(input),
23
+ };
24
+
25
+ export const rlsEnablementEntityKind: EntityKindDescriptor<
26
+ PostgresRlsEnablementInput,
27
+ PostgresRlsEnablement
28
+ > = {
29
+ kind: 'rls',
30
+ schema: PostgresRlsEnablementSchema,
31
+ construct: (input) => new PostgresRlsEnablement(input),
32
+ };
33
+
34
+ export const nativeEnumEntityKind: EntityKindDescriptor<
35
+ PostgresNativeEnumInput,
36
+ PostgresNativeEnum
37
+ > = {
38
+ kind: 'native_enum',
39
+ schema: PostgresNativeEnumSchema,
40
+ construct: (input) => new PostgresNativeEnum(input),
41
+ };
@@ -1,14 +1,16 @@
1
1
  import { CliStructuredError } from '@prisma-next/errors/control';
2
2
 
3
3
  /**
4
- * A `PostgresMigration` instance method that needs the materialized control
5
- * adapter (currently only `this.dataTransform(...)`) was invoked, but the
6
- * migration was constructed without a `ControlStack`. Concrete authoring
7
- * usage always goes through the migration CLI entrypoint, which assembles
8
- * a stack from the loaded `prisma-next.config.ts`; reaching this error
9
- * means a test fixture or ad-hoc consumer instantiated `PostgresMigration`
10
- * with the no-arg form (legal for `operations` / `describe` introspection
11
- * only).
4
+ * A `PostgresMigration` operation that needs the materialized control adapter
5
+ * named by `operation` (e.g. `createTable`, `dropColumn`, `dataTransform`)
6
+ * was invoked, but the migration was constructed without a `ControlStack`.
7
+ * Concrete authoring usage always goes through the migration CLI entrypoint,
8
+ * which assembles a stack from the loaded `prisma-next.config.ts`; reaching this
9
+ * error means a test fixture or ad-hoc consumer instantiated `PostgresMigration`
10
+ * with the no-arg form (legal for `operations` / `describe` introspection only).
11
+ *
12
+ * The `operation` argument is required so every throw site names the operation
13
+ * that actually failed; a new operation cannot inherit a misattributed message.
12
14
  *
13
15
  * Distinct from `PN-MIG-2001` (placeholder not filled) and `PN-MIG-2005`
14
16
  * (data-transform query plan against wrong contract) because the missing
@@ -19,15 +21,15 @@ import { CliStructuredError } from '@prisma-next/errors/control';
19
21
  * the contract it talks about (`PostgresMigration`, the Postgres control
20
22
  * adapter, the Postgres-target stack) only exists in this package.
21
23
  */
22
- export function errorPostgresMigrationStackMissing(): CliStructuredError {
24
+ export function errorPostgresMigrationStackMissing(operation: string): CliStructuredError {
23
25
  return new CliStructuredError(
24
26
  '2007',
25
- 'PostgresMigration.dataTransform requires a control adapter',
27
+ `PostgresMigration.${operation} requires a control adapter`,
26
28
  {
27
29
  domain: 'MIG',
28
- why: 'PostgresMigration.dataTransform was invoked on an instance constructed without a ControlStack. The stored controlAdapter is undefined, so dataTransform cannot lower its query plan.',
30
+ 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.`,
29
31
  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.',
30
- meta: {},
32
+ meta: { operation },
31
33
  },
32
34
  );
33
35
  }
@@ -0,0 +1,10 @@
1
+ import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
2
+
3
+ /**
4
+ * Maps a planner schema name to the contract-free DDL builder's optional
5
+ * `schema` field: the unbound sentinel becomes `undefined` (the builder omits
6
+ * the schema qualifier), every other name passes through.
7
+ */
8
+ export function boundSchema(schemaName: string): string | undefined {
9
+ return schemaName === UNBOUND_NAMESPACE_ID ? undefined : schemaName;
10
+ }
@@ -0,0 +1,117 @@
1
+ import type { CodecControlHooks } from '@prisma-next/family-sql/control';
2
+ import type { StorageColumn } from '@prisma-next/sql-contract/types';
3
+ import type { DdlColumn } from '@prisma-next/sql-relational-core/ast';
4
+ import * as contractFree from '@prisma-next/sql-relational-core/contract-free';
5
+ import type { SqlColumnDefaultIR, SqlColumnIR } from '@prisma-next/sql-schema-ir/types';
6
+ import { blindCast } from '@prisma-next/utils/casts';
7
+ import { ifDefined } from '@prisma-next/utils/defined';
8
+ import { postgresDefaultToDdlColumnDefault } from './op-factory-call';
9
+ import { buildColumnDefaultSql, buildColumnTypeSql } from './planner-ddl-builders';
10
+ import { resolveIdentityValue } from './planner-identity-values';
11
+ import { buildExpectedFormatType } from './planner-sql-checks';
12
+
13
+ /**
14
+ * Reconstructs the `StorageColumn`-shaped fields the DDL builder functions
15
+ * (`buildColumnTypeSql`, `buildExpectedFormatType`, `resolveIdentityValue`)
16
+ * expect, from a column node's own stamped codec identity (`codecRef` /
17
+ * `codecBaseNativeType` / `codecNamedType`, Decision 5) — never the
18
+ * contract. The builders were written against `StorageColumn` and are
19
+ * unchanged here; only the shape feeding them moves from the contract to
20
+ * the node. An empty `storageTypes` catalog is passed alongside: the
21
+ * node's fields are already resolved past any `typeRef` indirection, so no
22
+ * live lookup is needed, and passing a non-empty catalog would risk a
23
+ * false `typeRef` hit against an unrelated storage type.
24
+ */
25
+ function columnLike(
26
+ column: SqlColumnIR,
27
+ ): Pick<
28
+ StorageColumn,
29
+ 'nativeType' | 'codecId' | 'nullable' | 'many' | 'typeParams' | 'typeRef' | 'default'
30
+ > {
31
+ if (column.codecRef === undefined || column.codecBaseNativeType === undefined) {
32
+ throw new Error(
33
+ `columnLike: expected column "${column.name}" carries no codec identity — the expected tree must be derived via contractToSchemaIR for planning`,
34
+ );
35
+ }
36
+ return {
37
+ nativeType: column.codecBaseNativeType,
38
+ codecId: column.codecRef.codecId,
39
+ nullable: column.nullable,
40
+ // `column.many` is unset on contract-derived columns (array-ness rides
41
+ // on the `nativeType` `[]` suffix there instead) — `codecRef.many`
42
+ // carries it. Hand-built/introspected columns set `column.many` directly.
43
+ ...ifDefined('many', column.many ?? column.codecRef.many),
44
+ ...ifDefined(
45
+ 'typeParams',
46
+ column.codecRef.typeParams !== undefined
47
+ ? blindCast<
48
+ Record<string, unknown>,
49
+ 'CodecRef.typeParams is JsonValue-shaped; the DDL builders only ever read it as the Record the contract column originally carried'
50
+ >(column.codecRef.typeParams)
51
+ : undefined,
52
+ ),
53
+ ...(column.codecNamedType ? { typeRef: '<resolved>' } : {}),
54
+ ...ifDefined('default', column.resolvedDefault),
55
+ };
56
+ }
57
+
58
+ /**
59
+ * Builds the `CREATE TABLE` / `ADD COLUMN` DDL column for an expected column
60
+ * node, resolving type rendering from the node's codec identity against the
61
+ * codec hooks the caller holds — the same builder the pre-`plan(start, end)`
62
+ * op-path called, so the output is byte-identical.
63
+ */
64
+ export function renderColumnDdl(
65
+ name: string,
66
+ column: SqlColumnIR,
67
+ codecHooks: ReadonlyMap<string, CodecControlHooks>,
68
+ ): DdlColumn {
69
+ const like = columnLike(column);
70
+ const typeSql = buildColumnTypeSql(like, codecHooks, {});
71
+ const ddlDefault = postgresDefaultToDdlColumnDefault(like.default);
72
+ return contractFree.col(name, typeSql, {
73
+ ...(!column.nullable ? { notNull: true } : {}),
74
+ ...ifDefined('default', ddlDefault),
75
+ ...ifDefined('codecRef', column.codecRef),
76
+ });
77
+ }
78
+
79
+ /**
80
+ * Builds the `ALTER COLUMN … TYPE` operands for an expected column node.
81
+ */
82
+ export function renderColumnAlterType(
83
+ column: SqlColumnIR,
84
+ codecHooks: ReadonlyMap<string, CodecControlHooks>,
85
+ ): { readonly qualifiedTargetType: string; readonly formatTypeExpected: string } {
86
+ const like = columnLike(column);
87
+ return {
88
+ qualifiedTargetType: buildColumnTypeSql(like, codecHooks, {}, false),
89
+ formatTypeExpected: buildExpectedFormatType(like, codecHooks, {}),
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Resolves the identity value (monoid neutral element) SQL literal used as
95
+ * the temporary default when adding a NOT-NULL column with no contract
96
+ * default (`notNullAddColumnCallStrategy`'s shared-temp-default backfill).
97
+ * `null` when the column's type has no built-in/codec-provided identity
98
+ * value.
99
+ */
100
+ export function resolveColumnTemporaryDefault(
101
+ column: SqlColumnIR,
102
+ codecHooks: ReadonlyMap<string, CodecControlHooks>,
103
+ ): string | null {
104
+ return resolveIdentityValue(columnLike(column), codecHooks, {});
105
+ }
106
+
107
+ /**
108
+ * The column's `SET DEFAULT` clause SQL, resolved from a column-default
109
+ * diff node. `''` when the node carries no resolved default.
110
+ */
111
+ export function renderColumnDefaultSql(defaultNode: SqlColumnDefaultIR): string {
112
+ if (defaultNode.resolved === undefined) return '';
113
+ return buildColumnDefaultSql(defaultNode.resolved, {
114
+ nativeType: defaultNode.nativeTypeContext ?? '',
115
+ ...ifDefined('many', defaultNode.many),
116
+ });
117
+ }