@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,27 +3,38 @@ import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control'
3
3
  import type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';
4
4
  import { Migration as SqlMigration } from '@prisma-next/family-sql/migration';
5
5
  import type { ControlStack } from '@prisma-next/framework-components/control';
6
+ import { MigrationContractViews } from '@prisma-next/migration-tools/migration';
6
7
  import type { SqlStorage } from '@prisma-next/sql-contract/types';
7
8
  import type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';
8
9
  import { errorPostgresMigrationStackMissing } from '../errors';
10
+ import { PostgresContractView } from '../postgres-contract-view';
11
+ import { PostgresRlsPolicy, type PostgresRlsPolicyInput } from '../postgres-rls-policy';
9
12
  import {
10
13
  AddCheckConstraintCall,
11
14
  AddColumnCall,
12
15
  AddForeignKeyCall,
16
+ AddNativeEnumValueCall,
13
17
  AddPrimaryKeyCall,
14
18
  AddUniqueCall,
15
19
  AlterColumnTypeCall,
16
20
  type AlterColumnTypeOptions,
17
21
  CreateIndexCall,
22
+ CreateNativeEnumTypeCall,
23
+ CreatePostgresRlsPolicyCall,
18
24
  CreateSchemaCall,
19
25
  CreateTableCall,
26
+ DisableRowLevelSecurityCall,
20
27
  DropCheckConstraintCall,
21
28
  DropColumnCall,
22
29
  DropConstraintCall,
23
30
  DropDefaultCall,
24
31
  DropIndexCall,
32
+ DropNativeEnumTypeCall,
25
33
  DropNotNullCall,
34
+ DropPostgresRlsPolicyCall,
26
35
  DropTableCall,
36
+ EnableRowLevelSecurityCall,
37
+ RenamePostgresRlsPolicyCall,
27
38
  SetDefaultCall,
28
39
  SetNotNullCall,
29
40
  } from './op-factory-call';
