@prisma/orm-target-sqlite 8.0.0-rc.2-dev.3 → 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,1295 @@
1
+ import { a as SQLITE_INTEGER_CODEC_ID, c as SQLITE_TEXT_CODEC_ID, t as SQLITE_BIGINT_CODEC_ID } from "./codec-ids-wgEvkCkg-WltuexMR.mjs";
2
+ import { a as sqliteCharacterVarying, d as sqliteReal, f as sqliteText, l as sqliteInteger, r as sqliteCharacter, s as sqliteDatetime, t as sqliteBlob, u as sqliteJson } from "./data-types-coQrCWfS-yMCe4F52.mjs";
3
+ import { n as sqliteError, t as errorSqliteMigrationStackMissing } from "./errors-DnR-sMHS-D_gh214a.mjs";
4
+ import { n as encodeSqliteDatetime } from "./codecs-yZoH21Yj-lQXtGlEq.mjs";
5
+ import { n as escapeLiteral } from "./sql-utils-XGT5Esi2-Zr2mqJf8.mjs";
6
+ import { n as SqliteContractView } from "./sqlite-contract-view-CGfiGvKH-CT-JjNHd.mjs";
7
+ import { n as sqliteResolveDefault } from "./default-normalizer-DGMXypHg-CPf7oyZA.mjs";
8
+ import { S as sqliteIdentifiersCollide, _ as indexReplacementCalls, a as DropColumnCall, b as renameTableSteps, c as INLINE_AUTOINCREMENT_PRIMARY_KEY, d as RenameColumnCall, f as RenameTableCall, h as buildRecreateSummary, i as DataTransformCall, m as buildRecreatePostchecks, n as CreateIndexCall, o as DropIndexCall, r as CreateTableCall, s as DropTableCall, t as AddColumnCall, u as RecreateTableCall, x as sqliteDefaultToDdlColumnDefault } from "./op-factory-call-emj9Xp05-BFLkxrAK.mjs";
9
+ import { t as CONTROL_TABLE_NAMES } from "./control-tables-D_o8dKRB-n_QqsXcm.mjs";
10
+ import { DdlColumn, ForeignKeyConstraint, PrimaryKeyConstraint, UniqueConstraint } from "@prisma/orm-family-sql/relational-core/ast";
11
+ import { ifDefined } from "@prisma/orm-framework/utils/defined";
12
+ import { dataTypeParams } from "@prisma/orm-framework/components/codec";
13
+ import { blindCast } from "@prisma/orm-framework/utils/casts";
14
+ import { InternalError } from "@prisma/orm-framework/utils/internal-error";
15
+ import { isSqlDataType, nameIsCatalogText, renderSqlTypeName, sqlDataTypeOfCodec } from "@prisma/orm-family-sql/contract/data-type";
16
+ import { diffSchemas, issueOutcome, orderIssuesByDependencies } from "@prisma/orm-framework/components/control";
17
+ import { sqlTextOf } from "@prisma/orm-family-sql/relational-core/contract-free";
18
+ import { UNBOUND_NAMESPACE_ID, entityAt } from "@prisma/orm-framework/components/ir";
19
+ import { contractToSchemaIR, extractCodecControlHooks, resolveColumnRenameAgainst, resolveTableRenameAgainst, sqlTypeLookupsOf, unmatchedColumnRename, unmatchedTableRename } from "@prisma/orm-family-sql/family/control";
20
+ import { PrimaryKey, RelationalSchemaNodeKind, SqlCheckConstraintIR, SqlColumnIR, SqlForeignKeyIR, SqlIndexIR, SqlSchemaIR, SqlTableIR, SqlUniqueIR, relationalNodeGranularity, sqlColumnTypesEqual } from "@prisma/orm-family-sql/schema-ir/types";
21
+ import { verifySqlSchemaByDiff } from "@prisma/orm-family-sql/family/diff";
22
+ import { notOk, ok } from "@prisma/orm-framework/utils/result";
23
+ import { namingOf, namingOfLiveName, parseWireName } from "@prisma/orm-family-sql/schema-ir/naming";
24
+ import { isArrayEqual } from "@prisma/orm-framework/utils/array-equal";
25
+ import { Migration } from "@prisma/orm-family-sql/family/migration";
26
+ import { MigrationContractViews } from "@prisma/orm-toolchain/migration-tools/migration";
27
+ //#region ../../../3-targets/sqlite/1-target/dist/sqlite-migration-BAdSmooi.mjs
28
+ /**
29
+ * The SQLite expected-side projection: contract → flat relational schema IR.
30
+ *
31
+ * Each column's type is written from the data type its codec represents.
32
+ * Every expected column also carries its `codecRef` unconditionally
33
+ * (Decision 5) — the planner's op-builders resolve DDL rendering from it at
34
+ * plan time, so no separate render stamper is threaded here.
35
+ */
36
+ function sqliteContractToSchema(contract, types) {
37
+ return contractToSchemaIR(contract, {
38
+ annotationNamespace: "sqlite",
39
+ resolveDefault: sqliteResolveDefault,
40
+ dataTypeLookup: types.dataTypeLookup,
41
+ codecLookup: types.codecLookup
42
+ });
43
+ }
44
+ /**
45
+ * The SQLite schema verify: the full-tree node-diff verdict wrapped in the
46
+ * issue-based result envelope. Used by the runner's post-apply check; the
47
+ * family `verifySchema` runs the same composition via the descriptor hook.
48
+ */
49
+ function verifySqliteDatabaseSchema(input) {
50
+ return verifySqlSchemaByDiff({
51
+ contract: input.contract,
52
+ schema: input.actualSchema,
53
+ strict: input.strict,
54
+ frameworkComponents: input.frameworkComponents,
55
+ diffSchema: diffSqliteSchema,
56
+ granularityOf: relationalNodeGranularity
57
+ });
58
+ }
59
+ /**
60
+ * Resolves a verdict-diff issue's subject table's declared control policy
61
+ * directly from the contract. SQLite's expected tree is flat, so the issue
62
+ * path carries no namespace segment — `path[1]` is the table name (`path[0]`
63
+ * is the tree root's own id); every contract namespace is searched for that
64
+ * table name (table names are globally unique in the flat tree — duplicates
65
+ * across namespaces are rejected earlier, at `contractToSchemaIR`).
66
+ */
67
+ function resolveControlPolicy(issue, contract) {
68
+ const tableName = issue.path[1];
69
+ if (tableName === void 0) return void 0;
70
+ for (const namespaceId of Object.keys(contract.storage.namespaces)) {
71
+ const table = entityAt(contract.storage, {
72
+ namespaceId,
73
+ entityKind: "table",
74
+ entityName: tableName
75
+ });
76
+ if (table !== void 0) return table.control;
77
+ }
78
+ }
79
+ /**
80
+ * The SQLite full-tree node diff for the family verify verdict: derive the
81
+ * expected flat tree with resolved leaf values (parameterized types written
82
+ * with their parameters; FK nodes born with the flat empty
83
+ * `resolvedReferencedNamespace`), and run the generic differ over the trees
84
+ * as derived. Flat targets need no ownership scoping. The codec `verifyType`
85
+ * hooks run once per contract namespace with tables, each against the sole
86
+ * flat actual root — exactly the legacy per-namespace pairing.
87
+ */
88
+ function diffSqliteSchema(input) {
89
+ const types = sqlTypeLookupsOf(input.frameworkComponents);
90
+ const expected = sqliteContractToSchema(input.contract, types);
91
+ const actual = input.schema instanceof SqlSchemaIR ? input.schema : blindCast(input.schema);
92
+ return {
93
+ issues: diffSchemas(expected, actual),
94
+ resolveControlPolicy: (issue) => resolveControlPolicy(issue, input.contract),
95
+ namespacePairs: Object.values(input.contract.storage.namespaces).filter((ns) => Object.keys(ns.entries.table ?? {}).length > 0).map(() => ({ actual }))
96
+ };
97
+ }
98
+ /**
99
+ * The SQLite planner's diff input: the same tree-building
100
+ * `diffSqliteSchema` uses (FK nodes born flat). One differ
101
+ * drives both verify and plan over the trees as derived; this is the plan-side
102
+ * derivation — column DDL resolves from each expected column's `codecRef` at
103
+ * plan time (`column-ddl-rendering.ts`), so no separate render stamping happens here.
104
+ */
105
+ function buildSqlitePlanDiff(input) {
106
+ const types = sqlTypeLookupsOf(input.frameworkComponents);
107
+ const expected = sqliteContractToSchema(input.contract, types);
108
+ const actual = sqliteActualSchema(input.actualSchema);
109
+ return {
110
+ expected,
111
+ actual,
112
+ issues: diffSchemas(expected, actual)
113
+ };
114
+ }
115
+ /** The schema a plan starts from as a `SqlSchemaIR`, its table and column names taken from their keys. */
116
+ function sqliteActualSchema(actualSchema) {
117
+ return new SqlSchemaIR(withRecordKeyNames(actualSchema));
118
+ }
119
+ /**
120
+ * Every schema-tree builder in this codebase derives a table's / column's
121
+ * `name` from the record key it's stored under (`contractToSchemaIR`,
122
+ * the SQLite introspection adapter) rather than trusting a redundant
123
+ * embedded field — the record key IS the identity. Mirrors that discipline
124
+ * for the actual/live tree before construction, so `SqlTableIR.id` /
125
+ * `SqlColumnIR.id` (both derived from `.name`) are always correct without
126
+ * requiring every caller to duplicate the key onto the value. A no-op for a
127
+ * tree that already carries matching names (the real introspection adapter
128
+ * always does).
129
+ */
130
+ function withRecordKeyNames(actualSchema) {
131
+ const raw = blindCast(actualSchema);
132
+ const tables = {};
133
+ for (const [tableName, table] of Object.entries(raw.tables ?? {})) {
134
+ const rawTable = blindCast(table);
135
+ const columns = {};
136
+ for (const [columnName, column] of Object.entries(blindCast(table).columns ?? {})) columns[columnName] = column instanceof SqlColumnIR ? column.name === columnName ? column : column.withName(columnName) : {
137
+ ...blindCast(column),
138
+ name: columnName
139
+ };
140
+ tables[tableName] = {
141
+ ...rawTable,
142
+ name: tableName,
143
+ columns,
144
+ foreignKeys: rawTable.foreignKeys ?? [],
145
+ uniques: rawTable.uniques ?? [],
146
+ indexes: rawTable.indexes ?? []
147
+ };
148
+ }
149
+ return { tables };
150
+ }
151
+ /**
152
+ * The type DDL writes for a column node: the name of the type it is stored as, with the parameters as the contract writes them, in upper case, or as given for a data type whose name is its catalog text, since verify compares that text exactly (ADR 273).
153
+ */
154
+ function columnTypeSql(column) {
155
+ const type = column.storedType;
156
+ if (type === void 0 || !isSqlDataType(type)) throw new InternalError(`column "${column.name}" has no data type; the expected tree must be derived via contractToSchemaIR for planning`);
157
+ const written = renderSqlTypeName(type, dataTypeParams(type, column.codecRef?.typeParams));
158
+ return nameIsCatalogText(type) ? written : written.toUpperCase();
159
+ }
160
+ /** The default DDL writes: the one the contract authored; `resolvedDefault` exists for the diff comparison. */
161
+ function ddlDefaultOf(column) {
162
+ return column.authoredDefault ?? column.resolvedDefault;
163
+ }
164
+ /**
165
+ * True when the column is rendered inline as `INTEGER PRIMARY KEY
166
+ * AUTOINCREMENT` — the sole member of the table's primary key with an
167
+ * `autoincrement()` default. Node-based sibling of the retired
168
+ * `isInlineAutoincrementPrimaryKey` (which read the raw `StorageTable`);
169
+ * reads the table/column nodes instead.
170
+ */
171
+ function isInlineAutoincrementPrimaryKeyNode(table, column) {
172
+ if (table.primaryKey?.columns.length !== 1) return false;
173
+ if (table.primaryKey.columns[0] !== column.name) return false;
174
+ return column.resolvedDefault?.kind === "function" && column.resolvedDefault.expression === "autoincrement()";
175
+ }
176
+ /**
177
+ * Builds the flat `SqliteColumnSpec` `AddColumnCall` / `RecreateTableCall`
178
+ * need, with the type the column is stored as.
179
+ */
180
+ function columnSpecFromNode(column, inline) {
181
+ const typeSql = columnTypeSql(column);
182
+ return {
183
+ name: column.name,
184
+ typeSql,
185
+ ...inline ? {} : {
186
+ ...ifDefined("default", ddlDefaultOf(column)),
187
+ ...ifDefined("codecRef", column.codecRef)
188
+ },
189
+ nullable: column.nullable,
190
+ ...inline ? { inlineAutoincrementPrimaryKey: true } : {}
191
+ };
192
+ }
193
+ /**
194
+ * Builds the `DdlColumn` the `CreateTableCall` path needs, with the type the
195
+ * column is stored as.
196
+ */
197
+ function ddlColumnFromNode(column, inline) {
198
+ const typeSql = columnTypeSql(column);
199
+ if (inline) return new DdlColumn({
200
+ name: column.name,
201
+ type: `${typeSql}${INLINE_AUTOINCREMENT_PRIMARY_KEY}`
202
+ });
203
+ const colDefault = sqliteDefaultToDdlColumnDefault(ddlDefaultOf(column));
204
+ return new DdlColumn({
205
+ name: column.name,
206
+ type: typeSql,
207
+ ...!column.nullable ? { notNull: true } : {},
208
+ ...colDefault !== void 0 ? { default: colDefault } : {},
209
+ ...column.codecRef !== void 0 ? { codecRef: column.codecRef } : {}
210
+ });
211
+ }
212
+ /**
213
+ * Builds the table-level constraints (PK / unique / FK) for a `CreateTable`
214
+ * path from the table node — the node-sourced sibling of the retired
215
+ * contract-based `tableToDdlParts`'s constraint half.
216
+ *
217
+ * A check constraint on the table node throws rather than being dropped.
218
+ * `@@check` is refused earlier, by the `sql.checkConstraint` capability gate in
219
+ * PSL interpretation. The TS `check()` builder is not gated there — capabilities
220
+ * are adapter-reported and reach the contract only after it is built — so a
221
+ * `check()` declared against SQLite arrives here, and this is where it is
222
+ * refused. It is the primary enforcement point for that surface, and the safety
223
+ * net for a contract that reached storage some other way.
224
+ */
225
+ function tableConstraintsFromNode(table, hasInlinePk) {
226
+ const constraints = [];
227
+ if (table.primaryKey && !hasInlinePk) constraints.push(new PrimaryKeyConstraint({ columns: table.primaryKey.columns }));
228
+ for (const check of table.checks ?? []) throw sqliteError("CONTRACT.CONSTRAINT_INVALID", `The SQLite target does not support CHECK constraints (constraint "${check.name}" on table "${table.name}"). The "checkConstraint" capability is Postgres-only — remove the "@@check" / "check()" declaration, or target Postgres.`, { meta: {
229
+ constraintName: check.name,
230
+ tableName: table.name
231
+ } });
232
+ for (const u of table.uniques) constraints.push(new UniqueConstraint({
233
+ columns: u.columns,
234
+ ...u.name !== void 0 ? { name: u.name } : {}
235
+ }));
236
+ for (const fk of table.foreignKeys) constraints.push(new ForeignKeyConstraint({
237
+ columns: fk.columns,
238
+ refTable: fk.referencedTable,
239
+ refColumns: fk.referencedColumns,
240
+ ...fk.name !== void 0 ? { name: fk.name } : {},
241
+ ...fk.onDelete !== void 0 ? { onDelete: fk.onDelete } : {},
242
+ ...fk.onUpdate !== void 0 ? { onUpdate: fk.onUpdate } : {}
243
+ }));
244
+ return constraints;
245
+ }
246
+ const DATA_TYPE_FILL_VALUES = /* @__PURE__ */ new Map([
247
+ [sqliteDatetime.id, `'${escapeLiteral(encodeSqliteDatetime(/* @__PURE__ */ new Date(0)))}'`],
248
+ [sqliteJson.id, `'{}'`],
249
+ [sqliteInteger.id, "0"],
250
+ [sqliteReal.id, "0"],
251
+ [sqliteText.id, "''"],
252
+ [sqliteCharacter.id, "''"],
253
+ [sqliteCharacterVarying.id, "''"],
254
+ [sqliteBlob.id, "X''"]
255
+ ]);
256
+ function isParamRecord(value) {
257
+ return value !== null && typeof value === "object" && !Array.isArray(value);
258
+ }
259
+ /**
260
+ * The SQL value a new required column takes in the rows a table already has, or `undefined` when
261
+ * its type has none: the column's codec hook first, as on Postgres, then a value of its data type.
262
+ */
263
+ function sqliteFillValue(column, codecHooks, types) {
264
+ const codecRef = column.codecRef;
265
+ if (codecRef === void 0 || column.many === true) return void 0;
266
+ const dataType = sqlDataTypeOfCodec(codecRef.codecId, types).id;
267
+ const fromHook = codecHooks.get(codecRef.codecId)?.resolveIdentityValue?.({
268
+ dataType,
269
+ codecId: codecRef.codecId,
270
+ ...isParamRecord(codecRef.typeParams) ? { typeParams: codecRef.typeParams } : {}
271
+ });
272
+ if (fromHook !== void 0) return fromHook ?? void 0;
273
+ return DATA_TYPE_FILL_VALUES.get(dataType);
274
+ }
275
+ /**
276
+ * SQLite migration strategies.
277
+ *
278
+ * Each strategy examines the node-typed issue list, consumes issues it
279
+ * handles, and returns the `SqliteOpFactoryCall[]` to address them. The issue
280
+ * planner runs each strategy in order and routes whatever's left through
281
+ * `mapNodeIssueToCall`.
282
+ *
283
+ * SQLite has no enums and no component-declared database dependencies. The
284
+ * recipe that needs strategy-level multi-issue consumption is `recreateTable`,
285
+ * which absorbs type/nullability/default/constraint mismatches, and required
286
+ * columns added to existing tables, for a given table into one rebuild.
287
+ */
288
+ /**
289
+ * Classifies a node issue into the operation class a recreate absorbing it
290
+ * would need, or `null` when the strategy doesn't handle this node/reason at
291
+ * all (table/column not-found-or-not-expected, and index issues — those are
292
+ * standalone ops, never folded into a recreate).
293
+ *
294
+ * Column drift is a single `not-equal` issue (type and nullability compared
295
+ * together by `SqlColumnIR.isEqualTo`): a type change is destructive, because
296
+ * the copy can change values; a nullability change alone is widening, because
297
+ * a tightening copy fails on a NULL rather than losing it.
298
+ */
299
+ /** The column of a column issue, which `classifyNodeIssue` classes destructive only for a type change. */
300
+ function columnNameOf(issue) {
301
+ return blindCast(issue.expected).name;
302
+ }
303
+ /**
304
+ * The changes of codec a table rebuild's copy makes without losing a value: the column's type
305
+ * affinity stores each old value as the same value of the new type. An integer becomes its decimal
306
+ * text; a real is not listed, since SQLite writes it as text with fifteen significant digits. Keyed
307
+ * by codec, not data type, because `Int` and `BigInt` differ only in their codec.
308
+ */
309
+ const LOSSLESS_COPIES = /* @__PURE__ */ new Set([
310
+ `${SQLITE_INTEGER_CODEC_ID}→${SQLITE_TEXT_CODEC_ID}`,
311
+ `${SQLITE_BIGINT_CODEC_ID}→${SQLITE_TEXT_CODEC_ID}`,
312
+ `${SQLITE_INTEGER_CODEC_ID}→${SQLITE_BIGINT_CODEC_ID}`
313
+ ]);
314
+ function copyKeepsEveryValue(fromCodec, to) {
315
+ const toCodec = to.codecRef?.codecId;
316
+ return fromCodec !== void 0 && toCodec !== void 0 && LOSSLESS_COPIES.has(`${fromCodec}→${toCodec}`);
317
+ }
318
+ function classifyNodeIssue(issue, ctx) {
319
+ const node = issue.expected ?? issue.actual;
320
+ if (node === void 0) return null;
321
+ switch (blindCast(node).nodeKind) {
322
+ case RelationalSchemaNodeKind.column: {
323
+ if (issueOutcome(issue) !== "not-equal") return null;
324
+ const expected = blindCast(issue.expected);
325
+ const actual = blindCast(issue.actual);
326
+ const fromCodec = ctx.originCodecId(String(issue.path[1]), actual.name);
327
+ return !sqlColumnTypesEqual(expected, actual) && !copyKeepsEveryValue(fromCodec, expected) ? "destructive" : "widening";
328
+ }
329
+ case RelationalSchemaNodeKind.columnDefault:
330
+ case RelationalSchemaNodeKind.primaryKey:
331
+ case RelationalSchemaNodeKind.foreignKey:
332
+ case RelationalSchemaNodeKind.unique: return "widening";
333
+ default: return null;
334
+ }
335
+ }
336
+ function columnNode(node) {
337
+ return blindCast(node);
338
+ }
339
+ function isColumnIssue(issue) {
340
+ const node = issue.expected ?? issue.actual;
341
+ return node !== void 0 && blindCast(node).nodeKind === RelationalSchemaNodeKind.column;
342
+ }
343
+ /** The column a `--convert` or `--backfill` statement of `kind` names, if one names it. */
344
+ function statementColumn(ctx, kind, tableName, columnName) {
345
+ if (!ctx.policy.allowedOperationClasses.includes("data")) return void 0;
346
+ return ctx.statementColumns[kind].find((column) => column.table === tableName && column.column === columnName);
347
+ }
348
+ /** A column the plan adds to a table the database already has. */
349
+ function addedColumn(issue, ctx) {
350
+ if (issueOutcome(issue) !== "not-found" || !isColumnIssue(issue)) return void 0;
351
+ const tableName = issue.path[1];
352
+ if (tableName === void 0 || ctx.actual.tables[tableName] === void 0) return void 0;
353
+ return columnNode(issue.expected);
354
+ }
355
+ /**
356
+ * A required column with no default that the plan adds to a table the database already has, so
357
+ * existing rows need a value for it.
358
+ */
359
+ function addedRequiredColumn(issue, ctx) {
360
+ const column = addedColumn(issue, ctx);
361
+ return column === void 0 || column.nullable || column.resolvedDefault !== void 0 ? void 0 : column;
362
+ }
363
+ const CLASS_ORDER = [
364
+ "additive",
365
+ "widening",
366
+ "data",
367
+ "destructive"
368
+ ];
369
+ function highestClass(classes) {
370
+ return classes.reduce((highest, next) => CLASS_ORDER.indexOf(next) > CLASS_ORDER.indexOf(highest) ? next : highest, "additive");
371
+ }
372
+ /**
373
+ * Groups recreate-eligible issues by table and emits one `RecreateTableCall` per table, removing
374
+ * the issues it consumed so `mapNodeIssueToCall` does not handle them again.
375
+ *
376
+ * - A type change is `destructive`, since the copy can change values, unless a `--convert`
377
+ * statement names the column: the copy then goes through a slot the user fills, and the rebuild
378
+ * is `data`. Either way the rebuild checks after its copy that every value took the new type.
379
+ * - A nullability or constraint change alone is `widening`: a tightening copy fails on a NULL
380
+ * rather than losing it.
381
+ * - A required column with no default added to an existing table is copied from a temporary value
382
+ * (`additive`). A column in a key or foreign key, whose values come from a value set, or whose
383
+ * type has no such value is carried with nothing to copy from: the rebuild succeeds on an empty
384
+ * table and fails on `NOT NULL` when the table has rows. A column a `--backfill` statement names
385
+ * was added nullable and filled by earlier calls, so the rebuild copies it like a live column.
386
+ * - A rebuild that leaves a live column out loses its values, so it is `destructive`.
387
+ * - Any other column added to a table the plan rebuilds, optional or with a default, and an index
388
+ * on it, are left to the rebuild, which creates them from the new table's spec. The plan has no
389
+ * separate add, so the rebuild's source table is the live one (`additive`).
390
+ *
391
+ * The table shapes come from `ctx.expected` and `ctx.actual`, keyed by table name: SQLite is a
392
+ * flat, single-namespace target, and one issue only carries its own node.
393
+ */
394
+ const recreateTableStrategy = (issues, ctx) => {
395
+ const byTable = /* @__PURE__ */ new Map();
396
+ const consumed = /* @__PURE__ */ new Set();
397
+ const codecHooks = extractCodecControlHooks(ctx.frameworkComponents);
398
+ const rebuildOf = (tableName) => {
399
+ const existing = byTable.get(tableName);
400
+ if (existing !== void 0) return existing;
401
+ const created = {
402
+ issues: [],
403
+ classes: [],
404
+ retypedColumns: [],
405
+ copyExpressions: {},
406
+ temporaryValues: {},
407
+ addedColumns: []
408
+ };
409
+ byTable.set(tableName, created);
410
+ return created;
411
+ };
412
+ for (const issue of issues) {
413
+ const tableName = issue.path[1];
414
+ if (tableName === void 0) continue;
415
+ const added = addedRequiredColumn(issue, ctx);
416
+ if (added !== void 0) {
417
+ const expectedTable = ctx.expected.tables[tableName];
418
+ if (statementColumn(ctx, "backfill", tableName, added.name) !== void 0) {
419
+ const rebuild = rebuildOf(tableName);
420
+ rebuild.issues.push(issue);
421
+ rebuild.addedColumns.push(added.name);
422
+ rebuild.classes.push("widening");
423
+ consumed.add(issue);
424
+ continue;
425
+ }
426
+ const fill = expectedTable === void 0 || !ctx.takesTemporaryValue(tableName, added.name) ? void 0 : sqliteFillValue(added, codecHooks, ctx.types);
427
+ const rebuild = rebuildOf(tableName);
428
+ rebuild.issues.push(issue);
429
+ if (fill !== void 0) rebuild.temporaryValues[added.name] = {
430
+ kind: "sql",
431
+ sql: fill
432
+ };
433
+ rebuild.classes.push("additive");
434
+ consumed.add(issue);
435
+ continue;
436
+ }
437
+ const cls = classifyNodeIssue(issue, ctx);
438
+ if (!cls) continue;
439
+ const rebuild = rebuildOf(tableName);
440
+ rebuild.issues.push(issue);
441
+ consumed.add(issue);
442
+ if (cls === "widening") {
443
+ rebuild.classes.push("widening");
444
+ continue;
445
+ }
446
+ const column = columnNameOf(issue);
447
+ const converted = statementColumn(ctx, "convert", tableName, column);
448
+ rebuild.retypedColumns.push(column);
449
+ if (converted === void 0) {
450
+ rebuild.classes.push("destructive");
451
+ continue;
452
+ }
453
+ rebuild.copyExpressions[column] = {
454
+ kind: "placeholder",
455
+ slot: `${converted.text}:convert`
456
+ };
457
+ rebuild.classes.push("data");
458
+ }
459
+ for (const issue of issues) {
460
+ const rebuild = byTable.get(issue.path[1] ?? "");
461
+ if (consumed.has(issue) || rebuild === void 0 || addedColumn(issue, ctx) === void 0) continue;
462
+ rebuild.issues.push(issue);
463
+ rebuild.classes.push("additive");
464
+ consumed.add(issue);
465
+ }
466
+ if (byTable.size === 0) return { kind: "no_match" };
467
+ const calls = [];
468
+ for (const [tableName, rebuild] of byTable) {
469
+ const expectedTable = ctx.expected.tables[tableName];
470
+ const actualTable = ctx.actual.tables[tableName];
471
+ if (!expectedTable || !actualTable) continue;
472
+ const leavesColumnsOut = Object.keys(actualTable.columns).some((column) => !Object.hasOwn(expectedTable.columns, column));
473
+ const operationClass = highestClass([...rebuild.classes, ...leavesColumnsOut ? ["destructive"] : []]);
474
+ const tableSpec = tableSpecFromNode(expectedTable);
475
+ const indexes = expectedTable.indexes.map((idx) => ({
476
+ name: idx.name,
477
+ columns: idx.columns ?? []
478
+ }));
479
+ calls.push(new RecreateTableCall({
480
+ tableName,
481
+ contractTable: tableSpec,
482
+ schemaColumnNames: [...Object.keys(actualTable.columns), ...rebuild.addedColumns],
483
+ indexes,
484
+ summary: buildRecreateSummary(tableName, rebuild.issues),
485
+ postchecks: [...buildRecreatePostchecks(tableName, rebuild.issues, tableSpec, /* @__PURE__ */ new Set([...Object.keys(rebuild.copyExpressions), ...Object.keys(rebuild.temporaryValues)]), new Set(tableSpec.columns.filter(({ name }) => statementColumn(ctx, "backfill", tableName, name) !== void 0).map(({ name }) => name)))],
486
+ operationClass,
487
+ copyExpressions: rebuild.copyExpressions,
488
+ temporaryValues: rebuild.temporaryValues,
489
+ retypedColumns: rebuild.retypedColumns
490
+ }));
491
+ }
492
+ return {
493
+ kind: "match",
494
+ issues: issues.filter((i) => !consumed.has(i)),
495
+ calls,
496
+ recipe: true
497
+ };
498
+ };
499
+ /**
500
+ * Writes the calls that come before the rebuild of a column a `--backfill` statement names: for a
501
+ * required column added to an existing table, the nullable add and a data transform whose slot the
502
+ * user fills; for a column made required, the data transform. The rebuild that makes the column
503
+ * NOT NULL comes from `recreateTableStrategy`, so this strategy consumes no issue. Without the
504
+ * statement, a tightening rebuild fails on a NULL rather than guessing a value for it.
505
+ */
506
+ const nullabilityTighteningBackfillStrategy = (issues, ctx) => {
507
+ const calls = [];
508
+ for (const issue of issues) {
509
+ const tableName = issue.path[1];
510
+ if (tableName === void 0 || !isColumnIssue(issue)) continue;
511
+ const added = addedRequiredColumn(issue, ctx);
512
+ const tightened = issueOutcome(issue) === "not-equal" && !columnNode(issue.expected).nullable && columnNode(issue.actual).nullable ? columnNode(issue.expected) : void 0;
513
+ const column = added ?? tightened;
514
+ if (column === void 0) continue;
515
+ const named = statementColumn(ctx, "backfill", tableName, column.name);
516
+ if (named === void 0) continue;
517
+ if (added !== void 0) calls.push(new AddColumnCall(tableName, {
518
+ ...columnSpecFromNode(added, false),
519
+ nullable: true
520
+ }));
521
+ calls.push(new DataTransformCall(`data_migration.backfill-${tableName}-${column.name}`, `Backfill NULLs in "${tableName}"."${column.name}" before NOT NULL tightening`, tableName, column.name, `${named.text}:run`));
522
+ }
523
+ if (calls.length === 0) return { kind: "no_match" };
524
+ return {
525
+ kind: "match",
526
+ issues,
527
+ calls,
528
+ recipe: true
529
+ };
530
+ };
531
+ const sqlitePlannerStrategies = [nullabilityTighteningBackfillStrategy, recreateTableStrategy];
532
+ /**
533
+ * The generic differ is total: a missing/extra table (or column) emits an
534
+ * issue for itself AND for every node in its subtree (columns, defaults,
535
+ * constraints, indexes). `CreateTableCall`/`DropTableCall` and
536
+ * `AddColumnCall`/`DropColumnCall` already account for the whole subtree
537
+ * (reading it directly off the table/column node), so the nested issues are
538
+ * redundant — coalescing them is "the planner's responsibility" the differ's
539
+ * own contract assigns (`schema-diff.ts`). Drops any issue whose path is a
540
+ * strict descendant of a `not-found`/`not-expected` issue's path.
541
+ */
542
+ function coalesceSubtreeIssues(issues) {
543
+ const collapsingPaths = issues.filter((issue) => issueOutcome(issue) === "not-found" || issueOutcome(issue) === "not-expected").map((issue) => issue.path);
544
+ if (collapsingPaths.length === 0) return issues;
545
+ return issues.filter((issue) => !collapsingPaths.some((ancestor) => isStrictDescendantPath(issue.path, ancestor)));
546
+ }
547
+ function isStrictDescendantPath(path, ancestor) {
548
+ if (path.length <= ancestor.length) return false;
549
+ for (let i = 0; i < ancestor.length; i += 1) if (path[i] !== ancestor[i]) return false;
550
+ return true;
551
+ }
552
+ function issueNode(issue) {
553
+ const node = issue.expected ?? issue.actual;
554
+ if (node === void 0) return void 0;
555
+ return blindCast(node);
556
+ }
557
+ /**
558
+ * Builds the flat `SqliteTableSpec` `RecreateTableCall` needs from the
559
+ * expected table node — the node-sourced equivalent of the retired
560
+ * `toTableSpec` (which read a raw contract `StorageTable`). Every column's
561
+ * spec is resolved from its `codecRef` via `columnSpecFromNode`.
562
+ */
563
+ function tableSpecFromNode(table) {
564
+ const columns = Object.values(table.columns).map((c) => columnSpecFromNode(c, isInlineAutoincrementPrimaryKeyNode(table, c)));
565
+ const uniques = table.uniques.map((u) => ({
566
+ columns: u.columns,
567
+ ...u.name !== void 0 ? { name: u.name } : {}
568
+ }));
569
+ const foreignKeys = table.foreignKeys.map((fk) => ({
570
+ columns: fk.columns,
571
+ references: {
572
+ table: fk.referencedTable,
573
+ columns: fk.referencedColumns
574
+ },
575
+ ...fk.name !== void 0 ? { name: fk.name } : {},
576
+ ...fk.onDelete !== void 0 ? { onDelete: fk.onDelete } : {},
577
+ ...fk.onUpdate !== void 0 ? { onUpdate: fk.onUpdate } : {}
578
+ }));
579
+ return {
580
+ columns,
581
+ ...table.primaryKey ? { primaryKey: { columns: table.primaryKey.columns } } : {},
582
+ uniques,
583
+ foreignKeys
584
+ };
585
+ }
586
+ function issueConflict(kind, summary, location) {
587
+ return {
588
+ kind,
589
+ summary,
590
+ why: "Use `migration new` to author a custom migration for this change.",
591
+ ...location ? { location } : {}
592
+ };
593
+ }
594
+ function issueLocation(tableName, columnName) {
595
+ return columnName !== void 0 ? {
596
+ entityKind: "table",
597
+ entityName: tableName,
598
+ column: columnName
599
+ } : {
600
+ entityKind: "table",
601
+ entityName: tableName
602
+ };
603
+ }
604
+ /**
605
+ * Conflict kind for a node kind that `recreateTableStrategy` absorbs for
606
+ * every reachable production issue. Reaching `mapNodeIssueToCall` for one of
607
+ * these means the recreate strategy didn't run — mirrors the legacy
608
+ * `conflictKindForIssue` per-kind categorization.
609
+ */
610
+ function absorbedConflictKind(nodeKind) {
611
+ switch (nodeKind) {
612
+ case RelationalSchemaNodeKind.primaryKey:
613
+ case RelationalSchemaNodeKind.unique: return "indexIncompatible";
614
+ case RelationalSchemaNodeKind.foreignKey: return "foreignKeyConflict";
615
+ default: return "missingButNonAdditive";
616
+ }
617
+ }
618
+ /**
619
+ * Builds the `CreateTableCall` + per-index `CreateIndexCall`s for a
620
+ * newly-expected table. Reads only the table node's own children — indexes
621
+ * (declared + FK-backing, deduped) are already merged and ordered at
622
+ * derivation (`contractToSchemaIR`'s `convertTable`).
623
+ */
624
+ function buildCreateTableCalls(table) {
625
+ const columns = Object.values(table.columns).map((c) => ddlColumnFromNode(c, isInlineAutoincrementPrimaryKeyNode(table, c)));
626
+ const constraints = tableConstraintsFromNode(table, Object.values(table.columns).some((c) => isInlineAutoincrementPrimaryKeyNode(table, c)));
627
+ const calls = [new CreateTableCall(table.name, columns, constraints.length > 0 ? constraints : void 0)];
628
+ for (const index of table.indexes) {
629
+ const indexName = index.name;
630
+ calls.push(new CreateIndexCall(table.name, indexName, index.columns ?? []));
631
+ }
632
+ return calls;
633
+ }
634
+ function mapTableIssue(issue) {
635
+ if (issueOutcome(issue) === "not-found") return ok(buildCreateTableCalls(blindCast(issue.expected)));
636
+ if (issueOutcome(issue) === "not-expected") {
637
+ const table = blindCast(issue.actual);
638
+ if (CONTROL_TABLE_NAMES.has(table.name)) return ok([]);
639
+ return ok([new DropTableCall(table.name)]);
640
+ }
641
+ return notOk(issueConflict("unsupportedOperation", `Unexpected table drift: ${issue.path.join("/")}`));
642
+ }
643
+ function mapColumnIssue(issue, ctx) {
644
+ const tableName = issue.path[1];
645
+ if (tableName === void 0) return notOk(issueConflict("unsupportedOperation", `Column issue has no table in its path: ${issue.path.join("/")}`));
646
+ if (issueOutcome(issue) === "not-found") {
647
+ const column = blindCast(issue.expected);
648
+ const table = ctx.expected.tables[tableName];
649
+ return ok([new AddColumnCall(tableName, columnSpecFromNode(column, table !== void 0 && isInlineAutoincrementPrimaryKeyNode(table, column)))]);
650
+ }
651
+ if (issueOutcome(issue) === "not-expected") return ok([new DropColumnCall(tableName, blindCast(issue.actual).name)]);
652
+ const expected = blindCast(issue.expected);
653
+ return notOk(issueConflict(sqlColumnTypesEqual(expected, blindCast(issue.actual)) ? "nullabilityConflict" : "typeMismatch", issue.path.join("/"), issueLocation(tableName, expected.name)));
654
+ }
655
+ function mapIndexIssue(issue) {
656
+ const tableName = issue.path[1];
657
+ if (tableName === void 0) return notOk(issueConflict("unsupportedOperation", `Index issue has no table in its path: ${issue.path.join("/")}`));
658
+ if (issueOutcome(issue) === "not-found") {
659
+ const index = blindCast(issue.expected);
660
+ const indexName = index.name;
661
+ return ok([new CreateIndexCall(tableName, indexName, index.columns ?? [])]);
662
+ }
663
+ if (issueOutcome(issue) === "not-expected") {
664
+ const indexName = blindCast(issue.actual).name;
665
+ return ok([new DropIndexCall(tableName, indexName)]);
666
+ }
667
+ return notOk(issueConflict("indexIncompatible", issue.path.join("/"), issueLocation(tableName)));
668
+ }
669
+ function mapNodeIssueToCall(issue, ctx) {
670
+ const node = issueNode(issue);
671
+ if (node === void 0) return notOk(issueConflict("unsupportedOperation", `Issue carries neither an expected nor an actual node: ${issue.path.join("/")}`));
672
+ switch (node.nodeKind) {
673
+ case RelationalSchemaNodeKind.table: return mapTableIssue(issue);
674
+ case RelationalSchemaNodeKind.column: return mapColumnIssue(issue, ctx);
675
+ case RelationalSchemaNodeKind.index: return mapIndexIssue(issue);
676
+ case RelationalSchemaNodeKind.columnDefault:
677
+ case RelationalSchemaNodeKind.primaryKey:
678
+ case RelationalSchemaNodeKind.foreignKey:
679
+ case RelationalSchemaNodeKind.unique: return notOk(issueConflict(absorbedConflictKind(node.nodeKind), issue.path.join("/")));
680
+ case RelationalSchemaNodeKind.check: return notOk(issueConflict("unsupportedOperation", `The SQLite target does not support CHECK constraint DDL: ${issue.path.join("/")}`));
681
+ default: return notOk(issueConflict("unsupportedOperation", `Unhandled node kind: ${node.nodeKind}`));
682
+ }
683
+ }
684
+ function classifyCall(call) {
685
+ switch (call.factoryName) {
686
+ case "createTable": return "create-table";
687
+ case "addColumn": return "add-column";
688
+ case "createIndex": return "create-index";
689
+ case "dropColumn": return "drop-column";
690
+ case "dropIndex": return "drop-index";
691
+ case "dropTable": return "drop-table";
692
+ case "recreateTable": return null;
693
+ default: return null;
694
+ }
695
+ }
696
+ const DEFAULT_POLICY = { allowedOperationClasses: [
697
+ "additive",
698
+ "widening",
699
+ "destructive",
700
+ "data"
701
+ ] };
702
+ function planIssues(options) {
703
+ const policyProvided = options.policy !== void 0;
704
+ const policy = options.policy ?? DEFAULT_POLICY;
705
+ const frameworkComponents = options.frameworkComponents ?? [];
706
+ const context = {
707
+ expected: options.expected ?? emptySchemaIR(),
708
+ actual: options.actual ?? emptySchemaIR(),
709
+ policy,
710
+ frameworkComponents,
711
+ types: sqlTypeLookupsOf(frameworkComponents),
712
+ statementColumns: options.statementColumns ?? {
713
+ convert: [],
714
+ backfill: []
715
+ },
716
+ takesTemporaryValue: options.takesTemporaryValue ?? (() => true),
717
+ originCodecId: options.originCodecId ?? (() => void 0)
718
+ };
719
+ const strategies = options.strategies ?? sqlitePlannerStrategies;
720
+ let remaining = options.issues;
721
+ const recipeCalls = [];
722
+ const bucketableCalls = [];
723
+ for (const strategy of strategies) {
724
+ const result = strategy(remaining, context);
725
+ if (result.kind === "match") {
726
+ remaining = result.issues;
727
+ if (result.recipe) recipeCalls.push(...result.calls);
728
+ else bucketableCalls.push(...result.calls);
729
+ }
730
+ }
731
+ const sorted = orderIssuesByDependencies(remaining);
732
+ const defaultCalls = [];
733
+ const conflicts = [];
734
+ for (const issue of sorted) {
735
+ const result = mapNodeIssueToCall(issue, context);
736
+ if (result.ok) defaultCalls.push(...result.value);
737
+ else conflicts.push(result.failure);
738
+ }
739
+ const allowed = policy.allowedOperationClasses;
740
+ let gatedRecipe = recipeCalls;
741
+ let gatedBucketable = bucketableCalls;
742
+ let gatedDefault = defaultCalls;
743
+ if (policyProvided) {
744
+ const sink = (acc) => (call) => {
745
+ if (allowed.includes(call.operationClass)) {
746
+ acc.push(call);
747
+ return;
748
+ }
749
+ conflicts.push(conflictForDisallowedCall(call, allowed));
750
+ };
751
+ const gatedRecipeBucket = [];
752
+ const gatedBucketableBucket = [];
753
+ const gatedDefaultBucket = [];
754
+ recipeCalls.forEach(sink(gatedRecipeBucket));
755
+ bucketableCalls.forEach(sink(gatedBucketableBucket));
756
+ defaultCalls.forEach(sink(gatedDefaultBucket));
757
+ gatedRecipe = gatedRecipeBucket;
758
+ gatedBucketable = gatedBucketableBucket;
759
+ gatedDefault = gatedDefaultBucket;
760
+ }
761
+ if (conflicts.length > 0) return notOk(conflicts);
762
+ const rebuiltIndexes = new Set(gatedRecipe.flatMap((call) => call instanceof RecreateTableCall ? call.indexes.map((index) => indexKey(call.tableName, index.name)) : []));
763
+ const bucketed = [...gatedDefault, ...gatedBucketable];
764
+ const addedBeforeIndexes = new Set(bucketed.flatMap((call) => call instanceof AddColumnCall ? [indexKey(call.tableName, call.columnName)] : []));
765
+ const indexesANewColumn = (call) => {
766
+ const live = context.actual.tables[call.tableName];
767
+ return live !== void 0 && call.columns.some((column) => live.columns[column] === void 0 && !addedBeforeIndexes.has(indexKey(call.tableName, column)));
768
+ };
769
+ const combined = bucketed.filter((call) => !(call instanceof CreateIndexCall) || !indexesANewColumn(call) || !rebuiltIndexes.has(indexKey(call.tableName, call.indexName)));
770
+ const byCategory = (cat) => combined.filter((c) => classifyCall(c) === cat);
771
+ return ok({ calls: [
772
+ ...byCategory("create-table"),
773
+ ...byCategory("add-column"),
774
+ ...byCategory("create-index"),
775
+ ...gatedRecipe,
776
+ ...byCategory("drop-column"),
777
+ ...byCategory("drop-index"),
778
+ ...byCategory("drop-table")
779
+ ] });
780
+ }
781
+ function indexKey(tableName, indexName) {
782
+ return JSON.stringify([tableName, indexName]);
783
+ }
784
+ function emptySchemaIR() {
785
+ return new SqlSchemaIR({ tables: {} });
786
+ }
787
+ function conflictForDisallowedCall(call, allowed) {
788
+ const summary = `Operation "${call.label}" requires class "${call.operationClass}", but policy allows only: ${allowed.join(", ")}`;
789
+ const location = locationForCall(call);
790
+ return {
791
+ kind: conflictKindForCall(call),
792
+ summary,
793
+ why: "Use `migration new` to author a custom migration for this change.",
794
+ refusedOperationClass: call.operationClass,
795
+ ...location ? { location } : {}
796
+ };
797
+ }
798
+ function conflictKindForCall(call) {
799
+ switch (call.factoryName) {
800
+ case "createIndex":
801
+ case "dropIndex": return "indexIncompatible";
802
+ default: return "missingButNonAdditive";
803
+ }
804
+ }
805
+ function locationForCall(call) {
806
+ const location = {};
807
+ if ("tableName" in call) {
808
+ location.entityKind = "table";
809
+ location.entityName = call.tableName;
810
+ }
811
+ if ("columnName" in call) location.column = call.columnName;
812
+ if ("indexName" in call) location.index = call.indexName;
813
+ return Object.keys(location).length > 0 ? location : void 0;
814
+ }
815
+ function indexFindings(issues, outcome) {
816
+ return issues.flatMap((issue) => {
817
+ const node = issueNode(issue);
818
+ const tableName = issue.path[1];
819
+ if (node === void 0 || !SqlIndexIR.is(node) || tableName === void 0) return [];
820
+ return issueOutcome(issue) === outcome ? [{
821
+ issue,
822
+ index: node,
823
+ tableName
824
+ }] : [];
825
+ });
826
+ }
827
+ /**
828
+ * An index on a renamed table whose wire name derives from the table name: the old and the new index share their content hash and differ in name.
829
+ */
830
+ function renamedTableIndex(renamedTables) {
831
+ return (old, replacement) => {
832
+ const oldWire = parseWireName(old.index.name);
833
+ const replacementWire = parseWireName(replacement.index.name);
834
+ return renamedTables.has(old.tableName) && old.tableName === replacement.tableName && oldWire !== void 0 && oldWire.hash === replacementWire?.hash && old.index.name !== replacement.index.name;
835
+ };
836
+ }
837
+ /**
838
+ * An index on the renamed column whose wire name derives from the column name: after the rename
839
+ * the old and the new index cover the same columns on the same table and differ in name.
840
+ */
841
+ function renamedColumnIndex(table, column) {
842
+ return (old, replacement) => old.tableName === table && replacement.tableName === table && old.index.name !== replacement.index.name && old.index.expression === void 0 && old.index.where === void 0 && (old.index.columns ?? []).includes(column) && old.index.unique === replacement.index.unique && isArrayEqual(old.index.columns ?? [], replacement.index.columns ?? []);
843
+ }
844
+ /**
845
+ * An index on the same table whose new name SQLite takes for the old one, as after a table renamed by hand. Its content is not compared: the old index must be dropped before the new one can be created whatever either defines, and the new one is created from its own definition.
846
+ */
847
+ const indexNameCaseChange = (old, replacement) => old.tableName === replacement.tableName && old.index.name !== replacement.index.name && sqliteIdentifiersCollide(old.index.name, replacement.index.name);
848
+ /**
849
+ * Pairs each index the plan drops with the index that replaces it, and plans every paired drop before every paired create. SQLite cannot rename an index, and it compares index names without regard to the case of ASCII letters, so a replacement whose name differs from the old one only in that case would otherwise collide with it. The paired issues are returned as consumed so the ordinary diff does not plan them again.
850
+ */
851
+ function pairIndexReplacements(issues, matches) {
852
+ const missing = indexFindings(issues, "not-found");
853
+ const pairs = indexFindings(issues, "not-expected").flatMap((old) => {
854
+ const replacement = missing.find((candidate) => matches(old, candidate));
855
+ if (replacement === void 0) return [];
856
+ missing.splice(missing.indexOf(replacement), 1);
857
+ return [{
858
+ old,
859
+ replacement
860
+ }];
861
+ });
862
+ const replacements = pairs.map(({ old, replacement }) => ({
863
+ drop: new DropIndexCall(old.tableName, old.index.name),
864
+ create: new CreateIndexCall(replacement.tableName, replacement.index.name, replacement.index.columns ?? [])
865
+ }));
866
+ return {
867
+ replacements,
868
+ calls: indexReplacementCalls(replacements),
869
+ consumed: new Set(pairs.flatMap(({ old, replacement }) => [old.issue, replacement.issue]))
870
+ };
871
+ }
872
+ /**
873
+ * The tables of a SQLite schema. SQLite has one namespace, so the namespace id is ignored, and it
874
+ * compares table and column names without regard to the case of ASCII letters.
875
+ */
876
+ function sqliteSchemaTables(schema) {
877
+ const hasTable = (_namespaceId, table) => Object.hasOwn(schema.tables, table);
878
+ return {
879
+ hasTable,
880
+ hasColumn: (_namespaceId, table, column) => Object.hasOwn(schema.tables[table]?.columns ?? {}, column),
881
+ tablesNamed: (_namespaceId, table) => Object.keys(schema.tables).filter((existing) => sqliteIdentifiersCollide(existing, table)),
882
+ columnsNamed: (_namespaceId, table, column) => Object.keys(schema.tables[table]?.columns ?? {}).filter((existing) => sqliteIdentifiersCollide(existing, column)),
883
+ namespacesWithTable: (table) => hasTable(UNBOUND_NAMESPACE_ID, table) ? [UNBOUND_NAMESPACE_ID] : [],
884
+ hasNamespace: (namespaceId) => namespaceId === UNBOUND_NAMESPACE_ID
885
+ };
886
+ }
887
+ function rewriteRefs(refs, rewrite) {
888
+ return refs?.map(rewrite);
889
+ }
890
+ /**
891
+ * Rewrites the step of `kind` and `id` in a ref that runs through the given table, and the table
892
+ * step itself when `kind` is the table kind.
893
+ */
894
+ function stepRewrite(tableName, kind, fromId, toId) {
895
+ return (ref) => {
896
+ const tableStep = ref[1];
897
+ if (tableStep?.nodeKind !== RelationalSchemaNodeKind.table || tableStep.id !== tableName) return ref;
898
+ return ref.map((step, index) => index >= 1 && step.nodeKind === kind && step.id === fromId ? {
899
+ nodeKind: kind,
900
+ id: toId
901
+ } : step);
902
+ };
903
+ }
904
+ /**
905
+ * An index whose definition carries SQL text, an expression or a predicate, keeps its columns as
906
+ * they are: a column named inside the text cannot be renamed here, so the diff plans the index.
907
+ */
908
+ function withIndex(index, name, rewrite, columnName) {
909
+ const columnsFollow = index.expression === void 0 && index.where === void 0;
910
+ const base = {
911
+ naming: name === index.name ? namingOf(index.name, index.prefix) : namingOfLiveName(name),
912
+ where: index.where,
913
+ unique: index.unique,
914
+ partial: index.partial,
915
+ type: index.type,
916
+ options: index.options,
917
+ annotations: index.annotations,
918
+ dependsOn: rewriteRefs(index.dependsOn, rewrite)
919
+ };
920
+ return new SqlIndexIR(index.expression !== void 0 ? {
921
+ ...base,
922
+ expression: index.expression
923
+ } : {
924
+ ...base,
925
+ columns: (index.columns ?? []).map(columnsFollow ? columnName : (c) => c)
926
+ });
927
+ }
928
+ function rebuildTable(table, edit, rewrite) {
929
+ const { primaryKey } = table;
930
+ const { columnName } = edit;
931
+ return new SqlTableIR({
932
+ name: edit.name,
933
+ columns: Object.fromEntries(Object.values(table.columns).map((column) => {
934
+ const name = columnName(column.name);
935
+ return [name, name === column.name ? column : column.withName(name)];
936
+ })),
937
+ ...ifDefined("primaryKey", primaryKey === void 0 ? void 0 : new PrimaryKey({
938
+ columns: primaryKey.columns.map(columnName),
939
+ ...ifDefined("name", primaryKey.name),
940
+ ...ifDefined("dependsOn", rewriteRefs(primaryKey.dependsOn, rewrite))
941
+ })),
942
+ uniques: table.uniques.map((unique) => new SqlUniqueIR({
943
+ columns: unique.columns.map(columnName),
944
+ ...ifDefined("name", unique.name),
945
+ ...ifDefined("annotations", unique.annotations),
946
+ ...ifDefined("dependsOn", rewriteRefs(unique.dependsOn, rewrite))
947
+ })),
948
+ foreignKeys: table.foreignKeys.map((fk) => new SqlForeignKeyIR({
949
+ columns: fk.columns.map(columnName),
950
+ referencedTable: edit.referencedTable(fk),
951
+ referencedColumns: edit.referencedColumns(fk),
952
+ ...ifDefined("referencedSchema", fk.referencedSchema),
953
+ ...ifDefined("name", fk.name),
954
+ ...ifDefined("onDelete", fk.onDelete),
955
+ ...ifDefined("onUpdate", fk.onUpdate),
956
+ ...ifDefined("annotations", fk.annotations),
957
+ ...ifDefined("resolvedReferencedNamespace", fk.resolvedReferencedNamespace),
958
+ ...ifDefined("dependsOn", rewriteRefs(fk.dependsOn, rewrite))
959
+ })),
960
+ indexes: table.indexes.map((index) => withIndex(index, edit.indexName(index), rewrite, columnName)),
961
+ ...ifDefined("checks", table.checks?.map((check) => new SqlCheckConstraintIR({
962
+ naming: namingOf(check.name, check.prefix),
963
+ expression: check.expression,
964
+ dependsOn: rewriteRefs(check.dependsOn, rewrite)
965
+ }))),
966
+ ...ifDefined("annotations", table.annotations)
967
+ });
968
+ }
969
+ /** Rebuilds every table: `editFor` returns the edit for a table, or `undefined` to keep it. */
970
+ function mapTables(schema, rewrite, editFor) {
971
+ return new SqlSchemaIR({
972
+ tables: Object.fromEntries(Object.values(schema.tables).map((table) => {
973
+ const rebuilt = rebuildTable(table, {
974
+ name: table.name,
975
+ columnName: (column) => column,
976
+ referencedTable: (fk) => fk.referencedTable,
977
+ referencedColumns: (fk) => fk.referencedColumns,
978
+ indexName: (index) => index.name,
979
+ ...editFor(table)
980
+ }, rewrite);
981
+ return [rebuilt.name, rebuilt];
982
+ })),
983
+ ...ifDefined("annotations", schema.annotations)
984
+ });
985
+ }
986
+ /**
987
+ * The schema with one table under its new name. Foreign keys anywhere that reference the table
988
+ * follow it, and every dependency that names it moves with it. Object names do not change. An
989
+ * unnamed primary key, unique constraint or foreign key stays unnamed: SQLite gives such a
990
+ * constraint no name, so an introspected schema has none either, and the planner never renames
991
+ * one.
992
+ */
993
+ function renameTableInSqliteSchema(schema, rename) {
994
+ const { from, to } = rename;
995
+ return mapTables(schema, stepRewrite(from, RelationalSchemaNodeKind.table, from, to), (table) => ({
996
+ ...table.name === from ? { name: to } : {},
997
+ referencedTable: (fk) => fk.referencedTable === from ? to : fk.referencedTable
998
+ }));
999
+ }
1000
+ /**
1001
+ * The schema with one column under its new name. The table's primary key, unique constraints,
1002
+ * foreign keys and plain column indexes name it under the new name, foreign keys anywhere that
1003
+ * reference it follow it, and every dependency that names it moves with it. An index with an
1004
+ * expression or a predicate keeps its SQL text, and index names do not change, as in SQLite.
1005
+ */
1006
+ function renameColumnInSqliteSchema(schema, rename) {
1007
+ const { table: tableName, from, to } = rename;
1008
+ const rewrite = stepRewrite(tableName, RelationalSchemaNodeKind.column, `column:${from}`, `column:${to}`);
1009
+ const renamed = (column) => column === from ? to : column;
1010
+ return mapTables(schema, rewrite, (table) => ({
1011
+ ...table.name === tableName ? { columnName: renamed } : {},
1012
+ referencedColumns: (fk) => fk.referencedTable === tableName ? fk.referencedColumns.map(renamed) : fk.referencedColumns
1013
+ }));
1014
+ }
1015
+ function replaceIndex(schema, replacement) {
1016
+ const { tableName, indexName: oldIndexName } = replacement.drop;
1017
+ const newIndexName = replacement.create.indexName;
1018
+ return mapTables(schema, stepRewrite(tableName, RelationalSchemaNodeKind.index, `index:${oldIndexName}`, `index:${newIndexName}`), (table) => table.name === tableName ? { indexName: (index) => index.name === oldIndexName ? newIndexName : index.name } : void 0);
1019
+ }
1020
+ /** The working schema of a plan or a migration, starting from `initial`. */
1021
+ function createWorkingSchema(initial) {
1022
+ return new WorkingSchemaImpl(initial);
1023
+ }
1024
+ var WorkingSchemaImpl = class {
1025
+ #current;
1026
+ constructor(initial) {
1027
+ this.#current = initial;
1028
+ }
1029
+ get current() {
1030
+ return this.#current;
1031
+ }
1032
+ apply(call) {
1033
+ const renamed = call instanceof RenameColumnCall ? renameColumnInSqliteSchema(this.#current, {
1034
+ table: call.tableName,
1035
+ from: call.oldColumnName,
1036
+ to: call.columnName
1037
+ }) : renameTableInSqliteSchema(this.#current, {
1038
+ from: call.oldTableName,
1039
+ to: call.tableName
1040
+ });
1041
+ this.#current = call.indexReplacements.reduce(replaceIndex, renamed);
1042
+ }
1043
+ };
1044
+ /** The SQL a user runs against the database to rename the table by hand. */
1045
+ function renameTableByHandStatements(rename) {
1046
+ return renameTableSteps(rename.from, rename.to).map((renameStep) => renameStep.sql);
1047
+ }
1048
+ /** The `renameTable` call a user writes in `migration.ts` for `rename`; SQLite has no namespaces. */
1049
+ function renderRenameTableCall(rename) {
1050
+ return new RenameTableCall(rename.from, rename.to, []).renderTypeScript();
1051
+ }
1052
+ /** How a user renames a table by hand on SQLite. */
1053
+ const sqliteTableRenameByHand = {
1054
+ renderTableRename: renderRenameTableCall,
1055
+ tableRenameByHand: renameTableByHandStatements
1056
+ };
1057
+ /**
1058
+ * The call that renames a table, carrying as companions a drop and a create under the new name of
1059
+ * each index whose wire name derives from the old table name, since SQLite cannot rename an index.
1060
+ * `previous` is the schema with the table under its old name; the renamed copy is diffed against
1061
+ * `contract`. SQLite names no primary key, unique constraint or foreign key the contract leaves
1062
+ * unnamed, so those need nothing.
1063
+ */
1064
+ function sqliteTableRenameCall(input) {
1065
+ const { from, to } = input.rename;
1066
+ const { issues } = buildSqlitePlanDiff({
1067
+ contract: input.contract,
1068
+ actualSchema: renameTableInSqliteSchema(input.previous, {
1069
+ from,
1070
+ to
1071
+ }),
1072
+ frameworkComponents: input.frameworkComponents
1073
+ });
1074
+ const { replacements } = pairIndexReplacements(coalesceSubtreeIssues(issues), renamedTableIndex(/* @__PURE__ */ new Set([to])));
1075
+ return new RenameTableCall(from, to, replacements);
1076
+ }
1077
+ /**
1078
+ * The call that renames a column, carrying as companions a drop and a create under the new name of
1079
+ * each index on the column whose wire name derives from the column name, since SQLite cannot rename
1080
+ * an index and keeps the old name when it renames the column. `previous` is the schema with the
1081
+ * column under its old name; the renamed copy is diffed against `contract`.
1082
+ */
1083
+ function sqliteColumnRenameCall(input) {
1084
+ const { table, from, to } = input.rename;
1085
+ const { issues } = buildSqlitePlanDiff({
1086
+ contract: input.contract,
1087
+ actualSchema: renameColumnInSqliteSchema(input.previous, {
1088
+ table,
1089
+ from,
1090
+ to
1091
+ }),
1092
+ frameworkComponents: input.frameworkComponents
1093
+ });
1094
+ const { replacements } = pairIndexReplacements(coalesceSubtreeIssues(issues), renamedColumnIndex(table, to));
1095
+ return new RenameColumnCall(table, from, to, replacements);
1096
+ }
1097
+ /**
1098
+ * Target-owned base class for SQLite migrations. Fixes the `SqlMigration`
1099
+ * generic to `SqlitePlanTargetDetails` and the abstract `targetId` to the
1100
+ * SQLite literal, so both user-authored migrations and renderer-generated
1101
+ * scaffolds can extend `SqliteMigration` directly without redeclaring
1102
+ * target-local identity.
1103
+ *
1104
+ * The constructor materializes a single SQLite `SqlControlAdapter` from
1105
+ * `stack.adapter.create(stack)` and stores it; the protected instance methods
1106
+ * forward to the corresponding `*Call` with that stored adapter, so user
1107
+ * migrations can write `this.createTable({...})` without threading the adapter
1108
+ * through every call.
1109
+ *
1110
+ * Binds the framework base's `Start` / `End` contract generics so a subclass
1111
+ * that assigns its snapshot-store `contract.json` imports to
1112
+ * `startContractJson` / `endContractJson` gets fully-typed view accessors:
1113
+ * `this.endContract` is a `SqliteContractView<End>`
1114
+ * (sole namespace unwrapped to the root — `this.endContract.table.<name>`),
1115
+ * built lazily from the JSON fields via the shared `MigrationContractViews`
1116
+ * helper. Mirrors `MongoMigration`'s view getters; the framework base derives
1117
+ * `describe()` from the same JSON.
1118
+ */
1119
+ var SqliteMigration = class extends Migration {
1120
+ targetId = "sqlite";
1121
+ /**
1122
+ * Materialized SQLite control adapter, created once per migration
1123
+ * instance from the injected stack. `undefined` only when the migration
1124
+ * was instantiated without a stack (test fixtures); `controlAdapterFor`
1125
+ * throws a MIGRATION.SQLITE_CONTROL_STACK_MISSING in that case to surface the misuse.
1126
+ */
1127
+ controlAdapter;
1128
+ #endView = new MigrationContractViews(this, "SqliteMigration", (json) => SqliteContractView.fromJson(json));
1129
+ /** The rename calls this read of `operations` has made so far, in order. */
1130
+ #renames = [];
1131
+ #startView = new MigrationContractViews(this, "SqliteMigration", (json) => SqliteContractView.fromJson(json));
1132
+ constructor(stack) {
1133
+ super(stack);
1134
+ this.controlAdapter = stack?.adapter ? blindCast(stack.adapter.create(stack)) : void 0;
1135
+ }
1136
+ frameworkComponents() {
1137
+ const stack = this.stack;
1138
+ if (stack === void 0) return [];
1139
+ return [
1140
+ stack.target,
1141
+ ...stack.adapter === void 0 ? [] : [stack.adapter],
1142
+ ...stack.extensions
1143
+ ];
1144
+ }
1145
+ /**
1146
+ * Returns the materialized control adapter, or throws a MIGRATION.SQLITE_CONTROL_STACK_MISSING naming
1147
+ * `operation` when the migration was constructed without a `ControlStack`.
1148
+ * Single home for the null-check that every DDL/DML method shares.
1149
+ */
1150
+ controlAdapterFor(operation) {
1151
+ if (!this.controlAdapter) throw errorSqliteMigrationStackMissing(operation);
1152
+ return this.controlAdapter;
1153
+ }
1154
+ /**
1155
+ * The typed SQLite view over this migration's end-state contract — sole
1156
+ * namespace unwrapped to the root, so `this.endContract.table.<name>` etc.
1157
+ * Throws if no `endContractJson` was provided.
1158
+ */
1159
+ get endContract() {
1160
+ return this.#endView.endContract;
1161
+ }
1162
+ /**
1163
+ * The typed SQLite view over this migration's start-state contract, or
1164
+ * `null` for a baseline migration (no `startContractJson`).
1165
+ */
1166
+ get startContract() {
1167
+ return this.#startView.startContract;
1168
+ }
1169
+ createTable(options) {
1170
+ return new CreateTableCall(options.table, options.columns, options.constraints).toOp(this.controlAdapterFor("createTable"));
1171
+ }
1172
+ dropTable(options) {
1173
+ return new DropTableCall(options.table).toOp(this.controlAdapterFor("dropTable"));
1174
+ }
1175
+ /**
1176
+ * Emit the operations that rename a table: the table rename, then a drop and a create under the
1177
+ * new name of each index whose name was derived from the old table name. The old name is resolved
1178
+ * against the schema as this migration's earlier `renameTable` calls leave it, and the new name
1179
+ * against the end contract. Spread the result into `operations`:
1180
+ * `...this.renameTable({ table: 'userProfile', to: 'UserProfile' })`. Throws
1181
+ * `MIGRATION.TABLE_RENAME_UNMATCHED` when the table does not exist at that point of the migration
1182
+ * or the end contract lacks the new name.
1183
+ */
1184
+ renameTable(options) {
1185
+ const adapter = this.controlAdapterFor("renameTable");
1186
+ const rename = {
1187
+ namespaceId: void 0,
1188
+ from: options.table,
1189
+ to: options.to
1190
+ };
1191
+ const startContract = this.startContract;
1192
+ if (startContract === null) throw unmatchedTableRename(rename, "the migration has no start contract");
1193
+ const current = this.schemaAfterRenames(startContract);
1194
+ const endContract = this.endContract;
1195
+ const resolved = resolveTableRenameAgainst(sqliteSchemaTables(current), endContract, rename);
1196
+ if (!resolved.ok) throw resolved.failure;
1197
+ const call = sqliteTableRenameCall({
1198
+ previous: current,
1199
+ contract: endContract,
1200
+ rename: resolved.value,
1201
+ frameworkComponents: this.frameworkComponents()
1202
+ });
1203
+ this.#renames.push(call);
1204
+ return call.toOps(adapter);
1205
+ }
1206
+ /**
1207
+ * Emit the operations that rename a column: the column rename, then a drop and a create under
1208
+ * the new name of each index on the column whose name was derived from the old column name. The
1209
+ * column is resolved against the schema as this migration's earlier rename calls leave it, so a
1210
+ * column of a table an earlier `renameTable` renamed is named on the table's new name. Spread the
1211
+ * result into `operations`: `...this.renameColumn({ table: 'User', column: 'name', to:
1212
+ * 'fullName' })`. Throws `MIGRATION.COLUMN_RENAME_UNMATCHED` when the table or column does not
1213
+ * exist at that point of the migration, the table already has the new column, or the end
1214
+ * contract lacks it.
1215
+ */
1216
+ renameColumn(options) {
1217
+ const adapter = this.controlAdapterFor("renameColumn");
1218
+ const rename = {
1219
+ namespaceId: void 0,
1220
+ table: options.table,
1221
+ from: options.column,
1222
+ to: options.to
1223
+ };
1224
+ const startContract = this.startContract;
1225
+ if (startContract === null) throw unmatchedColumnRename(rename, "the migration has no start contract");
1226
+ const current = this.schemaAfterRenames(startContract);
1227
+ const resolved = resolveColumnRenameAgainst(sqliteSchemaTables(current), this.endContract, rename);
1228
+ if (!resolved.ok) throw resolved.failure;
1229
+ const call = sqliteColumnRenameCall({
1230
+ previous: current,
1231
+ contract: this.endContract,
1232
+ rename: resolved.value,
1233
+ frameworkComponents: this.frameworkComponents()
1234
+ });
1235
+ this.#renames.push(call);
1236
+ return call.toOps(adapter);
1237
+ }
1238
+ /** The start contract's schema with this read's rename calls applied in order. */
1239
+ schemaAfterRenames(startContract) {
1240
+ const working = createWorkingSchema(sqliteContractToSchema(startContract, sqlTypeLookupsOf(this.frameworkComponents())));
1241
+ for (const call of this.#renames) working.apply(call);
1242
+ return working.current;
1243
+ }
1244
+ beginOperationsRead() {
1245
+ this.#renames = [];
1246
+ }
1247
+ addColumn(options) {
1248
+ return new AddColumnCall(options.table, columnSpecOf(options.column, "addColumn", options.table)).toOp(this.controlAdapterFor("addColumn"));
1249
+ }
1250
+ dropColumn(options) {
1251
+ return new DropColumnCall(options.table, options.column).toOp(this.controlAdapterFor("dropColumn"));
1252
+ }
1253
+ createIndex(options) {
1254
+ return new CreateIndexCall(options.table, options.index, options.columns).toOp(this.controlAdapterFor("createIndex"));
1255
+ }
1256
+ dropIndex(options) {
1257
+ return new DropIndexCall(options.table, options.index).toOp(this.controlAdapterFor("dropIndex"));
1258
+ }
1259
+ recreateTable(options) {
1260
+ const { copyExpressions, temporaryValues, ...args } = options;
1261
+ return new RecreateTableCall({
1262
+ ...args,
1263
+ contractTable: {
1264
+ ...options.contractTable,
1265
+ columns: options.contractTable.columns.map((column) => columnSpecOf(column, "recreateTable", options.tableName))
1266
+ },
1267
+ ...ifDefined("copyExpressions", copyExpressions === void 0 ? void 0 : copyExpressionSlotsOf(copyExpressions, options.tableName)),
1268
+ ...ifDefined("temporaryValues", temporaryValues === void 0 ? void 0 : copyExpressionSlotsOf(temporaryValues, options.tableName, "temporaryValues"))
1269
+ }).toOp(this.controlAdapterFor("recreateTable"));
1270
+ }
1271
+ };
1272
+ function columnDefaultOf(columnDefault, what) {
1273
+ return columnDefault.kind === "function" ? {
1274
+ kind: "function",
1275
+ expression: sqlTextOf(columnDefault.expression, what)
1276
+ } : columnDefault;
1277
+ }
1278
+ function columnSpecOf(column, operation, table) {
1279
+ const { default: columnDefault, ...rest } = column;
1280
+ const what = `${operation} ${JSON.stringify(table)}.${JSON.stringify(column.name)} default`;
1281
+ return {
1282
+ ...rest,
1283
+ ...ifDefined("default", columnDefault === void 0 ? void 0 : columnDefaultOf(columnDefault, what))
1284
+ };
1285
+ }
1286
+ function copyExpressionSlotsOf(copyExpressions, table, option = "copyExpressions") {
1287
+ return Object.fromEntries(Object.entries(copyExpressions).map(([column, expression]) => [column, {
1288
+ kind: "sql",
1289
+ sql: sqlTextOf(expression, `recreateTable ${JSON.stringify(table)} ${option}.${column}`)
1290
+ }]));
1291
+ }
1292
+ //#endregion
1293
+ export { sqliteSchemaTables as _, createWorkingSchema as a, verifySqliteDatabaseSchema as b, issueNode as c, renameTableByHandStatements as d, renderRenameTableCall as f, sqlitePlannerStrategies as g, sqliteContractToSchema as h, conflictForDisallowedCall as i, pairIndexReplacements as l, sqliteColumnRenameCall as m, buildSqlitePlanDiff as n, diffSqliteSchema as o, sqliteActualSchema as p, coalesceSubtreeIssues as r, indexNameCaseChange as s, SqliteMigration as t, planIssues as u, sqliteTableRenameByHand as v, sqliteTableRenameCall as y };
1294
+
1295
+ //# sourceMappingURL=sqlite-migration-BAdSmooi-iWFVQgGV.mjs.map