@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
@@ -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
+ }
@@ -0,0 +1,160 @@
1
+ import type { ContractToSchemaIROptions } from '@prisma-next/family-sql/control';
2
+ import { contractNamespaceToSchemaIR } from '@prisma-next/family-sql/control';
3
+ import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
4
+ import { SqlForeignKeyIR } from '@prisma-next/sql-schema-ir/types';
5
+ import { ifDefined } from '@prisma-next/utils/defined';
6
+ import type { PostgresRlsPolicy } from '../postgres-rls-policy';
7
+ import type { PostgresContract } from '../postgres-schema';
8
+ import { isPostgresSchema } from '../postgres-schema';
9
+ import { PostgresDatabaseSchemaNode } from '../schema-ir/postgres-database-schema-node';
10
+ import { PostgresNamespaceSchemaNode } from '../schema-ir/postgres-namespace-schema-node';
11
+ import { PostgresPolicySchemaNode } from '../schema-ir/postgres-policy-schema-node';
12
+ import { PostgresRoleSchemaNode } from '../schema-ir/postgres-role-schema-node';
13
+ import { PostgresTableSchemaNode } from '../schema-ir/postgres-table-schema-node';
14
+ import { resolveDdlSchemaForNamespaceStorage } from './resolve-ddl-schema';
15
+
16
+ function toPolicyNode(policy: PostgresRlsPolicy, namespaceId: string): PostgresPolicySchemaNode {
17
+ return new PostgresPolicySchemaNode({
18
+ name: policy.name,
19
+ prefix: policy.prefix,
20
+ tableName: policy.tableName,
21
+ namespaceId,
22
+ operation: policy.operation,
23
+ roles: [...policy.roles],
24
+ ...ifDefined('using', policy.using),
25
+ ...ifDefined('withCheck', policy.withCheck),
26
+ permissive: policy.permissive,
27
+ });
28
+ }
29
+
30
+ /**
31
+ * Projects a Postgres contract into the expected schema-diff tree: a
32
+ * `PostgresDatabaseSchemaNode` root holding one `PostgresNamespaceSchemaNode`
33
+ * per Postgres namespace, each holding its `PostgresTableSchemaNode`s with
34
+ * their `PostgresPolicySchemaNode`s, plus the database roles on the root.
35
+ *
36
+ * Not a duplicate of the family's `contractToSchemaIR`: that builds a flat,
37
+ * single `{ tables }` map (and throws on cross-namespace name collisions, with
38
+ * no RLS/role concept) for SQLite's single-schema world. This is the
39
+ * Postgres-specific *tree* shape — multi-schema, RLS-policy-aware, role-aware.
40
+ * It reuses the family's per-namespace table conversion (`contractNamespaceToSchemaIR`)
41
+ * for column/FK/index building and only adds the Postgres tree/policy/role shape.
42
+ *
43
+ * Tables are grouped by their owning namespace (resolved DDL schema name) so
44
+ * the tree mirrors Postgres's object hierarchy. The DDL schema name is
45
+ * resolved once per namespace.
46
+ *
47
+ * A policy that references a table absent from its namespace is a malformed
48
+ * contract — the loop throws rather than fabricating a stub table.
49
+ */
50
+ export function contractToPostgresDatabaseSchemaNode(
51
+ contract: PostgresContract | null,
52
+ options: ContractToSchemaIROptions,
53
+ ): PostgresDatabaseSchemaNode {
54
+ if (contract === null) {
55
+ return new PostgresDatabaseSchemaNode({
56
+ namespaces: {},
57
+ roles: [],
58
+ existingSchemas: [],
59
+ pgVersion: '',
60
+ });
61
+ }
62
+
63
+ const namespaces: Record<string, PostgresNamespaceSchemaNode> = {};
64
+ const roles: PostgresRoleSchemaNode[] = [];
65
+ const ownedSchemas: string[] = [];
66
+
67
+ for (const ns of Object.values(contract.storage.namespaces)) {
68
+ if (!isPostgresSchema(ns)) continue;
69
+ const ddlSchema = resolveDdlSchemaForNamespaceStorage(contract.storage, ns.id);
70
+ ownedSchemas.push(ddlSchema);
71
+
72
+ // Convert only THIS namespace's tables (passing the full storage for
73
+ // type/value-set/enum resolution that spans namespaces), so the same table
74
+ // name can exist in two schemas without colliding in a bare-keyed record.
75
+ const sqlTables = contractNamespaceToSchemaIR(contract.storage, ns.id, options).tables;
76
+
77
+ const policiesByTable = new Map<string, PostgresPolicySchemaNode[]>();
78
+ for (const policy of Object.values(ns.policy)) {
79
+ const list = policiesByTable.get(policy.tableName) ?? [];
80
+ list.push(toPolicyNode(policy, ddlSchema));
81
+ policiesByTable.set(policy.tableName, list);
82
+ }
83
+
84
+ const tables: Record<string, PostgresTableSchemaNode> = {};
85
+ for (const tableName of Object.keys(ns.table)) {
86
+ const sqlTable = sqlTables[tableName];
87
+ if (sqlTable === undefined) continue;
88
+ // The family conversion stamps `referencedSchema` only for bound FK
89
+ // targets; an absent value means the FK targets the unbound namespace.
90
+ // Postgres restores its own coordinate for that slot (the unbound
91
+ // singleton's id) so the raw coordinate keeps qualifying REFERENCES
92
+ // clauses, and resolves the real live DDL schema — introspected FKs
93
+ // already carry the live schema, so this is what lets an expected FK
94
+ // pair (by diff-node id) with its introspected counterpart.
95
+ const foreignKeys = sqlTable.foreignKeys.map(
96
+ (fk) =>
97
+ new SqlForeignKeyIR({
98
+ columns: fk.columns,
99
+ referencedTable: fk.referencedTable,
100
+ referencedColumns: fk.referencedColumns,
101
+ referencedSchema: fk.referencedSchema ?? UNBOUND_NAMESPACE_ID,
102
+ ...ifDefined('name', fk.name),
103
+ ...ifDefined('onDelete', fk.onDelete),
104
+ ...ifDefined('onUpdate', fk.onUpdate),
105
+ ...ifDefined('annotations', fk.annotations),
106
+ resolvedReferencedNamespace: resolveDdlSchemaForNamespaceStorage(
107
+ contract.storage,
108
+ fk.referencedSchema ?? UNBOUND_NAMESPACE_ID,
109
+ ),
110
+ }),
111
+ );
112
+ tables[tableName] = new PostgresTableSchemaNode({
113
+ name: sqlTable.name,
114
+ columns: sqlTable.columns,
115
+ foreignKeys,
116
+ uniques: sqlTable.uniques,
117
+ indexes: sqlTable.indexes,
118
+ ...ifDefined('primaryKey', sqlTable.primaryKey),
119
+ ...ifDefined('annotations', sqlTable.annotations),
120
+ ...ifDefined('checks', sqlTable.checks),
121
+ policies: policiesByTable.get(tableName) ?? [],
122
+ // Marker-driven, never derived from the policy set: the `rls` entry
123
+ // is the single authored source of enablement.
124
+ rlsEnabled: Object.hasOwn(ns.rls, tableName),
125
+ });
126
+ }
127
+
128
+ for (const [tableName, tablePolicies] of policiesByTable) {
129
+ if (!(tableName in tables)) {
130
+ const policyName = tablePolicies[0]?.name ?? '(unknown)';
131
+ throw new Error(
132
+ `contract-to-postgres-database-schema-node: policy "${policyName}" references table "${tableName}" not present in namespace "${ddlSchema}"`,
133
+ );
134
+ }
135
+ if (!Object.hasOwn(ns.rls, tableName)) {
136
+ const policyPrefix = tablePolicies[0]?.prefix ?? '(unknown)';
137
+ throw new Error(
138
+ `contract-to-postgres-database-schema-node: policy "${policyPrefix}" targets table "${tableName}" in namespace "${ddlSchema}", which is not RLS-controlled. Mark the model with @@rls (entries.rls["${tableName}"]) or remove the policy.`,
139
+ );
140
+ }
141
+ }
142
+
143
+ namespaces[ddlSchema] = new PostgresNamespaceSchemaNode({
144
+ schemaName: ddlSchema,
145
+ tables,
146
+ nativeEnumTypeNames: [],
147
+ });
148
+
149
+ for (const role of Object.values(ns.role)) {
150
+ roles.push(new PostgresRoleSchemaNode({ name: role.name, namespaceId: role.namespaceId }));
151
+ }
152
+ }
153
+
154
+ return new PostgresDatabaseSchemaNode({
155
+ namespaces,
156
+ roles,
157
+ existingSchemas: ownedSchemas,
158
+ pgVersion: '',
159
+ });
160
+ }
@@ -1,10 +1,17 @@
1
1
  import type { Contract } from '@prisma-next/contract/types';