@@ -60,20 +71,31 @@ import type { PostgresPlanTargetDetails } from './planner-target-details';
60
71
  * is an antipattern in a migration. (The unbound/unspecified namespace concept
61
72
  * remains for SQLite, which has no schemas, and for Mongo's connection `db`.)
62
73
  */
63
- export abstract class PostgresMigration extends SqlMigration<
64
- PostgresPlanTargetDetails,
65
- 'postgres'
66
- > {
74
+ export abstract class PostgresMigration<
75
+ Start extends Contract<SqlStorage> = Contract<SqlStorage>,
76
+ End extends Contract<SqlStorage> = Contract<SqlStorage>,
77
+ > extends SqlMigration<PostgresPlanTargetDetails, 'postgres', Start, End> {
67
78
  readonly targetId = 'postgres' as const;
68
79
 
69
80
  /**
70
81
  * Materialized Postgres control adapter, created once per migration
71
82
  * instance from the injected stack. `undefined` only when the migration
72
- * was instantiated without a stack (test fixtures); `dataTransform`
73
- * throws in that case to surface the misuse.
83
+ * was instantiated without a stack (test fixtures); `controlAdapterFor`
84
+ * throws a PN-MIG-2007 in that case to surface the misuse.
74
85
  */
75
86
  protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;
76
87
 
88
+ #endView = new MigrationContractViews<PostgresContractView<End>>(
89
+ this,
90
+ 'PostgresMigration',
91
+ (json) => PostgresContractView.fromJson<End>(json),
92
+ );
93
+ #startView = new MigrationContractViews<PostgresContractView<Start>>(
94
+ this,
95
+ 'PostgresMigration',
96
+ (json) => PostgresContractView.fromJson<Start>(json),
97
+ );
98
+
77
99
  constructor(stack?: ControlStack<'sql', 'postgres'>) {
78
100
  super(stack);
79
101
  // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;
@@ -84,6 +106,35 @@ export abstract class PostgresMigration extends SqlMigration<
84
106
  : undefined;
85
107
  }
86
108
 
109
+ /**
110
+ * Returns the materialized control adapter, or throws a PN-MIG-2007 naming
111
+ * `operation` when the migration was constructed without a `ControlStack`.
112
+ * Single home for the null-check that every DDL/DML method shares.
113
+ */
114
+ private controlAdapterFor(operation: string): SqlControlAdapter<'postgres'> {
115
+ if (!this.controlAdapter) {
116
+ throw errorPostgresMigrationStackMissing(operation);
117
+ }
118
+ return this.controlAdapter;
119
+ }
120
+
121
+ /**
122
+ * The typed, schema-qualified Postgres view over this migration's end-state
123
+ * contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws
124
+ * if no `endContractJson` was provided.
125
+ */
126
+ get endContract(): PostgresContractView<End> {
127
+ return this.#endView.endContract;
128
+ }
129
+
130
+ /**
131
+ * The typed Postgres view over this migration's start-state contract, or
132
+ * `null` for a baseline migration (no `startContractJson`).
133
+ */
134
+ get startContract(): PostgresContractView<Start> | null {
135
+ return this.#startView.startContract;
136
+ }
137
+
87
138
  /**
88
139
  * Instance-method wrapper around the free `dataTransform` factory that
89
140
  * supplies the stored control adapter. Authors call this from inside
@@ -94,10 +145,7 @@ export abstract class PostgresMigration extends SqlMigration<
94
145
  name: string,
95
146
  options: DataTransformOptions,
96
147
  ): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
97
- if (!this.controlAdapter) {
98
- throw errorPostgresMigrationStackMissing();
99
- }
100
- return dataTransform(contract, name, options, this.controlAdapter);
148
+ return dataTransform(contract, name, options, this.controlAdapterFor('dataTransform'));
101
149
  }
102
150
 
103
151
  /**
@@ -112,15 +160,12 @@ export abstract class PostgresMigration extends SqlMigration<
112
160
  readonly columns: readonly DdlColumn[];
113
161
  readonly constraints?: readonly DdlTableConstraint[];
114
162
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
115
- if (!this.controlAdapter) {
116
- throw errorPostgresMigrationStackMissing();
117
- }
118
163
  return new CreateTableCall(
119
164
  options.schema,
120
165
  options.table,
121
166
  options.columns,
122
167
  options.constraints,
123
- ).toOp(this.controlAdapter);
168
+ ).toOp(this.controlAdapterFor('createTable'));
124
169
  }
125
170
 
126
171
  /**
@@ -132,10 +177,52 @@ export abstract class PostgresMigration extends SqlMigration<
132
177
  readonly schema: string;
133
178
  readonly ifNotExists?: boolean;
134
179
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
135
- if (!this.controlAdapter) {
136
- throw errorPostgresMigrationStackMissing();
137
- }
138
- return new CreateSchemaCall(options.schema).toOp(this.controlAdapter);
180
+ return new CreateSchemaCall(options.schema).toOp(this.controlAdapterFor('createSchema'));
181
+ }
182
+
183
+ /**
184
+ * Emit a `CREATE TYPE ... AS ENUM (...)` migration operation for a managed
185
+ * native enum. Builds a typed DDL node and lowers it through the stored
186
+ * control adapter (members render in declaration order). Throws if no adapter
187
+ * is present.
188
+ */
189
+ protected createNativeEnumType(options: {
190
+ readonly schema: string;
191
+ readonly typeName: string;
192
+ readonly members: readonly string[];
193
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
194
+ return new CreateNativeEnumTypeCall(options.schema, options.typeName, options.members).toOp(
195
+ this.controlAdapterFor('createNativeEnumType'),
196
+ );
197
+ }
198
+
199
+ /**
200
+ * Emit a `DROP TYPE` migration operation for a managed native enum, lowered
201
+ * through the stored control adapter. Throws if no adapter is present.
202
+ */
203
+ protected dropNativeEnumType(options: {
204
+ readonly schema: string;
205
+ readonly typeName: string;
206
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
207
+ return new DropNativeEnumTypeCall(options.schema, options.typeName).toOp(
208
+ this.controlAdapterFor('dropNativeEnumType'),
209
+ );
210
+ }
211
+
212
+ /**
213
+ * Emit an `ALTER TYPE ... ADD VALUE` migration operation appending one
214
+ * member to a managed native enum, lowered through the stored control
215
+ * adapter. Throws if no adapter is present. Every appended value is its
216
+ * own operation — call this once per value to append more than one.
217
+ */
218
+ protected addNativeEnumValue(options: {
219
+ readonly schema: string;
220
+ readonly typeName: string;
221
+ readonly value: string;
222
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
223
+ return new AddNativeEnumValueCall(options.schema, options.typeName, options.value).toOp(
224
+ this.controlAdapterFor('addNativeEnumValue'),
225
+ );
139
226
  }
140
227
 
141
228
  protected addColumn(options: {
@@ -143,11 +230,8 @@ export abstract class PostgresMigration extends SqlMigration<
143
230
  readonly table: string;
144
231
  readonly column: DdlColumn;
145
232
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
146
- if (!this.controlAdapter) {
147
- throw errorPostgresMigrationStackMissing();
148
- }
149
233
  return new AddColumnCall(options.schema, options.table, options.column).toOp(
150
- this.controlAdapter,
234
+ this.controlAdapterFor('addColumn'),
151
235
  );
152
236
  }
153
237
 
@@ -157,15 +241,12 @@ export abstract class PostgresMigration extends SqlMigration<
157
241
  readonly constraint: string;
158
242
  readonly columns: readonly string[];
159
243
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
160
- if (!this.controlAdapter) {
161
- throw errorPostgresMigrationStackMissing();
162
- }
163
244
  return new AddPrimaryKeyCall(
164
245
  options.schema,
165
246
  options.table,
166
247
  options.constraint,
167
248
  options.columns,
168
- ).toOp(this.controlAdapter);
249
+ ).toOp(this.controlAdapterFor('addPrimaryKey'));
169
250
  }
170
251
 
171
252
  protected addUnique(options: {
@@ -174,15 +255,12 @@ export abstract class PostgresMigration extends SqlMigration<
174
255
  readonly constraint: string;
175
256
  readonly columns: readonly string[];
176
257
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
177
- if (!this.controlAdapter) {
178
- throw errorPostgresMigrationStackMissing();
179
- }
180
258
  return new AddUniqueCall(
181
259
  options.schema,
182
260
  options.table,
183
261
  options.constraint,
184
262
  options.columns,
185
- ).toOp(this.controlAdapter);
263
+ ).toOp(this.controlAdapterFor('addUnique'));
186
264
  }
187
265
 
188
266
  protected addForeignKey(options: {
@@ -190,11 +268,8 @@ export abstract class PostgresMigration extends SqlMigration<
190
268
  readonly table: string;
191
269
  readonly foreignKey: ForeignKeySpec;
192
270
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
193
- if (!this.controlAdapter) {
194
- throw errorPostgresMigrationStackMissing();
195
- }
196
271
  return new AddForeignKeyCall(options.schema, options.table, options.foreignKey).toOp(
197
- this.controlAdapter,
272
+ this.controlAdapterFor('addForeignKey'),
198
273
  );
199
274
  }
200
275
 
@@ -205,16 +280,13 @@ export abstract class PostgresMigration extends SqlMigration<
205
280
  readonly column: string;
206
281
  readonly values: readonly string[];
207
282
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
208
- if (!this.controlAdapter) {
209
- throw errorPostgresMigrationStackMissing();
210
- }
211
283
  return new AddCheckConstraintCall(
212
284
  options.schema,
213
285
  options.table,
214
286
  options.constraint,
215
287
  options.column,
216
288
  options.values,
217
- ).toOp(this.controlAdapter);
289
+ ).toOp(this.controlAdapterFor('addCheckConstraint'));
218
290
  }
219
291
 
220
292
  protected dropCheckConstraint(options: {
@@ -222,11 +294,8 @@ export abstract class PostgresMigration extends SqlMigration<
222
294
  readonly table: string;
223
295
  readonly constraint: string;
224
296
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
225
- if (!this.controlAdapter) {
226
- throw errorPostgresMigrationStackMissing();
227
- }
228
297
  return new DropCheckConstraintCall(options.schema, options.table, options.constraint).toOp(
229
- this.controlAdapter,
298
+ this.controlAdapterFor('dropCheckConstraint'),
230
299
  );
231
300
  }
232
301
 
@@ -236,25 +305,21 @@ export abstract class PostgresMigration extends SqlMigration<
236
305
  readonly constraint: string;
237
306
  readonly kind?: 'foreignKey' | 'unique' | 'primaryKey';
238
307
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
239
- if (!this.controlAdapter) {
240
- throw errorPostgresMigrationStackMissing();
241
- }
242
308
  return new DropConstraintCall(
243
309
  options.schema,
244
310
  options.table,
245
311
  options.constraint,
246
312
  options.kind ?? 'unique',
247
- ).toOp(this.controlAdapter);
313
+ ).toOp(this.controlAdapterFor('dropConstraint'));
248
314
  }
249
315
 
250
316
  protected dropTable(options: {
251
317
  readonly schema: string;
252
318
  readonly table: string;
253
319
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
254
- if (!this.controlAdapter) {
255
- throw errorPostgresMigrationStackMissing();
256
- }
257
- return new DropTableCall(options.schema, options.table).toOp(this.controlAdapter);
320
+ return new DropTableCall(options.schema, options.table).toOp(
321
+ this.controlAdapterFor('dropTable'),
322
+ );
258
323
  }
259
324
 
260
325
  protected dropColumn(options: {
@@ -262,11 +327,8 @@ export abstract class PostgresMigration extends SqlMigration<
262
327
  readonly table: string;
263
328
  readonly column: string;
264
329
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
265
- if (!this.controlAdapter) {
266
- throw errorPostgresMigrationStackMissing();
267
- }
268
330
  return new DropColumnCall(options.schema, options.table, options.column).toOp(
269
- this.controlAdapter,
331
+ this.controlAdapterFor('dropColumn'),
270
332
  );
271
333
  }
272
334
 
@@ -276,15 +338,12 @@ export abstract class PostgresMigration extends SqlMigration<
276
338
  readonly column: string;
277
339
  readonly options: AlterColumnTypeOptions;
278
340
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
279
- if (!this.controlAdapter) {
280
- throw errorPostgresMigrationStackMissing();
281
- }
282
341
  return new AlterColumnTypeCall(
283
342
  options.schema,
284
343
  options.table,
285
344
  options.column,
286
345
  options.options,
287
- ).toOp(this.controlAdapter);
346
+ ).toOp(this.controlAdapterFor('alterColumnType'));
288
347
  }
289
348
 
290
349
  protected setNotNull(options: {
@@ -292,11 +351,8 @@ export abstract class PostgresMigration extends SqlMigration<
292
351
  readonly table: string;
293
352
  readonly column: string;
294
353
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
295
- if (!this.controlAdapter) {
296
- throw errorPostgresMigrationStackMissing();
297
- }
298
354
  return new SetNotNullCall(options.schema, options.table, options.column).toOp(
299
- this.controlAdapter,
355
+ this.controlAdapterFor('setNotNull'),
300
356
  );
301
357
  }
302
358
 
@@ -305,11 +361,8 @@ export abstract class PostgresMigration extends SqlMigration<
305
361
  readonly table: string;
306
362
  readonly column: string;
307
363
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
308
- if (!this.controlAdapter) {
309
- throw errorPostgresMigrationStackMissing();
310
- }
311
364
  return new DropNotNullCall(options.schema, options.table, options.column).toOp(
312
- this.controlAdapter,
365
+ this.controlAdapterFor('dropNotNull'),
313
366
  );
314
367
  }
315
368
 
@@ -320,16 +373,13 @@ export abstract class PostgresMigration extends SqlMigration<
320
373
  readonly defaultSql: string;
321
374
  readonly operationClass?: 'additive' | 'widening';
322
375
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
323
- if (!this.controlAdapter) {
324
- throw errorPostgresMigrationStackMissing();
325
- }
326
376
  return new SetDefaultCall(
327
377
  options.schema,
328
378
  options.table,
329
379
  options.column,
330
380
  options.defaultSql,
331
381
  options.operationClass,
332
- ).toOp(this.controlAdapter);
382
+ ).toOp(this.controlAdapterFor('setDefault'));
333
383
  }
