@prisma/orm-target-sqlite 8.0.0-rc.2-dev.2 → 8.0.0-rc.20-dev.1

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 (289) hide show
  1. package/README.md +1 -5
  2. package/dist/{adapter-CUTKlFpX-CW0J0Qs4.mjs → adapter-7m8HU4rt-DN15_Cn8.mjs} +178 -107
  3. package/dist/adapter-7m8HU4rt-DN15_Cn8.mjs.map +1 -0
  4. package/dist/adapter-C3hrAasJ.d.mts +197 -0
  5. package/dist/adapter-C3hrAasJ.d.mts.map +1 -0
  6. package/dist/{adapter-DEYUC-KO-DO_abhIq.d.mts → adapter-xFPDhkod-BsdLsy9N.d.mts} +12 -9
  7. package/dist/adapter-xFPDhkod-BsdLsy9N.d.mts.map +1 -0
  8. package/dist/adapter.d.mts +14 -15
  9. package/dist/adapter.mjs +7 -6
  10. package/dist/adapter__adapter.d.mts +4 -4
  11. package/dist/adapter__adapter.mjs +3 -2
  12. package/dist/adapter__codec-types.d.mts +3 -3
  13. package/dist/adapter__column-types.d.mts +2 -2
  14. package/dist/adapter__column-types.mjs +2 -2
  15. package/dist/adapter__control.d.mts +5 -5
  16. package/dist/adapter__control.mjs +12 -247
  17. package/dist/adapter__control.mjs.map +1 -1
  18. package/dist/adapter__runtime.d.mts +1 -1
  19. package/dist/adapter__runtime.mjs +11 -6
  20. package/dist/adapter__runtime.mjs.map +1 -1
  21. package/dist/adapter__sql-renderer.d.mts +2 -2
  22. package/dist/adapter__sql-renderer.mjs +1 -1
  23. package/dist/adapter__types.d.mts +3 -2
  24. package/dist/{aggregates-DWyPO7t6.mjs → aggregates-D5fuFVMC.mjs} +33 -20
  25. package/dist/aggregates-D5fuFVMC.mjs.map +1 -0
  26. package/dist/aggregates-UBmpuURb.d.mts +164 -0
  27. package/dist/aggregates-UBmpuURb.d.mts.map +1 -0
  28. package/dist/codec-descriptor-3oN7rtrW-Cc_u7U5-.d.mts +1 -0
  29. package/dist/codec-descriptor-C16gQAdS.d.mts +2 -0
  30. package/dist/{codec-descriptor-B9ru99aI-DTkdKFU5.mjs → codec-descriptor-DRmF-crq-BALI5Jtz.mjs} +11 -15
  31. package/dist/codec-descriptor-DRmF-crq-BALI5Jtz.mjs.map +1 -0
  32. package/dist/codec-descriptor-DuW-d9ef-BBRBN0Ri.d.mts +45 -0
  33. package/dist/codec-descriptor-DuW-d9ef-BBRBN0Ri.d.mts.map +1 -0
  34. package/dist/codec-ids-CMbhYIsa.d.mts +1 -0
  35. package/dist/{codec-ids-CzeDyMWW-BZAcI50I.d.mts → codec-ids-DuJYssXV-BPKbFNRL.d.mts} +4 -4
  36. package/dist/codec-ids-DuJYssXV-BPKbFNRL.d.mts.map +1 -0
  37. package/dist/{codec-ids-KMliSCRp-BhTbmbGr.mjs → codec-ids-wgEvkCkg-WltuexMR.mjs} +4 -4
  38. package/dist/codec-ids-wgEvkCkg-WltuexMR.mjs.map +1 -0
  39. package/dist/{codec-types-D7uWRvQ1-DPnvquS8.d.mts → codec-types-COh75Bop-CUehAexc.d.mts} +6 -5
  40. package/dist/codec-types-COh75Bop-CUehAexc.d.mts.map +1 -0
  41. package/dist/codec-types-ELHfd82J.d.mts +2 -0
  42. package/dist/codec-types-PONhVn74.d.mts +1 -0
  43. package/dist/{codecs-BQWqLgCl-CdB8t7HI.d.mts → codecs-BJYruC-a-BKDGae3k.d.mts} +86 -62
  44. package/dist/codecs-BJYruC-a-BKDGae3k.d.mts.map +1 -0
  45. package/dist/codecs-Dn0xoCuf.d.mts +1 -0
  46. package/dist/codecs-g-YI3BtK.mjs +49 -0
  47. package/dist/codecs-g-YI3BtK.mjs.map +1 -0
  48. package/dist/codecs-yZoH21Yj-lQXtGlEq.mjs +618 -0
  49. package/dist/codecs-yZoH21Yj-lQXtGlEq.mjs.map +1 -0
  50. package/dist/column-types-DcbNOYVb.mjs +22 -0
  51. package/dist/column-types-DcbNOYVb.mjs.map +1 -0
  52. package/dist/column-types-Dxm0BpPv.d.mts +36 -0
  53. package/dist/column-types-Dxm0BpPv.d.mts.map +1 -0
  54. package/dist/contract-contributions-wweWdXMK-CN-d35Rj.mjs +24 -0
  55. package/dist/contract-contributions-wweWdXMK-CN-d35Rj.mjs.map +1 -0
  56. package/dist/{contract-free-CCLAXZV2.d.mts → contract-free-BJwIJN6x.d.mts} +3 -3
  57. package/dist/contract-free-BJwIJN6x.d.mts.map +1 -0
  58. package/dist/{contract-free-D5cZrgNl.mjs → contract-free-DetowcoS.mjs} +8 -7
  59. package/dist/contract-free-DetowcoS.mjs.map +1 -0
  60. package/dist/{control-CLirKz11.d.mts → control-BbJiKI2r.d.mts} +24 -29
  61. package/dist/control-BbJiKI2r.d.mts.map +1 -0
  62. package/dist/{control-B16T9OoX.mjs → control-BxbKU2xs.mjs} +15 -6
  63. package/dist/control-BxbKU2xs.mjs.map +1 -0
  64. package/dist/{control-D9vMRRgU.d.mts → control-C2TjacST.d.mts} +3 -3
  65. package/dist/control-C2TjacST.d.mts.map +1 -0
  66. package/dist/{control--wMueaTg.d.mts → control-CmDsxEqb.d.mts} +75 -6
  67. package/dist/control-CmDsxEqb.d.mts.map +1 -0
  68. package/dist/{control-tables-Dua-YcJL.d.mts → control-tables-DKXLHvMU.d.mts} +2 -2
  69. package/dist/control-tables-DKXLHvMU.d.mts.map +1 -0
  70. package/dist/{control-tables-D_o8dKRB-BXi43noL.mjs → control-tables-D_o8dKRB-n_QqsXcm.mjs} +2 -2
  71. package/dist/control-tables-D_o8dKRB-n_QqsXcm.mjs.map +1 -0
  72. package/dist/data-type-entries-yQ-qYugg-C_NnX5WO.mjs +76 -0
  73. package/dist/data-type-entries-yQ-qYugg-C_NnX5WO.mjs.map +1 -0
  74. package/dist/data-types-Dx3rHsbF.d.mts +40 -0
  75. package/dist/data-types-Dx3rHsbF.d.mts.map +1 -0
  76. package/dist/data-types-coQrCWfS-yMCe4F52.mjs +140 -0
  77. package/dist/data-types-coQrCWfS-yMCe4F52.mjs.map +1 -0
  78. package/dist/datetime-text-Bniwehv--BSQhnrdE.mjs +9 -0
  79. package/dist/datetime-text-Bniwehv--BSQhnrdE.mjs.map +1 -0
  80. package/dist/ddl-31OBcTco.d.mts +1 -0
  81. package/dist/{ddl-CXduXyOT-nlDP6DGx.mjs → ddl-CX4tAZ-y-Bng-4PWC.mjs} +42 -5
  82. package/dist/ddl-CX4tAZ-y-Bng-4PWC.mjs.map +1 -0
  83. package/dist/default-normalizer-CkHy3JYk.d.mts +25 -0
  84. package/dist/default-normalizer-CkHy3JYk.d.mts.map +1 -0
  85. package/dist/default-normalizer-DGMXypHg-CPf7oyZA.mjs +112 -0
  86. package/dist/default-normalizer-DGMXypHg-CPf7oyZA.mjs.map +1 -0
  87. package/dist/descriptor-meta-COSGM3xb-Ct_5RPcm.mjs +110 -0
  88. package/dist/descriptor-meta-COSGM3xb-Ct_5RPcm.mjs.map +1 -0
  89. package/dist/descriptor-meta-DrNwC4vO-D7vuA6QK.mjs +26 -0
  90. package/dist/descriptor-meta-DrNwC4vO-D7vuA6QK.mjs.map +1 -0
  91. package/dist/{descriptor-meta-vjJkUDsn-Hz3rnAnk.mjs → descriptor-meta-cwy5CXTT-CLOhiryX.mjs} +17 -3
  92. package/dist/descriptor-meta-cwy5CXTT-CLOhiryX.mjs.map +1 -0
  93. package/dist/descriptor-meta-runtime-DX2JfHWF-Dbsh5NP8.mjs +15 -0
  94. package/dist/descriptor-meta-runtime-DX2JfHWF-Dbsh5NP8.mjs.map +1 -0
  95. package/dist/driver.d.mts +2 -2
  96. package/dist/driver.mjs +1 -1
  97. package/dist/driver__control.d.mts +1 -1
  98. package/dist/driver__control.mjs +1 -1
  99. package/dist/driver__runtime.d.mts +1 -1
  100. package/dist/driver__runtime.mjs +5 -8
  101. package/dist/driver__runtime.mjs.map +1 -1
  102. package/dist/{errors-DnR-sMHS-KkMLIP2U.mjs → errors-DnR-sMHS-D_gh214a.mjs} +2 -2
  103. package/dist/errors-DnR-sMHS-D_gh214a.mjs.map +1 -0
  104. package/dist/{migration-uylRe5MP.d.mts → migration-WJlUQmsn.d.mts} +6 -5
  105. package/dist/migration-WJlUQmsn.d.mts.map +1 -0
  106. package/dist/{migration-DOKPHtxn.mjs → migration-nqIDkjRz.mjs} +6 -5
  107. package/dist/migration-nqIDkjRz.mjs.map +1 -0
  108. package/dist/{nodes-D8EC1yCx-rpfpuJ4T.d.mts → nodes-D8EC1yCx-BS-fKla6.d.mts} +2 -2
  109. package/dist/nodes-D8EC1yCx-BS-fKla6.d.mts.map +1 -0
  110. package/dist/{nodes-DUZSdX86-BBEEaxXY.mjs → nodes-DUZSdX86-DWyLY3OW.mjs} +2 -2
  111. package/dist/nodes-DUZSdX86-DWyLY3OW.mjs.map +1 -0
  112. package/dist/{op-factory-call-DoHN7Q7L.d.mts → op-factory-call-De6MX7Yp.d.mts} +83 -19
  113. package/dist/op-factory-call-De6MX7Yp.d.mts.map +1 -0
  114. package/dist/op-factory-call-emj9Xp05-BFLkxrAK.mjs +1414 -0
  115. package/dist/op-factory-call-emj9Xp05-BFLkxrAK.mjs.map +1 -0
  116. package/dist/pack-DR0n9vHJ.d.mts +1179 -0
  117. package/dist/pack-DR0n9vHJ.d.mts.map +1 -0
  118. package/dist/planner-BvwYScnt-9H9LIJFn.mjs +362 -0
  119. package/dist/planner-BvwYScnt-9H9LIJFn.mjs.map +1 -0
  120. package/dist/{planner-Bxdi7jZF.d.mts → planner-CjMq9oEt.d.mts} +21 -10
  121. package/dist/planner-CjMq9oEt.d.mts.map +1 -0
  122. package/dist/{planner-produced-sqlite-migration-C9uVDKrJ-CWbxSANn.mjs → planner-produced-sqlite-migration-D2jtaItv-ZFZhPfGE.mjs} +4 -4
  123. package/dist/planner-produced-sqlite-migration-D2jtaItv-ZFZhPfGE.mjs.map +1 -0
  124. package/dist/{planner-produced-sqlite-migration-BuJysRxx-CaDUbNVx.d.mts → planner-produced-sqlite-migration-DuM9c3YI-Dacb6zQZ.d.mts} +4 -4
  125. package/dist/planner-produced-sqlite-migration-DuM9c3YI-Dacb6zQZ.d.mts.map +1 -0
  126. package/dist/planner-produced-sqlite-migration-GDP1M36D.d.mts +1 -0
  127. package/dist/{planner-target-details-CIQ789Gc-C5U4yVY9.mjs → planner-target-details-CIQ789Gc-Cug2V5g5.mjs} +2 -2
  128. package/dist/planner-target-details-CIQ789Gc-Cug2V5g5.mjs.map +1 -0
  129. package/dist/{planner-target-details-xR6UfIcz-CMahymzq.d.mts → planner-target-details-xR6UfIcz-BrBPQGOS.d.mts} +2 -2
  130. package/dist/planner-target-details-xR6UfIcz-BrBPQGOS.d.mts.map +1 -0
  131. package/dist/render-ops-BPLkHR-y-CPoXG5Ap.mjs +34 -0
  132. package/dist/render-ops-BPLkHR-y-CPoXG5Ap.mjs.map +1 -0
  133. package/dist/{render-ops-B10yqmdG.d.mts → render-ops-Ntl2jBJe.d.mts} +3 -3
  134. package/dist/render-ops-Ntl2jBJe.d.mts.map +1 -0
  135. package/dist/{runtime-B1coahKC.d.mts → runtime-BvMPuBrJ.d.mts} +3 -3
  136. package/dist/runtime-BvMPuBrJ.d.mts.map +1 -0
  137. package/dist/{runtime-B99c4n56.d.mts → runtime-CjIoI3sa.d.mts} +4 -4
  138. package/dist/runtime-CjIoI3sa.d.mts.map +1 -0
  139. package/dist/{runtime-C5J9fusd.d.mts → runtime-YfPIbtO6.d.mts} +4 -4
  140. package/dist/runtime-YfPIbtO6.d.mts.map +1 -0
  141. package/dist/sql-renderer-brQ96quu.d.mts +1 -0
  142. package/dist/{sql-utils-0SJZOd7Q.d.mts → sql-utils-BqHka8P6.d.mts} +2 -2
  143. package/dist/sql-utils-BqHka8P6.d.mts.map +1 -0
  144. package/dist/{sql-utils-C2O4zVkP-Dz3Hb85I.mjs → sql-utils-XGT5Esi2-Zr2mqJf8.mjs} +31 -4
  145. package/dist/sql-utils-XGT5Esi2-Zr2mqJf8.mjs.map +1 -0
  146. package/dist/{sqlite-contract-view-BpNMaU2m-COMDaGaq.d.mts → sqlite-contract-view-BDw8T5Cp-BfFajhe4.d.mts} +5 -4
  147. package/dist/sqlite-contract-view-BDw8T5Cp-BfFajhe4.d.mts.map +1 -0
  148. package/dist/{sqlite-contract-view-BYR10usg-BteDAUZr.mjs → sqlite-contract-view-CGfiGvKH-CT-JjNHd.mjs} +9 -6
  149. package/dist/sqlite-contract-view-CGfiGvKH-CT-JjNHd.mjs.map +1 -0
  150. package/dist/sqlite-migration-BAdSmooi-iWFVQgGV.mjs +1295 -0
  151. package/dist/sqlite-migration-BAdSmooi-iWFVQgGV.mjs.map +1 -0
  152. package/dist/{sqlite-migration-o23JHwzY-CwNJcqwl.d.mts → sqlite-migration-CLIMaHLy-5ZjJDdDP.d.mts} +61 -13
  153. package/dist/sqlite-migration-CLIMaHLy-5ZjJDdDP.d.mts.map +1 -0
  154. package/dist/{shared-BYAX0FaQ--VvRXVRC.d.mts → tables-C6oejIsc-CzK00Kwl.d.mts} +38 -10
  155. package/dist/tables-C6oejIsc-CzK00Kwl.d.mts.map +1 -0
  156. package/dist/target.d.mts +29 -29
  157. package/dist/target.mjs +24 -20
  158. package/dist/target__aggregates.d.mts +1 -1
  159. package/dist/target__aggregates.mjs +1 -1
  160. package/dist/target__codec-descriptor.d.mts +2 -2
  161. package/dist/target__codec-descriptor.mjs +1 -1
  162. package/dist/target__codec-ids.d.mts +3 -3
  163. package/dist/target__codec-ids.mjs +2 -2
  164. package/dist/target__codec-types.d.mts +3 -3
  165. package/dist/target__codecs.d.mts +3 -3
  166. package/dist/target__codecs.mjs +4 -2
  167. package/dist/target__contract-free.d.mts +1 -1
  168. package/dist/target__contract-free.mjs +2 -2
  169. package/dist/target__control-tables.d.mts +1 -1
  170. package/dist/target__control-tables.mjs +1 -1
  171. package/dist/target__control.d.mts +3 -3
  172. package/dist/target__control.mjs +168 -72
  173. package/dist/target__control.mjs.map +1 -1
  174. package/dist/target__data-types.d.mts +2 -0
  175. package/dist/target__data-types.mjs +3 -0
  176. package/dist/target__ddl.d.mts +2 -2
  177. package/dist/target__ddl.mjs +1 -1
  178. package/dist/target__default-normalizer.d.mts +2 -2
  179. package/dist/target__default-normalizer.mjs +2 -2
  180. package/dist/target__migration.d.mts +3 -3
  181. package/dist/target__migration.mjs +3 -3
  182. package/dist/target__op-factory-call.d.mts +2 -2
  183. package/dist/target__op-factory-call.mjs +2 -2
  184. package/dist/target__pack.d.mts +1 -1
  185. package/dist/target__pack.mjs +1 -1
  186. package/dist/target__planner-produced-sqlite-migration.d.mts +2 -2
  187. package/dist/target__planner-produced-sqlite-migration.mjs +1 -1
  188. package/dist/target__planner-target-details.d.mts +1 -1
  189. package/dist/target__planner-target-details.mjs +1 -1
  190. package/dist/target__planner.d.mts +1 -1
  191. package/dist/target__planner.mjs +1 -1
  192. package/dist/target__render-ops.d.mts +1 -1
  193. package/dist/target__render-ops.mjs +1 -1
  194. package/dist/target__runtime.d.mts +2 -2
  195. package/dist/target__runtime.mjs +3 -3
  196. package/dist/target__runtime.mjs.map +1 -1
  197. package/dist/target__sql-utils.d.mts +1 -1
  198. package/dist/target__sql-utils.mjs +1 -1
  199. package/dist/{types-C5FSREvo-CwUlKK34.d.mts → types-RJMd2PlL-BTGAJrBQ.d.mts} +5 -7
  200. package/dist/types-RJMd2PlL-BTGAJrBQ.d.mts.map +1 -0
  201. package/dist/types-y5JlAv97.d.mts +2 -0
  202. package/package.json +12 -12
  203. package/dist/adapter-CUTKlFpX-CW0J0Qs4.mjs.map +0 -1
  204. package/dist/adapter-D7zw14p5.d.mts +0 -2
  205. package/dist/adapter-DEYUC-KO-DO_abhIq.d.mts.map +0 -1
  206. package/dist/aggregates-BGuKJwfI.d.mts +0 -10
  207. package/dist/aggregates-BGuKJwfI.d.mts.map +0 -1
  208. package/dist/aggregates-DWyPO7t6.mjs.map +0 -1
  209. package/dist/codec-descriptor-B9ru99aI-DTkdKFU5.mjs.map +0 -1
  210. package/dist/codec-descriptor-BcgD9f3L-yDi5nh_k.d.mts +0 -31
  211. package/dist/codec-descriptor-BcgD9f3L-yDi5nh_k.d.mts.map +0 -1
  212. package/dist/codec-descriptor-rFuZ9DzY-CKRIRxah.d.mts +0 -1
  213. package/dist/codec-descriptor-vwfD3BMy.d.mts +0 -2
  214. package/dist/codec-ids-7WqtUuda.d.mts +0 -1
  215. package/dist/codec-ids-CzeDyMWW-BZAcI50I.d.mts.map +0 -1
  216. package/dist/codec-ids-KMliSCRp-BhTbmbGr.mjs.map +0 -1
  217. package/dist/codec-types-B-TDcvQc.d.mts +0 -1
  218. package/dist/codec-types-CS0bD1kX.d.mts +0 -2
  219. package/dist/codec-types-D7uWRvQ1-DPnvquS8.d.mts.map +0 -1
  220. package/dist/codecs-BDdR6FbY.mjs +0 -504
  221. package/dist/codecs-BDdR6FbY.mjs.map +0 -1
  222. package/dist/codecs-BQWqLgCl-CdB8t7HI.d.mts.map +0 -1
  223. package/dist/codecs-BTv6fRXv.d.mts +0 -1
  224. package/dist/column-types-NVxgsjFA.mjs +0 -34
  225. package/dist/column-types-NVxgsjFA.mjs.map +0 -1
  226. package/dist/column-types-iWGuW-0W.d.mts +0 -33
  227. package/dist/column-types-iWGuW-0W.d.mts.map +0 -1
  228. package/dist/contract-free-CCLAXZV2.d.mts.map +0 -1
  229. package/dist/contract-free-D5cZrgNl.mjs.map +0 -1
  230. package/dist/control--wMueaTg.d.mts.map +0 -1
  231. package/dist/control-B16T9OoX.mjs.map +0 -1
  232. package/dist/control-CLirKz11.d.mts.map +0 -1
  233. package/dist/control-D9vMRRgU.d.mts.map +0 -1
  234. package/dist/control-tables-D_o8dKRB-BXi43noL.mjs.map +0 -1
  235. package/dist/control-tables-Dua-YcJL.d.mts.map +0 -1
  236. package/dist/ddl-CXduXyOT-nlDP6DGx.mjs.map +0 -1
  237. package/dist/ddl-CfSqNT0M.d.mts +0 -1
  238. package/dist/default-normalizer-B9V7TY5u.d.mts +0 -7
  239. package/dist/default-normalizer-B9V7TY5u.d.mts.map +0 -1
  240. package/dist/default-normalizer-DuoHj9-O-DsK7lJZn.mjs +0 -69
  241. package/dist/default-normalizer-DuoHj9-O-DsK7lJZn.mjs.map +0 -1
  242. package/dist/descriptor-meta-DjKgG4z5-D_0obUB8.mjs +0 -34
  243. package/dist/descriptor-meta-DjKgG4z5-D_0obUB8.mjs.map +0 -1
  244. package/dist/descriptor-meta-nORSZfmr-Cw-pzAJr.mjs +0 -33
  245. package/dist/descriptor-meta-nORSZfmr-Cw-pzAJr.mjs.map +0 -1
  246. package/dist/descriptor-meta-runtime-BkXK3OjD-CxZdKHCw.mjs +0 -13
  247. package/dist/descriptor-meta-runtime-BkXK3OjD-CxZdKHCw.mjs.map +0 -1
  248. package/dist/descriptor-meta-vjJkUDsn-Hz3rnAnk.mjs.map +0 -1
  249. package/dist/errors-DnR-sMHS-KkMLIP2U.mjs.map +0 -1
  250. package/dist/migration-DOKPHtxn.mjs.map +0 -1
  251. package/dist/migration-uylRe5MP.d.mts.map +0 -1
  252. package/dist/native-type-normalizer-CO2wKGL6.d.mts +0 -12
  253. package/dist/native-type-normalizer-CO2wKGL6.d.mts.map +0 -1
  254. package/dist/native-type-normalizer-GpQMEyN5.mjs +0 -14
  255. package/dist/native-type-normalizer-GpQMEyN5.mjs.map +0 -1
  256. package/dist/nodes-D8EC1yCx-rpfpuJ4T.d.mts.map +0 -1
  257. package/dist/nodes-DUZSdX86-BBEEaxXY.mjs.map +0 -1
  258. package/dist/op-factory-call-DoHN7Q7L.d.mts.map +0 -1
  259. package/dist/op-factory-call-gc26GqyA-Db5Fasef.mjs +0 -829
  260. package/dist/op-factory-call-gc26GqyA-Db5Fasef.mjs.map +0 -1
  261. package/dist/pack-DIbefoZF.d.mts +0 -102
  262. package/dist/pack-DIbefoZF.d.mts.map +0 -1
  263. package/dist/planner-Bxdi7jZF.d.mts.map +0 -1
  264. package/dist/planner-Cqjr2usR-4wg3FB78.mjs +0 -824
  265. package/dist/planner-Cqjr2usR-4wg3FB78.mjs.map +0 -1
  266. package/dist/planner-produced-sqlite-migration-BuJysRxx-CaDUbNVx.d.mts.map +0 -1
  267. package/dist/planner-produced-sqlite-migration-C9uVDKrJ-CWbxSANn.mjs.map +0 -1
  268. package/dist/planner-produced-sqlite-migration-uySoqJO-.d.mts +0 -1
  269. package/dist/planner-target-details-CIQ789Gc-C5U4yVY9.mjs.map +0 -1
  270. package/dist/planner-target-details-xR6UfIcz-CMahymzq.d.mts.map +0 -1
  271. package/dist/render-ops-B10yqmdG.d.mts.map +0 -1
  272. package/dist/render-ops-KxAmAz6d-W2xyvA5y.mjs +0 -27
  273. package/dist/render-ops-KxAmAz6d-W2xyvA5y.mjs.map +0 -1
  274. package/dist/runtime-B1coahKC.d.mts.map +0 -1
  275. package/dist/runtime-B99c4n56.d.mts.map +0 -1
  276. package/dist/runtime-C5J9fusd.d.mts.map +0 -1
  277. package/dist/shared-BYAX0FaQ--VvRXVRC.d.mts.map +0 -1
  278. package/dist/sql-renderer-KX6hn_tg.d.mts +0 -1
  279. package/dist/sql-utils-0SJZOd7Q.d.mts.map +0 -1
  280. package/dist/sql-utils-C2O4zVkP-Dz3Hb85I.mjs.map +0 -1
  281. package/dist/sqlite-contract-view-BYR10usg-BteDAUZr.mjs.map +0 -1
  282. package/dist/sqlite-contract-view-BpNMaU2m-COMDaGaq.d.mts.map +0 -1
  283. package/dist/sqlite-migration-CjMkH4Id-c6dM9w61.mjs +0 -94
  284. package/dist/sqlite-migration-CjMkH4Id-c6dM9w61.mjs.map +0 -1
  285. package/dist/sqlite-migration-o23JHwzY-CwNJcqwl.d.mts.map +0 -1
  286. package/dist/target__native-type-normalizer.d.mts +0 -2
  287. package/dist/target__native-type-normalizer.mjs +0 -2
  288. package/dist/types-B7e2QVEx.d.mts +0 -1
  289. package/dist/types-C5FSREvo-CwUlKK34.d.mts.map +0 -1