2
2
  import type { ControlPolicySubject } from '@prisma-next/family-sql/control';
3
- import type { SchemaIssue } from '@prisma-next/framework-components/control';
3
+ import type { SchemaDiffIssue } from '@prisma-next/framework-components/control';
4
4
  import { entityAt, UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
5
5
  import type { SqlStorage, StorageTable } from '@prisma-next/sql-contract/types';
6
+ import { blindCast } from '@prisma-next/utils/casts';
6
7
  import { ifDefined } from '@prisma-next/utils/defined';
8
+ import { type PostgresRole, ROLE_DEFAULT_CONTROL_POLICY } from '../postgres-role';
7
9
  import { isPostgresSchema } from '../postgres-schema';
10
+ import type { PostgresNamespaceSchemaNode } from '../schema-ir/postgres-namespace-schema-node';
11
+ import { PostgresTableSchemaNode } from '../schema-ir/postgres-table-schema-node';
12
+ import type { SqlSchemaDiffNode } from '../schema-ir/schema-node-kinds';
13
+ import { PostgresSchemaNodeKind } from '../schema-ir/schema-node-kinds';
14
+ import { issueColumnName } from './issue-planner';
8
15
  import type { PostgresOpFactoryCall } from './op-factory-call';
9
16
 
10
17
  /**
@@ -21,6 +28,8 @@ import type { PostgresOpFactoryCall } from './op-factory-call';
21
28
  const OBJECT_CREATION_FACTORIES: ReadonlySet<string> = new Set<string>([
22
29
  'createTable',
23
30
  'createSchema',
31
+ 'createRlsPolicy',
32
+ 'enableRowLevelSecurity',
24
33
  ]);
25
34
 
26
35
  function createsNewTopLevelObject(call: PostgresOpFactoryCall): boolean {
@@ -54,7 +63,7 @@ function resolveNamespaceIdForTable(
54
63
  return UNBOUND_NAMESPACE_ID;
55
64
  }
56
65
 
57
- function resolveNamespaceIdForDdlSchema(
66
+ export function resolveNamespaceIdForDdlSchema(
58
67
  contract: Contract<SqlStorage>,
59
68
  ddlSchemaName: string,
60
69
  ): string {
@@ -141,64 +150,137 @@ export function resolvePostgresCallControlPolicySubject(
141
150
  }
142
151
 
143
152
  /**
144
- * Issue kinds that describe the absence of a whole, top-level Postgres
145
- * object — the same kinds `createsNewTopLevelObject` recognises for calls.
146
- * Used by {@link resolvePostgresIssueCreationFactoryName} to decide whether
147
- * a `tolerated` subject permits the issue to flow into the planner
153
+ * Node kinds that describe the absence of a whole, top-level Postgres
154
+ * object — the same objects `createsNewTopLevelObject` recognises for calls.
155
+ * Used by {@link resolvePostgresNodeIssueCreationFactoryName} to decide
156
+ * whether a `tolerated` subject permits the issue to flow into the planner
148
157
  * (create-if-absent) and to seed the suppressed-subject warning's
149
- * `factoryName` when the planner is skipped.
158
+ * `factoryName` when the planner is skipped. RLS policy creation is not
159
+ * listed here — policy issues never reach this issue-based partition (they
160
+ * are routed to `planPostgresSchemaDiff` and gated via the call-based
161
+ * {@link resolvePostgresCallControlPolicySubject} instead).
150
162
  */
151
- const POSTGRES_ISSUE_CREATION_FACTORY: Readonly<Record<string, string>> = Object.freeze({
152
- missing_schema: 'createSchema',
153
- missing_table: 'createTable',
163
+ const POSTGRES_NODE_CREATION_FACTORY: Readonly<Record<string, string>> = Object.freeze({
164
+ [PostgresSchemaNodeKind.namespace]: 'createSchema',
165
+ [PostgresSchemaNodeKind.table]: 'createTable',
154
166
  });
155
167
 
156
- export function resolvePostgresIssueCreationFactoryName(issue: SchemaIssue): string | undefined {
157
- return POSTGRES_ISSUE_CREATION_FACTORY[issue.kind];
168
+ /**
169
+ * A table `not-equal` issue whose `rlsEnabled` flips OFF→ON (expected on,
170
+ * actual off) is enablement toward `ENABLE ROW LEVEL SECURITY` —
171
+ * creation-class per `OBJECT_CREATION_FACTORIES` ('enableRowLevelSecurity'
172
+ * is a member): enabling RLS establishes the fail-closed guard the declared
173
+ * policy set attaches to, the same grant `tolerated` extends to creating the
174
+ * policies themselves. The opposite direction (`DISABLE`) is a modification
175
+ * and stays managed-only. Keying on the actual delta (not just the expected
176
+ * bit) keeps this correct if a second table attribute ever joins
177
+ * `isEqualTo`: a not-equal with no `rlsEnabled` delta is not enablement, so
178
+ * it is not admitted as creation-class here.
179
+ */
180
+ function isEnablementCreationIssue(issue: SchemaDiffIssue<SqlSchemaDiffNode>): boolean {
181
+ if (issue.reason !== 'not-equal') return false;
182
+ const { expected, actual } = issue;
183
+ return (
184
+ expected !== undefined &&
185
+ actual !== undefined &&
186
+ PostgresTableSchemaNode.is(expected) &&
187
+ PostgresTableSchemaNode.is(actual) &&
188
+ expected.rlsEnabled === true &&
189
+ actual.rlsEnabled === false
190
+ );
191
+ }
192
+
193
+ export function resolvePostgresNodeIssueCreationFactoryName(
194
+ issue: SchemaDiffIssue<SqlSchemaDiffNode>,
195
+ ): string | undefined {
196
+ if (isEnablementCreationIssue(issue)) {
197
+ return 'enableRowLevelSecurity';
198
+ }
199
+ if (issue.reason !== 'not-found') return undefined;
200
+ const node = issue.expected ?? issue.actual;
201
+ if (node === undefined) return undefined;
202
+ return POSTGRES_NODE_CREATION_FACTORY[node.nodeKind];
158
203
  }
159
204
 
160
205
  /**
161
- * Resolve the control-policy subject coordinate for a single
162
- * {@link SchemaIssue}. Mirrors the resolution `resolvePostgresCallControlPolicySubject`
163
- * performs for a generated DDL call, but works *off the issue* — so the
164
- * planner can partition issues by effective policy before the diff engine
165
- * runs. `createsNewObject` is derived from the issue's kind: schema/table/
166
- * type-missing issues describe a brand-new top-level object; everything else
167
- * touches an existing object.
206
+ * Resolve the control-policy subject coordinate for a single node-typed
207
+ * {@link SchemaDiffIssue}. Mirrors the resolution
208
+ * `resolvePostgresCallControlPolicySubject` performs for a generated DDL
209
+ * call, but works *off the issue* so the planner can partition issues by
210
+ * effective policy before the diff engine runs. `createsNewObject` is
211
+ * derived from the node kind + reason: a `not-found` schema/table describes
212
+ * a brand-new top-level object; everything else touches an existing object.
168
213
  *
169
- * An `extra_table` issue carries no contract namespace coordinate (the table
170
- * isn't in any contract namespace), so the subject's `namespaceId` falls
171
- * back to {@link UNBOUND_NAMESPACE_ID}; the call-side resolver does the same
172
- * for the `DropTableCall` it produces.
214
+ * A `not-expected` table carries no contract namespace coordinate (the live
215
+ * table isn't claimed by any contract namespace), so the subject's
216
+ * `namespaceId` falls back to {@link UNBOUND_NAMESPACE_ID} via
217
+ * `resolveNamespaceIdForTable`'s own fallback — the call-side resolver does
218
+ * the same for the `DropTableCall` it produces.
219
+ *
220
+ * A role node resolves against the `PostgresRole` contract entity at that
221
+ * role's name (roles are root-level diff subjects, so the name is the
222
+ * second path segment after the tree root). A `not-found` role is declared,
223
+ * so the entity is always found and its `control` read directly — which is
224
+ * always {@link ROLE_DEFAULT_CONTROL_POLICY} today, since no authoring
225
+ * surface sets it otherwise. A `not-expected` role has no contract entity
226
+ * (an undeclared live role, by definition), so the subject falls back to
227
+ * the same default — roles are referenced but never owned, so an
228
+ * undeclared role gets exactly the same governance as a declared one.
229
+ * Never creates a new object: role provisioning is a non-goal.
173
230
  */
174
- export function resolvePostgresIssueControlPolicySubject(
175
- issue: SchemaIssue,
231
+ export function resolvePostgresNodeIssueControlPolicySubject(
232
+ issue: SchemaDiffIssue<SqlSchemaDiffNode>,
176
233
  contract: Contract<SqlStorage>,
177
234
  ): ControlPolicySubject | undefined {
178
- const createsNewObject = POSTGRES_ISSUE_CREATION_FACTORY[issue.kind] !== undefined;
235
+ const node = issue.expected ?? issue.actual;
236
+ if (node === undefined) return undefined;
179
237
 
180
- if (issue.kind === 'missing_schema' && issue.namespaceId) {
181
- return { namespaceId: issue.namespaceId, createsNewObject };
238
+ if (node.nodeKind === PostgresSchemaNodeKind.namespace) {
239
+ const namespaceNode = blindCast<
240
+ PostgresNamespaceSchemaNode,
241
+ 'a postgres-namespace diff node is always a PostgresNamespaceSchemaNode'
242
+ >(node);
243
+ return {
244
+ namespaceId: resolveNamespaceIdForDdlSchema(contract, namespaceNode.schemaName),
245
+ createsNewObject: issue.reason === 'not-found',
246
+ };
182
247
  }
183
248
 
184
- if ('table' in issue && issue.table) {
185
- const namespaceId =
186
- 'namespaceId' in issue && issue.namespaceId
187
- ? issue.namespaceId
188
- : resolveNamespaceIdForTable(contract, issue.table, undefined);
189
- const table = entityAt<StorageTable>(contract.storage, {
190
- namespaceId,
191
- entityKind: 'table',
192
- entityName: issue.table,
193
- });
249
+ if (node.nodeKind === PostgresSchemaNodeKind.role) {
250
+ const roleName = issue.path[1];
251
+ const roleEntity =
252
+ roleName === undefined
253
+ ? undefined
254
+ : entityAt<PostgresRole>(contract.storage, {
255
+ namespaceId: UNBOUND_NAMESPACE_ID,
256
+ entityKind: 'role',
257
+ entityName: roleName,
258
+ });
194
259
  return {
195
- namespaceId,
196
- ...ifDefined('explicitNodeControlPolicy', table?.control),
197
- table: issue.table,
198
- ...ifDefined('column', 'column' in issue ? issue.column : undefined),
199
- createsNewObject,
260
+ namespaceId: UNBOUND_NAMESPACE_ID,
261
+ explicitNodeControlPolicy: roleEntity?.control ?? ROLE_DEFAULT_CONTROL_POLICY,
262
+ createsNewObject: false,
200
263
  };
201
264
  }
202
265
 
203
- return undefined;
266
+ const tableName = issue.path[2];
267
+ if (tableName === undefined) return undefined;
268
+ const ddlSchemaName = issue.path[1];
269
+ const namespaceId = resolveNamespaceIdForTable(contract, tableName, ddlSchemaName);
270
+ const table = entityAt<StorageTable>(contract.storage, {
271
+ namespaceId,
272
+ entityKind: 'table',
273
+ entityName: tableName,
274
+ });
275
+ const createsNewObject =
276
+ (node.nodeKind === PostgresSchemaNodeKind.table && issue.reason === 'not-found') ||
277
+ isEnablementCreationIssue(issue);
278
+
279
+ return {
280
+ namespaceId,
281
+ ...ifDefined('explicitNodeControlPolicy', table?.control),
282
+ table: tableName,
283
+ ...ifDefined('column', issueColumnName(issue)),
284
+ createsNewObject,
285
+ };
204
286
  }