@prisma-next/target-postgres 0.14.0-dev.8 → 0.14.0-dev.80

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 (266) hide show
  1. package/dist/authoring-Bi9aa8zG.mjs +574 -0
  2. package/dist/authoring-Bi9aa8zG.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-BemGS69L.mjs +927 -0
  15. package/dist/codecs-BemGS69L.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 +23 -7
  24. package/dist/contract-free.mjs.map +1 -1
  25. package/dist/control-policy-5LE2kwfb.mjs +1285 -0
  26. package/dist/control-policy-5LE2kwfb.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 +866 -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-BQzITB_e.mjs} +128 -6
  36. package/dist/ddl-BQzITB_e.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-DzL6vXAz.mjs +22 -0
  44. package/dist/descriptor-meta-DzL6vXAz.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-DULhiCNM.mjs +305 -0
  48. package/dist/diff-database-schema-DULhiCNM.mjs.map +1 -0
  49. package/dist/diff-database-schema.d.mts +46 -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-Bc2N3tMy.d.mts +170 -0
  68. package/dist/nodes-Bc2N3tMy.d.mts.map +1 -0
  69. package/dist/nodes-DJC5B8Id.mjs +192 -0
  70. package/dist/nodes-DJC5B8Id.mjs.map +1 -0
  71. package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-Bn9zDx4_.d.mts} +114 -15
  72. package/dist/op-factory-call-Bn9zDx4_.d.mts.map +1 -0
  73. package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-D6yu-PlS.mjs} +469 -32
  74. package/dist/op-factory-call-D6yu-PlS.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 +300 -3
  78. package/dist/pack.d.mts.map +1 -1
  79. package/dist/pack.mjs +1 -1
  80. package/dist/planner-DwDxdYxi.mjs +390 -0
  81. package/dist/planner-DwDxdYxi.mjs.map +1 -0
  82. package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-BKlmGDJl.mjs} +17 -28
  83. package/dist/planner-ddl-builders-BKlmGDJl.mjs.map +1 -0
  84. package/dist/planner-ddl-builders.d.mts +4 -6
  85. package/dist/planner-ddl-builders.d.mts.map +1 -1
  86. package/dist/planner-ddl-builders.mjs +2 -2
  87. package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -1
  88. package/dist/planner-identity-values.d.mts +8 -2
  89. package/dist/planner-identity-values.d.mts.map +1 -1
  90. package/dist/planner-identity-values.mjs +2 -2
  91. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-BEY1T0Xm.d.mts} +4 -4
  92. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-BEY1T0Xm.d.mts.map} +1 -1
  93. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-BGPpq56_.mjs} +3 -3
  94. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-BGPpq56_.mjs.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-CDXn2uaS.mjs} +5 -5
  98. package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-CDXn2uaS.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-serializer-k3TAcPMY.mjs → postgres-contract-view-C3LPCLP_.mjs} +45 -41
  109. package/dist/postgres-contract-view-C3LPCLP_.mjs.map +1 -0
  110. package/dist/postgres-contract-view-C9j5cqP0.d.mts +34 -0
  111. package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
  112. package/dist/postgres-database-schema-node-CJv5bfbs.d.mts +262 -0
  113. package/dist/postgres-database-schema-node-CJv5bfbs.d.mts.map +1 -0
  114. package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-DbckK1su.d.mts} +58 -9
  115. package/dist/postgres-migration-DbckK1su.d.mts.map +1 -0
  116. package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-et1td40f.mjs} +78 -45
  117. package/dist/postgres-migration-et1td40f.mjs.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-Cm-j0ZGM.mjs +190 -0
  123. package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs.map +1 -0
  124. package/dist/postgres-schema-DKq6s1P3.d.mts +269 -0
  125. package/dist/postgres-schema-DKq6s1P3.d.mts.map +1 -0
  126. package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-DYATroNx.mjs} +200 -11
  127. package/dist/postgres-schema-DYATroNx.mjs.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-DpGte50u.mjs +22 -0
  135. package/dist/resolve-ddl-schema-DpGte50u.mjs.map +1 -0
  136. package/dist/rls-canonicalize.d.mts +20 -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/{sql-utils-DcfMz4MQ.mjs → sql-utils-SU4FDvIV.mjs} +12 -3
  147. package/dist/{sql-utils-DcfMz4MQ.mjs.map → sql-utils-SU4FDvIV.mjs.map} +1 -1
  148. package/dist/sql-utils.d.mts +8 -1
  149. package/dist/sql-utils.d.mts.map +1 -1
  150. package/dist/sql-utils.mjs +2 -2
  151. package/dist/types.d.mts +4 -140
  152. package/dist/types.mjs +5 -2
  153. package/dist/wire-name-rHHtr1h0.mjs +75 -0
  154. package/dist/wire-name-rHHtr1h0.mjs.map +1 -0
  155. package/package.json +26 -20
  156. package/src/contract-free/checks.ts +153 -0
  157. package/src/contract-free/control-bootstrap.ts +20 -3
  158. package/src/contract-free/ddl.ts +98 -1
  159. package/src/core/authoring.ts +509 -2
  160. package/src/core/codec-helpers.ts +33 -7
  161. package/src/core/codec-ids.ts +1 -0
  162. package/src/core/codec-type-map.ts +2 -0
  163. package/src/core/codecs.ts +193 -12
  164. package/src/core/ddl/nodes.ts +185 -2
  165. package/src/core/default-normalizer.ts +122 -2
  166. package/src/core/descriptor-meta.ts +10 -1
  167. package/src/core/entity-kinds.ts +41 -0
  168. package/src/core/errors.ts +14 -12
  169. package/src/core/migrations/bound-schema.ts +10 -0
  170. package/src/core/migrations/column-ddl-rendering.ts +117 -0
  171. package/src/core/migrations/contract-to-postgres-database-schema-node.ts +189 -0
  172. package/src/core/migrations/control-policy.ts +217 -65
  173. package/src/core/migrations/diff-database-schema.ts +252 -0
  174. package/src/core/migrations/issue-planner.ts +817 -656
  175. package/src/core/migrations/op-factory-call.ts +383 -23
  176. package/src/core/migrations/operations/columns.ts +24 -12
  177. package/src/core/migrations/operations/constraints.ts +1 -1
  178. package/src/core/migrations/operations/data-transform.ts +6 -0
  179. package/src/core/migrations/operations/dependencies.ts +2 -1
  180. package/src/core/migrations/operations/native-enum-types.ts +62 -0
  181. package/src/core/migrations/operations/rls.ts +187 -0
  182. package/src/core/migrations/operations/shared.ts +0 -30
  183. package/src/core/migrations/planner-ddl-builders.ts +31 -59
  184. package/src/core/migrations/planner-identity-values.ts +1 -1
  185. package/src/core/migrations/planner-recipes.ts +31 -13
  186. package/src/core/migrations/planner-sql-checks.ts +1 -1
  187. package/src/core/migrations/planner-strategies.ts +248 -216
  188. package/src/core/migrations/planner-target-details.ts +3 -1
  189. package/src/core/migrations/planner.ts +357 -67
  190. package/src/core/migrations/postgres-migration.ts +118 -86
  191. package/src/core/migrations/render-typescript.ts +42 -15
  192. package/src/core/migrations/resolve-ddl-schema.ts +26 -0
  193. package/src/core/migrations/runner.ts +11 -16
  194. package/src/core/migrations/verify-postgres-namespaces.ts +46 -31
  195. package/src/core/namespace-ids.ts +3 -0
  196. package/src/core/postgres-contract-serializer.ts +46 -71
  197. package/src/core/postgres-contract-view.ts +48 -0
  198. package/src/core/postgres-native-enum.ts +61 -0
  199. package/src/core/postgres-rls-enablement.ts +34 -0
  200. package/src/core/postgres-rls-policy.ts +64 -0
  201. package/src/core/postgres-role.ts +59 -0
  202. package/src/core/postgres-schema-verifier.ts +10 -7
  203. package/src/core/postgres-schema.ts +85 -15
  204. package/src/core/postgres-validators.ts +34 -0
  205. package/src/core/psl-infer/infer-psl-contract.ts +1273 -0
  206. package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
  207. package/src/core/psl-infer/postgres-type-map.ts +128 -0
  208. package/src/core/rls/canonicalize.ts +48 -0
  209. package/src/core/rls/wire-name.ts +33 -0
  210. package/src/core/schema-ir/node-storage-coordinate.ts +26 -0
  211. package/src/core/schema-ir/postgres-database-schema-node.ts +61 -0
  212. package/src/core/schema-ir/postgres-namespace-schema-node.ts +70 -0
  213. package/src/core/schema-ir/postgres-native-enum-schema-node.ts +83 -0
  214. package/src/core/schema-ir/postgres-policy-schema-node.ts +90 -0
  215. package/src/core/schema-ir/postgres-role-schema-node.ts +65 -0
  216. package/src/core/schema-ir/postgres-table-schema-node.ts +140 -0
  217. package/src/core/schema-ir/schema-node-kinds.ts +122 -0
  218. package/src/core/sql-utils.ts +15 -2
  219. package/src/exports/codecs.ts +3 -0
  220. package/src/exports/contract-free.ts +11 -1
  221. package/src/exports/control.ts +27 -33
  222. package/src/exports/ddl.ts +8 -0
  223. package/src/exports/diff-database-schema.ts +7 -0
  224. package/src/exports/issue-planner.ts +1 -1
  225. package/src/exports/migration.ts +1 -0
  226. package/src/exports/op-factory-call.ts +4 -0
  227. package/src/exports/planner-ddl-builders.ts +0 -2
  228. package/src/exports/planner-identity-values.ts +4 -1
  229. package/src/exports/planner.ts +1 -0
  230. package/src/exports/rls-canonicalize.ts +7 -0
  231. package/src/exports/runtime.ts +1 -0
  232. package/src/exports/schema-ir-annotations.ts +1 -0
  233. package/src/exports/sql-utils.ts +1 -0
  234. package/src/exports/types.ts +37 -0
  235. package/dist/codec-ids-BvytN2P8.mjs.map +0 -1
  236. package/dist/codec-ids-CnXu9Qy3.d.mts.map +0 -1
  237. package/dist/codec-types-DHCkwPKE.d.mts.map +0 -1
  238. package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
  239. package/dist/ddl-QDyOSeLc.mjs.map +0 -1
  240. package/dist/default-normalizer-DyyCHQWs.mjs +0 -131
  241. package/dist/default-normalizer-DyyCHQWs.mjs.map +0 -1
  242. package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
  243. package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
  244. package/dist/errors-CUk87ByX.mjs +0 -33
  245. package/dist/errors-CUk87ByX.mjs.map +0 -1
  246. package/dist/issue-planner-DL6g3CmE.mjs +0 -824
  247. package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
  248. package/dist/native-type-normalizer-Bc9XJzWC.mjs +0 -38
  249. package/dist/native-type-normalizer-Bc9XJzWC.mjs.map +0 -1
  250. package/dist/nodes-Bbhs2rwj.mjs +0 -76
  251. package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
  252. package/dist/nodes-pLeLgdis.d.mts +0 -67
  253. package/dist/nodes-pLeLgdis.d.mts.map +0 -1
  254. package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
  255. package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
  256. package/dist/planner-Bs_baQax.mjs +0 -324
  257. package/dist/planner-Bs_baQax.mjs.map +0 -1
  258. package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
  259. package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
  260. package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
  261. package/dist/postgres-migration-B5jKrXv3.mjs.map +0 -1
  262. package/dist/postgres-migration-Y4YBJqkS.d.mts.map +0 -1
  263. package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
  264. package/dist/render-typescript-KMgosran.mjs.map +0 -1
  265. package/dist/types.d.mts.map +0 -1
  266. package/src/core/postgres-enum-type-schema.ts +0 -17