@@ -0,0 +1,1414 @@
1
+ import { n as sqliteError } from "./errors-DnR-sMHS-D_gh214a.mjs";
2
+ import { a as tableExistsAst, i as indexExistsAst, n as columnNameTakenAst, o as tableNameTakenAst, r as createTable, t as columnExistsAst } from "./ddl-CX4tAZ-y-Bng-4PWC.mjs";
3
+ import { n as escapeLiteral, r as quoteIdentifier, t as SQLITE_QUOTING } from "./sql-utils-XGT5Esi2-Zr2mqJf8.mjs";
4
+ import { r as stripOuterParens } from "./default-normalizer-DGMXypHg-CPf7oyZA.mjs";
5
+ import { t as buildTargetDetails } from "./planner-target-details-CIQ789Gc-Cug2V5g5.mjs";
6
+ import { DdlColumn, FunctionColumnDefault, LiteralColumnDefault, opaqueSql } from "@prisma/orm-family-sql/relational-core/ast";
7
+ import { ifDefined } from "@prisma/orm-framework/utils/defined";
8
+ import "@prisma/orm-framework/components/codec";
9
+ import { blindCast } from "@prisma/orm-framework/utils/casts";
10
+ import { assertNever } from "@prisma/orm-framework/utils/internal-error";
11
+ import "@prisma/orm-family-sql/contract/data-type";
12
+ import { type } from "arktype";
13
+ import { expectAbsent, expectPresent, issueOutcome } from "@prisma/orm-framework/components/control";
14
+ import { checkSqlExpressionText, convertedColumnMeta, createSqlTextSources, isUnfilledSlot, requiredColumnMeta, slotSource, sqlOfSlot } from "@prisma/orm-family-sql/family/control";
15
+ import { RelationalSchemaNodeKind, sqlColumnTypesEqual } from "@prisma/orm-family-sql/schema-ir/types";
16
+ import { errorMigrationOperationOptionRemoved, unfilledPlaceholderOperation } from "@prisma/orm-framework/errors/migration";
17
+ import { REFERENTIAL_ACTION_SQL } from "@prisma/orm-family-sql/contract/referential-action-sql";
18
+ import { TsExpression, jsonToTsSource, tsArraySource, tsObjectSource, tsQuotedTextSource } from "@prisma/orm-framework/ts-render";
19
+ //#region ../../../3-targets/sqlite/1-target/dist/op-factory-call-emj9Xp05.mjs
20
+ function foldAsciiLetters(identifier) {
21
+ return identifier.replace(/[A-Z]/g, (letter) => letter.toLowerCase());
22
+ }
23
+ /**
24
+ * Whether SQLite takes two identifiers for the same name. It compares table and index names without regard to the case of ASCII letters, and compares every other character exactly.
25
+ */
26
+ function sqliteIdentifiersCollide(left, right) {
27
+ return foldAsciiLetters(left) === foldAsciiLetters(right);
28
+ }
29
+ function step(description, sql, params, expectation) {
30
+ return {
31
+ description,
32
+ sql,
33
+ ...ifDefined("params", params),
34
+ ...ifDefined("expectation", expectation)
35
+ };
36
+ }
37
+ /** The text a `DdlColumn`'s type ends with when the column is SQLite's inline `INTEGER PRIMARY KEY AUTOINCREMENT`. */
38
+ const INLINE_AUTOINCREMENT_PRIMARY_KEY = " PRIMARY KEY AUTOINCREMENT";
39
+ /** The DDL default of a contract default: `autoincrement()` is written as part of the column's type instead. */
40
+ function sqliteDefaultToDdlColumnDefault(columnDefault) {
41
+ if (!columnDefault) return void 0;
42
+ switch (columnDefault.kind) {
43
+ case "literal": return new LiteralColumnDefault(columnDefault.value);
44
+ case "function":
45
+ if (columnDefault.expression === "autoincrement()") return void 0;
46
+ return new FunctionColumnDefault(opaqueSql(columnDefault.expression));
47
+ default: {
48
+ const exhaustive = columnDefault;
49
+ return assertNever(exhaustive, `sqliteDefaultToDdlColumnDefault: unhandled kind "${blindCast(exhaustive).kind}"`);
50
+ }
51
+ }
52
+ }
53
+ /**
54
+ * A column spec an earlier version wrote carries its default as SQL text in `defaultSql`, empty when it has none.
55
+ */
56
+ function refuseEarlierColumnSpecs(operation, tableName, columns) {
57
+ const earlier = columns.find((column) => Object.hasOwn(column, "defaultSql"));
58
+ if (earlier === void 0) return;
59
+ throw errorMigrationOperationOptionRemoved({
60
+ operation,
61
+ option: "defaultSql",
62
+ subject: `column ${JSON.stringify(earlier.name)} of table ${JSON.stringify(tableName)}`,
63
+ rewrite: "Write the column's default as `default: { kind: 'literal', value }` or `default: { kind: 'function', expression }`, with the column's `codecRef`, in place of `defaultSql`, and delete an empty `defaultSql`.",
64
+ upgradeEntry: "migration-ts-column-defaults"
65
+ });
66
+ }
67
+ /** The `DEFAULT …` clause the adapter writes for a column spec, `''` when it has none. */
68
+ function renderSpecDefault$1(column, tableName, lowerer) {
69
+ const ddlDefault = column.inlineAutoincrementPrimaryKey ? void 0 : sqliteDefaultToDdlColumnDefault(column.default);
70
+ return lowerer.renderColumnDefault(new DdlColumn({
71
+ name: column.name,
72
+ type: column.typeSql,
73
+ ...ifDefined("default", ddlDefault),
74
+ ...ifDefined("codecRef", column.codecRef)
75
+ }), tableName);
76
+ }
77
+ /**
78
+ * Renders a single column's inline DDL fragment within a `CREATE TABLE`
79
+ * statement. Honours the `inlineAutoincrementPrimaryKey` flag — SQLite
80
+ * treats `INTEGER PRIMARY KEY AUTOINCREMENT` as a special form that aliases
81
+ * `rowid`, and the column must not carry a `DEFAULT` or repeat `NOT NULL`.
82
+ */
83
+ function renderColumnDefinition(column, defaultClause) {
84
+ const parts = [quoteIdentifier(column.name), column.typeSql];
85
+ if (column.inlineAutoincrementPrimaryKey) parts.push("PRIMARY KEY AUTOINCREMENT");
86
+ else {
87
+ if (defaultClause) parts.push(defaultClause);
88
+ if (!column.nullable) parts.push("NOT NULL");
89
+ }
90
+ return parts.join(" ");
91
+ }
92
+ /**
93
+ * Renders an inline FOREIGN KEY constraint clause for a `CREATE TABLE`
94
+ * body. Every `SqliteForeignKeySpec` is constraint-bearing by construction
95
+ * (`tableSpecFromNode` only ever builds specs from schema-IR FK nodes, which
96
+ * are themselves constraint-only — a non-constraint FK contributes no node).
97
+ */
98
+ function renderForeignKeyClause(fk) {
99
+ let sql = `${fk.name ? `CONSTRAINT ${quoteIdentifier(fk.name)} ` : ""}FOREIGN KEY (${fk.columns.map(quoteIdentifier).join(", ")}) REFERENCES ${quoteIdentifier(fk.references.table)} (${fk.references.columns.map(quoteIdentifier).join(", ")})`;
100
+ if (fk.onDelete !== void 0) sql += ` ON DELETE ${REFERENTIAL_ACTION_SQL[fk.onDelete]}`;
101
+ if (fk.onUpdate !== void 0) sql += ` ON UPDATE ${REFERENTIAL_ACTION_SQL[fk.onUpdate]}`;
102
+ return sql;
103
+ }
104
+ function text(value) {
105
+ return `'${escapeLiteral(value)}'`;
106
+ }
107
+ function columnRow(column) {
108
+ return `(${text(column.name)}, ${text(column.typeSql.toLowerCase())}, ${column.notNull ? 1 : 0}, ${column.primaryKeyPosition})`;
109
+ }
110
+ /** Checks that the table has exactly these columns, each with its type, nullability and primary key position. */
111
+ function tableColumnsCheck(tableName, columns) {
112
+ const info = `pragma_table_info(${text(tableName)})`;
113
+ return {
114
+ description: `verify table "${tableName}" has exactly its columns`,
115
+ sql: `SELECT (SELECT COUNT(*) FROM ${info}) = ${columns.length} AND (SELECT COUNT(*) FROM ${info} WHERE (name, LOWER(type), "notnull", pk) IN (VALUES ${columns.map(columnRow).join(", ")})) = ${columns.length}`
116
+ };
117
+ }
118
+ /** Checks the column's type and nullability. */
119
+ function columnShapeCheck(tableName, column) {
120
+ return {
121
+ description: `verify column "${column.name}" on "${tableName}" has type ${column.typeSql} and ${column.notNull ? "is required" : "is optional"}`,
122
+ sql: `SELECT COUNT(*) > 0 FROM pragma_table_info(${text(tableName)}) WHERE name = ${text(column.name)} AND LOWER(type) = ${text(column.typeSql.toLowerCase())} AND "notnull" = ${column.notNull ? 1 : 0}`
123
+ };
124
+ }
125
+ /** Checks that the index is on the table, covers exactly these columns in this order, and is unique or not. */
126
+ function indexDefinitionCheck(tableName, indexName, columns, unique) {
127
+ const positions = columns.map((column, seqno) => `(${seqno}, ${text(column)})`).join(", ");
128
+ const info = `pragma_index_info(${text(indexName)})`;
129
+ return {
130
+ description: `verify index "${indexName}" on "${tableName}" covers (${columns.join(", ")})`,
131
+ sql: `SELECT EXISTS (SELECT 1 FROM pragma_index_list(${text(tableName)}) WHERE name = ${text(indexName)} AND "unique" = ${unique ? 1 : 0}) AND (SELECT COUNT(*) FROM ${info}) = ${columns.length} AND (SELECT COUNT(*) FROM ${info} WHERE (seqno, name) IN (VALUES ${positions})) = ${columns.length}`
132
+ };
133
+ }
134
+ function addColumnExecuteSql(tableName, column, defaultClause) {
135
+ return [
136
+ `ALTER TABLE ${quoteIdentifier(tableName)}`,
137
+ `ADD COLUMN ${quoteIdentifier(column.name)} ${column.typeSql}`,
138
+ defaultClause,
139
+ column.nullable ? "" : "NOT NULL"
140
+ ].filter(Boolean).join(" ");
141
+ }
142
+ function dropColumnExecuteSql(tableName, columnName) {
143
+ return `ALTER TABLE ${quoteIdentifier(tableName)} DROP COLUMN ${quoteIdentifier(columnName)}`;
144
+ }
145
+ async function addColumn(tableName, column, lowerer) {
146
+ refuseEarlierColumnSpecs("addColumn", tableName, [column]);
147
+ const defaultClause = await renderSpecDefault$1(column, tableName, lowerer);
148
+ const checks = columnExistsAst(tableName, column.name);
149
+ const absent = await lowerer.lowerToExecuteRequest(checks.columnAbsent());
150
+ const present = await lowerer.lowerToExecuteRequest(checks.columnPresent());
151
+ return {
152
+ id: `column.${tableName}.${column.name}`,
153
+ label: `Add column ${column.name} on ${tableName}`,
154
+ summary: `Adds column ${column.name} on ${tableName}`,
155
+ operationClass: "additive",
156
+ target: {
157
+ id: "sqlite",
158
+ details: buildTargetDetails("column", column.name, tableName)
159
+ },
160
+ precheck: [step(`ensure column "${column.name}" is missing`, absent.sql, absent.params, expectAbsent(`column "${column.name}" on "${tableName}"`))],
161
+ execute: [step(`add column "${column.name}"`, addColumnExecuteSql(tableName, column, defaultClause))],
162
+ postcheck: [step(`verify column "${column.name}" exists`, present.sql, present.params, expectPresent(`column "${column.name}" on "${tableName}"`)), columnShapeCheck(tableName, {
163
+ name: column.name,
164
+ typeSql: column.typeSql,
165
+ notNull: !column.nullable
166
+ })]
167
+ };
168
+ }
169
+ function renameColumnExecuteSql(tableName, fromName, toName) {
170
+ return `ALTER TABLE ${quoteIdentifier(tableName)} RENAME COLUMN ${quoteIdentifier(fromName)} TO ${quoteIdentifier(toName)}`;
171
+ }
172
+ /**
173
+ * Renames a column. SQLite updates the indexes, foreign keys and triggers that name it, and keeps
174
+ * index names. SQLite takes names that differ only in case for the same name, so the new name
175
+ * must be free whatever its case, except in a rename that only changes case, which SQLite performs
176
+ * in one statement.
177
+ */
178
+ function renameColumnOperationId(tableName, fromName) {
179
+ return `renameColumn.${tableName}.${fromName}`;
180
+ }
181
+ async function renameColumn(tableName, fromName, toName, lowerer) {
182
+ const fromChecks = columnExistsAst(tableName, fromName);
183
+ const toChecks = columnExistsAst(tableName, toName);
184
+ const fromPresent = await lowerer.lowerToExecuteRequest(fromChecks.columnPresent());
185
+ const onlyCase = sqliteIdentifiersCollide(fromName, toName);
186
+ const toAbsent = await lowerer.lowerToExecuteRequest(onlyCase ? toChecks.columnAbsent() : columnNameTakenAst(tableName, toName).nameFree());
187
+ const toPresent = await lowerer.lowerToExecuteRequest(toChecks.columnPresent());
188
+ const fromAbsent = await lowerer.lowerToExecuteRequest(fromChecks.columnAbsent());
189
+ return {
190
+ id: renameColumnOperationId(tableName, fromName),
191
+ label: `Rename column ${fromName} on ${tableName} to ${toName}`,
192
+ summary: `Renames column ${fromName} on ${tableName} to ${toName}, keeping its values`,
193
+ operationClass: "widening",
194
+ target: {
195
+ id: "sqlite",
196
+ details: buildTargetDetails("column", toName, tableName)
197
+ },
198
+ precheck: [step(`ensure column "${fromName}" exists on "${tableName}"`, fromPresent.sql, fromPresent.params, expectPresent(`column "${fromName}" on "${tableName}"`)), step(`ensure column "${toName}" does not exist on "${tableName}"`, toAbsent.sql, toAbsent.params, expectAbsent(onlyCase ? `column "${toName}" on "${tableName}"` : `a column named "${toName}" on "${tableName}" in any case`))],
199
+ execute: [step(`rename column "${fromName}" on "${tableName}" to "${toName}"`, renameColumnExecuteSql(tableName, fromName, toName))],
200
+ postcheck: [step(`verify column "${toName}" exists on "${tableName}"`, toPresent.sql, toPresent.params, expectPresent(`column "${toName}" on "${tableName}"`)), step(`verify column "${fromName}" no longer exists on "${tableName}"`, fromAbsent.sql, fromAbsent.params, expectAbsent(`column "${fromName}" on "${tableName}"`))]
201
+ };
202
+ }
203
+ function buildCreateIndexSql(tableName, indexName, columns, unique = false) {
204
+ return `CREATE ${unique ? "UNIQUE " : ""}INDEX ${quoteIdentifier(indexName)} ON ${quoteIdentifier(tableName)} (${columns.map(quoteIdentifier).join(", ")})`;
205
+ }
206
+ function buildDropIndexSql(indexName) {
207
+ return `DROP INDEX IF EXISTS ${quoteIdentifier(indexName)}`;
208
+ }
209
+ async function tableExistsSteps(lowerer, tableName) {
210
+ const checks = tableExistsAst(tableName);
211
+ return {
212
+ present: await lowerer.lowerToExecuteRequest(checks.tablePresent()),
213
+ absent: await lowerer.lowerToExecuteRequest(checks.tableAbsent())
214
+ };
215
+ }
216
+ /**
217
+ * Renders the body of a `CREATE TABLE <name> ( … )` statement from a flat
218
+ * `SqliteTableSpec`. SQLite's `INTEGER PRIMARY KEY AUTOINCREMENT` form is
219
+ * inline on the column; the table-level PRIMARY KEY clause is emitted only
220
+ * when no column carries `inlineAutoincrementPrimaryKey`.
221
+ */
222
+ function renderCreateTableSql(tableName, spec, defaultClauses) {
223
+ const columnDefs = spec.columns.map((column, index) => renderColumnDefinition(column, defaultClauses[index] ?? ""));
224
+ const constraintDefs = [];
225
+ const hasInlinePk = spec.columns.some((c) => c.inlineAutoincrementPrimaryKey);
226
+ if (spec.primaryKey && !hasInlinePk) constraintDefs.push(`PRIMARY KEY (${spec.primaryKey.columns.map(quoteIdentifier).join(", ")})`);
227
+ for (const u of spec.uniques ?? []) {
228
+ const name = u.name ? `CONSTRAINT ${quoteIdentifier(u.name)} ` : "";
229
+ constraintDefs.push(`${name}UNIQUE (${u.columns.map(quoteIdentifier).join(", ")})`);
230
+ }
231
+ for (const fk of spec.foreignKeys ?? []) {
232
+ const clause = renderForeignKeyClause(fk);
233
+ if (clause) constraintDefs.push(clause);
234
+ }
235
+ const allDefs = [...columnDefs, ...constraintDefs];
236
+ return `CREATE TABLE ${quoteIdentifier(tableName)} (\n ${allDefs.join(",\n ")}\n)`;
237
+ }
238
+ function renameTableViaName(toName) {
239
+ return `_prisma_rename_${toName}`;
240
+ }
241
+ function renameChangesOnlyCase(fromName, toName) {
242
+ return sqliteIdentifiersCollide(fromName, toName);
243
+ }
244
+ /**
245
+ * SQLite takes names that differ only in the case of ASCII letters for the
246
+ * same name, so such a rename (`userProfile` to `UserProfile`) is refused as
247
+ * "already exists" when done in one statement. It goes through a temporary name.
248
+ */
249
+ function renameTableSteps(fromName, toName) {
250
+ const from = quoteIdentifier(fromName);
251
+ const to = quoteIdentifier(toName);
252
+ if (!renameChangesOnlyCase(fromName, toName)) return [step(`rename table "${fromName}" to "${toName}"`, `ALTER TABLE ${from} RENAME TO ${to}`)];
253
+ const viaName = renameTableViaName(toName);
254
+ const via = quoteIdentifier(viaName);
255
+ return [step(`rename table "${fromName}" to "${viaName}" (SQLite table names are case-insensitive)`, `ALTER TABLE ${from} RENAME TO ${via}`), step(`rename table "${viaName}" to "${toName}"`, `ALTER TABLE ${via} RENAME TO ${to}`)];
256
+ }
257
+ /** The table a rebuild of `tableName` creates, copies into, and renames to `tableName`. */
258
+ function rebuiltTableName(tableName) {
259
+ return `_prisma_new_${tableName}`;
260
+ }
261
+ async function recreateTable(args, lowerer) {
262
+ const { tableName, contractTable, schemaColumnNames, indexes, summary, postchecks, operationClass, copyExpressions = {}, temporaryValues = {}, retypedColumns = [] } = args;
263
+ refuseEarlierColumnSpecs("recreateTable", tableName, contractTable.columns);
264
+ const tempName = rebuiltTableName(tableName);
265
+ const liveSet = new Set(schemaColumnNames);
266
+ const convertedBy = (column) => Object.hasOwn(copyExpressions, column) ? copyExpressions[column] : void 0;
267
+ const copiedFrom = (column) => convertedBy(column) ?? (Object.hasOwn(temporaryValues, column) ? temporaryValues[column] : void 0);
268
+ const sharedColumns = contractTable.columns.filter((c) => liveSet.has(c.name) || copiedFrom(c.name) !== void 0).map((c) => c.name);
269
+ const columnList = sharedColumns.map(quoteIdentifier).join(", ");
270
+ const selectList = sharedColumns.map((column) => copiedFrom(column) ?? quoteIdentifier(column)).join(", ");
271
+ const indexStatements = indexes.map((idx) => ({
272
+ description: `recreate index "${idx.name}" on "${tableName}"`,
273
+ sql: buildCreateIndexSql(tableName, idx.name, idx.columns)
274
+ }));
275
+ const conversions = Object.fromEntries(sharedColumns.flatMap((column) => {
276
+ const expression = convertedBy(column);
277
+ return expression === void 0 ? [] : [[column, expression]];
278
+ }));
279
+ const copyStep = sharedColumns.length > 0 ? [{
280
+ ...step(`copy data from "${tableName}" to "${tempName}"`, `INSERT INTO ${quoteIdentifier(tempName)} (${columnList}) SELECT ${selectList} FROM ${quoteIdentifier(tableName)}`),
281
+ ...Object.keys(conversions).length === 0 ? {} : { meta: { conversionCopy: {
282
+ table: tableName,
283
+ expressions: conversions
284
+ } } }
285
+ }] : [];
286
+ const defaultClauses = await renderSpecDefaults(contractTable, tableName, lowerer);
287
+ const clauseByColumn = new Map(contractTable.columns.map((column, index) => [column.name, defaultClauses[index] ?? ""]));
288
+ const tableSteps = await tableExistsSteps(lowerer, tableName);
289
+ const tempSteps = await tableExistsSteps(lowerer, tempName);
290
+ return {
291
+ id: `recreateTable.${tableName}`,
292
+ label: `Recreate table ${tableName}`,
293
+ summary,
294
+ operationClass,
295
+ target: {
296
+ id: "sqlite",
297
+ details: buildTargetDetails("table", tableName)
298
+ },
299
+ precheck: [
300
+ step(`ensure table "${tableName}" exists`, tableSteps.present.sql, tableSteps.present.params, expectPresent(`table "${tableName}"`)),
301
+ step(`ensure temp table "${tempName}" does not exist`, tempSteps.absent.sql, tempSteps.absent.params, expectAbsent(`temp table "${tempName}"`)),
302
+ sourceColumnsCheck(tableName, schemaColumnNames)
303
+ ],
304
+ execute: [
305
+ step(`create new table "${tempName}" with desired schema`, renderCreateTableSql(tempName, contractTable, defaultClauses)),
306
+ ...copyStep,
307
+ step(`drop old table "${tableName}"`, `DROP TABLE ${quoteIdentifier(tableName)}`),
308
+ step(`rename "${tempName}" to "${tableName}"`, `ALTER TABLE ${quoteIdentifier(tempName)} RENAME TO ${quoteIdentifier(tableName)}`),
309
+ ...indexStatements
310
+ ],
311
+ postcheck: [
312
+ step(`verify table "${tableName}" exists`, tableSteps.present.sql, tableSteps.present.params, expectPresent(`table "${tableName}"`)),
313
+ step(`verify temp table "${tempName}" is gone`, tempSteps.absent.sql, tempSteps.absent.params, expectAbsent(`temp table "${tempName}"`)),
314
+ rebuiltTableCheck(tableName, renderCreateTableSql(tableName, contractTable, defaultClauses)),
315
+ ...postchecks.flatMap((check) => "sql" in check ? [markedStep(tableName, check)] : defaultPostcheck(tableName, check, clauseByColumn.get(check.columnDefault))),
316
+ ...contractTable.columns.flatMap((column) => {
317
+ const by = Object.hasOwn(conversions, column.name) ? "conversion" : retypedColumns.includes(column.name) ? "cast" : void 0;
318
+ return by === void 0 ? [] : [{
319
+ ...storageClassCheck(tableName, column),
320
+ meta: convertedColumnMeta(tableName, column.name, by)
321
+ }];
322
+ })
323
+ ]
324
+ };
325
+ }
326
+ /**
327
+ * Checks that the table has exactly the columns the rebuild reads, the ones it copies and the ones it
328
+ * leaves out. The rebuild copies only the columns it knows, so on a table with another column, such
329
+ * as one a later migration added, it would drop that column and its values.
330
+ */
331
+ function sourceColumnsCheck(tableName, columns) {
332
+ const info = `pragma_table_info('${escapeLiteral(tableName)}')`;
333
+ const named = columns.length === 0 ? "" : ` AND (SELECT COUNT(*) FROM ${info} WHERE name IN (${quoteSqlList(columns)})) = ${columns.length}`;
334
+ return {
335
+ description: `ensure table "${tableName}" has exactly the columns the rebuild copies or leaves out (${columns.join(", ")})`,
336
+ sql: `SELECT (SELECT COUNT(*) FROM ${info}) = ${columns.length}${named}`
337
+ };
338
+ }
339
+ /**
340
+ * Checks that the table is stored as the statement the rebuild writes. SQLite keeps a table's
341
+ * `CREATE TABLE` text as written, and renaming the rebuilt table only replaces its name, so this holds
342
+ * once the rebuild ran and not before, whatever text an earlier table had. It is the only check of
343
+ * what SQLite keeps in that text alone, such as `AUTOINCREMENT`.
344
+ */
345
+ function rebuiltTableCheck(tableName, statement) {
346
+ return {
347
+ description: `verify "${tableName}" is stored as the rebuilt table`,
348
+ sql: `SELECT (SELECT sql FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tableName)}') = '${escapeLiteral(statement)}'`
349
+ };
350
+ }
351
+ function markedStep(tableName, check) {
352
+ const { requiredColumn, ...step } = check;
353
+ const meta = { ...requiredColumn === void 0 ? {} : requiredColumnMeta(tableName, requiredColumn.column, requiredColumn.reason) };
354
+ return Object.keys(meta).length === 0 ? step : {
355
+ ...step,
356
+ meta
357
+ };
358
+ }
359
+ /**
360
+ * The storage classes SQLite keeps a value in once a column of `typeSql` has taken it: the column's
361
+ * type affinity converts what it can, so a value of another class is one it could not convert.
362
+ * See https://www.sqlite.org/datatype3.html#determination_of_column_affinity.
363
+ */
364
+ function affinityStorageClasses(typeSql) {
365
+ const declared = typeSql.toUpperCase();
366
+ if (declared.includes("INT")) return ["integer"];
367
+ if ([
368
+ "CHAR",
369
+ "CLOB",
370
+ "TEXT"
371
+ ].some((part) => declared.includes(part))) return ["text"];
372
+ if (declared === "" || declared.includes("BLOB")) return ["blob"];
373
+ if ([
374
+ "REAL",
375
+ "FLOA",
376
+ "DOUB"
377
+ ].some((part) => declared.includes(part))) return ["real"];
378
+ return ["integer", "real"];
379
+ }
380
+ /**
381
+ * The check that the copy into a rebuilt table converted every value of a retyped column to the
382
+ * column's new type. SQLite keeps a value it cannot convert in its old storage class, so a value of
383
+ * any other class than the column's affinity keeps fails the check.
384
+ */
385
+ function storageClassCheck(tableName, column) {
386
+ const classes = ["null", ...affinityStorageClasses(column.typeSql)].map((storageClass) => `'${storageClass}'`).join(", ");
387
+ return {
388
+ description: `verify every value of "${column.name}" on "${tableName}" is stored as ${column.typeSql}`,
389
+ sql: `SELECT NOT EXISTS (SELECT 1 FROM ${quoteIdentifier(tableName)} WHERE typeof(${quoteIdentifier(column.name)}) NOT IN (${classes}))`
390
+ };
391
+ }
392
+ const ConversionCopyMeta = type({ conversionCopy: {
393
+ table: "string",
394
+ expressions: "Record<string, string>"
395
+ } });
396
+ /**
397
+ * The table a rebuild's copy step reads and the copy expression of each column its conversions
398
+ * convert, when the step converts any: an error of the step may be an error of one of them.
399
+ */
400
+ function conversionCopyOf(step) {
401
+ const meta = ConversionCopyMeta(step.meta ?? {});
402
+ return meta instanceof type.errors ? void 0 : meta.conversionCopy;
403
+ }
404
+ function renderSpecDefaults(spec, tableName, lowerer) {
405
+ return Promise.all(spec.columns.map((column) => renderSpecDefault$1(column, tableName, lowerer)));
406
+ }
407
+ /**
408
+ * Checks the column's default is the text of its `DEFAULT …` clause. SQLite's
409
+ * `pragma_table_info.dflt_value` strips the outer parentheses of an expression
410
+ * default, so `(strftime('%Y-%m-%dT%H:%M:%fZ','now'))` is stored as `strftime('%Y-%m-%dT%H:%M:%fZ','now')`; they are
411
+ * stripped here too.
412
+ */
413
+ function defaultPostcheck(tableName, check, clause) {
414
+ if (clause === void 0 || !clause.startsWith("DEFAULT ")) return [];
415
+ const expectedRaw = stripOuterParens(clause.slice(8));
416
+ return [{
417
+ description: check.description,
418
+ sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${escapeLiteral(tableName)}') WHERE name = '${escapeLiteral(check.columnDefault)}' AND dflt_value = '${escapeLiteral(expectedRaw)}'`
419
+ }];
420
+ }
421
+ /**
422
+ * Build a one-line summary of a recreate-table operation from the schema-diff
423
+ * issues that triggered it. Lives next to `recreateTable` so the planner
424
+ * (which has the issues) can produce the same description the factory
425
+ * used to build inline. Keeping the formatting target-side keeps
426
+ * `RecreateTableCall` issue-free at the IR layer. `SchemaDiffIssue` carries
427
+ * no rendered message, so this renders one from each issue's path.
428
+ */
429
+ function buildRecreateSummary(tableName, issues) {
430
+ return `Recreates table ${tableName} to apply schema changes: ${issues.map((i) => i.path.join("/")).join("; ")}`;
431
+ }
432
+ function nodeKindOf(issue) {
433
+ const node = issue.expected ?? issue.actual;
434
+ if (node === void 0) return void 0;
435
+ return blindCast(node).nodeKind;
436
+ }
437
+ /**
438
+ * Returns the columns the contract expects as the table's primary key. Picks
439
+ * up SQLite's inline `INTEGER PRIMARY KEY AUTOINCREMENT` form when no
440
+ * explicit `primaryKey` clause is set on the spec.
441
+ */
442
+ function expectedPrimaryKeyColumns(spec) {
443
+ if (spec.primaryKey) return spec.primaryKey.columns;
444
+ const inlinePk = spec.columns.find((c) => c.inlineAutoincrementPrimaryKey);
445
+ return inlinePk ? [inlinePk.name] : [];
446
+ }
447
+ /** The text `pragma_foreign_key_list` reports for a referential action; SQLite reads an absent action as `NO ACTION`. */
448
+ function referentialActionText(action) {
449
+ return REFERENTIAL_ACTION_SQL[action ?? "noAction"];
450
+ }
451
+ function quoteSqlList(values) {
452
+ return values.map((v) => `'${escapeLiteral(v)}'`).join(", ");
453
+ }
454
+ /**
455
+ * A condition on the index aliased `l`: it covers exactly these columns. Order is not checked, because SQLite identifies a unique index by its column set.
456
+ */
457
+ function indexCoversExactly(columns) {
458
+ return `(SELECT COUNT(*) FROM pragma_index_info(l.name)) = ${columns.length} AND (SELECT COUNT(*) FROM pragma_index_info(l.name) WHERE name IN (${quoteSqlList(columns)})) = ${columns.length}`;
459
+ }
460
+ function columnNameFromNode(issue) {
461
+ const node = issue.expected ?? issue.actual;
462
+ if (node === void 0) return void 0;
463
+ return blindCast(node).name;
464
+ }
465
+ /**
466
+ * A column-default issue's own node has no back-reference to its owning
467
+ * column — it's a transient child built by `SqlColumnIR.children()`. The
468
+ * column's id (`column:<name>`) is always the diff path's second-to-last
469
+ * segment for a default issue (`[..., tableId, columnId, 'default']`), so
470
+ * the name is recovered from the path rather than the node.
471
+ */
472
+ function columnNameFromDefaultIssuePath(issue) {
473
+ const columnId = issue.path[issue.path.length - 2];
474
+ if (columnId === void 0) return void 0;
475
+ return columnId.startsWith("column:") ? columnId.slice(7) : columnId;
476
+ }
477
+ /**
478
+ * Compares the declared type with `typeSql`: exactly for a data type named by its catalog text, as
479
+ * verify compares it (ADR 273), and without case otherwise.
480
+ */
481
+ function declaredTypeMatches(expected, typeSql) {
482
+ return expected.catalogText !== void 0 ? `type = '${escapeLiteral(typeSql)}'` : `LOWER(type) = '${escapeLiteral(typeSql.toLowerCase())}'`;
483
+ }
484
+ /**
485
+ * Per-issue postchecks verifying the recreated table's shape against the
486
+ * expected spec. Column-level issues (`sql-column` `not-equal`,
487
+ * `sql-column-default` any reason) emit one targeted check each;
488
+ * constraint-level issues (`sql-primary-key`, `sql-unique`, `sql-foreign-key`,
489
+ * any reason) emit one `pragma_*`-driven check per declared constraint in the
490
+ * expected spec, so a recreated table with the right columns but the wrong
491
+ * PK / unique / FK shape fails the postcheck instead of passing silently.
492
+ * Exported so the planner can pre-build the list at construction time and
493
+ * `RecreateTableCall` doesn't have to carry `SchemaDiffIssue` objects through
494
+ * to render time.
495
+ */
496
+ function buildRecreatePostchecks(tableName, issues, spec, copiedColumns = /* @__PURE__ */ new Set(), backfilledColumns = /* @__PURE__ */ new Set()) {
497
+ const checks = [];
498
+ const t = escapeLiteral(tableName);
499
+ const byName = new Map(spec.columns.map((c) => [c.name, c]));
500
+ let hasPkIssue = false;
501
+ let hasUniqueIssue = false;
502
+ let hasFkIssue = false;
503
+ for (const issue of issues) {
504
+ const nodeKind = nodeKindOf(issue);
505
+ if (nodeKind === RelationalSchemaNodeKind.column && issueOutcome(issue) === "not-found") {
506
+ const columnName = columnNameFromNode(issue);
507
+ const column = columnName === void 0 ? void 0 : byName.get(columnName);
508
+ if (columnName === void 0 || column === void 0) continue;
509
+ const takesNoValue = !column.nullable && column.default === void 0 && !copiedColumns.has(columnName);
510
+ checks.push({
511
+ description: `verify "${columnName}" nullability on "${tableName}"`,
512
+ sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${escapeLiteral(columnName)}' AND "notnull" = ${column.nullable ? 0 : 1}`,
513
+ ...backfilledColumns.has(columnName) ? { requiredColumn: {
514
+ column: columnName,
515
+ reason: "backfillMissedRows"
516
+ } } : takesNoValue ? { requiredColumn: {
517
+ column: columnName,
518
+ reason: "newField"
519
+ } } : {}
520
+ });
521
+ continue;
522
+ }
523
+ if (nodeKind === RelationalSchemaNodeKind.column && issueOutcome(issue) === "not-equal") {
524
+ const columnName = columnNameFromNode(issue);
525
+ if (columnName === void 0) continue;
526
+ const c = escapeLiteral(columnName);
527
+ const expected = blindCast(issue.expected);
528
+ const actual = blindCast(issue.actual);
529
+ if (expected.nullable !== actual.nullable) checks.push({
530
+ description: `verify "${columnName}" nullability on "${tableName}"`,
531
+ sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND "notnull" = ${expected.nullable ? 0 : 1}`,
532
+ ...expected.nullable ? {} : { requiredColumn: {
533
+ column: columnName,
534
+ reason: backfilledColumns.has(columnName) ? "backfillMissedRows" : "nullValues"
535
+ } }
536
+ });
537
+ if (!sqlColumnTypesEqual(expected, actual)) {
538
+ const colSpec = byName.get(columnName);
539
+ if (colSpec) checks.push({
540
+ description: `verify "${columnName}" type on "${tableName}"`,
541
+ sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND ${declaredTypeMatches(expected, colSpec.typeSql)}`
542
+ });
543
+ }
544
+ continue;
545
+ }
546
+ if (nodeKind === RelationalSchemaNodeKind.columnDefault) {
547
+ const columnName = columnNameFromDefaultIssuePath(issue);
548
+ if (columnName === void 0) continue;
549
+ const c = escapeLiteral(columnName);
550
+ if (issueOutcome(issue) === "not-expected") {
551
+ checks.push({
552
+ description: `verify "${columnName}" has no default on "${tableName}"`,
553
+ sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND dflt_value IS NULL`
554
+ });
555
+ continue;
556
+ }
557
+ if (byName.get(columnName)?.default !== void 0) checks.push({
558
+ description: `verify "${columnName}" default on "${tableName}"`,
559
+ columnDefault: columnName
560
+ });
561
+ continue;
562
+ }
563
+ if (nodeKind === RelationalSchemaNodeKind.primaryKey) hasPkIssue = true;
564
+ if (nodeKind === RelationalSchemaNodeKind.unique) hasUniqueIssue = true;
565
+ if (nodeKind === RelationalSchemaNodeKind.foreignKey) hasFkIssue = true;
566
+ }
567
+ if (hasPkIssue) {
568
+ const pkColumns = expectedPrimaryKeyColumns(spec);
569
+ const colCount = pkColumns.length;
570
+ if (colCount === 0) checks.push({
571
+ description: `verify "${tableName}" has no primary key`,
572
+ sql: `SELECT (SELECT COUNT(*) FROM pragma_table_info('${t}') WHERE pk > 0) = 0`
573
+ });
574
+ else checks.push({
575
+ description: `verify primary key on "${tableName}"`,
576
+ sql: `SELECT (SELECT COUNT(*) FROM pragma_table_info('${t}') WHERE pk > 0) = ${colCount} AND (SELECT COUNT(*) FROM pragma_table_info('${t}') WHERE pk > 0 AND name IN (${quoteSqlList(pkColumns)})) = ${colCount}`
577
+ });
578
+ }
579
+ if (hasUniqueIssue) for (const u of spec.uniques ?? []) {
580
+ const description = u.name ? `verify unique constraint "${u.name}" on "${tableName}"` : `verify unique constraint (${u.columns.join(", ")}) on "${tableName}"`;
581
+ checks.push({
582
+ description,
583
+ sql: `SELECT EXISTS (SELECT 1 FROM pragma_index_list('${t}') l WHERE l."unique" = 1 AND ${indexCoversExactly(u.columns)})`
584
+ });
585
+ }
586
+ if (hasUniqueIssue) {
587
+ const expected = (spec.uniques ?? []).map((u) => `(${indexCoversExactly(u.columns)})`);
588
+ checks.push({
589
+ description: `verify "${tableName}" has no unique constraint besides the expected ones`,
590
+ sql: `SELECT NOT EXISTS (SELECT 1 FROM pragma_index_list('${t}') l WHERE l.origin = 'u' AND NOT (${expected.length === 0 ? "0" : expected.join(" OR ")}))`
591
+ });
592
+ }
593
+ if (hasFkIssue) {
594
+ for (const fk of spec.foreignKeys ?? []) {
595
+ const refTable = escapeLiteral(fk.references.table);
596
+ const colCount = fk.columns.length;
597
+ const tuples = fk.columns.map((from, i) => {
598
+ const to = fk.references.columns[i] ?? from;
599
+ return `('${escapeLiteral(from)}', '${escapeLiteral(to)}')`;
600
+ }).join(", ");
601
+ const description = `verify foreign key (${fk.columns.join(", ")}) → ${fk.references.table}(${fk.references.columns.join(", ")}) on "${tableName}"`;
602
+ checks.push({
603
+ description,
604
+ sql: `SELECT EXISTS (SELECT 1 FROM pragma_foreign_key_list('${t}') f WHERE f."table" = '${refTable}' AND f.on_delete = '${referentialActionText(fk.onDelete)}' AND f.on_update = '${referentialActionText(fk.onUpdate)}' GROUP BY f.id HAVING COUNT(*) = ${colCount} AND SUM(CASE WHEN (f."from", f."to") IN (${tuples}) THEN 1 ELSE 0 END) = ${colCount})`
605
+ });
606
+ }
607
+ const expected = spec.foreignKeys?.length ?? 0;
608
+ checks.push({
609
+ description: `verify "${tableName}" has exactly ${expected} foreign keys`,
610
+ sql: `SELECT (SELECT COUNT(DISTINCT id) FROM pragma_foreign_key_list('${t}')) = ${expected}`
611
+ });
612
+ }
613
+ return checks;
614
+ }
615
+ const TARGET_MIGRATION_MODULE = "@internal/sqlite/migration";
616
+ var SqliteOpFactoryCallNode = class extends TsExpression {
617
+ /** The operations this call lowers to, in order: one, unless the call carries companions. */
618
+ toOps(lowerer) {
619
+ return [this.toOp(lowerer)];
620
+ }
621
+ importRequirements() {
622
+ return [{
623
+ moduleSpecifier: TARGET_MIGRATION_MODULE,
624
+ symbol: this.factoryName
625
+ }];
626
+ }
627
+ freeze() {
628
+ Object.freeze(this);
629
+ }
630
+ };
631
+ /** Whether `call` is one of this target's calls, which lower through {@link SqliteOpFactoryCallNode.toOps}. */
632
+ function isSqliteOpFactoryCall(call) {
633
+ return call instanceof SqliteOpFactoryCallNode;
634
+ }
635
+ function renderDdlColumnDefault(def, sql) {
636
+ if (!def) return "";
637
+ if (def.kind === "literal") return `lit(${jsonToTsSource(def.value)})`;
638
+ return `fn(${sql.source(def.expression.text)})`;
639
+ }
640
+ function renderDdlColumnAsTsCall(column, sql) {
641
+ const opts = [];
642
+ if (column.notNull) opts.push("notNull: true");
643
+ if (column.primaryKey) opts.push("primaryKey: true");
644
+ if (column.default) opts.push(`default: ${renderDdlColumnDefault(column.default, sql)}`);
645
+ if (column.codecRef) opts.push(`codecRef: ${jsonToTsSource(column.codecRef)}`);
646
+ const optsStr = opts.length > 0 ? `, { ${opts.join(", ")} }` : "";
647
+ return `col(${jsonToTsSource(column.name)}, ${jsonToTsSource(column.type)}${optsStr})`;
648
+ }
649
+ function renderDdlConstraintAsTsCall(constraint) {
650
+ switch (constraint.kind) {
651
+ case "primary-key": {
652
+ const nameOpt = constraint.name ? `, { name: ${jsonToTsSource(constraint.name)} }` : "";
653
+ return `primaryKey(${jsonToTsSource(constraint.columns)}${nameOpt})`;
654
+ }
655
+ case "foreign-key": {
656
+ const opts = [];
657
+ if (constraint.name) opts.push(`name: ${jsonToTsSource(constraint.name)}`);
658
+ if (constraint.onDelete) opts.push(`onDelete: ${jsonToTsSource(constraint.onDelete)}`);
659
+ if (constraint.onUpdate) opts.push(`onUpdate: ${jsonToTsSource(constraint.onUpdate)}`);
660
+ const optsStr = opts.length > 0 ? `, { ${opts.join(", ")} }` : "";
661
+ return `foreignKey(${jsonToTsSource(constraint.columns)}, ${jsonToTsSource(constraint.refTable)}, ${jsonToTsSource(constraint.refColumns)}${optsStr})`;
662
+ }
663
+ case "unique": {
664
+ const nameOpt = constraint.name ? `, { name: ${jsonToTsSource(constraint.name)} }` : "";
665
+ return `unique(${jsonToTsSource(constraint.columns)}${nameOpt})`;
666
+ }
667
+ case "check-expression": throw sqliteError("CONTRACT.CONSTRAINT_INVALID", `The SQLite target does not support CHECK constraints (constraint "${constraint.name}"). The "checkConstraint" capability is Postgres-only — remove the "@@check" / "check()" declaration, or target Postgres.`, { meta: { constraintName: constraint.name } });
668
+ }
669
+ }
670
+ function constraintImportSymbols(constraints) {
671
+ if (!constraints || constraints.length === 0) return [];
672
+ const symbols = /* @__PURE__ */ new Set();
673
+ for (const c of constraints) if (c.kind === "primary-key") symbols.add("primaryKey");
674
+ else if (c.kind === "foreign-key") symbols.add("foreignKey");
675
+ else if (c.kind === "unique") symbols.add("unique");
676
+ return [...symbols];
677
+ }
678
+ function defaultImportSymbols(columns) {
679
+ const symbols = /* @__PURE__ */ new Set();
680
+ for (const col of columns) if (col.default?.kind === "literal") symbols.add("lit");
681
+ else if (col.default?.kind === "function") symbols.add("fn");
682
+ return [...symbols];
683
+ }
684
+ function columnShapesOf(columns, constraints) {
685
+ const primaryKey = constraints?.find((constraint) => constraint.kind === "primary-key");
686
+ return columns.map((column) => {
687
+ if (column.type.endsWith(" PRIMARY KEY AUTOINCREMENT")) return {
688
+ name: column.name,
689
+ typeSql: column.type.slice(0, -26),
690
+ notNull: false,
691
+ primaryKeyPosition: 1
692
+ };
693
+ return {
694
+ name: column.name,
695
+ typeSql: column.type,
696
+ notNull: column.notNull === true,
697
+ primaryKeyPosition: column.primaryKey ? 1 : (primaryKey?.columns.indexOf(column.name) ?? -1) + 1
698
+ };
699
+ });
700
+ }
701
+ var CreateTableCall = class extends SqliteOpFactoryCallNode {
702
+ factoryName = "createTable";
703
+ operationClass = "additive";
704
+ tableName;
705
+ columns;
706
+ constraints;
707
+ label;
708
+ constructor(tableName, columns, constraints) {
709
+ super();
710
+ this.tableName = tableName;
711
+ this.columns = Object.freeze([...columns]);
712
+ this.constraints = constraints ? Object.freeze([...constraints]) : void 0;
713
+ this.label = `Create table ${tableName}`;
714
+ this.freeze();
715
+ }
716
+ async toOp(lowerer) {
717
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `CreateTableCall.toOp: a DDL lowerer is required on the SQLite planner path (table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
718
+ factory: this.factoryName,
719
+ tableName: this.tableName
720
+ } });
721
+ const ddlNode = createTable({
722
+ table: this.tableName,
723
+ columns: this.columns,
724
+ ...ifDefined("constraints", this.constraints)
725
+ });
726
+ const statement = await lowerer.lowerToExecuteRequest(ddlNode);
727
+ const tableName = this.tableName;
728
+ const tableChecks = tableExistsAst(tableName);
729
+ const absent = await lowerer.lowerToExecuteRequest(tableChecks.tableAbsent());
730
+ const present = await lowerer.lowerToExecuteRequest(tableChecks.tablePresent());
731
+ return {
732
+ id: `table.${tableName}`,
733
+ label: `Create table ${tableName}`,
734
+ summary: `Creates table ${tableName} with required columns`,
735
+ operationClass: "additive",
736
+ target: {
737
+ id: "sqlite",
738
+ details: buildTargetDetails("table", tableName)
739
+ },
740
+ precheck: [step(`ensure table "${tableName}" does not exist`, absent.sql, absent.params, expectAbsent(`table "${tableName}"`))],
741
+ execute: [{
742
+ description: `create table "${tableName}"`,
743
+ sql: statement.sql,
744
+ params: statement.params ?? []
745
+ }],
746
+ postcheck: [step(`verify table "${tableName}" exists`, present.sql, present.params, expectPresent(`table "${tableName}"`)), tableColumnsCheck(tableName, columnShapesOf(this.columns, this.constraints))]
747
+ };
748
+ }
749
+ renderTypeScript() {
750
+ return this.#written().source;
751
+ }
752
+ #written() {
753
+ const sql = createSqlTextSources(TARGET_MIGRATION_MODULE);
754
+ const columnsList = this.columns.map((column) => renderDdlColumnAsTsCall(column, sql)).join(", ");
755
+ const constraintsList = this.constraints ? this.constraints.map(renderDdlConstraintAsTsCall).join(", ") : void 0;
756
+ const opts = [];
757
+ opts.push(`table: ${jsonToTsSource(this.tableName)}`);
758
+ opts.push(`columns: [${columnsList}]`);
759
+ if (constraintsList) opts.push(`constraints: [${constraintsList}]`);
760
+ return {
761
+ source: `this.createTable({ ${opts.join(", ")} })`,
762
+ imports: sql.imports()
763
+ };
764
+ }
765
+ importRequirements() {
766
+ const req = [];
767
+ if (this.columns.length > 0) {
768
+ req.push({
769
+ moduleSpecifier: TARGET_MIGRATION_MODULE,
770
+ symbol: "col"
771
+ });
772
+ for (const sym of defaultImportSymbols(this.columns)) req.push({
773
+ moduleSpecifier: TARGET_MIGRATION_MODULE,
774
+ symbol: sym
775
+ });
776
+ }
777
+ for (const sym of constraintImportSymbols(this.constraints)) req.push({
778
+ moduleSpecifier: TARGET_MIGRATION_MODULE,
779
+ symbol: sym
780
+ });
781
+ req.push(...this.#written().imports);
782
+ return req;
783
+ }
784
+ };
785
+ var DropTableCall = class extends SqliteOpFactoryCallNode {
786
+ factoryName = "dropTable";
787
+ operationClass = "destructive";
788
+ tableName;
789
+ label;
790
+ constructor(tableName) {
791
+ super();
792
+ this.tableName = tableName;
793
+ this.label = `Drop table ${tableName}`;
794
+ this.freeze();
795
+ }
796
+ async toOp(lowerer) {
797
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `DropTableCall.toOp: a lowerer is required on the SQLite planner path (table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
798
+ factory: this.factoryName,
799
+ tableName: this.tableName
800
+ } });
801
+ const checks = tableExistsAst(this.tableName);
802
+ const present = await lowerer.lowerToExecuteRequest(checks.tablePresent());
803
+ const absent = await lowerer.lowerToExecuteRequest(checks.tableAbsent());
804
+ return {
805
+ id: `dropTable.${this.tableName}`,
806
+ label: `Drop table ${this.tableName}`,
807
+ summary: `Drops table ${this.tableName} which is not in the contract`,
808
+ operationClass: "destructive",
809
+ target: {
810
+ id: "sqlite",
811
+ details: buildTargetDetails("table", this.tableName)
812
+ },
813
+ precheck: [step(`ensure table "${this.tableName}" exists`, present.sql, present.params, expectPresent(`table "${this.tableName}"`))],
814
+ execute: [step(`drop table "${this.tableName}"`, `DROP TABLE ${quoteIdentifier(this.tableName)}`)],
815
+ postcheck: [step(`verify table "${this.tableName}" is gone`, absent.sql, absent.params, expectAbsent(`table "${this.tableName}"`))]
816
+ };
817
+ }
818
+ renderTypeScript() {
819
+ return `this.dropTable({ table: ${jsonToTsSource(this.tableName)} })`;
820
+ }
821
+ importRequirements() {
822
+ return [];
823
+ }
824
+ };
825
+ /** The replaced indexes' drops, then their creates, since a create may take a dropped name. */
826
+ function indexReplacementCalls(replacements) {
827
+ return [...replacements.map(({ drop }) => drop), ...replacements.map(({ create }) => create)];
828
+ }
829
+ var RenameTableCall = class extends SqliteOpFactoryCallNode {
830
+ factoryName = "renameTable";
831
+ operationClass = "widening";
832
+ oldTableName;
833
+ /** The new name: the table's contract-side identity after the rename. */
834
+ tableName;
835
+ label;
836
+ /** The indexes named after the old table, which SQLite cannot rename, so it replaces them. */
837
+ indexReplacements;
838
+ /**
839
+ * The replacements' drops, then their creates. They run after the table rename and are never
840
+ * rendered on their own.
841
+ */
842
+ companions;
843
+ constructor(oldTableName, tableName, indexReplacements) {
844
+ super();
845
+ this.oldTableName = oldTableName;
846
+ this.tableName = tableName;
847
+ this.label = `Rename table ${oldTableName} to ${tableName}`;
848
+ this.indexReplacements = Object.freeze([...indexReplacements]);
849
+ this.companions = Object.freeze(indexReplacementCalls(indexReplacements));
850
+ this.freeze();
851
+ }
852
+ /** The id of the operation this call lowers to. */
853
+ get operationId() {
854
+ return `renameTable.${this.oldTableName}`;
855
+ }
856
+ toOps(lowerer) {
857
+ return [this.toOp(lowerer), ...this.companions.map((companion) => companion.toOp(lowerer))];
858
+ }
859
+ async toOp(lowerer) {
860
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `RenameTableCall.toOp: a lowerer is required on the SQLite planner path (table "${this.oldTableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
861
+ factory: this.factoryName,
862
+ tableName: this.oldTableName
863
+ } });
864
+ const fromChecks = tableExistsAst(this.oldTableName);
865
+ const toChecks = tableExistsAst(this.tableName);
866
+ const fromPresent = await lowerer.lowerToExecuteRequest(fromChecks.tablePresent());
867
+ const onlyCase = renameChangesOnlyCase(this.oldTableName, this.tableName);
868
+ const toAbsent = await lowerer.lowerToExecuteRequest(onlyCase ? toChecks.tableAbsent() : tableNameTakenAst(this.tableName).nameFree());
869
+ const viaName = renameTableViaName(this.tableName);
870
+ const viaAbsent = onlyCase ? await lowerer.lowerToExecuteRequest(tableExistsAst(viaName).tableAbsent()) : void 0;
871
+ const toPresent = await lowerer.lowerToExecuteRequest(toChecks.tablePresent());
872
+ const fromAbsent = await lowerer.lowerToExecuteRequest(fromChecks.tableAbsent());
873
+ return {
874
+ id: this.operationId,
875
+ label: this.label,
876
+ summary: `Renames table ${this.oldTableName} to ${this.tableName}, keeping its rows`,
877
+ operationClass: "widening",
878
+ target: {
879
+ id: "sqlite",
880
+ details: buildTargetDetails("table", this.tableName)
881
+ },
882
+ precheck: [
883
+ step(`ensure table "${this.oldTableName}" exists`, fromPresent.sql, fromPresent.params, expectPresent(`table "${this.oldTableName}"`)),
884
+ step(onlyCase ? `ensure table "${this.tableName}" does not exist` : `ensure no table or index is named "${this.tableName}" in any case`, toAbsent.sql, toAbsent.params, expectAbsent(onlyCase ? `table "${this.tableName}"` : `a table or index named "${this.tableName}" in any case`)),
885
+ ...viaAbsent === void 0 ? [] : [step(`ensure table "${viaName}" does not exist (a rename that only changes case passes through this temporary name, because SQLite compares table names without case)`, viaAbsent.sql, viaAbsent.params, expectAbsent(`table "${viaName}"`))]
886
+ ],
887
+ execute: renameTableSteps(this.oldTableName, this.tableName),
888
+ postcheck: [step(`verify table "${this.tableName}" exists`, toPresent.sql, toPresent.params, expectPresent(`table "${this.tableName}"`)), step(`verify table "${this.oldTableName}" no longer exists`, fromAbsent.sql, fromAbsent.params, expectAbsent(`table "${this.oldTableName}"`))]
889
+ };
890
+ }
891
+ renderTypeScript() {
892
+ return `...this.renameTable({ table: ${jsonToTsSource(this.oldTableName)}, to: ${jsonToTsSource(this.tableName)} })`;
893
+ }
894
+ importRequirements() {
895
+ return [];
896
+ }
897
+ };
898
+ var RenameColumnCall = class extends SqliteOpFactoryCallNode {
899
+ factoryName = "renameColumn";
900
+ operationClass = "widening";
901
+ tableName;
902
+ oldColumnName;
903
+ /** The new name: the column's contract-side identity after the rename. */
904
+ columnName;
905
+ label;
906
+ /** The indexes on the column whose wire names change, which SQLite cannot rename. */
907
+ indexReplacements;
908
+ /**
909
+ * The replacements' drops, then their creates. They run after the column rename and are never
910
+ * rendered on their own.
911
+ */
912
+ companions;
913
+ constructor(tableName, oldColumnName, columnName, indexReplacements) {
914
+ super();
915
+ this.tableName = tableName;
916
+ this.oldColumnName = oldColumnName;
917
+ this.columnName = columnName;
918
+ this.label = `Rename column ${oldColumnName} on ${tableName} to ${columnName}`;
919
+ this.indexReplacements = Object.freeze([...indexReplacements]);
920
+ this.companions = Object.freeze(indexReplacementCalls(indexReplacements));
921
+ this.freeze();
922
+ }
923
+ toOps(lowerer) {
924
+ return [this.toOp(lowerer), ...this.companions.map((companion) => companion.toOp(lowerer))];
925
+ }
926
+ async toOp(lowerer) {
927
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `RenameColumnCall.toOp: a lowerer is required on the SQLite planner path (column "${this.oldColumnName}" on table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
928
+ factory: this.factoryName,
929
+ tableName: this.tableName
930
+ } });
931
+ return renameColumn(this.tableName, this.oldColumnName, this.columnName, lowerer);
932
+ }
933
+ renderTypeScript() {
934
+ return `...this.renameColumn({ table: ${jsonToTsSource(this.tableName)}, column: ${jsonToTsSource(this.oldColumnName)}, to: ${jsonToTsSource(this.columnName)} })`;
935
+ }
936
+ importRequirements() {
937
+ return [];
938
+ }
939
+ };
940
+ function refuseUnsafeCopyExpressions(tableName, option, expressions) {
941
+ for (const [column, expression] of Object.entries(expressions)) {
942
+ if (expression.kind !== "sql") continue;
943
+ const refused = checkSqlExpressionText(expression.sql, SQLITE_QUOTING);
944
+ if (refused === void 0) continue;
945
+ const call = `recreateTable({ tableName: ${jsonToTsSource(tableName)} })`;
946
+ throw sqliteError("MIGRATION.SQL_EXPRESSION_INVALID", `${call}: ${option}.${column} ${JSON.stringify(expression.sql)} holds ${refused}, which could end or extend the INSERT … SELECT statement it is written into`, {
947
+ why: "A copy expression or a temporary value is written into the SELECT that copies the rows into the rebuilt table. The check refuses a semicolon, a SQL comment, dollar quoting, and a comma or a statement keyword outside parentheses, since each could end or extend that statement; it does not check that the text is valid SQL.",
948
+ fix: `Write ${option}.${column} as one SQL expression over the old table's columns, such as CAST("${column}" AS INTEGER). If it holds a comma or a keyword such as FROM outside parentheses, wrap it in parentheses.`,
949
+ meta: {
950
+ call,
951
+ field: `${option}.${column}`,
952
+ expression: expression.sql,
953
+ refused
954
+ }
955
+ });
956
+ }
957
+ }
958
+ function refuseUnknownCopyExpressionColumns(tableName, contractTable, named) {
959
+ const columns = contractTable.columns.map((column) => column.name);
960
+ const unknown = [
961
+ ...Object.keys(named.copyExpressions).map((key) => ({
962
+ option: `copyExpressions.${key}`,
963
+ key
964
+ })),
965
+ ...Object.keys(named.temporaryValues).map((key) => ({
966
+ option: `temporaryValues.${key}`,
967
+ key
968
+ })),
969
+ ...named.retypedColumns.map((key) => ({
970
+ option: `retypedColumns entry ${JSON.stringify(key)}`,
971
+ key
972
+ }))
973
+ ].find(({ key }) => !columns.includes(key));
974
+ if (unknown === void 0) return;
975
+ const call = `recreateTable({ tableName: ${jsonToTsSource(tableName)} })`;
976
+ throw sqliteError("MIGRATION.COPY_EXPRESSION_COLUMN_UNKNOWN", `${call}: ${unknown.option} names no column of the new table. Its columns are ${columns.map((column) => JSON.stringify(column)).join(", ")}.`, {
977
+ why: "Each key of copyExpressions and temporaryValues, and each entry of retypedColumns, names a column of the new table. One that names no column applies to nothing, so the column meant would be copied unchanged or left without a value, or its values would go unchecked.",
978
+ fix: "Name a column in contractTable.columns, with the same letters and case.",
979
+ meta: {
980
+ call,
981
+ key: unknown.key,
982
+ columns
983
+ }
984
+ });
985
+ }
986
+ /**
987
+ * A temporary value fills a column the old table does not have, and only that: for a column the
988
+ * old table has it would replace every existing value, and a column with a copy expression is
989
+ * already filled by its conversion.
990
+ */
991
+ function refuseMisplacedTemporaryValues(tableName, schemaColumnNames, copyExpressions, temporaryValues) {
992
+ const call = `recreateTable({ tableName: ${jsonToTsSource(tableName)} })`;
993
+ for (const column of Object.keys(temporaryValues)) {
994
+ if (schemaColumnNames.includes(column)) throw sqliteError("MIGRATION.TEMPORARY_VALUE_INVALID", `${call}: temporaryValues.${column} names a column the old table already has, so the copy would replace every value of it.`, {
995
+ why: "A temporary value fills a new column in the existing rows. A column the old table has keeps its values through the copy, or is converted by a copy expression.",
996
+ fix: `Remove temporaryValues.${column}. To change the values of "${column}", write a conversion in copyExpressions.${column} instead.`,
997
+ meta: {
998
+ call,
999
+ column,
1000
+ reason: "existingColumn"
1001
+ }
1002
+ });
1003
+ if (Object.hasOwn(copyExpressions, column)) throw sqliteError("MIGRATION.TEMPORARY_VALUE_INVALID", `${call}: "${column}" is named in both copyExpressions and temporaryValues, so it would be filled twice.`, {
1004
+ why: "A column is filled either by the conversion in copyExpressions or by a temporary value, not both.",
1005
+ fix: `Keep one of copyExpressions.${column} and temporaryValues.${column}.`,
1006
+ meta: {
1007
+ call,
1008
+ column,
1009
+ reason: "alsoConverted"
1010
+ }
1011
+ });
1012
+ }
1013
+ }
1014
+ function sqlOfSlots(slots) {
1015
+ return Object.fromEntries(Object.entries(slots).flatMap(([column, slot]) => {
1016
+ const sql = sqlOfSlot(slot);
1017
+ return sql === void 0 ? [] : [[column, sql]];
1018
+ }));
1019
+ }
1020
+ var RecreateTableCall = class extends SqliteOpFactoryCallNode {
1021
+ factoryName = "recreateTable";
1022
+ operationClass;
1023
+ tableName;
1024
+ contractTable;
1025
+ schemaColumnNames;
1026
+ indexes;
1027
+ summary;
1028
+ postchecks;
1029
+ label;
1030
+ /** The conversion each named column of the new table is copied through, in place of the live column. */
1031
+ copyExpressions;
1032
+ /** The value each named new column takes in the existing rows. */
1033
+ temporaryValues;
1034
+ /** The columns whose type changes; the rebuild checks each after its copy, as a conversion when it has a copy expression and as SQLite's cast otherwise. */
1035
+ retypedColumns;
1036
+ constructor(args) {
1037
+ super();
1038
+ refuseUnsafeCopyExpressions(args.tableName, "copyExpressions", args.copyExpressions ?? {});
1039
+ refuseUnsafeCopyExpressions(args.tableName, "temporaryValues", args.temporaryValues ?? {});
1040
+ refuseUnknownCopyExpressionColumns(args.tableName, args.contractTable, {
1041
+ copyExpressions: args.copyExpressions ?? {},
1042
+ temporaryValues: args.temporaryValues ?? {},
1043
+ retypedColumns: args.retypedColumns ?? []
1044
+ });
1045
+ refuseMisplacedTemporaryValues(args.tableName, args.schemaColumnNames, args.copyExpressions ?? {}, args.temporaryValues ?? {});
1046
+ this.copyExpressions = Object.freeze({ ...args.copyExpressions });
1047
+ this.temporaryValues = Object.freeze({ ...args.temporaryValues });
1048
+ this.retypedColumns = Object.freeze([...args.retypedColumns ?? []]);
1049
+ this.tableName = args.tableName;
1050
+ this.contractTable = args.contractTable;
1051
+ this.schemaColumnNames = args.schemaColumnNames;
1052
+ this.indexes = args.indexes;
1053
+ this.summary = args.summary;
1054
+ this.postchecks = args.postchecks;
1055
+ this.operationClass = args.operationClass;
1056
+ this.label = `Recreate table ${args.tableName}`;
1057
+ this.freeze();
1058
+ }
1059
+ async toOp(lowerer) {
1060
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `RecreateTableCall.toOp: a lowerer is required on the SQLite planner path (table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
1061
+ factory: this.factoryName,
1062
+ tableName: this.tableName
1063
+ } });
1064
+ const copies = Object.entries(this.copyExpressions);
1065
+ if (copies.some(([, expression]) => isUnfilledSlot(expression))) return unfilledPlaceholderOperation(this.label);
1066
+ return recreateTable({
1067
+ tableName: this.tableName,
1068
+ contractTable: this.contractTable,
1069
+ schemaColumnNames: this.schemaColumnNames,
1070
+ indexes: this.indexes,
1071
+ summary: this.summary,
1072
+ postchecks: this.postchecks,
1073
+ operationClass: this.operationClass,
1074
+ retypedColumns: this.retypedColumns,
1075
+ ...copies.length === 0 ? {} : { copyExpressions: sqlOfSlots(this.copyExpressions) },
1076
+ ...Object.keys(this.temporaryValues).length === 0 ? {} : { temporaryValues: sqlOfSlots(this.temporaryValues) }
1077
+ }, lowerer);
1078
+ }
1079
+ #slotsSource(slots, sql) {
1080
+ return `{ ${Object.entries(slots).map(([column, expression]) => `${jsonToTsSource(column)}: ${slotSource(expression, sql)}`).join(", ")} }`;
1081
+ }
1082
+ renderTypeScript() {
1083
+ return this.#written().source;
1084
+ }
1085
+ importRequirements() {
1086
+ return [...Object.values(this.copyExpressions).some(isUnfilledSlot) ? [{
1087
+ moduleSpecifier: TARGET_MIGRATION_MODULE,
1088
+ symbol: "placeholder"
1089
+ }] : [], ...this.#written().imports];
1090
+ }
1091
+ #written() {
1092
+ const sql = createSqlTextSources(TARGET_MIGRATION_MODULE);
1093
+ return {
1094
+ source: `this.recreateTable(${tsObjectSource([
1095
+ ["tableName", jsonToTsSource(this.tableName)],
1096
+ ["contractTable", renderTableSpec(this.contractTable, sql)],
1097
+ ["schemaColumnNames", jsonToTsSource(this.schemaColumnNames)],
1098
+ ["indexes", jsonToTsSource(this.indexes)],
1099
+ ["summary", jsonToTsSource(this.summary)],
1100
+ ["postchecks", tsArraySource(this.postchecks.map(renderPostcheck))],
1101
+ ["operationClass", jsonToTsSource(this.operationClass)],
1102
+ ...Object.keys(this.copyExpressions).length === 0 ? [] : [["copyExpressions", this.#slotsSource(this.copyExpressions, sql)]],
1103
+ ...Object.keys(this.temporaryValues).length === 0 ? [] : [["temporaryValues", this.#slotsSource(this.temporaryValues, sql)]],
1104
+ ...this.retypedColumns.length === 0 ? [] : [["retypedColumns", jsonToTsSource(this.retypedColumns)]]
1105
+ ])})`,
1106
+ imports: sql.imports()
1107
+ };
1108
+ }
1109
+ };
1110
+ var AddColumnCall = class extends SqliteOpFactoryCallNode {
1111
+ factoryName = "addColumn";
1112
+ operationClass = "additive";
1113
+ tableName;
1114
+ columnName;
1115
+ column;
1116
+ label;
1117
+ constructor(tableName, column) {
1118
+ super();
1119
+ this.tableName = tableName;
1120
+ this.columnName = column.name;
1121
+ this.column = column;
1122
+ this.label = `Add column ${column.name} on ${tableName}`;
1123
+ this.freeze();
1124
+ }
1125
+ async toOp(lowerer) {
1126
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `AddColumnCall.toOp: a lowerer is required on the SQLite planner path (column "${this.column.name}" on table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
1127
+ factory: this.factoryName,
1128
+ tableName: this.tableName,
1129
+ columnName: this.column.name
1130
+ } });
1131
+ return addColumn(this.tableName, this.column, lowerer);
1132
+ }
1133
+ renderTypeScript() {
1134
+ return this.#written().source;
1135
+ }
1136
+ importRequirements() {
1137
+ return this.#written().imports;
1138
+ }
1139
+ #written() {
1140
+ const sql = createSqlTextSources(TARGET_MIGRATION_MODULE);
1141
+ return {
1142
+ source: `this.addColumn({ table: ${jsonToTsSource(this.tableName)}, column: ${renderColumnSpec(this.column, sql)} })`,
1143
+ imports: sql.imports()
1144
+ };
1145
+ }
1146
+ };
1147
+ var DropColumnCall = class extends SqliteOpFactoryCallNode {
1148
+ factoryName = "dropColumn";
1149
+ operationClass = "destructive";
1150
+ tableName;
1151
+ columnName;
1152
+ label;
1153
+ constructor(tableName, columnName) {
1154
+ super();
1155
+ this.tableName = tableName;
1156
+ this.columnName = columnName;
1157
+ this.label = `Drop column ${columnName} on ${tableName}`;
1158
+ this.freeze();
1159
+ }
1160
+ async toOp(lowerer) {
1161
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `DropColumnCall.toOp: a lowerer is required on the SQLite planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
1162
+ factory: this.factoryName,
1163
+ tableName: this.tableName,
1164
+ columnName: this.columnName
1165
+ } });
1166
+ const checks = columnExistsAst(this.tableName, this.columnName);
1167
+ const present = await lowerer.lowerToExecuteRequest(checks.columnPresent());
1168
+ const absent = await lowerer.lowerToExecuteRequest(checks.columnAbsent());
1169
+ return {
1170
+ id: `dropColumn.${this.tableName}.${this.columnName}`,
1171
+ label: `Drop column ${this.columnName} on ${this.tableName}`,
1172
+ summary: `Drops column ${this.columnName} on ${this.tableName} which is not in the contract`,
1173
+ operationClass: "destructive",
1174
+ target: {
1175
+ id: "sqlite",
1176
+ details: buildTargetDetails("column", this.columnName, this.tableName)
1177
+ },
1178
+ precheck: [step(`ensure column "${this.columnName}" exists on "${this.tableName}"`, present.sql, present.params, expectPresent(`column "${this.columnName}" on "${this.tableName}"`))],
1179
+ execute: [step(`drop column "${this.columnName}" from "${this.tableName}"`, dropColumnExecuteSql(this.tableName, this.columnName))],
1180
+ postcheck: [step(`verify column "${this.columnName}" is gone from "${this.tableName}"`, absent.sql, absent.params, expectAbsent(`column "${this.columnName}" on "${this.tableName}"`))]
1181
+ };
1182
+ }
1183
+ renderTypeScript() {
1184
+ return `this.dropColumn({ table: ${jsonToTsSource(this.tableName)}, column: ${jsonToTsSource(this.columnName)} })`;
1185
+ }
1186
+ importRequirements() {
1187
+ return [];
1188
+ }
1189
+ };
1190
+ var CreateIndexCall = class extends SqliteOpFactoryCallNode {
1191
+ factoryName = "createIndex";
1192
+ operationClass = "additive";
1193
+ tableName;
1194
+ indexName;
1195
+ columns;
1196
+ label;
1197
+ constructor(tableName, indexName, columns) {
1198
+ super();
1199
+ this.tableName = tableName;
1200
+ this.indexName = indexName;
1201
+ this.columns = columns;
1202
+ this.label = `Create index ${indexName} on ${tableName}`;
1203
+ this.freeze();
1204
+ }
1205
+ /** The id of the operation this call lowers to. */
1206
+ get operationId() {
1207
+ return `index.${this.tableName}.${this.indexName}`;
1208
+ }
1209
+ async toOp(lowerer) {
1210
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `CreateIndexCall.toOp: a lowerer is required on the SQLite planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
1211
+ factory: this.factoryName,
1212
+ tableName: this.tableName,
1213
+ indexName: this.indexName
1214
+ } });
1215
+ const checks = indexExistsAst(this.indexName);
1216
+ const absent = await lowerer.lowerToExecuteRequest(checks.indexAbsent());
1217
+ const present = await lowerer.lowerToExecuteRequest(checks.indexPresent());
1218
+ return {
1219
+ id: this.operationId,
1220
+ label: `Create index ${this.indexName} on ${this.tableName}`,
1221
+ summary: `Creates index ${this.indexName} on ${this.tableName}`,
1222
+ operationClass: "additive",
1223
+ target: {
1224
+ id: "sqlite",
1225
+ details: buildTargetDetails("index", this.indexName, this.tableName)
1226
+ },
1227
+ precheck: [step(`ensure index "${this.indexName}" is missing`, absent.sql, absent.params, expectAbsent(`index "${this.indexName}"`))],
1228
+ execute: [step(`create index "${this.indexName}"`, buildCreateIndexSql(this.tableName, this.indexName, this.columns))],
1229
+ postcheck: [step(`verify index "${this.indexName}" exists`, present.sql, present.params, expectPresent(`index "${this.indexName}"`)), indexDefinitionCheck(this.tableName, this.indexName, this.columns, false)]
1230
+ };
1231
+ }
1232
+ renderTypeScript() {
1233
+ return `this.createIndex({ table: ${jsonToTsSource(this.tableName)}, index: ${jsonToTsSource(this.indexName)}, columns: ${jsonToTsSource(this.columns)} })`;
1234
+ }
1235
+ importRequirements() {
1236
+ return [];
1237
+ }
1238
+ };
1239
+ var DropIndexCall = class extends SqliteOpFactoryCallNode {
1240
+ factoryName = "dropIndex";
1241
+ operationClass = "widening";
1242
+ tableName;
1243
+ indexName;
1244
+ label;
1245
+ constructor(tableName, indexName) {
1246
+ super();
1247
+ this.tableName = tableName;
1248
+ this.indexName = indexName;
1249
+ this.label = `Drop index ${indexName} on ${tableName}`;
1250
+ this.freeze();
1251
+ }
1252
+ /** The id of the operation this call lowers to. */
1253
+ get operationId() {
1254
+ return `dropIndex.${this.tableName}.${this.indexName}`;
1255
+ }
1256
+ async toOp(lowerer) {
1257
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `DropIndexCall.toOp: a lowerer is required on the SQLite planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
1258
+ factory: this.factoryName,
1259
+ tableName: this.tableName,
1260
+ indexName: this.indexName
1261
+ } });
1262
+ const checks = indexExistsAst(this.indexName);
1263
+ const present = await lowerer.lowerToExecuteRequest(checks.indexPresent());
1264
+ const absent = await lowerer.lowerToExecuteRequest(checks.indexAbsent());
1265
+ return {
1266
+ id: this.operationId,
1267
+ label: `Drop index ${this.indexName} on ${this.tableName}`,
1268
+ summary: `Drops index ${this.indexName} on ${this.tableName} which is not in the contract`,
1269
+ operationClass: "widening",
1270
+ target: {
1271
+ id: "sqlite",
1272
+ details: buildTargetDetails("index", this.indexName, this.tableName)
1273
+ },
1274
+ precheck: [step(`ensure index "${this.indexName}" exists`, present.sql, present.params, expectPresent(`index "${this.indexName}"`))],
1275
+ execute: [step(`drop index "${this.indexName}"`, buildDropIndexSql(this.indexName))],
1276
+ postcheck: [step(`verify index "${this.indexName}" is gone`, absent.sql, absent.params, expectAbsent(`index "${this.indexName}"`))]
1277
+ };
1278
+ }
1279
+ renderTypeScript() {
1280
+ return `this.dropIndex({ table: ${jsonToTsSource(this.tableName)}, index: ${jsonToTsSource(this.indexName)} })`;
1281
+ }
1282
+ importRequirements() {
1283
+ return [];
1284
+ }
1285
+ };
1286
+ /**
1287
+ * A planner-generated data-transform stub. The current default strategy
1288
+ * (`nullabilityTighteningBackfillStrategy`) emits one of these with a
1289
+ * backfill-flavored `id`/`label` when the policy allows `'data'` and the
1290
+ * contract tightens a column's nullability, but the op itself is generic —
1291
+ * any future strategy that needs a placeholder data step can construct one
1292
+ * with its own id/label.
1293
+ *
1294
+ * `toOp()` always rejects with `MIGRATION.UNFILLED_PLACEHOLDER`: the planner cannot lower a stubbed
1295
+ * transform to a runtime op — the user must edit the rendered
1296
+ * `migration.ts` and re-emit.
1297
+ */
1298
+ var DataTransformCall = class extends SqliteOpFactoryCallNode {
1299
+ factoryName = "dataTransform";
1300
+ operationClass = "data";
1301
+ id;
1302
+ label;
1303
+ tableName;
1304
+ columnName;
1305
+ /** The slot the user fills with the statement that fills the column: `<Model.field>:run`. */
1306
+ slot;
1307
+ constructor(id, label, tableName, columnName, slot) {
1308
+ super();
1309
+ this.id = id;
1310
+ this.label = label;
1311
+ this.tableName = tableName;
1312
+ this.columnName = columnName;
1313
+ this.slot = slot;
1314
+ this.freeze();
1315
+ }
1316
+ toOp(_lowerer) {
1317
+ return unfilledPlaceholderOperation(this.label);
1318
+ }
1319
+ renderTypeScript() {
1320
+ const slot = this.slot;
1321
+ return [
1322
+ "dataTransform({",
1323
+ ` id: ${jsonToTsSource(this.id)},`,
1324
+ ` label: ${jsonToTsSource(this.label)},`,
1325
+ ` table: ${jsonToTsSource(this.tableName)},`,
1326
+ ` description: ${jsonToTsSource(`Backfill NULL ${this.columnName} values in ${this.tableName}`)},`,
1327
+ ` run: () => placeholder(${jsonToTsSource(slot)}),`,
1328
+ "})"
1329
+ ].join("\n");
1330
+ }
1331
+ importRequirements() {
1332
+ return [{
1333
+ moduleSpecifier: TARGET_MIGRATION_MODULE,
1334
+ symbol: this.factoryName
1335
+ }, {
1336
+ moduleSpecifier: TARGET_MIGRATION_MODULE,
1337
+ symbol: "placeholder"
1338
+ }];
1339
+ }
1340
+ };
1341
+ /**
1342
+ * Laundered pre-built operation. Mirrors Postgres's `RawSqlCall`: wraps an
1343
+ * already-materialized `SqlMigrationPlanOperation` (typically produced by a
1344
+ * SQL-family helper or a codec lifecycle hook) so the planner can carry it
1345
+ * alongside structured call IR. `toOp()` returns the stored op unchanged;
1346
+ * `renderTypeScript()` emits `rawSql({...})` with the op serialized as a
1347
+ * JSON literal — round-tripping requires every field on the op to be
1348
+ * JSON-serializable (no closures).
1349
+ */
1350
+ var RawSqlCall = class extends SqliteOpFactoryCallNode {
1351
+ factoryName = "rawSql";
1352
+ operationClass;
1353
+ label;
1354
+ op;
1355
+ constructor(op) {
1356
+ super();
1357
+ this.op = op;
1358
+ this.label = op.label;
1359
+ this.operationClass = op.operationClass;
1360
+ this.freeze();
1361
+ }
1362
+ toOp(_lowerer) {
1363
+ return this.op;
1364
+ }
1365
+ renderTypeScript() {
1366
+ return `rawSql(${jsonToTsSource(this.op)})`;
1367
+ }
1368
+ };
1369
+ function definedSourceEntries(sources) {
1370
+ return Object.entries(sources).flatMap(([key, source]) => source === void 0 ? [] : [[key, source]]);
1371
+ }
1372
+ function renderIfDefined(value) {
1373
+ return value === void 0 ? void 0 : jsonToTsSource(value);
1374
+ }
1375
+ function renderColumnSpec(column, sql) {
1376
+ return tsObjectSource(definedSourceEntries({
1377
+ name: jsonToTsSource(column.name),
1378
+ typeSql: jsonToTsSource(column.typeSql),
1379
+ default: column.default === void 0 ? void 0 : renderSpecDefault(column.default, sql),
1380
+ codecRef: renderIfDefined(column.codecRef),
1381
+ nullable: jsonToTsSource(column.nullable),
1382
+ inlineAutoincrementPrimaryKey: renderIfDefined(column.inlineAutoincrementPrimaryKey)
1383
+ }));
1384
+ }
1385
+ function renderTableSpec(table, sql) {
1386
+ return tsObjectSource(definedSourceEntries({
1387
+ columns: tsArraySource(table.columns.map((column) => renderColumnSpec(column, sql))),
1388
+ primaryKey: renderIfDefined(table.primaryKey),
1389
+ uniques: renderIfDefined(table.uniques),
1390
+ foreignKeys: renderIfDefined(table.foreignKeys)
1391
+ }));
1392
+ }
1393
+ function renderSpecDefault(columnDefault, sql) {
1394
+ if (columnDefault.kind === "literal") return jsonToTsSource(columnDefault);
1395
+ return tsObjectSource(definedSourceEntries({
1396
+ kind: jsonToTsSource(columnDefault.kind),
1397
+ expression: sql.source(columnDefault.expression)
1398
+ }));
1399
+ }
1400
+ function renderPostcheck(postcheck) {
1401
+ if ("sql" in postcheck) return tsObjectSource(definedSourceEntries({
1402
+ description: jsonToTsSource(postcheck.description),
1403
+ sql: tsQuotedTextSource(postcheck.sql),
1404
+ requiredColumn: postcheck.requiredColumn === void 0 ? void 0 : jsonToTsSource(postcheck.requiredColumn)
1405
+ }));
1406
+ return tsObjectSource(definedSourceEntries({
1407
+ description: jsonToTsSource(postcheck.description),
1408
+ columnDefault: jsonToTsSource(postcheck.columnDefault)
1409
+ }));
1410
+ }
1411
+ //#endregion
1412
+ export { step as C, sqliteIdentifiersCollide as S, indexReplacementCalls as _, DropColumnCall as a, renameTableSteps as b, INLINE_AUTOINCREMENT_PRIMARY_KEY as c, RenameColumnCall as d, RenameTableCall as f, conversionCopyOf as g, buildRecreateSummary as h, DataTransformCall as i, RawSqlCall as l, buildRecreatePostchecks as m, CreateIndexCall as n, DropIndexCall as o, affinityStorageClasses as p, CreateTableCall as r, DropTableCall as s, AddColumnCall as t, RecreateTableCall as u, isSqliteOpFactoryCall as v, sqliteDefaultToDdlColumnDefault as x, rebuiltTableName as y };
1413
+
1414
+ //# sourceMappingURL=op-factory-call-emj9Xp05-BFLkxrAK.mjs.map