334
384
 
335
385
  protected dropDefault(options: {
@@ -337,11 +387,8 @@ export abstract class PostgresMigration extends SqlMigration<
337
387
  readonly table: string;
338
388
  readonly column: string;
339
389
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
340
- if (!this.controlAdapter) {
341
- throw errorPostgresMigrationStackMissing();
342
- }
343
390
  return new DropDefaultCall(options.schema, options.table, options.column).toOp(
344
- this.controlAdapter,
391
+ this.controlAdapterFor('dropDefault'),
345
392
  );
346
393
  }
347
394
 
@@ -352,16 +399,13 @@ export abstract class PostgresMigration extends SqlMigration<
352
399
  readonly columns: readonly string[];
353
400
  readonly extras?: CreateIndexExtras;
354
401
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
355
- if (!this.controlAdapter) {
356
- throw errorPostgresMigrationStackMissing();
357
- }
358
402
  return new CreateIndexCall(
359
403
  options.schema,
360
404
  options.table,
361
405
  options.index,
362
406
  options.columns,
363
407
  options.extras,
364
- ).toOp(this.controlAdapter);
408
+ ).toOp(this.controlAdapterFor('createIndex'));
365
409
  }
366
410
 
367
411
  protected dropIndex(options: {
@@ -369,11 +413,8 @@ export abstract class PostgresMigration extends SqlMigration<
369
413
  readonly table: string;
370
414
  readonly index: string;
371
415
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
372
- if (!this.controlAdapter) {
373
- throw errorPostgresMigrationStackMissing();
374
- }
375
416
  return new DropIndexCall(options.schema, options.table, options.index).toOp(
376
- this.controlAdapter,
417
+ this.controlAdapterFor('dropIndex'),
377
418
  );
378
419
  }
379
420
 
@@ -383,9 +424,60 @@ export abstract class PostgresMigration extends SqlMigration<
383
424
  readonly id: string;
384
425
  readonly label?: string;
385
426
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
386
- if (!this.controlAdapter) {
387
- throw errorPostgresMigrationStackMissing();
388
- }
389
- return installExtension(options, this.controlAdapter);
427
+ return installExtension(options, this.controlAdapterFor('installExtension'));
428
+ }
429
+
430
+ protected enableRowLevelSecurity(options: {
431
+ readonly schema: string;
432
+ readonly table: string;
433
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
434
+ return new EnableRowLevelSecurityCall(options.schema, options.table).toOp(
435
+ this.controlAdapterFor('enableRowLevelSecurity'),
436
+ );
437
+ }
438
+
439
+ protected disableRowLevelSecurity(options: {
440
+ readonly schema: string;
441
+ readonly table: string;
442
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
443
+ return new DisableRowLevelSecurityCall(options.schema, options.table).toOp(
444
+ this.controlAdapterFor('disableRowLevelSecurity'),
445
+ );
446
+ }
447
+
448
+ protected createRlsPolicy(options: {
449
+ readonly schema: string;
450
+ readonly table: string;
451
+ readonly policy: PostgresRlsPolicyInput;
452
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
453
+ return new CreatePostgresRlsPolicyCall(
454
+ options.schema,
455
+ options.table,
456
+ new PostgresRlsPolicy(options.policy),
457
+ ).toOp(this.controlAdapterFor('createRlsPolicy'));
458
+ }
459
+
460
+ protected dropRlsPolicy(options: {
461
+ readonly schema: string;
462
+ readonly table: string;
463
+ readonly policy: string;
464
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
465
+ return new DropPostgresRlsPolicyCall(options.schema, options.table, options.policy).toOp(
466
+ this.controlAdapterFor('dropRlsPolicy'),
467
+ );
468
+ }
469
+
470
+ protected renameRlsPolicy(options: {
471
+ readonly schema: string;
472
+ readonly table: string;
473
+ readonly from: string;
474
+ readonly to: string;
475
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
476
+ return new RenamePostgresRlsPolicyCall(
477
+ options.schema,
478
+ options.table,
479
+ options.from,
480
+ options.to,
481
+ ).toOp(this.controlAdapterFor('renameRlsPolicy'));
390
482
  }
391
483
  }
@@ -45,15 +45,19 @@ export function renderCallsToTypeScript(
45
45
  calls: ReadonlyArray<OpFactoryCall>,
46
46
  meta: RenderMigrationMeta,
47
47
  ): string {
48
- const imports = buildImports(calls);
48
+ const imports = buildImports(calls, meta);
49
49
  const operationsBody = calls.map((c) => renderCall(c)).join(',\n');
50
+ const hasStart = meta.from !== null;
51
+ const startField = hasStart ? [' override readonly startContractJson = startContract;'] : [];
50
52
 
51
53
  return [
52
54
  shebangLineFor(detectScaffoldRuntime()),
53
55
  imports,
54
56
  '',
55
- 'export default class M extends Migration {',
56
- buildDescribeMethod(meta),
57
+ `export default class M extends Migration<${hasStart ? 'Start' : 'never'}, End> {`,
58
+ ...startField,
59
+ ' override readonly endContractJson = endContract;',
60
+ '',
57
61
  ' override get operations() {',
58
62
  ' return [',
59
63
  indent(operationsBody, 6),
@@ -70,8 +74,8 @@ function renderCall(call: OpFactoryCall): string {
70
74
  return call.renderTypeScript();
71
75
  }
72
76
 
73
- function buildImports(calls: ReadonlyArray<OpFactoryCall>): string {
74
- const requirements: ImportRequirement[] = [...BASE_IMPORTS];
77
+ function buildImports(calls: ReadonlyArray<OpFactoryCall>, meta: RenderMigrationMeta): string {
78
+ const requirements: ImportRequirement[] = [...BASE_IMPORTS, ...contractImports(meta)];
75
79
  for (const call of calls) {
76
80
  for (const req of call.importRequirements()) {
77
81
  requirements.push(req);
@@ -80,16 +84,39 @@ function buildImports(calls: ReadonlyArray<OpFactoryCall>): string {
80
84
  return renderImports(requirements);
81
85
  }
82
86
 
83
- function buildDescribeMethod(meta: RenderMigrationMeta): string {
84
- const lines: string[] = [];
85
- lines.push(' override describe() {');
86
- lines.push(' return {');
87
- lines.push(` from: ${JSON.stringify(meta.from)},`);
88
- lines.push(` to: ${JSON.stringify(meta.to)},`);
89
- lines.push(' };');
90
- lines.push(' }');
91
- lines.push('');
92
- return lines.join('\n');
87
+ /**
88
+ * The committed contract-JSON imports the scaffold reads its from/to identity
89
+ * from. `end-contract.json` is always present; `start-contract.json` is added
90
+ * only for a non-baseline migration (`meta.from !== null`). The matching
91
+ * `Contract` type imports (aliased `Start`/`End`) feed the
92
+ * `Migration<Start, End>` generics. Baseline emits `Migration<never, End>` with
93
+ * no start imports — `never` is the honest "no prior contract" Start.
94
+ */
95
+ function contractImports(meta: RenderMigrationMeta): readonly ImportRequirement[] {
96
+ const reqs: ImportRequirement[] = [
97
+ {
98
+ moduleSpecifier: './end-contract.json',
99
+ symbol: 'endContract',
100
+ kind: 'default',
101
+ attributes: { type: 'json' },
102
+ },
103
+ { moduleSpecifier: './end-contract', symbol: 'Contract', alias: 'End', typeOnly: true },
104
+ ];
105
+ if (meta.from !== null) {
106
+ reqs.push({
107
+ moduleSpecifier: './start-contract.json',
108
+ symbol: 'startContract',
109
+ kind: 'default',
110
+ attributes: { type: 'json' },
111
+ });
112
+ reqs.push({
113
+ moduleSpecifier: './start-contract',
114
+ symbol: 'Contract',
115
+ alias: 'Start',
116
+ typeOnly: true,
117
+ });
118
+ }
119
+ return reqs;
93
120
  }
94
121
 
95
122
  function indent(text: string, spaces: number): string {
@@ -0,0 +1,26 @@
1
+ import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
2
+ import type { SqlStorage } from '@prisma-next/sql-contract/types';
3
+ import { DEFAULT_NAMESPACE_ID } from '../namespace-ids';
4
+ import { isPostgresSchema } from '../postgres-schema';
5
+
6
+ /**
7
+ * Given the contract's storage and a namespace id, returns the live Postgres
8
+ * DDL schema name that namespace maps to. A named Postgres namespace dispatches
9
+ * to its `ddlSchemaName(storage)`; the unbound sentinel resolves to
10
+ * `DEFAULT_NAMESPACE_ID` (the search-path default for offline planning); a
11
+ * bare object payload (used by some tests) falls back to the namespace id
12
+ * itself.
13
+ */
14
+ export function resolveDdlSchemaForNamespaceStorage(
15
+ storage: SqlStorage,
16
+ namespaceId: string,
17
+ ): string {
18
+ if (namespaceId === UNBOUND_NAMESPACE_ID) {
19
+ return DEFAULT_NAMESPACE_ID;
20
+ }
21
+ const namespace = storage.namespaces[namespaceId];
22
+ if (namespace && isPostgresSchema(namespace)) {
23
+ return namespace.ddlSchemaName(storage);
24
+ }
25
+ return namespaceId;
26
+ }
@@ -12,7 +12,6 @@ import type {
12
12
  SqlMigrationRunnerSuccessValue,
13
13
  } from '@prisma-next/family-sql/control';
14
14
  import { runnerFailure, runnerSuccess } from '@prisma-next/family-sql/control';
15
- import { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';
16
15
  import type { MigrationRunnerResult } from '@prisma-next/framework-components/control';
17
16
  import { APP_SPACE_ID } from '@prisma-next/framework-components/control';
18
17
  import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
@@ -23,8 +22,6 @@ import { blindCast } from '@prisma-next/utils/casts';
23
22
  import { ifDefined } from '@prisma-next/utils/defined';
24
23
  import type { Result } from '@prisma-next/utils/result';
25
24
  import { notOk, ok, okVoid } from '@prisma-next/utils/result';
26
- import { parsePostgresDefault } from '../default-normalizer';
27
- import { normalizeSchemaNativeType } from '../native-type-normalizer';
28
25
  import type { PostgresPlanTargetDetails } from './planner-target-details';
29
26
 
30
27
  interface ApplyPlanSuccessValue {
@@ -124,30 +121,27 @@ class PostgresMigrationRunner implements SqlMigrationRunner<PostgresPlanTargetDe
124
121
  applyValue = applyResult.value;
125
122
  }
126
123
 
127
- // Schema verification on app-space only extension spaces don't
128
- // own user-facing tables in the live schema, and `verifySqlSchema`
129
- // matches the destination contract against the database, which
130
- // would flag every app-space table as "extra" when called against
131
- // an extension contract.
124
+ // Verify the schema on app-space only: extension spaces don't own
125
+ // user-facing tables, so verifying the destination contract against the
126
+ // database would flag every app-space table as "extra". Delegates to the
127
+ // family `verifySchema` the same comparison the CLI verify runs.
132
128
  if (space === APP_SPACE_ID) {
133
- const schemaIR = await this.family.introspect({
129
+ const schemaNode = await this.family.introspect({
134
130
  driver,
135
131
  contract: options.destinationContract,
136
132
  });
137
- const schemaVerifyResult = verifySqlSchema({
133
+ const schemaVerifyResult = this.family.verifySchema({
138
134
  contract: options.destinationContract,
139
- schema: schemaIR,
135
+ schema: schemaNode,
140
136
  strict: options.strictVerification ?? true,
141
- context: options.context ?? {},
142
- typeMetadataRegistry: this.family.typeMetadataRegistry,
143
137
  frameworkComponents: options.frameworkComponents,
144
- normalizeDefault: parsePostgresDefault,
145
- normalizeNativeType: normalizeSchemaNativeType,
146
138
  });
147
139
  if (!schemaVerifyResult.ok) {
148
140
  return runnerFailure('SCHEMA_VERIFY_FAILED', schemaVerifyResult.summary, {
149
141
  why: 'The resulting database schema does not satisfy the destination contract.',
150
- meta: { issues: schemaVerifyResult.schema.issues },
142
+ meta: {
143
+ issues: schemaVerifyResult.schema.issues,
144
+ },
151
145
  });
152
146
  }
153
147
  }
@@ -666,6 +660,7 @@ class PostgresMigrationRunner implements SqlMigrationRunner<PostgresPlanTargetDe
666
660
  migrationName: edge.dirName,
667
661
  migrationHash: edge.migrationHash,
668
662
  operations: edgeOps,
663
+ ...ifDefined('destinationContractJson', edge.destinationContractJson),
669
664
  },
670
665
  });
671
666
  }