@@ -3,18 +3,22 @@ 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';
9
11
  import {
10
12
  AddCheckConstraintCall,
11
13
  AddColumnCall,
12
14
  AddForeignKeyCall,
15
+ AddNativeEnumValueCall,
13
16
  AddPrimaryKeyCall,
14
17
  AddUniqueCall,
15
18
  AlterColumnTypeCall,
16
19
  type AlterColumnTypeOptions,
17
20
  CreateIndexCall,
21
+ CreateNativeEnumTypeCall,
18
22
  CreateSchemaCall,
19
23
  CreateTableCall,
20
24
  DropCheckConstraintCall,
@@ -22,6 +26,7 @@ import {
22
26
  DropConstraintCall,
23
27
  DropDefaultCall,
24
28
  DropIndexCall,
29
+ DropNativeEnumTypeCall,
25
30
  DropNotNullCall,
26
31
  DropTableCall,
27
32
  SetDefaultCall,
@@ -60,20 +65,31 @@ import type { PostgresPlanTargetDetails } from './planner-target-details';
60
65
  * is an antipattern in a migration. (The unbound/unspecified namespace concept
61
66
  * remains for SQLite, which has no schemas, and for Mongo's connection `db`.)
62
67
  */
63
- export abstract class PostgresMigration extends SqlMigration<
64
- PostgresPlanTargetDetails,
65
- 'postgres'
66
- > {
68
+ export abstract class PostgresMigration<
69
+ Start extends Contract<SqlStorage> = Contract<SqlStorage>,
70
+ End extends Contract<SqlStorage> = Contract<SqlStorage>,
71
+ > extends SqlMigration<PostgresPlanTargetDetails, 'postgres', Start, End> {
67
72
  readonly targetId = 'postgres' as const;
68
73
 
69
74
  /**
70
75
  * Materialized Postgres control adapter, created once per migration
71
76
  * 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.
77
+ * was instantiated without a stack (test fixtures); `controlAdapterFor`
78
+ * throws a PN-MIG-2007 in that case to surface the misuse.
74
79
  */
75
80
  protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;
76
81
 
82
+ #endView = new MigrationContractViews<PostgresContractView<End>>(
83
+ this,
84
+ 'PostgresMigration',
85
+ (json) => PostgresContractView.fromJson<End>(json),
86
+ );
87
+ #startView = new MigrationContractViews<PostgresContractView<Start>>(
88
+ this,
89
+ 'PostgresMigration',
90
+ (json) => PostgresContractView.fromJson<Start>(json),
91
+ );
92
+
77
93
  constructor(stack?: ControlStack<'sql', 'postgres'>) {
78
94
  super(stack);
79
95
  // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;
@@ -84,6 +100,35 @@ export abstract class PostgresMigration extends SqlMigration<
84
100
  : undefined;
85
101
  }
86
102
 
103
+ /**
104
+ * Returns the materialized control adapter, or throws a PN-MIG-2007 naming
105
+ * `operation` when the migration was constructed without a `ControlStack`.
106
+ * Single home for the null-check that every DDL/DML method shares.
107
+ */
108
+ private controlAdapterFor(operation: string): SqlControlAdapter<'postgres'> {
109
+ if (!this.controlAdapter) {
110
+ throw errorPostgresMigrationStackMissing(operation);
111
+ }
112
+ return this.controlAdapter;
113
+ }
114
+
115
+ /**
116
+ * The typed, schema-qualified Postgres view over this migration's end-state
117
+ * contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws
118
+ * if no `endContractJson` was provided.
119
+ */
120
+ get endContract(): PostgresContractView<End> {
121
+ return this.#endView.endContract;
122
+ }
123
+
124
+ /**
125
+ * The typed Postgres view over this migration's start-state contract, or
126
+ * `null` for a baseline migration (no `startContractJson`).
127
+ */
128
+ get startContract(): PostgresContractView<Start> | null {
129
+ return this.#startView.startContract;
130
+ }
131
+
87
132
  /**
88
133
  * Instance-method wrapper around the free `dataTransform` factory that
89
134
  * supplies the stored control adapter. Authors call this from inside
@@ -94,10 +139,7 @@ export abstract class PostgresMigration extends SqlMigration<
94
139
  name: string,
95
140
  options: DataTransformOptions,
96
141
  ): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
97
- if (!this.controlAdapter) {
98
- throw errorPostgresMigrationStackMissing();
99
- }
100
- return dataTransform(contract, name, options, this.controlAdapter);
142
+ return dataTransform(contract, name, options, this.controlAdapterFor('dataTransform'));
101
143
  }
102
144
 
103
145
  /**
@@ -112,15 +154,12 @@ export abstract class PostgresMigration extends SqlMigration<
112
154
  readonly columns: readonly DdlColumn[];
113
155
  readonly constraints?: readonly DdlTableConstraint[];
114
156
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
115
- if (!this.controlAdapter) {
116
- throw errorPostgresMigrationStackMissing();
117
- }
118
157
  return new CreateTableCall(
119
158
  options.schema,
120
159
  options.table,
121
160
  options.columns,
122
161
  options.constraints,
123
- ).toOp(this.controlAdapter);
162
+ ).toOp(this.controlAdapterFor('createTable'));
124
163
  }
125
164
 
126
165
  /**
@@ -132,10 +171,52 @@ export abstract class PostgresMigration extends SqlMigration<
132
171
  readonly schema: string;
133
172
  readonly ifNotExists?: boolean;
134
173
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
135
- if (!this.controlAdapter) {
136
- throw errorPostgresMigrationStackMissing();
137
- }
138
- return new CreateSchemaCall(options.schema).toOp(this.controlAdapter);
174
+ return new CreateSchemaCall(options.schema).toOp(this.controlAdapterFor('createSchema'));
175
+ }
176
+
177
+ /**
178
+ * Emit a `CREATE TYPE ... AS ENUM (...)` migration operation for a managed
179
+ * native enum. Builds a typed DDL node and lowers it through the stored
180
+ * control adapter (members render in declaration order). Throws if no adapter
181
+ * is present.
182
+ */
183
+ protected createNativeEnumType(options: {
184
+ readonly schema: string;
185
+ readonly typeName: string;
186
+ readonly members: readonly string[];
187
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
188
+ return new CreateNativeEnumTypeCall(options.schema, options.typeName, options.members).toOp(
189
+ this.controlAdapterFor('createNativeEnumType'),
190
+ );
191
+ }
192
+
193
+ /**
194
+ * Emit a `DROP TYPE` migration operation for a managed native enum, lowered
195
+ * through the stored control adapter. Throws if no adapter is present.
196
+ */
197
+ protected dropNativeEnumType(options: {
198
+ readonly schema: string;
199
+ readonly typeName: string;
200
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
201
+ return new DropNativeEnumTypeCall(options.schema, options.typeName).toOp(
202
+ this.controlAdapterFor('dropNativeEnumType'),
203
+ );
204
+ }
205
+
206
+ /**
207
+ * Emit an `ALTER TYPE ... ADD VALUE` migration operation appending one
208
+ * member to a managed native enum, lowered through the stored control
209
+ * adapter. Throws if no adapter is present. Every appended value is its
210
+ * own operation — call this once per value to append more than one.
211
+ */
212
+ protected addNativeEnumValue(options: {
213
+ readonly schema: string;
214
+ readonly typeName: string;
215
+ readonly value: string;
216
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
217
+ return new AddNativeEnumValueCall(options.schema, options.typeName, options.value).toOp(
218
+ this.controlAdapterFor('addNativeEnumValue'),
219
+ );
139
220
  }
140
221
 
141
222
  protected addColumn(options: {
@@ -143,11 +224,8 @@ export abstract class PostgresMigration extends SqlMigration<
143
224
  readonly table: string;
144
225
  readonly column: DdlColumn;
145
226
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
146
- if (!this.controlAdapter) {
147
- throw errorPostgresMigrationStackMissing();
148
- }
149
227
  return new AddColumnCall(options.schema, options.table, options.column).toOp(
150
- this.controlAdapter,
228
+ this.controlAdapterFor('addColumn'),
151
229
  );
152
230
  }
153
231
 
@@ -157,15 +235,12 @@ export abstract class PostgresMigration extends SqlMigration<
157
235
  readonly constraint: string;
158
236
  readonly columns: readonly string[];
159
237
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
160
- if (!this.controlAdapter) {
161
- throw errorPostgresMigrationStackMissing();
162
- }
163
238
  return new AddPrimaryKeyCall(
164
239
  options.schema,
165
240
  options.table,
166
241
  options.constraint,
167
242
  options.columns,
168
- ).toOp(this.controlAdapter);
243
+ ).toOp(this.controlAdapterFor('addPrimaryKey'));
169
244
  }
170
245
 
171
246
  protected addUnique(options: {
@@ -174,15 +249,12 @@ export abstract class PostgresMigration extends SqlMigration<
174
249
  readonly constraint: string;
175
250
  readonly columns: readonly string[];
176
251
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
177
- if (!this.controlAdapter) {
178
- throw errorPostgresMigrationStackMissing();
179
- }
180
252
  return new AddUniqueCall(
181
253
  options.schema,
182
254
  options.table,
183
255
  options.constraint,
184
256
  options.columns,
185
- ).toOp(this.controlAdapter);
257
+ ).toOp(this.controlAdapterFor('addUnique'));
186
258
  }
187
259
 
188
260
  protected addForeignKey(options: {
@@ -190,11 +262,8 @@ export abstract class PostgresMigration extends SqlMigration<
190
262
  readonly table: string;
191
263
  readonly foreignKey: ForeignKeySpec;
192
264
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
193
- if (!this.controlAdapter) {
194
- throw errorPostgresMigrationStackMissing();
195
- }
196
265
  return new AddForeignKeyCall(options.schema, options.table, options.foreignKey).toOp(
197
- this.controlAdapter,
266
+ this.controlAdapterFor('addForeignKey'),
198
267
  );
199
268
  }
200
269
 
@@ -205,16 +274,13 @@ export abstract class PostgresMigration extends SqlMigration<
205
274
  readonly column: string;
206
275
  readonly values: readonly string[];
207
276
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
208
- if (!this.controlAdapter) {
209
- throw errorPostgresMigrationStackMissing();
210
- }
211
277
  return new AddCheckConstraintCall(
212
278
  options.schema,
213
279
  options.table,
214
280
  options.constraint,
215
281
  options.column,
216
282
  options.values,
217
- ).toOp(this.controlAdapter);
283
+ ).toOp(this.controlAdapterFor('addCheckConstraint'));
218
284
  }
219
285
 
220
286
  protected dropCheckConstraint(options: {
@@ -222,11 +288,8 @@ export abstract class PostgresMigration extends SqlMigration<
222
288
  readonly table: string;
223
289
  readonly constraint: string;
224
290
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
225
- if (!this.controlAdapter) {
226
- throw errorPostgresMigrationStackMissing();
227
- }
228
291
  return new DropCheckConstraintCall(options.schema, options.table, options.constraint).toOp(
229
- this.controlAdapter,
292
+ this.controlAdapterFor('dropCheckConstraint'),
230
293
  );
231
294
  }
232
295
 
@@ -236,25 +299,21 @@ export abstract class PostgresMigration extends SqlMigration<
236
299
  readonly constraint: string;
237
300
  readonly kind?: 'foreignKey' | 'unique' | 'primaryKey';
238
301
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
239
- if (!this.controlAdapter) {
240
- throw errorPostgresMigrationStackMissing();
241
- }
242
302
  return new DropConstraintCall(
243
303
  options.schema,
244
304
  options.table,
245
305
  options.constraint,
246
306
  options.kind ?? 'unique',
247
- ).toOp(this.controlAdapter);
307
+ ).toOp(this.controlAdapterFor('dropConstraint'));
248
308
  }
249
309
 
250
310
  protected dropTable(options: {
251
311
  readonly schema: string;
252
312
  readonly table: string;
253
313
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
254
- if (!this.controlAdapter) {
255
- throw errorPostgresMigrationStackMissing();
256
- }
257
- return new DropTableCall(options.schema, options.table).toOp(this.controlAdapter);
314
+ return new DropTableCall(options.schema, options.table).toOp(
315
+ this.controlAdapterFor('dropTable'),
316
+ );
258
317
  }
259
318
 
260
319
  protected dropColumn(options: {
@@ -262,11 +321,8 @@ export abstract class PostgresMigration extends SqlMigration<
262
321
  readonly table: string;
263
322
  readonly column: string;
264
323
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
265
- if (!this.controlAdapter) {
266
- throw errorPostgresMigrationStackMissing();
267
- }
268
324
  return new DropColumnCall(options.schema, options.table, options.column).toOp(
269
- this.controlAdapter,
325
+ this.controlAdapterFor('dropColumn'),
270
326
  );
271
327
  }
272
328
 
@@ -276,15 +332,12 @@ export abstract class PostgresMigration extends SqlMigration<
276
332
  readonly column: string;
277
333
  readonly options: AlterColumnTypeOptions;
278
334
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
279
- if (!this.controlAdapter) {
280
- throw errorPostgresMigrationStackMissing();
281
- }
282
335
  return new AlterColumnTypeCall(
283
336
  options.schema,
284
337
  options.table,
285
338
  options.column,
286
339
  options.options,
287
- ).toOp(this.controlAdapter);
340
+ ).toOp(this.controlAdapterFor('alterColumnType'));
288
341
  }
289
342
 
290
343
  protected setNotNull(options: {
@@ -292,11 +345,8 @@ export abstract class PostgresMigration extends SqlMigration<
292
345
  readonly table: string;
293
346
  readonly column: string;
294
347
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
295
- if (!this.controlAdapter) {
296
- throw errorPostgresMigrationStackMissing();
297
- }
298
348
  return new SetNotNullCall(options.schema, options.table, options.column).toOp(
299
- this.controlAdapter,
349
+ this.controlAdapterFor('setNotNull'),
300
350
  );
301
351
  }
302
352
 
@@ -305,11 +355,8 @@ export abstract class PostgresMigration extends SqlMigration<
305
355
  readonly table: string;
306
356
  readonly column: string;
307
357
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
308
- if (!this.controlAdapter) {
309
- throw errorPostgresMigrationStackMissing();
310
- }
311
358
  return new DropNotNullCall(options.schema, options.table, options.column).toOp(
312
- this.controlAdapter,
359
+ this.controlAdapterFor('dropNotNull'),
313
360
  );
314
361
  }
315
362
 
@@ -320,16 +367,13 @@ export abstract class PostgresMigration extends SqlMigration<
320
367
  readonly defaultSql: string;
321
368
  readonly operationClass?: 'additive' | 'widening';
322
369
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
323
- if (!this.controlAdapter) {
324
- throw errorPostgresMigrationStackMissing();
325
- }
326
370
  return new SetDefaultCall(
327
371
  options.schema,
328
372
  options.table,
329
373
  options.column,
330
374
  options.defaultSql,
331
375
  options.operationClass,
332
- ).toOp(this.controlAdapter);
376
+ ).toOp(this.controlAdapterFor('setDefault'));
333
377
  }
334
378
 
335
379
  protected dropDefault(options: {
@@ -337,11 +381,8 @@ export abstract class PostgresMigration extends SqlMigration<
337
381
  readonly table: string;
338
382
  readonly column: string;
339
383
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
340
- if (!this.controlAdapter) {
341
- throw errorPostgresMigrationStackMissing();
342
- }
343
384
  return new DropDefaultCall(options.schema, options.table, options.column).toOp(
344
- this.controlAdapter,
385
+ this.controlAdapterFor('dropDefault'),
345
386
  );
346
387
  }
347
388
 
@@ -352,16 +393,13 @@ export abstract class PostgresMigration extends SqlMigration<
352
393
  readonly columns: readonly string[];
353
394
  readonly extras?: CreateIndexExtras;
354
395
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
355
- if (!this.controlAdapter) {
356
- throw errorPostgresMigrationStackMissing();
357
- }
358
396
  return new CreateIndexCall(
359
397
  options.schema,
360
398
  options.table,
361
399
  options.index,
362
400
  options.columns,
363
401
  options.extras,
364
- ).toOp(this.controlAdapter);
402
+ ).toOp(this.controlAdapterFor('createIndex'));
365
403
  }
366
404
 
367
405
  protected dropIndex(options: {
@@ -369,11 +407,8 @@ export abstract class PostgresMigration extends SqlMigration<
369
407
  readonly table: string;
370
408
  readonly index: string;
371
409
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
372
- if (!this.controlAdapter) {
373
- throw errorPostgresMigrationStackMissing();
374
- }
375
410
  return new DropIndexCall(options.schema, options.table, options.index).toOp(
376
- this.controlAdapter,
411
+ this.controlAdapterFor('dropIndex'),
377
412
  );
378
413
  }
379
414
 
@@ -383,9 +418,6 @@ export abstract class PostgresMigration extends SqlMigration<
383
418
  readonly id: string;
384
419
  readonly label?: string;
385
420
  }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
386
- if (!this.controlAdapter) {
387
- throw errorPostgresMigrationStackMissing();
388
- }
389
- return installExtension(options, this.controlAdapter);
421
+ return installExtension(options, this.controlAdapterFor('installExtension'));
390
422
  }
391
423
  }
@@ -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
  }