@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
@@ -9,7 +9,9 @@ export type OperationClass =
9
9
  | 'unique'
10
10
  | 'index'
11
11
  | 'foreignKey'
12
- | 'checkConstraint';
12
+ | 'checkConstraint'
13
+ | 'rlsPolicy'
14
+ | 'rowLevelSecurity';
13
15
 
14
16
  export interface PostgresPlanTargetDetails {
15
17
  readonly schema: string;
@@ -13,28 +13,48 @@ import {
13
13
  plannerFailure,
14
14
  } from '@prisma-next/family-sql/control';
15
15
  import type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';
16
- import { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';
17
16
  import type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';
18
17
  import type {
19
18
  MigrationPlanner,
20
19
  MigrationPlanWithAuthoringSurface,
21
20
  MigrationScaffoldContext,
22
- SchemaIssue,
21
+ SchemaDiffIssue,
22
+ SchemaOwnership,
23
23
  } from '@prisma-next/framework-components/control';
24
24
  import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
25
+ import type { SqlStorage } from '@prisma-next/sql-contract/types';
26
+ import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
25
27
  import { blindCast } from '@prisma-next/utils/casts';
26
- import { parsePostgresDefault } from '../default-normalizer';
27
- import { normalizeSchemaNativeType } from '../native-type-normalizer';
28
+ import { ifDefined } from '@prisma-next/utils/defined';
29
+ import { PostgresRlsPolicy } from '../postgres-rls-policy';
30
+ import { parseRlsPolicyWireName } from '../rls/wire-name';
31
+ import { PostgresDatabaseSchemaNode } from '../schema-ir/postgres-database-schema-node';
32
+ import { PostgresPolicySchemaNode } from '../schema-ir/postgres-policy-schema-node';
33
+ import { PostgresSchemaNodeKind, type SqlSchemaDiffNode } from '../schema-ir/schema-node-kinds';
28
34
  import {
29
35
  formatPostgresControlPolicySubjectLabel,
36
+ resolveNamespaceIdForDdlSchema,
30
37
  resolvePostgresCallControlPolicySubject,
31
- resolvePostgresIssueControlPolicySubject,
32
- resolvePostgresIssueCreationFactoryName,
38
+ resolvePostgresNodeIssueControlPolicySubject,
39
+ resolvePostgresNodeIssueCreationFactoryName,
33
40
  } from './control-policy';
34
- import { planIssues } from './issue-planner';
41
+ import { buildPostgresPlanDiff } from './diff-database-schema';
42
+ import {
43
+ coalesceSubtreeIssues,
44
+ issueNode,
45
+ issueSchemaName,
46
+ issueTableName,
47
+ planIssues,
48
+ } from './issue-planner';
35
49
  import type { PostgresOpFactoryCall } from './op-factory-call';
50
+ import {
51
+ CreatePostgresRlsPolicyCall,
52
+ DropPostgresRlsPolicyCall,
53
+ RenamePostgresRlsPolicyCall,
54
+ } from './op-factory-call';
36
55
  import { TypeScriptRenderablePostgresMigration } from './planner-produced-postgres-migration';
37
56
  import { postgresPlannerStrategies } from './planner-strategies';
57
+ import { resolveDdlSchemaForNamespaceStorage } from './resolve-ddl-schema';
38
58
  import { verifyPostgresNamespacePresence } from './verify-postgres-namespaces';
39
59
 
40
60
  type PlannerFrameworkComponents = SqlMigrationPlannerPlanOptions extends {
@@ -47,10 +67,6 @@ type PlannerOptionsWithComponents = SqlMigrationPlannerPlanOptions & {
47
67
  readonly frameworkComponents: PlannerFrameworkComponents;
48
68
  };
49
69
 
50
- type VerifySqlSchemaOptionsWithComponents = Parameters<typeof verifySqlSchema>[0] & {
51
- readonly frameworkComponents: PlannerFrameworkComponents;
52
- };
53
-
54
70
  export function createPostgresMigrationPlanner(
55
71
  lowerer: ExecuteRequestLowerer,
56
72
  ): PostgresMigrationPlanner {
@@ -75,18 +91,20 @@ export type PostgresPlanResult =
75
91
  /**
76
92
  * Postgres migration planner — a thin wrapper over `planIssues`.
77
93
  *
78
- * `plan()` verifies the live schema against the target contract (producing
79
- * `SchemaIssue[]`) and delegates to `planIssues` with the unified
80
- * `postgresPlannerStrategies` list: enum-change, NOT-NULL backfill,
81
- * type-change, nullable-tightening, codec-hook storage types,
82
- * component-declared dependency installs, and shared-temp-default /
83
- * empty-table-guarded NOT-NULL add-column. The same strategy list runs for
84
- * `migration plan`, `db update`, and `db init`; behavior diverges purely on
85
- * `policy.allowedOperationClasses` (the data-safe strategies short-circuit
86
- * when `'data'` is excluded). The issue planner applies operation-class
87
- * policy gates and emits a single `PostgresOpFactoryCall[]` that drives both
88
- * the runtime-ops view (via `renderOps`) and the `renderTypeScript()`
89
- * authoring surface.
94
+ * `plan()` diffs the target contract against the live schema via the one
95
+ * differ (`buildPostgresPlanDiff`, producing node-typed `SchemaDiffIssue[]`)
96
+ * and delegates to `planIssues` with the unified `postgresPlannerStrategies`
97
+ * list: NOT-NULL backfill, type-change, nullable-tightening, codec-hook
98
+ * storage types, component-declared dependency installs, and
99
+ * shared-temp-default / empty-table-guarded NOT-NULL add-column. The same
100
+ * strategy list runs for `migration plan`, `db update`, and `db init`;
101
+ * behavior diverges purely on `policy.allowedOperationClasses` (the
102
+ * data-safe strategies short-circuit when `'data'` is excluded). The issue
103
+ * planner applies operation-class policy gates and emits a single
104
+ * `PostgresOpFactoryCall[]` that drives both the runtime-ops view (via
105
+ * `renderOps`) and the `renderTypeScript()` authoring surface. RLS policy
106
+ * drift (the structural half of the same one-differ tree) is handled
107
+ * separately via `planPostgresSchemaDiff`.
90
108
  */
91
109
  export class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgres'> {
92
110
  readonly #lowerer: ExecuteRequestLowerer | undefined;
@@ -122,6 +140,11 @@ export class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgr
122
140
  * the marker row by the right space.
123
141
  */
124
142
  readonly spaceId: string;
143
+ /**
144
+ * Ownership oracle over the contract-space composition — see
145
+ * {@link SqlMigrationPlannerPlanOptions.ownership}.
146
+ */
147
+ readonly ownership?: SchemaOwnership;
125
148
  }): PostgresPlanResult {
126
149
  return this.planSql(options as SqlMigrationPlannerPlanOptions);
127
150
  }
@@ -151,9 +174,73 @@ export class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgr
151
174
  return policyResult;
152
175
  }
153
176
 
154
- const schemaIssues = this.collectSchemaIssues(options);
177
+ // The one combined tree diff drives the whole plan: relational findings
178
+ // become structural DDL via `planIssues`, policy findings become RLS ops
179
+ // via `planPostgresSchemaDiff`. Verify runs its own full-tree node diff
180
+ // (`diffSchema`) over the same schema and rejects on a
181
+ // surviving failure.
182
+ PostgresDatabaseSchemaNode.assert(options.schema);
183
+ const { issues: rawIssues } = buildPostgresPlanDiff({
184
+ contract: options.contract,
185
+ actualSchema: options.schema,
186
+ frameworkComponents: options.frameworkComponents,
187
+ });
188
+ const policyDiffIssues = rawIssues.filter((issue) => isPolicyDiffIssue(issue));
189
+ // Role diff issues resolve to the `external` control policy (see
190
+ // `resolvePostgresNodeIssueControlPolicySubject`'s role branch), so the
191
+ // control-policy partition below suppresses them to zero ops on its own,
192
+ // before `mapNodeIssueToCall` ever sees them — no separate exclusion
193
+ // needed here.
194
+ const relationalDiffIssues = rawIssues.filter((issue) => !isPolicyDiffIssue(issue));
195
+
196
+ // The generic differ is total and un-gated: strict-mode extras filtering
197
+ // (dropping `not-expected` findings outside strict mode, mirroring the
198
+ // retired coordinate walk's `if (strict) { ...extra_* } }` guards),
199
+ // subtree coalescing (a missing/extra table also emits an issue for
200
+ // every child under it — redundant once the table-level Create/Drop call
201
+ // already accounts for the whole subtree), and ownership are all post-diff
202
+ // planner steps.
203
+ //
204
+ // Ownership: a live extra is only this plan's to drop when no contract
205
+ // space owns it. The differ ran against THIS space's contract, so a table
206
+ // a sibling space owns surfaces here as `not-expected`; the planner asks
207
+ // the ownership oracle (the passive aggregate) whether any space declares
208
+ // it and, if so, leaves it alone — it is a sibling's table, not an orphan.
209
+ // A table no space owns stays a genuine extra to drop under a destructive
210
+ // policy. Ownership lives in the aggregate; the planner only asks. Absent
211
+ // oracle (single-space, none handed) keeps every extra. Coalescing MUST
212
+ // run before this so a sibling-owned table's child issues have already
213
+ // collapsed into the one table-level issue that carries the table name.
214
+ const strict =
215
+ options.policy.allowedOperationClasses.includes('widening') ||
216
+ options.policy.allowedOperationClasses.includes('destructive');
217
+ const coalesced = coalesceSubtreeIssues(relationalDiffIssues);
218
+ const owned = retainUnownedExtras(coalesced, options.ownership, options.contract);
219
+ const gated = strict ? owned : owned.filter((issue) => issue.reason !== 'not-expected');
220
+
221
+ // Namespace presence (`CREATE SCHEMA`) is a planner-only op-generation
222
+ // concern stitched in here rather than inside the shared diff — verify
223
+ // never needs it (a missing schema already surfaces as a `not-found`
224
+ // table in the relational findings). These synthesized issues are added
225
+ // AFTER coalescing/scoping (never coalesced against the table diff —
226
+ // their path is an ancestor of every table path under that schema, so
227
+ // running them through the same coalesce would swallow the table-level
228
+ // `not-found` issues that drive `CREATE TABLE`) and are NOT subject to
229
+ // sibling-space scoping, matching the retired coordinate walk exactly.
230
+ const namespaceIssues = verifyPostgresNamespacePresence({
231
+ contract: options.contract,
232
+ schema: options.schema,
233
+ });
234
+ const schemaIssues = [...namespaceIssues, ...gated];
235
+
155
236
  const codecHooks = extractCodecControlHooks(options.frameworkComponents);
156
237
  const storageTypes = options.contract.storage.types ?? {};
238
+ // The strategy layer reads the live schema by bare table name for existence
239
+ // checks (shared-temp-default safety, FK/unique probes), so it takes one
240
+ // per-schema namespace node — never the whole tree root, and never a flat
241
+ // merge of every namespace (which would collide same-named tables across
242
+ // schemas). Probing more than one namespace at once is future work.
243
+ const relationalSchema = relationalNamespaceNode(options.schema, schemaName);
157
244
 
158
245
  // Input-side control-policy partition. `external` / `observed` subjects
159
246
  // — and non-creation issues for `tolerated` subjects — are dropped from
@@ -166,8 +253,8 @@ export class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgr
166
253
  issues: schemaIssues,
167
254
  contract: options.contract,
168
255
  resolveControlPolicySubject: (issue) =>
169
- resolvePostgresIssueControlPolicySubject(issue, options.contract),
170
- resolveCreationFactoryName: resolvePostgresIssueCreationFactoryName,
256
+ resolvePostgresNodeIssueControlPolicySubject(issue, options.contract),
257
+ resolveCreationFactoryName: resolvePostgresNodeIssueCreationFactoryName,
171
258
  formatSubjectLabel: (factoryName, subject) =>
172
259
  formatPostgresControlPolicySubjectLabel(factoryName, subject, options.contract),
173
260
  });
