@prisma-next/target-postgres 0.12.0 → 0.13.0-dev.2

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 (207) hide show
  1. package/dist/{codec-ids-D9fJ4HP5.d.mts → codec-ids-B1vOchLE.d.mts} +3 -2
  2. package/dist/codec-ids-B1vOchLE.d.mts.map +1 -0
  3. package/dist/{codec-ids-C5qzBqus.mjs → codec-ids-CTikp1if.mjs} +3 -2
  4. package/dist/codec-ids-CTikp1if.mjs.map +1 -0
  5. package/dist/codec-ids.d.mts +2 -2
  6. package/dist/codec-ids.mjs +2 -2
  7. package/dist/{codec-types-CRlHq7Cz.d.mts → codec-types-CnFiNML4.d.mts} +8 -9
  8. package/dist/codec-types-CnFiNML4.d.mts.map +1 -0
  9. package/dist/codec-types.d.mts +2 -2
  10. package/dist/{codecs-Dud5KDNk.d.mts → codecs-CBpEv4s5.d.mts} +33 -35
  11. package/dist/codecs-CBpEv4s5.d.mts.map +1 -0
  12. package/dist/codecs.d.mts +1 -1
  13. package/dist/codecs.mjs +37 -2
  14. package/dist/codecs.mjs.map +1 -1
  15. package/dist/contract-free.d.mts +80 -0
  16. package/dist/contract-free.d.mts.map +1 -0
  17. package/dist/contract-free.mjs +117 -0
  18. package/dist/contract-free.mjs.map +1 -0
  19. package/dist/control.d.mts +1 -1
  20. package/dist/control.d.mts.map +1 -1
  21. package/dist/control.mjs +66 -40
  22. package/dist/control.mjs.map +1 -1
  23. package/dist/{data-transform-CdtGUWp2.mjs → data-transform-D25tLeYU.mjs} +1 -1
  24. package/dist/{data-transform-CdtGUWp2.mjs.map → data-transform-D25tLeYU.mjs.map} +1 -1
  25. package/dist/{data-transform-bmOKkygi.d.mts → data-transform-DGOqcLrf.d.mts} +2 -2
  26. package/dist/{data-transform-bmOKkygi.d.mts.map → data-transform-DGOqcLrf.d.mts.map} +1 -1
  27. package/dist/data-transform.d.mts +1 -1
  28. package/dist/data-transform.mjs +1 -1
  29. package/dist/ddl-77SyXgFt.mjs +30 -0
  30. package/dist/ddl-77SyXgFt.mjs.map +1 -0
  31. package/dist/ddl.d.mts +2 -0
  32. package/dist/ddl.mjs +2 -0
  33. package/dist/{default-normalizer-CRscvhS5.mjs → default-normalizer-DyyCHQWs.mjs} +1 -1
  34. package/dist/{default-normalizer-CRscvhS5.mjs.map → default-normalizer-DyyCHQWs.mjs.map} +1 -1
  35. package/dist/default-normalizer.mjs +1 -1
  36. package/dist/descriptor-meta-DKmj-IMN.mjs +14 -0
  37. package/dist/descriptor-meta-DKmj-IMN.mjs.map +1 -0
  38. package/dist/{descriptor-meta-DLA2xV6B.mjs → descriptor-meta-runtime-My8_s4cs.mjs} +82 -78
  39. package/dist/descriptor-meta-runtime-My8_s4cs.mjs.map +1 -0
  40. package/dist/{enum-planning-Dz0Ye3Lb.mjs → enum-planning-BCyvlFHk.mjs} +0 -0
  41. package/dist/{enum-planning-Dz0Ye3Lb.mjs.map → enum-planning-BCyvlFHk.mjs.map} +1 -1
  42. package/dist/enum-planning.d.mts +1 -1
  43. package/dist/enum-planning.mjs +1 -1
  44. package/dist/{errors--zafB5_n.mjs → errors-CUk87ByX.mjs} +1 -1
  45. package/dist/{errors--zafB5_n.mjs.map → errors-CUk87ByX.mjs.map} +1 -1
  46. package/dist/errors.d.mts.map +1 -1
  47. package/dist/errors.mjs +1 -1
  48. package/dist/{issue-planner-ByQhUzS4.mjs → issue-planner-Br0pt1Ea.mjs} +130 -28
  49. package/dist/issue-planner-Br0pt1Ea.mjs.map +1 -0
  50. package/dist/issue-planner.d.mts +1 -1
  51. package/dist/issue-planner.d.mts.map +1 -1
  52. package/dist/issue-planner.mjs +1 -1
  53. package/dist/migration.d.mts +7 -8
  54. package/dist/migration.d.mts.map +1 -1
  55. package/dist/migration.mjs +5 -4
  56. package/dist/migration.mjs.map +1 -1
  57. package/dist/{native-type-normalizer-ClNPq__-.mjs → native-type-normalizer-Bc9XJzWC.mjs} +1 -1
  58. package/dist/{native-type-normalizer-ClNPq__-.mjs.map → native-type-normalizer-Bc9XJzWC.mjs.map} +1 -1
  59. package/dist/native-type-normalizer.mjs +1 -1
  60. package/dist/nodes-779hmCfL.d.mts +40 -0
  61. package/dist/nodes-779hmCfL.d.mts.map +1 -0
  62. package/dist/nodes-DZk2JZG3.mjs +47 -0
  63. package/dist/nodes-DZk2JZG3.mjs.map +1 -0
  64. package/dist/op-factory-call-D2aAUhmS.mjs +1307 -0
  65. package/dist/op-factory-call-D2aAUhmS.mjs.map +1 -0
  66. package/dist/{op-factory-call-Drccm_JD.d.mts → op-factory-call-DMA86_2D.d.mts} +39 -14
  67. package/dist/op-factory-call-DMA86_2D.d.mts.map +1 -0
  68. package/dist/op-factory-call.d.mts +2 -2
  69. package/dist/op-factory-call.mjs +2 -2
  70. package/dist/pack.d.mts +13 -12
  71. package/dist/pack.d.mts.map +1 -1
  72. package/dist/pack.mjs +1 -1
  73. package/dist/planner-CAYPJObw.mjs +344 -0
  74. package/dist/planner-CAYPJObw.mjs.map +1 -0
  75. package/dist/{planner-ddl-builders-BxRCSn_b.mjs → planner-ddl-builders-Cw2n2llW.mjs} +7 -30
  76. package/dist/planner-ddl-builders-Cw2n2llW.mjs.map +1 -0
  77. package/dist/planner-ddl-builders.d.mts +6 -7
  78. package/dist/planner-ddl-builders.d.mts.map +1 -1
  79. package/dist/planner-ddl-builders.mjs +2 -2
  80. package/dist/{planner-identity-values-ojX-6cPV.mjs → planner-identity-values-BIpa5p2I.mjs} +1 -1
  81. package/dist/{planner-identity-values-ojX-6cPV.mjs.map → planner-identity-values-BIpa5p2I.mjs.map} +1 -1
  82. package/dist/planner-identity-values.mjs +1 -1
  83. package/dist/{planner-produced-postgres-migration-p-VKkCia.d.mts → planner-produced-postgres-migration-B4EDvLdz.d.mts} +5 -4
  84. package/dist/planner-produced-postgres-migration-B4EDvLdz.d.mts.map +1 -0
  85. package/dist/{planner-produced-postgres-migration-N1yqYg20.mjs → planner-produced-postgres-migration-NSEhWL0L.mjs} +8 -6
  86. package/dist/planner-produced-postgres-migration-NSEhWL0L.mjs.map +1 -0
  87. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  88. package/dist/planner-produced-postgres-migration.mjs +1 -1
  89. package/dist/{planner-schema-lookup-BGyukuzG.mjs → planner-schema-lookup-CiVaAQP-.mjs} +1 -1
  90. package/dist/{planner-schema-lookup-BGyukuzG.mjs.map → planner-schema-lookup-CiVaAQP-.mjs.map} +1 -1
  91. package/dist/planner-schema-lookup.mjs +1 -1
  92. package/dist/{planner-sql-checks-D3H-xOO1.mjs → planner-sql-checks-DAdhnI2c.mjs} +41 -30
  93. package/dist/planner-sql-checks-DAdhnI2c.mjs.map +1 -0
  94. package/dist/planner-sql-checks.d.mts.map +1 -1
  95. package/dist/planner-sql-checks.mjs +1 -1
  96. package/dist/{planner-target-details-CIj61DUj.d.mts → planner-target-details-CIY6tLeo.d.mts} +2 -2
  97. package/dist/planner-target-details-CIY6tLeo.d.mts.map +1 -0
  98. package/dist/planner-target-details.d.mts +2 -2
  99. package/dist/planner-type-resolution-836DExFN.mjs +20 -0
  100. package/dist/planner-type-resolution-836DExFN.mjs.map +1 -0
  101. package/dist/planner.d.mts +7 -3
  102. package/dist/planner.d.mts.map +1 -1
  103. package/dist/planner.mjs +1 -1
  104. package/dist/{postgres-contract-serializer-YJvjKrmo.mjs → postgres-contract-serializer-DYTyXjPf.mjs} +33 -24
  105. package/dist/postgres-contract-serializer-DYTyXjPf.mjs.map +1 -0
  106. package/dist/{postgres-enum-type-CNhPTDhy.d.mts → postgres-enum-type-BVn63a89.d.mts} +4 -1
  107. package/dist/postgres-enum-type-BVn63a89.d.mts.map +1 -0
  108. package/dist/{postgres-enum-type-DS-KLVRH.mjs → postgres-enum-type-DPKqCBem.mjs} +2 -1
  109. package/dist/postgres-enum-type-DPKqCBem.mjs.map +1 -0
  110. package/dist/{postgres-migration-uADmx0dW.mjs → postgres-migration-COore9Mz.mjs} +23 -3
  111. package/dist/postgres-migration-COore9Mz.mjs.map +1 -0
  112. package/dist/{postgres-migration-Fd4fQkBw.d.mts → postgres-migration-DZ_gLUOW.d.mts} +25 -3
  113. package/dist/postgres-migration-DZ_gLUOW.d.mts.map +1 -0
  114. package/dist/{postgres-schema-Bm7vjlOv.mjs → postgres-schema-BuxCxbvB.mjs} +29 -14
  115. package/dist/postgres-schema-BuxCxbvB.mjs.map +1 -0
  116. package/dist/{render-ops-BC2PtCkj.mjs → render-ops-BpjstrKQ.mjs} +4 -3
  117. package/dist/{render-ops-BC2PtCkj.mjs.map → render-ops-BpjstrKQ.mjs.map} +1 -1
  118. package/dist/render-ops.d.mts +3 -2
  119. package/dist/render-ops.d.mts.map +1 -1
  120. package/dist/render-ops.mjs +1 -1
  121. package/dist/{render-typescript-CPk7hhWH.mjs → render-typescript-KMgosran.mjs} +5 -2
  122. package/dist/render-typescript-KMgosran.mjs.map +1 -0
  123. package/dist/render-typescript.mjs +1 -1
  124. package/dist/runtime.d.mts.map +1 -1
  125. package/dist/runtime.mjs +3 -3
  126. package/dist/runtime.mjs.map +1 -1
  127. package/dist/{shared-ByhSooBS.d.mts → shared-DarONYBZ.d.mts} +5 -5
  128. package/dist/{shared-ByhSooBS.d.mts.map → shared-DarONYBZ.d.mts.map} +1 -1
  129. package/dist/{sql-utils-B_ruBD-M.mjs → sql-utils-DcfMz4MQ.mjs} +1 -1
  130. package/dist/{sql-utils-B_ruBD-M.mjs.map → sql-utils-DcfMz4MQ.mjs.map} +1 -1
  131. package/dist/sql-utils.mjs +1 -1
  132. package/dist/{types-D-XIpzHA.d.mts → types-BDKkx8MA.d.mts} +1 -1
  133. package/dist/types-BDKkx8MA.d.mts.map +1 -0
  134. package/dist/types.d.mts +16 -11
  135. package/dist/types.d.mts.map +1 -1
  136. package/dist/types.mjs +2 -2
  137. package/package.json +21 -20
  138. package/src/contract-free/columns.ts +49 -0
  139. package/src/contract-free/control-bootstrap.ts +55 -0
  140. package/src/contract-free/ddl.ts +37 -0
  141. package/src/core/ast/table-source.ts +23 -0
  142. package/src/core/authoring.ts +1 -1
  143. package/src/core/codec-ids.ts +1 -0
  144. package/src/core/codecs.ts +44 -0
  145. package/src/core/ddl/nodes.ts +72 -0
  146. package/src/core/descriptor-meta-runtime.ts +28 -0
  147. package/src/core/descriptor-meta.ts +3 -6
  148. package/src/core/migrations/control-policy.ts +234 -0
  149. package/src/core/migrations/issue-planner.ts +81 -13
  150. package/src/core/migrations/op-factory-call.ts +289 -46
  151. package/src/core/migrations/operations/constraints.ts +79 -10
  152. package/src/core/migrations/operations/dependencies.ts +0 -17
  153. package/src/core/migrations/operations/shared.ts +3 -3
  154. package/src/core/migrations/operations/tables.ts +1 -39
  155. package/src/core/migrations/planner-ddl-builders.ts +7 -48
  156. package/src/core/migrations/planner-produced-postgres-migration.ts +11 -6
  157. package/src/core/migrations/planner-sql-checks.ts +9 -9
  158. package/src/core/migrations/planner-strategies.ts +149 -11
  159. package/src/core/migrations/planner-target-details.ts +2 -1
  160. package/src/core/migrations/planner.ts +66 -8
  161. package/src/core/migrations/postgres-migration.ts +41 -0
  162. package/src/core/migrations/render-ops.ts +7 -2
  163. package/src/core/migrations/render-typescript.ts +5 -1
  164. package/src/core/migrations/runner.ts +78 -50
  165. package/src/core/postgres-contract-serializer.ts +52 -46
  166. package/src/core/postgres-enum-type.ts +4 -0
  167. package/src/core/postgres-schema.ts +43 -25
  168. package/src/exports/contract-free.ts +7 -0
  169. package/src/exports/control.ts +6 -8
  170. package/src/exports/ddl.ts +7 -0
  171. package/src/exports/migration.ts +11 -2
  172. package/src/exports/op-factory-call.ts +2 -0
  173. package/src/exports/planner-ddl-builders.ts +0 -1
  174. package/src/exports/runtime.ts +2 -2
  175. package/dist/codec-ids-C5qzBqus.mjs.map +0 -1
  176. package/dist/codec-ids-D9fJ4HP5.d.mts.map +0 -1
  177. package/dist/codec-types-CRlHq7Cz.d.mts.map +0 -1
  178. package/dist/codecs-Dud5KDNk.d.mts.map +0 -1
  179. package/dist/descriptor-meta-DLA2xV6B.mjs.map +0 -1
  180. package/dist/issue-planner-ByQhUzS4.mjs.map +0 -1
  181. package/dist/op-factory-call-B0WNg30h.mjs +0 -625
  182. package/dist/op-factory-call-B0WNg30h.mjs.map +0 -1
  183. package/dist/op-factory-call-Drccm_JD.d.mts.map +0 -1
  184. package/dist/planner-ClF0y0YR.mjs +0 -177
  185. package/dist/planner-ClF0y0YR.mjs.map +0 -1
  186. package/dist/planner-ddl-builders-BxRCSn_b.mjs.map +0 -1
  187. package/dist/planner-produced-postgres-migration-N1yqYg20.mjs.map +0 -1
  188. package/dist/planner-produced-postgres-migration-p-VKkCia.d.mts.map +0 -1
  189. package/dist/planner-sql-checks-D3H-xOO1.mjs.map +0 -1
  190. package/dist/planner-target-details-CIj61DUj.d.mts.map +0 -1
  191. package/dist/postgres-contract-serializer-YJvjKrmo.mjs.map +0 -1
  192. package/dist/postgres-enum-type-CNhPTDhy.d.mts.map +0 -1
  193. package/dist/postgres-enum-type-DS-KLVRH.mjs.map +0 -1
  194. package/dist/postgres-migration-Fd4fQkBw.d.mts.map +0 -1
  195. package/dist/postgres-migration-uADmx0dW.mjs.map +0 -1
  196. package/dist/postgres-schema-Bm7vjlOv.mjs.map +0 -1
  197. package/dist/render-typescript-CPk7hhWH.mjs.map +0 -1
  198. package/dist/statement-builders-vImtdfmM.mjs +0 -131
  199. package/dist/statement-builders-vImtdfmM.mjs.map +0 -1
  200. package/dist/statement-builders.d.mts +0 -51
  201. package/dist/statement-builders.d.mts.map +0 -1
  202. package/dist/statement-builders.mjs +0 -2
  203. package/dist/tables-Dcb2q9zV.mjs +0 -516
  204. package/dist/tables-Dcb2q9zV.mjs.map +0 -1
  205. package/dist/types-D-XIpzHA.d.mts.map +0 -1
  206. package/src/core/migrations/statement-builders.ts +0 -183
  207. package/src/exports/statement-builders.ts +0 -8
