@farm.js/core 0.1.46 → 0.1.48
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.
- package/dist/after.cjs +3 -3
- package/dist/after.mjs +2 -2
- package/dist/agent-mcp-CXN3g0eX.d.mts +115 -0
- package/dist/agent-mcp-DAjB8Eyu.d.ts +115 -0
- package/dist/agent-mcp-handler-RT3COCEL.cjs +18 -0
- package/dist/agent-mcp-handler-WWCC4GLG.mjs +18 -0
- package/dist/agent-runtime.cjs +33 -61
- package/dist/agent-runtime.d.mts +1 -1
- package/dist/agent-runtime.d.ts +1 -1
- package/dist/agent-runtime.mjs +32 -60
- package/dist/api/client.cjs +14 -14
- package/dist/api/client.mjs +13 -13
- package/dist/api/route-manager.cjs +41 -41
- package/dist/api/route-manager.d.mts +3 -3
- package/dist/api/route-manager.d.ts +3 -3
- package/dist/api/route-manager.mjs +40 -40
- package/dist/api/runtime.cjs +23 -23
- package/dist/api/runtime.d.mts +2 -2
- package/dist/api/runtime.d.ts +2 -2
- package/dist/api/runtime.mjs +22 -22
- package/dist/api.cjs +52 -52
- package/dist/api.d.mts +3 -3
- package/dist/api.d.ts +3 -3
- package/dist/api.mjs +51 -51
- package/dist/app-DytgRPjJ.d.mts +562 -0
- package/dist/app-VK9sHDn5.d.ts +562 -0
- package/dist/app-manifest-BUu7YGAx.d.ts +120 -0
- package/dist/app-manifest-DPgW5ke5.d.mts +120 -0
- package/dist/app-markdown.cjs +14 -15
- package/dist/app-markdown.d.mts +2 -2
- package/dist/app-markdown.d.ts +2 -2
- package/dist/app-markdown.mjs +13 -14
- package/dist/cache.cjs +8 -8
- package/dist/cache.mjs +7 -7
- package/dist/chunk-22W4FNTG.mjs +538 -0
- package/dist/chunk-23LVFSID.mjs +182 -0
- package/dist/chunk-2DA7CLY7.mjs +560 -0
- package/dist/chunk-2DLGV2ZG.mjs +71 -0
- package/dist/chunk-2H3FJYY6.mjs +78 -0
- package/dist/chunk-2HW5LWAH.cjs +19 -0
- package/dist/chunk-2KMIJDY6.cjs +20 -0
- package/dist/chunk-2NGZFOKG.mjs +190 -0
- package/dist/chunk-2NHOYYUT.mjs +2250 -0
- package/dist/chunk-2SVJGOAX.mjs +206 -0
- package/dist/chunk-2WZTGPK6.mjs +65 -0
- package/dist/chunk-2XGBJSDV.cjs +408 -0
- package/dist/chunk-3BIASUGR.cjs +59 -0
- package/dist/chunk-3EEET2Q5.cjs +1044 -0
- package/dist/chunk-3EIPOTZV.cjs +272 -0
- package/dist/chunk-3HBFI373.cjs +227 -0
- package/dist/chunk-45EUIICW.mjs +15 -0
- package/dist/chunk-46P5KNTE.mjs +8 -0
- package/dist/chunk-47JV57DA.cjs +69 -0
- package/dist/chunk-4DCWVSL2.cjs +15 -0
- package/dist/chunk-4HBKBHVP.mjs +36 -0
- package/dist/chunk-4IICUBQX.cjs +657 -0
- package/dist/chunk-4MU4QCX4.mjs +158 -0
- package/dist/chunk-4S7M63WX.cjs +91 -0
- package/dist/chunk-4ZJ5C7UJ.cjs +75 -0
- package/dist/chunk-52Y3C3HG.mjs +421 -0
- package/dist/chunk-53EHWHT2.cjs +166 -0
- package/dist/chunk-5566GNEG.cjs +410 -0
- package/dist/chunk-5C7XMKQ4.cjs +410 -0
- package/dist/chunk-5DX3O6TT.cjs +266 -0
- package/dist/chunk-5J45H65F.mjs +48 -0
- package/dist/chunk-5OJVKXFV.cjs +2072 -0
- package/dist/chunk-5PKDHKQP.cjs +81 -0
- package/dist/chunk-5PZJ63PK.mjs +17 -0
- package/dist/chunk-5Y2P454O.cjs +421 -0
- package/dist/chunk-5Y4GYKKH.mjs +13 -0
- package/dist/chunk-5YPBFMBN.cjs +19 -0
- package/dist/chunk-6BLAY2VQ.mjs +45 -0
- package/dist/chunk-6CTFVBAT.cjs +29 -0
- package/dist/chunk-6FXBJPF5.cjs +35 -0
- package/dist/chunk-6HRAK7I5.mjs +215 -0
- package/dist/chunk-6IOZPJ3I.cjs +549 -0
- package/dist/chunk-6JHZPB52.cjs +538 -0
- package/dist/chunk-6LH33DLL.cjs +34 -0
- package/dist/chunk-6M3HXUBQ.mjs +135 -0
- package/dist/chunk-6ONBZGVH.cjs +124 -0
- package/dist/chunk-6XFGJBYX.cjs +78 -0
- package/dist/chunk-6XQSPIN6.cjs +155 -0
- package/dist/chunk-6YFC3ZFX.mjs +449 -0
- package/dist/chunk-6ZFRWRHO.mjs +54 -0
- package/dist/chunk-72D2NX77.mjs +293 -0
- package/dist/chunk-72KABRWN.mjs +2072 -0
- package/dist/chunk-72KCTHLV.cjs +723 -0
- package/dist/chunk-73XBJRZW.cjs +462 -0
- package/dist/chunk-75XSZIRE.mjs +180 -0
- package/dist/chunk-7EPYN7GW.cjs +30 -0
- package/dist/chunk-7H4SVNC4.cjs +700 -0
- package/dist/chunk-7JUIK547.cjs +62 -0
- package/dist/chunk-7KJJ4SBS.cjs +13 -0
- package/dist/chunk-7PTISZSQ.cjs +176 -0
- package/dist/chunk-7S7AAK2D.mjs +82 -0
- package/dist/chunk-A25FXJ7D.cjs +38 -0
- package/dist/chunk-A4PWGL46.mjs +141 -0
- package/dist/chunk-A7DK663W.cjs +577 -0
- package/dist/chunk-ALD2WMLA.mjs +387 -0
- package/dist/chunk-AOKXITZ6.cjs +16 -0
- package/dist/chunk-ATHPRVP2.mjs +651 -0
- package/dist/chunk-ATYTLVSI.cjs +45 -0
- package/dist/chunk-AXRNEVCS.cjs +150 -0
- package/dist/chunk-AY2YD5ZX.mjs +34 -0
- package/dist/chunk-AYP2YFVN.mjs +168 -0
- package/dist/chunk-AZQXXXDX.mjs +80 -0
- package/dist/chunk-B5BBTPJQ.cjs +44 -0
- package/dist/chunk-BBPDJGCU.cjs +157 -0
- package/dist/chunk-BEXYFR2R.cjs +527 -0
- package/dist/chunk-BLD5GVCG.mjs +152 -0
- package/dist/chunk-BMQAPZXD.mjs +31 -0
- package/dist/chunk-BNH53KOT.cjs +69 -0
- package/dist/chunk-BNMHXVLL.mjs +239 -0
- package/dist/chunk-BOVGCUDZ.cjs +35 -0
- package/dist/chunk-BPAXGCKX.mjs +166 -0
- package/dist/chunk-BPNOYILC.cjs +450 -0
- package/dist/chunk-BR5FSKZ5.cjs +1457 -0
- package/dist/chunk-BRWIVOV4.cjs +48 -0
- package/dist/chunk-BTZ5O6VM.cjs +14 -0
- package/dist/chunk-BUC3FDYC.cjs +158 -0
- package/dist/chunk-C2R5RVLA.cjs +800 -0
- package/dist/chunk-C5JXCUKR.mjs +905 -0
- package/dist/chunk-C64XOPBZ.mjs +380 -0
- package/dist/chunk-C6U66WWF.mjs +410 -0
- package/dist/chunk-C7425KDG.cjs +406 -0
- package/dist/chunk-C7LCTVJ2.cjs +30 -0
- package/dist/chunk-CA7DNRHO.cjs +164 -0
- package/dist/chunk-CBJKDB6F.mjs +80 -0
- package/dist/chunk-CDTIXBKN.mjs +40 -0
- package/dist/chunk-CL2ONP73.cjs +180 -0
- package/dist/chunk-CQL5ZGFU.cjs +50 -0
- package/dist/chunk-CSLUBKGG.mjs +44 -0
- package/dist/chunk-CU5SYTJG.mjs +23 -0
- package/dist/chunk-CV6MFQ4Y.mjs +259 -0
- package/dist/chunk-D22BUQKW.cjs +82 -0
- package/dist/chunk-D2LCAV6L.mjs +79 -0
- package/dist/chunk-D4XGKF67.cjs +127 -0
- package/dist/chunk-D7Y63SOY.mjs +15 -0
- package/dist/chunk-DM3TFCC2.cjs +697 -0
- package/dist/chunk-DMAP4RND.cjs +998 -0
- package/dist/chunk-DQJ2CIH7.cjs +87 -0
- package/dist/chunk-DRFADSKY.mjs +697 -0
- package/dist/chunk-DU4VHHPJ.mjs +157 -0
- package/dist/chunk-DUIP64BF.cjs +16 -0
- package/dist/chunk-DV52ZS53.cjs +40 -0
- package/dist/chunk-DXUXQP2T.cjs +142 -0
- package/dist/chunk-E552H232.cjs +154 -0
- package/dist/chunk-E7QOEV5Z.cjs +449 -0
- package/dist/chunk-EA5PMJDU.mjs +527 -0
- package/dist/chunk-EDPENAVO.mjs +266 -0
- package/dist/chunk-EFLNOZGH.mjs +30 -0
- package/dist/chunk-EGHPFXPZ.cjs +590 -0
- package/dist/chunk-EJCVG25Z.mjs +49 -0
- package/dist/chunk-EMDGXYUD.mjs +75 -0
- package/dist/chunk-EOXPRC2C.cjs +48 -0
- package/dist/chunk-EQMTJBB7.cjs +161 -0
- package/dist/chunk-ERMUL73L.cjs +39 -0
- package/dist/chunk-ES2LD2YD.mjs +203 -0
- package/dist/chunk-ETF5C6HR.cjs +135 -0
- package/dist/chunk-EV4SBMPX.mjs +208 -0
- package/dist/chunk-EVCQX243.cjs +1923 -0
- package/dist/chunk-EVIWKPJV.cjs +560 -0
- package/dist/chunk-EVMXPJCB.mjs +133 -0
- package/dist/chunk-EXHEPWFJ.cjs +387 -0
- package/dist/chunk-EZTKXD6P.cjs +182 -0
- package/dist/chunk-F3N52U7S.mjs +138 -0
- package/dist/chunk-F6TLUMH7.mjs +172 -0
- package/dist/chunk-FBEBSAVI.cjs +225 -0
- package/dist/chunk-FEFCISOX.cjs +102 -0
- package/dist/chunk-FGJQS4EC.cjs +385 -0
- package/dist/chunk-FHURJABM.mjs +45 -0
- package/dist/chunk-GBMWLDCC.cjs +138 -0
- package/dist/chunk-GBPDSUFE.mjs +203 -0
- package/dist/chunk-GERUXONA.cjs +775 -0
- package/dist/chunk-GHNW564E.mjs +1044 -0
- package/dist/chunk-GL3ZDHKI.mjs +274 -0
- package/dist/chunk-GLOICKDO.mjs +142 -0
- package/dist/chunk-GSVJ3IIF.cjs +173 -0
- package/dist/chunk-GUZC226X.mjs +164 -0
- package/dist/chunk-GW4YUIHW.mjs +277 -0
- package/dist/chunk-GWXZS7K5.mjs +24 -0
- package/dist/chunk-GXSMF7UR.mjs +1923 -0
- package/dist/chunk-GYMGK467.mjs +214 -0
- package/dist/chunk-H227LYHT.mjs +88 -0
- package/dist/chunk-H4WUWLQR.mjs +16 -0
- package/dist/chunk-HA7YRO53.cjs +214 -0
- package/dist/chunk-HAH4FBTA.mjs +227 -0
- package/dist/chunk-HELQXYVI.cjs +1093 -0
- package/dist/chunk-HEPJIKKQ.cjs +190 -0
- package/dist/chunk-HIFIG6HL.cjs +341 -0
- package/dist/chunk-HLYRXN2I.cjs +242 -0
- package/dist/chunk-HNAISJFD.cjs +215 -0
- package/dist/chunk-HNAUK3SC.mjs +1181 -0
- package/dist/chunk-HPP2II4Z.mjs +332 -0
- package/dist/chunk-HRLYO2XJ.mjs +9 -0
- package/dist/chunk-HUL4LTC6.cjs +390 -0
- package/dist/chunk-HXNLKCWH.cjs +13 -0
- package/dist/chunk-HZOMT5DY.mjs +30 -0
- package/dist/chunk-I2BYNELA.cjs +380 -0
- package/dist/chunk-I2SWKWO7.mjs +453 -0
- package/dist/chunk-IAPTECEB.mjs +48 -0
- package/dist/chunk-IFTGERT3.mjs +408 -0
- package/dist/chunk-IGL6CO6M.mjs +9 -0
- package/dist/chunk-ITV4QQL2.cjs +93 -0
- package/dist/chunk-IUQLRTTO.mjs +159 -0
- package/dist/chunk-IWFV5ZED.cjs +152 -0
- package/dist/chunk-IXSMFKZ2.cjs +100 -0
- package/dist/chunk-IYEY3JWJ.mjs +186 -0
- package/dist/chunk-J2ZEVDEK.cjs +80 -0
- package/dist/chunk-J37KTQIA.cjs +905 -0
- package/dist/chunk-JATTVAHA.cjs +277 -0
- package/dist/chunk-JGAE5XPL.cjs +26 -0
- package/dist/chunk-JHXJBNLY.cjs +22 -0
- package/dist/chunk-JLS6ZLFM.cjs +9 -0
- package/dist/chunk-JMYXO572.cjs +531 -0
- package/dist/chunk-JNYFXL7X.mjs +62 -0
- package/dist/chunk-JOHXK4BB.mjs +385 -0
- package/dist/chunk-JPAVNDZH.cjs +712 -0
- package/dist/chunk-JRHGJVJH.mjs +44 -0
- package/dist/chunk-JUMPFVMK.mjs +78 -0
- package/dist/chunk-JWP56HCP.mjs +712 -0
- package/dist/chunk-JXIYH2NO.cjs +24 -0
- package/dist/chunk-JYT7AN37.cjs +79 -0
- package/dist/chunk-JZMZKABS.cjs +78 -0
- package/dist/chunk-K5EW7GUU.mjs +417 -0
- package/dist/chunk-K76CBYQM.mjs +157 -0
- package/dist/chunk-KBGZ5FD6.cjs +17 -0
- package/dist/chunk-KBRZAYI7.mjs +593 -0
- package/dist/chunk-KJMWAUKE.mjs +124 -0
- package/dist/chunk-KORZ6PRE.cjs +64 -0
- package/dist/chunk-KPAJWD3N.mjs +168 -0
- package/dist/chunk-KQH2COEJ.mjs +42 -0
- package/dist/chunk-KRRZJ77U.mjs +169 -0
- package/dist/chunk-KZT2VHRQ.cjs +894 -0
- package/dist/chunk-L5JDKFMQ.cjs +44 -0
- package/dist/chunk-L6QDME5Z.cjs +36 -0
- package/dist/chunk-LAZK6UV7.mjs +341 -0
- package/dist/chunk-LL7TDMOM.mjs +222 -0
- package/dist/chunk-LM2YOGDK.mjs +44 -0
- package/dist/chunk-LM55GS4R.mjs +38 -0
- package/dist/chunk-LNVGXUL3.cjs +172 -0
- package/dist/chunk-LSHX2H5G.cjs +57 -0
- package/dist/chunk-LZBM35DH.mjs +577 -0
- package/dist/chunk-M25IONJP.mjs +16 -0
- package/dist/chunk-MF3IA2AW.cjs +25 -0
- package/dist/chunk-MFQGU5CC.mjs +127 -0
- package/dist/chunk-MJ6IC4K2.mjs +34 -0
- package/dist/chunk-MNIR7I7B.mjs +217 -0
- package/dist/chunk-MPU5DOXX.cjs +21 -0
- package/dist/chunk-MTB57GOK.mjs +81 -0
- package/dist/chunk-MU5V7XHL.mjs +172 -0
- package/dist/chunk-MZZA6ZQV.mjs +113 -0
- package/dist/chunk-N25RPPO5.cjs +1963 -0
- package/dist/chunk-N33DLJBC.mjs +272 -0
- package/dist/chunk-N35YPV4N.mjs +48 -0
- package/dist/chunk-N6SIQJEJ.mjs +390 -0
- package/dist/chunk-N77JBPLC.mjs +1357 -0
- package/dist/chunk-N7SPZJLY.mjs +6166 -0
- package/dist/chunk-N7XWC6BN.mjs +21 -0
- package/dist/chunk-NBIVGHAT.mjs +50 -0
- package/dist/chunk-NCIAP562.mjs +27 -0
- package/dist/chunk-NE33FRQ5.mjs +11944 -0
- package/dist/chunk-NG44F7AH.mjs +150 -0
- package/dist/chunk-NIPKC4DA.mjs +800 -0
- package/dist/chunk-NJLTQR5P.cjs +293 -0
- package/dist/chunk-NR63PD3P.mjs +64 -0
- package/dist/chunk-NRFUVDTH.mjs +489 -0
- package/dist/chunk-NRNAHZ57.mjs +39 -0
- package/dist/chunk-NW2BKDVT.mjs +1963 -0
- package/dist/chunk-NYQSC4DX.cjs +593 -0
- package/dist/chunk-O4F3JUST.mjs +176 -0
- package/dist/chunk-OAJOQU5J.mjs +225 -0
- package/dist/chunk-OCS3PSYR.cjs +51 -0
- package/dist/chunk-OHWM2VI4.mjs +29 -0
- package/dist/chunk-OJO2GOM3.mjs +69 -0
- package/dist/chunk-OLGQZRW6.mjs +700 -0
- package/dist/chunk-ONG4RDW3.mjs +155 -0
- package/dist/chunk-OOJBBHYW.cjs +38 -0
- package/dist/chunk-OOZEU5KK.cjs +18 -0
- package/dist/chunk-OWQV6MLM.cjs +82 -0
- package/dist/chunk-OYZXVBZP.cjs +133 -0
- package/dist/chunk-OZC2JPW6.cjs +10 -0
- package/dist/chunk-P2355C6E.cjs +186 -0
- package/dist/chunk-PAKCHVUS.mjs +450 -0
- package/dist/chunk-PEHL3IZL.cjs +203 -0
- package/dist/chunk-PENBZAHJ.cjs +88 -0
- package/dist/chunk-PFV2KPDZ.cjs +172 -0
- package/dist/chunk-PO5MXV5X.cjs +13 -0
- package/dist/chunk-PSUYE5HR.mjs +25 -0
- package/dist/chunk-PTLXHRJZ.mjs +57 -0
- package/dist/chunk-PXEXOQ5R.mjs +135 -0
- package/dist/chunk-PZXYAWYG.cjs +274 -0
- package/dist/chunk-Q2ZKQ6GD.cjs +6166 -0
- package/dist/chunk-Q3UU2KXC.mjs +775 -0
- package/dist/chunk-Q5B4LNON.mjs +19 -0
- package/dist/chunk-QFQDRJKJ.mjs +666 -0
- package/dist/chunk-QGJ4FI2G.mjs +723 -0
- package/dist/chunk-QISW423S.cjs +335 -0
- package/dist/chunk-QNQEK3OF.cjs +666 -0
- package/dist/chunk-QPJ4MZTO.mjs +60 -0
- package/dist/chunk-QPNVDSFZ.mjs +18 -0
- package/dist/chunk-QQ44FYRO.cjs +27 -0
- package/dist/chunk-QSTRBKHZ.mjs +102 -0
- package/dist/chunk-R2SEZEBC.cjs +453 -0
- package/dist/chunk-R5U7OIPI.cjs +34 -0
- package/dist/chunk-R62SF5R4.mjs +410 -0
- package/dist/chunk-RD623KW4.cjs +203 -0
- package/dist/chunk-RFKTJTWZ.mjs +26 -0
- package/dist/chunk-RI3EVPKD.cjs +57 -0
- package/dist/chunk-RLEALQEN.mjs +998 -0
- package/dist/chunk-RVGLYMJM.cjs +259 -0
- package/dist/chunk-S32PDOLO.mjs +13 -0
- package/dist/chunk-S6O2L47H.mjs +549 -0
- package/dist/chunk-SBABQKPT.cjs +169 -0
- package/dist/chunk-SBDWCDS6.cjs +8 -0
- package/dist/chunk-SF3JB56B.mjs +82 -0
- package/dist/chunk-SG57PX7K.cjs +65 -0
- package/dist/chunk-SGBNF56S.cjs +44 -0
- package/dist/chunk-SHD265HW.cjs +19 -0
- package/dist/chunk-SHIWRBFI.cjs +17 -0
- package/dist/chunk-SM2SYWAR.cjs +49 -0
- package/dist/chunk-SNP33A33.cjs +9 -0
- package/dist/chunk-SSNN55Q6.cjs +651 -0
- package/dist/chunk-STF6VDYQ.cjs +23 -0
- package/dist/chunk-SVCUSOEF.mjs +590 -0
- package/dist/chunk-SXCL2MIN.cjs +208 -0
- package/dist/chunk-SYW346ZN.cjs +71 -0
- package/dist/chunk-TFA6BUAE.cjs +113 -0
- package/dist/chunk-TGSEVBPO.mjs +93 -0
- package/dist/chunk-TJVUTGED.mjs +531 -0
- package/dist/chunk-TQWGOQ7O.mjs +8606 -0
- package/dist/chunk-TTYXOAB7.mjs +657 -0
- package/dist/chunk-TUPKMMXT.mjs +173 -0
- package/dist/chunk-TVCFY3KK.cjs +217 -0
- package/dist/chunk-TXK4D46O.mjs +22 -0
- package/dist/chunk-UAQD67HM.mjs +154 -0
- package/dist/chunk-UCQ52TJY.mjs +406 -0
- package/dist/chunk-UIJOLBUL.mjs +19 -0
- package/dist/chunk-UPYIFH2H.cjs +168 -0
- package/dist/chunk-UUMKLGUU.mjs +69 -0
- package/dist/chunk-UYQOIPXE.mjs +368 -0
- package/dist/chunk-UYTAP4FQ.cjs +60 -0
- package/dist/chunk-UZCMMJJT.cjs +80 -0
- package/dist/chunk-V3UOEWCB.cjs +46 -0
- package/dist/chunk-V56632LA.cjs +141 -0
- package/dist/chunk-V7KTQR4C.cjs +15 -0
- package/dist/chunk-VCFBQFOV.mjs +1093 -0
- package/dist/chunk-VDLF2DJA.cjs +11947 -0
- package/dist/chunk-VE3FWJBO.mjs +46 -0
- package/dist/chunk-VFXE6NWR.mjs +87 -0
- package/dist/chunk-VHIXGZYH.mjs +9 -0
- package/dist/chunk-VISQDC6W.mjs +10 -0
- package/dist/chunk-VIXTAVEA.mjs +59 -0
- package/dist/chunk-VJXLUTBM.mjs +894 -0
- package/dist/chunk-VM57CK74.cjs +42 -0
- package/dist/chunk-VOQ7XZZT.cjs +157 -0
- package/dist/chunk-VR4SEDEM.mjs +1457 -0
- package/dist/chunk-VR6QLTTX.mjs +59 -0
- package/dist/chunk-VSLM6BHX.cjs +2250 -0
- package/dist/chunk-VU3MYZPO.mjs +432 -0
- package/dist/chunk-VXCFJWK5.cjs +59 -0
- package/dist/chunk-VZY7MAVS.cjs +432 -0
- package/dist/chunk-WB6XES4V.mjs +161 -0
- package/dist/chunk-WCLLPR6H.mjs +35 -0
- package/dist/chunk-WEGAVN37.cjs +45 -0
- package/dist/chunk-WJFFPXCV.cjs +1357 -0
- package/dist/chunk-WNDAISB7.mjs +51 -0
- package/dist/chunk-WNLPQW7W.mjs +19 -0
- package/dist/chunk-WQGRD5BJ.cjs +239 -0
- package/dist/chunk-WT6RAN2I.cjs +41 -0
- package/dist/chunk-WUEDTW6E.cjs +135 -0
- package/dist/chunk-WXFY5JIY.mjs +20 -0
- package/dist/chunk-WYL4ODZ4.mjs +38 -0
- package/dist/chunk-X333W5KV.cjs +31 -0
- package/dist/chunk-X3XUZWRB.mjs +141 -0
- package/dist/chunk-XGJVRPYL.cjs +141 -0
- package/dist/chunk-XLLVWLWO.mjs +100 -0
- package/dist/chunk-XLYXG73A.mjs +87 -0
- package/dist/chunk-XN2MB4QZ.cjs +206 -0
- package/dist/chunk-XO6WL6NL.mjs +462 -0
- package/dist/chunk-XQ4DPO4G.mjs +13 -0
- package/dist/chunk-XQSYOVCW.cjs +417 -0
- package/dist/chunk-XR2ZIBQK.mjs +57 -0
- package/dist/chunk-XURDCXNH.cjs +48 -0
- package/dist/chunk-XXB37YET.cjs +40 -0
- package/dist/chunk-Y3WG64CP.cjs +9 -0
- package/dist/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/chunk-Y7NN63LS.mjs +40 -0
- package/dist/chunk-YDXLC4DW.cjs +54 -0
- package/dist/chunk-YP7YO3S3.mjs +17 -0
- package/dist/chunk-YQGZLCT4.cjs +368 -0
- package/dist/chunk-YSPMY4B7.cjs +8609 -0
- package/dist/chunk-YT3SLLZK.mjs +242 -0
- package/dist/chunk-YTVSWXEZ.cjs +168 -0
- package/dist/chunk-YVJV7Q2X.mjs +35 -0
- package/dist/chunk-YWPNIYUP.mjs +41 -0
- package/dist/chunk-YX6AFPXC.mjs +8 -0
- package/dist/chunk-Z5MZDFX4.cjs +159 -0
- package/dist/chunk-ZBS3GOQZ.cjs +222 -0
- package/dist/chunk-ZGS3ZDF7.cjs +489 -0
- package/dist/chunk-ZSIGEHSE.cjs +1181 -0
- package/dist/chunk-ZXK2EYQW.cjs +8 -0
- package/dist/client/lifecycle.cjs +3 -3
- package/dist/client/lifecycle.mjs +2 -2
- package/dist/client-plugins-BlEzV5FO.d.mts +3920 -0
- package/dist/client-plugins-DqjCsKMN.d.ts +3920 -0
- package/dist/client-plugins.cjs +3 -3
- package/dist/client-plugins.d.mts +1 -1
- package/dist/client-plugins.d.ts +1 -1
- package/dist/client-plugins.mjs +2 -2
- package/dist/client.cjs +41 -41
- package/dist/client.d.mts +5 -5
- package/dist/client.d.ts +5 -5
- package/dist/client.mjs +42 -42
- package/dist/config.cjs +3 -3
- package/dist/config.d.mts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.mjs +2 -2
- package/dist/cron.cjs +9 -9
- package/dist/cron.mjs +8 -8
- package/dist/deferred.cjs +3 -3
- package/dist/deferred.mjs +2 -2
- package/dist/deployment.cjs +3 -3
- package/dist/deployment.mjs +2 -2
- package/dist/desktop.cjs +13 -0
- package/dist/desktop.d.mts +120 -0
- package/dist/desktop.d.ts +120 -0
- package/dist/desktop.mjs +13 -0
- package/dist/dev-guard-4NQ3LFO5.cjs +57 -0
- package/dist/dev-guard-MPZUJFIV.mjs +57 -0
- package/dist/devtools-A37WWJZL.cjs +463 -0
- package/dist/devtools-BLKHPY3C.mjs +463 -0
- package/dist/devtools-client-SU4XH46J.mjs +250 -0
- package/dist/devtools-client-X5OQCXDF.cjs +250 -0
- package/dist/devtools-ui-CYBVFLPH.mjs +1265 -0
- package/dist/devtools-ui-SYRUXUA7.cjs +1265 -0
- package/dist/docs.cjs +64 -64
- package/dist/docs.d.mts +2 -2
- package/dist/docs.d.ts +2 -2
- package/dist/docs.mjs +63 -63
- package/dist/env-types.cjs +4 -4
- package/dist/env-types.mjs +3 -3
- package/dist/env.cjs +4 -4
- package/dist/env.mjs +3 -3
- package/dist/environment/vite.cjs +7 -7
- package/dist/environment/vite.mjs +6 -6
- package/dist/environment.cjs +3 -3
- package/dist/environment.mjs +2 -2
- package/dist/font.cjs +3 -3
- package/dist/font.mjs +2 -2
- package/dist/headers.cjs +6 -6
- package/dist/headers.mjs +5 -5
- package/dist/i18n/client.cjs +19 -30
- package/dist/i18n/client.mjs +9 -20
- package/dist/i18n/index.cjs +6 -6
- package/dist/i18n/index.mjs +5 -5
- package/dist/i18n/server.cjs +10 -10
- package/dist/i18n/server.mjs +9 -9
- package/dist/image/server.cjs +6 -6
- package/dist/image/server.mjs +5 -5
- package/dist/image/sharp.cjs +15 -21
- package/dist/image/sharp.mjs +7 -13
- package/dist/image.cjs +9 -18
- package/dist/image.mjs +4 -13
- package/dist/index-CMigAr9f.d.mts +54 -0
- package/dist/index-n3hjOvVC.d.ts +54 -0
- package/dist/index.cjs +187 -196
- package/dist/index.d.mts +15 -15
- package/dist/index.d.ts +15 -15
- package/dist/index.mjs +217 -226
- package/dist/instrumentation.cjs +5 -5
- package/dist/instrumentation.mjs +4 -4
- package/dist/integration-orm-52GPGTHO.cjs +14 -0
- package/dist/integration-orm-CO23MSFE.mjs +14 -0
- package/dist/integrations.cjs +20 -20
- package/dist/integrations.d.mts +1 -1
- package/dist/integrations.d.ts +1 -1
- package/dist/integrations.mjs +19 -19
- package/dist/internal/app-markdown-runtime.cjs +12 -13
- package/dist/internal/app-markdown-runtime.d.mts +2 -2
- package/dist/internal/app-markdown-runtime.d.ts +2 -2
- package/dist/internal/app-markdown-runtime.mjs +11 -12
- package/dist/internal/build-runtime.cjs +152 -149
- package/dist/internal/build-runtime.d.mts +3 -3
- package/dist/internal/build-runtime.d.ts +3 -3
- package/dist/internal/build-runtime.mjs +135 -132
- package/dist/internal/cli-runtime.cjs +88 -88
- package/dist/internal/cli-runtime.mjs +87 -87
- package/dist/internal/client-error-overlay.cjs +18 -49
- package/dist/internal/client-error-overlay.mjs +14 -45
- package/dist/internal/client-runtime.cjs +39 -53
- package/dist/internal/client-runtime.mjs +36 -50
- package/dist/internal/compression-runtime.cjs +4 -4
- package/dist/internal/compression-runtime.d.mts +1 -1
- package/dist/internal/compression-runtime.d.ts +1 -1
- package/dist/internal/compression-runtime.mjs +3 -3
- package/dist/internal/config-runtime.cjs +85 -69
- package/dist/internal/config-runtime.d.mts +2 -2
- package/dist/internal/config-runtime.d.ts +2 -2
- package/dist/internal/config-runtime.mjs +73 -57
- package/dist/internal/desktop-guard.cjs +17 -0
- package/dist/internal/desktop-guard.d.mts +45 -0
- package/dist/internal/desktop-guard.d.ts +45 -0
- package/dist/internal/desktop-guard.mjs +17 -0
- package/dist/internal/docs-precompiled-runtime.cjs +5 -17
- package/dist/internal/docs-precompiled-runtime.mjs +4 -16
- package/dist/internal/form-actions-client.cjs +1 -5
- package/dist/internal/form-actions-client.mjs +1 -5
- package/dist/internal/form-actions.cjs +10 -10
- package/dist/internal/form-actions.mjs +9 -9
- package/dist/internal/infra-analytics-runtime.cjs +22 -8
- package/dist/internal/infra-analytics-runtime.mjs +20 -6
- package/dist/internal/island-codec.cjs +4 -4
- package/dist/internal/island-codec.mjs +3 -3
- package/dist/internal/island-value-store.cjs +1 -4
- package/dist/internal/island-value-store.mjs +1 -4
- package/dist/internal/islands-runtime.cjs +46 -21
- package/dist/internal/islands-runtime.d.mts +31 -19
- package/dist/internal/islands-runtime.d.ts +31 -19
- package/dist/internal/islands-runtime.mjs +41 -16
- package/dist/internal/islands-server.cjs +6 -9
- package/dist/internal/islands-server.mjs +5 -8
- package/dist/internal/islx-client.cjs +1 -1
- package/dist/internal/islx-react.cjs +1 -1
- package/dist/internal/islx-server.cjs +1 -1
- package/dist/internal/isolated-boundary.cjs +5 -5
- package/dist/internal/isolated-boundary.mjs +4 -4
- package/dist/internal/metadata-image-runtime.cjs +8 -8
- package/dist/internal/metadata-image-runtime.d.mts +6 -1
- package/dist/internal/metadata-image-runtime.d.ts +6 -1
- package/dist/internal/metadata-image-runtime.mjs +7 -7
- package/dist/internal/product-telemetry-runtime.cjs +5 -17
- package/dist/internal/product-telemetry-runtime.mjs +3 -15
- package/dist/internal/production-node-env.cjs +3 -3
- package/dist/internal/production-node-env.mjs +2 -2
- package/dist/internal/production-runtime.cjs +102 -103
- package/dist/internal/production-runtime.d.mts +42 -11
- package/dist/internal/production-runtime.d.ts +42 -11
- package/dist/internal/production-runtime.mjs +114 -115
- package/dist/internal/request-cookies.cjs +3 -3
- package/dist/internal/request-cookies.mjs +2 -2
- package/dist/internal/server-tree.cjs +5 -5
- package/dist/internal/server-tree.mjs +4 -4
- package/dist/json-ld.cjs +3 -16
- package/dist/json-ld.mjs +3 -16
- package/dist/layers-DMRXRL7F.cjs +18 -0
- package/dist/layers-T55SA47E.mjs +18 -0
- package/dist/manager-2LUKNX2N.cjs +14 -0
- package/dist/manager-H5ZM3HAM.mjs +14 -0
- package/dist/markdown.cjs +11 -12
- package/dist/markdown.d.mts +1 -1
- package/dist/markdown.d.ts +1 -1
- package/dist/markdown.mjs +10 -11
- package/dist/middleware.cjs +31 -31
- package/dist/middleware.d.mts +3 -3
- package/dist/middleware.d.ts +3 -3
- package/dist/middleware.mjs +30 -30
- package/dist/navigation.cjs +22 -22
- package/dist/navigation.d.mts +4 -4
- package/dist/navigation.d.ts +4 -4
- package/dist/navigation.mjs +21 -21
- package/dist/nitro-BIXIKJZS.cjs +650 -0
- package/dist/nitro-UT2J5A5D.mjs +650 -0
- package/dist/node-module-bundle-7JHPPF6B.mjs +11 -0
- package/dist/node-module-bundle-YJGYBOGK.cjs +11 -0
- package/dist/observability.cjs +3 -3
- package/dist/observability.mjs +2 -2
- package/dist/og.cjs +1 -1
- package/dist/og.mjs +1 -1
- package/dist/platform.cjs +28 -0
- package/dist/platform.d.mts +23 -0
- package/dist/platform.d.ts +23 -0
- package/dist/platform.mjs +28 -0
- package/dist/plugin-4KYXV7BB.mjs +32 -0
- package/dist/plugin-WBANOZQM.cjs +32 -0
- package/dist/plugin.cjs +147 -144
- package/dist/plugin.d.mts +3 -3
- package/dist/plugin.d.ts +3 -3
- package/dist/plugin.mjs +127 -124
- package/dist/production-runtime-YVDGYWBG.d.ts +123 -0
- package/dist/production-runtime-bWZJMcQb.d.mts +123 -0
- package/dist/programmatic-routes-client-BFKOTEXN.d.mts +184 -0
- package/dist/programmatic-routes-client-DviwGeAv.d.ts +184 -0
- package/dist/query/client.cjs +59 -70
- package/dist/query/client.mjs +49 -60
- package/dist/query/index.cjs +4 -4
- package/dist/query/index.mjs +3 -3
- package/dist/query/parsers.cjs +3 -3
- package/dist/query/parsers.mjs +2 -2
- package/dist/query/server.cjs +5 -11
- package/dist/query/server.mjs +3 -9
- package/dist/render-plan-CS8l0zaK.d.mts +25 -0
- package/dist/render-plan-DqWXo3-B.d.ts +25 -0
- package/dist/renderer/react/client.cjs +1 -1
- package/dist/renderer/react/client.mjs +1 -1
- package/dist/renderer/react/server.cjs +10 -15
- package/dist/renderer/react/server.mjs +10 -15
- package/dist/renderer/react/vite.cjs +1 -4
- package/dist/renderer/react/vite.mjs +1 -4
- package/dist/renderer-client.cjs +67 -79
- package/dist/renderer-client.d.mts +3 -3
- package/dist/renderer-client.d.ts +3 -3
- package/dist/renderer-client.mjs +44 -56
- package/dist/renderer.cjs +3 -3
- package/dist/renderer.mjs +2 -2
- package/dist/request-CBrHpaCC.d.ts +24 -0
- package/dist/request-D4XqmnJF.d.mts +24 -0
- package/dist/request.cjs +4 -4
- package/dist/request.d.mts +2 -2
- package/dist/request.d.ts +2 -2
- package/dist/request.mjs +3 -3
- package/dist/route-rendering-3pRPtyO2.d.mts +44 -0
- package/dist/route-rendering-Bltnu8a3.d.ts +44 -0
- package/dist/router-BFSmKGtI.d.mts +50 -0
- package/dist/router-DDT7bkg7.d.ts +50 -0
- package/dist/router.cjs +5 -5
- package/dist/router.mjs +4 -4
- package/dist/routes.cjs +13 -13
- package/dist/routes.d.mts +1 -1
- package/dist/routes.d.ts +1 -1
- package/dist/routes.mjs +12 -12
- package/dist/rsc-pipeline-4KOITP64.cjs +80 -0
- package/dist/rsc-pipeline-ULFIB3UT.mjs +80 -0
- package/dist/runtime-C6yG64je.d.ts +69 -0
- package/dist/runtime-Cpylaypt.d.mts +69 -0
- package/dist/schema-dev-notice-O3I5HLXK.mjs +54 -0
- package/dist/schema-dev-notice-Z73J3NJ6.cjs +54 -0
- package/dist/schema.cjs +3 -3
- package/dist/schema.mjs +2 -2
- package/dist/search-client-BTXL5XWD.mjs +13 -0
- package/dist/search-client-QCYAL6AY.cjs +13 -0
- package/dist/server-action-security.cjs +8 -8
- package/dist/server-action-security.mjs +7 -7
- package/dist/server-fn-client.cjs +4 -4
- package/dist/server-fn-client.mjs +3 -3
- package/dist/server-fn.cjs +15 -15
- package/dist/server-fn.mjs +14 -14
- package/dist/server-plugins.cjs +15 -15
- package/dist/server-plugins.d.mts +2 -2
- package/dist/server-plugins.d.ts +2 -2
- package/dist/server-plugins.mjs +14 -14
- package/dist/server-query-client.cjs +8 -8
- package/dist/server-query-client.mjs +7 -7
- package/dist/server-query.cjs +17 -17
- package/dist/server-query.mjs +16 -16
- package/dist/server.cjs +215 -219
- package/dist/server.d.mts +9 -9
- package/dist/server.d.ts +9 -9
- package/dist/server.mjs +178 -182
- package/dist/spa-router-CKuS81mi.d.ts +239 -0
- package/dist/spa-router-CkTPnA4L.d.mts +239 -0
- package/dist/storage.cjs +3 -3
- package/dist/storage.mjs +2 -2
- package/dist/testing.cjs +57 -77
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.mjs +46 -66
- package/dist/theme/client.cjs +5 -5
- package/dist/theme/client.mjs +4 -4
- package/dist/theme/index.cjs +3 -3
- package/dist/theme/index.mjs +2 -2
- package/dist/theme/runtime.cjs +3 -3
- package/dist/theme/runtime.mjs +2 -2
- package/dist/theme/server.cjs +8 -8
- package/dist/theme/server.mjs +7 -7
- package/dist/utils-C0ORLYXc.d.ts +48 -0
- package/dist/utils-IA9wVkef.d.mts +48 -0
- package/dist/version.cjs +3 -3
- package/dist/version.mjs +2 -2
- package/dist/vite.cjs +152 -149
- package/dist/vite.d.mts +4 -4
- package/dist/vite.d.ts +4 -4
- package/dist/vite.mjs +127 -124
- package/dist/workflows.cjs +14 -14
- package/dist/workflows.mjs +13 -13
- package/package.json +26 -2
- package/dist/agent-mcp-BtK_KZ1m.d.ts +0 -115
- package/dist/agent-mcp-Cc-ypyNi.d.mts +0 -115
- package/dist/agent-mcp-handler-HVV5LNXF.mjs +0 -19
- package/dist/agent-mcp-handler-YKG7KVCY.cjs +0 -19
- package/dist/app-2SBLAaNq.d.mts +0 -554
- package/dist/app-BlXGEpdA.d.ts +0 -554
- package/dist/app-manifest-D1Tgp8ya.d.ts +0 -120
- package/dist/app-manifest-nZHIvS3a.d.mts +0 -120
- package/dist/chunk-25LPIZSX.cjs +0 -576
- package/dist/chunk-26CXZR6L.mjs +0 -1242
- package/dist/chunk-26RUNDIR.mjs +0 -2355
- package/dist/chunk-2A3EQHXX.mjs +0 -173
- package/dist/chunk-2CQ74SP6.cjs +0 -13
- package/dist/chunk-2FUIT2G2.cjs +0 -85
- package/dist/chunk-2GVF3C2F.cjs +0 -616
- package/dist/chunk-2J7W2WND.mjs +0 -149
- package/dist/chunk-2NXO5SBY.mjs +0 -57
- package/dist/chunk-2PQNJXFM.mjs +0 -20
- package/dist/chunk-2SJ4RQ6P.cjs +0 -57
- package/dist/chunk-2UC36WAC.mjs +0 -22
- package/dist/chunk-2VQKKQ6D.mjs +0 -51
- package/dist/chunk-2Y3JRYVG.mjs +0 -71
- package/dist/chunk-37VKVISD.mjs +0 -2042
- package/dist/chunk-3BROEWFY.cjs +0 -39
- package/dist/chunk-3SAWHWDH.cjs +0 -186
- package/dist/chunk-3XEMGDBF.cjs +0 -1242
- package/dist/chunk-44SYJEG3.mjs +0 -13
- package/dist/chunk-45QJHGZM.cjs +0 -1063
- package/dist/chunk-45ZSJLDT.mjs +0 -183
- package/dist/chunk-4GP3XZ4Z.mjs +0 -595
- package/dist/chunk-4GRLJURM.mjs +0 -1210
- package/dist/chunk-4JCQDWPX.mjs +0 -24
- package/dist/chunk-4KQDHTWX.mjs +0 -487
- package/dist/chunk-4OOBRCJX.mjs +0 -300
- package/dist/chunk-4PPEPOZZ.cjs +0 -21
- package/dist/chunk-4RB44K6Z.mjs +0 -94
- package/dist/chunk-4SIYUGRY.mjs +0 -93
- package/dist/chunk-4TLUFAIP.cjs +0 -92
- package/dist/chunk-4U5XZDLG.cjs +0 -80
- package/dist/chunk-4ZZNPK25.mjs +0 -178
- package/dist/chunk-53ZV6K65.mjs +0 -241
- package/dist/chunk-54UPOYFS.mjs +0 -35
- package/dist/chunk-55YI3RRB.mjs +0 -192
- package/dist/chunk-5LPHJZSI.cjs +0 -241
- package/dist/chunk-5NAVKJCZ.cjs +0 -435
- package/dist/chunk-5NIWBWDD.mjs +0 -97
- package/dist/chunk-5QIKR7RR.cjs +0 -224
- package/dist/chunk-5WI2S4CO.mjs +0 -20
- package/dist/chunk-63H6BKXG.cjs +0 -389
- package/dist/chunk-64SBBZDU.cjs +0 -102
- package/dist/chunk-666CKENS.mjs +0 -49
- package/dist/chunk-6BWKJ6QS.cjs +0 -43
- package/dist/chunk-6D24SDKO.cjs +0 -145
- package/dist/chunk-6EODJYCX.cjs +0 -183
- package/dist/chunk-6EXBPJ24.cjs +0 -434
- package/dist/chunk-6IZWX6ES.cjs +0 -74
- package/dist/chunk-6LVRDOAW.mjs +0 -74
- package/dist/chunk-6MVFHNYZ.cjs +0 -1033
- package/dist/chunk-6NT6S2VQ.mjs +0 -180
- package/dist/chunk-6QOLZITB.cjs +0 -22
- package/dist/chunk-6QQDAAAZ.cjs +0 -38
- package/dist/chunk-72ADZ6GQ.cjs +0 -19
- package/dist/chunk-72AK62H5.mjs +0 -55
- package/dist/chunk-73WX6PRY.mjs +0 -575
- package/dist/chunk-75RZHGLS.cjs +0 -135
- package/dist/chunk-7GNWGLWB.mjs +0 -14
- package/dist/chunk-7IQQIPRZ.mjs +0 -55
- package/dist/chunk-7LTCDQRS.mjs +0 -166
- package/dist/chunk-7RNAKBWF.cjs +0 -40
- package/dist/chunk-7UEEHAW7.mjs +0 -576
- package/dist/chunk-7W3CPVXS.cjs +0 -24
- package/dist/chunk-A6WIQH5Z.cjs +0 -31
- package/dist/chunk-A7XJHKRK.cjs +0 -8621
- package/dist/chunk-AELACLOB.mjs +0 -47
- package/dist/chunk-AI7QMY7O.cjs +0 -41
- package/dist/chunk-ALPWLT27.cjs +0 -291
- package/dist/chunk-AMDMVWMI.cjs +0 -39
- package/dist/chunk-APDGOKKE.cjs +0 -148
- package/dist/chunk-ARJWXNQL.cjs +0 -256
- package/dist/chunk-AZBSVLRM.cjs +0 -132
- package/dist/chunk-B2GSRB3P.mjs +0 -1033
- package/dist/chunk-B6XAA7V6.cjs +0 -2042
- package/dist/chunk-BCMSYSN2.mjs +0 -183
- package/dist/chunk-BIDYX3SL.cjs +0 -91
- package/dist/chunk-BJIYRUGQ.mjs +0 -35
- package/dist/chunk-BMOBTMDR.cjs +0 -178
- package/dist/chunk-BOYNDCZL.mjs +0 -54
- package/dist/chunk-BPNRQ5BA.mjs +0 -690
- package/dist/chunk-BRYHOB4X.mjs +0 -18
- package/dist/chunk-BTHHUD7Q.mjs +0 -51
- package/dist/chunk-BUGNQIHC.mjs +0 -449
- package/dist/chunk-C4NCTZLM.mjs +0 -22
- package/dist/chunk-C5GUTBZK.cjs +0 -173
- package/dist/chunk-CALY6QG6.mjs +0 -963
- package/dist/chunk-CBBLJMR5.mjs +0 -74
- package/dist/chunk-CBXBGM72.cjs +0 -212
- package/dist/chunk-CEDPEDNW.cjs +0 -98
- package/dist/chunk-CGR525MJ.cjs +0 -357
- package/dist/chunk-CGVPXIRN.cjs +0 -472
- package/dist/chunk-CMGMGHUZ.cjs +0 -27
- package/dist/chunk-CNOQY6Z7.mjs +0 -156
- package/dist/chunk-COABSY3U.mjs +0 -196
- package/dist/chunk-CQ6OSQ3K.mjs +0 -36
- package/dist/chunk-CU625VAY.mjs +0 -13
- package/dist/chunk-CW6SNEN2.cjs +0 -727
- package/dist/chunk-CXP5U3RW.cjs +0 -54
- package/dist/chunk-CY2ZQ5C6.cjs +0 -56
- package/dist/chunk-CZS6OACQ.mjs +0 -63
- package/dist/chunk-D4ROBNTK.cjs +0 -1378
- package/dist/chunk-D5IHNDHI.cjs +0 -367
- package/dist/chunk-D5RFPV2H.mjs +0 -148
- package/dist/chunk-D64OPY6A.cjs +0 -710
- package/dist/chunk-D7JTOLFK.cjs +0 -285
- package/dist/chunk-DAATZTKJ.mjs +0 -220
- package/dist/chunk-DMRPN25V.mjs +0 -701
- package/dist/chunk-DQNWI2PV.cjs +0 -109
- package/dist/chunk-DVM4FKZL.cjs +0 -169
- package/dist/chunk-E22SWCXB.cjs +0 -144
- package/dist/chunk-E6Z63WDR.cjs +0 -11784
- package/dist/chunk-EMLAPBEM.mjs +0 -256
- package/dist/chunk-ETPEZLS3.mjs +0 -367
- package/dist/chunk-F3VB7ONA.mjs +0 -338
- package/dist/chunk-F646BZ4Y.mjs +0 -581
- package/dist/chunk-F6KWRHF5.cjs +0 -9
- package/dist/chunk-FA2W42OV.mjs +0 -25
- package/dist/chunk-FEYQCYT7.cjs +0 -823
- package/dist/chunk-FGH3ZXTP.mjs +0 -1063
- package/dist/chunk-FIAPD365.mjs +0 -85
- package/dist/chunk-FJ3M4CUX.cjs +0 -46
- package/dist/chunk-FK6GO24V.cjs +0 -54
- package/dist/chunk-FP2INE7H.mjs +0 -113
- package/dist/chunk-FVPXT2JR.cjs +0 -63
- package/dist/chunk-FWCGUVVL.mjs +0 -86
- package/dist/chunk-FXFKIJDA.cjs +0 -168
- package/dist/chunk-G2KY33I6.mjs +0 -202
- package/dist/chunk-G2Z5DGMS.cjs +0 -581
- package/dist/chunk-G4MWPDSE.mjs +0 -19
- package/dist/chunk-G643DQCH.cjs +0 -13
- package/dist/chunk-G7HXGLEC.cjs +0 -175
- package/dist/chunk-GB7LDGY5.cjs +0 -2355
- package/dist/chunk-GC3EM6H4.mjs +0 -80
- package/dist/chunk-GCXWJJKH.mjs +0 -169
- package/dist/chunk-GHFS7RUB.mjs +0 -152
- package/dist/chunk-GS3WR5HX.cjs +0 -595
- package/dist/chunk-GZTUT75U.mjs +0 -293
- package/dist/chunk-GZWHCWLB.mjs +0 -186
- package/dist/chunk-H3EGVQE5.mjs +0 -22
- package/dist/chunk-H4AMB6ZE.mjs +0 -421
- package/dist/chunk-H4LXPWI2.mjs +0 -46
- package/dist/chunk-H77NVNJ2.mjs +0 -57
- package/dist/chunk-H7BLEEAE.cjs +0 -57
- package/dist/chunk-HANGSYMB.mjs +0 -67
- package/dist/chunk-HDFNAUSG.cjs +0 -6066
- package/dist/chunk-HJ64F4GS.mjs +0 -537
- package/dist/chunk-HKFBMHCD.mjs +0 -291
- package/dist/chunk-HLJ6MBUZ.cjs +0 -183
- package/dist/chunk-HNGR7CTG.mjs +0 -9
- package/dist/chunk-HREOKQWT.cjs +0 -45
- package/dist/chunk-I2BHUNBU.mjs +0 -14
- package/dist/chunk-I57LW5VZ.cjs +0 -94
- package/dist/chunk-I5MG3TKE.cjs +0 -487
- package/dist/chunk-I6UVKUYK.mjs +0 -1378
- package/dist/chunk-IE7XCHH3.cjs +0 -85
- package/dist/chunk-IF4NU2NG.mjs +0 -314
- package/dist/chunk-IFWSR7YZ.cjs +0 -416
- package/dist/chunk-IHQIOZLC.mjs +0 -65
- package/dist/chunk-IK6LVLKC.cjs +0 -51
- package/dist/chunk-IM7DY3ED.mjs +0 -40
- package/dist/chunk-IN6RCKLL.mjs +0 -396
- package/dist/chunk-INQ64HTJ.mjs +0 -696
- package/dist/chunk-IOAUK4OI.cjs +0 -2162
- package/dist/chunk-IOEH4VWN.mjs +0 -202
- package/dist/chunk-IOMVXBLZ.mjs +0 -144
- package/dist/chunk-IXFOBGLQ.cjs +0 -1120
- package/dist/chunk-J7FSKED3.cjs +0 -93
- package/dist/chunk-J7K2NZD6.mjs +0 -56
- package/dist/chunk-JAXDRRRC.cjs +0 -701
- package/dist/chunk-JBL546U4.mjs +0 -6066
- package/dist/chunk-JBSVKMC5.mjs +0 -28
- package/dist/chunk-JDNHKPTD.cjs +0 -22
- package/dist/chunk-JEIG3EWE.cjs +0 -690
- package/dist/chunk-JEZO6VUR.cjs +0 -35
- package/dist/chunk-JGHCKIRI.mjs +0 -580
- package/dist/chunk-JGLC4TO3.cjs +0 -192
- package/dist/chunk-JM5XPKWH.mjs +0 -41
- package/dist/chunk-JNZ4TDWM.mjs +0 -445
- package/dist/chunk-JOW4HDJO.mjs +0 -179
- package/dist/chunk-JPLUGGRV.mjs +0 -230
- package/dist/chunk-JVXW76I7.mjs +0 -727
- package/dist/chunk-KCMTCM6I.cjs +0 -53
- package/dist/chunk-KEXK442I.cjs +0 -696
- package/dist/chunk-KF6VDJH7.cjs +0 -86
- package/dist/chunk-KFZZFZ7J.cjs +0 -46
- package/dist/chunk-KGB5UXJJ.mjs +0 -27
- package/dist/chunk-KGZIORNL.cjs +0 -43
- package/dist/chunk-KI3MESHB.mjs +0 -224
- package/dist/chunk-KLDBRGD5.mjs +0 -8620
- package/dist/chunk-KNBBQHO2.cjs +0 -51
- package/dist/chunk-KNHBTJP6.mjs +0 -472
- package/dist/chunk-KR6CKSXT.cjs +0 -15
- package/dist/chunk-KYN5ODF6.mjs +0 -62
- package/dist/chunk-L3KT7IXV.mjs +0 -91
- package/dist/chunk-L5H2GSUC.cjs +0 -49
- package/dist/chunk-L6A26QT5.cjs +0 -537
- package/dist/chunk-LCCBO7PJ.cjs +0 -46
- package/dist/chunk-LFHCG2DU.mjs +0 -43
- package/dist/chunk-LIUGYUX3.cjs +0 -22
- package/dist/chunk-LIZTLA5F.cjs +0 -396
- package/dist/chunk-LLUA2LSC.mjs +0 -157
- package/dist/chunk-LPE3ED4R.cjs +0 -929
- package/dist/chunk-LPEX4YW6.mjs +0 -13
- package/dist/chunk-LRJRXXQZ.cjs +0 -109
- package/dist/chunk-LTNGXMQ6.cjs +0 -55
- package/dist/chunk-LYLEZIG3.cjs +0 -73
- package/dist/chunk-LYV44OIR.mjs +0 -256
- package/dist/chunk-LZESP4IR.cjs +0 -575
- package/dist/chunk-M2L4MYDQ.cjs +0 -14
- package/dist/chunk-M3BXTWJM.mjs +0 -467
- package/dist/chunk-M7MKQXAF.cjs +0 -87
- package/dist/chunk-MEASUNVY.mjs +0 -440
- package/dist/chunk-MGMF4VP7.mjs +0 -102
- package/dist/chunk-MHHCLYXU.mjs +0 -236
- package/dist/chunk-MN4TQJ3W.cjs +0 -157
- package/dist/chunk-MQ3H6LT5.cjs +0 -202
- package/dist/chunk-MWSK6C4J.cjs +0 -18
- package/dist/chunk-MWWVKDW3.cjs +0 -169
- package/dist/chunk-MY5PZYAD.cjs +0 -2083
- package/dist/chunk-N46M65CI.mjs +0 -54
- package/dist/chunk-N4UOK6ZI.cjs +0 -256
- package/dist/chunk-NBPNUQYO.cjs +0 -179
- package/dist/chunk-NFG4PUPI.cjs +0 -64
- package/dist/chunk-NO3WWW3N.cjs +0 -192
- package/dist/chunk-NPC7VWJE.mjs +0 -277
- package/dist/chunk-NYJMY3JA.cjs +0 -156
- package/dist/chunk-NZKJGRB3.cjs +0 -230
- package/dist/chunk-O6BCQV2T.mjs +0 -46
- package/dist/chunk-O7BH5O46.mjs +0 -175
- package/dist/chunk-O7USYJ4U.mjs +0 -64
- package/dist/chunk-OHY2ZWUG.cjs +0 -25
- package/dist/chunk-OI6CMLWX.cjs +0 -47
- package/dist/chunk-OILHPMFX.cjs +0 -580
- package/dist/chunk-OJ7JP7RJ.mjs +0 -212
- package/dist/chunk-ONUEYC6N.mjs +0 -27
- package/dist/chunk-OT6ZEW74.mjs +0 -139
- package/dist/chunk-OX6O6WVA.cjs +0 -74
- package/dist/chunk-OYEUREB6.cjs +0 -35
- package/dist/chunk-OYZGFRPA.mjs +0 -714
- package/dist/chunk-OZVEHHMA.cjs +0 -194
- package/dist/chunk-P2UJF4SS.mjs +0 -823
- package/dist/chunk-P4TYB4SF.cjs +0 -417
- package/dist/chunk-P7XDC7UJ.mjs +0 -92
- package/dist/chunk-PCOTGFSM.cjs +0 -139
- package/dist/chunk-PDU4P2IC.cjs +0 -467
- package/dist/chunk-PJ42JESY.cjs +0 -87
- package/dist/chunk-PJEHUSHA.mjs +0 -229
- package/dist/chunk-PNGWZFUQ.mjs +0 -39
- package/dist/chunk-PSV6XKPO.cjs +0 -220
- package/dist/chunk-PZYCPSCC.cjs +0 -35
- package/dist/chunk-Q5B3KJBP.cjs +0 -152
- package/dist/chunk-QBK2AA4U.cjs +0 -445
- package/dist/chunk-QCFBDFRS.mjs +0 -169
- package/dist/chunk-QCVE2OCI.cjs +0 -169
- package/dist/chunk-QCVIRVHE.mjs +0 -87
- package/dist/chunk-QE6VAKLT.mjs +0 -85
- package/dist/chunk-QGH2RQVF.mjs +0 -132
- package/dist/chunk-QHSH7IH4.mjs +0 -35
- package/dist/chunk-QIBP5EFA.cjs +0 -476
- package/dist/chunk-QNPEUFHQ.cjs +0 -27
- package/dist/chunk-QVKYGNVM.mjs +0 -27
- package/dist/chunk-QVYLBY73.mjs +0 -93
- package/dist/chunk-R3DS7A2T.mjs +0 -21
- package/dist/chunk-R3ZFQJEF.mjs +0 -616
- package/dist/chunk-R5A5KNVX.cjs +0 -20
- package/dist/chunk-R5JIFR6B.cjs +0 -42
- package/dist/chunk-RHAZ22ZN.mjs +0 -87
- package/dist/chunk-S34OBRMZ.mjs +0 -109
- package/dist/chunk-S3A45T7F.cjs +0 -166
- package/dist/chunk-S3FNNQHR.mjs +0 -31
- package/dist/chunk-S3JO3N4H.cjs +0 -17
- package/dist/chunk-S3ZEMCE6.mjs +0 -1120
- package/dist/chunk-S67OYZU7.mjs +0 -711
- package/dist/chunk-S6ENKNNG.mjs +0 -168
- package/dist/chunk-S6FJO323.cjs +0 -65
- package/dist/chunk-S7MTDRYA.cjs +0 -394
- package/dist/chunk-SAXPH6G5.mjs +0 -169
- package/dist/chunk-SBH2JLLF.cjs +0 -55
- package/dist/chunk-SEJ5N6SL.mjs +0 -38
- package/dist/chunk-SFGWNC43.mjs +0 -97
- package/dist/chunk-SGB4IW7K.mjs +0 -710
- package/dist/chunk-SGBZPZUW.mjs +0 -75
- package/dist/chunk-SHB3GYXI.mjs +0 -285
- package/dist/chunk-SK35NQKK.cjs +0 -27
- package/dist/chunk-SKK6UF5P.cjs +0 -755
- package/dist/chunk-SKNL7VA2.mjs +0 -42
- package/dist/chunk-SLQCDJSO.mjs +0 -18
- package/dist/chunk-SOR334EB.cjs +0 -149
- package/dist/chunk-SU7MH53P.cjs +0 -180
- package/dist/chunk-SVRTJOUF.cjs +0 -113
- package/dist/chunk-SZLNU3GJ.cjs +0 -293
- package/dist/chunk-T76H22WI.mjs +0 -2162
- package/dist/chunk-TFQG7TBC.mjs +0 -43
- package/dist/chunk-TI7UANHI.cjs +0 -77
- package/dist/chunk-TIWHTW3Q.cjs +0 -24
- package/dist/chunk-TKJZFIML.cjs +0 -20
- package/dist/chunk-TUGIZGTH.mjs +0 -109
- package/dist/chunk-TVGP4BBZ.mjs +0 -45
- package/dist/chunk-UFDAAQFX.cjs +0 -169
- package/dist/chunk-UFDV5N3C.cjs +0 -711
- package/dist/chunk-UIDWEU7M.mjs +0 -357
- package/dist/chunk-ULQOP5UI.mjs +0 -54
- package/dist/chunk-UP4CW6WP.mjs +0 -169
- package/dist/chunk-UQUEANTY.mjs +0 -2083
- package/dist/chunk-UQZ4AYTH.cjs +0 -168
- package/dist/chunk-US2QVW3E.cjs +0 -36
- package/dist/chunk-UXHS27O6.cjs +0 -75
- package/dist/chunk-UYIHRDE4.cjs +0 -97
- package/dist/chunk-V2FTMRS7.mjs +0 -223
- package/dist/chunk-VB6UCX3V.cjs +0 -421
- package/dist/chunk-VDRM36QB.cjs +0 -963
- package/dist/chunk-VEKFLAQM.cjs +0 -300
- package/dist/chunk-VHRS3MCW.cjs +0 -196
- package/dist/chunk-VNPXKF3G.cjs +0 -314
- package/dist/chunk-VQDBNVOO.cjs +0 -14
- package/dist/chunk-VQGKD7RV.mjs +0 -25
- package/dist/chunk-VTBXE6QG.mjs +0 -476
- package/dist/chunk-W3B4PKAW.mjs +0 -28
- package/dist/chunk-W4E7WMXE.cjs +0 -71
- package/dist/chunk-WBKEZXWE.cjs +0 -449
- package/dist/chunk-WDMIW6Q6.mjs +0 -145
- package/dist/chunk-WLHA5USH.cjs +0 -1514
- package/dist/chunk-WMAPPDMM.cjs +0 -28
- package/dist/chunk-WMBRZI5V.mjs +0 -416
- package/dist/chunk-WMHG64DA.mjs +0 -417
- package/dist/chunk-WMOGFOUJ.cjs +0 -223
- package/dist/chunk-WNSDDRNU.mjs +0 -24
- package/dist/chunk-WPJQN64R.mjs +0 -755
- package/dist/chunk-WROEFVNO.cjs +0 -236
- package/dist/chunk-WU7ZS3EM.cjs +0 -440
- package/dist/chunk-WWYXIECF.mjs +0 -929
- package/dist/chunk-X3GMHKO3.cjs +0 -62
- package/dist/chunk-X3NGFVRF.mjs +0 -237
- package/dist/chunk-XJJVLDM6.mjs +0 -194
- package/dist/chunk-XJXBIP67.cjs +0 -277
- package/dist/chunk-XNPDONUH.mjs +0 -389
- package/dist/chunk-XSIRSMAS.cjs +0 -339
- package/dist/chunk-XUC6CFLE.mjs +0 -1514
- package/dist/chunk-XUGFRFD2.mjs +0 -39
- package/dist/chunk-XZNTNMHT.mjs +0 -15
- package/dist/chunk-Y5RG6B7S.mjs +0 -77
- package/dist/chunk-YFILVET3.mjs +0 -192
- package/dist/chunk-YFPGHF5F.cjs +0 -202
- package/dist/chunk-YHOCRI4H.mjs +0 -434
- package/dist/chunk-YJRZR7VU.cjs +0 -28
- package/dist/chunk-YKUEJ3MG.cjs +0 -229
- package/dist/chunk-YLPEGQDE.mjs +0 -11783
- package/dist/chunk-YN2QEMMO.cjs +0 -714
- package/dist/chunk-YOZYCI6Z.mjs +0 -73
- package/dist/chunk-YWCYV7QC.cjs +0 -54
- package/dist/chunk-YX3DBN4M.cjs +0 -18
- package/dist/chunk-YYQVGKO5.mjs +0 -394
- package/dist/chunk-YZAKIXRL.cjs +0 -67
- package/dist/chunk-Z2RZJZIZ.mjs +0 -168
- package/dist/chunk-Z3HATSKO.mjs +0 -46
- package/dist/chunk-ZEG3OPIB.cjs +0 -93
- package/dist/chunk-ZLAT2CWY.mjs +0 -135
- package/dist/chunk-ZM6U54TC.cjs +0 -1210
- package/dist/chunk-ZQRCSUSB.cjs +0 -25
- package/dist/chunk-ZTP3BJG6.cjs +0 -237
- package/dist/chunk-ZZGQD7A4.mjs +0 -435
- package/dist/chunk-ZZSRYEYU.mjs +0 -53
- package/dist/client-plugins-DEmIQo5R.d.mts +0 -3801
- package/dist/client-plugins-br48Hpmk.d.ts +0 -3801
- package/dist/devtools-5Q7VRKVH.cjs +0 -478
- package/dist/devtools-LJ4IGYGW.mjs +0 -478
- package/dist/devtools-client-CXQ6PXI6.cjs +0 -254
- package/dist/devtools-client-HJS2T34Y.mjs +0 -254
- package/dist/devtools-ui-5GBDIGMK.cjs +0 -1296
- package/dist/devtools-ui-5KDAVPIF.mjs +0 -1296
- package/dist/index-CyD9Rfso.d.ts +0 -48
- package/dist/index-_nhUt_dh.d.mts +0 -48
- package/dist/integration-orm-P2II2EBK.cjs +0 -14
- package/dist/integration-orm-RBKCIQYZ.mjs +0 -14
- package/dist/layers-UTB43B7A.mjs +0 -18
- package/dist/layers-VUWIOFEO.cjs +0 -18
- package/dist/manager-RT733VRK.mjs +0 -14
- package/dist/manager-XZ5TX7AO.cjs +0 -14
- package/dist/nitro-KDACKNHU.mjs +0 -654
- package/dist/nitro-NPGU6VBT.cjs +0 -654
- package/dist/node-module-bundle-L5L7JCZ4.mjs +0 -11
- package/dist/node-module-bundle-VAFZOXMJ.cjs +0 -11
- package/dist/plugin-DBBZ4JI2.cjs +0 -32
- package/dist/plugin-SYMK7PQ2.mjs +0 -32
- package/dist/production-runtime-BEbIyIUe.d.mts +0 -123
- package/dist/production-runtime-DsHjccVI.d.ts +0 -123
- package/dist/programmatic-routes-client-DlMKstmL.d.ts +0 -184
- package/dist/programmatic-routes-client-Dqr6tHND.d.mts +0 -184
- package/dist/render-plan-Bu6XOxNg.d.mts +0 -25
- package/dist/render-plan-MefW_fLC.d.ts +0 -25
- package/dist/request-BBe1B8Bk.d.mts +0 -24
- package/dist/request-CMsRJQK3.d.ts +0 -24
- package/dist/route-rendering-DTLNruPw.d.ts +0 -44
- package/dist/route-rendering-Do8tuYgh.d.mts +0 -44
- package/dist/router-BJreOZ-k.d.ts +0 -50
- package/dist/router-o2mZB9Y4.d.mts +0 -50
- package/dist/rsc-pipeline-4ZJ6GUVQ.cjs +0 -78
- package/dist/rsc-pipeline-KK6GFDET.mjs +0 -78
- package/dist/runtime-Cp5YZNz4.d.mts +0 -69
- package/dist/runtime-Da57KD8F.d.ts +0 -69
- package/dist/schema-dev-notice-77ZL23PL.cjs +0 -58
- package/dist/schema-dev-notice-BLXOS6U2.mjs +0 -58
- package/dist/search-client-G3RICOFU.cjs +0 -13
- package/dist/search-client-KR7YRIVR.mjs +0 -13
- package/dist/spa-router-CN2vc0GY.d.ts +0 -239
- package/dist/spa-router-COZLIB7k.d.mts +0 -239
- package/dist/utils-BAtVIHfw.d.mts +0 -48
- package/dist/utils-Y8MZrj4b.d.ts +0 -48
|
@@ -0,0 +1,2072 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collectSchemaExtensions,
|
|
3
|
+
describeSchemaExtensionApproval,
|
|
4
|
+
isSchemaExtensionAllowed,
|
|
5
|
+
readSchemaTables
|
|
6
|
+
} from "./chunk-2DLGV2ZG.mjs";
|
|
7
|
+
import {
|
|
8
|
+
assertNoSchemaListField,
|
|
9
|
+
isDatabaseEnforcedReference
|
|
10
|
+
} from "./chunk-WNLPQW7W.mjs";
|
|
11
|
+
import {
|
|
12
|
+
resolveSchemaModels
|
|
13
|
+
} from "./chunk-F3N52U7S.mjs";
|
|
14
|
+
|
|
15
|
+
// src/schema-sql-identifiers.ts
|
|
16
|
+
var POSTGRES_IDENTIFIER_BYTES = 63;
|
|
17
|
+
function fitSqlIndexName(dialect, name) {
|
|
18
|
+
if (dialect !== "postgres") return name;
|
|
19
|
+
const encoder = new TextEncoder();
|
|
20
|
+
const bytes = encoder.encode(name);
|
|
21
|
+
if (bytes.length <= POSTGRES_IDENTIFIER_BYTES) return name;
|
|
22
|
+
let hash = 2166136261;
|
|
23
|
+
for (const byte of bytes) hash = Math.imul(hash ^ byte, 16777619);
|
|
24
|
+
const suffix = `_${(hash >>> 0).toString(16).padStart(8, "0")}`;
|
|
25
|
+
let prefix = "";
|
|
26
|
+
let length = 0;
|
|
27
|
+
for (const character of name) {
|
|
28
|
+
const size = encoder.encode(character).length;
|
|
29
|
+
if (length + size > POSTGRES_IDENTIFIER_BYTES - suffix.length) break;
|
|
30
|
+
prefix += character;
|
|
31
|
+
length += size;
|
|
32
|
+
}
|
|
33
|
+
return prefix + suffix;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/schema-sql.ts
|
|
37
|
+
function describeSchemaReference(model, fieldKey) {
|
|
38
|
+
const field = model.model.fields[fieldKey];
|
|
39
|
+
const target = model.referenceTargets?.[fieldKey];
|
|
40
|
+
if (target) return `${target.table}.${target.column}`;
|
|
41
|
+
return `${field?.reference?.model}.${field?.reference?.field}`;
|
|
42
|
+
}
|
|
43
|
+
var SQL_ON_DELETE_ACTIONS = {
|
|
44
|
+
cascade: "CASCADE",
|
|
45
|
+
restrict: "RESTRICT",
|
|
46
|
+
setNull: "SET NULL",
|
|
47
|
+
noAction: "NO ACTION"
|
|
48
|
+
};
|
|
49
|
+
function collectSchemaModels(entries) {
|
|
50
|
+
const collectedModels = [];
|
|
51
|
+
const seenModelNames = /* @__PURE__ */ new Map();
|
|
52
|
+
for (const [ownerKey, schema, only] of entries) {
|
|
53
|
+
const resolvedModels = resolveSchemaModels(ownerKey, schema);
|
|
54
|
+
for (const [modelKey, model] of Object.entries(resolvedModels)) {
|
|
55
|
+
if (only && !only.includes(modelKey)) continue;
|
|
56
|
+
if (model.external) continue;
|
|
57
|
+
const collisionKey = model.name.toLowerCase();
|
|
58
|
+
const previousOwner = seenModelNames.get(collisionKey);
|
|
59
|
+
if (previousOwner && previousOwner !== `${ownerKey}.${modelKey}`) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`Schema model "${ownerKey}.${modelKey}" resolves to "${model.name}", which conflicts with "${previousOwner}". Rename one of the models with schema.models.<model>.name.`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
seenModelNames.set(collisionKey, `${ownerKey}.${modelKey}`);
|
|
65
|
+
const referenceTargets = {};
|
|
66
|
+
for (const [fieldKey, field] of Object.entries(model.fields)) {
|
|
67
|
+
const reference = field.reference;
|
|
68
|
+
if (!reference || !Object.prototype.hasOwnProperty.call(resolvedModels, reference.model)) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const target = resolvedModels[reference.model];
|
|
72
|
+
if (!target.external && (!only || only.includes(reference.model))) continue;
|
|
73
|
+
referenceTargets[fieldKey] = {
|
|
74
|
+
table: target.name,
|
|
75
|
+
column: target.fields[reference.field]?.name ?? reference.field
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
collectedModels.push({
|
|
79
|
+
ownerKey,
|
|
80
|
+
modelKey,
|
|
81
|
+
modelName: model.name,
|
|
82
|
+
exportName: toCamelCase(`${ownerKey}_${modelKey}`),
|
|
83
|
+
prismaModelName: toPascalCase(`${ownerKey}_${modelKey}`),
|
|
84
|
+
model,
|
|
85
|
+
...Object.keys(referenceTargets).length > 0 ? { referenceTargets } : {}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return collectedModels;
|
|
90
|
+
}
|
|
91
|
+
function generateSqlStatements(models, dialect) {
|
|
92
|
+
const modelLookup = createModelLookup(models);
|
|
93
|
+
const orderedModels = orderSchemaModelsByReferences(models, modelLookup);
|
|
94
|
+
const statements = [];
|
|
95
|
+
for (const model of orderedModels) {
|
|
96
|
+
statements.push({
|
|
97
|
+
kind: "table",
|
|
98
|
+
target: model.modelName,
|
|
99
|
+
sql: renderSqlTable(model, dialect, modelLookup)
|
|
100
|
+
});
|
|
101
|
+
for (const index of renderSqlIndexes(model, dialect)) {
|
|
102
|
+
statements.push(index);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return statements;
|
|
106
|
+
}
|
|
107
|
+
function renderSqlSchemaFile(models, dialect) {
|
|
108
|
+
const lines = ["-- Generated by Farm.js CLI. Review before applying.", ""];
|
|
109
|
+
const modelLookup = createModelLookup(models);
|
|
110
|
+
const orderedModels = orderSchemaModelsByReferences(models, modelLookup);
|
|
111
|
+
for (const model of orderedModels) {
|
|
112
|
+
lines.push(
|
|
113
|
+
`-- Owner "${model.ownerKey}" model "${model.modelKey}"`,
|
|
114
|
+
renderSqlTable(model, dialect, modelLookup),
|
|
115
|
+
""
|
|
116
|
+
);
|
|
117
|
+
for (const statement of renderSqlIndexes(model, dialect)) {
|
|
118
|
+
lines.push(statement.sql, "");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return lines.join("\n").trimEnd() + "\n";
|
|
122
|
+
}
|
|
123
|
+
function renderSqlTable(model, dialect, modelLookup) {
|
|
124
|
+
const tableName = quoteSqlIdentifier(dialect, model.modelName);
|
|
125
|
+
const lines = [`CREATE TABLE IF NOT EXISTS ${tableName} (`];
|
|
126
|
+
const columns = [];
|
|
127
|
+
const internalReferences = createInternalReferenceLookup(model, dialect, modelLookup);
|
|
128
|
+
for (const [fieldKey, field] of Object.entries(model.model.fields)) {
|
|
129
|
+
assertNoSchemaListField(
|
|
130
|
+
field,
|
|
131
|
+
`${model.ownerKey}.${model.modelKey}.${fieldKey}`,
|
|
132
|
+
`${dialect} SQL generation`
|
|
133
|
+
);
|
|
134
|
+
const parts = [
|
|
135
|
+
` ${quoteSqlIdentifier(dialect, field.name)}`,
|
|
136
|
+
getSqlColumnType(field, dialect)
|
|
137
|
+
];
|
|
138
|
+
if (field.primaryKey) {
|
|
139
|
+
parts.push("PRIMARY KEY");
|
|
140
|
+
} else if (!isNullableField(field)) {
|
|
141
|
+
parts.push("NOT NULL");
|
|
142
|
+
}
|
|
143
|
+
if (!field.primaryKey && field.unique) {
|
|
144
|
+
parts.push("UNIQUE");
|
|
145
|
+
}
|
|
146
|
+
const defaultValue = getSqlDefaultExpression(field, dialect);
|
|
147
|
+
if (defaultValue) {
|
|
148
|
+
parts.push(`DEFAULT ${defaultValue}`);
|
|
149
|
+
}
|
|
150
|
+
const crossOwner = model.foreignKeys?.[fieldKey];
|
|
151
|
+
const reference = internalReferences.get(fieldKey) ?? (crossOwner ? `REFERENCES ${quoteSqlIdentifier(dialect, crossOwner.table)} (${quoteSqlIdentifier(dialect, crossOwner.column)})${crossOwner.onDelete !== "noAction" ? ` ON DELETE ${SQL_ON_DELETE_ACTIONS[crossOwner.onDelete]}` : ""}` : void 0);
|
|
152
|
+
if (reference) {
|
|
153
|
+
parts.push(reference);
|
|
154
|
+
} else if (field.reference) {
|
|
155
|
+
parts.push(
|
|
156
|
+
`/* references ${describeSchemaReference(model, fieldKey)}${field.reference.onDelete ? ` on delete ${field.reference.onDelete}` : ""} */`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
columns.push(parts.join(" "));
|
|
160
|
+
}
|
|
161
|
+
if (dialect === "mysql") {
|
|
162
|
+
for (const definition of collectSchemaIndexes(model, dialect)) {
|
|
163
|
+
columns.push(
|
|
164
|
+
` ${definition.unique ? "UNIQUE KEY" : "KEY"} ${quoteSqlIdentifier(dialect, definition.name)} (${definition.columns.join(", ")})`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
lines.push(columns.join(",\n"));
|
|
169
|
+
lines.push(");");
|
|
170
|
+
return lines.join("\n");
|
|
171
|
+
}
|
|
172
|
+
function collectSchemaIndexes(model, dialect) {
|
|
173
|
+
const definitions = [];
|
|
174
|
+
for (const field of Object.values(model.model.fields)) {
|
|
175
|
+
if (!field.index) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
definitions.push({
|
|
179
|
+
name: fitSqlIndexName(dialect, `${model.modelName}_${field.name}_idx`),
|
|
180
|
+
columns: [quoteSqlIdentifier(dialect, field.name)],
|
|
181
|
+
unique: false
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
for (const constraint of model.model.constraints || []) {
|
|
185
|
+
definitions.push({
|
|
186
|
+
name: fitSqlIndexName(
|
|
187
|
+
dialect,
|
|
188
|
+
constraint.name || `${model.modelName}_${constraint.fields.map((fieldKey) => model.model.fields[fieldKey]?.name || fieldKey).join("_")}_${constraint.type}`
|
|
189
|
+
),
|
|
190
|
+
columns: constraint.fields.map(
|
|
191
|
+
(fieldKey) => quoteSqlIdentifier(dialect, model.model.fields[fieldKey]?.name || fieldKey)
|
|
192
|
+
),
|
|
193
|
+
unique: constraint.type === "unique"
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return definitions;
|
|
197
|
+
}
|
|
198
|
+
function renderSqlIndexes(model, dialect) {
|
|
199
|
+
if (dialect === "mysql") {
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
const tableName = quoteSqlIdentifier(dialect, model.modelName);
|
|
203
|
+
return collectSchemaIndexes(model, dialect).map((definition) => ({
|
|
204
|
+
kind: "index",
|
|
205
|
+
target: definition.name,
|
|
206
|
+
sql: `CREATE ${definition.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${quoteSqlIdentifier(dialect, definition.name)} ON ${tableName} (${definition.columns.join(", ")});`
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
function createInternalReferenceLookup(model, dialect, modelLookup) {
|
|
210
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
211
|
+
for (const [fieldKey, field] of Object.entries(model.model.fields)) {
|
|
212
|
+
if (!field.reference || !isDatabaseEnforcedReference(field.reference)) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const referencedModel = modelLookup.get(`${model.ownerKey}.${field.reference.model}`);
|
|
216
|
+
if (referencedModel) {
|
|
217
|
+
const referencedField = field.reference.field;
|
|
218
|
+
const pieces = [
|
|
219
|
+
`REFERENCES ${quoteSqlIdentifier(dialect, referencedModel.modelName)} (${quoteSqlIdentifier(dialect, referencedModel.model.fields[referencedField]?.name || referencedField)})`
|
|
220
|
+
];
|
|
221
|
+
if (field.reference.onDelete) {
|
|
222
|
+
pieces.push(`ON DELETE ${SQL_ON_DELETE_ACTIONS[field.reference.onDelete]}`);
|
|
223
|
+
}
|
|
224
|
+
lookup.set(fieldKey, pieces.join(" "));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return lookup;
|
|
228
|
+
}
|
|
229
|
+
function getSqlColumnType(field, dialect) {
|
|
230
|
+
if (dialect === "postgres") {
|
|
231
|
+
switch (field.type) {
|
|
232
|
+
case "boolean":
|
|
233
|
+
return "BOOLEAN";
|
|
234
|
+
case "integer":
|
|
235
|
+
return "INTEGER";
|
|
236
|
+
case "number":
|
|
237
|
+
return "DOUBLE PRECISION";
|
|
238
|
+
case "datetime":
|
|
239
|
+
return "TIMESTAMPTZ";
|
|
240
|
+
case "json":
|
|
241
|
+
return "JSONB";
|
|
242
|
+
default:
|
|
243
|
+
return "TEXT";
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (dialect === "mysql") {
|
|
247
|
+
switch (field.type) {
|
|
248
|
+
case "boolean":
|
|
249
|
+
return "BOOLEAN";
|
|
250
|
+
case "integer":
|
|
251
|
+
return "INT";
|
|
252
|
+
case "number":
|
|
253
|
+
return "DOUBLE";
|
|
254
|
+
case "datetime":
|
|
255
|
+
return "DATETIME";
|
|
256
|
+
case "json":
|
|
257
|
+
return "JSON";
|
|
258
|
+
case "text":
|
|
259
|
+
return "TEXT";
|
|
260
|
+
default:
|
|
261
|
+
return "VARCHAR(255)";
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
switch (field.type) {
|
|
265
|
+
case "boolean":
|
|
266
|
+
case "integer":
|
|
267
|
+
return "INTEGER";
|
|
268
|
+
case "number":
|
|
269
|
+
return "REAL";
|
|
270
|
+
default:
|
|
271
|
+
return "TEXT";
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function getSqlDefaultExpression(field, dialect) {
|
|
275
|
+
if (field.default === void 0) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
if (field.type === "datetime" && field.default === "now") {
|
|
279
|
+
return "CURRENT_TIMESTAMP";
|
|
280
|
+
}
|
|
281
|
+
if (typeof field.default === "string") {
|
|
282
|
+
return `'${escapeSqlString(field.default, dialect)}'`;
|
|
283
|
+
}
|
|
284
|
+
if (typeof field.default === "number") {
|
|
285
|
+
return String(field.default);
|
|
286
|
+
}
|
|
287
|
+
if (typeof field.default === "boolean") {
|
|
288
|
+
if (dialect === "sqlite") {
|
|
289
|
+
return field.default ? "1" : "0";
|
|
290
|
+
}
|
|
291
|
+
return field.default ? "TRUE" : "FALSE";
|
|
292
|
+
}
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
function isNullableField(field) {
|
|
296
|
+
return field.nullable === true || field.required === false;
|
|
297
|
+
}
|
|
298
|
+
function quoteSqlIdentifier(dialect, value) {
|
|
299
|
+
if (dialect === "mysql") {
|
|
300
|
+
return `\`${value.replace(/`/g, "``")}\``;
|
|
301
|
+
}
|
|
302
|
+
return `"${value.replace(/"/g, '""')}"`;
|
|
303
|
+
}
|
|
304
|
+
function createModelLookup(models) {
|
|
305
|
+
return new Map(models.map((model) => [`${model.ownerKey}.${model.modelKey}`, model]));
|
|
306
|
+
}
|
|
307
|
+
function orderSchemaModelsByReferences(models, modelLookup) {
|
|
308
|
+
const ordered = [];
|
|
309
|
+
const states = /* @__PURE__ */ new Map();
|
|
310
|
+
const stack = [];
|
|
311
|
+
const visit = (model) => {
|
|
312
|
+
const modelKey = getCollectedModelKey(model);
|
|
313
|
+
if (states.get(modelKey) === "visited") {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
states.set(modelKey, "visiting");
|
|
317
|
+
stack.push(model);
|
|
318
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
319
|
+
for (const field of Object.values(model.model.fields)) {
|
|
320
|
+
if (field.reference && isDatabaseEnforcedReference(field.reference)) {
|
|
321
|
+
dependencies.add(`${model.ownerKey}.${field.reference.model}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
for (const dependencyKey of dependencies) {
|
|
325
|
+
const dependency = modelLookup.get(dependencyKey);
|
|
326
|
+
if (!dependency || dependency === model) {
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
if (states.get(dependencyKey) === "visiting") {
|
|
330
|
+
const cycleStart = stack.findIndex(
|
|
331
|
+
(candidate) => getCollectedModelKey(candidate) === dependencyKey
|
|
332
|
+
);
|
|
333
|
+
const cycle = [...stack.slice(cycleStart), dependency].map((candidate) => `"${getCollectedModelKey(candidate)}"`).join(" -> ");
|
|
334
|
+
throw new Error(
|
|
335
|
+
`Schema table references contain a cycle: ${cycle}. Database-enforced cross-table cycles cannot be created inline; remove one edge or manage that constraint separately.`
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
visit(dependency);
|
|
339
|
+
}
|
|
340
|
+
stack.pop();
|
|
341
|
+
states.set(modelKey, "visited");
|
|
342
|
+
ordered.push(model);
|
|
343
|
+
};
|
|
344
|
+
for (const model of models) {
|
|
345
|
+
visit(model);
|
|
346
|
+
}
|
|
347
|
+
return ordered;
|
|
348
|
+
}
|
|
349
|
+
function getCollectedModelKey(model) {
|
|
350
|
+
return `${model.ownerKey}.${model.modelKey}`;
|
|
351
|
+
}
|
|
352
|
+
function toSnakeCase(value) {
|
|
353
|
+
return value.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[\s.-]+/g, "_").replace(/__+/g, "_").toLowerCase();
|
|
354
|
+
}
|
|
355
|
+
function toPascalCase(value) {
|
|
356
|
+
return value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[\s._-]+/g, " ").split(" ").filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
357
|
+
}
|
|
358
|
+
function toCamelCase(value) {
|
|
359
|
+
const pascal = toPascalCase(value);
|
|
360
|
+
return pascal ? pascal.charAt(0).toLowerCase() + pascal.slice(1) : pascal;
|
|
361
|
+
}
|
|
362
|
+
function escapeSqlString(value, dialect) {
|
|
363
|
+
const quoted = value.replace(/'/g, "''");
|
|
364
|
+
return dialect === "mysql" ? quoted.replace(/\\/g, "\\\\") : quoted;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/schema-migrate.ts
|
|
368
|
+
async function planSchemaMigration(models, dialect, executor) {
|
|
369
|
+
const statements = [];
|
|
370
|
+
const upToDate = [];
|
|
371
|
+
const drift = [];
|
|
372
|
+
const addableForeignKeys = [];
|
|
373
|
+
const upgrades = [];
|
|
374
|
+
const modelLookup = new Map(
|
|
375
|
+
models.map((model) => [`${model.ownerKey}.${model.modelKey}`, model])
|
|
376
|
+
);
|
|
377
|
+
const byTable = /* @__PURE__ */ new Map();
|
|
378
|
+
let currentTable;
|
|
379
|
+
for (const statement of generateSqlStatements(models, dialect)) {
|
|
380
|
+
if (statement.kind === "table") {
|
|
381
|
+
currentTable = [];
|
|
382
|
+
byTable.set(statement.target, currentTable);
|
|
383
|
+
}
|
|
384
|
+
currentTable?.push(statement);
|
|
385
|
+
}
|
|
386
|
+
for (const model of models) {
|
|
387
|
+
const existing = await describeTable(executor, dialect, model.modelName);
|
|
388
|
+
if (!existing) {
|
|
389
|
+
statements.push(...byTable.get(model.modelName) ?? []);
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
const expectedColumns = new Map(
|
|
393
|
+
Object.values(model.model.fields).map((field) => [field.name.toLowerCase(), field])
|
|
394
|
+
);
|
|
395
|
+
const actualColumns = new Map(
|
|
396
|
+
existing.columns.map((column) => [column.name.toLowerCase(), column])
|
|
397
|
+
);
|
|
398
|
+
const missingColumns = [...expectedColumns.values()].filter((field) => !actualColumns.has(field.name.toLowerCase())).map((field) => field.name);
|
|
399
|
+
const extraColumns = existing.columns.filter((column) => !expectedColumns.has(column.name.toLowerCase())).map((column) => column.name);
|
|
400
|
+
const changedColumns = [];
|
|
401
|
+
for (const [columnKey, field] of expectedColumns) {
|
|
402
|
+
const actualColumn = actualColumns.get(columnKey);
|
|
403
|
+
if (!actualColumn) continue;
|
|
404
|
+
const expectedDefinition = expectedColumnDefinition(field, dialect);
|
|
405
|
+
const actualDefinition = actualColumnDefinition(actualColumn, field, dialect);
|
|
406
|
+
const differences = [];
|
|
407
|
+
if (expectedDefinition.type !== actualDefinition.type) differences.push("type");
|
|
408
|
+
if (expectedDefinition.nullable !== actualDefinition.nullable) {
|
|
409
|
+
differences.push("nullability");
|
|
410
|
+
}
|
|
411
|
+
if (expectedDefinition.default !== actualDefinition.default) differences.push("default");
|
|
412
|
+
if (expectedDefinition.primaryKey !== actualDefinition.primaryKey) {
|
|
413
|
+
differences.push("primaryKey");
|
|
414
|
+
}
|
|
415
|
+
if (differences.length > 0) {
|
|
416
|
+
changedColumns.push({
|
|
417
|
+
column: field.name,
|
|
418
|
+
differences,
|
|
419
|
+
expected: expectedDefinition,
|
|
420
|
+
actual: actualDefinition
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
const expectedIndexes = collectExpectedIndexes(model);
|
|
425
|
+
const actualIndexes = existing.indexes.filter((index) => !index.primary);
|
|
426
|
+
const { missing: missingIndexes, extra: unmatchedIndexes } = compareDefinitions(
|
|
427
|
+
expectedIndexes,
|
|
428
|
+
actualIndexes,
|
|
429
|
+
indexSignature
|
|
430
|
+
);
|
|
431
|
+
const expectedReferences = collectExpectedReferences(model, modelLookup);
|
|
432
|
+
const crossOwner = Object.entries(model.foreignKeys ?? {}).map(([fieldKey, key]) => ({
|
|
433
|
+
...key,
|
|
434
|
+
column: model.model.fields[fieldKey].name,
|
|
435
|
+
referencedColumn: key.column
|
|
436
|
+
}));
|
|
437
|
+
const isCrossOwnerOf = (key) => (reference) => key.column.toLowerCase() === reference.column.toLowerCase() && key.table.toLowerCase() === reference.referencedTable.toLowerCase();
|
|
438
|
+
const isCrossOwner = (reference) => crossOwner.some((key) => isCrossOwnerOf(key)(reference));
|
|
439
|
+
const { missing: missingReferences, extra: unmatchedReferences } = compareDefinitions(
|
|
440
|
+
expectedReferences,
|
|
441
|
+
existing.references,
|
|
442
|
+
referenceSignature
|
|
443
|
+
);
|
|
444
|
+
const extraReferences = unmatchedReferences.filter((reference) => !isCrossOwner(reference));
|
|
445
|
+
for (const key of crossOwner) {
|
|
446
|
+
if (existing.references.some(isCrossOwnerOf(key))) continue;
|
|
447
|
+
addableForeignKeys.push({
|
|
448
|
+
modelKey: model.modelKey,
|
|
449
|
+
table: model.modelName,
|
|
450
|
+
column: key.column,
|
|
451
|
+
referencedTable: key.table,
|
|
452
|
+
referencedColumn: key.referencedColumn,
|
|
453
|
+
onDelete: key.onDelete
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
const referenceColumns = new Set(
|
|
457
|
+
existing.references.map((reference) => reference.column.toLowerCase())
|
|
458
|
+
);
|
|
459
|
+
const extraIndexes = unmatchedIndexes.filter(
|
|
460
|
+
(index) => !(dialect === "mysql" && !index.unique && index.columns.length === 1 && referenceColumns.has(index.columns[0].toLowerCase()))
|
|
461
|
+
);
|
|
462
|
+
const remainingColumns = [];
|
|
463
|
+
for (const column of missingColumns) {
|
|
464
|
+
const field = expectedColumns.get(column.toLowerCase());
|
|
465
|
+
if (field.primaryKey || field.unique || unsupportedColumnReason(field, dialect)) {
|
|
466
|
+
remainingColumns.push(column);
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
upgrades.push({
|
|
470
|
+
kind: "column",
|
|
471
|
+
table: model.modelName,
|
|
472
|
+
target: `${model.modelName}.${column}`,
|
|
473
|
+
sql: addColumnStatement(dialect, model.modelName, field)
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
const remainingIndexes = [];
|
|
477
|
+
for (const index of missingIndexes) {
|
|
478
|
+
const columnsExist = index.columns.every(
|
|
479
|
+
(column) => actualColumns.has(column.toLowerCase()) || !remainingColumns.includes(column)
|
|
480
|
+
);
|
|
481
|
+
if (index.unique || !columnsExist) {
|
|
482
|
+
remainingIndexes.push(index);
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
const columns = index.columns.map((column) => quoteSqlIdentifier(dialect, column)).join(", ");
|
|
486
|
+
const name = fitSqlIndexName(dialect, index.name);
|
|
487
|
+
upgrades.push({
|
|
488
|
+
kind: "index",
|
|
489
|
+
table: model.modelName,
|
|
490
|
+
target: name,
|
|
491
|
+
sql: `CREATE INDEX${dialect === "mysql" ? "" : " IF NOT EXISTS"} ${quoteSqlIdentifier(dialect, name)} ON ${quoteTableName(dialect, model.modelName)} (${columns});`
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
const entry = {
|
|
495
|
+
table: model.modelName,
|
|
496
|
+
missingColumns: remainingColumns,
|
|
497
|
+
extraColumns,
|
|
498
|
+
changedColumns,
|
|
499
|
+
missingIndexes: remainingIndexes,
|
|
500
|
+
extraIndexes: extraIndexes.map(({ name, columns, unique }) => ({ name, columns, unique })),
|
|
501
|
+
missingReferences,
|
|
502
|
+
extraReferences
|
|
503
|
+
};
|
|
504
|
+
if (hasSchemaDrift(entry)) drift.push(entry);
|
|
505
|
+
else if (!upgrades.some((upgrade) => upgrade.table === model.modelName)) {
|
|
506
|
+
upToDate.push(model.modelName);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return { dialect, statements, upgrades, upToDate, drift, addableForeignKeys };
|
|
510
|
+
}
|
|
511
|
+
async function describeSchemaTable(executor, dialect, table) {
|
|
512
|
+
const described = await describeTable(executor, dialect, table);
|
|
513
|
+
if (!described) {
|
|
514
|
+
if (dialect === "sqlite") return void 0;
|
|
515
|
+
const dot = table.indexOf(".");
|
|
516
|
+
if (dot > 0) {
|
|
517
|
+
return describeQualifiedTable(executor, dialect, table.slice(0, dot), table.slice(dot + 1));
|
|
518
|
+
}
|
|
519
|
+
if (dialect === "postgres") {
|
|
520
|
+
const schema = await findOnSearchPath(executor, table);
|
|
521
|
+
return schema ? describeQualifiedTable(executor, dialect, schema, table) : void 0;
|
|
522
|
+
}
|
|
523
|
+
return void 0;
|
|
524
|
+
}
|
|
525
|
+
return {
|
|
526
|
+
columns: described.columns.map(({ name, type, nullable, primaryKey }) => ({
|
|
527
|
+
name,
|
|
528
|
+
type,
|
|
529
|
+
nullable,
|
|
530
|
+
primaryKey
|
|
531
|
+
}))
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
async function describeQualifiedTable(executor, dialect, schema, table) {
|
|
535
|
+
const rows = await executor.query(
|
|
536
|
+
dialect === "mysql" ? "select column_name, column_type as type, is_nullable from information_schema.columns where table_schema = ? and table_name = ? order by ordinal_position" : "select column_name, data_type as type, is_nullable from information_schema.columns where table_schema = $1 and table_name = $2 order by ordinal_position",
|
|
537
|
+
[schema, table]
|
|
538
|
+
);
|
|
539
|
+
if (rows.length === 0) return void 0;
|
|
540
|
+
return {
|
|
541
|
+
columns: rows.map((row) => ({
|
|
542
|
+
name: String(readRowValue(row, "column_name")),
|
|
543
|
+
type: normalizeColumnType(dialect, String(readRowValue(row, "type"))),
|
|
544
|
+
nullable: String(readRowValue(row, "is_nullable")).toUpperCase() === "YES",
|
|
545
|
+
primaryKey: false
|
|
546
|
+
}))
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
async function findOnSearchPath(executor, table) {
|
|
550
|
+
const rows = await executor.query(
|
|
551
|
+
`select namespace.nspname as schema_name
|
|
552
|
+
from unnest(current_schemas(false)) with ordinality as path(name, position)
|
|
553
|
+
join pg_namespace namespace on namespace.nspname = path.name
|
|
554
|
+
join pg_class relation on relation.relnamespace = namespace.oid
|
|
555
|
+
where relation.relname = $1 and relation.relkind in ('r', 'p', 'v', 'f')
|
|
556
|
+
order by path.position
|
|
557
|
+
limit 1`,
|
|
558
|
+
[table]
|
|
559
|
+
);
|
|
560
|
+
const schema = rows[0] && readRowValue(rows[0], "schema_name");
|
|
561
|
+
return schema ? String(schema) : void 0;
|
|
562
|
+
}
|
|
563
|
+
async function describeTable(executor, dialect, table) {
|
|
564
|
+
if (dialect === "sqlite") {
|
|
565
|
+
return describeSqliteTable(executor, table);
|
|
566
|
+
}
|
|
567
|
+
const [sql, params] = dialect === "mysql" ? [
|
|
568
|
+
"select column_name, data_type, column_type, is_nullable, column_default from information_schema.columns where table_name = ? and table_schema = database() order by ordinal_position",
|
|
569
|
+
[table]
|
|
570
|
+
] : [
|
|
571
|
+
"select column_name, data_type, udt_name, is_nullable, column_default from information_schema.columns where table_name = $1 and table_schema = current_schema() order by ordinal_position",
|
|
572
|
+
[table]
|
|
573
|
+
];
|
|
574
|
+
const rows = await executor.query(sql, params);
|
|
575
|
+
if (rows.length === 0) return void 0;
|
|
576
|
+
const columns = rows.map((row) => ({
|
|
577
|
+
name: String(readRowValue(row, "column_name")),
|
|
578
|
+
type: normalizeColumnType(
|
|
579
|
+
dialect,
|
|
580
|
+
String(
|
|
581
|
+
readRowValue(row, dialect === "mysql" ? "column_type" : "data_type") ?? readRowValue(row, "data_type")
|
|
582
|
+
)
|
|
583
|
+
),
|
|
584
|
+
nullable: String(readRowValue(row, "is_nullable")).toUpperCase() === "YES",
|
|
585
|
+
rawDefault: nullableString(readRowValue(row, "column_default")),
|
|
586
|
+
primaryKey: false
|
|
587
|
+
}));
|
|
588
|
+
const indexes = await describeServerIndexes(executor, dialect, table);
|
|
589
|
+
const primaryColumns = new Set(
|
|
590
|
+
indexes.filter((index) => index.primary).flatMap((index) => index.columns.map((column) => column.toLowerCase()))
|
|
591
|
+
);
|
|
592
|
+
for (const column of columns) {
|
|
593
|
+
if (primaryColumns.has(column.name.toLowerCase())) {
|
|
594
|
+
column.primaryKey = true;
|
|
595
|
+
column.nullable = false;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
return {
|
|
599
|
+
columns,
|
|
600
|
+
indexes,
|
|
601
|
+
references: await describeServerReferences(executor, dialect, table)
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
async function describeSqliteTable(executor, table) {
|
|
605
|
+
const escapedTable = escapeSqlitePragmaValue(table);
|
|
606
|
+
const rows = await executor.query(`pragma table_info('${escapedTable}')`);
|
|
607
|
+
if (rows.length === 0) return void 0;
|
|
608
|
+
const columns = rows.map((row) => {
|
|
609
|
+
const primaryKey = Number(readRowValue(row, "pk") ?? 0) > 0;
|
|
610
|
+
return {
|
|
611
|
+
name: String(readRowValue(row, "name")),
|
|
612
|
+
type: normalizeColumnType("sqlite", String(readRowValue(row, "type") ?? "")),
|
|
613
|
+
nullable: !primaryKey && Number(readRowValue(row, "notnull") ?? 0) === 0,
|
|
614
|
+
rawDefault: nullableString(readRowValue(row, "dflt_value")),
|
|
615
|
+
primaryKey
|
|
616
|
+
};
|
|
617
|
+
});
|
|
618
|
+
const indexRows = await executor.query(`pragma index_list('${escapedTable}')`);
|
|
619
|
+
const indexes = [];
|
|
620
|
+
for (const row of indexRows) {
|
|
621
|
+
const name = String(readRowValue(row, "name"));
|
|
622
|
+
const columnRows = await executor.query(
|
|
623
|
+
`pragma index_info('${escapeSqlitePragmaValue(name)}')`
|
|
624
|
+
);
|
|
625
|
+
indexes.push({
|
|
626
|
+
name,
|
|
627
|
+
columns: columnRows.sort(
|
|
628
|
+
(left, right) => Number(readRowValue(left, "seqno") ?? 0) - Number(readRowValue(right, "seqno") ?? 0)
|
|
629
|
+
).map((column) => String(readRowValue(column, "name"))),
|
|
630
|
+
unique: asBoolean(readRowValue(row, "unique")),
|
|
631
|
+
primary: String(readRowValue(row, "origin") ?? "").toLowerCase() === "pk"
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
const referenceRows = await executor.query(`pragma foreign_key_list('${escapedTable}')`);
|
|
635
|
+
return {
|
|
636
|
+
columns,
|
|
637
|
+
indexes,
|
|
638
|
+
references: referenceRows.map((row) => ({
|
|
639
|
+
column: String(readRowValue(row, "from")),
|
|
640
|
+
referencedTable: String(readRowValue(row, "table")),
|
|
641
|
+
referencedColumn: String(readRowValue(row, "to")),
|
|
642
|
+
onDelete: normalizeDeleteAction(readRowValue(row, "on_delete"))
|
|
643
|
+
}))
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
async function describeServerIndexes(executor, dialect, table) {
|
|
647
|
+
const [sql, params] = dialect === "mysql" ? [
|
|
648
|
+
"select index_name, non_unique, column_name, seq_in_index from information_schema.statistics where table_name = ? and table_schema = database() order by index_name, seq_in_index",
|
|
649
|
+
[table]
|
|
650
|
+
] : [
|
|
651
|
+
`select index_class.relname as index_name,
|
|
652
|
+
index_info.indisunique as is_unique,
|
|
653
|
+
index_info.indisprimary as is_primary,
|
|
654
|
+
attribute.attname as column_name,
|
|
655
|
+
index_key.column_position
|
|
656
|
+
from pg_catalog.pg_class table_class
|
|
657
|
+
join pg_catalog.pg_namespace namespace on namespace.oid = table_class.relnamespace
|
|
658
|
+
join pg_catalog.pg_index index_info on index_info.indrelid = table_class.oid
|
|
659
|
+
join pg_catalog.pg_class index_class on index_class.oid = index_info.indexrelid
|
|
660
|
+
join lateral unnest(index_info.indkey) with ordinality as index_key(attnum, column_position) on true
|
|
661
|
+
left join pg_catalog.pg_attribute attribute
|
|
662
|
+
on attribute.attrelid = table_class.oid and attribute.attnum = index_key.attnum
|
|
663
|
+
where table_class.relname = $1
|
|
664
|
+
and namespace.nspname = current_schema()
|
|
665
|
+
and index_key.column_position <= index_info.indnkeyatts
|
|
666
|
+
order by index_class.relname, index_key.column_position`,
|
|
667
|
+
[table]
|
|
668
|
+
];
|
|
669
|
+
const rows = await executor.query(sql, params);
|
|
670
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
671
|
+
for (const row of rows) {
|
|
672
|
+
const name = String(readRowValue(row, "index_name"));
|
|
673
|
+
const index = grouped.get(name) ?? {
|
|
674
|
+
name,
|
|
675
|
+
columns: [],
|
|
676
|
+
unique: dialect === "mysql" ? Number(readRowValue(row, "non_unique") ?? 1) === 0 : asBoolean(readRowValue(row, "is_unique")),
|
|
677
|
+
primary: dialect === "mysql" ? name.toUpperCase() === "PRIMARY" : asBoolean(readRowValue(row, "is_primary")),
|
|
678
|
+
orderedColumns: []
|
|
679
|
+
};
|
|
680
|
+
const column = readRowValue(row, "column_name");
|
|
681
|
+
if (column !== void 0 && column !== null) {
|
|
682
|
+
index.orderedColumns.push({
|
|
683
|
+
position: Number(
|
|
684
|
+
readRowValue(row, dialect === "mysql" ? "seq_in_index" : "column_position") ?? 0
|
|
685
|
+
),
|
|
686
|
+
name: String(column)
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
grouped.set(name, index);
|
|
690
|
+
}
|
|
691
|
+
return [...grouped.values()].map(({ orderedColumns, ...index }) => ({
|
|
692
|
+
...index,
|
|
693
|
+
columns: orderedColumns.sort((left, right) => left.position - right.position).map((column) => column.name)
|
|
694
|
+
}));
|
|
695
|
+
}
|
|
696
|
+
async function describeServerReferences(executor, dialect, table) {
|
|
697
|
+
const [sql, params] = dialect === "mysql" ? [
|
|
698
|
+
`select key_columns.column_name,
|
|
699
|
+
key_columns.referenced_table_name as referenced_table,
|
|
700
|
+
key_columns.referenced_column_name as referenced_column,
|
|
701
|
+
referential.delete_rule
|
|
702
|
+
from information_schema.key_column_usage key_columns
|
|
703
|
+
join information_schema.referential_constraints referential
|
|
704
|
+
on referential.constraint_schema = key_columns.constraint_schema
|
|
705
|
+
and referential.constraint_name = key_columns.constraint_name
|
|
706
|
+
and referential.table_name = key_columns.table_name
|
|
707
|
+
where key_columns.table_schema = database()
|
|
708
|
+
and key_columns.table_name = ?
|
|
709
|
+
and key_columns.referenced_table_name is not null
|
|
710
|
+
order by key_columns.constraint_name, key_columns.ordinal_position`,
|
|
711
|
+
[table]
|
|
712
|
+
] : [
|
|
713
|
+
`select key_columns.column_name,
|
|
714
|
+
referenced_columns.table_name as referenced_table,
|
|
715
|
+
referenced_columns.column_name as referenced_column,
|
|
716
|
+
referential.delete_rule
|
|
717
|
+
from information_schema.table_constraints constraints
|
|
718
|
+
join information_schema.key_column_usage key_columns
|
|
719
|
+
on key_columns.constraint_catalog = constraints.constraint_catalog
|
|
720
|
+
and key_columns.constraint_schema = constraints.constraint_schema
|
|
721
|
+
and key_columns.constraint_name = constraints.constraint_name
|
|
722
|
+
join information_schema.referential_constraints referential
|
|
723
|
+
on referential.constraint_catalog = constraints.constraint_catalog
|
|
724
|
+
and referential.constraint_schema = constraints.constraint_schema
|
|
725
|
+
and referential.constraint_name = constraints.constraint_name
|
|
726
|
+
join information_schema.constraint_column_usage referenced_columns
|
|
727
|
+
on referenced_columns.constraint_catalog = referential.unique_constraint_catalog
|
|
728
|
+
and referenced_columns.constraint_schema = referential.unique_constraint_schema
|
|
729
|
+
and referenced_columns.constraint_name = referential.unique_constraint_name
|
|
730
|
+
where constraints.constraint_type = 'FOREIGN KEY'
|
|
731
|
+
and constraints.table_schema = current_schema()
|
|
732
|
+
and constraints.table_name = $1
|
|
733
|
+
order by constraints.constraint_name, key_columns.ordinal_position`,
|
|
734
|
+
[table]
|
|
735
|
+
];
|
|
736
|
+
const rows = await executor.query(sql, params);
|
|
737
|
+
return rows.map((row) => ({
|
|
738
|
+
column: String(readRowValue(row, "column_name")),
|
|
739
|
+
referencedTable: String(readRowValue(row, "referenced_table")),
|
|
740
|
+
referencedColumn: String(readRowValue(row, "referenced_column")),
|
|
741
|
+
onDelete: normalizeDeleteAction(readRowValue(row, "delete_rule"))
|
|
742
|
+
}));
|
|
743
|
+
}
|
|
744
|
+
function expectedColumnDefinition(field, dialect) {
|
|
745
|
+
return {
|
|
746
|
+
type: normalizeColumnType(dialect, getSqlColumnType(field, dialect)),
|
|
747
|
+
nullable: !field.primaryKey && isNullableField(field),
|
|
748
|
+
default: expectedDefault(field),
|
|
749
|
+
primaryKey: field.primaryKey === true
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
function actualColumnDefinition(column, field, dialect) {
|
|
753
|
+
return {
|
|
754
|
+
type: column.type,
|
|
755
|
+
nullable: column.nullable,
|
|
756
|
+
default: normalizeDatabaseDefault(column.rawDefault, field, dialect),
|
|
757
|
+
primaryKey: column.primaryKey
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
function expectedDefault(field) {
|
|
761
|
+
if (field.default === void 0) return null;
|
|
762
|
+
if (field.type === "datetime" && field.default === "now") return "CURRENT_TIMESTAMP";
|
|
763
|
+
if (typeof field.default === "string") return JSON.stringify(field.default);
|
|
764
|
+
if (typeof field.default === "number" || typeof field.default === "boolean") {
|
|
765
|
+
return String(field.default);
|
|
766
|
+
}
|
|
767
|
+
return null;
|
|
768
|
+
}
|
|
769
|
+
function normalizeDatabaseDefault(value, field, dialect) {
|
|
770
|
+
if (value === null) return null;
|
|
771
|
+
let normalized = stripWrappingParentheses(value.trim());
|
|
772
|
+
if (dialect === "postgres") {
|
|
773
|
+
normalized = normalized.replace(/::[\w\s"]+$/u, "");
|
|
774
|
+
}
|
|
775
|
+
if (field.type === "datetime" && /^(?:current_timestamp(?:\(\d+\))?|now\(\))$/iu.test(normalized)) {
|
|
776
|
+
return "CURRENT_TIMESTAMP";
|
|
777
|
+
}
|
|
778
|
+
if (field.type === "boolean") {
|
|
779
|
+
const booleanValue = stripSqlQuotes(normalized).toLowerCase();
|
|
780
|
+
if (["1", "true", "t", "b'1'"].includes(booleanValue)) return "true";
|
|
781
|
+
if (["0", "false", "f", "b'0'"].includes(booleanValue)) return "false";
|
|
782
|
+
}
|
|
783
|
+
if (field.type === "integer" || field.type === "number") {
|
|
784
|
+
return stripSqlQuotes(normalized);
|
|
785
|
+
}
|
|
786
|
+
if (["id", "uuid", "string", "text", "enum", "datetime"].includes(field.type)) {
|
|
787
|
+
return JSON.stringify(stripSqlQuotes(normalized).replace(/''/gu, "'"));
|
|
788
|
+
}
|
|
789
|
+
return normalized.toUpperCase();
|
|
790
|
+
}
|
|
791
|
+
function normalizeColumnType(dialect, value) {
|
|
792
|
+
const type = value.trim().toLowerCase().replace(/\s+/gu, " ");
|
|
793
|
+
if (dialect === "sqlite") {
|
|
794
|
+
if (/int/u.test(type)) return "integer";
|
|
795
|
+
if (/(?:char|clob|text)/u.test(type)) return "text";
|
|
796
|
+
if (/(?:real|floa|doub)/u.test(type)) return "real";
|
|
797
|
+
if (/blob/u.test(type) || type === "") return "blob";
|
|
798
|
+
return "numeric";
|
|
799
|
+
}
|
|
800
|
+
if (dialect === "mysql") {
|
|
801
|
+
if (/^(?:bool|boolean|tinyint\(1\))/u.test(type)) return "boolean";
|
|
802
|
+
if (/^(?:int|integer)(?:\(\d+\))?/u.test(type)) return "integer";
|
|
803
|
+
if (/^(?:double|double precision)/u.test(type)) return "double";
|
|
804
|
+
return type;
|
|
805
|
+
}
|
|
806
|
+
if (["int4", "integer"].includes(type)) return "integer";
|
|
807
|
+
if (["float8", "double precision"].includes(type)) return "double precision";
|
|
808
|
+
if (["timestamptz", "timestamp with time zone"].includes(type)) return "timestamptz";
|
|
809
|
+
return type;
|
|
810
|
+
}
|
|
811
|
+
function collectExpectedIndexes(model) {
|
|
812
|
+
const indexes = [];
|
|
813
|
+
for (const field of Object.values(model.model.fields)) {
|
|
814
|
+
if (field.index) {
|
|
815
|
+
indexes.push({
|
|
816
|
+
name: `${model.modelName}_${field.name}_idx`,
|
|
817
|
+
columns: [field.name],
|
|
818
|
+
unique: false
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
if (!field.primaryKey && field.unique) {
|
|
822
|
+
indexes.push({
|
|
823
|
+
name: `${model.modelName}_${field.name}_unique`,
|
|
824
|
+
columns: [field.name],
|
|
825
|
+
unique: true
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
for (const constraint of model.model.constraints ?? []) {
|
|
830
|
+
indexes.push({
|
|
831
|
+
name: constraint.name ?? `${model.modelName}_${constraint.fields.map((fieldKey) => model.model.fields[fieldKey]?.name ?? fieldKey).join("_")}_${constraint.type}`,
|
|
832
|
+
columns: constraint.fields.map((fieldKey) => model.model.fields[fieldKey]?.name ?? fieldKey),
|
|
833
|
+
unique: constraint.type === "unique"
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
return indexes;
|
|
837
|
+
}
|
|
838
|
+
function collectExpectedReferences(model, modelLookup) {
|
|
839
|
+
const references = [];
|
|
840
|
+
for (const field of Object.values(model.model.fields)) {
|
|
841
|
+
if (!field.reference || !isDatabaseEnforcedReference(field.reference)) continue;
|
|
842
|
+
const target = modelLookup.get(`${model.ownerKey}.${field.reference.model}`);
|
|
843
|
+
if (!target) continue;
|
|
844
|
+
references.push({
|
|
845
|
+
column: field.name,
|
|
846
|
+
referencedTable: target.modelName,
|
|
847
|
+
referencedColumn: target.model.fields[field.reference.field]?.name ?? field.reference.field,
|
|
848
|
+
onDelete: field.reference.onDelete ?? "noAction"
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
return references;
|
|
852
|
+
}
|
|
853
|
+
function compareDefinitions(expected, actual, signature) {
|
|
854
|
+
const remaining = [...actual];
|
|
855
|
+
const missing = [];
|
|
856
|
+
for (const expectedValue of expected) {
|
|
857
|
+
const expectedSignature = signature(expectedValue);
|
|
858
|
+
const actualIndex = remaining.findIndex(
|
|
859
|
+
(actualValue) => signature(actualValue) === expectedSignature
|
|
860
|
+
);
|
|
861
|
+
if (actualIndex === -1) missing.push(expectedValue);
|
|
862
|
+
else remaining.splice(actualIndex, 1);
|
|
863
|
+
}
|
|
864
|
+
return { missing, extra: remaining };
|
|
865
|
+
}
|
|
866
|
+
function indexSignature(index) {
|
|
867
|
+
return `${index.unique ? "unique" : "index"}:${index.columns.map((column) => column.toLowerCase()).join(",")}`;
|
|
868
|
+
}
|
|
869
|
+
function referenceSignature(reference) {
|
|
870
|
+
return [
|
|
871
|
+
reference.column,
|
|
872
|
+
reference.referencedTable,
|
|
873
|
+
reference.referencedColumn,
|
|
874
|
+
reference.onDelete
|
|
875
|
+
].map((value) => value.toLowerCase()).join(":");
|
|
876
|
+
}
|
|
877
|
+
function hasSchemaDrift(drift) {
|
|
878
|
+
return drift.missingColumns.length > 0 || drift.extraColumns.length > 0 || drift.changedColumns.length > 0 || drift.missingIndexes.length > 0 || drift.extraIndexes.length > 0 || drift.missingReferences.length > 0 || drift.extraReferences.length > 0;
|
|
879
|
+
}
|
|
880
|
+
function readRowValue(row, name) {
|
|
881
|
+
return row[name] ?? row[name.toUpperCase()];
|
|
882
|
+
}
|
|
883
|
+
function nullableString(value) {
|
|
884
|
+
return value === void 0 || value === null ? null : String(value);
|
|
885
|
+
}
|
|
886
|
+
function asBoolean(value) {
|
|
887
|
+
return value === true || value === 1 || value === "1" || String(value).toLowerCase() === "true";
|
|
888
|
+
}
|
|
889
|
+
function normalizeDeleteAction(value) {
|
|
890
|
+
switch (String(value ?? "NO ACTION").toUpperCase().replace(/[_\s]+/gu, "")) {
|
|
891
|
+
case "CASCADE":
|
|
892
|
+
return "cascade";
|
|
893
|
+
case "RESTRICT":
|
|
894
|
+
return "restrict";
|
|
895
|
+
case "SETNULL":
|
|
896
|
+
return "setNull";
|
|
897
|
+
default:
|
|
898
|
+
return "noAction";
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
function stripWrappingParentheses(value) {
|
|
902
|
+
let result = value;
|
|
903
|
+
while (result.startsWith("(") && result.endsWith(")")) {
|
|
904
|
+
result = result.slice(1, -1).trim();
|
|
905
|
+
}
|
|
906
|
+
return result;
|
|
907
|
+
}
|
|
908
|
+
function stripSqlQuotes(value) {
|
|
909
|
+
if (value.length >= 2 && (value.startsWith("'") && value.endsWith("'") || value.startsWith('"') && value.endsWith('"'))) {
|
|
910
|
+
return value.slice(1, -1);
|
|
911
|
+
}
|
|
912
|
+
return value;
|
|
913
|
+
}
|
|
914
|
+
function escapeSqlitePragmaValue(value) {
|
|
915
|
+
return value.replace(/'/gu, "''");
|
|
916
|
+
}
|
|
917
|
+
async function applySchemaMigration(plan, executor) {
|
|
918
|
+
const applied = [];
|
|
919
|
+
for (const statement of [...plan.statements, ...plan.upgrades ?? []]) {
|
|
920
|
+
await executor.execute(statement.sql);
|
|
921
|
+
applied.push(statement.target);
|
|
922
|
+
}
|
|
923
|
+
return { applied, skipped: plan.drift };
|
|
924
|
+
}
|
|
925
|
+
function columnTypeFamily(type) {
|
|
926
|
+
const value = type.trim().toLowerCase();
|
|
927
|
+
if (/^(bool|boolean|tinyint\(1\))/u.test(value)) return "boolean";
|
|
928
|
+
if (value.startsWith("uuid")) return "uuid";
|
|
929
|
+
if (/(char|text|clob|citext|string)/u.test(value)) return "text";
|
|
930
|
+
if (/^(int|integer|smallint|bigint|mediumint|tinyint|int[248]|serial|bigserial)/u.test(value)) {
|
|
931
|
+
return "integer";
|
|
932
|
+
}
|
|
933
|
+
if (/^(double|real|float|numeric|decimal|number)/u.test(value)) return "number";
|
|
934
|
+
if (/^(timestamp|datetime|date)/u.test(value)) return "datetime";
|
|
935
|
+
if (value.startsWith("json")) return "json";
|
|
936
|
+
return void 0;
|
|
937
|
+
}
|
|
938
|
+
async function planSchemaExtensions(extensions, dialect, executor) {
|
|
939
|
+
const plan = {
|
|
940
|
+
statements: [],
|
|
941
|
+
present: [],
|
|
942
|
+
missingTables: [],
|
|
943
|
+
conflicts: [],
|
|
944
|
+
unsupported: []
|
|
945
|
+
};
|
|
946
|
+
for (const extension of extensions) {
|
|
947
|
+
const table = await describeSchemaTable(executor, dialect, extension.table);
|
|
948
|
+
if (!table) {
|
|
949
|
+
plan.missingTables.push(extension);
|
|
950
|
+
continue;
|
|
951
|
+
}
|
|
952
|
+
for (const { fieldKey, field } of extension.fields) {
|
|
953
|
+
const existing = table.columns.find(
|
|
954
|
+
(column) => dialect === "postgres" ? column.name === field.name : column.name.toLowerCase() === field.name.toLowerCase()
|
|
955
|
+
);
|
|
956
|
+
const expected = getSqlColumnType(field, dialect);
|
|
957
|
+
if (existing) {
|
|
958
|
+
const mine = columnTypeFamily(expected);
|
|
959
|
+
const theirs = columnTypeFamily(existing.type);
|
|
960
|
+
if (dialect !== "sqlite" && mine && theirs && mine !== theirs) {
|
|
961
|
+
plan.conflicts.push({ extension, column: field.name, expected, actual: existing.type });
|
|
962
|
+
} else {
|
|
963
|
+
plan.present.push(`${extension.table}.${field.name}`);
|
|
964
|
+
}
|
|
965
|
+
continue;
|
|
966
|
+
}
|
|
967
|
+
const reason = unsupportedColumnReason(field, dialect);
|
|
968
|
+
if (reason) {
|
|
969
|
+
plan.unsupported.push({ extension, column: field.name, reason });
|
|
970
|
+
continue;
|
|
971
|
+
}
|
|
972
|
+
plan.statements.push({
|
|
973
|
+
kind: "column",
|
|
974
|
+
target: `${extension.table}.${field.name}`,
|
|
975
|
+
sql: addColumnStatement(dialect, extension.table, field),
|
|
976
|
+
extension,
|
|
977
|
+
fieldKey,
|
|
978
|
+
column: field.name
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
return plan;
|
|
983
|
+
}
|
|
984
|
+
function addColumnStatement(dialect, table, field) {
|
|
985
|
+
const defaultValue = getSqlDefaultExpression(field, dialect);
|
|
986
|
+
const parts = [
|
|
987
|
+
`ALTER TABLE ${quoteTableName(dialect, table)} ADD COLUMN`,
|
|
988
|
+
quoteSqlIdentifier(dialect, field.name),
|
|
989
|
+
getSqlColumnType(field, dialect),
|
|
990
|
+
...isNullableField(field) ? [] : ["NOT NULL"],
|
|
991
|
+
...defaultValue ? [`DEFAULT ${defaultValue}`] : []
|
|
992
|
+
];
|
|
993
|
+
return `${parts.join(" ")};`;
|
|
994
|
+
}
|
|
995
|
+
function unsupportedColumnReason(field, dialect) {
|
|
996
|
+
const type = getSqlColumnType(field, dialect);
|
|
997
|
+
const defaultValue = getSqlDefaultExpression(field, dialect);
|
|
998
|
+
if (dialect === "mysql" && defaultValue && (type === "TEXT" || type === "JSON")) {
|
|
999
|
+
return `MySQL cannot give a ${type} column a default. Make it nullable without a default.`;
|
|
1000
|
+
}
|
|
1001
|
+
if (dialect === "sqlite" && defaultValue === "CURRENT_TIMESTAMP") {
|
|
1002
|
+
return "SQLite cannot add a column whose default is the current time. Make it nullable.";
|
|
1003
|
+
}
|
|
1004
|
+
if (!isNullableField(field) && !defaultValue) {
|
|
1005
|
+
return "It is required but its default cannot be written in SQL. Make it nullable.";
|
|
1006
|
+
}
|
|
1007
|
+
return void 0;
|
|
1008
|
+
}
|
|
1009
|
+
function quoteTableName(dialect, table) {
|
|
1010
|
+
const dot = table.indexOf(".");
|
|
1011
|
+
if (dialect === "sqlite" || dot <= 0) return quoteSqlIdentifier(dialect, table);
|
|
1012
|
+
return `${quoteSqlIdentifier(dialect, table.slice(0, dot))}.${quoteSqlIdentifier(dialect, table.slice(dot + 1))}`;
|
|
1013
|
+
}
|
|
1014
|
+
function formatSchemaMigration(plan, owner, options = {}) {
|
|
1015
|
+
const header = [
|
|
1016
|
+
`-- Generated by \`farm ${owner} migrate\` from the ${owner} schema.`,
|
|
1017
|
+
`-- Dialect: ${plan.dialect}`,
|
|
1018
|
+
options.addsColumns || (plan.upgrades?.length ?? 0) > 0 ? "-- Review before applying. Existing tables only get what is added below; nothing is changed or dropped." : "-- Review before applying. Farm never alters existing tables."
|
|
1019
|
+
];
|
|
1020
|
+
const upgrades = plan.upgrades ?? [];
|
|
1021
|
+
if (plan.statements.length === 0 && upgrades.length === 0) {
|
|
1022
|
+
header.push("--", "-- Nothing to create: every declared model already has a table.");
|
|
1023
|
+
return `${header.join("\n")}
|
|
1024
|
+
`;
|
|
1025
|
+
}
|
|
1026
|
+
const sections = [
|
|
1027
|
+
...plan.statements.map((statement) => statement.sql),
|
|
1028
|
+
...upgrades.length > 0 ? [
|
|
1029
|
+
[
|
|
1030
|
+
"-- Added to tables that already exist:",
|
|
1031
|
+
...upgrades.map((statement) => statement.sql)
|
|
1032
|
+
].join("\n")
|
|
1033
|
+
] : []
|
|
1034
|
+
];
|
|
1035
|
+
return `${header.join("\n")}
|
|
1036
|
+
|
|
1037
|
+
${sections.join("\n\n")}
|
|
1038
|
+
`;
|
|
1039
|
+
}
|
|
1040
|
+
function describeSchemaDrift(drift) {
|
|
1041
|
+
return drift.map((entry) => {
|
|
1042
|
+
const lines = [` ${entry.table}`];
|
|
1043
|
+
if (entry.missingColumns.length > 0) {
|
|
1044
|
+
lines.push(` missing in the database: ${entry.missingColumns.join(", ")}`);
|
|
1045
|
+
}
|
|
1046
|
+
if (entry.extraColumns.length > 0) {
|
|
1047
|
+
lines.push(` not in the schema: ${entry.extraColumns.join(", ")}`);
|
|
1048
|
+
}
|
|
1049
|
+
for (const column of entry.changedColumns) {
|
|
1050
|
+
const differences = column.differences.map((difference) => {
|
|
1051
|
+
if (difference === "type") {
|
|
1052
|
+
return `type expected ${column.expected.type}, found ${column.actual.type}`;
|
|
1053
|
+
}
|
|
1054
|
+
if (difference === "nullability") {
|
|
1055
|
+
return `nullability expected ${column.expected.nullable ? "nullable" : "required"}, found ${column.actual.nullable ? "nullable" : "required"}`;
|
|
1056
|
+
}
|
|
1057
|
+
if (difference === "default") {
|
|
1058
|
+
return `default expected ${column.expected.default ?? "none"}, found ${column.actual.default ?? "none"}`;
|
|
1059
|
+
}
|
|
1060
|
+
return `primary key expected ${column.expected.primaryKey ? "yes" : "no"}, found ${column.actual.primaryKey ? "yes" : "no"}`;
|
|
1061
|
+
});
|
|
1062
|
+
lines.push(` changed column ${column.column}: ${differences.join("; ")}`);
|
|
1063
|
+
}
|
|
1064
|
+
if (entry.missingIndexes.length > 0) {
|
|
1065
|
+
lines.push(
|
|
1066
|
+
` missing indexes: ${entry.missingIndexes.map(formatIndexDefinition).join(", ")}`
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
if (entry.extraIndexes.length > 0) {
|
|
1070
|
+
lines.push(
|
|
1071
|
+
` not in the schema indexes: ${entry.extraIndexes.map(formatIndexDefinition).join(", ")}`
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
if (entry.missingReferences.length > 0) {
|
|
1075
|
+
lines.push(
|
|
1076
|
+
` missing references: ${entry.missingReferences.map(formatReferenceDefinition).join(", ")}`
|
|
1077
|
+
);
|
|
1078
|
+
}
|
|
1079
|
+
if (entry.extraReferences.length > 0) {
|
|
1080
|
+
lines.push(
|
|
1081
|
+
` not in the schema references: ${entry.extraReferences.map(formatReferenceDefinition).join(", ")}`
|
|
1082
|
+
);
|
|
1083
|
+
}
|
|
1084
|
+
return lines.join("\n");
|
|
1085
|
+
}).join("\n");
|
|
1086
|
+
}
|
|
1087
|
+
function formatIndexDefinition(index) {
|
|
1088
|
+
return `${index.name} (${index.unique ? "unique: " : ""}${index.columns.join(", ")})`;
|
|
1089
|
+
}
|
|
1090
|
+
function formatReferenceDefinition(reference) {
|
|
1091
|
+
return `${reference.column} -> ${reference.referencedTable}.${reference.referencedColumn} on delete ${reference.onDelete}`;
|
|
1092
|
+
}
|
|
1093
|
+
function createSchemaExecutor(client, owner) {
|
|
1094
|
+
const candidate = client;
|
|
1095
|
+
if (candidate && typeof candidate.getItem === "function" && typeof candidate.setItem === "function") {
|
|
1096
|
+
return null;
|
|
1097
|
+
}
|
|
1098
|
+
if (typeof candidate?.prepare === "function" && typeof candidate?.exec === "function") {
|
|
1099
|
+
return {
|
|
1100
|
+
dialect: "sqlite",
|
|
1101
|
+
executor: {
|
|
1102
|
+
async execute(sql) {
|
|
1103
|
+
candidate.exec(sql);
|
|
1104
|
+
},
|
|
1105
|
+
async query(sql) {
|
|
1106
|
+
return candidate.prepare(sql).all();
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
if (typeof candidate?.query === "function") {
|
|
1112
|
+
const isMysqlClient = typeof candidate.escapeId === "function" || typeof candidate.format === "function";
|
|
1113
|
+
return {
|
|
1114
|
+
dialect: isMysqlClient ? "mysql" : "postgres",
|
|
1115
|
+
executor: {
|
|
1116
|
+
async execute(sql) {
|
|
1117
|
+
await candidate.query(sql);
|
|
1118
|
+
},
|
|
1119
|
+
async query(sql, params) {
|
|
1120
|
+
const result = await candidate.query(sql, params);
|
|
1121
|
+
if (Array.isArray(result)) return result[0] ?? [];
|
|
1122
|
+
return result?.rows ?? [];
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
throw new Error(
|
|
1128
|
+
`${owner}: the configured client cannot run migrations. Pass a pg, mysql, or sqlite connection, or create the tables with your own migration tooling.`
|
|
1129
|
+
);
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
// src/schema-state.ts
|
|
1133
|
+
var literal = (dialect, value) => value === null ? "NULL" : `'${escapeSqlString(value, dialect)}'`;
|
|
1134
|
+
var FARM_SCHEMA_STATE_TABLE = "farm_schema_state";
|
|
1135
|
+
function createSchemaSnapshot(models) {
|
|
1136
|
+
const tables = {};
|
|
1137
|
+
for (const model of models) {
|
|
1138
|
+
const columns = {};
|
|
1139
|
+
const indexes = [];
|
|
1140
|
+
for (const field of Object.values(model.model.fields)) {
|
|
1141
|
+
columns[field.name] = {
|
|
1142
|
+
type: field.type,
|
|
1143
|
+
nullable: field.nullable === true || field.required === false,
|
|
1144
|
+
primaryKey: field.primaryKey === true,
|
|
1145
|
+
unique: field.unique === true,
|
|
1146
|
+
...field.default !== void 0 ? { default: field.default } : {}
|
|
1147
|
+
};
|
|
1148
|
+
if (field.index) indexes.push(`${model.modelName}_${field.name}_idx`);
|
|
1149
|
+
}
|
|
1150
|
+
for (const constraint of model.model.constraints ?? []) {
|
|
1151
|
+
indexes.push(
|
|
1152
|
+
constraint.name ?? `${model.modelName}_${constraint.fields.map((key) => model.model.fields[key]?.name ?? key).join("_")}_${constraint.type}`
|
|
1153
|
+
);
|
|
1154
|
+
}
|
|
1155
|
+
tables[model.modelName] = { columns, indexes: indexes.sort() };
|
|
1156
|
+
}
|
|
1157
|
+
return { tables };
|
|
1158
|
+
}
|
|
1159
|
+
function diffSchemaSnapshots(previous, next) {
|
|
1160
|
+
const changes = {
|
|
1161
|
+
addedTables: [],
|
|
1162
|
+
addedColumns: [],
|
|
1163
|
+
addedIndexes: [],
|
|
1164
|
+
otherChanges: [],
|
|
1165
|
+
removedColumns: []
|
|
1166
|
+
};
|
|
1167
|
+
for (const [table, definition] of Object.entries(next.tables)) {
|
|
1168
|
+
const before = previous.tables[table];
|
|
1169
|
+
if (!before) {
|
|
1170
|
+
changes.addedTables.push(table);
|
|
1171
|
+
continue;
|
|
1172
|
+
}
|
|
1173
|
+
for (const [column, columnDefinition] of Object.entries(definition.columns)) {
|
|
1174
|
+
const old = before.columns[column];
|
|
1175
|
+
if (!old) {
|
|
1176
|
+
changes.addedColumns.push({ table, column, type: columnDefinition.type });
|
|
1177
|
+
} else if (JSON.stringify(old) !== JSON.stringify(columnDefinition)) {
|
|
1178
|
+
changes.otherChanges.push(`${table}.${column} is redefined`);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
for (const [column, old] of Object.entries(before.columns)) {
|
|
1182
|
+
if (definition.columns[column]) continue;
|
|
1183
|
+
changes.otherChanges.push(`${table}.${column} is removed`);
|
|
1184
|
+
changes.removedColumns.push({ table, column, type: old.type });
|
|
1185
|
+
}
|
|
1186
|
+
for (const index of definition.indexes) {
|
|
1187
|
+
if (!before.indexes.includes(index)) changes.addedIndexes.push(index);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
for (const table of Object.keys(previous.tables)) {
|
|
1191
|
+
if (!next.tables[table]) changes.otherChanges.push(`${table} is removed`);
|
|
1192
|
+
}
|
|
1193
|
+
return changes;
|
|
1194
|
+
}
|
|
1195
|
+
function hasSchemaChanges(changes) {
|
|
1196
|
+
return changes.addedTables.length + changes.addedColumns.length + changes.addedIndexes.length + changes.otherChanges.length > 0;
|
|
1197
|
+
}
|
|
1198
|
+
async function readSchemaState(executor, dialect, owner) {
|
|
1199
|
+
const q = (name) => quoteSqlIdentifier(dialect, name);
|
|
1200
|
+
let rows;
|
|
1201
|
+
try {
|
|
1202
|
+
if (!await describeSchemaTable(executor, dialect, FARM_SCHEMA_STATE_TABLE)) return void 0;
|
|
1203
|
+
rows = await executor.query(
|
|
1204
|
+
`SELECT ${q("version")}, ${q("snapshot")}, ${q("applied_at")} FROM ${q(FARM_SCHEMA_STATE_TABLE)} WHERE ${q("owner")} = ${literal(dialect, owner)}`
|
|
1205
|
+
);
|
|
1206
|
+
} catch {
|
|
1207
|
+
return void 0;
|
|
1208
|
+
}
|
|
1209
|
+
const row = rows[0];
|
|
1210
|
+
if (!row) return void 0;
|
|
1211
|
+
const read = (name) => row[name] ?? row[name.toUpperCase()];
|
|
1212
|
+
try {
|
|
1213
|
+
const snapshot = read("snapshot");
|
|
1214
|
+
return {
|
|
1215
|
+
version: read("version") == null ? void 0 : String(read("version")),
|
|
1216
|
+
snapshot: typeof snapshot === "string" ? JSON.parse(snapshot) : snapshot,
|
|
1217
|
+
appliedAt: String(read("applied_at"))
|
|
1218
|
+
};
|
|
1219
|
+
} catch {
|
|
1220
|
+
return void 0;
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
async function writeSchemaState(executor, dialect, owner, state) {
|
|
1224
|
+
const q = (name) => quoteSqlIdentifier(dialect, name);
|
|
1225
|
+
const key = dialect === "mysql" ? "VARCHAR(191)" : "TEXT";
|
|
1226
|
+
await executor.execute(
|
|
1227
|
+
`CREATE TABLE IF NOT EXISTS ${q(FARM_SCHEMA_STATE_TABLE)} (${q("owner")} ${key} PRIMARY KEY, ${q("version")} ${dialect === "mysql" ? "VARCHAR(255)" : "TEXT"}, ${q("snapshot")} ${dialect === "mysql" ? "LONGTEXT" : "TEXT"} NOT NULL, ${q("applied_at")} ${dialect === "mysql" ? "VARCHAR(64)" : "TEXT"} NOT NULL)`
|
|
1228
|
+
);
|
|
1229
|
+
const values = [
|
|
1230
|
+
literal(dialect, owner),
|
|
1231
|
+
literal(dialect, state.version ?? null),
|
|
1232
|
+
literal(dialect, JSON.stringify(state.snapshot)),
|
|
1233
|
+
literal(dialect, (/* @__PURE__ */ new Date()).toISOString())
|
|
1234
|
+
];
|
|
1235
|
+
await executor.execute(
|
|
1236
|
+
`DELETE FROM ${q(FARM_SCHEMA_STATE_TABLE)} WHERE ${q("owner")} = ${values[0]}`
|
|
1237
|
+
);
|
|
1238
|
+
await executor.execute(
|
|
1239
|
+
`INSERT INTO ${q(FARM_SCHEMA_STATE_TABLE)} (${q("owner")}, ${q("version")}, ${q("snapshot")}, ${q("applied_at")}) VALUES (${values.join(", ")})`
|
|
1240
|
+
);
|
|
1241
|
+
}
|
|
1242
|
+
function describeSchemaChanges(changes) {
|
|
1243
|
+
return [
|
|
1244
|
+
...changes.addedTables.map((table) => ` + ${table} new table`),
|
|
1245
|
+
...changes.addedColumns.map(({ table, column, type }) => ` + ${table}.${column} ${type}`),
|
|
1246
|
+
...changes.addedIndexes.map((index) => ` + ${index} index`),
|
|
1247
|
+
...changes.otherChanges.map((change) => ` ~ ${change} (Farm will not do this on its own)`)
|
|
1248
|
+
];
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
// src/schema-steps.ts
|
|
1252
|
+
var FARM_SCHEMA_STEPS_TABLE = "farm_schema_steps";
|
|
1253
|
+
function schemaStepChecksum(step) {
|
|
1254
|
+
const { description: _description, ...definition } = step;
|
|
1255
|
+
let hash = 2166136261;
|
|
1256
|
+
for (const character of JSON.stringify(definition)) {
|
|
1257
|
+
hash ^= character.codePointAt(0);
|
|
1258
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
1259
|
+
}
|
|
1260
|
+
return hash.toString(16).padStart(8, "0");
|
|
1261
|
+
}
|
|
1262
|
+
var literal2 = (dialect, value) => `'${escapeSqlString(value, dialect)}'`;
|
|
1263
|
+
async function readAppliedSchemaSteps(executor, dialect, owner) {
|
|
1264
|
+
const applied = /* @__PURE__ */ new Map();
|
|
1265
|
+
try {
|
|
1266
|
+
if (!await describeSchemaTable(executor, dialect, FARM_SCHEMA_STEPS_TABLE)) return applied;
|
|
1267
|
+
const q = (name) => quoteSqlIdentifier(dialect, name);
|
|
1268
|
+
const rows = await executor.query(
|
|
1269
|
+
`SELECT ${q("id")}, ${q("checksum")} FROM ${q(FARM_SCHEMA_STEPS_TABLE)} WHERE ${q("owner")} = ${literal2(dialect, owner)}`
|
|
1270
|
+
);
|
|
1271
|
+
for (const row of rows) {
|
|
1272
|
+
const read = (name) => row[name] ?? row[name.toUpperCase()];
|
|
1273
|
+
applied.set(String(read("id")), String(read("checksum")));
|
|
1274
|
+
}
|
|
1275
|
+
} catch {
|
|
1276
|
+
}
|
|
1277
|
+
return applied;
|
|
1278
|
+
}
|
|
1279
|
+
function stepsTableStatement(dialect) {
|
|
1280
|
+
const q = (name) => quoteSqlIdentifier(dialect, name);
|
|
1281
|
+
const key = dialect === "mysql" ? "VARCHAR(191)" : "TEXT";
|
|
1282
|
+
return `CREATE TABLE IF NOT EXISTS ${q(FARM_SCHEMA_STEPS_TABLE)} (${q("owner")} ${key} NOT NULL, ${q("id")} ${key} NOT NULL, ${q("checksum")} ${dialect === "mysql" ? "VARCHAR(64)" : "TEXT"} NOT NULL, ${q("applied_at")} ${dialect === "mysql" ? "VARCHAR(64)" : "TEXT"} NOT NULL, PRIMARY KEY (${q("owner")}, ${q("id")}))`;
|
|
1283
|
+
}
|
|
1284
|
+
function recordStatement(dialect, owner, step) {
|
|
1285
|
+
const q = (name) => quoteSqlIdentifier(dialect, name);
|
|
1286
|
+
return `INSERT INTO ${q(FARM_SCHEMA_STEPS_TABLE)} (${q("owner")}, ${q("id")}, ${q("checksum")}, ${q("applied_at")}) VALUES (${[owner, step.id, schemaStepChecksum(step), (/* @__PURE__ */ new Date()).toISOString()].map((value) => literal2(dialect, value)).join(", ")})`;
|
|
1287
|
+
}
|
|
1288
|
+
async function planSchemaSteps(input) {
|
|
1289
|
+
const { owner, dialect, executor, applied } = input;
|
|
1290
|
+
const plan = { steps: [], edited: [], fresh: input.fresh };
|
|
1291
|
+
const models = resolveSchemaModels(owner, input.schema);
|
|
1292
|
+
const q = (name) => quoteSqlIdentifier(dialect, name);
|
|
1293
|
+
const columnsOf = async (table) => (await describeSchemaTable(executor, dialect, table))?.columns.map((column) => column.name);
|
|
1294
|
+
const has = (columns, name) => Boolean(
|
|
1295
|
+
columns?.some(
|
|
1296
|
+
(column) => dialect === "postgres" ? column === name : column.toLowerCase() === name.toLowerCase()
|
|
1297
|
+
)
|
|
1298
|
+
);
|
|
1299
|
+
for (const step of input.steps) {
|
|
1300
|
+
const recorded = applied.get(step.id);
|
|
1301
|
+
if (recorded !== void 0) {
|
|
1302
|
+
if (recorded !== schemaStepChecksum(step)) plan.edited.push(step.id);
|
|
1303
|
+
continue;
|
|
1304
|
+
}
|
|
1305
|
+
if (input.fresh) {
|
|
1306
|
+
plan.steps.push({
|
|
1307
|
+
step,
|
|
1308
|
+
summary: summarize(step, models),
|
|
1309
|
+
phase: "before",
|
|
1310
|
+
statements: [],
|
|
1311
|
+
state: "record"
|
|
1312
|
+
});
|
|
1313
|
+
continue;
|
|
1314
|
+
}
|
|
1315
|
+
if ("renameColumn" in step) {
|
|
1316
|
+
const table = models[step.renameColumn.model].name;
|
|
1317
|
+
const to = models[step.renameColumn.model].fields[step.renameColumn.to].name;
|
|
1318
|
+
const from = step.renameColumn.from;
|
|
1319
|
+
const columns = await columnsOf(table);
|
|
1320
|
+
const summary = `rename ${table}.${from} \u2192 ${table}.${to}`;
|
|
1321
|
+
const planned = {
|
|
1322
|
+
step,
|
|
1323
|
+
summary,
|
|
1324
|
+
phase: "before",
|
|
1325
|
+
statements: [`ALTER TABLE ${q(table)} RENAME COLUMN ${q(from)} TO ${q(to)}`],
|
|
1326
|
+
state: "run"
|
|
1327
|
+
};
|
|
1328
|
+
if (!columns) {
|
|
1329
|
+
Object.assign(planned, { state: "blocked", reason: `"${table}" does not exist.` });
|
|
1330
|
+
} else if (has(columns, from) && has(columns, to)) {
|
|
1331
|
+
Object.assign(planned, {
|
|
1332
|
+
state: "blocked",
|
|
1333
|
+
reason: `both "${from}" and "${to}" exist, so renaming would lose one. Move the data and drop one column yourself.`
|
|
1334
|
+
});
|
|
1335
|
+
} else if (!has(columns, from)) {
|
|
1336
|
+
Object.assign(planned, {
|
|
1337
|
+
state: has(columns, to) ? "record" : "blocked",
|
|
1338
|
+
statements: [],
|
|
1339
|
+
...has(columns, to) ? {} : { reason: `"${table}" has neither "${from}" nor "${to}".` }
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
plan.steps.push(planned);
|
|
1343
|
+
} else if ("renameTable" in step) {
|
|
1344
|
+
const to = models[step.renameTable.to].name;
|
|
1345
|
+
const from = step.renameTable.from;
|
|
1346
|
+
const summary = `rename table ${from} \u2192 ${to}`;
|
|
1347
|
+
const [hasFrom, hasTo] = [Boolean(await columnsOf(from)), Boolean(await columnsOf(to))];
|
|
1348
|
+
plan.steps.push({
|
|
1349
|
+
step,
|
|
1350
|
+
summary,
|
|
1351
|
+
phase: "before",
|
|
1352
|
+
statements: hasFrom && !hasTo ? [
|
|
1353
|
+
dialect === "mysql" ? `RENAME TABLE ${q(from)} TO ${q(to)}` : `ALTER TABLE ${q(from)} RENAME TO ${q(to)}`
|
|
1354
|
+
] : [],
|
|
1355
|
+
state: hasFrom && !hasTo ? "run" : hasTo && !hasFrom ? "record" : "blocked",
|
|
1356
|
+
...hasFrom && hasTo ? { reason: `both "${from}" and "${to}" exist, so renaming would lose one.` } : !hasFrom && !hasTo ? { reason: `neither "${from}" nor "${to}" exists.` } : {}
|
|
1357
|
+
});
|
|
1358
|
+
} else if ("dropColumn" in step) {
|
|
1359
|
+
const table = models[step.dropColumn.model].name;
|
|
1360
|
+
const column = step.dropColumn.column;
|
|
1361
|
+
const columns = await columnsOf(table);
|
|
1362
|
+
const summary = `drop ${table}.${column}`;
|
|
1363
|
+
const created = Boolean(input.recorded?.tables[table]?.columns[column]);
|
|
1364
|
+
const planned = {
|
|
1365
|
+
step,
|
|
1366
|
+
summary,
|
|
1367
|
+
phase: "before",
|
|
1368
|
+
statements: [`ALTER TABLE ${q(table)} DROP COLUMN ${q(column)}`],
|
|
1369
|
+
state: "run",
|
|
1370
|
+
destructive: true
|
|
1371
|
+
};
|
|
1372
|
+
if (!columns) {
|
|
1373
|
+
Object.assign(planned, { state: "blocked", reason: `"${table}" does not exist.` });
|
|
1374
|
+
} else if (!has(columns, column)) {
|
|
1375
|
+
Object.assign(planned, { state: "record", statements: [] });
|
|
1376
|
+
} else if (!created) {
|
|
1377
|
+
Object.assign(planned, {
|
|
1378
|
+
state: "blocked",
|
|
1379
|
+
reason: `Farm has no record of ${owner} creating "${table}.${column}", so it will not drop it. Drop it yourself if it is no longer needed.`
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
plan.steps.push(planned);
|
|
1383
|
+
} else if ("dropTable" in step) {
|
|
1384
|
+
const table = step.dropTable.table;
|
|
1385
|
+
const exists = Boolean(await columnsOf(table));
|
|
1386
|
+
const created = Boolean(input.recorded?.tables[table]);
|
|
1387
|
+
const ownedElsewhere = [...input.othersTables ?? []].some(
|
|
1388
|
+
(other) => other.toLowerCase() === table.toLowerCase()
|
|
1389
|
+
);
|
|
1390
|
+
plan.steps.push({
|
|
1391
|
+
step,
|
|
1392
|
+
summary: `drop table ${table}`,
|
|
1393
|
+
phase: "before",
|
|
1394
|
+
statements: exists ? [`DROP TABLE ${q(table)}`] : [],
|
|
1395
|
+
destructive: true,
|
|
1396
|
+
...!exists ? { state: "record" } : ownedElsewhere ? {
|
|
1397
|
+
state: "blocked",
|
|
1398
|
+
reason: `another plugin creates "${table}", so ${owner} will not drop it.`
|
|
1399
|
+
} : !created ? {
|
|
1400
|
+
state: "blocked",
|
|
1401
|
+
reason: `Farm has no record of ${owner} creating "${table}", so it will not drop it. Drop it yourself if it is no longer needed.`
|
|
1402
|
+
} : { state: "run" }
|
|
1403
|
+
});
|
|
1404
|
+
} else {
|
|
1405
|
+
const sql = step.sql[dialect];
|
|
1406
|
+
const statements = sql === void 0 ? [] : typeof sql === "string" ? [sql] : [...sql];
|
|
1407
|
+
plan.steps.push({
|
|
1408
|
+
step,
|
|
1409
|
+
summary: step.description ?? `custom SQL (${step.id})`,
|
|
1410
|
+
phase: step.before ? "before" : "after",
|
|
1411
|
+
statements,
|
|
1412
|
+
state: sql === void 0 ? "blocked" : "run",
|
|
1413
|
+
...sql === void 0 ? { reason: `it has no SQL for ${dialect}.` } : {}
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
return plan;
|
|
1418
|
+
}
|
|
1419
|
+
function summarize(step, models) {
|
|
1420
|
+
if ("renameColumn" in step) {
|
|
1421
|
+
const model = models[step.renameColumn.model];
|
|
1422
|
+
return `rename ${model.name}.${step.renameColumn.from} \u2192 ${model.name}.${model.fields[step.renameColumn.to].name}`;
|
|
1423
|
+
}
|
|
1424
|
+
if ("renameTable" in step) {
|
|
1425
|
+
return `rename table ${step.renameTable.from} \u2192 ${models[step.renameTable.to].name}`;
|
|
1426
|
+
}
|
|
1427
|
+
if ("dropColumn" in step) {
|
|
1428
|
+
return `drop ${models[step.dropColumn.model].name}.${step.dropColumn.column}`;
|
|
1429
|
+
}
|
|
1430
|
+
if ("dropTable" in step) return `drop table ${step.dropTable.table}`;
|
|
1431
|
+
return step.description ?? `custom SQL (${step.id})`;
|
|
1432
|
+
}
|
|
1433
|
+
async function runSchemaStep(executor, dialect, owner, planned) {
|
|
1434
|
+
await executor.execute(stepsTableStatement(dialect));
|
|
1435
|
+
const statements = [
|
|
1436
|
+
...planned.state === "run" ? planned.statements : [],
|
|
1437
|
+
recordStatement(dialect, owner, planned.step)
|
|
1438
|
+
];
|
|
1439
|
+
if (dialect === "postgres") {
|
|
1440
|
+
await executor.execute(
|
|
1441
|
+
statements.map((statement) => statement.replace(/;\s*$/u, "")).join(";\n")
|
|
1442
|
+
);
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
if (dialect === "sqlite") {
|
|
1446
|
+
await executor.execute("BEGIN");
|
|
1447
|
+
try {
|
|
1448
|
+
for (const statement of statements) await executor.execute(statement);
|
|
1449
|
+
await executor.execute("COMMIT");
|
|
1450
|
+
} catch (error) {
|
|
1451
|
+
await executor.execute("ROLLBACK").catch(() => {
|
|
1452
|
+
});
|
|
1453
|
+
throw error;
|
|
1454
|
+
}
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
for (const statement of statements) await executor.execute(statement);
|
|
1458
|
+
}
|
|
1459
|
+
function withoutRenameTargets(models, stepPlan) {
|
|
1460
|
+
const pending = (stepPlan?.steps ?? []).filter((planned) => planned.state === "run");
|
|
1461
|
+
if (pending.length === 0) return models;
|
|
1462
|
+
const tables = /* @__PURE__ */ new Set();
|
|
1463
|
+
const columns = /* @__PURE__ */ new Map();
|
|
1464
|
+
for (const { step } of pending) {
|
|
1465
|
+
if ("renameTable" in step) tables.add(step.renameTable.to);
|
|
1466
|
+
if ("renameColumn" in step) {
|
|
1467
|
+
const set = columns.get(step.renameColumn.model) ?? /* @__PURE__ */ new Set();
|
|
1468
|
+
set.add(step.renameColumn.to);
|
|
1469
|
+
columns.set(step.renameColumn.model, set);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
return models.filter((model) => !tables.has(model.modelKey)).map((model) => {
|
|
1473
|
+
const skip = columns.get(model.modelKey);
|
|
1474
|
+
if (!skip) return model;
|
|
1475
|
+
const fields = Object.fromEntries(
|
|
1476
|
+
Object.entries(model.model.fields).filter(([key]) => !skip.has(key))
|
|
1477
|
+
);
|
|
1478
|
+
return { ...model, model: { ...model.model, fields } };
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
async function planOwnerSchemaSteps(input) {
|
|
1482
|
+
const applied = input.readApplied === false ? /* @__PURE__ */ new Map() : await readAppliedSchemaSteps(input.executor, input.dialect, input.owner);
|
|
1483
|
+
const candidates = [
|
|
1484
|
+
...input.tables,
|
|
1485
|
+
...input.steps.flatMap((step) => "renameTable" in step ? [step.renameTable.from] : [])
|
|
1486
|
+
];
|
|
1487
|
+
let fresh = applied.size === 0;
|
|
1488
|
+
for (const table of candidates) {
|
|
1489
|
+
if (!fresh) break;
|
|
1490
|
+
if (await describeSchemaTable(input.executor, input.dialect, table)) fresh = false;
|
|
1491
|
+
}
|
|
1492
|
+
const recorded = input.readApplied === false ? void 0 : (await readSchemaState(input.executor, input.dialect, input.owner))?.snapshot;
|
|
1493
|
+
return planSchemaSteps({ ...input, applied, fresh, recorded });
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
// src/schema-foreign-keys.ts
|
|
1497
|
+
async function planCrossOwnerReferences(owner, others, dialect, executor) {
|
|
1498
|
+
const plan = { eligible: [], waiting: [], skipped: [] };
|
|
1499
|
+
const own = resolveSchemaModels(owner.name, owner.schema);
|
|
1500
|
+
const creators = /* @__PURE__ */ new Map();
|
|
1501
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
1502
|
+
for (const other of others) {
|
|
1503
|
+
if (other.name === owner.name) continue;
|
|
1504
|
+
try {
|
|
1505
|
+
for (const model of collectSchemaModels([[other.name, other.schema, other.models]])) {
|
|
1506
|
+
creators.set(model.modelName.toLowerCase(), { owner: other.name, model });
|
|
1507
|
+
byKey.set(model.modelKey, model);
|
|
1508
|
+
}
|
|
1509
|
+
} catch {
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
for (const model of collectSchemaModels([[owner.name, owner.schema, owner.models]])) {
|
|
1513
|
+
for (const [fieldKey, field] of Object.entries(model.model.fields)) {
|
|
1514
|
+
const reference = field.reference;
|
|
1515
|
+
if (!reference || !isDatabaseEnforcedReference(reference)) continue;
|
|
1516
|
+
const described = Object.prototype.hasOwnProperty.call(own, reference.model) ? own[reference.model].name : byKey.get(reference.model)?.modelName;
|
|
1517
|
+
const creator = described ? creators.get(described.toLowerCase()) : void 0;
|
|
1518
|
+
if (!creator) continue;
|
|
1519
|
+
const target = Object.entries(creator.model.model.fields).find(
|
|
1520
|
+
([key, candidate]) => key === reference.field || candidate.name === reference.field
|
|
1521
|
+
)?.[1];
|
|
1522
|
+
const entry = {
|
|
1523
|
+
owner: owner.name,
|
|
1524
|
+
modelKey: model.modelKey,
|
|
1525
|
+
fieldKey,
|
|
1526
|
+
table: model.modelName,
|
|
1527
|
+
column: field.name,
|
|
1528
|
+
referencedOwner: creator.owner,
|
|
1529
|
+
referencedTable: creator.model.modelName,
|
|
1530
|
+
referencedColumn: target?.name ?? reference.field,
|
|
1531
|
+
onDelete: reference.onDelete ?? "noAction"
|
|
1532
|
+
};
|
|
1533
|
+
if (!target || !(target.primaryKey || target.unique)) {
|
|
1534
|
+
plan.skipped.push({
|
|
1535
|
+
reference: entry,
|
|
1536
|
+
reason: `"${entry.referencedTable}.${entry.referencedColumn}" is not its primary key or unique.`
|
|
1537
|
+
});
|
|
1538
|
+
continue;
|
|
1539
|
+
}
|
|
1540
|
+
const mine = columnTypeFamily(getSqlColumnType(field, dialect));
|
|
1541
|
+
const theirs = columnTypeFamily(getSqlColumnType(target, dialect));
|
|
1542
|
+
if (dialect !== "sqlite" && mine !== theirs) {
|
|
1543
|
+
plan.skipped.push({ reference: entry, reason: "the column types differ." });
|
|
1544
|
+
continue;
|
|
1545
|
+
}
|
|
1546
|
+
const table = await describeSchemaTable(executor, dialect, entry.referencedTable);
|
|
1547
|
+
if (!table) {
|
|
1548
|
+
plan.waiting.push(entry);
|
|
1549
|
+
continue;
|
|
1550
|
+
}
|
|
1551
|
+
const column = table.columns.find(
|
|
1552
|
+
(candidate) => dialect === "postgres" ? candidate.name === entry.referencedColumn : candidate.name.toLowerCase() === entry.referencedColumn.toLowerCase()
|
|
1553
|
+
);
|
|
1554
|
+
if (!column) {
|
|
1555
|
+
plan.skipped.push({
|
|
1556
|
+
reference: entry,
|
|
1557
|
+
reason: `"${entry.referencedTable}" has no column "${entry.referencedColumn}".`
|
|
1558
|
+
});
|
|
1559
|
+
continue;
|
|
1560
|
+
}
|
|
1561
|
+
plan.eligible.push(entry);
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
return plan;
|
|
1565
|
+
}
|
|
1566
|
+
function isForeignKeyAllowed(allowForeignKeys, reference) {
|
|
1567
|
+
if (!allowForeignKeys || !Object.prototype.hasOwnProperty.call(allowForeignKeys, reference.owner)) {
|
|
1568
|
+
return false;
|
|
1569
|
+
}
|
|
1570
|
+
const allowed = allowForeignKeys[reference.owner] ?? [];
|
|
1571
|
+
return allowed.includes(reference.modelKey) || allowed.includes(reference.table);
|
|
1572
|
+
}
|
|
1573
|
+
function describeForeignKeyApproval(reference) {
|
|
1574
|
+
return `schema: { allowForeignKeys: { ${JSON.stringify(reference.owner)}: [${JSON.stringify(reference.modelKey)}] } }`;
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
// src/schema-tables.ts
|
|
1578
|
+
function findSchemaTableOwners(config) {
|
|
1579
|
+
const integrations = config.integrations;
|
|
1580
|
+
const candidates = [
|
|
1581
|
+
...config.plugins ?? [],
|
|
1582
|
+
...Array.isArray(integrations) ? integrations : Object.values(integrations ?? {})
|
|
1583
|
+
];
|
|
1584
|
+
const owners = [];
|
|
1585
|
+
for (const candidate of candidates) {
|
|
1586
|
+
const declaration = readSchemaTables(candidate);
|
|
1587
|
+
if (declaration && !owners.some((owner) => owner.name === declaration.name)) {
|
|
1588
|
+
owners.push(declaration);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
return owners;
|
|
1592
|
+
}
|
|
1593
|
+
function collectOwnerModels(owner) {
|
|
1594
|
+
return collectSchemaModels([[owner.name, owner.schema, owner.models]]);
|
|
1595
|
+
}
|
|
1596
|
+
var emptyExtensionPlan = () => ({
|
|
1597
|
+
statements: [],
|
|
1598
|
+
present: [],
|
|
1599
|
+
missingTables: [],
|
|
1600
|
+
conflicts: [],
|
|
1601
|
+
unsupported: []
|
|
1602
|
+
});
|
|
1603
|
+
async function migrateSchemaTables(owner, options = {}) {
|
|
1604
|
+
const log = options.log ?? (() => {
|
|
1605
|
+
});
|
|
1606
|
+
const client = await owner.resolveClient(options.config ?? {});
|
|
1607
|
+
const adapter = createSchemaExecutor(client, owner.name);
|
|
1608
|
+
if (!adapter) {
|
|
1609
|
+
log(
|
|
1610
|
+
`Nothing to create: ${owner.name} stores data through a storage mount, which has no tables.`
|
|
1611
|
+
);
|
|
1612
|
+
return {
|
|
1613
|
+
plan: { dialect: "sqlite", statements: [], upToDate: [], drift: [] },
|
|
1614
|
+
sql: "",
|
|
1615
|
+
applied: [],
|
|
1616
|
+
extensions: { ...emptyExtensionPlan(), unapproved: [], pending: [] },
|
|
1617
|
+
foreignKeys: { waiting: [], unapproved: [], unsupported: [], blocked: [] },
|
|
1618
|
+
steps: { ran: [], pending: [] },
|
|
1619
|
+
planned: 0
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1622
|
+
const { executor } = adapter;
|
|
1623
|
+
const dialect = owner.dialect ?? adapter.dialect;
|
|
1624
|
+
const schemaConfig = options.config?.schema;
|
|
1625
|
+
const reportOnly = options.extensions === "report";
|
|
1626
|
+
const applying = Boolean(options.apply) && !reportOnly;
|
|
1627
|
+
const steps = owner.migrations ?? [];
|
|
1628
|
+
let stepPlan;
|
|
1629
|
+
const stepsRan = [];
|
|
1630
|
+
let stepsStopped;
|
|
1631
|
+
if (steps.length > 0) {
|
|
1632
|
+
const othersTables = new Set(
|
|
1633
|
+
(options.config ? findSchemaTableOwners(options.config) : []).filter((other) => other.name !== owner.name).flatMap((other) => {
|
|
1634
|
+
try {
|
|
1635
|
+
return collectOwnerModels(other).map((model) => model.modelName);
|
|
1636
|
+
} catch {
|
|
1637
|
+
return [];
|
|
1638
|
+
}
|
|
1639
|
+
})
|
|
1640
|
+
);
|
|
1641
|
+
stepPlan = await planOwnerSchemaSteps({
|
|
1642
|
+
owner: owner.name,
|
|
1643
|
+
schema: owner.schema,
|
|
1644
|
+
steps,
|
|
1645
|
+
tables: collectOwnerModels(owner).map((model) => model.modelName),
|
|
1646
|
+
dialect,
|
|
1647
|
+
executor,
|
|
1648
|
+
readApplied: !reportOnly,
|
|
1649
|
+
othersTables
|
|
1650
|
+
});
|
|
1651
|
+
for (const id of stepPlan.edited) {
|
|
1652
|
+
log(
|
|
1653
|
+
`Migration step "${id}" changed after it ran here. Farm never runs a step twice; review the change yourself.`
|
|
1654
|
+
);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
const runSteps = async (phase) => {
|
|
1658
|
+
for (const planned of stepPlan?.steps ?? []) {
|
|
1659
|
+
if (stepsStopped) return;
|
|
1660
|
+
if (planned.phase !== phase) continue;
|
|
1661
|
+
if (planned.state === "run" && planned.destructive && !options.allowDestructive) {
|
|
1662
|
+
stepsStopped = planned;
|
|
1663
|
+
log(
|
|
1664
|
+
`Stopped at migration step "${planned.step.id}" (${planned.summary}): it deletes data. Run again with --allow-destructive to let it. Later steps wait.`
|
|
1665
|
+
);
|
|
1666
|
+
return;
|
|
1667
|
+
}
|
|
1668
|
+
if (planned.state === "blocked") {
|
|
1669
|
+
stepsStopped = planned;
|
|
1670
|
+
log(
|
|
1671
|
+
`Stopped at migration step "${planned.step.id}" (${planned.summary}): ${planned.reason} Later steps wait for it.`
|
|
1672
|
+
);
|
|
1673
|
+
return;
|
|
1674
|
+
}
|
|
1675
|
+
await runSchemaStep(executor, dialect, owner.name, planned);
|
|
1676
|
+
stepsRan.push(planned.step.id);
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
1679
|
+
if (applying) await runSteps("before");
|
|
1680
|
+
const models = collectOwnerModels(owner);
|
|
1681
|
+
const planningModels = applying ? models : withoutRenameTargets(models, stepPlan);
|
|
1682
|
+
const others = options.config ? findSchemaTableOwners(options.config) : [];
|
|
1683
|
+
const crossOwner = await planCrossOwnerReferences(owner, others, dialect, executor);
|
|
1684
|
+
for (const reference of crossOwner.eligible) {
|
|
1685
|
+
const model = planningModels.find((candidate) => candidate.modelKey === reference.modelKey);
|
|
1686
|
+
if (!model) continue;
|
|
1687
|
+
(model.foreignKeys ?? (model.foreignKeys = {}))[reference.fieldKey] = {
|
|
1688
|
+
table: reference.referencedTable,
|
|
1689
|
+
column: reference.referencedColumn,
|
|
1690
|
+
onDelete: reference.onDelete
|
|
1691
|
+
};
|
|
1692
|
+
}
|
|
1693
|
+
const plan = await planSchemaMigration(planningModels, dialect, executor);
|
|
1694
|
+
const snapshot = createSchemaSnapshot(models);
|
|
1695
|
+
const state = await readSchemaState(executor, dialect, owner.name);
|
|
1696
|
+
const changes = state ? diffSchemaSnapshots(state.snapshot, snapshot) : void 0;
|
|
1697
|
+
const upgrade = state && changes && hasSchemaChanges(changes) ? { from: state.version, to: owner.version, changes } : void 0;
|
|
1698
|
+
const pendingSteps = (stepPlan?.steps ?? []).filter((planned) => planned.state !== "record");
|
|
1699
|
+
if (upgrade || pendingSteps.length > 0) {
|
|
1700
|
+
const versions = upgrade?.from && upgrade.to && upgrade.from !== upgrade.to ? `${owner.name} ${upgrade.from} \u2192 ${upgrade.to} changes its tables:` : `${owner.name}'s tables changed since they were last migrated:`;
|
|
1701
|
+
log(
|
|
1702
|
+
[
|
|
1703
|
+
versions,
|
|
1704
|
+
...describeStepChanges(stepPlan, Boolean(options.allowDestructive)),
|
|
1705
|
+
...describeSchemaChanges(withoutStepChanges(changes, stepPlan)),
|
|
1706
|
+
...renameHints(withoutStepChanges(changes, stepPlan))
|
|
1707
|
+
].join("\n")
|
|
1708
|
+
);
|
|
1709
|
+
}
|
|
1710
|
+
const recordState = async () => {
|
|
1711
|
+
if (options.extensions === "report") return;
|
|
1712
|
+
const unfinished = (stepPlan?.steps ?? []).some(
|
|
1713
|
+
(planned) => !stepsRan.includes(planned.step.id)
|
|
1714
|
+
);
|
|
1715
|
+
if (stepsStopped || unfinished) return;
|
|
1716
|
+
try {
|
|
1717
|
+
await writeSchemaState(executor, dialect, owner.name, { version: owner.version, snapshot });
|
|
1718
|
+
} catch (error) {
|
|
1719
|
+
log(
|
|
1720
|
+
`Applied, but could not record it in "${FARM_SCHEMA_STATE_TABLE}" (${error instanceof Error ? error.message : String(error)}). The next upgrade of ${owner.name} will be compared with the database instead of this version.`
|
|
1721
|
+
);
|
|
1722
|
+
}
|
|
1723
|
+
};
|
|
1724
|
+
const addable = plan.addableForeignKeys ?? [];
|
|
1725
|
+
const foreignKeysUnsupported = dialect === "sqlite" ? addable : [];
|
|
1726
|
+
const foreignKeysAllowed = dialect === "sqlite" ? [] : addable.filter(
|
|
1727
|
+
(key) => isForeignKeyAllowed(schemaConfig?.allowForeignKeys, { owner: owner.name, ...key })
|
|
1728
|
+
);
|
|
1729
|
+
const foreignKeysUnapproved = dialect === "sqlite" ? [] : addable.filter((key) => !foreignKeysAllowed.includes(key));
|
|
1730
|
+
const extensionsPlan = await planSchemaExtensions(
|
|
1731
|
+
collectSchemaExtensions(owner.name, owner.schema, owner.models),
|
|
1732
|
+
dialect,
|
|
1733
|
+
executor
|
|
1734
|
+
);
|
|
1735
|
+
const allowExtend = schemaConfig?.allowExtend;
|
|
1736
|
+
const approved = reportOnly ? [] : extensionsPlan.statements.filter(
|
|
1737
|
+
(statement) => isSchemaExtensionAllowed(allowExtend, statement.extension)
|
|
1738
|
+
);
|
|
1739
|
+
const unapproved = reportOnly ? [] : extensionsPlan.statements.filter((statement) => !approved.includes(statement));
|
|
1740
|
+
const sql = formatSteps(stepPlan, "before", reportOnly) + formatSchemaMigration(plan, owner.name, {
|
|
1741
|
+
addsColumns: approved.length + foreignKeysAllowed.length > 0
|
|
1742
|
+
}) + formatSteps(stepPlan, "after", reportOnly) + formatForeignKeys(owner.name, dialect, foreignKeysAllowed, foreignKeysUnapproved) + formatExtensions(owner.name, {
|
|
1743
|
+
approved,
|
|
1744
|
+
unapproved,
|
|
1745
|
+
reported: reportOnly ? extensionsPlan.statements : []
|
|
1746
|
+
});
|
|
1747
|
+
const pendingAfter = (added) => [
|
|
1748
|
+
...extensionsPlan.statements.map((statement) => statement.target).filter((target) => !added.has(target)),
|
|
1749
|
+
...extensionsPlan.unsupported.map((entry) => `${entry.extension.table}.${entry.column}`),
|
|
1750
|
+
...extensionsPlan.missingTables.flatMap(
|
|
1751
|
+
(extension) => extension.fields.map(({ field }) => `${extension.table}.${field.name}`)
|
|
1752
|
+
)
|
|
1753
|
+
];
|
|
1754
|
+
const blocked = [];
|
|
1755
|
+
const result = (applied2) => ({
|
|
1756
|
+
plan,
|
|
1757
|
+
sql,
|
|
1758
|
+
applied: applied2,
|
|
1759
|
+
extensions: { ...extensionsPlan, unapproved, pending: pendingAfter(new Set(applied2)) },
|
|
1760
|
+
foreignKeys: {
|
|
1761
|
+
waiting: crossOwner.waiting,
|
|
1762
|
+
unapproved: foreignKeysUnapproved,
|
|
1763
|
+
unsupported: foreignKeysUnsupported,
|
|
1764
|
+
blocked
|
|
1765
|
+
},
|
|
1766
|
+
upgrade,
|
|
1767
|
+
steps: {
|
|
1768
|
+
plan: stepPlan,
|
|
1769
|
+
ran: stepsRan,
|
|
1770
|
+
pending: (stepPlan?.steps ?? []).filter((planned) => !stepsRan.includes(planned.step.id)).map((planned) => planned.step.id)
|
|
1771
|
+
},
|
|
1772
|
+
planned: pendingStatements + runnableSteps
|
|
1773
|
+
});
|
|
1774
|
+
const creating = new Set(plan.statements.map((statement) => statement.target));
|
|
1775
|
+
for (const reference of crossOwner.waiting) {
|
|
1776
|
+
if (!creating.has(reference.table)) continue;
|
|
1777
|
+
log(
|
|
1778
|
+
`"${reference.table}.${reference.column}" is created without a foreign key: ${reference.referencedOwner} has not created "${reference.referencedTable}" yet. Run \`farm schema migrate\` to create both in order.`
|
|
1779
|
+
);
|
|
1780
|
+
}
|
|
1781
|
+
for (const key of foreignKeysUnsupported) {
|
|
1782
|
+
log(
|
|
1783
|
+
`"${key.table}.${key.column}" has no foreign key to "${key.referencedTable}". SQLite can only add one when it creates the table.`
|
|
1784
|
+
);
|
|
1785
|
+
}
|
|
1786
|
+
if (plan.upToDate.length > 0) {
|
|
1787
|
+
log(`Already up to date: ${plan.upToDate.join(", ")}`);
|
|
1788
|
+
}
|
|
1789
|
+
if (plan.drift.length > 0) {
|
|
1790
|
+
log(
|
|
1791
|
+
`These tables exist but no longer match the schema. Farm will not change them:
|
|
1792
|
+
${describeSchemaDrift(plan.drift)}`
|
|
1793
|
+
);
|
|
1794
|
+
}
|
|
1795
|
+
logExtensionProblems(owner.name, extensionsPlan, log);
|
|
1796
|
+
const pendingStatements = plan.statements.length + (plan.upgrades?.length ?? 0) + approved.length + foreignKeysAllowed.length;
|
|
1797
|
+
const blockedAt = (stepPlan?.steps ?? []).findIndex(
|
|
1798
|
+
(planned) => planned.state === "blocked" || planned.state === "run" && planned.destructive && !options.allowDestructive
|
|
1799
|
+
);
|
|
1800
|
+
const runnableSteps = (stepPlan?.steps ?? []).slice(0, blockedAt === -1 ? void 0 : blockedAt).filter((planned) => !stepsRan.includes(planned.step.id)).length;
|
|
1801
|
+
if (pendingStatements === 0 && runnableSteps === 0 && blockedAt === -1 && unapproved.length === 0 && foreignKeysUnapproved.length === 0 && (!reportOnly || extensionsPlan.statements.length === 0)) {
|
|
1802
|
+
log("Nothing to create.");
|
|
1803
|
+
if (options.apply) await recordState();
|
|
1804
|
+
return result([]);
|
|
1805
|
+
}
|
|
1806
|
+
if (options.write) {
|
|
1807
|
+
const { writeFile, mkdir } = await import("fs/promises");
|
|
1808
|
+
const { dirname } = await import("path");
|
|
1809
|
+
await mkdir(dirname(options.write), { recursive: true });
|
|
1810
|
+
await writeFile(options.write, sql, "utf8");
|
|
1811
|
+
log(`Wrote ${pendingStatements} statement(s) to ${options.write}`);
|
|
1812
|
+
return result([]);
|
|
1813
|
+
}
|
|
1814
|
+
if (!options.apply) {
|
|
1815
|
+
log(sql);
|
|
1816
|
+
return result([]);
|
|
1817
|
+
}
|
|
1818
|
+
for (const approval of new Set(
|
|
1819
|
+
unapproved.map((statement) => describeSchemaExtensionApproval(statement.extension))
|
|
1820
|
+
)) {
|
|
1821
|
+
const columns = unapproved.filter((statement) => describeSchemaExtensionApproval(statement.extension) === approval).map((statement) => statement.target);
|
|
1822
|
+
log(
|
|
1823
|
+
`Not allowed yet, so not added: ${columns.join(", ")}. To allow it, add to farm.config: ${approval}`
|
|
1824
|
+
);
|
|
1825
|
+
}
|
|
1826
|
+
const created = await applySchemaMigration(plan, executor);
|
|
1827
|
+
const applied = [...created.applied];
|
|
1828
|
+
for (const statement of approved) {
|
|
1829
|
+
await executor.execute(statement.sql);
|
|
1830
|
+
applied.push(statement.target);
|
|
1831
|
+
}
|
|
1832
|
+
for (const key of foreignKeysAllowed) {
|
|
1833
|
+
const orphans = await countOrphans(executor, dialect, key);
|
|
1834
|
+
if (orphans > 0) {
|
|
1835
|
+
blocked.push({ key, orphans });
|
|
1836
|
+
log(
|
|
1837
|
+
`Cannot add the foreign key "${key.table}.${key.column}" \u2192 "${key.referencedTable}": ${orphans} row(s) point at no "${key.referencedTable}". Fix or remove them, then run again.`
|
|
1838
|
+
);
|
|
1839
|
+
continue;
|
|
1840
|
+
}
|
|
1841
|
+
await executor.execute(foreignKeyStatement(dialect, key));
|
|
1842
|
+
applied.push(`${key.table}.${key.column} \u2192 ${key.referencedTable}`);
|
|
1843
|
+
}
|
|
1844
|
+
for (const key of foreignKeysUnapproved) {
|
|
1845
|
+
log(
|
|
1846
|
+
`Not allowed yet, so not added: the foreign key "${key.table}.${key.column}" \u2192 "${key.referencedTable}". To allow it, add to farm.config: ${describeForeignKeyApproval({ owner: owner.name, modelKey: key.modelKey })}`
|
|
1847
|
+
);
|
|
1848
|
+
}
|
|
1849
|
+
if (applied.length > 0) log(`Created: ${applied.join(", ")}`);
|
|
1850
|
+
await runSteps("after");
|
|
1851
|
+
if (stepsRan.length > 0) log(`Ran migration steps: ${stepsRan.join(", ")}`);
|
|
1852
|
+
await recordState();
|
|
1853
|
+
return result(applied);
|
|
1854
|
+
}
|
|
1855
|
+
function foreignKeyStatement(dialect, key) {
|
|
1856
|
+
const name = `${key.table}_${key.column}_fkey`.slice(0, 63);
|
|
1857
|
+
const onDelete = key.onDelete !== "noAction" ? ` ON DELETE ${SQL_ON_DELETE[key.onDelete]}` : "";
|
|
1858
|
+
const q = (value) => quoteSqlIdentifier(dialect, value);
|
|
1859
|
+
return `ALTER TABLE ${q(key.table)} ADD CONSTRAINT ${q(name)} FOREIGN KEY (${q(key.column)}) REFERENCES ${q(key.referencedTable)} (${q(key.referencedColumn)})${onDelete};`;
|
|
1860
|
+
}
|
|
1861
|
+
var SQL_ON_DELETE = {
|
|
1862
|
+
cascade: "CASCADE",
|
|
1863
|
+
restrict: "RESTRICT",
|
|
1864
|
+
setNull: "SET NULL",
|
|
1865
|
+
noAction: "NO ACTION"
|
|
1866
|
+
};
|
|
1867
|
+
async function countOrphans(executor, dialect, key) {
|
|
1868
|
+
const q = (name) => quoteSqlIdentifier(dialect, name);
|
|
1869
|
+
const rows = await executor.query(
|
|
1870
|
+
`SELECT COUNT(*) AS orphans FROM ${q(key.table)} child WHERE child.${q(key.column)} IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${q(key.referencedTable)} parent WHERE parent.${q(key.referencedColumn)} = child.${q(key.column)})`
|
|
1871
|
+
);
|
|
1872
|
+
const row = rows[0] ?? {};
|
|
1873
|
+
return Number(row.orphans ?? row.ORPHANS ?? Object.values(row)[0] ?? 0);
|
|
1874
|
+
}
|
|
1875
|
+
function formatForeignKeys(owner, dialect, allowed, unapproved) {
|
|
1876
|
+
const sections = [];
|
|
1877
|
+
if (allowed.length > 0) {
|
|
1878
|
+
sections.push(
|
|
1879
|
+
[
|
|
1880
|
+
`-- Foreign keys from ${owner}'s existing tables to other plugins' tables, allowed in farm.config.`,
|
|
1881
|
+
"-- Added only when no row points at nothing.",
|
|
1882
|
+
...allowed.map((key) => foreignKeyStatement(dialect, key))
|
|
1883
|
+
].join("\n")
|
|
1884
|
+
);
|
|
1885
|
+
}
|
|
1886
|
+
if (unapproved.length > 0) {
|
|
1887
|
+
const approvals = [
|
|
1888
|
+
...new Set(
|
|
1889
|
+
unapproved.map((key) => describeForeignKeyApproval({ owner, modelKey: key.modelKey }))
|
|
1890
|
+
)
|
|
1891
|
+
];
|
|
1892
|
+
sections.push(
|
|
1893
|
+
[
|
|
1894
|
+
`-- Foreign keys from ${owner}'s existing tables to other plugins' tables. Not allowed yet, so not run.`,
|
|
1895
|
+
"-- To allow them, add to farm.config:",
|
|
1896
|
+
...approvals.map((approval) => `-- ${approval}`),
|
|
1897
|
+
...unapproved.map((key) => `-- ${foreignKeyStatement(dialect, key)}`)
|
|
1898
|
+
].join("\n")
|
|
1899
|
+
);
|
|
1900
|
+
}
|
|
1901
|
+
return sections.length > 0 ? `
|
|
1902
|
+
${sections.join("\n\n")}
|
|
1903
|
+
` : "";
|
|
1904
|
+
}
|
|
1905
|
+
function describeStepChanges(stepPlan, allowDestructive) {
|
|
1906
|
+
const pending = (stepPlan?.steps ?? []).filter((planned) => planned.state !== "record");
|
|
1907
|
+
return pending.map((planned, index) => {
|
|
1908
|
+
const when = planned.phase === "after" ? " (after the changes below)" : "";
|
|
1909
|
+
const deletes = planned.destructive && planned.state === "run" ? allowDestructive ? " \u26A0 deletes data" : " \u26A0 deletes data, needs --allow-destructive" : "";
|
|
1910
|
+
const blocked = planned.state === "blocked" ? ` \u2717 blocked: ${planned.reason}` : "";
|
|
1911
|
+
return ` ${index + 1}. ${planned.summary}${when}${deletes}${blocked}`;
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
function withoutStepChanges(changes, stepPlan) {
|
|
1915
|
+
const empty = {
|
|
1916
|
+
addedTables: [],
|
|
1917
|
+
addedColumns: [],
|
|
1918
|
+
addedIndexes: [],
|
|
1919
|
+
otherChanges: [],
|
|
1920
|
+
removedColumns: []
|
|
1921
|
+
};
|
|
1922
|
+
if (!changes) return empty;
|
|
1923
|
+
const renamedTo = /* @__PURE__ */ new Set();
|
|
1924
|
+
const renamedFrom = /* @__PURE__ */ new Set();
|
|
1925
|
+
for (const { summary, step } of stepPlan?.steps ?? []) {
|
|
1926
|
+
const match = /^rename (?:table )?(\S+) → (\S+)$/u.exec(summary);
|
|
1927
|
+
if (!match || !("renameColumn" in step || "renameTable" in step)) continue;
|
|
1928
|
+
renamedFrom.add(match[1]);
|
|
1929
|
+
renamedTo.add(match[2]);
|
|
1930
|
+
}
|
|
1931
|
+
return {
|
|
1932
|
+
addedTables: changes.addedTables.filter((table) => !renamedTo.has(table)),
|
|
1933
|
+
addedColumns: changes.addedColumns.filter(
|
|
1934
|
+
({ table, column }) => !renamedTo.has(`${table}.${column}`)
|
|
1935
|
+
),
|
|
1936
|
+
addedIndexes: changes.addedIndexes,
|
|
1937
|
+
otherChanges: changes.otherChanges.filter(
|
|
1938
|
+
(change) => ![...renamedFrom].some((from) => change === `${from} is removed`)
|
|
1939
|
+
),
|
|
1940
|
+
removedColumns: (changes.removedColumns ?? []).filter(
|
|
1941
|
+
({ table, column }) => !renamedFrom.has(`${table}.${column}`)
|
|
1942
|
+
)
|
|
1943
|
+
};
|
|
1944
|
+
}
|
|
1945
|
+
function renameHints(changes) {
|
|
1946
|
+
const hints = [];
|
|
1947
|
+
for (const removed of changes.removedColumns ?? []) {
|
|
1948
|
+
const added = changes.addedColumns.find(
|
|
1949
|
+
({ table, type }) => table === removed.table && type === removed.type
|
|
1950
|
+
);
|
|
1951
|
+
if (!added) continue;
|
|
1952
|
+
hints.push(
|
|
1953
|
+
` ? if ${removed.table}.${removed.column} was renamed to ${added.table}.${added.column}, the plugin needs a migration step, or the data stays in ${removed.column}`
|
|
1954
|
+
);
|
|
1955
|
+
}
|
|
1956
|
+
return hints;
|
|
1957
|
+
}
|
|
1958
|
+
function formatSteps(stepPlan, phase, reportOnly) {
|
|
1959
|
+
const planned = (stepPlan?.steps ?? []).filter(
|
|
1960
|
+
(entry) => entry.phase === phase && entry.state !== "record"
|
|
1961
|
+
);
|
|
1962
|
+
if (planned.length === 0) return "";
|
|
1963
|
+
const heading = phase === "before" ? "-- Migration steps, run before the changes below:" : "-- Migration steps, run after the changes above:";
|
|
1964
|
+
const lines = [heading];
|
|
1965
|
+
for (const entry of planned) {
|
|
1966
|
+
lines.push(
|
|
1967
|
+
`-- ${entry.step.id}: ${entry.summary}${entry.destructive ? " (deletes data)" : ""}`
|
|
1968
|
+
);
|
|
1969
|
+
if (entry.state === "blocked") {
|
|
1970
|
+
lines.push(`-- blocked: ${entry.reason}`);
|
|
1971
|
+
continue;
|
|
1972
|
+
}
|
|
1973
|
+
for (const statement of entry.statements) {
|
|
1974
|
+
lines.push(reportOnly ? `-- ${statement};` : `${statement.replace(/;\s*$/u, "")};`);
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
if (reportOnly) {
|
|
1978
|
+
lines.push("-- Your ORM owns these tables: add the steps to its migrations instead.");
|
|
1979
|
+
}
|
|
1980
|
+
return `${lines.join("\n")}
|
|
1981
|
+
|
|
1982
|
+
`;
|
|
1983
|
+
}
|
|
1984
|
+
function formatExtensions(owner, groups) {
|
|
1985
|
+
const sections = [];
|
|
1986
|
+
if (groups.approved.length > 0) {
|
|
1987
|
+
sections.push(
|
|
1988
|
+
[
|
|
1989
|
+
`-- Columns ${owner} adds to tables it does not own, allowed in farm.config.`,
|
|
1990
|
+
...groups.approved.map((statement) => statement.sql)
|
|
1991
|
+
].join("\n")
|
|
1992
|
+
);
|
|
1993
|
+
}
|
|
1994
|
+
if (groups.unapproved.length > 0) {
|
|
1995
|
+
const approvals = [
|
|
1996
|
+
...new Set(
|
|
1997
|
+
groups.unapproved.map((statement) => describeSchemaExtensionApproval(statement.extension))
|
|
1998
|
+
)
|
|
1999
|
+
];
|
|
2000
|
+
sections.push(
|
|
2001
|
+
[
|
|
2002
|
+
`-- Columns ${owner} adds to tables it does not own. Not allowed yet, so not run.`,
|
|
2003
|
+
"-- To allow them, add to farm.config:",
|
|
2004
|
+
...approvals.map((approval) => `-- ${approval}`),
|
|
2005
|
+
...groups.unapproved.map((statement) => `-- ${statement.sql}`)
|
|
2006
|
+
].join("\n")
|
|
2007
|
+
);
|
|
2008
|
+
}
|
|
2009
|
+
if (groups.reported.length > 0) {
|
|
2010
|
+
sections.push(
|
|
2011
|
+
[
|
|
2012
|
+
`-- Columns ${owner} adds to tables your ORM owns. Farm will not alter them:`,
|
|
2013
|
+
"-- add them to your ORM's schema and run its migration.",
|
|
2014
|
+
...groups.reported.map((statement) => `-- ${statement.sql}`)
|
|
2015
|
+
].join("\n")
|
|
2016
|
+
);
|
|
2017
|
+
}
|
|
2018
|
+
return sections.length > 0 ? `
|
|
2019
|
+
${sections.join("\n\n")}
|
|
2020
|
+
` : "";
|
|
2021
|
+
}
|
|
2022
|
+
function logExtensionProblems(owner, plan, log) {
|
|
2023
|
+
for (const extension of plan.missingTables) {
|
|
2024
|
+
log(
|
|
2025
|
+
`Cannot add ${extension.fields.map(({ field }) => field.name).join(", ")} to "${extension.table}": the table does not exist. Run the migration that creates it (your ORM's, or a library's such as Better Auth) first.`
|
|
2026
|
+
);
|
|
2027
|
+
}
|
|
2028
|
+
for (const entry of plan.unsupported) {
|
|
2029
|
+
log(`Cannot add "${entry.extension.table}.${entry.column}" for ${owner}: ${entry.reason}`);
|
|
2030
|
+
}
|
|
2031
|
+
for (const entry of plan.conflicts) {
|
|
2032
|
+
log(
|
|
2033
|
+
`"${entry.extension.table}.${entry.column}" already exists as ${entry.actual}; ${owner} expects ${entry.expected.toLowerCase()}. Farm will not change it.`
|
|
2034
|
+
);
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
export {
|
|
2039
|
+
describeSchemaReference,
|
|
2040
|
+
collectSchemaModels,
|
|
2041
|
+
generateSqlStatements,
|
|
2042
|
+
renderSqlSchemaFile,
|
|
2043
|
+
getSqlColumnType,
|
|
2044
|
+
getSqlDefaultExpression,
|
|
2045
|
+
isNullableField,
|
|
2046
|
+
quoteSqlIdentifier,
|
|
2047
|
+
toSnakeCase,
|
|
2048
|
+
toPascalCase,
|
|
2049
|
+
toCamelCase,
|
|
2050
|
+
escapeSqlString,
|
|
2051
|
+
planSchemaMigration,
|
|
2052
|
+
describeSchemaTable,
|
|
2053
|
+
applySchemaMigration,
|
|
2054
|
+
columnTypeFamily,
|
|
2055
|
+
planSchemaExtensions,
|
|
2056
|
+
formatSchemaMigration,
|
|
2057
|
+
describeSchemaDrift,
|
|
2058
|
+
createSchemaExecutor,
|
|
2059
|
+
FARM_SCHEMA_STATE_TABLE,
|
|
2060
|
+
createSchemaSnapshot,
|
|
2061
|
+
diffSchemaSnapshots,
|
|
2062
|
+
hasSchemaChanges,
|
|
2063
|
+
readSchemaState,
|
|
2064
|
+
FARM_SCHEMA_STEPS_TABLE,
|
|
2065
|
+
withoutRenameTargets,
|
|
2066
|
+
planOwnerSchemaSteps,
|
|
2067
|
+
planCrossOwnerReferences,
|
|
2068
|
+
describeForeignKeyApproval,
|
|
2069
|
+
findSchemaTableOwners,
|
|
2070
|
+
collectOwnerModels,
|
|
2071
|
+
migrateSchemaTables
|
|
2072
|
+
};
|