void 1.1.0 → 1.1.12
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/{account-cmd-BTcUzv9L.mjs → account-cmd-Cj6sCMTk.mjs} +4 -4
- package/dist/{application-analysis-AB_YYWgH.mjs → application-analysis-D7nNmNJb.mjs} +6 -6
- package/dist/{application-routing-L7V-TFhZ.mjs → application-routing-CZH66gXn.mjs} +1 -1
- package/dist/{auth-link-DUJuvRx5.mjs → auth-link-Dj7lAC_K.mjs} +4 -4
- package/dist/{auth-migrations-Cgs0k6lS.mjs → auth-migrations-BO27GDNr.mjs} +38 -2
- package/dist/{auth-router-CIxiMG7i.mjs → auth-router-CNsMOFCa.mjs} +5 -4
- package/dist/{better-auth-shared-B74NJIus.d.mts → better-auth-shared-Bv18bB-l.d.mts} +2 -0
- package/dist/{better-auth-shared-CMXlZG7W.mjs → better-auth-shared-D-6z0q0f.mjs} +28 -1
- package/dist/{build-cmd-BkIv25PA.mjs → build-cmd-ByhegwRC.mjs} +2 -2
- package/dist/{cache-Ctzfig-W.mjs → cache-CEFb5ban.mjs} +2 -2
- package/dist/{cancel-deploy-CD9o-SsC.mjs → cancel-deploy-CaARY26n.mjs} +2 -2
- package/dist/{cf-build-output-Bc8i3dzE.mjs → cf-build-output-ChEKWan2.mjs} +71 -7
- package/dist/cf-build-output-Dcmxa-Zm.mjs +1 -0
- package/dist/{cf-user-agent-ChjQp2MU.mjs → cf-command-values-b8OqDoo9.mjs} +5 -16
- package/dist/cf-user-agent-BkEHPDLA.mjs +16 -0
- package/dist/cli/cli.mjs +180 -57
- package/dist/cli/cloudflare-operation-process.mjs +46 -9
- package/dist/cli/env-schema-probe.mjs +3 -3
- package/dist/{client-DM9Kcf4e.mjs → client-BdzxubTS.mjs} +58 -13
- package/dist/client-DAnfyMe9.mjs +1 -0
- package/dist/{cloudflare-auth-CqFBDo52.mjs → cloudflare-auth-DSvBc1Gu.mjs} +1 -1
- package/dist/{cloudflare-cmd-BIAF_BIY.mjs → cloudflare-cmd-D_2-Q-_i.mjs} +4 -4
- package/dist/{cloudflare-config-DV60XFFK.mjs → cloudflare-config-rdFOys4X.mjs} +2 -2
- package/dist/{cloudflare-connect-WjwnVOJA.mjs → cloudflare-connect-BN-k2kD-.mjs} +2 -2
- package/dist/{cloudflare-operations-CrSUFRzJ.mjs → cloudflare-operations-BFLCpUCV.mjs} +1 -1
- package/dist/{cloudflare-operations-B42EZeJy.mjs → cloudflare-operations-D5PLrOqD.mjs} +18 -8
- package/dist/{cloudflare-process-CeDWJRhj.mjs → cloudflare-process-CZJ4viYl.mjs} +2 -2
- package/dist/collect-BWhkgtAn.mjs +1 -0
- package/dist/{collect-xjffdCdk.mjs → collect-Dew86qce.mjs} +4 -3
- package/dist/{config-D0GY5ItR.mjs → config-CyUJzi3q.mjs} +1 -1
- package/dist/{config-Bx_1SpnO.mjs → config-D26zcdKy.mjs} +2 -2
- package/dist/{config-BEm9vRvS.mjs → config-DC5llZaI.mjs} +2 -2
- package/dist/{config-QrJWu0IX.mjs → config-DYJV8aEH.mjs} +1 -1
- package/dist/{connect-CKtk-EZe.mjs → connect-C4_m2moF.mjs} +5 -5
- package/dist/{create-project-B-ewF_Af.mjs → create-project-CvuYDD-l.mjs} +1 -1
- package/dist/{create-project-yInGo72M.mjs → create-project-D8jQTwVQ.mjs} +2 -2
- package/dist/database-provider.d.mts +6 -0
- package/dist/{db-7I_gfdVq.mjs → db-BsiOAa0A.mjs} +306 -111
- package/dist/{db-types-Bb4WBWIs.mjs → db-types-NGxPwnlt.mjs} +1 -1
- package/dist/{delete-Cy-M1u-r.mjs → delete-CAma7nFi.mjs} +2 -2
- package/dist/{deploy-BYYlnsiy.mjs → deploy-D1gIPiAq.mjs} +148 -64
- package/dist/deploy-Dc0XsCQj.mjs +2 -0
- package/dist/{deploy-managed-static-Ca4TFdmx.mjs → deploy-managed-static-B9KVxY3X.mjs} +80 -34
- package/dist/{deploy-transport-DWlWBe6M.mjs → deploy-transport-B3mtEi_q.mjs} +2 -2
- package/dist/deploy.d.mts +22 -1
- package/dist/deploy.mjs +49 -8
- package/dist/discover-D4TPKo57.mjs +1 -0
- package/dist/{discover-D2PGT63u.mjs → discover-LaV0tbIu.mjs} +1 -1
- package/dist/{dispatch-DrTTk8Xg.mjs → dispatch-BAbbn3jg.mjs} +6 -6
- package/dist/{domain-CZGxPv9u.mjs → domain-BAdwm-QS.mjs} +3 -3
- package/dist/{drizzle-CF84FOVM.mjs → drizzle-BQfyvQKX.mjs} +13 -2
- package/dist/{email-DzyNVuoU.mjs → email-MwjA7kaL.mjs} +11 -12
- package/dist/{email-cloudflare-DfG6UEMm.mjs → email-cloudflare-etpKiITL.mjs} +7 -10
- package/dist/{entry-ehmBvs5w.mjs → entry-B_0IhV64.mjs} +1 -1
- package/dist/{env-Nx3yf50r.mjs → env-B163-G1s.mjs} +5 -5
- package/dist/{env-types-DS2_y4X8.mjs → env-types-GRchm5dw.mjs} +1 -1
- package/dist/{env-validation-BT7z-qpQ.mjs → env-validation-CuGfWRJd.mjs} +1 -1
- package/dist/{env-validation-DYxjz_Wo.mjs → env-validation-D_KyMdab.mjs} +2 -2
- package/dist/{fetch-BPCYVi3H.d.mts → fetch-CUX0tB78.d.mts} +16 -3
- package/dist/fetch-CtESUYWd.mjs +26 -0
- package/dist/{fetch-error-Dj3crt0e.mjs → fetch-error-Bw0n-IY-.mjs} +1 -1
- package/dist/{fetch-stream-PGgz4uGz.mjs → fetch-stream-BspOeTAI.mjs} +1 -1
- package/dist/{fetch-stream-obvZ7fvO.d.mts → fetch-stream-DfkAzZf-.d.mts} +1 -1
- package/dist/{gen-CufHEf42.mjs → gen-CYN3wiov.mjs} +26 -20
- package/dist/gen-Cf-RBVg4.mjs +1 -0
- package/dist/{generate-Dat0UTry.mjs → generate-B1m4Cm4n.mjs} +1 -1
- package/dist/{generate-ClI89brV.mjs → generate-DkEb9rL-.mjs} +1 -1
- package/dist/{github-cmd-FU8EjFyU.mjs → github-cmd-C8QsnJQs.mjs} +2 -2
- package/dist/{handler-_PqY82xe.d.mts → handler-D5K_yP6T.d.mts} +1 -1
- package/dist/{headers-Di1FsD3e.mjs → headers-Bi4bOAwp.mjs} +1 -1
- package/dist/{help-BT2hovNI.mjs → help-B2sFwn9b.mjs} +60 -15
- package/dist/help-w-xlx_kq.mjs +1 -0
- package/dist/{inbound-brj2-TM5.d.mts → inbound-Da7XsjH3.d.mts} +6 -12
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +139 -126
- package/dist/{info-l249eUdH.mjs → info-Bxunp14X.mjs} +4 -4
- package/dist/{init-D0A6M64Q.mjs → init-DGFQMnbk.mjs} +51 -28
- package/dist/{link-WMoJFf4i.mjs → link-CwrfpjIM.mjs} +3 -3
- package/dist/{list-CQ2EQEHL.mjs → list-hKoW5z-b.mjs} +3 -3
- package/dist/{live-DJONVlQK.d.mts → live-JheIDZKc.d.mts} +1 -1
- package/dist/{local-d1-BxvQYEFi.mjs → local-d1-CpaPbd_L.mjs} +5 -5
- package/dist/login-08mBwZfI.mjs +1 -0
- package/dist/{login-C2T1oVG-.mjs → login-f2eu2TQh.mjs} +3 -3
- package/dist/{logs-DnC1d7xB.mjs → logs-CEWqD-_B.mjs} +3 -3
- package/dist/{migrate-BDIprOYd.mjs → migrate-DYfdWBXt.mjs} +5 -5
- package/dist/migrate-Di-4EuoE.mjs +1 -0
- package/dist/{neon-n74ta1Pr.mjs → neon-DTZr7Bu7.mjs} +0 -1
- package/dist/nitro.mjs +3 -3
- package/dist/{node-cPadMgUO.mjs → node-uN8_zxJr.mjs} +15 -9
- package/dist/operator-cmd-Bv20yLu2.mjs +1 -0
- package/dist/{operator-cmd-DHieWtFp.mjs → operator-cmd-DCr_QGMH.mjs} +4 -4
- package/dist/{output-Ba6ZbrzY.mjs → output-CKguMgr7.mjs} +13 -1
- package/dist/pages/client.d.mts +2 -2
- package/dist/pages/client.mjs +18 -5
- package/dist/pages/index.d.mts +2 -2
- package/dist/pages/index.mjs +5 -5
- package/dist/pages/islands-plugin.d.mts +44 -6
- package/dist/pages/islands-plugin.mjs +99 -28
- package/dist/pages/protocol.d.mts +2 -2
- package/dist/pages/protocol.mjs +1 -1
- package/dist/pages/serialize.d.mts +2 -2
- package/dist/pages/serialize.mjs +1 -1
- package/dist/{platform-args-CaCL_1Ch.mjs → platform-args-B7ke06up.mjs} +1 -4
- package/dist/platform-args-B_LrqEZB.mjs +1 -0
- package/dist/{platform-auth-config-Z16-I8nT.mjs → platform-auth-config-qGvEuns3.mjs} +5 -5
- package/dist/{platform-auth-protection-BXwZiJSF.mjs → platform-auth-protection-CyLcD6ot.mjs} +3 -3
- package/dist/{platform-auth-recovery-CXjfqyOv.mjs → platform-auth-recovery-B2LKI8V2.mjs} +3 -3
- package/dist/{platform-cmd-PT4YwMLM.mjs → platform-cmd-B2ec5eFg.mjs} +1 -1
- package/dist/{platform-cmd-DaAOiWTl.mjs → platform-cmd-CX7phm7V.mjs} +6 -6
- package/dist/{platform-domain-CxpvUeo0.mjs → platform-domain-DDNK2y-4.mjs} +3 -3
- package/dist/{platform-lifecycle-DBiS0cJd.mjs → platform-lifecycle-3CR98Tg2.mjs} +399 -40
- package/dist/{platform-lifecycle-u9pMOvxC.mjs → platform-lifecycle-CWc5gr6c.mjs} +1 -1
- package/dist/{platform-management-DvBS83rC.mjs → platform-management-DAE6g2QU.mjs} +1 -1
- package/dist/{platform-management-DhEFdQAf.mjs → platform-management-o3LCCeE4.mjs} +40 -4
- package/dist/{platform-plans-config-BWn1S2Rv.mjs → platform-plans-config-CBMZxCep.mjs} +1 -1
- package/dist/{platform-recovery-BUGOB4RC.mjs → platform-recovery-Dmsg7lWA.mjs} +2 -2
- package/dist/{platform-setup-YvN9VQXV.mjs → platform-setup-hFbnWAVQ.mjs} +1 -1
- package/dist/{plugin-inference-DsARdQKE.mjs → plugin-inference-Bekzjuqw.mjs} +2 -2
- package/dist/{prepare-DEB5SeVJ.mjs → prepare-DepAGBcV.mjs} +9 -9
- package/dist/prepare-EVEbQ9n2.mjs +1 -0
- package/dist/{prepare-PQCgsny0.mjs → prepare-HKo7Rh5V.mjs} +2 -2
- package/dist/{project-cmd-DVatD8Ev.mjs → project-cmd-8ylYGx-O.mjs} +18 -18
- package/dist/{project-paths-DMvEeSau.mjs → project-paths-DGu_QZ_Q.mjs} +1 -1
- package/dist/{project-team-DJrWEAG1.mjs → project-team-Bvpl78we.mjs} +2 -2
- package/dist/{project-token-CBgLBuL6.mjs → project-token-QWHoJH2t.mjs} +2 -2
- package/dist/{project-tsconfig-bveqhlYA.mjs → project-tsconfig-Itv1f4WC.mjs} +1 -1
- package/dist/{project-zero-trust-92gLtZ25.mjs → project-zero-trust-8tJ-RFvu.mjs} +2 -2
- package/dist/{protocol-4H7V_3Os.d.mts → protocol-Ssc_LhHj.d.mts} +2 -2
- package/dist/{protocol-RNP0u7UY.mjs → protocol-bAUUkx70.mjs} +1 -1
- package/dist/{providers-BXuhmuub.mjs → providers-BUHwJlmM.mjs} +10 -1
- package/dist/provision-BgXFDv0d.mjs +1 -0
- package/dist/{provision-BnSSkiED.mjs → provision-DZKYCEJg.mjs} +66 -66
- package/dist/r2-conditions-B8xUgJRc.mjs +61 -0
- package/dist/{requests-7W1Pygt2.mjs → requests-Vk5Zyhcy.mjs} +2 -2
- package/dist/{rollback-BcASVnwP.mjs → rollback-CH4yMQys.mjs} +9 -8
- package/dist/{runner-CabsQ-iM.mjs → runner-3uGC-oLF.mjs} +9 -7
- package/dist/{runner-So9mYfcm.mjs → runner-WCdfeI0q.mjs} +1 -1
- package/dist/{runner-mysql-BhRaONkO.mjs → runner-mysql-BWmbk5IE.mjs} +1 -1
- package/dist/{runner-mysql-DWwE8jKi.mjs → runner-mysql-BcHnLUuM.mjs} +1 -1
- package/dist/{runner-pg-_Xncr3H5.mjs → runner-pg-Cgp-cr_p.mjs} +1 -1
- package/dist/{runner-pg-BRemq_GX.mjs → runner-pg-Cr3qrqi4.mjs} +1 -1
- package/dist/runtime/ai.d.mts +4 -0
- package/dist/runtime/ai.mjs +2 -37
- package/dist/runtime/better-auth-mysql.d.mts +1 -1
- package/dist/runtime/better-auth-mysql.mjs +2 -2
- package/dist/runtime/better-auth-pg.d.mts +1 -1
- package/dist/runtime/better-auth-pg.mjs +2 -2
- package/dist/runtime/better-auth.d.mts +1 -1
- package/dist/runtime/better-auth.mjs +2 -2
- package/dist/runtime/client-react.d.mts +2 -2
- package/dist/runtime/client-react.mjs +3 -3
- package/dist/runtime/client-solid.d.mts +2 -2
- package/dist/runtime/client-solid.mjs +3 -3
- package/dist/runtime/client-svelte.d.mts +2 -2
- package/dist/runtime/client-svelte.mjs +3 -3
- package/dist/runtime/client-vue.d.mts +2 -2
- package/dist/runtime/client-vue.mjs +3 -3
- package/dist/runtime/client.d.mts +2 -2
- package/dist/runtime/client.mjs +3 -3
- package/dist/runtime/email/testing.d.mts +1 -1
- package/dist/runtime/email.d.mts +2 -3
- package/dist/runtime/email.mjs +2 -3
- package/dist/runtime/fetch-server.d.mts +8 -0
- package/dist/runtime/fetch-server.mjs +30 -0
- package/dist/runtime/fetch-stream.d.mts +2 -2
- package/dist/runtime/fetch-stream.mjs +2 -2
- package/dist/runtime/fetch.d.mts +2 -2
- package/dist/runtime/fetch.mjs +3 -3
- package/dist/runtime/handler.d.mts +1 -1
- package/dist/runtime/live-client.d.mts +1 -1
- package/dist/runtime/live.d.mts +1 -1
- package/dist/runtime/migration-handler-mysql.mjs +4 -4
- package/dist/runtime/migration-handler-pg.mjs +9 -1
- package/dist/runtime/remote/binding-handler.mjs +25 -25
- package/dist/runtime/remote/index.d.mts +3 -0
- package/dist/runtime/remote/index.mjs +86 -23
- package/dist/runtime/routing.d.mts +2 -2
- package/dist/runtime/routing.mjs +1 -1
- package/dist/runtime/sse-client.d.mts +4 -0
- package/dist/runtime/validator.d.mts +1 -1
- package/dist/runtime/ws-server.d.mts +2 -2
- package/dist/runtime/ws.d.mts +1 -1
- package/dist/{scan-C0BMdmEd.mjs → scan-D2-FcLHs.mjs} +13 -5
- package/dist/{secret-bg73f1Ge.mjs → secret-wr6Sn4Xa.mjs} +4 -4
- package/dist/serialize-DtR8Vwa_.d.mts +18 -0
- package/dist/serialize-YHvlcG3Q.mjs +31 -0
- package/dist/{subcommand-prompt-Bm3ZlYgA.mjs → subcommand-prompt-CNZc4XUd.mjs} +1 -1
- package/dist/{types-BAp5AEBU.d.mts → types-7AIz0OZu.d.mts} +1 -1
- package/dist/{validate-CheZGRE7.mjs → validate-CnZPMq4q.mjs} +22 -17
- package/dist/validate-D7Wn8PUX.mjs +1 -0
- package/dist/{version-metadata-DIrqEHQo.mjs → version-metadata-B1Bm2wSq.mjs} +1 -1
- package/dist/{wrangler-BYs07Rxy.mjs → wrangler-C9XSzrju.mjs} +3 -3
- package/dist/wrangler-DAdxHEzh.mjs +1 -0
- package/dist/{wrapper-CwhpNWtH.mjs → wrapper-DGsYwNi6.mjs} +6 -4
- package/dist/{ws-aKVYB-fA.d.mts → ws-nnFnAyQb.d.mts} +6 -1
- package/docs/guide/auth.md +1 -1
- package/docs/guide/database/d1.md +2 -2
- package/docs/guide/database/mysql.md +1 -1
- package/docs/guide/deployment.md +2 -0
- package/docs/guide/edge/headers.md +10 -2
- package/docs/guide/edge/revalidation.md +2 -0
- package/docs/guide/email/receiving.md +1 -1
- package/docs/guide/email/sending.md +3 -3
- package/docs/guide/pages-routing/islands.md +2 -2
- package/docs/guide/pages-routing/markdown.md +3 -1
- package/docs/guide/platform/administration/connected-apps.md +18 -2
- package/docs/guide/platform/administration/email.md +7 -1
- package/docs/guide/platform/installation/ci.md +2 -0
- package/docs/guide/platform/installation/credentials.md +23 -5
- package/docs/guide/platform/installation/maintenance.md +32 -2
- package/docs/guide/platform/installation/setup.md +1 -1
- package/docs/guide/remote-dev.md +2 -0
- package/docs/guide/typed-fetch.md +1 -1
- package/docs/guide/websockets.md +2 -2
- package/docs/index.md +78 -22
- package/docs/integrations/cloudflare.md +1 -1
- package/docs/integrations/frameworks/tanstack-start.md +25 -0
- package/docs/reference/api/deploy.md +35 -3
- package/docs/reference/api/pages.md +7 -5
- package/docs/reference/api.md +2 -0
- package/docs/reference/cli/database.md +22 -5
- package/docs/reference/cli/deploy.md +12 -10
- package/docs/reference/cli/email.md +1 -1
- package/docs/reference/cli/generate.md +1 -1
- package/docs/reference/cli/platform-installation.md +4 -2
- package/docs/reference/cli/project.md +8 -4
- package/docs/reference/cli.md +2 -1
- package/docs/reference/config.md +12 -2
- package/package.json +8 -7
- package/dist/cf-build-output-BU3hqdHu.mjs +0 -1
- package/dist/client-B60PwCC4.mjs +0 -1
- package/dist/collect-Cae8A7Zr.mjs +0 -1
- package/dist/deploy-9lgfhrXS.mjs +0 -2
- package/dist/discover-ClzFSwns.mjs +0 -1
- package/dist/fetch-sAcwjzLO.mjs +0 -18
- package/dist/gen-sXyp5DFO.mjs +0 -1
- package/dist/help-i2YGGnTH.mjs +0 -1
- package/dist/login-XD844Xs-.mjs +0 -1
- package/dist/migrate-BRwU-blY.mjs +0 -1
- package/dist/operator-cmd-D6gnZsnK.mjs +0 -1
- package/dist/platform-args-B0HeTh0C.mjs +0 -1
- package/dist/prepare-CYT6tAzD.mjs +0 -1
- package/dist/r2-conditions-D1Wk8i7b.mjs +0 -30
- package/dist/serialize-BtQyaYoC.mjs +0 -20
- package/dist/serialize-CfSwWfF2.d.mts +0 -10
- package/dist/validate-BQFdf0Pi.mjs +0 -1
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { a as join, c as resolve, n as dirname, r as extname, s as relative, t as basename } from "./dist-ipQi0Q8y.mjs";
|
|
2
|
-
import { r as detectFramework } from "./plugin-inference-
|
|
3
|
-
import { n as readProjectPaths } from "./project-paths-
|
|
4
|
-
import { d as readConfig, f as resolveBindingNames, s as getDatabaseDialect } from "./config-
|
|
5
|
-
import { i as writeJournal, n as readJournal, r as stripSqlExt, t as collectMigrations } from "./collect-
|
|
2
|
+
import { r as detectFramework } from "./plugin-inference-Bekzjuqw.mjs";
|
|
3
|
+
import { n as readProjectPaths } from "./project-paths-DGu_QZ_Q.mjs";
|
|
4
|
+
import { d as readConfig, f as resolveBindingNames, s as getDatabaseDialect } from "./config-D26zcdKy.mjs";
|
|
5
|
+
import { i as writeJournal, n as readJournal, r as stripSqlExt, t as collectMigrations } from "./collect-Dew86qce.mjs";
|
|
6
6
|
import { n as readDeploymentPlatform, r as readProjectConfig } from "./project-rqDnVsJN.mjs";
|
|
7
|
-
import { t as resolveLocalD1Target } from "./local-d1-
|
|
7
|
+
import { t as resolveLocalD1Target } from "./local-d1-CpaPbd_L.mjs";
|
|
8
8
|
import { t as cfAccessHeaders } from "./cf-access-BM9G0lhO.mjs";
|
|
9
9
|
import { n as ensurePlatformProxyAccess, r as isCloudflareAccessChallenge, t as ensurePlatformAccessToken } from "./cf-access-CWP4avfP.mjs";
|
|
10
10
|
import { c as getToken, o as getProxyUrl } from "./auth-B6iOCjKI.mjs";
|
|
11
11
|
import { A as confirm, H as outro, L as log, X as text, tt as isCancel } from "./dist-BVdsO7Py.mjs";
|
|
12
|
-
import { f as import_picocolors, i as dim, l as formatUrl, m as printSuccess, o as formatCount, u as getErrorMessage } from "./output-
|
|
12
|
+
import { f as import_picocolors, i as dim, l as formatUrl, m as printSuccess, o as formatCount, u as getErrorMessage } from "./output-CKguMgr7.mjs";
|
|
13
13
|
import { o as loadLocalEnv } from "./env-BJjULvL0.mjs";
|
|
14
|
-
import { i as validateMigrations, t as assertJournalCoherence } from "./validate-
|
|
15
|
-
import { n as PlatformApiError, r as PlatformClient } from "./client-
|
|
14
|
+
import { i as validateMigrations, t as assertJournalCoherence } from "./validate-CnZPMq4q.mjs";
|
|
15
|
+
import { n as PlatformApiError, r as PlatformClient } from "./client-BdzxubTS.mjs";
|
|
16
16
|
import { n as drizzleKitBin } from "./yarn-pnp-DLbEFMT0.mjs";
|
|
17
|
-
import { n as formatTimestamp } from "./gen-
|
|
17
|
+
import { n as formatTimestamp } from "./gen-CYN3wiov.mjs";
|
|
18
18
|
import { createRequire } from "node:module";
|
|
19
19
|
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
20
20
|
import { pathToFileURL } from "node:url";
|
|
@@ -156,7 +156,7 @@ function runDrizzleKit(root, args) {
|
|
|
156
156
|
* already printed its own error.
|
|
157
157
|
*/
|
|
158
158
|
async function runDrizzleKitWithDatabaseUrl(root, url, dialect, command) {
|
|
159
|
-
const { withPrivateDrizzleConfig } = await import("./config-
|
|
159
|
+
const { withPrivateDrizzleConfig } = await import("./config-DYJV8aEH.mjs");
|
|
160
160
|
if (!withPrivateDrizzleConfig(root, url, dialect, (configPath) => {
|
|
161
161
|
try {
|
|
162
162
|
runDrizzleKit(root, [
|
|
@@ -186,12 +186,18 @@ async function withPgClient(root, fn) {
|
|
|
186
186
|
await client.end();
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
async function withMySqlClient(root, fn) {
|
|
190
|
-
const { toMySqlClient } = await import("./runner-mysql-
|
|
189
|
+
async function withMySqlClient(root, fn, options = {}) {
|
|
190
|
+
const { toMySqlClient } = await import("./runner-mysql-BcHnLUuM.mjs");
|
|
191
191
|
const { createConnection } = await import("mysql2/promise");
|
|
192
192
|
const connection = await createConnection({
|
|
193
193
|
uri: getLocalDatabaseUrl(root, "mysql"),
|
|
194
|
-
multipleStatements: true
|
|
194
|
+
multipleStatements: true,
|
|
195
|
+
...options.textValues ? {
|
|
196
|
+
dateStrings: true,
|
|
197
|
+
jsonStrings: true,
|
|
198
|
+
supportBigNumbers: true,
|
|
199
|
+
bigNumberStrings: true
|
|
200
|
+
} : {}
|
|
195
201
|
});
|
|
196
202
|
try {
|
|
197
203
|
return await fn(toMySqlClient(connection));
|
|
@@ -217,6 +223,7 @@ async function runDbCommand(root, args) {
|
|
|
217
223
|
else if (args.action === "studio") await runStudio(root, dialect, args.remote);
|
|
218
224
|
else if (args.action === "set-url") await runSetUrl(root, dialect);
|
|
219
225
|
else if (args.action === "connect") await runConnect(root, dialect, args);
|
|
226
|
+
else if (args.action === "restore") await runRestore(root, dialect, args);
|
|
220
227
|
else if (args.action === "rename-migrations") await runRenameMigrations(root, dialect);
|
|
221
228
|
else await runExport(root, args, dialect);
|
|
222
229
|
}
|
|
@@ -245,7 +252,7 @@ function assertDatabaseProvider(value, source) {
|
|
|
245
252
|
}
|
|
246
253
|
async function loadDatabaseProvider(root, provider) {
|
|
247
254
|
if (provider === "neon") {
|
|
248
|
-
const { createNeonDatabaseProvider } = await import("./neon-
|
|
255
|
+
const { createNeonDatabaseProvider } = await import("./neon-DTZr7Bu7.mjs");
|
|
249
256
|
return createNeonDatabaseProvider();
|
|
250
257
|
}
|
|
251
258
|
const requireFromProject = createRequire(join(root, "package.json"));
|
|
@@ -305,7 +312,7 @@ async function runPush(root, dialect) {
|
|
|
305
312
|
printSuccess("Database schema pushed.");
|
|
306
313
|
return;
|
|
307
314
|
}
|
|
308
|
-
const { writeDrizzleConfig } = await import("./config-
|
|
315
|
+
const { writeDrizzleConfig } = await import("./config-DYJV8aEH.mjs");
|
|
309
316
|
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
310
317
|
mkdirSync(dirname(dbPath), { recursive: true });
|
|
311
318
|
const configPath = writeDrizzleConfig(root, dbPath);
|
|
@@ -321,15 +328,15 @@ async function runPush(root, dialect) {
|
|
|
321
328
|
printSuccess("Database schema pushed.");
|
|
322
329
|
}
|
|
323
330
|
async function runGenerate(root, dialect) {
|
|
324
|
-
const { prepareProject } = await import("./prepare-
|
|
325
|
-
const { PLACEHOLDER_DB_URL, writeDrizzleConfig } = await import("./config-
|
|
331
|
+
const { prepareProject } = await import("./prepare-EVEbQ9n2.mjs");
|
|
332
|
+
const { PLACEHOLDER_DB_URL, writeDrizzleConfig } = await import("./config-DYJV8aEH.mjs");
|
|
326
333
|
await prepareProject(root);
|
|
327
334
|
const authSchemaPath = join(root, ".void", "better-auth-schema.ts");
|
|
328
335
|
const additionalSchemas = existsSync(authSchemaPath) ? [authSchemaPath] : void 0;
|
|
329
336
|
const configPath = writeDrizzleConfig(root, PLACEHOLDER_DB_URL[dialect], dialect, { additionalSchemas });
|
|
330
337
|
try {
|
|
331
338
|
if (dialect === "sqlite") {
|
|
332
|
-
const { generateValidatedSqliteMigrations } = await import("./generate-
|
|
339
|
+
const { generateValidatedSqliteMigrations } = await import("./generate-DkEb9rL-.mjs");
|
|
333
340
|
await generateValidatedSqliteMigrations(readProjectPaths(root).migrationsDir, () => {
|
|
334
341
|
runDrizzleKit(root, [
|
|
335
342
|
"generate",
|
|
@@ -353,7 +360,7 @@ async function runStatus(root, dialect) {
|
|
|
353
360
|
const migrationsDir = paths.migrationsDir;
|
|
354
361
|
const allMigrations = collectMigrations(migrationsDir);
|
|
355
362
|
try {
|
|
356
|
-
assertJournalCoherence(migrationsDir, allMigrations);
|
|
363
|
+
assertJournalCoherence(migrationsDir, allMigrations, paths.sourceRelative);
|
|
357
364
|
} catch (err) {
|
|
358
365
|
log.error(getErrorMessage(err));
|
|
359
366
|
process.exit(1);
|
|
@@ -363,35 +370,36 @@ async function runStatus(root, dialect) {
|
|
|
363
370
|
return;
|
|
364
371
|
}
|
|
365
372
|
let localApplied;
|
|
373
|
+
let localError;
|
|
366
374
|
if (dialect === "postgresql") try {
|
|
367
|
-
const { readPgAppliedMigrations } = await import("./runner-pg-
|
|
375
|
+
const { readPgAppliedMigrations } = await import("./runner-pg-Cgp-cr_p.mjs");
|
|
368
376
|
localApplied = await withPgClient(root, readPgAppliedMigrations);
|
|
369
|
-
} catch {
|
|
370
|
-
|
|
377
|
+
} catch (error) {
|
|
378
|
+
localError = error;
|
|
371
379
|
}
|
|
372
380
|
else if (dialect === "mysql") try {
|
|
373
|
-
const { readMySqlAppliedMigrations } = await import("./runner-mysql-
|
|
381
|
+
const { readMySqlAppliedMigrations } = await import("./runner-mysql-BcHnLUuM.mjs");
|
|
374
382
|
localApplied = await withMySqlClient(root, readMySqlAppliedMigrations);
|
|
375
|
-
} catch {
|
|
376
|
-
|
|
383
|
+
} catch (error) {
|
|
384
|
+
localError = error;
|
|
377
385
|
}
|
|
378
386
|
else {
|
|
379
|
-
const { getAppliedMigrations } = await import("./runner-
|
|
387
|
+
const { getAppliedMigrations } = await import("./runner-WCdfeI0q.mjs");
|
|
380
388
|
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
381
389
|
localApplied = (await getAppliedMigrations(dbPath)).map((m) => m.name);
|
|
382
390
|
}
|
|
383
|
-
const localSet = new Set(localApplied);
|
|
391
|
+
const localSet = localApplied ? new Set(localApplied) : null;
|
|
384
392
|
let remoteApplied = null;
|
|
385
393
|
if (readDeploymentPlatform(root) === "cloudflare") try {
|
|
386
394
|
if (dialect !== "sqlite") {
|
|
387
395
|
const databaseUrl = process.env.DATABASE_URL;
|
|
388
396
|
if (!databaseUrl) throw new Error("DATABASE_URL is not available.");
|
|
389
|
-
remoteApplied = (dialect === "postgresql" ? await (await import("./runner-pg-
|
|
397
|
+
remoteApplied = (dialect === "postgresql" ? await (await import("./runner-pg-Cgp-cr_p.mjs")).getPgAppliedMigrations(databaseUrl) : await (await import("./runner-mysql-BcHnLUuM.mjs")).getMySqlAppliedMigrations(databaseUrl)).map((name) => ({
|
|
390
398
|
name,
|
|
391
399
|
applied_at: ""
|
|
392
400
|
}));
|
|
393
401
|
} else {
|
|
394
|
-
const { readCloudflareD1Migrations, resolveCloudflareD1Context } = await import("./cloudflare-operations-
|
|
402
|
+
const { readCloudflareD1Migrations, resolveCloudflareD1Context } = await import("./cloudflare-operations-BFLCpUCV.mjs");
|
|
395
403
|
remoteApplied = (await readCloudflareD1Migrations(resolveCloudflareD1Context(root, configuredD1Binding(root)))).map((name) => ({
|
|
396
404
|
name,
|
|
397
405
|
applied_at: ""
|
|
@@ -406,19 +414,29 @@ async function runStatus(root, dialect) {
|
|
|
406
414
|
} catch {}
|
|
407
415
|
}
|
|
408
416
|
const remoteSet = remoteApplied ? new Set(remoteApplied.map((m) => m.name)) : null;
|
|
417
|
+
if (localSet === null) {
|
|
418
|
+
const message = `Local migration status is unavailable: ${getErrorMessage(localError)}`;
|
|
419
|
+
if (remoteSet === null) {
|
|
420
|
+
log.error(message);
|
|
421
|
+
process.exit(1);
|
|
422
|
+
}
|
|
423
|
+
log.warn(message);
|
|
424
|
+
}
|
|
409
425
|
const lines = [];
|
|
410
426
|
for (const migration of allMigrations) {
|
|
411
|
-
const localStatus = localSet.has(migration.name) ? import_picocolors.default.green("applied") : import_picocolors.default.yellow("pending");
|
|
427
|
+
const localStatus = localSet === null ? dim("unknown") : localSet.has(migration.name) ? import_picocolors.default.green("applied") : import_picocolors.default.yellow("pending");
|
|
412
428
|
let remotePart = "";
|
|
413
429
|
if (remoteSet !== null) remotePart = ` remote: ${remoteSet.has(migration.name) ? import_picocolors.default.green("applied") : import_picocolors.default.yellow("pending")}`;
|
|
414
430
|
lines.push(` ${migration.name} ${dim("local:")} ${localStatus}${remotePart}`);
|
|
415
431
|
}
|
|
416
432
|
log.info(lines.join("\n"));
|
|
417
|
-
const localPending = allMigrations.length - localSet.size;
|
|
418
433
|
const parts = [formatCount(allMigrations.length, "migration")];
|
|
419
|
-
if (
|
|
434
|
+
if (localSet !== null) {
|
|
435
|
+
const localPending = allMigrations.filter((m) => !localSet.has(m.name)).length;
|
|
436
|
+
if (localPending > 0) parts.push(`${localPending} pending locally`);
|
|
437
|
+
}
|
|
420
438
|
if (remoteSet !== null) {
|
|
421
|
-
const remotePending = allMigrations.
|
|
439
|
+
const remotePending = allMigrations.filter((m) => !remoteSet.has(m.name)).length;
|
|
422
440
|
if (remotePending > 0) parts.push(`${remotePending} pending remotely`);
|
|
423
441
|
}
|
|
424
442
|
outro(parts.join(", "));
|
|
@@ -431,6 +449,69 @@ const LOCAL_DATABASE_HOSTS = /* @__PURE__ */ new Set([
|
|
|
431
449
|
"[::1]"
|
|
432
450
|
]);
|
|
433
451
|
/**
|
|
452
|
+
* Objects that `void db reset` drops in `public` before it applies every migration again:
|
|
453
|
+
* tables and views first, then standalone sequences, then enum, domain, range and composite
|
|
454
|
+
* types. drizzle-kit creates them without `IF NOT EXISTS`, so any one that stays makes the
|
|
455
|
+
* migration fail. Extension members stay, and so do sequences that a column owns: the table
|
|
456
|
+
* drop removes them, and their names change when a table is renamed.
|
|
457
|
+
*/
|
|
458
|
+
const PG_RESET_OBJECTS = `SELECT kind, name FROM (
|
|
459
|
+
SELECT CASE rel.relkind WHEN 'v' THEN 'VIEW' WHEN 'm' THEN 'MATERIALIZED VIEW'
|
|
460
|
+
WHEN 'S' THEN 'SEQUENCE' ELSE 'TABLE' END AS kind,
|
|
461
|
+
rel.relname AS name, CASE rel.relkind WHEN 'S' THEN 1 ELSE 0 END AS step
|
|
462
|
+
FROM pg_class rel JOIN pg_namespace ns ON ns.oid = rel.relnamespace
|
|
463
|
+
WHERE ns.nspname = 'public' AND rel.relkind IN ('r', 'p', 'v', 'm', 'S')
|
|
464
|
+
AND NOT EXISTS (
|
|
465
|
+
SELECT 1 FROM pg_depend dep WHERE dep.classid = 'pg_class'::regclass AND dep.objid = rel.oid
|
|
466
|
+
AND (dep.deptype = 'e' OR (rel.relkind = 'S' AND dep.deptype IN ('a', 'i')))
|
|
467
|
+
)
|
|
468
|
+
UNION ALL
|
|
469
|
+
SELECT 'TYPE', typ.typname, 2
|
|
470
|
+
FROM pg_type typ JOIN pg_namespace ns ON ns.oid = typ.typnamespace
|
|
471
|
+
WHERE ns.nspname = 'public'
|
|
472
|
+
AND (typ.typtype IN ('e', 'd', 'r')
|
|
473
|
+
OR (typ.typtype = 'c' AND (SELECT relkind FROM pg_class WHERE oid = typ.typrelid) = 'c'))
|
|
474
|
+
AND NOT EXISTS (
|
|
475
|
+
SELECT 1 FROM pg_depend dep WHERE dep.classid = 'pg_type'::regclass AND dep.objid = typ.oid
|
|
476
|
+
AND dep.deptype = 'e'
|
|
477
|
+
)
|
|
478
|
+
) objects ORDER BY step, name`;
|
|
479
|
+
/**
|
|
480
|
+
* Objects in other schemas that `CASCADE` would also drop with the types ($1) and the views,
|
|
481
|
+
* materialized views and sequences ($2) that reset drops in `public`: a column of that type or
|
|
482
|
+
* its array type, a view, a function, a column default and so on, also through a type or
|
|
483
|
+
* function in `public` that goes with them. Reset must not remove these, so it stops when there
|
|
484
|
+
* are any. The TOAST table of a materialized view is part of it, so it does not count. The table
|
|
485
|
+
* drops still remove what depends on a `public` table in another schema (a view, a foreign key,
|
|
486
|
+
* an inheriting table); a view that also uses one of these objects is listed here too.
|
|
487
|
+
*/
|
|
488
|
+
const PG_RESET_OUTSIDE_DEPENDENTS = `WITH RECURSIVE dropped(classid, objid) AS (
|
|
489
|
+
SELECT 'pg_type'::regclass::oid, typ.oid FROM pg_type typ
|
|
490
|
+
WHERE typ.typnamespace = 'public'::regnamespace AND typ.typname = ANY($1::text[])
|
|
491
|
+
UNION ALL
|
|
492
|
+
SELECT 'pg_class'::regclass::oid, rel.oid FROM pg_class rel
|
|
493
|
+
WHERE rel.relnamespace = 'public'::regnamespace AND rel.relname = ANY($2::text[])
|
|
494
|
+
UNION
|
|
495
|
+
SELECT dep.classid, dep.objid FROM dropped
|
|
496
|
+
JOIN pg_depend dep ON dep.refclassid = dropped.classid AND dep.refobjid = dropped.objid
|
|
497
|
+
WHERE dep.classid IN ('pg_type'::regclass, 'pg_proc'::regclass)
|
|
498
|
+
AND (pg_identify_object(dep.classid, dep.objid, 0)).schema = 'public'
|
|
499
|
+
)
|
|
500
|
+
SELECT DISTINCT pg_describe_object(dep.classid, dep.objid, dep.objsubid) || ' uses '
|
|
501
|
+
|| pg_describe_object(dep.refclassid, dep.refobjid, 0) AS object
|
|
502
|
+
FROM dropped
|
|
503
|
+
JOIN pg_depend dep ON dep.refclassid = dropped.classid AND dep.refobjid = dropped.objid
|
|
504
|
+
WHERE NOT (dep.classid = 'pg_class'::regclass AND dep.deptype = 'i')
|
|
505
|
+
AND COALESCE((pg_identify_object(dep.classid, dep.objid, dep.objsubid)).schema, (
|
|
506
|
+
SELECT ns.nspname FROM pg_class rel JOIN pg_namespace ns ON ns.oid = rel.relnamespace
|
|
507
|
+
WHERE rel.oid = CASE dep.classid
|
|
508
|
+
WHEN 'pg_attrdef'::regclass THEN (SELECT adrelid FROM pg_attrdef WHERE oid = dep.objid)
|
|
509
|
+
WHEN 'pg_rewrite'::regclass THEN (SELECT ev_class FROM pg_rewrite WHERE oid = dep.objid)
|
|
510
|
+
WHEN 'pg_trigger'::regclass THEN (SELECT tgrelid FROM pg_trigger WHERE oid = dep.objid)
|
|
511
|
+
WHEN 'pg_policy'::regclass THEN (SELECT polrelid FROM pg_policy WHERE oid = dep.objid)
|
|
512
|
+
END)) <> 'public'
|
|
513
|
+
ORDER BY object`;
|
|
514
|
+
/**
|
|
434
515
|
* `.env` may hold the deployed database URL (`void db connect` writes it there), so ask before
|
|
435
516
|
* dropping every table on any other host. Without a TTY, require `--yes`.
|
|
436
517
|
*/
|
|
@@ -446,39 +527,56 @@ async function confirmDropAllTables(host, target, yes) {
|
|
|
446
527
|
process.exit(0);
|
|
447
528
|
}
|
|
448
529
|
}
|
|
530
|
+
async function confirmReset(root, dialect, yes) {
|
|
531
|
+
if (dialect === "postgresql") {
|
|
532
|
+
const { Client } = await import("pg");
|
|
533
|
+
const { host, port, database } = new Client({ connectionString: getLocalDatabaseUrl(root, dialect) });
|
|
534
|
+
await confirmDropAllTables(host, `database "${database}" on ${host}:${port}`, yes);
|
|
535
|
+
} else if (dialect === "mysql") {
|
|
536
|
+
const { hostname, host, pathname } = new URL(getLocalDatabaseUrl(root, dialect));
|
|
537
|
+
await confirmDropAllTables(hostname, `database "${decodeURIComponent(pathname.slice(1))}" on ${host}`, yes);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
449
540
|
async function resetDatabase(root, dialect, yes) {
|
|
450
|
-
const
|
|
541
|
+
const paths = readProjectPaths(root);
|
|
542
|
+
const migrationsDir = paths.migrationsDir;
|
|
451
543
|
const migrations = collectMigrations(migrationsDir);
|
|
452
544
|
try {
|
|
453
|
-
assertJournalCoherence(migrationsDir, migrations);
|
|
545
|
+
assertJournalCoherence(migrationsDir, migrations, paths.sourceRelative);
|
|
454
546
|
} catch (err) {
|
|
455
547
|
log.error(getErrorMessage(err));
|
|
456
548
|
process.exit(1);
|
|
457
549
|
}
|
|
550
|
+
await confirmReset(root, dialect, yes);
|
|
458
551
|
if (dialect === "postgresql") {
|
|
459
|
-
const {
|
|
460
|
-
const { host, port, database } = new Client({ connectionString: getLocalDatabaseUrl(root, dialect) });
|
|
461
|
-
await confirmDropAllTables(host, `database "${database}" on ${host}:${port}`, yes);
|
|
462
|
-
const { applyPgMigrations } = await import("./runner-pg-_Xncr3H5.mjs");
|
|
552
|
+
const { applyPgMigrations } = await import("./runner-pg-Cgp-cr_p.mjs");
|
|
463
553
|
await withPgClient(root, async (client) => {
|
|
464
|
-
const
|
|
465
|
-
|
|
554
|
+
const objects = await client.query(PG_RESET_OBJECTS);
|
|
555
|
+
const names = (kind) => objects.rows.filter((row) => row.kind === kind).map((row) => row.name);
|
|
556
|
+
const types = names("TYPE");
|
|
557
|
+
const relations = [
|
|
558
|
+
...names("VIEW"),
|
|
559
|
+
...names("MATERIALIZED VIEW"),
|
|
560
|
+
...names("SEQUENCE")
|
|
561
|
+
];
|
|
562
|
+
const outside = types.length > 0 || relations.length > 0 ? await client.query(PG_RESET_OUTSIDE_DEPENDENTS, [types, relations]) : { rows: [] };
|
|
563
|
+
if (outside.rows.length > 0) throw new Error("db: Reset stopped before dropping anything. Dropping the views, sequences and types in the public schema would also remove these objects in other schemas:\n" + outside.rows.map((row) => ` - ${row.object}\n`).join("") + "Change or drop these objects, or move the views, sequences and types they use out of the public schema, then run the command again.");
|
|
564
|
+
for (const { kind, name } of objects.rows) await client.query(`DROP ${kind} IF EXISTS public.${quoteSqlIdentifier(name)} CASCADE`);
|
|
466
565
|
await applyPgMigrations(client, migrations);
|
|
467
566
|
});
|
|
468
567
|
return migrations.length;
|
|
469
568
|
}
|
|
470
569
|
if (dialect === "mysql") {
|
|
471
|
-
const {
|
|
472
|
-
await confirmDropAllTables(hostname, `database "${decodeURIComponent(pathname.slice(1))}" on ${host}`, yes);
|
|
473
|
-
const { applyPendingMySqlMigrations, withMySqlMigrationLock } = await import("./runner-mysql-DWwE8jKi.mjs");
|
|
570
|
+
const { applyPendingMySqlMigrations, withMySqlMigrationLock } = await import("./runner-mysql-BcHnLUuM.mjs");
|
|
474
571
|
await withMySqlClient(root, (client) => withMySqlMigrationLock(client, async () => {
|
|
475
|
-
const tables = await client.query("SELECT table_name AS table_name FROM information_schema.tables WHERE table_schema = DATABASE() AND table_type
|
|
572
|
+
const tables = await client.query("SELECT table_name AS table_name, table_type AS table_type FROM information_schema.tables WHERE table_schema = DATABASE() AND table_type IN ('BASE TABLE', 'VIEW')");
|
|
476
573
|
await client.query("SET FOREIGN_KEY_CHECKS = 0");
|
|
477
574
|
try {
|
|
478
575
|
for (const row of tables) {
|
|
479
576
|
if (row.table_name === "_void_migration_lock") continue;
|
|
577
|
+
const kind = row.table_type === "VIEW" ? "VIEW" : "TABLE";
|
|
480
578
|
const table = String(row.table_name).replaceAll("`", "``");
|
|
481
|
-
await client.query(`DROP
|
|
579
|
+
await client.query(`DROP ${kind} IF EXISTS \`${table}\``);
|
|
482
580
|
}
|
|
483
581
|
} finally {
|
|
484
582
|
await client.query("SET FOREIGN_KEY_CHECKS = 1");
|
|
@@ -487,7 +585,7 @@ async function resetDatabase(root, dialect, yes) {
|
|
|
487
585
|
}));
|
|
488
586
|
return migrations.length;
|
|
489
587
|
}
|
|
490
|
-
const { runMigrations } = await import("./runner-
|
|
588
|
+
const { runMigrations } = await import("./runner-WCdfeI0q.mjs");
|
|
491
589
|
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
492
590
|
rmSync(dbPath, { force: true });
|
|
493
591
|
rmSync(dbPath + "-wal", { force: true });
|
|
@@ -500,11 +598,13 @@ async function runReset(root, dialect, yes) {
|
|
|
500
598
|
printSuccess(`Database reset. Applied ${formatCount(count, "migration")}.`);
|
|
501
599
|
}
|
|
502
600
|
async function runSeed(root, file, dialect, yes) {
|
|
503
|
-
const migrationCount = await resetDatabase(root, dialect, yes);
|
|
504
|
-
log.step(`Reset database. Applied ${formatCount(migrationCount, "migration")}.`);
|
|
505
601
|
const seed = resolveSeedTarget(root, file);
|
|
506
|
-
|
|
507
|
-
|
|
602
|
+
const sql = seed.kind === "sql" ? readFileSync(seed.path, "utf-8") : void 0;
|
|
603
|
+
await confirmReset(root, dialect, yes);
|
|
604
|
+
const seedFn = sql === void 0 ? await loadSeedFunction(seed.path) : void 0;
|
|
605
|
+
const migrationCount = await resetDatabase(root, dialect, true);
|
|
606
|
+
log.step(`Reset database. Applied ${formatCount(migrationCount, "migration")}.`);
|
|
607
|
+
if (sql !== void 0) {
|
|
508
608
|
if (dialect === "postgresql") {
|
|
509
609
|
await withPgClient(root, async (client) => {
|
|
510
610
|
await client.query(sql);
|
|
@@ -519,7 +619,7 @@ async function runSeed(root, file, dialect, yes) {
|
|
|
519
619
|
printSuccess(`Seeded from ${seed.displayPath}.`);
|
|
520
620
|
return;
|
|
521
621
|
}
|
|
522
|
-
const { openSqliteDatabase } = await import("./runner-
|
|
622
|
+
const { openSqliteDatabase } = await import("./runner-WCdfeI0q.mjs");
|
|
523
623
|
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
524
624
|
const db = await openSqliteDatabase(dbPath);
|
|
525
625
|
try {
|
|
@@ -527,7 +627,7 @@ async function runSeed(root, file, dialect, yes) {
|
|
|
527
627
|
} finally {
|
|
528
628
|
db.close();
|
|
529
629
|
}
|
|
530
|
-
} else await runSeedModule(root,
|
|
630
|
+
} else await runSeedModule(root, seedFn, dialect);
|
|
531
631
|
log.info(dim("Restart your dev server if it's running."));
|
|
532
632
|
printSuccess(`Seeded from ${seed.displayPath}.`);
|
|
533
633
|
}
|
|
@@ -604,18 +704,14 @@ async function confirmDestructiveRemote(sql) {
|
|
|
604
704
|
async function runExecute(root, command, file, dialect, remote) {
|
|
605
705
|
if (remote) {
|
|
606
706
|
const directCloudflare = readDeploymentPlatform(root) === "cloudflare";
|
|
607
|
-
|
|
608
|
-
log.error("--file is not yet supported with --remote D1; pipe statements through stdin or run them one at a time.");
|
|
609
|
-
process.exit(1);
|
|
610
|
-
}
|
|
611
|
-
const sql = file ? readFileSync(join(root, file), "utf-8") : command;
|
|
707
|
+
const sql = file ? readFileSync(resolve(root, file), "utf-8") : command;
|
|
612
708
|
if (directCloudflare) {
|
|
613
709
|
if (!await confirmDestructiveRemote(sql)) {
|
|
614
710
|
log.info("Cancelled.");
|
|
615
711
|
process.exit(0);
|
|
616
712
|
}
|
|
617
713
|
if (dialect === "sqlite") {
|
|
618
|
-
const { executeCloudflareD1Sql, resolveCloudflareD1Context } = await import("./cloudflare-operations-
|
|
714
|
+
const { executeCloudflareD1Sql, resolveCloudflareD1Context } = await import("./cloudflare-operations-BFLCpUCV.mjs");
|
|
619
715
|
const rows = await executeCloudflareD1Sql(resolveCloudflareD1Context(root, configuredD1Binding(root)), sql);
|
|
620
716
|
if (rows.length > 0) printTable(rows);
|
|
621
717
|
} else {
|
|
@@ -649,10 +745,11 @@ async function runExecute(root, command, file, dialect, remote) {
|
|
|
649
745
|
return;
|
|
650
746
|
}
|
|
651
747
|
const platformClient = new PlatformClient(token, { root });
|
|
652
|
-
|
|
748
|
+
const configuredBinding = configuredD1Binding(root);
|
|
749
|
+
let binding = configuredBinding;
|
|
653
750
|
try {
|
|
654
|
-
const
|
|
655
|
-
if (
|
|
751
|
+
const d1Bindings = (await platformClient.getResources(projectConfig.projectId)).filter((r) => r.type === "d1").map((r) => r.binding_name);
|
|
752
|
+
if (!d1Bindings.includes(configuredBinding) && d1Bindings.length === 1) binding = d1Bindings[0];
|
|
656
753
|
} catch {}
|
|
657
754
|
const proxyUrl = getProxyUrl(root);
|
|
658
755
|
ensurePlatformProxyAccess(platformClient.apiUrl, proxyUrl);
|
|
@@ -698,7 +795,7 @@ async function runExecute(root, command, file, dialect, remote) {
|
|
|
698
795
|
return;
|
|
699
796
|
}
|
|
700
797
|
if (dialect === "postgresql") {
|
|
701
|
-
const sql = file ? readFileSync(
|
|
798
|
+
const sql = file ? readFileSync(resolve(root, file), "utf-8") : command;
|
|
702
799
|
await withPgClient(root, async (client) => {
|
|
703
800
|
const result = await client.query(sql);
|
|
704
801
|
if (result.rows && result.rows.length > 0) printTable(result.rows);
|
|
@@ -707,7 +804,7 @@ async function runExecute(root, command, file, dialect, remote) {
|
|
|
707
804
|
return;
|
|
708
805
|
}
|
|
709
806
|
if (dialect === "mysql") {
|
|
710
|
-
const sql = file ? readFileSync(
|
|
807
|
+
const sql = file ? readFileSync(resolve(root, file), "utf-8") : command;
|
|
711
808
|
await withMySqlClient(root, async (client) => {
|
|
712
809
|
const rows = await client.query(sql);
|
|
713
810
|
if (rows.length > 0) printTable(rows);
|
|
@@ -715,13 +812,13 @@ async function runExecute(root, command, file, dialect, remote) {
|
|
|
715
812
|
printSuccess("SQL executed successfully.");
|
|
716
813
|
return;
|
|
717
814
|
}
|
|
718
|
-
const { openSqliteDatabase } = await import("./runner-
|
|
815
|
+
const { openSqliteDatabase } = await import("./runner-WCdfeI0q.mjs");
|
|
719
816
|
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
720
817
|
if (!existsSync(dbPath)) {
|
|
721
|
-
log.error("No local database found.
|
|
818
|
+
log.error("No local database found. Start the dev server first.");
|
|
722
819
|
process.exit(1);
|
|
723
820
|
}
|
|
724
|
-
const sql = file ? readFileSync(
|
|
821
|
+
const sql = file ? readFileSync(resolve(root, file), "utf-8") : command;
|
|
725
822
|
const db = await openSqliteDatabase(dbPath);
|
|
726
823
|
try {
|
|
727
824
|
const trimmed = sql.trimStart();
|
|
@@ -754,7 +851,7 @@ async function runMigrate(root, dialect, remote) {
|
|
|
754
851
|
const migrationsDir = paths.migrationsDir;
|
|
755
852
|
const rawMigrations = collectMigrations(migrationsDir);
|
|
756
853
|
try {
|
|
757
|
-
assertJournalCoherence(migrationsDir, rawMigrations);
|
|
854
|
+
assertJournalCoherence(migrationsDir, rawMigrations, paths.sourceRelative);
|
|
758
855
|
} catch (err) {
|
|
759
856
|
log.error(getErrorMessage(err));
|
|
760
857
|
process.exit(1);
|
|
@@ -779,11 +876,11 @@ async function runMigrate(root, dialect, remote) {
|
|
|
779
876
|
let appliedNames;
|
|
780
877
|
let applyMigrations;
|
|
781
878
|
if (dialect === "postgresql") {
|
|
782
|
-
const { getPgAppliedMigrations, runPgMigrations } = await import("./runner-pg-
|
|
879
|
+
const { getPgAppliedMigrations, runPgMigrations } = await import("./runner-pg-Cgp-cr_p.mjs");
|
|
783
880
|
appliedNames = await getPgAppliedMigrations(databaseUrl);
|
|
784
881
|
applyMigrations = () => runPgMigrations(migrationsDir, databaseUrl);
|
|
785
882
|
} else {
|
|
786
|
-
const { getMySqlAppliedMigrations, runMySqlMigrations } = await import("./runner-mysql-
|
|
883
|
+
const { getMySqlAppliedMigrations, runMySqlMigrations } = await import("./runner-mysql-BcHnLUuM.mjs");
|
|
787
884
|
appliedNames = await getMySqlAppliedMigrations(databaseUrl);
|
|
788
885
|
applyMigrations = () => runMySqlMigrations(migrationsDir, databaseUrl);
|
|
789
886
|
}
|
|
@@ -808,7 +905,7 @@ async function runMigrate(root, dialect, remote) {
|
|
|
808
905
|
log.info(`No migration files found in ${paths.sourceRelative("db/migrations")}/`);
|
|
809
906
|
return;
|
|
810
907
|
}
|
|
811
|
-
const { applyCloudflareD1Migrations, readCloudflareD1Migrations, resolveCloudflareD1Context } = await import("./cloudflare-operations-
|
|
908
|
+
const { applyCloudflareD1Migrations, readCloudflareD1Migrations, resolveCloudflareD1Context } = await import("./cloudflare-operations-BFLCpUCV.mjs");
|
|
812
909
|
const binding = configuredD1Binding(root);
|
|
813
910
|
const context = resolveCloudflareD1Context(root, binding);
|
|
814
911
|
const remoteBefore = new Set(await readCloudflareD1Migrations(context));
|
|
@@ -823,8 +920,13 @@ async function runMigrate(root, dialect, remote) {
|
|
|
823
920
|
log.error(getErrorMessage(error));
|
|
824
921
|
process.exit(1);
|
|
825
922
|
}
|
|
826
|
-
|
|
827
|
-
|
|
923
|
+
if (!context.migrationsDir) {
|
|
924
|
+
const dir = paths.sourceRelative("db/migrations");
|
|
925
|
+
log.error(`db: D1 binding ${binding} has no "migrations_dir", so Cloudflare would apply ./migrations instead of ${dir}/. Add "migrations_dir": "./${dir}" to that D1 binding in your Cloudflare config, then run the command again.`);
|
|
926
|
+
process.exit(1);
|
|
927
|
+
}
|
|
928
|
+
const { checkWranglerMigrationApplySet, parseRootWranglerConfig } = await import("./deploy-Dc0XsCQj.mjs");
|
|
929
|
+
const applySet = await checkWranglerMigrationApplySet(context.operation.configPath, parseRootWranglerConfig(context.operation.configPath), binding, context.migrationsDir, rawMigrations, paths.sourceRelative("db/migrations"));
|
|
828
930
|
if (!applySet.ok) {
|
|
829
931
|
log.error(applySet.reason);
|
|
830
932
|
process.exit(1);
|
|
@@ -885,7 +987,7 @@ async function runMigrate(root, dialect, remote) {
|
|
|
885
987
|
return;
|
|
886
988
|
}
|
|
887
989
|
if (dialect === "postgresql") {
|
|
888
|
-
const { applyPgMigrations, readPgAppliedMigrations } = await import("./runner-pg-
|
|
990
|
+
const { applyPgMigrations, readPgAppliedMigrations } = await import("./runner-pg-Cgp-cr_p.mjs");
|
|
889
991
|
const applied = await withPgClient(root, async (client) => {
|
|
890
992
|
const appliedNames = await readPgAppliedMigrations(client).catch(() => []);
|
|
891
993
|
try {
|
|
@@ -904,7 +1006,7 @@ async function runMigrate(root, dialect, remote) {
|
|
|
904
1006
|
return;
|
|
905
1007
|
}
|
|
906
1008
|
if (dialect === "mysql") {
|
|
907
|
-
const { applyMySqlMigrations, readMySqlAppliedMigrations } = await import("./runner-mysql-
|
|
1009
|
+
const { applyMySqlMigrations, readMySqlAppliedMigrations } = await import("./runner-mysql-BcHnLUuM.mjs");
|
|
908
1010
|
const applied = await withMySqlClient(root, async (client) => {
|
|
909
1011
|
const appliedNames = await readMySqlAppliedMigrations(client).catch(() => []);
|
|
910
1012
|
try {
|
|
@@ -922,7 +1024,7 @@ async function runMigrate(root, dialect, remote) {
|
|
|
922
1024
|
}
|
|
923
1025
|
return;
|
|
924
1026
|
}
|
|
925
|
-
const { getAppliedMigrations, runMigrations } = await import("./runner-
|
|
1027
|
+
const { getAppliedMigrations, runMigrations } = await import("./runner-WCdfeI0q.mjs");
|
|
926
1028
|
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
927
1029
|
try {
|
|
928
1030
|
const existingRows = await getAppliedMigrations(dbPath);
|
|
@@ -931,7 +1033,7 @@ async function runMigrate(root, dialect, remote) {
|
|
|
931
1033
|
log.error(getErrorMessage(err));
|
|
932
1034
|
process.exit(1);
|
|
933
1035
|
}
|
|
934
|
-
const applied = await runMigrations(migrationsDir, dbPath);
|
|
1036
|
+
const applied = await runMigrations(migrationsDir, dbPath, paths.sourceRelative);
|
|
935
1037
|
if (applied.length === 0) log.info("All migrations are up to date.");
|
|
936
1038
|
else {
|
|
937
1039
|
for (const name of applied) log.step(name);
|
|
@@ -939,10 +1041,59 @@ async function runMigrate(root, dialect, remote) {
|
|
|
939
1041
|
printSuccess(`Applied ${formatCount(applied.length, "migration")}.`);
|
|
940
1042
|
}
|
|
941
1043
|
}
|
|
1044
|
+
async function runRestore(root, dialect, { target, platform: explicitPlatform, yes }) {
|
|
1045
|
+
const platform = readDeploymentPlatform(root);
|
|
1046
|
+
const directCloudflare = explicitPlatform === "cloudflare" || platform === "cloudflare" || platform === null && !readProjectConfig(root) && await hasDeployedCloudflareDatabase(root);
|
|
1047
|
+
if (dialect !== "sqlite") {
|
|
1048
|
+
log.error("db: `void db restore` restores D1 databases only.");
|
|
1049
|
+
process.exit(1);
|
|
1050
|
+
}
|
|
1051
|
+
if (!directCloudflare) {
|
|
1052
|
+
log.error("db: `void db restore` restores the D1 database of a direct Cloudflare deploy. After a one-off `void deploy --platform cloudflare`, run it with `--platform cloudflare`.");
|
|
1053
|
+
process.exit(1);
|
|
1054
|
+
}
|
|
1055
|
+
const { readCloudflareD1Migrations, resolveCloudflareD1Context, restoreCloudflareD1Database } = await import("./cloudflare-operations-BFLCpUCV.mjs");
|
|
1056
|
+
const binding = configuredD1Binding(root);
|
|
1057
|
+
const context = resolveCloudflareD1Context(root, binding);
|
|
1058
|
+
const database = `D1 database ${context.migrateToken} (${binding})`;
|
|
1059
|
+
const point = "bookmark" in target ? `bookmark ${target.bookmark}` : target.timestamp;
|
|
1060
|
+
if (!yes) {
|
|
1061
|
+
if (!process.stdin.isTTY) {
|
|
1062
|
+
log.error(`db: Refusing to restore ${database} without confirmation. Re-run with --yes.`);
|
|
1063
|
+
process.exit(1);
|
|
1064
|
+
}
|
|
1065
|
+
const ok = await confirm({
|
|
1066
|
+
message: `This restores ${database} to ${point} and discards every write made after it. Continue?`,
|
|
1067
|
+
initialValue: false
|
|
1068
|
+
});
|
|
1069
|
+
if (isCancel(ok) || !ok) {
|
|
1070
|
+
log.info("Cancelled.");
|
|
1071
|
+
process.exit(0);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
let previousBookmark;
|
|
1075
|
+
try {
|
|
1076
|
+
previousBookmark = await restoreCloudflareD1Database(context, target);
|
|
1077
|
+
} catch (error) {
|
|
1078
|
+
log.error(`db: Could not restore ${database} to ${point}: ${getErrorMessage(error)}\nRestore points expire after 7 days on Workers Free and 30 days on Workers Paid. To undo an older migration, write a new migration that reverses it.`);
|
|
1079
|
+
process.exit(1);
|
|
1080
|
+
}
|
|
1081
|
+
const platformFlag = platform === "cloudflare" ? "" : " --platform cloudflare";
|
|
1082
|
+
if (previousBookmark) log.info(`To undo this restore, run \`void db restore${platformFlag} --bookmark=${previousBookmark}\`.`);
|
|
1083
|
+
const paths = readProjectPaths(root);
|
|
1084
|
+
try {
|
|
1085
|
+
const applied = new Set(await readCloudflareD1Migrations(context));
|
|
1086
|
+
const unapplied = collectMigrations(paths.migrationsDir).filter((migration) => !applied.has(migration.name));
|
|
1087
|
+
if (unapplied.length > 0) log.warn(`The remote database does not have these migrations applied: ${unapplied.map((migration) => migration.name).join(", ")}. The next \`void deploy${platformFlag}\` applies them. Fix or remove a migration that caused the problem before you deploy.`);
|
|
1088
|
+
} catch (error) {
|
|
1089
|
+
log.warn(`Could not read the applied migrations after the restore: ${getErrorMessage(error)}. ` + (platformFlag ? `The next \`void deploy${platformFlag}\` applies any migration the restore rewound.` : "Run `void db status` to check them."));
|
|
1090
|
+
}
|
|
1091
|
+
printSuccess(`Restored ${database} to ${point}.`);
|
|
1092
|
+
}
|
|
942
1093
|
async function runStudio(root, dialect, remote) {
|
|
943
1094
|
if (remote) {
|
|
944
1095
|
if (dialect === "sqlite") {
|
|
945
|
-
log.error("Remote
|
|
1096
|
+
log.error("Remote Studio supports PostgreSQL and MySQL databases. For D1, use `void db execute --remote` to query the deployed database.");
|
|
946
1097
|
process.exit(1);
|
|
947
1098
|
}
|
|
948
1099
|
let dbUrl;
|
|
@@ -975,10 +1126,10 @@ async function runStudio(root, dialect, remote) {
|
|
|
975
1126
|
await runDrizzleKitWithDatabaseUrl(root, url, dialect, "studio");
|
|
976
1127
|
return;
|
|
977
1128
|
}
|
|
978
|
-
const { writeDrizzleConfig } = await import("./config-
|
|
1129
|
+
const { writeDrizzleConfig } = await import("./config-DYJV8aEH.mjs");
|
|
979
1130
|
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
980
1131
|
if (!existsSync(dbPath)) {
|
|
981
|
-
log.error("No local database found.
|
|
1132
|
+
log.error("No local database found. Start the dev server first.");
|
|
982
1133
|
process.exit(1);
|
|
983
1134
|
}
|
|
984
1135
|
const configPath = writeDrizzleConfig(root, dbPath);
|
|
@@ -993,21 +1144,37 @@ async function runStudio(root, dialect, remote) {
|
|
|
993
1144
|
process.exit(1);
|
|
994
1145
|
}
|
|
995
1146
|
}
|
|
1147
|
+
/** A direct Cloudflare deploy records its D1 or Hyperdrive id in the checked-in Cloudflare config. */
|
|
1148
|
+
async function hasDeployedCloudflareDatabase(root) {
|
|
1149
|
+
const { readRootWranglerConfig } = await import("./wrangler-DAdxHEzh.mjs");
|
|
1150
|
+
const { isRealD1Id, isRealHyperdriveId } = await import("./provision-BgXFDv0d.mjs");
|
|
1151
|
+
const config = readRootWranglerConfig(root)?.config;
|
|
1152
|
+
const entries = (key) => {
|
|
1153
|
+
const value = config?.[key];
|
|
1154
|
+
return Array.isArray(value) ? value.filter((entry) => !!entry && typeof entry === "object") : [];
|
|
1155
|
+
};
|
|
1156
|
+
return entries("d1_databases").some((entry) => isRealD1Id(entry.database_id)) || entries("hyperdrive").some((entry) => isRealHyperdriveId(entry.id));
|
|
1157
|
+
}
|
|
996
1158
|
async function runRenameMigrations(root, dialect) {
|
|
997
|
-
const
|
|
1159
|
+
const paths = readProjectPaths(root);
|
|
1160
|
+
const migrationsDir = paths.migrationsDir;
|
|
1161
|
+
const dir = paths.sourceRelative("db/migrations");
|
|
998
1162
|
if (!existsSync(migrationsDir)) {
|
|
999
1163
|
log.info("No migrations directory found.");
|
|
1000
1164
|
return;
|
|
1001
1165
|
}
|
|
1002
1166
|
const currentMigrations = collectMigrations(migrationsDir);
|
|
1003
1167
|
try {
|
|
1004
|
-
assertJournalCoherence(migrationsDir, currentMigrations);
|
|
1168
|
+
assertJournalCoherence(migrationsDir, currentMigrations, paths.sourceRelative);
|
|
1005
1169
|
} catch (err) {
|
|
1006
1170
|
log.error(getErrorMessage(err));
|
|
1007
1171
|
process.exit(1);
|
|
1008
1172
|
}
|
|
1009
1173
|
if (existsSync(join(migrationsDir, "migrations.js"))) {
|
|
1010
|
-
log.error(
|
|
1174
|
+
log.error(`This project uses Drizzle's bundled migration format (${dir}/migrations.js).\n\`void db rename-migrations\` cannot rename migrations in bundled mode because
|
|
1175
|
+
\`migrations.js\` contains static imports of the SQL files by filename.
|
|
1176
|
+
|
|
1177
|
+
Delete ${dir}/migrations.js and re-run \`void db generate\` to migrate away\nfrom bundled mode, then retry \`void db rename-migrations\`.`);
|
|
1011
1178
|
process.exit(1);
|
|
1012
1179
|
}
|
|
1013
1180
|
const files = readdirSync(migrationsDir).filter((f) => f.endsWith(".sql") && f !== "seed.sql").sort();
|
|
@@ -1016,6 +1183,16 @@ async function runRenameMigrations(root, dialect) {
|
|
|
1016
1183
|
log.info("No migrations with numeric prefixes found. Nothing to rename.");
|
|
1017
1184
|
return;
|
|
1018
1185
|
}
|
|
1186
|
+
const platform = readDeploymentPlatform(root);
|
|
1187
|
+
const config = readProjectConfig(root);
|
|
1188
|
+
if (platform === "cloudflare" || !config && platform !== "void" && await hasDeployedCloudflareDatabase(root)) {
|
|
1189
|
+
log.error("`void db rename-migrations` does not support direct Cloudflare deploys.\nVoid cannot rename the migration records in your deployed database, so the next deploy would run the renamed migrations again.\nKeep the current file names. New migrations use timestamps and run after them.");
|
|
1190
|
+
process.exit(1);
|
|
1191
|
+
}
|
|
1192
|
+
if (platform === "void" && !config) {
|
|
1193
|
+
log.error("This project deploys to Void but is not linked, so Void cannot rename the migration records in its deployed database.\nRun `void project link`, then run `void db rename-migrations` again.");
|
|
1194
|
+
process.exit(1);
|
|
1195
|
+
}
|
|
1019
1196
|
const timestampFiles = files.filter((f) => /^\d{14}_/.test(f));
|
|
1020
1197
|
let baseTime;
|
|
1021
1198
|
if (timestampFiles.length > 0) {
|
|
@@ -1042,7 +1219,7 @@ async function runRenameMigrations(root, dialect) {
|
|
|
1042
1219
|
const metaDir = join(migrationsDir, "meta");
|
|
1043
1220
|
const journalPath = join(metaDir, "_journal.json");
|
|
1044
1221
|
const originalJournalBytes = existsSync(journalPath) ? readFileSync(journalPath) : null;
|
|
1045
|
-
const journal = readJournal(migrationsDir);
|
|
1222
|
+
const journal = readJournal(migrationsDir, paths.sourceRelative);
|
|
1046
1223
|
const snapshotPrefix = (tag) => tag.split("_")[0];
|
|
1047
1224
|
const snapshotPathFor = (tag) => join(metaDir, `${snapshotPrefix(tag)}_snapshot.json`);
|
|
1048
1225
|
if (journal && journal.entries.length > 0) {
|
|
@@ -1054,13 +1231,12 @@ async function runRenameMigrations(root, dialect) {
|
|
|
1054
1231
|
}
|
|
1055
1232
|
if (missingSnapshots.length > 0) {
|
|
1056
1233
|
log.error("db: Cannot rename migrations because one or more Drizzle snapshot files are missing:");
|
|
1057
|
-
for (const p of missingSnapshots) log.error(` -
|
|
1234
|
+
for (const p of missingSnapshots) log.error(` - ${dir}/${p}`);
|
|
1058
1235
|
log.error("\nRestore the missing snapshot(s) from version control, or reset the migration directory with `void db generate`, then retry.");
|
|
1059
1236
|
process.exit(1);
|
|
1060
1237
|
}
|
|
1061
1238
|
}
|
|
1062
1239
|
const token = getToken(root);
|
|
1063
|
-
const config = readProjectConfig(root);
|
|
1064
1240
|
let remoteRenamed = false;
|
|
1065
1241
|
if (config && !token) {
|
|
1066
1242
|
log.error("Project is linked but you are not logged in.\nRun `void account login` first so remote migration records can be updated.");
|
|
@@ -1091,7 +1267,8 @@ async function runRenameMigrations(root, dialect) {
|
|
|
1091
1267
|
if (journalRewritten && originalJournalBytes !== null) try {
|
|
1092
1268
|
writeFileSync(journalPath, originalJournalBytes);
|
|
1093
1269
|
} catch (error) {
|
|
1094
|
-
log.warn(
|
|
1270
|
+
log.warn(`Could not restore ${dir}/meta/_journal.json after rollback. The journal may be in a partial state.
|
|
1271
|
+
Regenerate it with \`void db generate\`, or restore it from version control.`);
|
|
1095
1272
|
log.warn(String(error));
|
|
1096
1273
|
}
|
|
1097
1274
|
if (remoteRenamed && token && config) try {
|
|
@@ -1130,8 +1307,8 @@ async function runRenameMigrations(root, dialect) {
|
|
|
1130
1307
|
await rollback("db: Failed to rename migration files. All changes have been reverted.", err);
|
|
1131
1308
|
}
|
|
1132
1309
|
if (journal) try {
|
|
1133
|
-
const current = readJournal(migrationsDir);
|
|
1134
|
-
if (!current) throw new Error(
|
|
1310
|
+
const current = readJournal(migrationsDir, paths.sourceRelative);
|
|
1311
|
+
if (!current) throw new Error(`db: ${dir}/meta/_journal.json disappeared mid-run. File renames will be reverted.`);
|
|
1135
1312
|
const renameMap = /* @__PURE__ */ new Map();
|
|
1136
1313
|
for (const { from, to } of renames) renameMap.set(stripSqlExt(from), stripSqlExt(to));
|
|
1137
1314
|
const updatedEntries = current.entries.map((entry) => {
|
|
@@ -1148,7 +1325,7 @@ async function runRenameMigrations(root, dialect) {
|
|
|
1148
1325
|
entries: updatedEntries
|
|
1149
1326
|
});
|
|
1150
1327
|
} catch (err) {
|
|
1151
|
-
await rollback(
|
|
1328
|
+
await rollback(`db: Failed to update ${dir}/meta/_journal.json. File renames have been reverted.`, err);
|
|
1152
1329
|
}
|
|
1153
1330
|
if (dialect === "postgresql") try {
|
|
1154
1331
|
await withPgClient(root, async (client) => {
|
|
@@ -1168,13 +1345,20 @@ async function runRenameMigrations(root, dialect) {
|
|
|
1168
1345
|
else if (dialect === "mysql") try {
|
|
1169
1346
|
await withMySqlClient(root, async (client) => {
|
|
1170
1347
|
if ((await client.query("SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = '_void_migrations' LIMIT 1")).length === 0) return;
|
|
1171
|
-
|
|
1348
|
+
await client.query("START TRANSACTION");
|
|
1349
|
+
try {
|
|
1350
|
+
for (const { from, to } of renames) await client.query("UPDATE `_void_migrations` SET `name` = ? WHERE `name` = ?", [to, from]);
|
|
1351
|
+
await client.query("COMMIT");
|
|
1352
|
+
} catch (err) {
|
|
1353
|
+
await client.query("ROLLBACK").catch(() => {});
|
|
1354
|
+
throw err;
|
|
1355
|
+
}
|
|
1172
1356
|
});
|
|
1173
1357
|
} catch (err) {
|
|
1174
1358
|
await rollback("db: Failed to update MySQL tracking table. File renames have been reverted.\nFix the database connection and run `void db rename-migrations` again.", err);
|
|
1175
1359
|
}
|
|
1176
1360
|
else {
|
|
1177
|
-
const { openSqliteDatabase } = await import("./runner-
|
|
1361
|
+
const { openSqliteDatabase } = await import("./runner-WCdfeI0q.mjs");
|
|
1178
1362
|
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
1179
1363
|
if (existsSync(dbPath)) try {
|
|
1180
1364
|
const db = await openSqliteDatabase(dbPath);
|
|
@@ -1197,12 +1381,23 @@ async function runRenameMigrations(root, dialect) {
|
|
|
1197
1381
|
}
|
|
1198
1382
|
printSuccess(`Renamed ${formatCount(renames.length, "migration")} to timestamp format.`);
|
|
1199
1383
|
}
|
|
1384
|
+
const INTERNAL_TABLES = /* @__PURE__ */ new Set([
|
|
1385
|
+
"_void_migrations",
|
|
1386
|
+
"_void_migration_attempts",
|
|
1387
|
+
"_void_migration_lock",
|
|
1388
|
+
"_void_migration_fences",
|
|
1389
|
+
"__drizzle_migrations"
|
|
1390
|
+
]);
|
|
1391
|
+
function isInternalTable(name, dialect) {
|
|
1392
|
+
if (INTERNAL_TABLES.has(name)) return true;
|
|
1393
|
+
return dialect === "sqlite" && (name === "_migrations" || name.startsWith("_cf_") || name.startsWith("sqlite_"));
|
|
1394
|
+
}
|
|
1200
1395
|
function formatMySqlExportValue(value) {
|
|
1201
1396
|
if (value === null || value === void 0) return "NULL";
|
|
1202
1397
|
if (typeof value === "number" || typeof value === "bigint") return String(value);
|
|
1203
1398
|
if (typeof value === "boolean") return value ? "1" : "0";
|
|
1204
1399
|
if (value instanceof Uint8Array) return `X'${Array.from(value, (byte) => byte.toString(16).padStart(2, "0")).join("")}'`;
|
|
1205
|
-
return `'${
|
|
1400
|
+
return `'${String(value).replaceAll("\\", "\\\\").replaceAll("'", "''")}'`;
|
|
1206
1401
|
}
|
|
1207
1402
|
function formatSqliteExportValue(value) {
|
|
1208
1403
|
if (value === null) return "NULL";
|
|
@@ -1222,7 +1417,7 @@ async function runExport(root, args, dialect) {
|
|
|
1222
1417
|
process.exit(1);
|
|
1223
1418
|
}
|
|
1224
1419
|
tables = [args.table];
|
|
1225
|
-
} else tables = (await client.query("SELECT tablename FROM pg_tables WHERE schemaname = 'public'
|
|
1420
|
+
} else tables = (await client.query("SELECT tablename FROM pg_tables WHERE schemaname = 'public' ORDER BY tablename")).rows.map((row) => String(row.tablename)).filter((name) => !isInternalTable(name, dialect));
|
|
1226
1421
|
if (!args.noSchema) await assertPgExportableSchema(client, tables, !args.table);
|
|
1227
1422
|
const sequences = await exportPgSequences(client, tables, args);
|
|
1228
1423
|
parts.push(...sequences.before);
|
|
@@ -1274,14 +1469,14 @@ async function runExport(root, args, dialect) {
|
|
|
1274
1469
|
});
|
|
1275
1470
|
const output = parts.join("\n");
|
|
1276
1471
|
if (args.output) {
|
|
1277
|
-
writeFileSync(
|
|
1472
|
+
writeFileSync(resolve(root, args.output), output);
|
|
1278
1473
|
printSuccess(`Exported to ${args.output}`);
|
|
1279
1474
|
} else process.stdout.write(output);
|
|
1280
1475
|
return;
|
|
1281
1476
|
}
|
|
1282
1477
|
if (dialect === "mysql") {
|
|
1283
1478
|
const parts = [];
|
|
1284
|
-
|
|
1479
|
+
const exportTables = async (client) => {
|
|
1285
1480
|
let tables;
|
|
1286
1481
|
if (args.table) {
|
|
1287
1482
|
if ((await client.query("SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ?", [args.table])).length === 0) {
|
|
@@ -1289,8 +1484,9 @@ async function runExport(root, args, dialect) {
|
|
|
1289
1484
|
process.exit(1);
|
|
1290
1485
|
}
|
|
1291
1486
|
tables = [args.table];
|
|
1292
|
-
} else tables = (await client.query("SELECT table_name AS table_name FROM information_schema.tables WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE'
|
|
1293
|
-
|
|
1487
|
+
} else tables = (await client.query("SELECT table_name AS table_name FROM information_schema.tables WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE' ORDER BY table_name")).map((row) => String(row.table_name)).filter((name) => !isInternalTable(name, dialect));
|
|
1488
|
+
await client.query("SET time_zone = '+00:00'");
|
|
1489
|
+
parts.push("SET FOREIGN_KEY_CHECKS = 0;", "SET time_zone = '+00:00';");
|
|
1294
1490
|
for (const table of tables) {
|
|
1295
1491
|
const escapedTable = table.replaceAll("`", "``");
|
|
1296
1492
|
if (!args.noSchema) {
|
|
@@ -1309,18 +1505,19 @@ async function runExport(root, args, dialect) {
|
|
|
1309
1505
|
parts.push("");
|
|
1310
1506
|
}
|
|
1311
1507
|
parts.push("SET FOREIGN_KEY_CHECKS = 1;", "");
|
|
1312
|
-
}
|
|
1508
|
+
};
|
|
1509
|
+
await withMySqlClient(root, exportTables, { textValues: true });
|
|
1313
1510
|
const output = parts.join("\n");
|
|
1314
1511
|
if (args.output) {
|
|
1315
|
-
writeFileSync(
|
|
1512
|
+
writeFileSync(resolve(root, args.output), output);
|
|
1316
1513
|
printSuccess(`Exported to ${args.output}`);
|
|
1317
1514
|
} else process.stdout.write(output);
|
|
1318
1515
|
return;
|
|
1319
1516
|
}
|
|
1320
|
-
const { openSqliteDatabase } = await import("./runner-
|
|
1517
|
+
const { openSqliteDatabase } = await import("./runner-WCdfeI0q.mjs");
|
|
1321
1518
|
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
1322
1519
|
if (!existsSync(dbPath)) {
|
|
1323
|
-
log.error("No local database found.
|
|
1520
|
+
log.error("No local database found. Start the dev server first.", errOut);
|
|
1324
1521
|
process.exit(1);
|
|
1325
1522
|
}
|
|
1326
1523
|
const db = await openSqliteDatabase(dbPath, { readonly: true });
|
|
@@ -1332,7 +1529,7 @@ async function runExport(root, args, dialect) {
|
|
|
1332
1529
|
process.exit(1);
|
|
1333
1530
|
}
|
|
1334
1531
|
tables = [args.table];
|
|
1335
|
-
} else tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table'
|
|
1532
|
+
} else tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name").all().map((row) => String(row.name)).filter((name) => !isInternalTable(name, dialect));
|
|
1336
1533
|
const parts = [];
|
|
1337
1534
|
for (const table of tables) {
|
|
1338
1535
|
if (!args.noSchema) {
|
|
@@ -1367,14 +1564,14 @@ async function runExport(root, args, dialect) {
|
|
|
1367
1564
|
]) for (const object of schemaObjects) {
|
|
1368
1565
|
if (object.type !== type) continue;
|
|
1369
1566
|
if (type === "view") {
|
|
1370
|
-
if (args.table || object.name
|
|
1567
|
+
if (args.table || isInternalTable(object.name, dialect)) continue;
|
|
1371
1568
|
} else if (!tables.includes(object.tbl_name)) continue;
|
|
1372
1569
|
parts.push(object.sql.trim().replace(/;?$/, ";"));
|
|
1373
1570
|
}
|
|
1374
1571
|
}
|
|
1375
1572
|
const output = parts.join("\n");
|
|
1376
1573
|
if (args.output) {
|
|
1377
|
-
writeFileSync(
|
|
1574
|
+
writeFileSync(resolve(root, args.output), output);
|
|
1378
1575
|
printSuccess(`Exported to ${args.output}`);
|
|
1379
1576
|
} else process.stdout.write(output);
|
|
1380
1577
|
} finally {
|
|
@@ -1444,18 +1641,16 @@ function toSeedTarget(root, seedPath, displayPath) {
|
|
|
1444
1641
|
log.error(`db: Unsupported seed file '${normalizedDisplay}'. Use .sql, .ts, .mts, .js, or .mjs.`);
|
|
1445
1642
|
process.exit(1);
|
|
1446
1643
|
}
|
|
1447
|
-
async function runSeedModule(root,
|
|
1448
|
-
const seed = await loadSeedFunction(seedPath);
|
|
1644
|
+
async function runSeedModule(root, seed, dialect) {
|
|
1449
1645
|
const schema = await loadSeedSchema(root);
|
|
1450
1646
|
if (dialect === "postgresql") {
|
|
1451
1647
|
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
1452
1648
|
await withPgClient(root, async (client) => {
|
|
1453
1649
|
const options = getDrizzleSchemaOptions(schema);
|
|
1454
1650
|
const drizzleClient = client;
|
|
1455
|
-
const db = options ? drizzle(drizzleClient, options) : drizzle(drizzleClient);
|
|
1456
1651
|
await seed({
|
|
1457
1652
|
dialect,
|
|
1458
|
-
db,
|
|
1653
|
+
db: options ? drizzle(drizzleClient, options) : drizzle(drizzleClient),
|
|
1459
1654
|
schema
|
|
1460
1655
|
});
|
|
1461
1656
|
});
|
|
@@ -1481,7 +1676,7 @@ async function runSeedModule(root, seedPath, dialect) {
|
|
|
1481
1676
|
return;
|
|
1482
1677
|
}
|
|
1483
1678
|
const { drizzle } = await import("drizzle-orm/better-sqlite3");
|
|
1484
|
-
const { openSqliteDatabase } = await import("./runner-
|
|
1679
|
+
const { openSqliteDatabase } = await import("./runner-WCdfeI0q.mjs");
|
|
1485
1680
|
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
1486
1681
|
const sqlite = await openSqliteDatabase(dbPath);
|
|
1487
1682
|
try {
|
|
@@ -1502,7 +1697,7 @@ async function loadSeedFunction(seedPath) {
|
|
|
1502
1697
|
return seed;
|
|
1503
1698
|
}
|
|
1504
1699
|
async function loadSeedSchema(root) {
|
|
1505
|
-
const { discoverSchema } = await import("./discover-
|
|
1700
|
+
const { discoverSchema } = await import("./discover-D4TPKo57.mjs");
|
|
1506
1701
|
const location = discoverSchema(root, readProjectPaths(root));
|
|
1507
1702
|
if (!location) return {};
|
|
1508
1703
|
if (location.type === "file") {
|