@@ -1,4 +1,4 @@
1
- import { t as PostgresEnumType } from "./postgres-enum-type-DS-KLVRH.mjs";
1
+ import { t as PostgresEnumType } from "./postgres-enum-type-DPKqCBem.mjs";
2
2
  import { temporalAuthoringPresets } from "@prisma-next/family-sql/control";
3
3
  import { PostgresEnumTypeSchema } from "@prisma-next/sql-contract/validators";
4
4
  //#region src/core/authoring.ts
@@ -39,88 +39,92 @@ const postgresAuthoringEntityTypes = { enum: {
39
39
  validatorSchema: PostgresEnumTypeSchema,
40
40
  output: { factory: (input) => new PostgresEnumType(input) }
41
41
  } };
42
- const postgresTargetDescriptorMeta = {
42
+ /**
43
+ * Field presets contributed by the Postgres target pack.
44
+ *
45
+ * These mirror the PSL scalar-to-codec mapping used by the Postgres adapter
46
+ * (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field
47
+ * via the TS callback surface (e.g. `field.int()`) and via the PSL scalar
48
+ * surface (e.g. `Int`) lowers to byte-identical contracts.
49
+ */
50
+ const postgresAuthoringFieldPresets = {
51
+ text: {
52
+ kind: "fieldPreset",
53
+ output: {
54
+ codecId: "pg/text@1",
55
+ nativeType: "text"
56
+ }
57
+ },
58
+ int: {
59
+ kind: "fieldPreset",
60
+ output: {
61
+ codecId: "pg/int4@1",
62
+ nativeType: "int4"
63
+ }
64
+ },
65
+ bigint: {
66
+ kind: "fieldPreset",
67
+ output: {
68
+ codecId: "pg/int8@1",
69
+ nativeType: "int8"
70
+ }
71
+ },
72
+ float: {
73
+ kind: "fieldPreset",
74
+ output: {
75
+ codecId: "pg/float8@1",
76
+ nativeType: "float8"
77
+ }
78
+ },
79
+ decimal: {
80
+ kind: "fieldPreset",
81
+ output: {
82
+ codecId: "pg/numeric@1",
83
+ nativeType: "numeric"
84
+ }
85
+ },
86
+ boolean: {
87
+ kind: "fieldPreset",
88
+ output: {
89
+ codecId: "pg/bool@1",
90
+ nativeType: "bool"
91
+ }
92
+ },
93
+ json: {
94
+ kind: "fieldPreset",
95
+ output: {
96
+ codecId: "pg/jsonb@1",
97
+ nativeType: "jsonb"
98
+ }
99
+ },
100
+ bytes: {
101
+ kind: "fieldPreset",
102
+ output: {
103
+ codecId: "pg/bytea@1",
104
+ nativeType: "bytea"
105
+ }
106
+ },
107
+ dateTime: {
108
+ kind: "fieldPreset",
109
+ output: {
110
+ codecId: "pg/timestamptz@1",
111
+ nativeType: "timestamptz"
112
+ }
113
+ },
114
+ temporal: /* @__PURE__ */ temporalAuthoringPresets({
115
+ codecId: "pg/timestamptz@1",
116
+ nativeType: "timestamptz"
117
+ })
118
+ };
119
+ const postgresTargetDescriptorMetaRuntime = {
43
120
  kind: "target",
44
121
  familyId: "sql",
45
122
  targetId: "postgres",
46
123
  id: "postgres",
47
124
  version: "0.0.1",
48
- capabilities: {},
49
- authoring: {
50
- type: postgresAuthoringTypes,
51
- field: {
52
- text: {
53
- kind: "fieldPreset",
54
- output: {
55
- codecId: "pg/text@1",
56
- nativeType: "text"
57
- }
58
- },
59
- int: {
60
- kind: "fieldPreset",
61
- output: {
62
- codecId: "pg/int4@1",
63
- nativeType: "int4"
64
- }
65
- },
66
- bigint: {
67
- kind: "fieldPreset",
68
- output: {
69
- codecId: "pg/int8@1",
70
- nativeType: "int8"
71
- }
72
- },
73
- float: {
74
- kind: "fieldPreset",
75
- output: {
76
- codecId: "pg/float8@1",
77
- nativeType: "float8"
78
- }
79
- },
80
- decimal: {
81
- kind: "fieldPreset",
82
- output: {
83
- codecId: "pg/numeric@1",
84
- nativeType: "numeric"
85
- }
86
- },
87
- boolean: {
88
- kind: "fieldPreset",
89
- output: {
90
- codecId: "pg/bool@1",
91
- nativeType: "bool"
92
- }
93
- },
94
- json: {
95
- kind: "fieldPreset",
96
- output: {
97
- codecId: "pg/jsonb@1",
98
- nativeType: "jsonb"
99
- }
100
- },
101
- bytes: {
102
- kind: "fieldPreset",
103
- output: {
104
- codecId: "pg/bytea@1",
105
- nativeType: "bytea"
106
- }
107
- },
108
- dateTime: {
109
- kind: "fieldPreset",
110
- output: {
111
- codecId: "pg/timestamptz@1",
112
- nativeType: "timestamptz"
113
- }
114
- },
115
- temporal: temporalAuthoringPresets({
116
- codecId: "pg/timestamptz@1",
117
- nativeType: "timestamptz"
118
- })
119
- },
120
- entityTypes: postgresAuthoringEntityTypes
121
- }
125
+ capabilities: {}
122
126
  };
123
127
  //#endregion
124
- export { postgresAuthoringEntityTypes as n, postgresTargetDescriptorMeta as t };
128
+ export { postgresAuthoringTypes as i, postgresAuthoringEntityTypes as n, postgresAuthoringFieldPresets as r, postgresTargetDescriptorMetaRuntime as t };
125
129
 
126
- //# sourceMappingURL=descriptor-meta-DLA2xV6B.mjs.map
130
+ //# sourceMappingURL=descriptor-meta-runtime-My8_s4cs.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor-meta-runtime-My8_s4cs.mjs","names":[],"sources":["../src/core/authoring.ts","../src/core/descriptor-meta-runtime.ts"],"sourcesContent":["import { temporalAuthoringPresets } from '@prisma-next/family-sql/control';\nimport type {\n AuthoringEntityTypeNamespace,\n AuthoringFieldNamespace,\n AuthoringTypeNamespace,\n} from '@prisma-next/framework-components/authoring';\nimport type { PostgresEnumStorageEntry } from '@prisma-next/sql-contract/types';\nimport { PostgresEnumTypeSchema } from '@prisma-next/sql-contract/validators';\nimport { PostgresEnumType, type PostgresEnumTypeInput } from './postgres-enum-type';\n\nexport const postgresAuthoringTypes = {} as const satisfies AuthoringTypeNamespace;\n\n/**\n * Entity type contributions surface as top-level helpers on the\n * composed-helpers shape (e.g. `helpers.enum({...})`), flattened\n * alongside the built-in `model` / `rel` helpers. Pack contributions\n * still ship via the contribution data structure\n * `authoring.entityTypes.<name>`; the composed-helpers template\n * performs the rename in the type system.\n *\n * `enum` is the first real consumer of the entities-namespace mechanism:\n * the factory constructs a `PostgresEnumType` IR-class instance from\n * the user-supplied input. Both authoring runtimes (TS DSL and PSL)\n * dispatch through this single contribution — PSL `enum Status { … }`\n * declarations are lowered by the interpreter into a factory call\n * with the parsed name + value list; TS DSL `helpers.enum({...})`\n * resolves through the same path. Removing this contribution makes\n * both surfaces fail with a \"no entity helper named `enum`\" type\n * error at the contract-definition site.\n */\n/**\n * The factory constructs a `PostgresEnumType` instance natively — the\n * `SqlStorage.types` slot accepts polymorphic IR (the framework\n * `StorageType` alphabet), so no cast is needed at the contribution\n * surface. The declared return type is the structural\n * `PostgresEnumStorageEntry` so the inferred contract type stays\n * portable (it names a type exported from\n * `@prisma-next/sql-contract/types`, a public surface every consumer\n * already imports). Sharpening the inferred contract type to surface\n * enum-specific narrowing through `EntityHelperFunction` is a\n * separable refinement and lives outside this PR.\n */\nexport const postgresAuthoringEntityTypes = {\n enum: {\n kind: 'entity',\n discriminator: 'postgres-enum',\n validatorSchema: PostgresEnumTypeSchema,\n output: {\n factory: (input: PostgresEnumTypeInput): PostgresEnumStorageEntry =>\n new PostgresEnumType(input),\n },\n },\n} as const satisfies AuthoringEntityTypeNamespace;\n\n/**\n * Field presets contributed by the Postgres target pack.\n *\n * These mirror the PSL scalar-to-codec mapping used by the Postgres adapter\n * (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field\n * via the TS callback surface (e.g. `field.int()`) and via the PSL scalar\n * surface (e.g. `Int`) lowers to byte-identical contracts.\n */\nexport const postgresAuthoringFieldPresets = {\n text: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/text@1',\n nativeType: 'text',\n },\n },\n int: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int4@1',\n nativeType: 'int4',\n },\n },\n bigint: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int8@1',\n nativeType: 'int8',\n },\n },\n float: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/float8@1',\n nativeType: 'float8',\n },\n },\n decimal: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/numeric@1',\n nativeType: 'numeric',\n },\n },\n boolean: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bool@1',\n nativeType: 'bool',\n },\n },\n json: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/jsonb@1',\n nativeType: 'jsonb',\n },\n },\n bytes: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bytea@1',\n nativeType: 'bytea',\n },\n },\n dateTime: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n },\n },\n temporal: /* @__PURE__ */ temporalAuthoringPresets({\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n }),\n} as const satisfies AuthoringFieldNamespace;\n","// Runtime-safe slice of the postgres target descriptor metadata.\n//\n// This file exists separately from ./descriptor-meta on purpose: the runtime\n// plane reads only `kind/familyId/targetId/id/version/capabilities` (plus the\n// `__codecTypes` phantom). The `authoring` slot lives on the pack/control\n// descriptor only, because authoring contributions are consumed at\n// contract-construction time by `assembleAuthoringContributions` (control\n// plane) and the PSL interpreter — never at runtime.\n//\n// Keeping the runtime closure free of the `./authoring` import is what lets\n// the bundler tree-shake `@prisma-next/family-sql/control` (and its\n// transitive `verify-sql-schema` chunk) out of the runtime entry. Do not\n// add an `authoring` field here — if you need to, the pack/control meta in\n// `./descriptor-meta` is the right place. See TML-2766 for context.\nimport type { CodecTypes } from '../exports/codec-types';\n\nconst postgresTargetDescriptorMetaRuntimeBase = {\n kind: 'target',\n familyId: 'sql',\n targetId: 'postgres',\n id: 'postgres',\n version: '0.0.1',\n capabilities: {},\n} as const;\n\nexport const postgresTargetDescriptorMetaRuntime: typeof postgresTargetDescriptorMetaRuntimeBase & {\n readonly __codecTypes?: CodecTypes;\n} = postgresTargetDescriptorMetaRuntimeBase;\n"],"mappings":";;;;AAUA,MAAa,yBAAyB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCvC,MAAa,+BAA+B,EAC1C,MAAM;CACJ,MAAM;CACN,eAAe;CACf,iBAAiB;CACjB,QAAQ,EACN,UAAU,UACR,IAAI,iBAAiB,KAAK,EAC9B;AACF,EACF;;;;;;;;;AAUA,MAAa,gCAAgC;CAC3C,MAAM;EACJ,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,KAAK;EACH,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,QAAQ;EACN,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,OAAO;EACL,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,SAAS;EACP,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,SAAS;EACP,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,OAAO;EACL,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,UAAU;EACR,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,UAA0B,yCAAyB;EACjD,SAAS;EACT,YAAY;CACd,CAAC;AACH;ACzGA,MAAa,sCAET;CAVF,MAAM;CACN,UAAU;CACV,UAAU;CACV,IAAI;CACJ,SAAS;CACT,cAAc,CAAC;AAKb"}
@@ -1 +1 @@
1
- {"version":3,"file":"enum-planning-Dz0Ye3Lb.mjs","names":[],"sources":["../src/core/migrations/enum-planning.ts"],"sourcesContent":["/**\n * Pure planning helpers for Postgres enum types: the diff/rebuild logic\n * that the verifier and planner use to walk `PostgresEnumType` instances\n * natively. Op builders live in `./operations/enums.ts`.\n */\n\nimport { arraysEqual } from '@prisma-next/family-sql/schema-verify';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { PostgresEnumStorageEntry, SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { PG_ENUM_CODEC_ID } from '../codec-ids';\nimport type { PostgresEnumType } from '../postgres-enum-type';\nimport { isPostgresSchema } from '../postgres-schema';\n\n/**\n * Codec-typed enum entry shape stored under\n * `schema.annotations.pg.storageTypes[(schemaName, nativeType)]`.\n */\ninterface PgStorageTypeEntry {\n readonly codecId?: string;\n readonly typeParams?: { readonly values?: unknown };\n}\n\n/** Postgres-specific subtree on family `SqlSchemaIR.annotations`. */\nexport interface PostgresSchemaIrAnnotations {\n readonly schema?: string;\n readonly storageTypes?: Readonly<Record<string, PgStorageTypeEntry>>;\n}\n\nfunction readOptionalString(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction readPgStorageTypeEntry(value: unknown): PgStorageTypeEntry | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const codecId = Reflect.get(value, 'codecId');\n const typeParamsRaw = Reflect.get(value, 'typeParams');\n const typeParams =\n typeParamsRaw !== undefined &&\n typeParamsRaw !== null &&\n typeof typeParamsRaw === 'object' &&\n !Array.isArray(typeParamsRaw)\n ? { values: Reflect.get(typeParamsRaw, 'values') }\n : undefined;\n return {\n ...(typeof codecId === 'string' ? { codecId } : {}),\n ...(typeParams !== undefined ? { typeParams } : {}),\n };\n}\n\nfunction readPgStorageTypesMap(\n value: unknown,\n): Readonly<Record<string, PgStorageTypeEntry>> | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const entries: Record<string, PgStorageTypeEntry> = {};\n for (const [key, entryValue] of Object.entries(value)) {\n const entry = readPgStorageTypeEntry(entryValue);\n if (entry !== undefined) {\n entries[key] = entry;\n }\n }\n return Object.keys(entries).length > 0 ? entries : undefined;\n}\n\n/**\n * Reads the Postgres annotation envelope (`schema.annotations.pg`) from\n * family Schema IR. `SqlAnnotations` is an open target-pack extensibility\n * map (`Record<string, unknown>`); this accessor narrows the `pg` slot at\n * runtime so Postgres code can read introspection fields without casts.\n */\nexport function readPostgresSchemaIrAnnotations(schema: SqlSchemaIR): PostgresSchemaIrAnnotations {\n const raw = schema.annotations?.['pg'];\n if (raw === undefined || raw === null || typeof raw !== 'object' || Array.isArray(raw)) {\n return {};\n }\n const schemaField = readOptionalString(Reflect.get(raw, 'schema'));\n const storageTypes = readPgStorageTypesMap(Reflect.get(raw, 'storageTypes'));\n return {\n ...(schemaField !== undefined ? { schema: schemaField } : {}),\n ...(storageTypes !== undefined ? { storageTypes } : {}),\n };\n}\n\n/**\n * Separator for `(schemaName, nativeType)` keys in introspected\n * `schema.annotations.pg.storageTypes`. NUL cannot appear in Postgres\n * identifiers, so the pair is unambiguous.\n */\nexport const ENUM_STORAGE_KEY_SEP = '\\u0000';\n\n/** Builds the schema-qualified storageTypes map key for a live Postgres enum. */\nexport function enumStorageCompoundKey(schemaName: string, nativeType: string): string {\n return `${schemaName}${ENUM_STORAGE_KEY_SEP}${nativeType}`;\n}\n\n/**\n * Resolves the live-schema name a namespace's enums are introspected under,\n * for keying `readExistingEnumValues` lookups. The unbound namespace's\n * `ddlSchemaName` is a planner-emit sentinel (`__unbound__`) that never names a\n * real schema, so for the unbound coordinate we read the *introspected* schema\n * recorded on `annotations.pg.schema` (the live `current_schema()` the adapter\n * walked) — that is the schema the enum's `storageTypes` entry is keyed under.\n * Named namespaces resolve to their own DDL schema, which matches the\n * per-schema introspection key directly.\n */\nexport function resolveDdlSchemaForNamespaceStorage(\n storage: SqlStorage,\n namespaceId: string,\n schemaIr?: SqlSchemaIR,\n): string {\n if (namespaceId === UNBOUND_NAMESPACE_ID) {\n return (schemaIr ? readPostgresSchemaIrAnnotations(schemaIr).schema : undefined) ?? 'public';\n }\n const namespace = storage.namespaces[namespaceId];\n if (namespace && isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n\n/** Contract-scoped bridge for the family verifier's enum value resolver. */\nexport function createResolveExistingEnumValues(\n storage: SqlStorage,\n): (\n schema: SqlSchemaIR,\n enumType: PostgresEnumStorageEntry,\n namespaceId: string,\n) => readonly string[] | null {\n return (schema, enumType, namespaceId) =>\n readExistingEnumValues(\n schema,\n resolveDdlSchemaForNamespaceStorage(storage, namespaceId, schema),\n enumType.nativeType,\n );\n}\n\n/**\n * Categorisation of how an existing enum type's values relate to the\n * desired set in the contract.\n */\nexport type EnumDiff =\n | { readonly kind: 'unchanged' }\n | { readonly kind: 'add_values'; readonly values: readonly string[] }\n | { readonly kind: 'rebuild'; readonly removedValues: readonly string[] };\n\n/**\n * Reads existing enum values for `(schemaName, nativeType)` from the\n * Postgres-introspected `schema.annotations.pg.storageTypes` map.\n *\n * Schema IR's `storageTypes` slots are always codec-typed\n * (`{codecId: PG_ENUM_CODEC_ID, typeParams.values}`): the introspector\n * writes that shape, and the Contract→Schema IR projector resolves\n * `PostgresEnumType` instances down to the same codec-typed triple before\n * they ever land in Schema IR. There is no second on-disk shape to\n * accept here.\n *\n * Returns `null` when no enum entry exists for the given native type.\n */\nexport function readExistingEnumValues(\n schema: SqlSchemaIR,\n schemaName: string,\n nativeType: string,\n): readonly string[] | null {\n const storageTypes = readPostgresSchemaIrAnnotations(schema).storageTypes;\n const existing = storageTypes?.[enumStorageCompoundKey(schemaName, nativeType)];\n if (!existing || existing.codecId !== PG_ENUM_CODEC_ID) {\n return null;\n }\n const enumValues = existing.typeParams?.values;\n if (!Array.isArray(enumValues) || !enumValues.every((v) => typeof v === 'string')) {\n return null;\n }\n return enumValues;\n}\n\n/**\n * Determines what changes are needed to transform existing enum values to\n * desired values.\n *\n * Postgres enums can only have values added (not removed or reordered)\n * without a full type rebuild involving temp type creation and column\n * migration; `'rebuild'` covers the value-removal and reorder cases.\n */\nexport function determineEnumDiff(\n existing: readonly string[],\n desired: readonly string[],\n): EnumDiff {\n if (arraysEqual(existing, desired)) {\n return { kind: 'unchanged' };\n }\n const existingSet = new Set(existing);\n const desiredSet = new Set(desired);\n const missingValues = desired.filter((value) => !existingSet.has(value));\n const removedValues = existing.filter((value) => !desiredSet.has(value));\n const orderMismatch =\n missingValues.length === 0 && removedValues.length === 0 && !arraysEqual(existing, desired);\n if (removedValues.length > 0 || orderMismatch) {\n return { kind: 'rebuild', removedValues };\n }\n return { kind: 'add_values', values: missingValues };\n}\n\n/**\n * Convenience accessor — returns the enum's desired values from a\n * `PostgresEnumType` IR instance.\n */\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CACvE,MAAM,gBACJ,cAAc,WAAW,KAAK,cAAc,WAAW,KAAK,CAAC,YAAY,UAAU,OAAO;CAC5F,IAAI,cAAc,SAAS,KAAK,eAC9B,OAAO;EAAE,MAAM;EAAW;CAAc;CAE1C,OAAO;EAAE,MAAM;EAAc,QAAQ;CAAc;AACrD;;;;;AAMA,SAAgB,qBAAqB,cAAmD;CACtF,OAAO,aAAa;AACtB"}
1
+ {"version":3,"file":"enum-planning-BCyvlFHk.mjs","names":[],"sources":["../src/core/migrations/enum-planning.ts"],"sourcesContent":["/**\n * Pure planning helpers for Postgres enum types: the diff/rebuild logic\n * that the verifier and planner use to walk `PostgresEnumType` instances\n * natively. Op builders live in `./operations/enums.ts`.\n */\n\nimport { arraysEqual } from '@prisma-next/family-sql/schema-verify';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { PostgresEnumStorageEntry, SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { PG_ENUM_CODEC_ID } from '../codec-ids';\nimport type { PostgresEnumType } from '../postgres-enum-type';\nimport { isPostgresSchema } from '../postgres-schema';\n\n/**\n * Codec-typed enum entry shape stored under\n * `schema.annotations.pg.storageTypes[(schemaName, nativeType)]`.\n */\ninterface PgStorageTypeEntry {\n readonly codecId?: string;\n readonly typeParams?: { readonly values?: unknown };\n}\n\n/** Postgres-specific subtree on family `SqlSchemaIR.annotations`. */\nexport interface PostgresSchemaIrAnnotations {\n readonly schema?: string;\n readonly storageTypes?: Readonly<Record<string, PgStorageTypeEntry>>;\n}\n\nfunction readOptionalString(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction readPgStorageTypeEntry(value: unknown): PgStorageTypeEntry | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const codecId = Reflect.get(value, 'codecId');\n const typeParamsRaw = Reflect.get(value, 'typeParams');\n const typeParams =\n typeParamsRaw !== undefined &&\n typeParamsRaw !== null &&\n typeof typeParamsRaw === 'object' &&\n !Array.isArray(typeParamsRaw)\n ? { values: Reflect.get(typeParamsRaw, 'values') }\n : undefined;\n return {\n ...(typeof codecId === 'string' ? { codecId } : {}),\n ...(typeParams !== undefined ? { typeParams } : {}),\n };\n}\n\nfunction readPgStorageTypesMap(\n value: unknown,\n): Readonly<Record<string, PgStorageTypeEntry>> | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const entries: Record<string, PgStorageTypeEntry> = {};\n for (const [key, entryValue] of Object.entries(value)) {\n const entry = readPgStorageTypeEntry(entryValue);\n if (entry !== undefined) {\n entries[key] = entry;\n }\n }\n return Object.keys(entries).length > 0 ? entries : undefined;\n}\n\n/**\n * Reads the Postgres annotation envelope (`schema.annotations.pg`) from\n * family Schema IR. `SqlAnnotations` is an open target-pack extensibility\n * map (`Record<string, unknown>`); this accessor narrows the `pg` slot at\n * runtime so Postgres code can read introspection fields without casts.\n */\nexport function readPostgresSchemaIrAnnotations(schema: SqlSchemaIR): PostgresSchemaIrAnnotations {\n const raw = schema.annotations?.['pg'];\n if (raw === undefined || raw === null || typeof raw !== 'object' || Array.isArray(raw)) {\n return {};\n }\n const schemaField = readOptionalString(Reflect.get(raw, 'schema'));\n const storageTypes = readPgStorageTypesMap(Reflect.get(raw, 'storageTypes'));\n return {\n ...(schemaField !== undefined ? { schema: schemaField } : {}),\n ...(storageTypes !== undefined ? { storageTypes } : {}),\n };\n}\n\n/**\n * Separator for `(schemaName, nativeType)` keys in introspected\n * `schema.annotations.pg.storageTypes`. NUL cannot appear in Postgres\n * identifiers, so the pair is unambiguous.\n */\nexport const ENUM_STORAGE_KEY_SEP = '\\u0000';\n\n/** Builds the schema-qualified storageTypes map key for a live Postgres enum. */\nexport function enumStorageCompoundKey(schemaName: string, nativeType: string): string {\n return `${schemaName}${ENUM_STORAGE_KEY_SEP}${nativeType}`;\n}\n\n/**\n * Resolves the live-schema name a namespace's enums are introspected under,\n * for keying `readExistingEnumValues` lookups. The unbound namespace's\n * `ddlSchemaName` is a planner-emit sentinel (`__unbound__`) that never names a\n * real schema, so for the unbound coordinate we read the *introspected* schema\n * recorded on `annotations.pg.schema` (the live `current_schema()` the adapter\n * walked) — that is the schema the enum's `storageTypes` entry is keyed under.\n * Named namespaces resolve to their own DDL schema, which matches the\n * per-schema introspection key directly.\n */\nexport function resolveDdlSchemaForNamespaceStorage(\n storage: SqlStorage,\n namespaceId: string,\n schemaIr?: SqlSchemaIR,\n): string {\n if (namespaceId === UNBOUND_NAMESPACE_ID) {\n return (schemaIr ? readPostgresSchemaIrAnnotations(schemaIr).schema : undefined) ?? 'public';\n }\n const namespace = storage.namespaces[namespaceId];\n if (namespace && isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n\n/** Contract-scoped bridge for the family verifier's enum value resolver. */\nexport function createResolveExistingEnumValues(\n storage: SqlStorage,\n): (\n schema: SqlSchemaIR,\n enumType: PostgresEnumStorageEntry,\n namespaceId: string,\n) => readonly string[] | null {\n return (schema, enumType, namespaceId) =>\n readExistingEnumValues(\n schema,\n resolveDdlSchemaForNamespaceStorage(storage, namespaceId, schema),\n enumType.nativeType,\n );\n}\n\n/**\n * Categorisation of how an existing enum type's values relate to the\n * desired set in the contract.\n */\nexport type EnumDiff =\n | { readonly kind: 'unchanged' }\n | { readonly kind: 'add_values'; readonly values: readonly string[] }\n | { readonly kind: 'rebuild'; readonly removedValues: readonly string[] };\n\n/**\n * Reads existing enum values for `(schemaName, nativeType)` from the\n * Postgres-introspected `schema.annotations.pg.storageTypes` map.\n *\n * Schema IR's `storageTypes` slots are always codec-typed\n * (`{codecId: PG_ENUM_CODEC_ID, typeParams.values}`): the introspector\n * writes that shape, and the Contract→Schema IR projector resolves\n * `PostgresEnumType` instances down to the same codec-typed triple before\n * they ever land in Schema IR. There is no second on-disk shape to\n * accept here.\n *\n * Returns `null` when no enum entry exists for the given native type.\n */\nexport function readExistingEnumValues(\n schema: SqlSchemaIR,\n schemaName: string,\n nativeType: string,\n): readonly string[] | null {\n const storageTypes = readPostgresSchemaIrAnnotations(schema).storageTypes;\n const existing = storageTypes?.[enumStorageCompoundKey(schemaName, nativeType)];\n if (!existing || existing.codecId !== PG_ENUM_CODEC_ID) {\n return null;\n }\n const enumValues = existing.typeParams?.values;\n if (!Array.isArray(enumValues) || !enumValues.every((v) => typeof v === 'string')) {\n return null;\n }\n return enumValues;\n}\n\n/**\n * Determines what changes are needed to transform existing enum values to\n * desired values.\n *\n * Postgres enums can only have values added (not removed or reordered)\n * without a full type rebuild involving temp type creation and column\n * migration; `'rebuild'` covers the value-removal and reorder cases.\n */\nexport function determineEnumDiff(\n existing: readonly string[],\n desired: readonly string[],\n): EnumDiff {\n if (arraysEqual(existing, desired)) {\n return { kind: 'unchanged' };\n }\n const existingSet = new Set(existing);\n const desiredSet = new Set(desired);\n const missingValues = desired.filter((value) => !existingSet.has(value));\n const removedValues = existing.filter((value) => !desiredSet.has(value));\n const orderMismatch =\n missingValues.length === 0 && removedValues.length === 0 && !arraysEqual(existing, desired);\n if (removedValues.length > 0 || orderMismatch) {\n return { kind: 'rebuild', removedValues };\n }\n return { kind: 'add_values', values: missingValues };\n}\n\n/**\n * Convenience accessor — returns the enum's desired values from a\n * `PostgresEnumType` IR instance.\n */\nexport function getDesiredEnumValues(typeInstance: PostgresEnumType): readonly string[] {\n return typeInstance.values;\n}\n"],"mappings":";;;;;;;;;;AA6BA,SAAS,mBAAmB,OAAoC;CAC9D,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;AAC7C;AAEA,SAAS,uBAAuB,OAAgD;CAC9E,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GACpE;CAEF,MAAM,UAAU,QAAQ,IAAI,OAAO,SAAS;CAC5C,MAAM,gBAAgB,QAAQ,IAAI,OAAO,YAAY;CACrD,MAAM,aACJ,kBAAkB,KAAA,KAClB,kB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";
2
2
  import { PostgresEnumStorageEntry, SqlStorage } from "@prisma-next/sql-contract/types";
3
3
  import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
4
4
 
@@ -1,2 +1,2 @@
1
- import { a as readExistingEnumValues, i as getDesiredEnumValues, n as determineEnumDiff, o as readPostgresSchemaIrAnnotations, r as enumStorageCompoundKey, s as resolveDdlSchemaForNamespaceStorage, t as createResolveExistingEnumValues } from "./enum-planning-Dz0Ye3Lb.mjs";
1
+ import { a as readExistingEnumValues, i as getDesiredEnumValues, n as determineEnumDiff, o as readPostgresSchemaIrAnnotations, r as enumStorageCompoundKey, s as resolveDdlSchemaForNamespaceStorage, t as createResolveExistingEnumValues } from "./enum-planning-BCyvlFHk.mjs";
2
2
  export { createResolveExistingEnumValues, determineEnumDiff, enumStorageCompoundKey, getDesiredEnumValues, readExistingEnumValues, readPostgresSchemaIrAnnotations, resolveDdlSchemaForNamespaceStorage };
@@ -30,4 +30,4 @@ function errorPostgresMigrationStackMissing() {
30
30
  //#endregion
31
31
  export { errorPostgresMigrationStackMissing as t };
32
32
 
33
- //# sourceMappingURL=errors--zafB5_n.mjs.map
33
+ //# sourceMappingURL=errors-CUk87ByX.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors--zafB5_n.mjs","names":[],"sources":["../src/core/errors.ts"],"sourcesContent":["import { CliStructuredError } from '@prisma-next/errors/control';\n\n/**\n * A `PostgresMigration` instance method that needs the materialized control\n * adapter (currently only `this.dataTransform(...)`) was invoked, but the\n * migration was constructed without a `ControlStack`. Concrete authoring\n * usage always goes through the migration CLI entrypoint, which assembles\n * a stack from the loaded `prisma-next.config.ts`; reaching this error\n * means a test fixture or ad-hoc consumer instantiated `PostgresMigration`\n * with the no-arg form (legal for `operations` / `describe` introspection\n * only).\n *\n * Distinct from `PN-MIG-2001` (placeholder not filled) and `PN-MIG-2005`\n * (data-transform query plan against wrong contract) because the missing\n * input is the stack itself, not the per-operation contract.\n *\n * Lives in `@prisma-next/target-postgres/errors` rather than the shared\n * framework migration errors module because the failure is target-specific:\n * the contract it talks about (`PostgresMigration`, the Postgres control\n * adapter, the Postgres-target stack) only exists in this package.\n */\nexport function errorPostgresMigrationStackMissing(): CliStructuredError {\n return new CliStructuredError(\n '2007',\n 'PostgresMigration.dataTransform requires a control adapter',\n {\n domain: 'MIG',\n why: 'PostgresMigration.dataTransform was invoked on an instance constructed without a ControlStack. The stored controlAdapter is undefined, so dataTransform cannot lower its query plan.',\n fix: 'Construct the migration via the migration CLI entrypoint (which assembles a ControlStack from the loaded prisma-next.config.ts), or pass a ControlStack containing a Postgres adapter to the migration constructor in test fixtures.',\n meta: {},\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,qCAAyD;CACvE,OAAO,IAAI,mBACT,QACA,8DACA;EACE,QAAQ;EACR,KAAK;EACL,KAAK;EACL,MAAM,CAAC;CACT,CACF;AACF"}
1
+ {"version":3,"file":"errors-CUk87ByX.mjs","names":[],"sources":["../src/core/errors.ts"],"sourcesContent":["import { CliStructuredError } from '@prisma-next/errors/control';\n\n/**\n * A `PostgresMigration` instance method that needs the materialized control\n * adapter (currently only `this.dataTransform(...)`) was invoked, but the\n * migration was constructed without a `ControlStack`. Concrete authoring\n * usage always goes through the migration CLI entrypoint, which assembles\n * a stack from the loaded `prisma-next.config.ts`; reaching this error\n * means a test fixture or ad-hoc consumer instantiated `PostgresMigration`\n * with the no-arg form (legal for `operations` / `describe` introspection\n * only).\n *\n * Distinct from `PN-MIG-2001` (placeholder not filled) and `PN-MIG-2005`\n * (data-transform query plan against wrong contract) because the missing\n * input is the stack itself, not the per-operation contract.\n *\n * Lives in `@prisma-next/target-postgres/errors` rather than the shared\n * framework migration errors module because the failure is target-specific:\n * the contract it talks about (`PostgresMigration`, the Postgres control\n * adapter, the Postgres-target stack) only exists in this package.\n */\nexport function errorPostgresMigrationStackMissing(): CliStructuredError {\n return new CliStructuredError(\n '2007',\n 'PostgresMigration.dataTransform requires a control adapter',\n {\n domain: 'MIG',\n why: 'PostgresMigration.dataTransform was invoked on an instance constructed without a ControlStack. The stored controlAdapter is undefined, so dataTransform cannot lower its query plan.',\n fix: 'Construct the migration via the migration CLI entrypoint (which assembles a ControlStack from the loaded prisma-next.config.ts), or pass a ControlStack containing a Postgres adapter to the migration constructor in test fixtures.',\n meta: {},\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,qCAAyD;CACvE,OAAO,IAAI,mBACT,QACA,8DACA;EACE,QAAQ;EACR,KAAK;EACL,KAAK;EACL,MAAM,CAAC;CACT,CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.mts","names":[],"sources":["../src/core/errors.ts"],"mappings":";;;;;AAqBA;;;;AAAwE;;;;;;;;;;;;;iBAAxD,kCAAA,CAAA,GAAsC,kBAAkB"}
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../src/core/errors.ts"],"mappings":";;;;;AAqBA;;;;AAAwE;;;;;;;;;;;;;iBAAxD,kCAAA,IAAsC,kBAAkB"}
package/dist/errors.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as errorPostgresMigrationStackMissing } from "./errors--zafB5_n.mjs";
1
+ import { t as errorPostgresMigrationStackMissing } from "./errors-CUk87ByX.mjs";
2
2
  export { errorPostgresMigrationStackMissing };
@@ -1,16 +1,19 @@
1
- import { t as PostgresEnumType } from "./postgres-enum-type-DS-KLVRH.mjs";
2
- import { i as quoteIdentifier } from "./sql-utils-B_ruBD-M.mjs";
3
- import { r as isPostgresSchema } from "./postgres-schema-Bm7vjlOv.mjs";
4
- import { a as readExistingEnumValues, n as determineEnumDiff, s as resolveDdlSchemaForNamespaceStorage } from "./enum-planning-Dz0Ye3Lb.mjs";
5
- import { a as columnNullabilityCheck, c as qualifyTableName, i as columnHasNoDefaultCheck, r as columnExistsCheck, t as buildExpectedFormatType, u as tableIsEmptyCheck } from "./planner-sql-checks-D3H-xOO1.mjs";
6
- import { C as SetNotNullCall, S as SetDefaultCall, _ as DropIndexCall, a as AddUniqueCall, b as RawSqlCall, d as CreateTableCall, f as DataTransformCall, g as DropEnumTypeCall, h as DropDefaultCall, i as AddPrimaryKeyCall, l as CreateIndexCall, m as DropConstraintCall, n as AddEnumValuesCall, o as AlterColumnTypeCall, p as DropColumnCall, r as AddForeignKeyCall, s as CreateEnumTypeCall, t as AddColumnCall, u as CreateSchemaCall, v as DropNotNullCall, x as RenameTypeCall, y as DropTableCall } from "./op-factory-call-B0WNg30h.mjs";
7
- import { n as buildColumnDefaultSql, r as buildColumnTypeSql, t as buildAddColumnSql } from "./planner-ddl-builders-BxRCSn_b.mjs";
8
- import { n as resolveIdentityValue } from "./planner-identity-values-ojX-6cPV.mjs";
9
- import { i as hasUniqueConstraint, n as hasForeignKey, t as buildSchemaLookupMap } from "./planner-schema-lookup-BGyukuzG.mjs";
1
+ import { t as PostgresEnumType } from "./postgres-enum-type-DPKqCBem.mjs";
2
+ import { i as quoteIdentifier } from "./sql-utils-DcfMz4MQ.mjs";
3
+ import { r as isPostgresSchema } from "./postgres-schema-BuxCxbvB.mjs";
4
+ import { a as readExistingEnumValues, n as determineEnumDiff, s as resolveDdlSchemaForNamespaceStorage } from "./enum-planning-BCyvlFHk.mjs";
5
+ import { a as columnNullabilityCheck, c as qualifyTableName, i as columnHasNoDefaultCheck, r as columnExistsCheck, t as buildExpectedFormatType, u as tableIsEmptyCheck } from "./planner-sql-checks-DAdhnI2c.mjs";
6
+ import { C as RenameTypeCall, E as postgresDefaultToDdlColumnDefault, S as RawSqlCall, T as SetNotNullCall, _ as DropDefaultCall, a as AddPrimaryKeyCall, b as DropNotNullCall, c as CreateEnumTypeCall, d as CreateSchemaCall, f as CreateTableCall, g as DropConstraintCall, h as DropColumnCall, i as AddForeignKeyCall, m as DropCheckConstraintCall, n as AddColumnCall, o as AddUniqueCall, p as DataTransformCall, r as AddEnumValuesCall, s as AlterColumnTypeCall, t as AddCheckConstraintCall, u as CreateIndexCall, v as DropEnumTypeCall, w as SetDefaultCall, x as DropTableCall, y as DropIndexCall } from "./op-factory-call-D2aAUhmS.mjs";
7
+ import { n as buildColumnDefaultSql, r as buildColumnTypeSql, t as buildAddColumnSql } from "./planner-ddl-builders-Cw2n2llW.mjs";
8
+ import { n as resolveIdentityValue } from "./planner-identity-values-BIpa5p2I.mjs";
9
+ import { i as hasUniqueConstraint, n as hasForeignKey, t as buildSchemaLookupMap } from "./planner-schema-lookup-CiVaAQP-.mjs";
10
+ import { resolveValueSetValues } from "@prisma-next/family-sql/control";
10
11
  import { ifDefined } from "@prisma-next/utils/defined";
11
12
  import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
12
- import { isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
13
+ import { StorageTable, isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
13
14
  import { arraysEqual } from "@prisma-next/family-sql/schema-verify";
15
+ import { blindCast } from "@prisma-next/utils/casts";
16
+ import * as contractFree from "@prisma-next/sql-relational-core/contract-free";
14
17
  import { notOk, ok } from "@prisma-next/utils/result";
15
18
  //#region src/core/migrations/planner-target-details.ts
16
19
  function buildTargetDetails(objectType, name, schema, table) {
@@ -99,7 +102,7 @@ const REBUILD_SUFFIX = "__prisma_next_new";
99
102
  * contracts where two namespaces can carry the same table name).
100
103
  */
101
104
  function tableAt(storage, namespaceId, tableName) {
102
- return storage.namespaces[namespaceId]?.tables[tableName];
105
+ return storage.namespaces[namespaceId]?.entries.table[tableName];
103
106
  }
104
107
  /**
105
108
  * Default namespace coordinate for an issue that does not carry one
@@ -134,8 +137,8 @@ function resolveDdlSchemaForNamespace(ctx, namespaceId) {
134
137
  const DEFAULT_ENUM_NAMESPACE_ID = "public";
135
138
  function namespaceHasEnum(storage, namespaceId, typeName) {
136
139
  const ns = storage.namespaces[namespaceId];
137
- if (!ns || !("enum" in ns) || ns.enum == null) return false;
138
- return ns.enum[typeName] !== void 0;
140
+ if (!isPostgresSchema(ns)) return false;
141
+ return ns.entries.type[typeName] !== void 0;
139
142
  }
140
143
  /**
141
144
  * Resolves which namespace's enum a column's bare `typeRef` binds to.
@@ -158,14 +161,14 @@ function resolveColumnEnumNamespace(storage, columnNamespaceId, typeName) {
158
161
  }
159
162
  /**
160
163
  * Finds a type entry by explicit namespace coordinate. Namespace types (e.g.
161
- * Postgres enums) live under `storage.namespaces[nsId].enum`. Returns the
164
+ * Postgres enums) live under `storage.namespaces[nsId].entries.type`. Returns the
162
165
  * entry from the named namespace only — never scans other namespaces, so two
163
166
  * namespaces that hold an enum with the same name resolve independently.
164
167
  */
165
168
  function locateNamespaceType(storage, namespaceId, typeName) {
166
- const ns = storage.namespaces[namespaceId];
167
- if (!ns || !("enum" in ns) || ns.enum == null) return void 0;
168
- return ns.enum[typeName];
169
+ const raw = storage.namespaces[namespaceId]?.entries["type"]?.[typeName];
170
+ if (raw === void 0) return void 0;
171
+ return blindCast(raw);
169
172
  }
170
173
  function buildColumnSpec(namespaceId, table, column, ctx, overrides) {
171
174
  const col = tableAt(ctx.toContract.storage, namespaceId, table)?.columns[column];
@@ -176,6 +179,7 @@ function buildColumnSpec(namespaceId, table, column, ctx, overrides) {
176
179
  name: column,
177
180
  typeSql: buildColumnTypeSql(col, mutableHooks, mutableTypes),
178
181
  defaultSql: buildColumnDefaultSql(col.default, col),
182
+ columnDefault: col.default,
179
183
  nullable: overrides?.nullable ?? col.nullable
180
184
  };
181
185
  }
@@ -282,7 +286,7 @@ function enumRebuildCallRecipe(namespaceId, typeName, ctx) {
282
286
  const tempName = `${nativeType}${REBUILD_SUFFIX}`;
283
287
  const ddlSchema = resolveDdlSchemaForNamespaceStorage(ctx.toContract.storage, namespaceId, ctx.schema);
284
288
  const columnRefs = [];
285
- for (const [nsId, ns] of Object.entries(ctx.toContract.storage.namespaces)) for (const [tableName, tableNode] of Object.entries(ns.tables)) {
289
+ for (const [nsId, ns] of Object.entries(ctx.toContract.storage.namespaces)) for (const [tableName, tableNode] of Object.entries(ns.entries.table)) {
286
290
  const table = tableNode;
287
291
  for (const [columnName, column] of Object.entries(table.columns)) if (column.typeRef === typeName && resolveColumnEnumNamespace(ctx.toContract.storage, nsId, typeName) === namespaceId) columnRefs.push({
288
292
  namespaceId: nsId,
@@ -410,13 +414,89 @@ const nativeEnumPlanCallStrategy = (issues, ctx) => {
410
414
  function collectPostgresEnumTypes(storage) {
411
415
  const result = /* @__PURE__ */ new Map();
412
416
  for (const [nsId, ns] of Object.entries(storage.namespaces)) {
413
- if (!("enum" in ns) || ns.enum == null) continue;
414
- const nsEnums = ns.enum;
415
- for (const [name, instance] of Object.entries(nsEnums).sort(([a], [b]) => a.localeCompare(b))) if (instance instanceof PostgresEnumType) result.set(enumCompoundKey(nsId, name), instance);
417
+ if (!isPostgresSchema(ns)) continue;
418
+ for (const [name, instance] of Object.entries(ns.entries.type).sort(([a], [b]) => a.localeCompare(b))) if (instance instanceof PostgresEnumType) result.set(enumCompoundKey(nsId, name), instance);
416
419
  }
417
420
  return result;
418
421
  }
419
422
  /**
423
+ * Collects every check constraint from a table in the contract storage.
424
+ * Returns an empty array when the table has no checks or the table is absent.
425
+ */
426
+ function collectContractChecks(storage, namespaceId, tableName) {
427
+ const tableRaw = storage.namespaces[namespaceId]?.entries.table[tableName];
428
+ if (!(tableRaw instanceof StorageTable)) return [];
429
+ const checks = tableRaw.checks;
430
+ if (!checks || checks.length === 0) return [];
431
+ return checks.map((c) => ({
432
+ name: c.name,
433
+ column: c.column,
434
+ permittedValues: resolveValueSetValues(c.valueSet, storage, `check "${c.name}" on "${tableName}"`)
435
+ }));
436
+ }
437
+ /**
438
+ * Compares two value arrays as unordered sets.
439
+ */
440
+ function checkValueSetsEqual(a, b) {
441
+ if (a.length !== b.length) return false;
442
+ const bSet = new Set(b);
443
+ return a.every((v) => bSet.has(v));
444
+ }
445
+ /**
446
+ * Plans check-constraint migrations for `enumType`-authored columns.
447
+ *
448
+ * Walks every namespace's tables in the target contract. For each table that
449
+ * carries `checks`, diffs the contract-expected checks against the live
450
+ * schema's checks:
451
+ *
452
+ * - Check in contract, absent from live DB → `AddCheckConstraintCall`.
453
+ * - Check in live DB, absent from contract → `DropCheckConstraintCall`.
454
+ * - Check on both sides but value sets differ → `DropCheckConstraintCall`
455
+ * then `AddCheckConstraintCall` (drop + recreate; a check predicate cannot
456
+ * be altered in place).
457
+ *
458
+ * Consumes `check_missing`, `check_removed`, and `check_mismatch` issues.
459
+ * Does not touch the native enum path (`nativeEnumPlanCallStrategy` is
460
+ * unchanged).
461
+ */
462
+ const checkConstraintPlanCallStrategy = (issues, ctx) => {
463
+ const calls = [];
464
+ const handledIssueKeys = /* @__PURE__ */ new Set();
465
+ for (const [namespaceId, ns] of Object.entries(ctx.toContract.storage.namespaces)) for (const tableName of Object.keys(ns.entries.table)) {
466
+ const contractChecks = collectContractChecks(ctx.toContract.storage, namespaceId, tableName);
467
+ if (contractChecks.length === 0) continue;
468
+ const liveChecks = ctx.schema.tables[tableName]?.checks ?? [];
469
+ const ddlSchema = resolveDdlSchemaForNamespace(ctx, namespaceId);
470
+ for (const contractCheck of contractChecks) {
471
+ const liveCheck = liveChecks.find((c) => c.name === contractCheck.name);
472
+ const issueKey = `${tableName}${contractCheck.name}`;
473
+ if (!liveCheck) {
474
+ calls.push(new AddCheckConstraintCall(ddlSchema, tableName, contractCheck.name, contractCheck.column, contractCheck.permittedValues));
475
+ handledIssueKeys.add(issueKey);
476
+ } else if (!checkValueSetsEqual(contractCheck.permittedValues, liveCheck.permittedValues)) {
477
+ calls.push(new DropCheckConstraintCall(ddlSchema, tableName, contractCheck.name), new AddCheckConstraintCall(ddlSchema, tableName, contractCheck.name, contractCheck.column, contractCheck.permittedValues));
478
+ handledIssueKeys.add(issueKey);
479
+ } else handledIssueKeys.add(issueKey);
480
+ }
481
+ for (const liveCheck of liveChecks) if (!contractChecks.some((c) => c.name === liveCheck.name)) {
482
+ const issueKey = `${tableName}${liveCheck.name}`;
483
+ calls.push(new DropCheckConstraintCall(ddlSchema, tableName, liveCheck.name));
484
+ handledIssueKeys.add(issueKey);
485
+ }
486
+ }
487
+ if (calls.length === 0 && handledIssueKeys.size === 0) return { kind: "no_match" };
488
+ return {
489
+ kind: "match",
490
+ issues: issues.filter((issue) => {
491
+ if (issue.kind !== "check_missing" && issue.kind !== "check_removed" && issue.kind !== "check_mismatch") return true;
492
+ if (!issue.table || !issue.indexOrConstraint) return true;
493
+ const key = `${issue.table}${issue.indexOrConstraint}`;
494
+ return !handledIssueKeys.has(key);
495
+ }),
496
+ calls
497
+ };
498
+ };
499
+ /**
420
500
  * Dispatches non-enum codec-typed storage types through their codec's
421
501
  * `planTypeOperations` hook (the authoritative source for codec-driven DDL
422
502
  * such as custom type creation). Enum dispatch lives in
@@ -608,6 +688,7 @@ const postgresPlannerStrategies = [
608
688
  typeChangeCallStrategy,
609
689
  nullableTighteningCallStrategy,
610
690
  nativeEnumPlanCallStrategy,
691
+ checkConstraintPlanCallStrategy,
611
692
  storageTypePlanCallStrategy,
612
693
  notNullAddColumnCallStrategy
613
694
  ];
@@ -619,8 +700,7 @@ const postgresPlannerStrategies = [
619
700
  */
620
701
  function locateNamespaceTypeInStorage(storage, namespaceId, typeName) {
621
702
  const ns = storage.namespaces[namespaceId];
622
- if (!ns || !("enum" in ns) || ns.enum == null) return void 0;
623
- return ns.enum[typeName];
703
+ return isPostgresSchema(ns) ? ns.entries.type[typeName] : void 0;
624
704
  }
625
705
  const ISSUE_KIND_ORDER = {
626
706
  missing_schema: 1,
@@ -643,7 +723,10 @@ const ISSUE_KIND_ORDER = {
643
723
  primary_key_mismatch: 50,
644
724
  unique_constraint_mismatch: 51,
645
725
  index_mismatch: 52,
646
- foreign_key_mismatch: 60
726
+ foreign_key_mismatch: 60,
727
+ check_missing: 53,
728
+ check_mismatch: 54,
729
+ check_removed: 55
647
730
  };
648
731
  function issueOrder(issue) {
649
732
  return ISSUE_KIND_ORDER[issue.kind] ?? 99;
@@ -668,6 +751,14 @@ function toColumnSpec(name, column, codecHooks, storageTypes) {
668
751
  nullable: column.nullable
669
752
  };
670
753
  }
754
+ function toDdlColumn(name, column, codecHooks, storageTypes) {
755
+ const typeSql = buildColumnTypeSql(column, codecHooks, storageTypes);
756
+ const ddlDefault = postgresDefaultToDdlColumnDefault(column.default);
757
+ return contractFree.col(name, typeSql, {
758
+ ...!column.nullable ? { notNull: true } : {},
759
+ ...ddlDefault ? { default: ddlDefault } : {}
760
+ });
761
+ }
671
762
  function mapIssueToCall(issue, ctx) {
672
763
  const { schemaName, codecHooks, storageTypes } = ctx;
673
764
  const tableSchema = (issue) => {
@@ -687,9 +778,9 @@ function mapIssueToCall(issue, ctx) {
687
778
  const contractTable = tableAt(ctx.toContract.storage, namespaceId, issue.table);
688
779
  if (!contractTable) return notOk(issueConflict("unsupportedOperation", `Table "${issue.table}" in namespace "${namespaceId}" reported missing but not found in destination contract`));
689
780
  const schemaForTable = tableSchema(issue);
690
- const columns = Object.entries(contractTable.columns).map(([name, column]) => toColumnSpec(name, column, codecHooks, storageTypes));
691
- const primaryKey = contractTable.primaryKey ? { columns: contractTable.primaryKey.columns } : void 0;
692
- const calls = [new CreateTableCall(schemaForTable, issue.table, columns, primaryKey)];
781
+ const ddlColumns = Object.entries(contractTable.columns).map(([name, column]) => toDdlColumn(name, column, codecHooks, storageTypes));
782
+ const ddlConstraints = contractTable.primaryKey ? [contractFree.primaryKey(contractTable.primaryKey.columns, { ...contractTable.primaryKey.name ? { name: contractTable.primaryKey.name } : {} })] : void 0;
783
+ const calls = [new CreateTableCall(schemaForTable, issue.table, ddlColumns, ddlConstraints)];
693
784
  for (const index of contractTable.indexes) {
694
785
  const indexName = index.name ?? `${issue.table}_${index.columns.join("_")}_idx`;
695
786
  const extras = {};
@@ -831,6 +922,15 @@ function mapIssueToCall(issue, ctx) {
831
922
  return ok([new CreateIndexCall(tableSchema(issue), issue.table, indexName, columns, extras)]);
832
923
  }
833
924
  return notOk(issueConflict("indexIncompatible", `Index on "${issue.table}" differs (expected: ${issue.expected}, actual: ${issue.actual})`, { table: issue.table }));
925
+ case "check_missing":
926
+ if (!issue.table || !issue.indexOrConstraint) return notOk(issueConflict("unsupportedOperation", "Check missing issue has no table/constraint name"));
927
+ return notOk(issueConflict("unsupportedOperation", `Check constraint "${issue.indexOrConstraint}" missing on "${issue.table}" — handled by checkConstraintPlanCallStrategy`));
928
+ case "check_mismatch":
929
+ if (!issue.table || !issue.indexOrConstraint) return notOk(issueConflict("unsupportedOperation", "Check mismatch issue has no table/constraint name"));
930
+ return notOk(issueConflict("unsupportedOperation", `Check constraint "${issue.indexOrConstraint}" values mismatch on "${issue.table}" — handled by checkConstraintPlanCallStrategy`));
931
+ case "check_removed":
932
+ if (!issue.table || !issue.indexOrConstraint) return notOk(issueConflict("unsupportedOperation", "Check removed issue has no table/constraint name"));
933
+ return ok([new DropCheckConstraintCall(tableSchema(issue), issue.table, issue.indexOrConstraint)]);
834
934
  case "foreign_key_mismatch":
835
935
  if (!issue.table) return notOk(issueConflict("foreignKeyConflict", "Foreign key issue has no table name"));
836
936
  if (isMissing(issue) && issue.expected) {
@@ -888,8 +988,10 @@ function classifyCall(call) {
888
988
  case "dropTable":
889
989
  case "dropColumn":
890
990
  case "dropConstraint":
991
+ case "dropCheckConstraint":
891
992
  case "dropIndex":
892
993
  case "dropDefault": return "drop";
994
+ case "addCheckConstraint": return "unique";
893
995
  case "createTable": return "table";
894
996
  case "addColumn": return "column";
895
997
  case "alterColumnType":
@@ -1033,4 +1135,4 @@ function planIssues(options) {
1033
1135
  //#endregion
1034
1136
  export { postgresPlannerStrategies as n, planIssues as t };
1035
1137
 
1036
- //# sourceMappingURL=issue-planner-ByQhUzS4.mjs.map
1138
+ //# sourceMappingURL=issue-planner-Br0pt1Ea.mjs.map