@@ -179,12 +266,12 @@ export class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgr
179
266
  // `db update` / `db init`, which means data-safety strategies needing
180
267
  // from/to comparisons (unsafe type change, nullable tightening) are
181
268
  // inapplicable there — reconciliation falls through to
182
- // `mapIssueToCall`'s direct destructive handlers.
269
+ // `mapNodeIssueToCall`'s direct destructive handlers.
183
270
  fromContract: options.fromContract,
184
271
  schemaName,
185
272
  codecHooks,
186
273
  storageTypes,
187
- schema: options.schema,
274
+ ...ifDefined('schema', relationalSchema),
188
275
  policy: options.policy,
189
276
  frameworkComponents: options.frameworkComponents,
190
277
  strategies: postgresPlannerStrategies,
@@ -194,6 +281,17 @@ export class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgr
194
281
  return plannerFailure(result.failure);
195
282
  }
196
283
 
284
+ const schemaDiffCalls = this.planPostgresSchemaDiff(options, policyDiffIssues);
285
+ const schemaDiffPartition = partitionCallsByControlPolicy({
286
+ calls: schemaDiffCalls,
287
+ contract: options.contract,
288
+ resolveControlPolicySubject: (call) =>
289
+ resolvePostgresCallControlPolicySubject(call, options.contract),
290
+ resolveFactoryName: (call) => call.factoryName,
291
+ formatSubjectLabel: (factoryName, subject) =>
292
+ formatPostgresControlPolicySubjectLabel(factoryName, subject, options.contract),
293
+ });
294
+
197
295
  // Inline `onFieldEvent`-emitted ops after structural DDL. The fixed
198
296
  // ordering is `structural → added → dropped → altered`, with
199
297
  // within-group sorting by `(tableName, fieldName)` so re-emits are
@@ -219,9 +317,10 @@ export class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgr
219
317
  formatSubjectLabel: (factoryName, subject) =>
220
318
  formatPostgresControlPolicySubjectLabel(factoryName, subject, options.contract),
221
319
  });
222
- const calls = [...result.value.calls, ...fieldEventPartition.kept];
320
+ const calls = [...result.value.calls, ...schemaDiffPartition.kept, ...fieldEventPartition.kept];
223
321
  const warnings: SqlPlannerConflict[] = [
224
322
  ...issuePartition.warnings,
323
+ ...schemaDiffPartition.warnings,
225
324
  ...fieldEventPartition.warnings,
226
325
  ];
227
326
 
@@ -240,6 +339,142 @@ export class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgr
240
339
  });
241
340
  }
242
341
 
342
+ /**
343
+ * Maps the RLS policy presence findings of the one combined tree diff
344
+ * (`buildPostgresPlanDiff`, already ownership-filtered) into
345
+ * `CREATE POLICY` / `DROP POLICY` / `ALTER POLICY … RENAME TO` ops. It
346
+ * does not re-diff — it consumes exactly the policy-node subset of the
347
+ * shared diff's issues. Enablement is NOT decided here: `ENABLE`/`DISABLE
348
+ * ROW LEVEL SECURITY` derive from the table's marker-driven `rlsEnabled`
349
+ * attribute diff on the relational side.
350
+ *
351
+ * Rename post-pass: a `not-found` and a `not-expected` policy on the SAME
352
+ * table whose wire-name content hashes match but prefixes differ are one
353
+ * prefix-only rename, collapsed into a single non-destructive
354
+ * `RenamePostgresRlsPolicyCall`. Multi-candidate hash groups pair
355
+ * deterministically by sorted wire name; leftovers proceed as
356
+ * create/drop. Unparseable wire names never pair.
357
+ *
358
+ * The pairing runs only when the policy allows `widening` (rename's
359
+ * class). Without it (db-init's additive-only set), pairing degrades
360
+ * deliberately to the additive half: the new name is CREATEd and the old
361
+ * policy survives live until a widening/destructive-allowed plan runs —
362
+ * emitting an ungated widening rename would only fail at the runner's
363
+ * class re-enforcement.
364
+ */
365
+ private planPostgresSchemaDiff(
366
+ options: PlannerOptionsWithComponents,
367
+ filteredDiffIssues: readonly SchemaDiffIssue<SqlSchemaDiffNode>[],
368
+ ): readonly PostgresOpFactoryCall[] {
369
+ const allowsDestructive = options.policy.allowedOperationClasses.includes('destructive');
370
+ const allowsWidening = options.policy.allowedOperationClasses.includes('widening');
371
+
372
+ interface PolicyFinding {
373
+ readonly node: PostgresPolicySchemaNode;
374
+ readonly schemaForTable: string;
375
+ }
376
+ const missing: PolicyFinding[] = [];
377
+ const extra: PolicyFinding[] = [];
378
+
379
+ for (const issue of filteredDiffIssues) {
380
+ // 'not-equal' is unreachable for content-addressed policies: the wire name
381
+ // encodes the body hash, so two policies sharing a local key (same name)
382
+ // are always equal and isEqualTo never returns false.
383
+ if (issue.reason === 'not-found') {
384
+ const expected = issue.expected;
385
+ PostgresPolicySchemaNode.assert(expected);
386
+ // expected.namespaceId is the DDL schema name (resolved during projection);
387
+ // this re-resolution is a no-op as long as PostgresSchema.ddlSchemaName() returns this.id.
388
+ missing.push({
389
+ node: expected,
390
+ schemaForTable: resolveDdlSchemaForNamespaceStorage(
391
+ options.contract.storage,
392
+ expected.namespaceId,
393
+ ),
394
+ });
395
+ } else if (issue.reason === 'not-expected') {
396
+ const actual = issue.actual;
397
+ PostgresPolicySchemaNode.assert(actual);
398
+ extra.push({
399
+ node: actual,
400
+ schemaForTable: resolveDdlSchemaForNamespaceStorage(
401
+ options.contract.storage,
402
+ actual.namespaceId,
403
+ ),
404
+ });
405
+ }
406
+ }
407
+
408
+ const calls: PostgresOpFactoryCall[] = [];
409
+ const renamedExtras = new Set<PolicyFinding>();
410
+ const renamedMissing = new Set<PolicyFinding>();
411
+ const pairingKey = (finding: PolicyFinding, hash: string): string =>
412
+ JSON.stringify([finding.schemaForTable, finding.node.tableName, hash]);
413
+
414
+ if (allowsWidening) {
415
+ const extrasByGroup = new Map<string, PolicyFinding[]>();
416
+ for (const finding of extra) {
417
+ const parsed = parseRlsPolicyWireName(finding.node.name);
418
+ if (parsed === undefined) continue;
419
+ const key = pairingKey(finding, parsed.hash);
420
+ const group = extrasByGroup.get(key) ?? [];
421
+ group.push(finding);
422
+ extrasByGroup.set(key, group);
423
+ }
424
+ for (const group of extrasByGroup.values()) {
425
+ group.sort((a, b) => (a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0));
426
+ }
427
+
428
+ const sortedMissing = [...missing].sort((a, b) =>
429
+ a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0,
430
+ );
431
+ for (const missingFinding of sortedMissing) {
432
+ const parsed = parseRlsPolicyWireName(missingFinding.node.name);
433
+ if (parsed === undefined) continue;
434
+ const candidates = extrasByGroup.get(pairingKey(missingFinding, parsed.hash));
435
+ const candidate = candidates?.shift();
436
+ if (candidate === undefined) continue;
437
+ // Same name would never surface as missing+extra (the differ pairs by
438
+ // name), so a matched candidate always differs in prefix only.
439
+ renamedExtras.add(candidate);
440
+ renamedMissing.add(missingFinding);
441
+ calls.push(
442
+ new RenamePostgresRlsPolicyCall(
443
+ missingFinding.schemaForTable,
444
+ missingFinding.node.tableName,
445
+ candidate.node.name,
446
+ missingFinding.node.name,
447
+ ),
448
+ );
449
+ }
450
+ }
451
+
452
+ for (const finding of missing) {
453
+ if (renamedMissing.has(finding)) continue;
454
+ calls.push(
455
+ new CreatePostgresRlsPolicyCall(
456
+ finding.schemaForTable,
457
+ finding.node.tableName,
458
+ policyNodeToContractPolicy(finding.node),
459
+ ),
460
+ );
461
+ }
462
+ if (allowsDestructive) {
463
+ for (const finding of extra) {
464
+ if (renamedExtras.has(finding)) continue;
465
+ calls.push(
466
+ new DropPostgresRlsPolicyCall(
467
+ finding.schemaForTable,
468
+ finding.node.tableName,
469
+ finding.node.name,
470
+ ),
471
+ );
472
+ }
473
+ }
474
+
475
+ return calls;
476
+ }
477
+
243
478
  private ensureAdditivePolicy(policy: MigrationOperationPolicy) {
244
479
  if (!policy.allowedOperationClasses.includes('additive')) {
245
480
  return plannerFailure([
@@ -252,35 +487,127 @@ export class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgr
252
487
  }
253
488
  return null;
254
489
  }
490
+ }
255
491
 
256
- private collectSchemaIssues(options: PlannerOptionsWithComponents): readonly SchemaIssue[] {
257
- // `db init` uses additive-only policy and intentionally ignores extra
258
- // schema objects. Any reconciliation-capable policy (widening or
259
- // destructive) must inspect extras to reconcile strict equality.
260
- const allowed = options.policy.allowedOperationClasses;
261
- const strict = allowed.includes('widening') || allowed.includes('destructive');
262
- const verifyOptions: VerifySqlSchemaOptionsWithComponents = {
263
- contract: options.contract,
264
- schema: options.schema,
265
- strict,
266
- typeMetadataRegistry: new Map(),
267
- frameworkComponents: options.frameworkComponents,
268
- normalizeDefault: parsePostgresDefault,
269
- normalizeNativeType: normalizeSchemaNativeType,
270
- };
271
- const verifyResult = verifySqlSchema(verifyOptions);
272
- // Schema presence is a Postgres-specific concern (no equivalent in
273
- // SQLite / Mongo), so the issue emission lives in the target layer
274
- // rather than in the family verifier. Stitch it in here so a single
275
- // `SchemaIssue[]` flows through `planIssues` and the planner emits
276
- // CREATE SCHEMA in the dep bucket before any CreateTableCall.
277
- const namespaceIssues = verifyPostgresNamespacePresence({
278
- contract: options.contract,
279
- schema: options.schema,
280
- });
281
- if (namespaceIssues.length === 0) {
282
- return verifyResult.schema.issues;
283
- }
284
- return [...namespaceIssues, ...verifyResult.schema.issues];
285
- }
492
+ /**
493
+ * A diff issue whose node is an RLS policy the structural half of the one
494
+ * combined tree diff, routed to `planPostgresSchemaDiff` instead of
495
+ * `planIssues`.
496
+ */
497
+ function isPolicyDiffIssue(issue: SchemaDiffIssue<SqlSchemaDiffNode>): boolean {
498
+ const node = issue.expected ?? issue.actual;
499
+ return node !== undefined && PostgresPolicySchemaNode.is(node);
500
+ }
501
+
502
+ /**
503
+ * Drops a `not-expected` issue when it is a whole extra TABLE that some
504
+ * contract space owns, asking the ownership oracle per node.
505
+ *
506
+ * The consultation applies ONLY to table-level extras — a live table this
507
+ * space's contract lacks — identified by asking the issue's own node
508
+ * (`nodeKind === table`), never by counting path segments. `declaresEntity`
509
+ * answers over the whole composition (self included), keyed on the schema-IR
510
+ * entity coordinate so a genuine orphan in one namespace is never conflated
511
+ * with a same-named table a sibling space declares in another, or with a
512
+ * same-named non-table entity (an enum, an RLS policy) a sibling declares in
513
+ * the SAME namespace: a positive answer means another space owns THIS table
514
+ * in THIS namespace (a table this space owned would be in its expected tree,
515
+ * never an extra) — leave it. A negative answer means no space owns it — a
516
+ * genuine orphan to drop. `entityKind` is the literal `'table'` here: this
517
+ * function only ever asks about a node already confirmed to be
518
+ * `PostgresSchemaNodeKind.table` (checked just above), and the diff tree's
519
+ * `nodeKind` vocabulary (`'postgres-table'`) is distinct from the storage
520
+ * `entries` vocabulary `elementCoordinates` walks (`'table'`) — the literal
521
+ * is that storage-entries spelling, not the node kind.
522
+ *
523
+ * The issue path carries the *resolved DDL schema* (e.g. `public`), but a
524
+ * contract space's own declared namespace id can be the unbound sentinel
525
+ * (`__unbound__`) that resolves to that schema — the two spellings would
526
+ * never string-match. `resolveNamespaceIdForDdlSchema` recovers the raw
527
+ * namespace id THIS space's own contract would use for that DDL schema, so
528
+ * a table this space's own unbound namespace declares (and any sibling
529
+ * whose own unbound namespace resolves the same way) is compared on the
530
+ * same coordinate the aggregate's `elementCoordinates` walk yields.
531
+ *
532
+ * A DEEPER extra (an extra column/constraint on a table this space DOES own —
533
+ * only the child drifted, so the table is in the expected tree) is this
534
+ * space's own drift and is always kept for dropping; asking the oracle there
535
+ * would wrongly suppress it, because the owned table answers `true`. Shallower
536
+ * issues (namespace/root) are never ownership-scoped here. No oracle ⇒ every
537
+ * extra is kept (single-space plan).
538
+ */
539
+ function retainUnownedExtras(
540
+ issues: readonly SchemaDiffIssue<SqlSchemaDiffNode>[],
541
+ ownership: SchemaOwnership | undefined,
542
+ contract: Contract<SqlStorage>,
543
+ ): readonly SchemaDiffIssue<SqlSchemaDiffNode>[] {
544
+ if (ownership === undefined) return issues;
545
+ return issues.filter((issue) => {
546
+ if (issue.reason !== 'not-expected') return true;
547
+ const node = issueNode(issue);
548
+ if (node === undefined || node.nodeKind !== PostgresSchemaNodeKind.table) return true;
549
+ const ddlSchemaName = issueSchemaName(issue);
550
+ const tableName = issueTableName(issue);
551
+ if (ddlSchemaName === undefined || tableName === undefined) return true;
552
+ const namespaceId = resolveNamespaceIdForDdlSchema(contract, ddlSchemaName);
553
+ return !ownership.declaresEntity({ namespaceId, entityKind: 'table', entityName: tableName });
554
+ });
555
+ }
556
+
557
+ /**
558
+ * Returns the one namespace node the relational strategy layer probes for
559
+ * live-table existence and reads codec-hook context off — the namespace
560
+ * matching the planner's resolved schema name, or the first namespace when
561
+ * none matches. `undefined` when the tree has no namespaces, so the strategy
562
+ * context uses its empty-schema default.
563
+ *
564
+ * The relational strategies key tables by bare name, so they can only probe one
565
+ * namespace at a time; probing across every namespace at once is future work.
566
+ *
567
+ * Returns the real `PostgresNamespaceSchemaNode` reference rather than a
568
+ * projection: `storageTypePlanCallStrategy` hands this same value to codec
569
+ * `planTypeOperations` hooks as `schema`, and hooks read the Postgres-specific
570
+ * `nativeEnumTypeNames` field off it (via `PostgresNamespaceSchemaNode.is`) to
571
+ * decide whether a native enum type already exists — a projection that only
572
+ * copies `tables` would silently drop that signal. `StrategyContext.schema`'s
573
+ * declared type (`SqlSchemaIR`, shared with SQLite's flat shape) doesn't
574
+ * capture this, so the return is `blindCast` the same way `namespaceSchemaNodes`
575
+ * in the family's relational walk already treats a namespace node as a
576
+ * structurally-`SqlSchemaIR`-shaped value.
577
+ */
578
+ function relationalNamespaceNode(
579
+ schema: PostgresDatabaseSchemaNode,
580
+ schemaName: string,
581
+ ): SqlSchemaIR | undefined {
582
+ const namespaceNodes = Object.values(schema.namespaces);
583
+ const namespaceNode =
584
+ namespaceNodes.find((node) => node.schemaName === schemaName) ?? namespaceNodes[0];
585
+ if (namespaceNode === undefined) return undefined;
586
+ return blindCast<
587
+ SqlSchemaIR,
588
+ 'PostgresNamespaceSchemaNode carries tables (+ nativeEnumTypeNames, read by codec hooks via PostgresNamespaceSchemaNode.is) structurally compatible with the SqlSchemaIR shape the strategy layer declares'
589
+ >(namespaceNode);
590
+ }
591
+
592
+ /**
593
+ * Rebuilds the `PostgresRlsPolicy` contract entity `CreatePostgresRlsPolicyCall`
594
+ * carries (its `renderTypeScript`/`createRlsPolicy` paths serialize the whole
595
+ * entity, `namespaceId` included). This reconstructs rather than looking the
596
+ * original up in the contract on purpose: the diff node's `namespaceId` is the
597
+ * *resolved DDL schema* (set when the expected tree was built), which is the
598
+ * value the emitted op must carry; the contract-stored entity holds the raw,
599
+ * pre-resolution coordinate, so a lookup would change the migration output.
600
+ */
601
+ function policyNodeToContractPolicy(node: PostgresPolicySchemaNode): PostgresRlsPolicy {
602
+ return new PostgresRlsPolicy({
603
+ name: node.name,
604
+ prefix: node.prefix,
605
+ tableName: node.tableName,
606
+ namespaceId: node.namespaceId,
607
+ operation: node.operation,
608
+ roles: [...node.roles],
609
+ ...ifDefined('using', node.using),
610
+ ...ifDefined('withCheck', node.withCheck),
611
+ permissive: node.permissive,
612
+ });
286
613
  }