@builtbyfriends/bwf 0.0.0-stage → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS_TEMPLATE.md +4 -0
- package/LICENSE +22 -0
- package/README.md +48 -2
- package/dist/account-cmd-Cj0I2_bJ.mjs +45 -0
- package/dist/agents-BLiMq9E1.mjs +113 -0
- package/dist/application-analysis-C9Ck2Yeg.mjs +1498 -0
- package/dist/application-routing-DbR-W5lG.mjs +25 -0
- package/dist/atomic-write-DA6eD1Kp.mjs +17 -0
- package/dist/auth-BKsUmWbT.d.mts +77 -0
- package/dist/auth-DkvoW5hB.mjs +33 -0
- package/dist/auth-aKyIWkdS.mjs +1 -0
- package/dist/auth-client-6-Ft9i9T.d.mts +5 -0
- package/dist/auth-client-DwCdwKbw.mjs +5 -0
- package/dist/auth-client-react-CJdeErvM.mjs +5 -0
- package/dist/auth-client-react-DvQLe5Zb.d.mts +5 -0
- package/dist/auth-link-D-DddkCQ.mjs +26 -0
- package/dist/auth-migrations-DDeifS3v.mjs +206 -0
- package/dist/auth-router-tWzIwf8f.mjs +66 -0
- package/dist/auth-xnkmpZUl.mjs +311 -0
- package/dist/base64-ikl9yBy3.mjs +15 -0
- package/dist/better-auth-shared-Br6TNaYJ.mjs +473 -0
- package/dist/better-auth-shared-CsBNvPOU.d.mts +56 -0
- package/dist/build-cmd-BnZezraT.mjs +153 -0
- package/dist/build-output-dir-Clj_unKN.mjs +402 -0
- package/dist/cancel-deploy-DKAj5U1Z.mjs +57 -0
- package/dist/cf-access-Bhz9wX6p.mjs +131 -0
- package/dist/cf-access-CUP5L08W.mjs +67 -0
- package/dist/cf-build-output-DA6uJomQ.mjs +1 -0
- package/dist/cf-build-output-DNQTwMNU.mjs +438 -0
- package/dist/cf-command-values-2kOtxMo1.mjs +26 -0
- package/dist/cf-config-migrate-COOCi4Ge.mjs +330 -0
- package/dist/cf-worker-settings-CIh4t_yG.mjs +41 -0
- package/dist/cli/cli.d.mts +1 -0
- package/dist/cli/cli.mjs +88 -0
- package/dist/cli/cloudflare-operation-process.d.mts +1 -0
- package/dist/cli/cloudflare-operation-process.mjs +1284 -0
- package/dist/cli/env-schema-probe.d.mts +43 -0
- package/dist/cli/env-schema-probe.mjs +165 -0
- package/dist/cli-main-HeXRQml6.mjs +1846 -0
- package/dist/client-D3D5RM5h.mjs +940 -0
- package/dist/client-VF2Nzc7Z.mjs +1 -0
- package/dist/cloudflare-auth-jb-1e43r.mjs +152 -0
- package/dist/cloudflare-cmd-B62t8Fm-.mjs +59 -0
- package/dist/cloudflare-config-i8yanry0.mjs +186 -0
- package/dist/cloudflare-connect-x7IsYghw.mjs +55 -0
- package/dist/cloudflare-operations-BeK7bhnP.mjs +627 -0
- package/dist/cloudflare-operations-C3Uu0Emj.mjs +1 -0
- package/dist/cloudflare-process-Cc6oiJqk.mjs +309 -0
- package/dist/cloudflare-user-output-CqONaAbP.mjs +19 -0
- package/dist/collect-8i0wU63d.mjs +1 -0
- package/dist/collect-C6Blu9yw.mjs +48 -0
- package/dist/config-CN_RFRkS.mjs +86 -0
- package/dist/config-D5G-Tx6o.mjs +1 -0
- package/dist/config-DOaFIK3w.mjs +88 -0
- package/dist/config-entry.d.mts +202 -0
- package/dist/config-entry.mjs +6 -0
- package/dist/config-tNx0HlFv.mjs +516 -0
- package/dist/connect-hLPNppu3.mjs +84 -0
- package/dist/create-project-B35ux-LA.mjs +126 -0
- package/dist/create-project-tJ1KwNss.mjs +1 -0
- package/dist/database-provider-DkZo4VwN.mjs +5 -0
- package/dist/database-provider.d.mts +25 -0
- package/dist/database-provider.mjs +1 -0
- package/dist/db-BH_md90k.mjs +1735 -0
- package/dist/delete-BSKI7V23.mjs +65 -0
- package/dist/deploy-C8KHBNsh.mjs +6512 -0
- package/dist/deploy-DCZBr7Ey.mjs +2 -0
- package/dist/deploy.d.mts +31 -0
- package/dist/deploy.mjs +118 -0
- package/dist/dev-inbox-I0nqTCdf.mjs +216 -0
- package/dist/discover-DJPmQcL5.mjs +36 -0
- package/dist/discover-EVuydEoM.mjs +1 -0
- package/dist/dist-B6eN80gc.mjs +1612 -0
- package/dist/dist-Cp4b1_T9.mjs +1 -0
- package/dist/dist-DMYe8CZJ.mjs +48 -0
- package/dist/dist-STQXl8ck.mjs +1878 -0
- package/dist/domain-C4ZhEiFG.mjs +149 -0
- package/dist/dotenv-4NdUCXbB.mjs +156 -0
- package/dist/drizzle-DqVFXtlc.mjs +306 -0
- package/dist/drizzle-Ds5P0n-S.mjs +1 -0
- package/dist/edge.d.mts +2 -0
- package/dist/edge.mjs +1 -0
- package/dist/email-B3TWga7x.mjs +742 -0
- package/dist/email-C_ATvNIG.mjs +2865 -0
- package/dist/email-cloudflare-DuAc9zny.mjs +854 -0
- package/dist/email-protocol-CZ0bAkI8.mjs +81 -0
- package/dist/env-CTAo8ifZ.mjs +73 -0
- package/dist/env-DUyTzroe.mjs +88 -0
- package/dist/env-Dl4Wggec.mjs +71 -0
- package/dist/env-helpers-BX0APszT.mjs +135 -0
- package/dist/env-helpers-U56xuFgL.d.mts +20 -0
- package/dist/env-mask-BsHxq3R8.mjs +46 -0
- package/dist/env-public-Cw_xPi1D.d.mts +119 -0
- package/dist/env-raw-Bo6TtrHU.mjs +41 -0
- package/dist/env-types-Bg-dTh8u.mjs +56 -0
- package/dist/env-validation-BufZConV.mjs +488 -0
- package/dist/env-validation-DPqDo4DU.mjs +1 -0
- package/dist/fetch-CBgyyhzm.d.mts +87 -0
- package/dist/fetch-error-DmlRM6e4.mjs +264 -0
- package/dist/fetch-stream-2GUN3YN1.mjs +102 -0
- package/dist/fetch-stream-bUXynOyZ.d.mts +32 -0
- package/dist/fetch-tpPiSK10.mjs +25 -0
- package/dist/gen-dc13IRXh.mjs +509 -0
- package/dist/gen-kQqhFyOP.mjs +1 -0
- package/dist/generate-BgtlYpKg.mjs +1 -0
- package/dist/generate-Da9mWKzU.mjs +80 -0
- package/dist/generated-wrangler-config-CoDaaFsA.mjs +17 -0
- package/dist/git-metadata-Cukp5kV5.mjs +82 -0
- package/dist/github-cmd-DT5Onu6E.mjs +690 -0
- package/dist/handler-CJ7DiiRF.mjs +161 -0
- package/dist/handler-CVsIfRv7.d.mts +279 -0
- package/dist/help-Bpv6Qeqn.mjs +1946 -0
- package/dist/help-CfZ4Bsw5.mjs +1 -0
- package/dist/inbound-CqubE-9T.d.mts +311 -0
- package/dist/inbound-lHugZPuK.mjs +509 -0
- package/dist/index.d.mts +64 -0
- package/dist/index.mjs +4163 -0
- package/dist/info-CLQoCenb.mjs +109 -0
- package/dist/init-DRUR0j8C.mjs +2486 -0
- package/dist/limits-CMmYT2l8.d.mts +16 -0
- package/dist/limits-D27Lp6FP.mjs +46 -0
- package/dist/link-DinwJnon.mjs +52 -0
- package/dist/list-B84t4BhW.mjs +130 -0
- package/dist/live-Dui0-aj_.d.mts +105 -0
- package/dist/live-saC8barp.mjs +410 -0
- package/dist/load-user-env-g0ahkZcj.mjs +34 -0
- package/dist/local-d1-C3EeOV7-.mjs +103 -0
- package/dist/log-JDnPc0cF.mjs +23 -0
- package/dist/login-Bl5lH8nH.mjs +87 -0
- package/dist/login-DoI7AsbY.mjs +1 -0
- package/dist/logs-CaT2N2f7.mjs +129 -0
- package/dist/migrate-CbGscX-V.mjs +125 -0
- package/dist/migrate-Ce3JKLVs.mjs +1 -0
- package/dist/migration-handler-22qiuWPq.mjs +469 -0
- package/dist/migration-handler-Bb2BJh6g.d.mts +38 -0
- package/dist/mime-BMUN_QKG.mjs +1004 -0
- package/dist/mysql-migration-sql-CNuBSqdx.mjs +239 -0
- package/dist/neon-CJzQSycr.mjs +52 -0
- package/dist/node-tfv-3v0V.mjs +64 -0
- package/dist/operator-ai-logging-Ay7M4KWw.mjs +121 -0
- package/dist/operator-args-BFg32YyY.mjs +722 -0
- package/dist/operator-auth-DdYZYEkO.mjs +47 -0
- package/dist/operator-client-DBujdELO.mjs +82 -0
- package/dist/operator-cmd-C73WWJBl.mjs +443 -0
- package/dist/operator-cmd-CdZytuAF.mjs +1 -0
- package/dist/output-Bb34lF0w.mjs +173 -0
- package/dist/output-CVolXKC1.mjs +1 -0
- package/dist/package-DO4d3Qz5.mjs +1444 -0
- package/dist/package-json-DvS6IFRv.mjs +43 -0
- package/dist/pg-DoyPxa_X.mjs +15 -0
- package/dist/picocolors-D1NxSLw-.mjs +71 -0
- package/dist/plan-BHNt1QhK.mjs +1 -0
- package/dist/plan-DX4_-OM5.mjs +58 -0
- package/dist/platform-args-NI_vfWvD.mjs +538 -0
- package/dist/platform-args-ZC1-A1N9.mjs +1 -0
- package/dist/platform-auth-config-d-lY5-aY.mjs +371 -0
- package/dist/platform-auth-protection-Dhw7lUCk.mjs +231 -0
- package/dist/platform-auth-recovery-DaCc0tlx.mjs +309 -0
- package/dist/platform-cmd-5Ry-C9im.mjs +193 -0
- package/dist/platform-cmd-5oZq91lI.mjs +1 -0
- package/dist/platform-discovery-Bxg9aZXU.mjs +40 -0
- package/dist/platform-domain-DLVdGvGG.mjs +256 -0
- package/dist/platform-lifecycle-CUgjipXO.mjs +1 -0
- package/dist/platform-lifecycle-fRt5VMls.mjs +8928 -0
- package/dist/platform-management-5hEsRfR2.mjs +1 -0
- package/dist/platform-management-Djh1hzLP.mjs +1607 -0
- package/dist/platform-plans-config-CkbUKFpm.mjs +447 -0
- package/dist/platform-recovery-Cghx7FCR.mjs +96 -0
- package/dist/platform-registry-x1m9HBxf.mjs +450 -0
- package/dist/platform-runtime-logs-kkoiYFpF.mjs +72 -0
- package/dist/platform-setup-SfwCwnZg.mjs +306 -0
- package/dist/prepare-B9mB47T5.mjs +84 -0
- package/dist/prepare-DNIq07so.mjs +13 -0
- package/dist/prepare-LHkyJqxi.mjs +1 -0
- package/dist/project-CC7eN00D.mjs +141 -0
- package/dist/project-DcSd4BeI.mjs +1 -0
- package/dist/project-cmd-DTF19-fC.mjs +109 -0
- package/dist/project-paths-iXHKRTTQ.mjs +159 -0
- package/dist/project-slug-BUy0lmyR.mjs +1 -0
- package/dist/project-slug-CO6ci9XG.mjs +7 -0
- package/dist/project-team-CvdLhDF2.mjs +129 -0
- package/dist/project-token-CwZdUEGu.mjs +70 -0
- package/dist/project-tsconfig-P9X952KG.mjs +98 -0
- package/dist/project-zero-trust-CKDoPdN1.mjs +64 -0
- package/dist/providers-Cd3c7wi0.mjs +64 -0
- package/dist/providers-Df69hb_X.d.mts +5 -0
- package/dist/provision-DGlFJ3T9.mjs +1 -0
- package/dist/provision-mYVLuQiy.mjs +1814 -0
- package/dist/queues-Bc3FsBQT.d.mts +5 -0
- package/dist/r2-conditions-DSLmkiR5.mjs +60 -0
- package/dist/requests-DNhfyF3l.mjs +52 -0
- package/dist/resolve-project-BCsAMDRA.mjs +47 -0
- package/dist/resolve-project-DhU9_lIo.mjs +1 -0
- package/dist/resource-name-DlJ9QXzg.mjs +10 -0
- package/dist/response-HmNjB30w.mjs +29 -0
- package/dist/rollback-BvCHol52.mjs +150 -0
- package/dist/rolldown-runtime-uD8oG6U2.mjs +24 -0
- package/dist/route-types-CRWhr93D.mjs +592 -0
- package/dist/route-url-BIDZT78M.mjs +58 -0
- package/dist/route-url-Bla3Upsy.d.mts +42 -0
- package/dist/routes-stub.d.mts +24 -0
- package/dist/routes-stub.mjs +1 -0
- package/dist/routing-assets-CSheDWWM.mjs +54 -0
- package/dist/rpc-DcByS_q0.d.mts +39 -0
- package/dist/rpc-DtxIN9Tv.mjs +19 -0
- package/dist/runner-CPerdjIl.mjs +163 -0
- package/dist/runner-CUNtS5x7.mjs +1 -0
- package/dist/runner-mysql-7aA5hGoM.mjs +145 -0
- package/dist/runner-mysql-DrMKw203.mjs +1 -0
- package/dist/runner-pg-2pjltt0t.mjs +1 -0
- package/dist/runner-pg-mYc75KfH.mjs +61 -0
- package/dist/runtime/ai.d.mts +50 -0
- package/dist/runtime/ai.mjs +455 -0
- package/dist/runtime/auth-client-react.d.mts +2 -0
- package/dist/runtime/auth-client-react.mjs +1 -0
- package/dist/runtime/auth-client.d.mts +2 -0
- package/dist/runtime/auth-client.mjs +1 -0
- package/dist/runtime/auth.d.mts +2 -0
- package/dist/runtime/auth.mjs +1 -0
- package/dist/runtime/better-auth-mysql.d.mts +5 -0
- package/dist/runtime/better-auth-mysql.mjs +21 -0
- package/dist/runtime/better-auth-pg.d.mts +5 -0
- package/dist/runtime/better-auth-pg.mjs +21 -0
- package/dist/runtime/better-auth.d.mts +6 -0
- package/dist/runtime/better-auth.mjs +22 -0
- package/dist/runtime/client-react.d.mts +5 -0
- package/dist/runtime/client-react.mjs +5 -0
- package/dist/runtime/client.d.mts +5 -0
- package/dist/runtime/client.mjs +5 -0
- package/dist/runtime/db-mysql.d.mts +2 -0
- package/dist/runtime/db-mysql.mjs +1 -0
- package/dist/runtime/db-pg.d.mts +2 -0
- package/dist/runtime/db-pg.mjs +1 -0
- package/dist/runtime/db.d.mts +17 -0
- package/dist/runtime/db.mjs +36 -0
- package/dist/runtime/drizzle-arktype.d.mts +1 -0
- package/dist/runtime/drizzle-arktype.mjs +2 -0
- package/dist/runtime/drizzle-valibot.d.mts +1 -0
- package/dist/runtime/drizzle-valibot.mjs +2 -0
- package/dist/runtime/drizzle-zod.d.mts +1 -0
- package/dist/runtime/drizzle-zod.mjs +2 -0
- package/dist/runtime/durable.d.mts +64 -0
- package/dist/runtime/durable.mjs +165 -0
- package/dist/runtime/email/testing.d.mts +108 -0
- package/dist/runtime/email/testing.mjs +268 -0
- package/dist/runtime/email-protocol.d.mts +25 -0
- package/dist/runtime/email-protocol.mjs +1 -0
- package/dist/runtime/email.d.mts +26 -0
- package/dist/runtime/email.mjs +524 -0
- package/dist/runtime/env-public-client.d.mts +19 -0
- package/dist/runtime/env-public-client.mjs +55 -0
- package/dist/runtime/env-public.d.mts +4 -0
- package/dist/runtime/env-public.mjs +277 -0
- package/dist/runtime/env.d.mts +12 -0
- package/dist/runtime/env.mjs +1 -0
- package/dist/runtime/fetch-server.d.mts +6 -0
- package/dist/runtime/fetch-server.mjs +29 -0
- package/dist/runtime/fetch-stream.d.mts +3 -0
- package/dist/runtime/fetch-stream.mjs +3 -0
- package/dist/runtime/fetch.d.mts +2 -0
- package/dist/runtime/fetch.mjs +3 -0
- package/dist/runtime/handler.d.mts +3 -0
- package/dist/runtime/handler.mjs +1 -0
- package/dist/runtime/kv.d.mts +45 -0
- package/dist/runtime/kv.mjs +103 -0
- package/dist/runtime/limits.d.mts +2 -0
- package/dist/runtime/limits.mjs +1 -0
- package/dist/runtime/live-client.d.mts +40 -0
- package/dist/runtime/live-client.mjs +282 -0
- package/dist/runtime/live-server.d.mts +11 -0
- package/dist/runtime/live-server.mjs +419 -0
- package/dist/runtime/live.d.mts +3 -0
- package/dist/runtime/live.mjs +1 -0
- package/dist/runtime/log.d.mts +24 -0
- package/dist/runtime/log.mjs +57 -0
- package/dist/runtime/migration-handler-mysql.d.mts +2 -0
- package/dist/runtime/migration-handler-mysql.mjs +111 -0
- package/dist/runtime/migration-handler-pg.d.mts +2 -0
- package/dist/runtime/migration-handler-pg.mjs +94 -0
- package/dist/runtime/migration-handler.d.mts +2 -0
- package/dist/runtime/migration-handler.mjs +1 -0
- package/dist/runtime/procedure.d.mts +27 -0
- package/dist/runtime/procedure.mjs +36 -0
- package/dist/runtime/procedures.d.mts +24 -0
- package/dist/runtime/procedures.mjs +56 -0
- package/dist/runtime/queues.d.mts +2 -0
- package/dist/runtime/queues.mjs +8 -0
- package/dist/runtime/remote/binding-handler.d.mts +11 -0
- package/dist/runtime/remote/binding-handler.mjs +227 -0
- package/dist/runtime/remote/index.d.mts +12 -0
- package/dist/runtime/remote/index.mjs +467 -0
- package/dist/runtime/response.d.mts +11 -0
- package/dist/runtime/response.mjs +1 -0
- package/dist/runtime/route-url.d.mts +2 -0
- package/dist/runtime/route-url.mjs +1 -0
- package/dist/runtime/routing.d.mts +53 -0
- package/dist/runtime/routing.mjs +425 -0
- package/dist/runtime/rpc-react.d.mts +16 -0
- package/dist/runtime/rpc-react.mjs +50 -0
- package/dist/runtime/rpc.d.mts +2 -0
- package/dist/runtime/rpc.mjs +1 -0
- package/dist/runtime/sandbox-container.d.mts +3 -0
- package/dist/runtime/sandbox-container.mjs +1 -0
- package/dist/runtime/sandbox.d.mts +5 -0
- package/dist/runtime/sandbox.mjs +196 -0
- package/dist/runtime/schema-d1.d.mts +1 -0
- package/dist/runtime/schema-d1.mjs +2 -0
- package/dist/runtime/schema-mysql.d.mts +1 -0
- package/dist/runtime/schema-mysql.mjs +2 -0
- package/dist/runtime/schema-pg.d.mts +1 -0
- package/dist/runtime/schema-pg.mjs +2 -0
- package/dist/runtime/seed.d.mts +34 -0
- package/dist/runtime/seed.mjs +5 -0
- package/dist/runtime/sse-client.d.mts +31 -0
- package/dist/runtime/sse-client.mjs +42 -0
- package/dist/runtime/sse.d.mts +32 -0
- package/dist/runtime/sse.mjs +1 -0
- package/dist/runtime/storage.d.mts +4 -0
- package/dist/runtime/storage.mjs +13 -0
- package/dist/runtime/validator.d.mts +2 -0
- package/dist/runtime/validator.mjs +1 -0
- package/dist/runtime/ws-server.d.mts +26 -0
- package/dist/runtime/ws-server.mjs +297 -0
- package/dist/runtime/ws.d.mts +2 -0
- package/dist/runtime/ws.mjs +108 -0
- package/dist/sandbox-CWDjoEG2.d.mts +50 -0
- package/dist/sandbox-container-BqamdFCx.d.mts +73 -0
- package/dist/sandbox-container-d1AHLpgn.mjs +291 -0
- package/dist/secret-DCF9RXTc.mjs +146 -0
- package/dist/skills-Dr3AjuBF.mjs +63 -0
- package/dist/sqlite-validation-CLJXXN93.mjs +24 -0
- package/dist/sse-CxR30yMF.mjs +174 -0
- package/dist/standard-schema-CuDawHOC.d.mts +40 -0
- package/dist/static-asset-marker-mWMX2dLa.mjs +38 -0
- package/dist/subcommand-prompt-B9yUo--u.mjs +370 -0
- package/dist/terminal-log-text-DNsWJREL.mjs +31 -0
- package/dist/types-D7-4tBu7.d.mts +1 -0
- package/dist/untrusted-env-lL7RkYiC.mjs +50 -0
- package/dist/validate-B-zsjhiz.mjs +162 -0
- package/dist/validate-DbqGdPPY.mjs +1 -0
- package/dist/validator-8-NZs2Xr.mjs +168 -0
- package/dist/version-metadata-DsSoNsKJ.mjs +23 -0
- package/dist/wrangler-DU784Dkf.mjs +1452 -0
- package/dist/wrangler-Rr9_76DQ.mjs +1 -0
- package/dist/ws-Q_osq9VK.d.mts +137 -0
- package/dist/yarn-pnp-DgWbE7z5.mjs +91 -0
- package/docs/guide/ai.md +273 -0
- package/docs/guide/app-types.md +101 -0
- package/docs/guide/auth.md +255 -0
- package/docs/guide/database/d1.md +86 -0
- package/docs/guide/database/mysql.md +72 -0
- package/docs/guide/database/postgresql.md +94 -0
- package/docs/guide/database.md +454 -0
- package/docs/guide/deployment.md +124 -0
- package/docs/guide/durable-state.md +192 -0
- package/docs/guide/edge/headers.md +47 -0
- package/docs/guide/edge/redirects.md +85 -0
- package/docs/guide/edge/rewrites.md +119 -0
- package/docs/guide/edge/static-assets.md +94 -0
- package/docs/guide/email/domains.md +119 -0
- package/docs/guide/email/receiving.md +142 -0
- package/docs/guide/email/sending.md +262 -0
- package/docs/guide/email.md +23 -0
- package/docs/guide/env-vars.md +115 -0
- package/docs/guide/index.md +37 -0
- package/docs/guide/jobs.md +80 -0
- package/docs/guide/kv.md +100 -0
- package/docs/guide/live.md +181 -0
- package/docs/guide/platform/administration/access.md +165 -0
- package/docs/guide/platform/administration/connected-apps.md +84 -0
- package/docs/guide/platform/administration/email.md +169 -0
- package/docs/guide/platform/administration/operations.md +100 -0
- package/docs/guide/platform/administration/plans.md +156 -0
- package/docs/guide/platform/administration/projects.md +74 -0
- package/docs/guide/platform/administration/zero-trust.md +205 -0
- package/docs/guide/platform/development/local.md +122 -0
- package/docs/guide/platform/development/runtime.md +115 -0
- package/docs/guide/platform/development/schema-ci.md +44 -0
- package/docs/guide/platform/installation/ci.md +62 -0
- package/docs/guide/platform/installation/credentials.md +140 -0
- package/docs/guide/platform/installation/domains.md +120 -0
- package/docs/guide/platform/installation/first-deployment.md +95 -0
- package/docs/guide/platform/installation/maintenance.md +250 -0
- package/docs/guide/platform/installation/prerequisites.md +176 -0
- package/docs/guide/platform/installation/setup.md +300 -0
- package/docs/guide/platform/installation/uninstall.md +110 -0
- package/docs/guide/platform-administration.md +19 -0
- package/docs/guide/platform-development.md +16 -0
- package/docs/guide/procedures.md +48 -0
- package/docs/guide/project-collaboration.md +99 -0
- package/docs/guide/queues.md +149 -0
- package/docs/guide/quickstart.md +129 -0
- package/docs/guide/remote-dev.md +67 -0
- package/docs/guide/sandboxes.md +134 -0
- package/docs/guide/self-hosted-platform.md +45 -0
- package/docs/guide/server-routing.md +283 -0
- package/docs/guide/sse.md +174 -0
- package/docs/guide/storage.md +82 -0
- package/docs/guide/testing.md +64 -0
- package/docs/guide/type-safety.md +270 -0
- package/docs/guide/typed-fetch.md +98 -0
- package/docs/guide/websockets.md +230 -0
- package/docs/index.md +102 -0
- package/docs/integrations/agents.md +38 -0
- package/docs/integrations/cloudflare.md +241 -0
- package/docs/integrations/hono.md +127 -0
- package/docs/reference/api/auth.md +195 -0
- package/docs/reference/api/client.md +90 -0
- package/docs/reference/api/database.md +118 -0
- package/docs/reference/api/deploy.md +63 -0
- package/docs/reference/api/durable.md +47 -0
- package/docs/reference/api/env.md +51 -0
- package/docs/reference/api/handlers.md +189 -0
- package/docs/reference/api/plugin.md +40 -0
- package/docs/reference/api/resources.md +116 -0
- package/docs/reference/api/rewrites.md +111 -0
- package/docs/reference/api/types.md +126 -0
- package/docs/reference/api.md +71 -0
- package/docs/reference/cli/auth.md +87 -0
- package/docs/reference/cli/database.md +159 -0
- package/docs/reference/cli/deploy.md +117 -0
- package/docs/reference/cli/domains.md +42 -0
- package/docs/reference/cli/email.md +145 -0
- package/docs/reference/cli/generate.md +113 -0
- package/docs/reference/cli/github.md +181 -0
- package/docs/reference/cli/platform-config.md +93 -0
- package/docs/reference/cli/platform-email.md +81 -0
- package/docs/reference/cli/platform-installation.md +166 -0
- package/docs/reference/cli/platform-operations.md +90 -0
- package/docs/reference/cli/platform-users.md +159 -0
- package/docs/reference/cli/platform-zero-trust.md +60 -0
- package/docs/reference/cli/platform.md +78 -0
- package/docs/reference/cli/project.md +208 -0
- package/docs/reference/cli/secrets.md +79 -0
- package/docs/reference/cli/setup.md +88 -0
- package/docs/reference/cli.md +115 -0
- package/docs/reference/config.md +478 -0
- package/docs/reference/resource-inference.md +72 -0
- package/docs/reference/structure.md +138 -0
- package/package.json +389 -3
- package/sandbox.Dockerfile +4 -0
- package/schema.json +353 -0
- package/skills/bwf/SKILL.md +100 -0
- package/skills/migrate-vite-cloudflare-to-bwf/SKILL.md +53 -0
- package/templates/assets/bwf.svg +5 -0
- package/templates/assets/icons.svg +49 -0
- package/templates/assets/react.svg +1 -0
- package/templates/assets/stack.svg +35 -0
|
@@ -0,0 +1,1735 @@
|
|
|
1
|
+
import { A as confirm, H as outro, L as log, X as text, tt as isCancel } from "./dist-STQXl8ck.mjs";
|
|
2
|
+
import { a as join, c as resolve, n as dirname, r as extname, s as relative, t as basename } from "./dist-DMYe8CZJ.mjs";
|
|
3
|
+
import { c as getDatabaseCasing, f as readConfig, l as getDatabaseDialect, p as resolveBindingNames } from "./config-tNx0HlFv.mjs";
|
|
4
|
+
import { t as resolveLocalD1Target } from "./local-d1-C3EeOV7-.mjs";
|
|
5
|
+
import { i as writeJournal, n as readJournal, r as stripSqlExt, t as collectMigrations } from "./collect-C6Blu9yw.mjs";
|
|
6
|
+
import { i as validateMigrations, t as assertJournalCoherence } from "./validate-B-zsjhiz.mjs";
|
|
7
|
+
import { n as readProjectPaths } from "./project-paths-iXHKRTTQ.mjs";
|
|
8
|
+
import { t as cfAccessHeaders } from "./cf-access-CUP5L08W.mjs";
|
|
9
|
+
import { c as loadLocalEnv } from "./env-DUyTzroe.mjs";
|
|
10
|
+
import { c as getToken, o as getProxyUrl } from "./auth-xnkmpZUl.mjs";
|
|
11
|
+
import { n as ensurePlatformProxyAccess, r as isCloudflareAccessChallenge, t as ensurePlatformAccessToken } from "./cf-access-Bhz9wX6p.mjs";
|
|
12
|
+
import { n as PlatformApiError, r as PlatformClient } from "./client-D3D5RM5h.mjs";
|
|
13
|
+
import { n as formatTimestamp } from "./gen-dc13IRXh.mjs";
|
|
14
|
+
import { f as import_picocolors, i as dim, l as formatUrl, m as printSuccess, o as formatCount, u as getErrorMessage } from "./output-Bb34lF0w.mjs";
|
|
15
|
+
import { n as readDeploymentPlatform, r as readProjectConfig } from "./project-CC7eN00D.mjs";
|
|
16
|
+
import { n as drizzleKitBin } from "./yarn-pnp-DgWbE7z5.mjs";
|
|
17
|
+
import { createRequire } from "node:module";
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
19
|
+
import { pathToFileURL } from "node:url";
|
|
20
|
+
import { createJiti } from "jiti";
|
|
21
|
+
import { execFileSync } from "node:child_process";
|
|
22
|
+
// src/cli/db-export-sequences.ts
|
|
23
|
+
function quoteSqlIdentifier(value) {
|
|
24
|
+
return `"${value.replaceAll("\"", "\"\"")}"`;
|
|
25
|
+
}
|
|
26
|
+
function quoteSqlString(value) {
|
|
27
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
28
|
+
}
|
|
29
|
+
/** Fail before writing a schema dump that would silently omit dependent objects. */
|
|
30
|
+
async function assertPgExportableSchema(client, tables, fullExport) {
|
|
31
|
+
const unsupported = (await client.query(`SELECT kind, name FROM (
|
|
32
|
+
SELECT 'view' AS kind, rel.relname AS name
|
|
33
|
+
FROM pg_class rel JOIN pg_namespace ns ON ns.oid = rel.relnamespace
|
|
34
|
+
WHERE ns.nspname = 'public' AND rel.relkind IN ('v', 'm') AND $2::boolean
|
|
35
|
+
UNION ALL
|
|
36
|
+
SELECT 'trigger', tg.tgname
|
|
37
|
+
FROM pg_trigger tg JOIN pg_class tbl ON tbl.oid = tg.tgrelid
|
|
38
|
+
JOIN pg_namespace ns ON ns.oid = tbl.relnamespace
|
|
39
|
+
WHERE ns.nspname = 'public' AND tbl.relname = ANY($1::text[]) AND NOT tg.tgisinternal
|
|
40
|
+
UNION ALL
|
|
41
|
+
SELECT 'custom type', typ.typname
|
|
42
|
+
FROM pg_attribute col JOIN pg_class tbl ON tbl.oid = col.attrelid
|
|
43
|
+
JOIN pg_namespace ns ON ns.oid = tbl.relnamespace
|
|
44
|
+
JOIN pg_type typ ON typ.oid = col.atttypid
|
|
45
|
+
JOIN pg_namespace type_ns ON type_ns.oid = typ.typnamespace
|
|
46
|
+
WHERE ns.nspname = 'public' AND tbl.relname = ANY($1::text[])
|
|
47
|
+
AND col.attnum > 0 AND NOT col.attisdropped AND type_ns.nspname = 'public'
|
|
48
|
+
UNION ALL
|
|
49
|
+
SELECT 'function', proc.proname
|
|
50
|
+
FROM pg_proc proc JOIN pg_namespace ns ON ns.oid = proc.pronamespace
|
|
51
|
+
WHERE ns.nspname = 'public' AND $2::boolean
|
|
52
|
+
UNION ALL
|
|
53
|
+
SELECT 'standalone sequence', seq.relname
|
|
54
|
+
FROM pg_class seq JOIN pg_namespace ns ON ns.oid = seq.relnamespace
|
|
55
|
+
WHERE ns.nspname = 'public' AND seq.relkind = 'S' AND $2::boolean
|
|
56
|
+
AND NOT EXISTS (
|
|
57
|
+
SELECT 1 FROM pg_depend dep WHERE dep.objid = seq.oid
|
|
58
|
+
AND dep.classid = 'pg_class'::regclass AND dep.deptype IN ('a', 'i')
|
|
59
|
+
)
|
|
60
|
+
) objects ORDER BY kind, name LIMIT 1`, [tables, fullExport])).rows[0];
|
|
61
|
+
if (unsupported) throw new Error(`db: PostgreSQL schema contains ${unsupported.kind} ${quoteSqlIdentifier(unsupported.name)}, which bwf db export cannot restore. Use pg_dump for a complete schema dump.`);
|
|
62
|
+
}
|
|
63
|
+
/** Restore SERIAL dependencies before tables, ownership/state after their data. */
|
|
64
|
+
async function exportPgSequences(client, tables, options) {
|
|
65
|
+
const result = await client.query(`SELECT ns.nspname AS schema_name, seq.relname AS sequence_name,
|
|
66
|
+
dep.deptype AS dependency_type,
|
|
67
|
+
tbl.relname AS table_name, col.attname AS column_name,
|
|
68
|
+
format_type(s.seqtypid, NULL) AS data_type,
|
|
69
|
+
s.seqstart::text AS start_value, s.seqincrement::text AS increment_by,
|
|
70
|
+
s.seqmin::text AS min_value, s.seqmax::text AS max_value,
|
|
71
|
+
s.seqcache::text AS cache_size, s.seqcycle AS cycle
|
|
72
|
+
FROM pg_sequence s
|
|
73
|
+
JOIN pg_class seq ON seq.oid = s.seqrelid
|
|
74
|
+
JOIN pg_namespace ns ON ns.oid = seq.relnamespace
|
|
75
|
+
JOIN pg_depend dep ON dep.objid = seq.oid AND dep.classid = 'pg_class'::regclass
|
|
76
|
+
JOIN pg_class tbl ON tbl.oid = dep.refobjid
|
|
77
|
+
JOIN pg_namespace tblns ON tblns.oid = tbl.relnamespace
|
|
78
|
+
JOIN pg_attribute col ON col.attrelid = tbl.oid AND col.attnum = dep.refobjsubid
|
|
79
|
+
WHERE tblns.nspname = 'public' AND tbl.relname = ANY($1::text[])
|
|
80
|
+
AND dep.deptype IN ('a', 'i')
|
|
81
|
+
ORDER BY ns.nspname, seq.relname`, [tables]);
|
|
82
|
+
const before = [];
|
|
83
|
+
const after = [];
|
|
84
|
+
for (const seq of result.rows) {
|
|
85
|
+
const name = `${quoteSqlIdentifier(seq.schema_name)}.${quoteSqlIdentifier(seq.sequence_name)}`;
|
|
86
|
+
if (!options.noSchema && seq.dependency_type === "a") {
|
|
87
|
+
before.push(`CREATE SEQUENCE ${name} AS ${seq.data_type} INCREMENT BY ${seq.increment_by} MINVALUE ${seq.min_value} MAXVALUE ${seq.max_value} START WITH ${seq.start_value} CACHE ${seq.cache_size} ${seq.cycle ? "CYCLE" : "NO CYCLE"};`);
|
|
88
|
+
after.push(`ALTER SEQUENCE ${name} OWNED BY "public".${quoteSqlIdentifier(seq.table_name)}.${quoteSqlIdentifier(seq.column_name)};`);
|
|
89
|
+
}
|
|
90
|
+
if (!options.noData) {
|
|
91
|
+
const value = (await client.query(`SELECT last_value::text, is_called FROM ${name}`)).rows[0];
|
|
92
|
+
after.push(`SELECT pg_catalog.setval(${quoteSqlString(name)}, ${value.last_value}, ${value.is_called});`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
before,
|
|
97
|
+
after
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** Add constraints after all tables/data so cross-table references can resolve. */
|
|
101
|
+
async function exportPgConstraints(client, tables) {
|
|
102
|
+
const constraints = await client.query(`
|
|
103
|
+
SELECT tbl.relname AS table_name, con.conname AS name, pg_get_constraintdef(con.oid) AS definition
|
|
104
|
+
FROM pg_constraint con JOIN pg_class tbl ON tbl.oid = con.conrelid
|
|
105
|
+
JOIN pg_namespace ns ON ns.oid = tbl.relnamespace
|
|
106
|
+
WHERE ns.nspname = 'public' AND tbl.relname = ANY($1::text[])
|
|
107
|
+
AND con.contype IN ('p', 'u', 'f', 'c', 'x')
|
|
108
|
+
ORDER BY CASE WHEN con.contype = 'f' THEN 1 ELSE 0 END, tbl.relname, con.conname`, [tables]);
|
|
109
|
+
const indexes = await client.query(`
|
|
110
|
+
SELECT pg_get_indexdef(idx.indexrelid) AS definition
|
|
111
|
+
FROM pg_index idx JOIN pg_class tbl ON tbl.oid = idx.indrelid
|
|
112
|
+
JOIN pg_namespace ns ON ns.oid = tbl.relnamespace
|
|
113
|
+
WHERE ns.nspname = 'public' AND tbl.relname = ANY($1::text[])
|
|
114
|
+
AND NOT EXISTS (SELECT 1 FROM pg_constraint con WHERE con.conindid = idx.indexrelid)
|
|
115
|
+
ORDER BY idx.indexrelid`, [tables]);
|
|
116
|
+
return [...constraints.rows.map((row) => `ALTER TABLE "public".${quoteSqlIdentifier(row.table_name)} ADD CONSTRAINT ${quoteSqlIdentifier(row.name)} ${row.definition};`), ...indexes.rows.map((row) => row.definition + ";")];
|
|
117
|
+
}
|
|
118
|
+
// src/cli/db.ts
|
|
119
|
+
const DEFAULT_SEED_FILES = [
|
|
120
|
+
"db/seed.ts",
|
|
121
|
+
"db/seed.mts",
|
|
122
|
+
"db/seed.js",
|
|
123
|
+
"db/seed.mjs",
|
|
124
|
+
"db/seed.sql"
|
|
125
|
+
];
|
|
126
|
+
const MODULE_SEED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
127
|
+
".ts",
|
|
128
|
+
".mts",
|
|
129
|
+
".js",
|
|
130
|
+
".mjs"
|
|
131
|
+
]);
|
|
132
|
+
function getLocalD1Target(root) {
|
|
133
|
+
return resolveLocalD1Target(root, {
|
|
134
|
+
bindingName: configuredD1Binding(root),
|
|
135
|
+
defaultPersistRoot: join(root, ".bwf"),
|
|
136
|
+
readPersistState: true
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function configuredD1Binding(root) {
|
|
140
|
+
return resolveBindingNames(readConfig(root).inference?.bindings)?.d1 ?? "DB";
|
|
141
|
+
}
|
|
142
|
+
function runDrizzleKit(root, args) {
|
|
143
|
+
execFileSync(process.execPath, [drizzleKitBin, ...args], {
|
|
144
|
+
cwd: root,
|
|
145
|
+
stdio: "inherit"
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Run a drizzle-kit command against a real database URL. The config holding
|
|
150
|
+
* the URL lives in a private temp directory outside the project and is
|
|
151
|
+
* removed afterwards. Exits with code 1 when drizzle-kit fails; it has
|
|
152
|
+
* already printed its own error.
|
|
153
|
+
*/
|
|
154
|
+
async function runDrizzleKitWithDatabaseUrl(root, url, dialect, command) {
|
|
155
|
+
const { withPrivateDrizzleConfig } = await import("./config-D5G-Tx6o.mjs");
|
|
156
|
+
if (!withPrivateDrizzleConfig(root, url, dialect, (configPath) => {
|
|
157
|
+
try {
|
|
158
|
+
runDrizzleKit(root, [
|
|
159
|
+
command,
|
|
160
|
+
"--config",
|
|
161
|
+
configPath
|
|
162
|
+
]);
|
|
163
|
+
return true;
|
|
164
|
+
} catch {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
})) process.exit(1);
|
|
168
|
+
}
|
|
169
|
+
function getLocalDatabaseUrl(root, dialect) {
|
|
170
|
+
const url = loadLocalEnv(root).DATABASE_URL;
|
|
171
|
+
if (!url) throw new Error(`DATABASE_URL not found in .env. Add it to connect to your local ${dialect === "mysql" ? "MySQL" : "PostgreSQL"} database.`);
|
|
172
|
+
return url;
|
|
173
|
+
}
|
|
174
|
+
async function withPgClient(root, fn) {
|
|
175
|
+
const url = getLocalDatabaseUrl(root, "postgresql");
|
|
176
|
+
const { Client } = await import("pg");
|
|
177
|
+
const client = new Client({ connectionString: url });
|
|
178
|
+
await client.connect();
|
|
179
|
+
try {
|
|
180
|
+
return await fn(client);
|
|
181
|
+
} finally {
|
|
182
|
+
await client.end();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async function withMySqlClient(root, fn, options = {}) {
|
|
186
|
+
const { toMySqlClient } = await import("./runner-mysql-DrMKw203.mjs");
|
|
187
|
+
const { createConnection } = await import("mysql2/promise");
|
|
188
|
+
const connection = await createConnection({
|
|
189
|
+
uri: getLocalDatabaseUrl(root, "mysql"),
|
|
190
|
+
multipleStatements: true,
|
|
191
|
+
...options.textValues ? {
|
|
192
|
+
dateStrings: true,
|
|
193
|
+
jsonStrings: true,
|
|
194
|
+
supportBigNumbers: true,
|
|
195
|
+
bigNumberStrings: true
|
|
196
|
+
} : {}
|
|
197
|
+
});
|
|
198
|
+
try {
|
|
199
|
+
return await fn(toMySqlClient(connection));
|
|
200
|
+
} finally {
|
|
201
|
+
await connection.end();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function validatePendingMigrations(migrations, appliedNames) {
|
|
205
|
+
const pending = migrations.filter((migration) => !appliedNames.has(migration.name));
|
|
206
|
+
if (pending.length === 0) return;
|
|
207
|
+
validateMigrations(pending);
|
|
208
|
+
}
|
|
209
|
+
async function runDbCommand(root, args) {
|
|
210
|
+
if (!(args.action === "export" && !args.output)) console.log();
|
|
211
|
+
const dialect = getDatabaseDialect(readConfig(root));
|
|
212
|
+
if (args.action === "push") await runPush(root, dialect);
|
|
213
|
+
else if (args.action === "generate") await runGenerate(root, dialect);
|
|
214
|
+
else if (args.action === "status") await runStatus(root, dialect);
|
|
215
|
+
else if (args.action === "reset") await runReset(root, dialect, args.yes);
|
|
216
|
+
else if (args.action === "seed") await runSeed(root, args.file, dialect, args.yes);
|
|
217
|
+
else if (args.action === "execute") await runExecute(root, args.command, args.file, dialect, args.remote);
|
|
218
|
+
else if (args.action === "migrate") await runMigrate(root, dialect, args.remote);
|
|
219
|
+
else if (args.action === "studio") await runStudio(root, dialect, args.remote);
|
|
220
|
+
else if (args.action === "set-url") await runSetUrl(root, dialect);
|
|
221
|
+
else if (args.action === "connect") await runConnect(root, dialect, args);
|
|
222
|
+
else if (args.action === "restore") await runRestore(root, dialect, args);
|
|
223
|
+
else if (args.action === "rename-migrations") await runRenameMigrations(root, dialect);
|
|
224
|
+
else await runExport(root, args, dialect);
|
|
225
|
+
}
|
|
226
|
+
function writeLocalDatabaseUrl(root, connectionString) {
|
|
227
|
+
const envPath = join(root, ".env");
|
|
228
|
+
const original = existsSync(envPath) ? readFileSync(envPath, "utf-8") : "";
|
|
229
|
+
const lines = original ? original.replace(/\r\n/g, "\n").split("\n") : [];
|
|
230
|
+
const assignment = `DATABASE_URL=${JSON.stringify(connectionString)}`;
|
|
231
|
+
const index = lines.findIndex((line) => /^\s*(?:export\s+)?DATABASE_URL\s*=/.test(line));
|
|
232
|
+
if (index === -1) {
|
|
233
|
+
while (lines.at(-1) === "") lines.pop();
|
|
234
|
+
if (lines.length > 0) lines.push("");
|
|
235
|
+
lines.push(assignment);
|
|
236
|
+
} else {
|
|
237
|
+
lines[index] = assignment;
|
|
238
|
+
for (let i = lines.length - 1; i > index; i--) if (/^\s*(?:export\s+)?DATABASE_URL\s*=/.test(lines[i])) lines.splice(i, 1);
|
|
239
|
+
}
|
|
240
|
+
while (lines.at(-1) === "") lines.pop();
|
|
241
|
+
writeFileSync(envPath, `${lines.join("\n")}\n`);
|
|
242
|
+
}
|
|
243
|
+
function assertDatabaseProvider(value, source) {
|
|
244
|
+
if (!value || typeof value !== "object") throw new Error(`Database provider '${source}' did not export an adapter object.`);
|
|
245
|
+
const adapter = value;
|
|
246
|
+
if (typeof adapter.id !== "string" || typeof adapter.label !== "string" || !Array.isArray(adapter.dialects) || typeof adapter.provision !== "function") throw new Error(`Database provider '${source}' does not implement DatabaseProviderAdapter.`);
|
|
247
|
+
return adapter;
|
|
248
|
+
}
|
|
249
|
+
async function loadDatabaseProvider(root, provider) {
|
|
250
|
+
if (provider === "neon") {
|
|
251
|
+
const { createNeonDatabaseProvider } = await import("./neon-CJzQSycr.mjs");
|
|
252
|
+
return createNeonDatabaseProvider();
|
|
253
|
+
}
|
|
254
|
+
const requireFromProject = createRequire(join(root, "package.json"));
|
|
255
|
+
let resolved;
|
|
256
|
+
try {
|
|
257
|
+
resolved = provider.startsWith(".") || provider.startsWith("/") ? resolve(root, provider) : requireFromProject.resolve(provider);
|
|
258
|
+
} catch {
|
|
259
|
+
throw new Error(`Could not resolve database provider adapter '${provider}' from this project. Install it first or pass a file path.`);
|
|
260
|
+
}
|
|
261
|
+
const mod = await import(pathToFileURL(resolved).href);
|
|
262
|
+
return assertDatabaseProvider(mod.default ?? mod.databaseProvider, provider);
|
|
263
|
+
}
|
|
264
|
+
async function runConnect(root, dialect, args) {
|
|
265
|
+
if (dialect === "sqlite") {
|
|
266
|
+
log.error("db: `bwf db connect` requires an external database. Set \"database\" to \"pg\" or \"mysql\" in bwf.config.ts first.");
|
|
267
|
+
process.exit(1);
|
|
268
|
+
}
|
|
269
|
+
let connectionString = args.url;
|
|
270
|
+
if (args.provider) {
|
|
271
|
+
const adapter = await loadDatabaseProvider(root, args.provider);
|
|
272
|
+
if (!adapter.dialects.includes(dialect)) throw new Error(`${adapter.label} does not support the configured ${dialect} dialect.`);
|
|
273
|
+
log.info(`Provisioning ${adapter.label} database...`);
|
|
274
|
+
const result = await adapter.provision({
|
|
275
|
+
name: args.name ?? basename(root),
|
|
276
|
+
dialect,
|
|
277
|
+
region: args.region
|
|
278
|
+
});
|
|
279
|
+
connectionString = result.connectionString;
|
|
280
|
+
log.step(`Provisioned ${adapter.label} database.`);
|
|
281
|
+
if (result.dashboardUrl) log.info(`Dashboard: ${formatUrl(result.dashboardUrl)}`);
|
|
282
|
+
}
|
|
283
|
+
if (!connectionString) {
|
|
284
|
+
const answer = await text({
|
|
285
|
+
message: `Enter your ${dialect === "mysql" ? "MySQL" : "PostgreSQL"} connection string:`,
|
|
286
|
+
placeholder: dialect === "mysql" ? "mysql://user:pass@host:3306/database" : "postgresql://user:pass@host:5432/database"
|
|
287
|
+
});
|
|
288
|
+
if (isCancel(answer)) process.exit(0);
|
|
289
|
+
connectionString = answer;
|
|
290
|
+
}
|
|
291
|
+
const parsed = new URL(connectionString);
|
|
292
|
+
if (!(dialect === "mysql" ? ["mysql:"] : ["postgres:", "postgresql:"]).includes(parsed.protocol)) throw new Error(`Connection string protocol '${parsed.protocol}' does not match the configured ${dialect} dialect.`);
|
|
293
|
+
writeLocalDatabaseUrl(root, connectionString);
|
|
294
|
+
log.step("Saved DATABASE_URL to .env.");
|
|
295
|
+
if (!args.localOnly) {
|
|
296
|
+
const token = getToken(root);
|
|
297
|
+
const projectConfig = readProjectConfig(root);
|
|
298
|
+
if (token && projectConfig) {
|
|
299
|
+
await new PlatformClient(token, { root }).setDatabaseUrl(projectConfig.projectId, connectionString);
|
|
300
|
+
log.step("Updated the linked bwf project database URL.");
|
|
301
|
+
} else log.info("No authenticated bwf project is linked, so only local configuration was updated.");
|
|
302
|
+
}
|
|
303
|
+
printSuccess("Database connected.");
|
|
304
|
+
}
|
|
305
|
+
async function runPush(root, dialect) {
|
|
306
|
+
if (dialect !== "sqlite") {
|
|
307
|
+
await runDrizzleKitWithDatabaseUrl(root, getLocalDatabaseUrl(root, dialect), dialect, "push");
|
|
308
|
+
printSuccess("Database schema pushed.");
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const { writeDrizzleConfig } = await import("./config-D5G-Tx6o.mjs");
|
|
312
|
+
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
313
|
+
mkdirSync(dirname(dbPath), { recursive: true });
|
|
314
|
+
const configPath = writeDrizzleConfig(root, dbPath);
|
|
315
|
+
try {
|
|
316
|
+
runDrizzleKit(root, [
|
|
317
|
+
"push",
|
|
318
|
+
"--config",
|
|
319
|
+
configPath
|
|
320
|
+
]);
|
|
321
|
+
} catch {
|
|
322
|
+
process.exit(1);
|
|
323
|
+
}
|
|
324
|
+
printSuccess("Database schema pushed.");
|
|
325
|
+
}
|
|
326
|
+
async function runGenerate(root, dialect) {
|
|
327
|
+
const { prepareProject } = await import("./prepare-LHkyJqxi.mjs");
|
|
328
|
+
const { PLACEHOLDER_DB_URL, writeDrizzleConfig } = await import("./config-D5G-Tx6o.mjs");
|
|
329
|
+
await prepareProject(root);
|
|
330
|
+
const authSchemaPath = join(root, ".bwf", "better-auth-schema.ts");
|
|
331
|
+
const additionalSchemas = existsSync(authSchemaPath) ? [authSchemaPath] : void 0;
|
|
332
|
+
const configPath = writeDrizzleConfig(root, PLACEHOLDER_DB_URL[dialect], dialect, { additionalSchemas });
|
|
333
|
+
try {
|
|
334
|
+
if (dialect === "sqlite") {
|
|
335
|
+
const { generateValidatedSqliteMigrations } = await import("./generate-BgtlYpKg.mjs");
|
|
336
|
+
await generateValidatedSqliteMigrations(readProjectPaths(root).migrationsDir, () => {
|
|
337
|
+
runDrizzleKit(root, [
|
|
338
|
+
"generate",
|
|
339
|
+
"--config",
|
|
340
|
+
configPath
|
|
341
|
+
]);
|
|
342
|
+
});
|
|
343
|
+
} else runDrizzleKit(root, [
|
|
344
|
+
"generate",
|
|
345
|
+
"--config",
|
|
346
|
+
configPath
|
|
347
|
+
]);
|
|
348
|
+
} catch (error) {
|
|
349
|
+
log.error(getErrorMessage(error));
|
|
350
|
+
process.exit(1);
|
|
351
|
+
}
|
|
352
|
+
printSuccess("Migration generation complete.");
|
|
353
|
+
}
|
|
354
|
+
async function runStatus(root, dialect) {
|
|
355
|
+
const paths = readProjectPaths(root);
|
|
356
|
+
const migrationsDir = paths.migrationsDir;
|
|
357
|
+
const allMigrations = collectMigrations(migrationsDir);
|
|
358
|
+
try {
|
|
359
|
+
assertJournalCoherence(migrationsDir, allMigrations, paths.sourceRelative);
|
|
360
|
+
} catch (err) {
|
|
361
|
+
log.error(getErrorMessage(err));
|
|
362
|
+
process.exit(1);
|
|
363
|
+
}
|
|
364
|
+
if (allMigrations.length === 0) {
|
|
365
|
+
log.info(`No migration files found in ${paths.sourceRelative("db/migrations")}/`);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
let localApplied;
|
|
369
|
+
let localError;
|
|
370
|
+
if (dialect === "postgresql") try {
|
|
371
|
+
const { readPgAppliedMigrations } = await import("./runner-pg-2pjltt0t.mjs");
|
|
372
|
+
localApplied = await withPgClient(root, readPgAppliedMigrations);
|
|
373
|
+
} catch (error) {
|
|
374
|
+
localError = error;
|
|
375
|
+
}
|
|
376
|
+
else if (dialect === "mysql") try {
|
|
377
|
+
const { readMySqlAppliedMigrations } = await import("./runner-mysql-DrMKw203.mjs");
|
|
378
|
+
localApplied = await withMySqlClient(root, readMySqlAppliedMigrations);
|
|
379
|
+
} catch (error) {
|
|
380
|
+
localError = error;
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
const { getAppliedMigrations } = await import("./runner-CUNtS5x7.mjs");
|
|
384
|
+
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
385
|
+
localApplied = (await getAppliedMigrations(dbPath)).map((m) => m.name);
|
|
386
|
+
}
|
|
387
|
+
const localSet = localApplied ? new Set(localApplied) : null;
|
|
388
|
+
let remoteApplied = null;
|
|
389
|
+
if (readDeploymentPlatform(root) === "cloudflare") try {
|
|
390
|
+
if (dialect !== "sqlite") {
|
|
391
|
+
const databaseUrl = process.env.DATABASE_URL;
|
|
392
|
+
if (!databaseUrl) throw new Error("DATABASE_URL is not available.");
|
|
393
|
+
remoteApplied = (dialect === "postgresql" ? await (await import("./runner-pg-2pjltt0t.mjs")).getPgAppliedMigrations(databaseUrl) : await (await import("./runner-mysql-DrMKw203.mjs")).getMySqlAppliedMigrations(databaseUrl)).map((name) => ({
|
|
394
|
+
name,
|
|
395
|
+
applied_at: ""
|
|
396
|
+
}));
|
|
397
|
+
} else {
|
|
398
|
+
const { readCloudflareD1Migrations, resolveCloudflareD1Context } = await import("./cloudflare-operations-C3Uu0Emj.mjs");
|
|
399
|
+
remoteApplied = (await readCloudflareD1Migrations(resolveCloudflareD1Context(root, configuredD1Binding(root)))).map((name) => ({
|
|
400
|
+
name,
|
|
401
|
+
applied_at: ""
|
|
402
|
+
}));
|
|
403
|
+
}
|
|
404
|
+
} catch {}
|
|
405
|
+
else {
|
|
406
|
+
const token = getToken(root);
|
|
407
|
+
const config = readProjectConfig(root);
|
|
408
|
+
if (token && config) try {
|
|
409
|
+
remoteApplied = (await new PlatformClient(token, { root }).getMigrationStatus(config.projectId, dialect)).applied;
|
|
410
|
+
} catch {}
|
|
411
|
+
}
|
|
412
|
+
const remoteSet = remoteApplied ? new Set(remoteApplied.map((m) => m.name)) : null;
|
|
413
|
+
if (localSet === null) {
|
|
414
|
+
const message = `Local migration status is unavailable: ${getErrorMessage(localError)}`;
|
|
415
|
+
if (remoteSet === null) {
|
|
416
|
+
log.error(message);
|
|
417
|
+
process.exit(1);
|
|
418
|
+
}
|
|
419
|
+
log.warn(message);
|
|
420
|
+
}
|
|
421
|
+
const lines = [];
|
|
422
|
+
for (const migration of allMigrations) {
|
|
423
|
+
const localStatus = localSet === null ? dim("unknown") : localSet.has(migration.name) ? import_picocolors.default.green("applied") : import_picocolors.default.yellow("pending");
|
|
424
|
+
let remotePart = "";
|
|
425
|
+
if (remoteSet !== null) remotePart = ` remote: ${remoteSet.has(migration.name) ? import_picocolors.default.green("applied") : import_picocolors.default.yellow("pending")}`;
|
|
426
|
+
lines.push(` ${migration.name} ${dim("local:")} ${localStatus}${remotePart}`);
|
|
427
|
+
}
|
|
428
|
+
log.info(lines.join("\n"));
|
|
429
|
+
const parts = [formatCount(allMigrations.length, "migration")];
|
|
430
|
+
if (localSet !== null) {
|
|
431
|
+
const localPending = allMigrations.filter((m) => !localSet.has(m.name)).length;
|
|
432
|
+
if (localPending > 0) parts.push(`${localPending} pending locally`);
|
|
433
|
+
}
|
|
434
|
+
if (remoteSet !== null) {
|
|
435
|
+
const remotePending = allMigrations.filter((m) => !remoteSet.has(m.name)).length;
|
|
436
|
+
if (remotePending > 0) parts.push(`${remotePending} pending remotely`);
|
|
437
|
+
}
|
|
438
|
+
outro(parts.join(", "));
|
|
439
|
+
}
|
|
440
|
+
const LOCAL_DATABASE_HOSTS = /* @__PURE__ */ new Set([
|
|
441
|
+
"",
|
|
442
|
+
"localhost",
|
|
443
|
+
"127.0.0.1",
|
|
444
|
+
"::1",
|
|
445
|
+
"[::1]"
|
|
446
|
+
]);
|
|
447
|
+
/**
|
|
448
|
+
* Objects that `bwf db reset` drops in `public` before it applies every migration again:
|
|
449
|
+
* tables and views first, then standalone sequences, then enum, domain, range and composite
|
|
450
|
+
* types. drizzle-kit creates them without `IF NOT EXISTS`, so any one that stays makes the
|
|
451
|
+
* migration fail. Extension members stay, and so do sequences that a column owns: the table
|
|
452
|
+
* drop removes them, and their names change when a table is renamed.
|
|
453
|
+
*/
|
|
454
|
+
const PG_RESET_OBJECTS = `SELECT kind, name FROM (
|
|
455
|
+
SELECT CASE rel.relkind WHEN 'v' THEN 'VIEW' WHEN 'm' THEN 'MATERIALIZED VIEW'
|
|
456
|
+
WHEN 'S' THEN 'SEQUENCE' ELSE 'TABLE' END AS kind,
|
|
457
|
+
rel.relname AS name, CASE rel.relkind WHEN 'S' THEN 1 ELSE 0 END AS step
|
|
458
|
+
FROM pg_class rel JOIN pg_namespace ns ON ns.oid = rel.relnamespace
|
|
459
|
+
WHERE ns.nspname = 'public' AND rel.relkind IN ('r', 'p', 'v', 'm', 'S')
|
|
460
|
+
AND NOT EXISTS (
|
|
461
|
+
SELECT 1 FROM pg_depend dep WHERE dep.classid = 'pg_class'::regclass AND dep.objid = rel.oid
|
|
462
|
+
AND (dep.deptype = 'e' OR (rel.relkind = 'S' AND dep.deptype IN ('a', 'i')))
|
|
463
|
+
)
|
|
464
|
+
UNION ALL
|
|
465
|
+
SELECT 'TYPE', typ.typname, 2
|
|
466
|
+
FROM pg_type typ JOIN pg_namespace ns ON ns.oid = typ.typnamespace
|
|
467
|
+
WHERE ns.nspname = 'public'
|
|
468
|
+
AND (typ.typtype IN ('e', 'd', 'r')
|
|
469
|
+
OR (typ.typtype = 'c' AND (SELECT relkind FROM pg_class WHERE oid = typ.typrelid) = 'c'))
|
|
470
|
+
AND NOT EXISTS (
|
|
471
|
+
SELECT 1 FROM pg_depend dep WHERE dep.classid = 'pg_type'::regclass AND dep.objid = typ.oid
|
|
472
|
+
AND dep.deptype = 'e'
|
|
473
|
+
)
|
|
474
|
+
) objects ORDER BY step, name`;
|
|
475
|
+
/**
|
|
476
|
+
* Objects in other schemas that `CASCADE` would also drop with the types ($1) and the views,
|
|
477
|
+
* materialized views and sequences ($2) that reset drops in `public`: a column of that type or
|
|
478
|
+
* its array type, a view, a function, a column default and so on, also through a type or
|
|
479
|
+
* function in `public` that goes with them. Reset must not remove these, so it stops when there
|
|
480
|
+
* are any. The TOAST table of a materialized view is part of it, so it does not count. The table
|
|
481
|
+
* drops still remove what depends on a `public` table in another schema (a view, a foreign key,
|
|
482
|
+
* an inheriting table); a view that also uses one of these objects is listed here too.
|
|
483
|
+
*/
|
|
484
|
+
const PG_RESET_OUTSIDE_DEPENDENTS = `WITH RECURSIVE dropped(classid, objid) AS (
|
|
485
|
+
SELECT 'pg_type'::regclass::oid, typ.oid FROM pg_type typ
|
|
486
|
+
WHERE typ.typnamespace = 'public'::regnamespace AND typ.typname = ANY($1::text[])
|
|
487
|
+
UNION ALL
|
|
488
|
+
SELECT 'pg_class'::regclass::oid, rel.oid FROM pg_class rel
|
|
489
|
+
WHERE rel.relnamespace = 'public'::regnamespace AND rel.relname = ANY($2::text[])
|
|
490
|
+
UNION
|
|
491
|
+
SELECT dep.classid, dep.objid FROM dropped
|
|
492
|
+
JOIN pg_depend dep ON dep.refclassid = dropped.classid AND dep.refobjid = dropped.objid
|
|
493
|
+
WHERE dep.classid IN ('pg_type'::regclass, 'pg_proc'::regclass)
|
|
494
|
+
AND (pg_identify_object(dep.classid, dep.objid, 0)).schema = 'public'
|
|
495
|
+
)
|
|
496
|
+
SELECT DISTINCT pg_describe_object(dep.classid, dep.objid, dep.objsubid) || ' uses '
|
|
497
|
+
|| pg_describe_object(dep.refclassid, dep.refobjid, 0) AS object
|
|
498
|
+
FROM dropped
|
|
499
|
+
JOIN pg_depend dep ON dep.refclassid = dropped.classid AND dep.refobjid = dropped.objid
|
|
500
|
+
WHERE NOT (dep.classid = 'pg_class'::regclass AND dep.deptype = 'i')
|
|
501
|
+
AND COALESCE((pg_identify_object(dep.classid, dep.objid, dep.objsubid)).schema, (
|
|
502
|
+
SELECT ns.nspname FROM pg_class rel JOIN pg_namespace ns ON ns.oid = rel.relnamespace
|
|
503
|
+
WHERE rel.oid = CASE dep.classid
|
|
504
|
+
WHEN 'pg_attrdef'::regclass THEN (SELECT adrelid FROM pg_attrdef WHERE oid = dep.objid)
|
|
505
|
+
WHEN 'pg_rewrite'::regclass THEN (SELECT ev_class FROM pg_rewrite WHERE oid = dep.objid)
|
|
506
|
+
WHEN 'pg_trigger'::regclass THEN (SELECT tgrelid FROM pg_trigger WHERE oid = dep.objid)
|
|
507
|
+
WHEN 'pg_policy'::regclass THEN (SELECT polrelid FROM pg_policy WHERE oid = dep.objid)
|
|
508
|
+
END)) <> 'public'
|
|
509
|
+
ORDER BY object`;
|
|
510
|
+
/**
|
|
511
|
+
* `.env` may hold the deployed database URL (`bwf db connect` writes it there), so ask before
|
|
512
|
+
* dropping every table on any other host. Without a TTY, require `--yes`.
|
|
513
|
+
*/
|
|
514
|
+
async function confirmDropAllTables(host, target, yes) {
|
|
515
|
+
if (yes || LOCAL_DATABASE_HOSTS.has(host) || host.startsWith("/")) return;
|
|
516
|
+
if (!process.stdin.isTTY) {
|
|
517
|
+
log.error(`db: Refusing to drop every table in ${target} without confirmation. Re-run with --yes.`);
|
|
518
|
+
process.exit(1);
|
|
519
|
+
}
|
|
520
|
+
const ok = await confirm({ message: `This drops every table in ${target}. Continue?` });
|
|
521
|
+
if (isCancel(ok) || !ok) {
|
|
522
|
+
log.info("Cancelled.");
|
|
523
|
+
process.exit(0);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
async function confirmReset(root, dialect, yes) {
|
|
527
|
+
if (dialect === "postgresql") {
|
|
528
|
+
const { Client } = await import("pg");
|
|
529
|
+
const { host, port, database } = new Client({ connectionString: getLocalDatabaseUrl(root, dialect) });
|
|
530
|
+
await confirmDropAllTables(host, `database "${database}" on ${host}:${port}`, yes);
|
|
531
|
+
} else if (dialect === "mysql") {
|
|
532
|
+
const { hostname, host, pathname } = new URL(getLocalDatabaseUrl(root, dialect));
|
|
533
|
+
await confirmDropAllTables(hostname, `database "${decodeURIComponent(pathname.slice(1))}" on ${host}`, yes);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
async function resetDatabase(root, dialect, yes) {
|
|
537
|
+
const paths = readProjectPaths(root);
|
|
538
|
+
const migrationsDir = paths.migrationsDir;
|
|
539
|
+
const migrations = collectMigrations(migrationsDir);
|
|
540
|
+
try {
|
|
541
|
+
assertJournalCoherence(migrationsDir, migrations, paths.sourceRelative);
|
|
542
|
+
} catch (err) {
|
|
543
|
+
log.error(getErrorMessage(err));
|
|
544
|
+
process.exit(1);
|
|
545
|
+
}
|
|
546
|
+
await confirmReset(root, dialect, yes);
|
|
547
|
+
if (dialect === "postgresql") {
|
|
548
|
+
const { applyPgMigrations } = await import("./runner-pg-2pjltt0t.mjs");
|
|
549
|
+
await withPgClient(root, async (client) => {
|
|
550
|
+
const objects = await client.query(PG_RESET_OBJECTS);
|
|
551
|
+
const names = (kind) => objects.rows.filter((row) => row.kind === kind).map((row) => row.name);
|
|
552
|
+
const types = names("TYPE");
|
|
553
|
+
const relations = [
|
|
554
|
+
...names("VIEW"),
|
|
555
|
+
...names("MATERIALIZED VIEW"),
|
|
556
|
+
...names("SEQUENCE")
|
|
557
|
+
];
|
|
558
|
+
const outside = types.length > 0 || relations.length > 0 ? await client.query(PG_RESET_OUTSIDE_DEPENDENTS, [types, relations]) : { rows: [] };
|
|
559
|
+
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.");
|
|
560
|
+
for (const { kind, name } of objects.rows) await client.query(`DROP ${kind} IF EXISTS public.${quoteSqlIdentifier(name)} CASCADE`);
|
|
561
|
+
await applyPgMigrations(client, migrations);
|
|
562
|
+
});
|
|
563
|
+
return migrations.length;
|
|
564
|
+
}
|
|
565
|
+
if (dialect === "mysql") {
|
|
566
|
+
const { applyPendingMySqlMigrations, withMySqlMigrationLock } = await import("./runner-mysql-DrMKw203.mjs");
|
|
567
|
+
await withMySqlClient(root, (client) => withMySqlMigrationLock(client, async () => {
|
|
568
|
+
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')");
|
|
569
|
+
await client.query("SET FOREIGN_KEY_CHECKS = 0");
|
|
570
|
+
try {
|
|
571
|
+
for (const row of tables) {
|
|
572
|
+
if (row.table_name === "_void_migration_lock") continue;
|
|
573
|
+
const kind = row.table_type === "VIEW" ? "VIEW" : "TABLE";
|
|
574
|
+
const table = String(row.table_name).replaceAll("`", "``");
|
|
575
|
+
await client.query(`DROP ${kind} IF EXISTS \`${table}\``);
|
|
576
|
+
}
|
|
577
|
+
} finally {
|
|
578
|
+
await client.query("SET FOREIGN_KEY_CHECKS = 1");
|
|
579
|
+
}
|
|
580
|
+
await applyPendingMySqlMigrations(client, migrations);
|
|
581
|
+
}));
|
|
582
|
+
return migrations.length;
|
|
583
|
+
}
|
|
584
|
+
const { runMigrations } = await import("./runner-CUNtS5x7.mjs");
|
|
585
|
+
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
586
|
+
rmSync(dbPath, { force: true });
|
|
587
|
+
rmSync(dbPath + "-wal", { force: true });
|
|
588
|
+
rmSync(dbPath + "-shm", { force: true });
|
|
589
|
+
return (await runMigrations(migrationsDir, dbPath)).length;
|
|
590
|
+
}
|
|
591
|
+
async function runReset(root, dialect, yes) {
|
|
592
|
+
const count = await resetDatabase(root, dialect, yes);
|
|
593
|
+
if (dialect === "sqlite") log.info(dim("Restart your dev server if it's running."));
|
|
594
|
+
printSuccess(`Database reset. Applied ${formatCount(count, "migration")}.`);
|
|
595
|
+
}
|
|
596
|
+
async function runSeed(root, file, dialect, yes) {
|
|
597
|
+
const seed = resolveSeedTarget(root, file);
|
|
598
|
+
const sql = seed.kind === "sql" ? readFileSync(seed.path, "utf-8") : void 0;
|
|
599
|
+
await confirmReset(root, dialect, yes);
|
|
600
|
+
const seedFn = sql === void 0 ? await loadSeedFunction(seed.path) : void 0;
|
|
601
|
+
const migrationCount = await resetDatabase(root, dialect, true);
|
|
602
|
+
log.step(`Reset database. Applied ${formatCount(migrationCount, "migration")}.`);
|
|
603
|
+
if (sql !== void 0) {
|
|
604
|
+
if (dialect === "postgresql") {
|
|
605
|
+
await withPgClient(root, async (client) => {
|
|
606
|
+
await client.query(sql);
|
|
607
|
+
});
|
|
608
|
+
printSuccess(`Seeded from ${seed.displayPath}.`);
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
if (dialect === "mysql") {
|
|
612
|
+
await withMySqlClient(root, async (client) => {
|
|
613
|
+
await client.query(sql);
|
|
614
|
+
});
|
|
615
|
+
printSuccess(`Seeded from ${seed.displayPath}.`);
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const { openSqliteDatabase } = await import("./runner-CUNtS5x7.mjs");
|
|
619
|
+
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
620
|
+
const db = await openSqliteDatabase(dbPath);
|
|
621
|
+
try {
|
|
622
|
+
db.exec(sql);
|
|
623
|
+
} finally {
|
|
624
|
+
db.close();
|
|
625
|
+
}
|
|
626
|
+
} else await runSeedModule(root, seedFn, dialect);
|
|
627
|
+
log.info(dim("Restart your dev server if it's running."));
|
|
628
|
+
printSuccess(`Seeded from ${seed.displayPath}.`);
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Fail-closed check for read-only SQL (SELECT or plain EXPLAIN), which skips the remote
|
|
632
|
+
* confirmation prompt. Comments are stripped first so they cannot hide `ANALYZE`.
|
|
633
|
+
* Multiple statements and `WITH` (a CTE can write) are rejected, and so is `EXPLAIN ANALYZE`
|
|
634
|
+
* in either form, because PostgreSQL executes the analyzed statement.
|
|
635
|
+
*/
|
|
636
|
+
function isSafeStatement(sql) {
|
|
637
|
+
const stripped = sql.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/--[^\n]*/g, " ").replace(/;\s*$/, "");
|
|
638
|
+
if (stripped.includes(";")) return false;
|
|
639
|
+
if (/^\s*SELECT\b/i.test(stripped)) return true;
|
|
640
|
+
if (/^\s*EXPLAIN\b/i.test(stripped)) {
|
|
641
|
+
if (/^\s*EXPLAIN\s+ANALYZE\b/i.test(stripped)) return false;
|
|
642
|
+
const parenMatch = stripped.match(/^\s*EXPLAIN\s*\(([^)]*)\)/i);
|
|
643
|
+
if (parenMatch && /\bANALYZE\b/i.test(parenMatch[1])) return false;
|
|
644
|
+
return true;
|
|
645
|
+
}
|
|
646
|
+
return false;
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Fetch a project's remote PostgreSQL connection string from the platform.
|
|
650
|
+
* Exits with a friendly message when the URL has never been stored (404);
|
|
651
|
+
* other errors propagate so the caller's top-level handler can report them.
|
|
652
|
+
*/
|
|
653
|
+
async function fetchRemoteDatabaseUrl(client, projectId) {
|
|
654
|
+
try {
|
|
655
|
+
return (await client.getDatabaseUrl(projectId)).url;
|
|
656
|
+
} catch (err) {
|
|
657
|
+
if (err instanceof PlatformApiError && err.status === 404) {
|
|
658
|
+
log.error("This project's database URL isn't stored on the platform yet. Run `bwf db set-url` once to populate it, then retry.");
|
|
659
|
+
process.exit(1);
|
|
660
|
+
}
|
|
661
|
+
throw err;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
async function executeExternalRemoteSql(dialect, dbUrl, sql) {
|
|
665
|
+
if (dialect === "postgresql") {
|
|
666
|
+
const { Client } = await import("pg");
|
|
667
|
+
const pgClient = new Client({ connectionString: dbUrl });
|
|
668
|
+
await pgClient.connect();
|
|
669
|
+
try {
|
|
670
|
+
const result = await pgClient.query(sql);
|
|
671
|
+
if (result.rows && result.rows.length > 0) printTable(result.rows);
|
|
672
|
+
} finally {
|
|
673
|
+
await pgClient.end();
|
|
674
|
+
}
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
const { createConnection } = await import("mysql2/promise");
|
|
678
|
+
const mySqlClient = await createConnection({
|
|
679
|
+
uri: dbUrl,
|
|
680
|
+
multipleStatements: true
|
|
681
|
+
});
|
|
682
|
+
try {
|
|
683
|
+
const [rows] = await mySqlClient.query(sql);
|
|
684
|
+
if (Array.isArray(rows) && rows.length > 0) printTable(rows);
|
|
685
|
+
} finally {
|
|
686
|
+
await mySqlClient.end();
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Prompt the user to confirm a destructive remote query when running in a TTY.
|
|
691
|
+
* Returns true if execution should proceed, false if it was cancelled.
|
|
692
|
+
*/
|
|
693
|
+
async function confirmDestructiveRemote(sql) {
|
|
694
|
+
if (isSafeStatement(sql)) return true;
|
|
695
|
+
if (!process.stdin.isTTY) return true;
|
|
696
|
+
const ok = await confirm({ message: "This will run against your deployed database. Continue?" });
|
|
697
|
+
if (isCancel(ok) || !ok) return false;
|
|
698
|
+
return true;
|
|
699
|
+
}
|
|
700
|
+
async function runExecute(root, command, file, dialect, remote) {
|
|
701
|
+
if (remote) {
|
|
702
|
+
const directCloudflare = readDeploymentPlatform(root) === "cloudflare";
|
|
703
|
+
const sql = file ? readFileSync(resolve(root, file), "utf-8") : command;
|
|
704
|
+
if (directCloudflare) {
|
|
705
|
+
if (!await confirmDestructiveRemote(sql)) {
|
|
706
|
+
log.info("Cancelled.");
|
|
707
|
+
process.exit(0);
|
|
708
|
+
}
|
|
709
|
+
if (dialect === "sqlite") {
|
|
710
|
+
const { executeCloudflareD1Sql, resolveCloudflareD1Context } = await import("./cloudflare-operations-C3Uu0Emj.mjs");
|
|
711
|
+
const rows = await executeCloudflareD1Sql(resolveCloudflareD1Context(root, configuredD1Binding(root)), sql);
|
|
712
|
+
if (rows.length > 0) printTable(rows);
|
|
713
|
+
} else {
|
|
714
|
+
const dbUrl = process.env.DATABASE_URL;
|
|
715
|
+
if (!dbUrl) {
|
|
716
|
+
log.error("DATABASE_URL is required in the shell for a direct Cloudflare remote database command.");
|
|
717
|
+
process.exit(1);
|
|
718
|
+
}
|
|
719
|
+
await executeExternalRemoteSql(dialect, dbUrl, sql);
|
|
720
|
+
}
|
|
721
|
+
printSuccess("SQL executed successfully.");
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
const token = getToken(root);
|
|
725
|
+
if (!token) {
|
|
726
|
+
log.error("Not logged in. Run `bwf account login` first.");
|
|
727
|
+
process.exit(1);
|
|
728
|
+
}
|
|
729
|
+
const projectConfig = readProjectConfig(root);
|
|
730
|
+
if (!projectConfig) {
|
|
731
|
+
log.error("No project linked. Run `bwf deploy` first or link a project.");
|
|
732
|
+
process.exit(1);
|
|
733
|
+
}
|
|
734
|
+
if (!await confirmDestructiveRemote(sql)) {
|
|
735
|
+
log.info("Cancelled.");
|
|
736
|
+
process.exit(0);
|
|
737
|
+
}
|
|
738
|
+
if (dialect !== "sqlite") {
|
|
739
|
+
await executeExternalRemoteSql(dialect, await fetchRemoteDatabaseUrl(new PlatformClient(token, { root }), projectConfig.projectId), sql);
|
|
740
|
+
printSuccess("SQL executed successfully.");
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
const platformClient = new PlatformClient(token, { root });
|
|
744
|
+
const configuredBinding = configuredD1Binding(root);
|
|
745
|
+
let binding = configuredBinding;
|
|
746
|
+
try {
|
|
747
|
+
const d1Bindings = (await platformClient.getResources(projectConfig.projectId)).filter((r) => r.type === "d1").map((r) => r.binding_name);
|
|
748
|
+
if (!d1Bindings.includes(configuredBinding) && d1Bindings.length === 1) binding = d1Bindings[0];
|
|
749
|
+
} catch {}
|
|
750
|
+
const proxyUrl = getProxyUrl(root);
|
|
751
|
+
ensurePlatformProxyAccess(platformClient.apiUrl, proxyUrl);
|
|
752
|
+
const capturedAccessHeaders = cfAccessHeaders(process.env, proxyUrl);
|
|
753
|
+
const requestProxy = () => {
|
|
754
|
+
const currentAccessHeaders = cfAccessHeaders(process.env, proxyUrl);
|
|
755
|
+
const accessHeaders = Object.keys(currentAccessHeaders).length > 0 ? currentAccessHeaders : capturedAccessHeaders;
|
|
756
|
+
return {
|
|
757
|
+
accessHeaders,
|
|
758
|
+
response: fetch(`${proxyUrl}/d1/query`, {
|
|
759
|
+
method: "POST",
|
|
760
|
+
headers: {
|
|
761
|
+
Authorization: `Bearer ${token}`,
|
|
762
|
+
"Content-Type": "application/json",
|
|
763
|
+
...accessHeaders
|
|
764
|
+
},
|
|
765
|
+
body: JSON.stringify({
|
|
766
|
+
projectId: projectConfig.projectId,
|
|
767
|
+
binding,
|
|
768
|
+
sql,
|
|
769
|
+
params: [],
|
|
770
|
+
method: "all"
|
|
771
|
+
}),
|
|
772
|
+
redirect: "manual"
|
|
773
|
+
})
|
|
774
|
+
};
|
|
775
|
+
};
|
|
776
|
+
const first = requestProxy();
|
|
777
|
+
let res = await first.response;
|
|
778
|
+
if (isCloudflareAccessChallenge(res) && !first.accessHeaders["CF-Access-Client-Id"]) {
|
|
779
|
+
await res.body?.cancel();
|
|
780
|
+
ensurePlatformAccessToken(proxyUrl, true, false, first.accessHeaders["cf-access-token"]);
|
|
781
|
+
res = await requestProxy().response;
|
|
782
|
+
}
|
|
783
|
+
if (!res.ok) {
|
|
784
|
+
const text = await res.text().catch(() => res.statusText);
|
|
785
|
+
log.error(`db: Proxy request failed with ${res.status}: '${text}'.`);
|
|
786
|
+
process.exit(1);
|
|
787
|
+
}
|
|
788
|
+
const rows = (await res.json()).results ?? [];
|
|
789
|
+
if (rows.length > 0) printTable(rows);
|
|
790
|
+
printSuccess("SQL executed successfully.");
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
if (dialect === "postgresql") {
|
|
794
|
+
const sql = file ? readFileSync(resolve(root, file), "utf-8") : command;
|
|
795
|
+
await withPgClient(root, async (client) => {
|
|
796
|
+
const result = await client.query(sql);
|
|
797
|
+
if (result.rows && result.rows.length > 0) printTable(result.rows);
|
|
798
|
+
});
|
|
799
|
+
printSuccess("SQL executed successfully.");
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
if (dialect === "mysql") {
|
|
803
|
+
const sql = file ? readFileSync(resolve(root, file), "utf-8") : command;
|
|
804
|
+
await withMySqlClient(root, async (client) => {
|
|
805
|
+
const rows = await client.query(sql);
|
|
806
|
+
if (rows.length > 0) printTable(rows);
|
|
807
|
+
});
|
|
808
|
+
printSuccess("SQL executed successfully.");
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
const { openSqliteDatabase } = await import("./runner-CUNtS5x7.mjs");
|
|
812
|
+
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
813
|
+
if (!existsSync(dbPath)) {
|
|
814
|
+
log.error("No local database found. Start the dev server first.");
|
|
815
|
+
process.exit(1);
|
|
816
|
+
}
|
|
817
|
+
const sql = file ? readFileSync(resolve(root, file), "utf-8") : command;
|
|
818
|
+
const db = await openSqliteDatabase(dbPath);
|
|
819
|
+
try {
|
|
820
|
+
const trimmed = sql.trimStart();
|
|
821
|
+
if (/^SELECT\b/i.test(trimmed)) {
|
|
822
|
+
const rows = db.prepare(sql).all();
|
|
823
|
+
if (rows.length === 0) log.info("No rows returned.");
|
|
824
|
+
else printTable(rows);
|
|
825
|
+
} else db.exec(sql);
|
|
826
|
+
} finally {
|
|
827
|
+
db.close();
|
|
828
|
+
}
|
|
829
|
+
printSuccess("SQL executed successfully.");
|
|
830
|
+
}
|
|
831
|
+
function printTable(rows) {
|
|
832
|
+
const cols = Object.keys(rows[0]);
|
|
833
|
+
const widths = cols.map((col) => {
|
|
834
|
+
let max = col.length;
|
|
835
|
+
for (const row of rows) {
|
|
836
|
+
const len = String(row[col] ?? "NULL").length;
|
|
837
|
+
if (len > max) max = len;
|
|
838
|
+
}
|
|
839
|
+
return max;
|
|
840
|
+
});
|
|
841
|
+
const lines = [cols.map((col, columnIndex) => col.padEnd(widths[columnIndex])).join(" "), widths.map((width) => "─".repeat(width)).join("──")];
|
|
842
|
+
for (const row of rows) lines.push(cols.map((col, columnIndex) => String(row[col] ?? "NULL").padEnd(widths[columnIndex])).join(" "));
|
|
843
|
+
console.log(lines.join("\n"));
|
|
844
|
+
}
|
|
845
|
+
async function runMigrate(root, dialect, remote) {
|
|
846
|
+
const paths = readProjectPaths(root);
|
|
847
|
+
const migrationsDir = paths.migrationsDir;
|
|
848
|
+
const rawMigrations = collectMigrations(migrationsDir);
|
|
849
|
+
try {
|
|
850
|
+
assertJournalCoherence(migrationsDir, rawMigrations, paths.sourceRelative);
|
|
851
|
+
} catch (err) {
|
|
852
|
+
log.error(getErrorMessage(err));
|
|
853
|
+
process.exit(1);
|
|
854
|
+
}
|
|
855
|
+
if (remote) {
|
|
856
|
+
const deploymentPlatform = readDeploymentPlatform(root);
|
|
857
|
+
if (dialect !== "sqlite") {
|
|
858
|
+
if (deploymentPlatform !== "cloudflare") {
|
|
859
|
+
log.error(`db: \`bwf db migrate --remote\` is only supported for D1 projects. ${dialect === "mysql" ? "MySQL" : "PostgreSQL"} remote migrations run during \`bwf deploy\` through the project Hyperdrive binding.`);
|
|
860
|
+
process.exit(1);
|
|
861
|
+
}
|
|
862
|
+
if (rawMigrations.length === 0) {
|
|
863
|
+
log.info(`No migration files found in ${paths.sourceRelative("db/migrations")}/`);
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
const databaseUrl = process.env.DATABASE_URL;
|
|
867
|
+
if (!databaseUrl) {
|
|
868
|
+
log.error("DATABASE_URL is required in the shell for a direct Cloudflare remote database command.");
|
|
869
|
+
process.exit(1);
|
|
870
|
+
}
|
|
871
|
+
try {
|
|
872
|
+
let appliedNames;
|
|
873
|
+
let applyMigrations;
|
|
874
|
+
if (dialect === "postgresql") {
|
|
875
|
+
const { getPgAppliedMigrations, runPgMigrations } = await import("./runner-pg-2pjltt0t.mjs");
|
|
876
|
+
appliedNames = await getPgAppliedMigrations(databaseUrl);
|
|
877
|
+
applyMigrations = () => runPgMigrations(migrationsDir, databaseUrl);
|
|
878
|
+
} else {
|
|
879
|
+
const { getMySqlAppliedMigrations, runMySqlMigrations } = await import("./runner-mysql-DrMKw203.mjs");
|
|
880
|
+
appliedNames = await getMySqlAppliedMigrations(databaseUrl);
|
|
881
|
+
applyMigrations = () => runMySqlMigrations(migrationsDir, databaseUrl);
|
|
882
|
+
}
|
|
883
|
+
const appliedSet = new Set(appliedNames);
|
|
884
|
+
const pending = rawMigrations.filter((migration) => !appliedSet.has(migration.name));
|
|
885
|
+
if (pending.length === 0) {
|
|
886
|
+
log.info("Remote database is up to date.");
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
validateMigrations(pending);
|
|
890
|
+
const applied = await applyMigrations();
|
|
891
|
+
for (const migration of applied) log.step(migration);
|
|
892
|
+
printSuccess(`Applied ${formatCount(applied.length, "migration")} to remote database.`);
|
|
893
|
+
return;
|
|
894
|
+
} catch (error) {
|
|
895
|
+
log.error(`db: Remote ${dialect} migrations failed — ${getErrorMessage(error)}`);
|
|
896
|
+
process.exit(1);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
if (deploymentPlatform === "cloudflare") {
|
|
900
|
+
if (rawMigrations.length === 0) {
|
|
901
|
+
log.info(`No migration files found in ${paths.sourceRelative("db/migrations")}/`);
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
const { applyCloudflareD1Migrations, readCloudflareD1Migrations, resolveCloudflareD1Context } = await import("./cloudflare-operations-C3Uu0Emj.mjs");
|
|
905
|
+
const binding = configuredD1Binding(root);
|
|
906
|
+
const context = resolveCloudflareD1Context(root, binding);
|
|
907
|
+
const remoteBefore = new Set(await readCloudflareD1Migrations(context));
|
|
908
|
+
const pending = rawMigrations.filter((migration) => !remoteBefore.has(migration.name));
|
|
909
|
+
if (pending.length === 0) {
|
|
910
|
+
log.info("Remote database is up to date.");
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
try {
|
|
914
|
+
validateMigrations(pending);
|
|
915
|
+
} catch (error) {
|
|
916
|
+
log.error(getErrorMessage(error));
|
|
917
|
+
process.exit(1);
|
|
918
|
+
}
|
|
919
|
+
if (!context.migrationsDir) {
|
|
920
|
+
const dir = paths.sourceRelative("db/migrations");
|
|
921
|
+
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.`);
|
|
922
|
+
process.exit(1);
|
|
923
|
+
}
|
|
924
|
+
const { checkWranglerMigrationApplySet, parseRootWranglerConfig } = await import("./deploy-DCZBr7Ey.mjs");
|
|
925
|
+
const applySet = await checkWranglerMigrationApplySet(context.operation.configPath, parseRootWranglerConfig(context.operation.configPath), binding, context.migrationsDir, rawMigrations, paths.sourceRelative("db/migrations"));
|
|
926
|
+
if (!applySet.ok) {
|
|
927
|
+
log.error(applySet.reason);
|
|
928
|
+
process.exit(1);
|
|
929
|
+
}
|
|
930
|
+
await applyCloudflareD1Migrations(context);
|
|
931
|
+
const remoteAfter = new Set(await readCloudflareD1Migrations(context));
|
|
932
|
+
const unapplied = rawMigrations.filter((migration) => !remoteAfter.has(migration.name));
|
|
933
|
+
if (unapplied.length > 0) {
|
|
934
|
+
log.error(`db: Remote D1 still has unapplied migrations: ${unapplied.map((migration) => migration.name).join(", ")}.`);
|
|
935
|
+
process.exit(1);
|
|
936
|
+
}
|
|
937
|
+
for (const migration of pending) log.step(migration.name);
|
|
938
|
+
printSuccess(`Applied ${formatCount(pending.length, "migration")} to remote database.`);
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
const token = getToken(root);
|
|
942
|
+
if (!token) {
|
|
943
|
+
log.error("Not logged in. Run `bwf account login` first.");
|
|
944
|
+
process.exit(1);
|
|
945
|
+
}
|
|
946
|
+
const config = readProjectConfig(root);
|
|
947
|
+
if (!config) {
|
|
948
|
+
log.error("No project linked. Run `bwf deploy` first or link a project.");
|
|
949
|
+
process.exit(1);
|
|
950
|
+
}
|
|
951
|
+
if (rawMigrations.length === 0) {
|
|
952
|
+
log.info(`No migration files found in ${paths.sourceRelative("db/migrations")}/`);
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
const client = new PlatformClient(token, { root });
|
|
956
|
+
let remoteApplied;
|
|
957
|
+
try {
|
|
958
|
+
const status = await client.getMigrationStatus(config.projectId, dialect);
|
|
959
|
+
remoteApplied = new Set(status.applied.map((m) => m.name));
|
|
960
|
+
} catch (err) {
|
|
961
|
+
log.error(`db: Failed to fetch remote migration status: '${err instanceof Error ? err.message : String(err)}'.`);
|
|
962
|
+
process.exit(1);
|
|
963
|
+
}
|
|
964
|
+
const pendingMigrations = rawMigrations.filter((m) => !remoteApplied.has(m.name));
|
|
965
|
+
if (pendingMigrations.length === 0) {
|
|
966
|
+
log.info("Remote database is up to date.");
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
try {
|
|
970
|
+
validateMigrations(pendingMigrations);
|
|
971
|
+
} catch (err) {
|
|
972
|
+
log.error(getErrorMessage(err));
|
|
973
|
+
process.exit(1);
|
|
974
|
+
}
|
|
975
|
+
const result = await client.applyRemoteMigrations(config.projectId, pendingMigrations);
|
|
976
|
+
if (!result.ok) {
|
|
977
|
+
log.error(result.error ? `db: Remote migration failed: '${result.error}'.` : "db: Remote migration failed.");
|
|
978
|
+
process.exit(1);
|
|
979
|
+
}
|
|
980
|
+
if (result.applied.length === 0) log.info("Remote database is up to date.");
|
|
981
|
+
else for (const name of result.applied) log.step(name);
|
|
982
|
+
if (result.applied.length > 0) printSuccess(`Applied ${formatCount(result.applied.length, "migration")} to remote database.`);
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
if (dialect === "postgresql") {
|
|
986
|
+
const { applyPgMigrations, readPgAppliedMigrations } = await import("./runner-pg-2pjltt0t.mjs");
|
|
987
|
+
const applied = await withPgClient(root, async (client) => {
|
|
988
|
+
const appliedNames = await readPgAppliedMigrations(client).catch(() => []);
|
|
989
|
+
try {
|
|
990
|
+
validatePendingMigrations(rawMigrations, new Set(appliedNames));
|
|
991
|
+
} catch (err) {
|
|
992
|
+
log.error(getErrorMessage(err));
|
|
993
|
+
process.exit(1);
|
|
994
|
+
}
|
|
995
|
+
return applyPgMigrations(client, rawMigrations);
|
|
996
|
+
});
|
|
997
|
+
if (applied.length === 0) log.info("All migrations are up to date.");
|
|
998
|
+
else {
|
|
999
|
+
for (const name of applied) log.step(name);
|
|
1000
|
+
printSuccess(`Applied ${formatCount(applied.length, "migration")}.`);
|
|
1001
|
+
}
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
if (dialect === "mysql") {
|
|
1005
|
+
const { applyMySqlMigrations, readMySqlAppliedMigrations } = await import("./runner-mysql-DrMKw203.mjs");
|
|
1006
|
+
const applied = await withMySqlClient(root, async (client) => {
|
|
1007
|
+
const appliedNames = await readMySqlAppliedMigrations(client).catch(() => []);
|
|
1008
|
+
try {
|
|
1009
|
+
validatePendingMigrations(rawMigrations, new Set(appliedNames));
|
|
1010
|
+
} catch (err) {
|
|
1011
|
+
log.error(getErrorMessage(err));
|
|
1012
|
+
process.exit(1);
|
|
1013
|
+
}
|
|
1014
|
+
return applyMySqlMigrations(client, rawMigrations);
|
|
1015
|
+
});
|
|
1016
|
+
if (applied.length === 0) log.info("All migrations are up to date.");
|
|
1017
|
+
else {
|
|
1018
|
+
for (const name of applied) log.step(name);
|
|
1019
|
+
printSuccess(`Applied ${formatCount(applied.length, "migration")}.`);
|
|
1020
|
+
}
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
const { getAppliedMigrations, runMigrations } = await import("./runner-CUNtS5x7.mjs");
|
|
1024
|
+
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
1025
|
+
try {
|
|
1026
|
+
const existingRows = await getAppliedMigrations(dbPath);
|
|
1027
|
+
validatePendingMigrations(rawMigrations, new Set(existingRows.map((row) => row.name)));
|
|
1028
|
+
} catch (err) {
|
|
1029
|
+
log.error(getErrorMessage(err));
|
|
1030
|
+
process.exit(1);
|
|
1031
|
+
}
|
|
1032
|
+
const applied = await runMigrations(migrationsDir, dbPath, paths.sourceRelative);
|
|
1033
|
+
if (applied.length === 0) log.info("All migrations are up to date.");
|
|
1034
|
+
else {
|
|
1035
|
+
for (const name of applied) log.step(name);
|
|
1036
|
+
log.info(dim("Restart your dev server if it's running."));
|
|
1037
|
+
printSuccess(`Applied ${formatCount(applied.length, "migration")}.`);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
async function runRestore(root, dialect, { target, platform: explicitPlatform, yes }) {
|
|
1041
|
+
const platform = readDeploymentPlatform(root);
|
|
1042
|
+
const directCloudflare = explicitPlatform === "cloudflare" || platform === "cloudflare" || platform === null && !readProjectConfig(root) && await hasDeployedCloudflareDatabase(root);
|
|
1043
|
+
if (dialect !== "sqlite") {
|
|
1044
|
+
log.error("db: `bwf db restore` restores D1 databases only.");
|
|
1045
|
+
process.exit(1);
|
|
1046
|
+
}
|
|
1047
|
+
if (!directCloudflare) {
|
|
1048
|
+
log.error("db: `bwf db restore` restores the D1 database of a direct Cloudflare deploy. After a one-off `bwf deploy --platform cloudflare`, run it with `--platform cloudflare`.");
|
|
1049
|
+
process.exit(1);
|
|
1050
|
+
}
|
|
1051
|
+
const { readCloudflareD1Migrations, resolveCloudflareD1Context, restoreCloudflareD1Database } = await import("./cloudflare-operations-C3Uu0Emj.mjs");
|
|
1052
|
+
const binding = configuredD1Binding(root);
|
|
1053
|
+
const context = resolveCloudflareD1Context(root, binding);
|
|
1054
|
+
const database = `D1 database ${context.migrateToken} (${binding})`;
|
|
1055
|
+
const point = "bookmark" in target ? `bookmark ${target.bookmark}` : target.timestamp;
|
|
1056
|
+
if (!yes) {
|
|
1057
|
+
if (!process.stdin.isTTY) {
|
|
1058
|
+
log.error(`db: Refusing to restore ${database} without confirmation. Re-run with --yes.`);
|
|
1059
|
+
process.exit(1);
|
|
1060
|
+
}
|
|
1061
|
+
const ok = await confirm({
|
|
1062
|
+
message: `This restores ${database} to ${point} and discards every write made after it. Continue?`,
|
|
1063
|
+
initialValue: false
|
|
1064
|
+
});
|
|
1065
|
+
if (isCancel(ok) || !ok) {
|
|
1066
|
+
log.info("Cancelled.");
|
|
1067
|
+
process.exit(0);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
let previousBookmark;
|
|
1071
|
+
try {
|
|
1072
|
+
previousBookmark = await restoreCloudflareD1Database(context, target);
|
|
1073
|
+
} catch (error) {
|
|
1074
|
+
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.`);
|
|
1075
|
+
process.exit(1);
|
|
1076
|
+
}
|
|
1077
|
+
const platformFlag = platform === "cloudflare" ? "" : " --platform cloudflare";
|
|
1078
|
+
if (previousBookmark) log.info(`To undo this restore, run \`bwf db restore${platformFlag} --bookmark=${previousBookmark}\`.`);
|
|
1079
|
+
const paths = readProjectPaths(root);
|
|
1080
|
+
try {
|
|
1081
|
+
const applied = new Set(await readCloudflareD1Migrations(context));
|
|
1082
|
+
const unapplied = collectMigrations(paths.migrationsDir).filter((migration) => !applied.has(migration.name));
|
|
1083
|
+
if (unapplied.length > 0) log.warn(`The remote database does not have these migrations applied: ${unapplied.map((migration) => migration.name).join(", ")}. The next \`bwf deploy${platformFlag}\` applies them. Fix or remove a migration that caused the problem before you deploy.`);
|
|
1084
|
+
} catch (error) {
|
|
1085
|
+
log.warn(`Could not read the applied migrations after the restore: ${getErrorMessage(error)}. ` + (platformFlag ? `The next \`bwf deploy${platformFlag}\` applies any migration the restore rewound.` : "Run `bwf db status` to check them."));
|
|
1086
|
+
}
|
|
1087
|
+
printSuccess(`Restored ${database} to ${point}.`);
|
|
1088
|
+
}
|
|
1089
|
+
async function runStudio(root, dialect, remote) {
|
|
1090
|
+
if (remote) {
|
|
1091
|
+
if (dialect === "sqlite") {
|
|
1092
|
+
log.error("Remote Studio supports PostgreSQL and MySQL databases. For D1, use `bwf db execute --remote` to query the deployed database.");
|
|
1093
|
+
process.exit(1);
|
|
1094
|
+
}
|
|
1095
|
+
let dbUrl;
|
|
1096
|
+
if (readDeploymentPlatform(root) === "cloudflare") {
|
|
1097
|
+
dbUrl = process.env.DATABASE_URL ?? "";
|
|
1098
|
+
if (!dbUrl) {
|
|
1099
|
+
log.error("DATABASE_URL is required in the shell for direct Cloudflare remote Studio.");
|
|
1100
|
+
process.exit(1);
|
|
1101
|
+
}
|
|
1102
|
+
} else {
|
|
1103
|
+
const token = getToken(root);
|
|
1104
|
+
if (!token) {
|
|
1105
|
+
log.error("Not logged in. Run `bwf account login` first.");
|
|
1106
|
+
process.exit(1);
|
|
1107
|
+
}
|
|
1108
|
+
const projectConfig = readProjectConfig(root);
|
|
1109
|
+
if (!projectConfig) {
|
|
1110
|
+
log.error("No project linked. Run `bwf deploy` first or link a project.");
|
|
1111
|
+
process.exit(1);
|
|
1112
|
+
}
|
|
1113
|
+
dbUrl = await fetchRemoteDatabaseUrl(new PlatformClient(token, { root }), projectConfig.projectId);
|
|
1114
|
+
}
|
|
1115
|
+
log.info("Opening Drizzle Studio (remote)...");
|
|
1116
|
+
await runDrizzleKitWithDatabaseUrl(root, dbUrl, dialect, "studio");
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
if (dialect !== "sqlite") {
|
|
1120
|
+
const url = getLocalDatabaseUrl(root, dialect);
|
|
1121
|
+
log.info("Opening Drizzle Studio...");
|
|
1122
|
+
await runDrizzleKitWithDatabaseUrl(root, url, dialect, "studio");
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
const { writeDrizzleConfig } = await import("./config-D5G-Tx6o.mjs");
|
|
1126
|
+
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
1127
|
+
if (!existsSync(dbPath)) {
|
|
1128
|
+
log.error("No local database found. Start the dev server first.");
|
|
1129
|
+
process.exit(1);
|
|
1130
|
+
}
|
|
1131
|
+
const configPath = writeDrizzleConfig(root, dbPath);
|
|
1132
|
+
log.info("Opening Drizzle Studio...");
|
|
1133
|
+
try {
|
|
1134
|
+
runDrizzleKit(root, [
|
|
1135
|
+
"studio",
|
|
1136
|
+
"--config",
|
|
1137
|
+
configPath
|
|
1138
|
+
]);
|
|
1139
|
+
} catch {
|
|
1140
|
+
process.exit(1);
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
/** A direct Cloudflare deploy records its D1 or Hyperdrive id in the checked-in Cloudflare config. */
|
|
1144
|
+
async function hasDeployedCloudflareDatabase(root) {
|
|
1145
|
+
const { readRootWranglerConfig } = await import("./wrangler-Rr9_76DQ.mjs");
|
|
1146
|
+
const { isRealD1Id, isRealHyperdriveId } = await import("./provision-DGlFJ3T9.mjs");
|
|
1147
|
+
const config = readRootWranglerConfig(root)?.config;
|
|
1148
|
+
const entries = (key) => {
|
|
1149
|
+
const value = config?.[key];
|
|
1150
|
+
return Array.isArray(value) ? value.filter((entry) => !!entry && typeof entry === "object") : [];
|
|
1151
|
+
};
|
|
1152
|
+
return entries("d1_databases").some((entry) => isRealD1Id(entry.database_id)) || entries("hyperdrive").some((entry) => isRealHyperdriveId(entry.id));
|
|
1153
|
+
}
|
|
1154
|
+
async function runRenameMigrations(root, dialect) {
|
|
1155
|
+
const paths = readProjectPaths(root);
|
|
1156
|
+
const migrationsDir = paths.migrationsDir;
|
|
1157
|
+
const dir = paths.sourceRelative("db/migrations");
|
|
1158
|
+
if (!existsSync(migrationsDir)) {
|
|
1159
|
+
log.info("No migrations directory found.");
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
const currentMigrations = collectMigrations(migrationsDir);
|
|
1163
|
+
try {
|
|
1164
|
+
assertJournalCoherence(migrationsDir, currentMigrations, paths.sourceRelative);
|
|
1165
|
+
} catch (err) {
|
|
1166
|
+
log.error(getErrorMessage(err));
|
|
1167
|
+
process.exit(1);
|
|
1168
|
+
}
|
|
1169
|
+
if (existsSync(join(migrationsDir, "migrations.js"))) {
|
|
1170
|
+
log.error(`This project uses Drizzle's bundled migration format (${dir}/migrations.js).\n\`bwf db rename-migrations\` cannot rename migrations in bundled mode because
|
|
1171
|
+
\`migrations.js\` contains static imports of the SQL files by filename.
|
|
1172
|
+
|
|
1173
|
+
Delete ${dir}/migrations.js and re-run \`bwf db generate\` to migrate away\nfrom bundled mode, then retry \`bwf db rename-migrations\`.`);
|
|
1174
|
+
process.exit(1);
|
|
1175
|
+
}
|
|
1176
|
+
const files = readdirSync(migrationsDir).filter((f) => f.endsWith(".sql") && f !== "seed.sql").sort();
|
|
1177
|
+
const oldStyleFiles = files.filter((f) => /^\d{1,4}_/.test(f));
|
|
1178
|
+
if (oldStyleFiles.length === 0) {
|
|
1179
|
+
log.info("No migrations with numeric prefixes found. Nothing to rename.");
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
const platform = readDeploymentPlatform(root);
|
|
1183
|
+
const config = readProjectConfig(root);
|
|
1184
|
+
if (platform === "cloudflare" || !config && platform !== "nosam" && await hasDeployedCloudflareDatabase(root)) {
|
|
1185
|
+
log.error("`bwf db rename-migrations` does not support direct Cloudflare deploys.\nbwf 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.");
|
|
1186
|
+
process.exit(1);
|
|
1187
|
+
}
|
|
1188
|
+
if (platform === "nosam" && !config) {
|
|
1189
|
+
log.error("This project deploys to bwf but is not linked, so bwf cannot rename the migration records in its deployed database.\nRun `bwf project link`, then run `bwf db rename-migrations` again.");
|
|
1190
|
+
process.exit(1);
|
|
1191
|
+
}
|
|
1192
|
+
const timestampFiles = files.filter((f) => /^\d{14}_/.test(f));
|
|
1193
|
+
let baseTime;
|
|
1194
|
+
if (timestampFiles.length > 0) {
|
|
1195
|
+
const earliest = timestampFiles[0].slice(0, 14);
|
|
1196
|
+
const year = +earliest.slice(0, 4);
|
|
1197
|
+
const monthIndex = +earliest.slice(4, 6) - 1;
|
|
1198
|
+
const day = +earliest.slice(6, 8);
|
|
1199
|
+
const hour = +earliest.slice(8, 10);
|
|
1200
|
+
const minute = +earliest.slice(10, 12);
|
|
1201
|
+
const second = +earliest.slice(12, 14);
|
|
1202
|
+
baseTime = new Date(Date.UTC(year, monthIndex, day, hour, minute, second - oldStyleFiles.length));
|
|
1203
|
+
} else baseTime = /* @__PURE__ */ new Date(Date.now() - oldStyleFiles.length * 1e3);
|
|
1204
|
+
const renames = [];
|
|
1205
|
+
for (let fileIndex = 0; fileIndex < oldStyleFiles.length; fileIndex++) {
|
|
1206
|
+
const oldName = oldStyleFiles[fileIndex];
|
|
1207
|
+
const description = oldName.replace(/^\d+_/, "");
|
|
1208
|
+
const ts = new Date(baseTime.getTime() + fileIndex * 1e3);
|
|
1209
|
+
const newName = `${formatTimestamp(ts)}_${description}`;
|
|
1210
|
+
renames.push({
|
|
1211
|
+
from: oldName,
|
|
1212
|
+
to: newName
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
const metaDir = join(migrationsDir, "meta");
|
|
1216
|
+
const journalPath = join(metaDir, "_journal.json");
|
|
1217
|
+
const originalJournalBytes = existsSync(journalPath) ? readFileSync(journalPath) : null;
|
|
1218
|
+
const journal = readJournal(migrationsDir, paths.sourceRelative);
|
|
1219
|
+
const snapshotPrefix = (tag) => tag.split("_")[0];
|
|
1220
|
+
const snapshotPathFor = (tag) => join(metaDir, `${snapshotPrefix(tag)}_snapshot.json`);
|
|
1221
|
+
if (journal && journal.entries.length > 0) {
|
|
1222
|
+
const missingSnapshots = [];
|
|
1223
|
+
for (const { from } of renames) {
|
|
1224
|
+
const fromTag = stripSqlExt(from);
|
|
1225
|
+
const snapshotFrom = snapshotPathFor(fromTag);
|
|
1226
|
+
if (!existsSync(snapshotFrom)) missingSnapshots.push(`meta/${snapshotPrefix(fromTag)}_snapshot.json`);
|
|
1227
|
+
}
|
|
1228
|
+
if (missingSnapshots.length > 0) {
|
|
1229
|
+
log.error("db: Cannot rename migrations because one or more Drizzle snapshot files are missing:");
|
|
1230
|
+
for (const p of missingSnapshots) log.error(` - ${dir}/${p}`);
|
|
1231
|
+
log.error("\nRestore the missing snapshot(s) from version control, or reset the migration directory with `bwf db generate`, then retry.");
|
|
1232
|
+
process.exit(1);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
const token = getToken(root);
|
|
1236
|
+
let remoteRenamed = false;
|
|
1237
|
+
if (config && !token) {
|
|
1238
|
+
log.error("Project is linked but you are not logged in.\nRun `bwf account login` first so remote migration records can be updated.");
|
|
1239
|
+
process.exit(1);
|
|
1240
|
+
}
|
|
1241
|
+
if (token && config) try {
|
|
1242
|
+
await new PlatformClient(token, { root }).renameMigrations(config.projectId, renames);
|
|
1243
|
+
remoteRenamed = true;
|
|
1244
|
+
log.info("Remote migration records updated.");
|
|
1245
|
+
} catch (err) {
|
|
1246
|
+
log.error("db: Failed to update remote migration records. No local changes were made.\nFix the connection and run `bwf db rename-migrations` again.");
|
|
1247
|
+
log.error(String(err));
|
|
1248
|
+
process.exit(1);
|
|
1249
|
+
}
|
|
1250
|
+
let journalRewritten = false;
|
|
1251
|
+
const renamed = [];
|
|
1252
|
+
const renamedSnapshots = [];
|
|
1253
|
+
const rollback = async (message, err) => {
|
|
1254
|
+
for (const { from, to } of renamedSnapshots) try {
|
|
1255
|
+
renameSync(to, from);
|
|
1256
|
+
} catch (error) {
|
|
1257
|
+
log.warn(`db: Could not reverse snapshot rename for '${from}'. The meta/ directory may be in a partial state.`);
|
|
1258
|
+
log.warn(String(error));
|
|
1259
|
+
}
|
|
1260
|
+
for (const { from, to } of renamed) try {
|
|
1261
|
+
renameSync(join(migrationsDir, to), join(migrationsDir, from));
|
|
1262
|
+
} catch {}
|
|
1263
|
+
if (journalRewritten && originalJournalBytes !== null) try {
|
|
1264
|
+
writeFileSync(journalPath, originalJournalBytes);
|
|
1265
|
+
} catch (error) {
|
|
1266
|
+
log.warn(`Could not restore ${dir}/meta/_journal.json after rollback. The journal may be in a partial state.
|
|
1267
|
+
Regenerate it with \`bwf db generate\`, or restore it from version control.`);
|
|
1268
|
+
log.warn(String(error));
|
|
1269
|
+
}
|
|
1270
|
+
if (remoteRenamed && token && config) try {
|
|
1271
|
+
const client = new PlatformClient(token, { root });
|
|
1272
|
+
const reversed = renames.map(({ from, to }) => ({
|
|
1273
|
+
from: to,
|
|
1274
|
+
to: from
|
|
1275
|
+
}));
|
|
1276
|
+
await client.renameMigrations(config.projectId, reversed);
|
|
1277
|
+
} catch {
|
|
1278
|
+
log.warn("db: Could not reverse remote rename. Run `bwf deploy` to sync remote records.");
|
|
1279
|
+
}
|
|
1280
|
+
log.error(message);
|
|
1281
|
+
log.error(String(err));
|
|
1282
|
+
process.exit(1);
|
|
1283
|
+
};
|
|
1284
|
+
try {
|
|
1285
|
+
for (const { from, to } of renames) {
|
|
1286
|
+
renameSync(join(migrationsDir, from), join(migrationsDir, to));
|
|
1287
|
+
renamed.push({
|
|
1288
|
+
from,
|
|
1289
|
+
to
|
|
1290
|
+
});
|
|
1291
|
+
log.step(`${from} → ${to}`);
|
|
1292
|
+
const snapshotFrom = snapshotPathFor(stripSqlExt(from));
|
|
1293
|
+
const snapshotTo = snapshotPathFor(stripSqlExt(to));
|
|
1294
|
+
if (existsSync(snapshotFrom)) {
|
|
1295
|
+
renameSync(snapshotFrom, snapshotTo);
|
|
1296
|
+
renamedSnapshots.push({
|
|
1297
|
+
from: snapshotFrom,
|
|
1298
|
+
to: snapshotTo
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
} catch (err) {
|
|
1303
|
+
await rollback("db: Failed to rename migration files. All changes have been reverted.", err);
|
|
1304
|
+
}
|
|
1305
|
+
if (journal) try {
|
|
1306
|
+
const current = readJournal(migrationsDir, paths.sourceRelative);
|
|
1307
|
+
if (!current) throw new Error(`db: ${dir}/meta/_journal.json disappeared mid-run. File renames will be reverted.`);
|
|
1308
|
+
const renameMap = /* @__PURE__ */ new Map();
|
|
1309
|
+
for (const { from, to } of renames) renameMap.set(stripSqlExt(from), stripSqlExt(to));
|
|
1310
|
+
const updatedEntries = current.entries.map((entry) => {
|
|
1311
|
+
const next = renameMap.get(entry.tag);
|
|
1312
|
+
return next ? {
|
|
1313
|
+
...entry,
|
|
1314
|
+
tag: next
|
|
1315
|
+
} : entry;
|
|
1316
|
+
});
|
|
1317
|
+
journalRewritten = true;
|
|
1318
|
+
writeJournal(migrationsDir, {
|
|
1319
|
+
version: current.version,
|
|
1320
|
+
dialect: current.dialect,
|
|
1321
|
+
entries: updatedEntries
|
|
1322
|
+
});
|
|
1323
|
+
} catch (err) {
|
|
1324
|
+
await rollback(`db: Failed to update ${dir}/meta/_journal.json. File renames have been reverted.`, err);
|
|
1325
|
+
}
|
|
1326
|
+
if (dialect === "postgresql") try {
|
|
1327
|
+
await withPgClient(root, async (client) => {
|
|
1328
|
+
if ((await client.query(`SELECT 1 FROM information_schema.tables WHERE table_name = '_void_migrations' LIMIT 1`)).rows.length === 0) return;
|
|
1329
|
+
await client.query("BEGIN");
|
|
1330
|
+
try {
|
|
1331
|
+
for (const { from, to } of renames) await client.query("UPDATE _void_migrations SET name = $1 WHERE name = $2", [to, from]);
|
|
1332
|
+
await client.query("COMMIT");
|
|
1333
|
+
} catch (err) {
|
|
1334
|
+
await client.query("ROLLBACK");
|
|
1335
|
+
throw err;
|
|
1336
|
+
}
|
|
1337
|
+
});
|
|
1338
|
+
} catch (err) {
|
|
1339
|
+
await rollback("db: Failed to update PostgreSQL tracking table. File renames have been reverted.\nFix the database connection and run `bwf db rename-migrations` again.", err);
|
|
1340
|
+
}
|
|
1341
|
+
else if (dialect === "mysql") try {
|
|
1342
|
+
await withMySqlClient(root, async (client) => {
|
|
1343
|
+
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;
|
|
1344
|
+
await client.query("START TRANSACTION");
|
|
1345
|
+
try {
|
|
1346
|
+
for (const { from, to } of renames) await client.query("UPDATE `_void_migrations` SET `name` = ? WHERE `name` = ?", [to, from]);
|
|
1347
|
+
await client.query("COMMIT");
|
|
1348
|
+
} catch (err) {
|
|
1349
|
+
await client.query("ROLLBACK").catch(() => {});
|
|
1350
|
+
throw err;
|
|
1351
|
+
}
|
|
1352
|
+
});
|
|
1353
|
+
} catch (err) {
|
|
1354
|
+
await rollback("db: Failed to update MySQL tracking table. File renames have been reverted.\nFix the database connection and run `bwf db rename-migrations` again.", err);
|
|
1355
|
+
}
|
|
1356
|
+
else {
|
|
1357
|
+
const { openSqliteDatabase } = await import("./runner-CUNtS5x7.mjs");
|
|
1358
|
+
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
1359
|
+
if (existsSync(dbPath)) try {
|
|
1360
|
+
const db = await openSqliteDatabase(dbPath);
|
|
1361
|
+
try {
|
|
1362
|
+
const hasNew = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='_void_migrations'").get();
|
|
1363
|
+
const hasLegacy = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='_migrations'").get();
|
|
1364
|
+
const tableName = hasNew ? "_void_migrations" : hasLegacy ? "_migrations" : null;
|
|
1365
|
+
if (tableName) {
|
|
1366
|
+
const updateStmt = db.prepare(`UPDATE ${tableName} SET name = ? WHERE name = ?`);
|
|
1367
|
+
db.transaction(() => {
|
|
1368
|
+
for (const { from, to } of renames) updateStmt.run(to, from);
|
|
1369
|
+
})();
|
|
1370
|
+
}
|
|
1371
|
+
} finally {
|
|
1372
|
+
db.close();
|
|
1373
|
+
}
|
|
1374
|
+
} catch (err) {
|
|
1375
|
+
await rollback("db: Failed to update SQLite tracking table. File renames have been reverted.\nFix the database issue and run `bwf db rename-migrations` again.", err);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
printSuccess(`Renamed ${formatCount(renames.length, "migration")} to timestamp format.`);
|
|
1379
|
+
}
|
|
1380
|
+
const INTERNAL_TABLES = /* @__PURE__ */ new Set([
|
|
1381
|
+
"_void_migrations",
|
|
1382
|
+
"_void_migration_attempts",
|
|
1383
|
+
"_void_migration_lock",
|
|
1384
|
+
"_void_migration_fences",
|
|
1385
|
+
"__drizzle_migrations"
|
|
1386
|
+
]);
|
|
1387
|
+
function isInternalTable(name, dialect) {
|
|
1388
|
+
if (INTERNAL_TABLES.has(name)) return true;
|
|
1389
|
+
return dialect === "sqlite" && (name === "_migrations" || name.startsWith("_cf_") || name.startsWith("sqlite_"));
|
|
1390
|
+
}
|
|
1391
|
+
function formatMySqlExportValue(value) {
|
|
1392
|
+
if (value === null || value === void 0) return "NULL";
|
|
1393
|
+
if (typeof value === "number" || typeof value === "bigint") return String(value);
|
|
1394
|
+
if (typeof value === "boolean") return value ? "1" : "0";
|
|
1395
|
+
if (value instanceof Uint8Array) return `X'${Array.from(value, (byte) => byte.toString(16).padStart(2, "0")).join("")}'`;
|
|
1396
|
+
return `'${String(value).replaceAll("\\", "\\\\").replaceAll("'", "''")}'`;
|
|
1397
|
+
}
|
|
1398
|
+
function formatSqliteExportValue(value) {
|
|
1399
|
+
if (value === null) return "NULL";
|
|
1400
|
+
if (value instanceof Uint8Array) return `X'${Array.from(value, (byte) => byte.toString(16).padStart(2, "0")).join("")}'`;
|
|
1401
|
+
if (typeof value === "number" || typeof value === "bigint") return String(value);
|
|
1402
|
+
return `'${String(value).replaceAll("'", "''")}'`;
|
|
1403
|
+
}
|
|
1404
|
+
async function runExport(root, args, dialect) {
|
|
1405
|
+
const errOut = { output: process.stderr };
|
|
1406
|
+
if (dialect === "postgresql") {
|
|
1407
|
+
const parts = [];
|
|
1408
|
+
await withPgClient(root, async (client) => {
|
|
1409
|
+
let tables;
|
|
1410
|
+
if (args.table) {
|
|
1411
|
+
if ((await client.query("SELECT tablename FROM pg_tables WHERE schemaname = 'public' AND tablename = $1", [args.table])).rows.length === 0) {
|
|
1412
|
+
log.error(`db: Table '${args.table}' not found.`, errOut);
|
|
1413
|
+
process.exit(1);
|
|
1414
|
+
}
|
|
1415
|
+
tables = [args.table];
|
|
1416
|
+
} 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));
|
|
1417
|
+
if (!args.noSchema) await assertPgExportableSchema(client, tables, !args.table);
|
|
1418
|
+
const sequences = await exportPgSequences(client, tables, args);
|
|
1419
|
+
parts.push(...sequences.before);
|
|
1420
|
+
for (const table of tables) {
|
|
1421
|
+
const cols = await client.query(`SELECT a.attname AS column_name,
|
|
1422
|
+
pg_catalog.format_type(a.atttypid, a.atttypmod) AS data_type,
|
|
1423
|
+
a.attnotnull AS not_null,
|
|
1424
|
+
pg_get_expr(def.adbin, def.adrelid) AS column_default,
|
|
1425
|
+
a.attidentity AS identity,
|
|
1426
|
+
a.attgenerated AS generated
|
|
1427
|
+
FROM pg_attribute a
|
|
1428
|
+
JOIN pg_class tbl ON tbl.oid = a.attrelid
|
|
1429
|
+
JOIN pg_namespace ns ON ns.oid = tbl.relnamespace
|
|
1430
|
+
LEFT JOIN pg_attrdef def ON def.adrelid = tbl.oid AND def.adnum = a.attnum
|
|
1431
|
+
WHERE ns.nspname = 'public' AND tbl.relname = $1
|
|
1432
|
+
AND a.attnum > 0 AND NOT a.attisdropped
|
|
1433
|
+
ORDER BY a.attnum`, [table]);
|
|
1434
|
+
const names = cols.rows.filter((column) => !column.generated).map((column) => quoteSqlIdentifier(String(column.column_name)));
|
|
1435
|
+
const tableName = `"public".${quoteSqlIdentifier(table)}`;
|
|
1436
|
+
if (!args.noSchema) {
|
|
1437
|
+
const colDefs = cols.rows.map((column) => {
|
|
1438
|
+
let def = ` ${quoteSqlIdentifier(String(column.column_name))} ${String(column.data_type)}`;
|
|
1439
|
+
if (column.generated) def += ` GENERATED ALWAYS AS (${String(column.column_default)}) STORED`;
|
|
1440
|
+
else if (column.identity) def += ` GENERATED ${column.identity === "a" ? "ALWAYS" : "BY DEFAULT"} AS IDENTITY`;
|
|
1441
|
+
else if (column.column_default) def += ` DEFAULT ${String(column.column_default)}`;
|
|
1442
|
+
if (column.not_null) def += " NOT NULL";
|
|
1443
|
+
return def;
|
|
1444
|
+
});
|
|
1445
|
+
parts.push(`CREATE TABLE ${tableName} (\n${colDefs.join(",\n")}\n);`);
|
|
1446
|
+
}
|
|
1447
|
+
if (!args.noData) {
|
|
1448
|
+
const rows = await client.query(`SELECT ${names.map((name) => `${name}::text AS ${name}`).join(", ")} FROM ${tableName}`);
|
|
1449
|
+
const overriding = cols.rows.some((column) => column.identity === "a") ? " OVERRIDING SYSTEM VALUE" : "";
|
|
1450
|
+
for (const row of rows.rows) {
|
|
1451
|
+
const cols = Object.keys(row);
|
|
1452
|
+
const vals = cols.map((column) => {
|
|
1453
|
+
const value = row[column];
|
|
1454
|
+
if (value === null) return "NULL";
|
|
1455
|
+
if (typeof value === "number") return String(value);
|
|
1456
|
+
return `'${String(value).replace(/'/g, "''")}'`;
|
|
1457
|
+
});
|
|
1458
|
+
parts.push(`INSERT INTO ${tableName} (${cols.map(quoteSqlIdentifier).join(", ")})${overriding} VALUES (${vals.join(", ")});`);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
parts.push("");
|
|
1462
|
+
}
|
|
1463
|
+
parts.push(...sequences.after);
|
|
1464
|
+
if (!args.noSchema) parts.push(...await exportPgConstraints(client, tables));
|
|
1465
|
+
});
|
|
1466
|
+
const output = parts.join("\n");
|
|
1467
|
+
if (args.output) {
|
|
1468
|
+
writeFileSync(resolve(root, args.output), output);
|
|
1469
|
+
printSuccess(`Exported to ${args.output}`);
|
|
1470
|
+
} else process.stdout.write(output);
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
if (dialect === "mysql") {
|
|
1474
|
+
const parts = [];
|
|
1475
|
+
const exportTables = async (client) => {
|
|
1476
|
+
let tables;
|
|
1477
|
+
if (args.table) {
|
|
1478
|
+
if ((await client.query("SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ?", [args.table])).length === 0) {
|
|
1479
|
+
log.error(`db: Table '${args.table}' not found.`, errOut);
|
|
1480
|
+
process.exit(1);
|
|
1481
|
+
}
|
|
1482
|
+
tables = [args.table];
|
|
1483
|
+
} 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));
|
|
1484
|
+
await client.query("SET time_zone = '+00:00'");
|
|
1485
|
+
parts.push("SET FOREIGN_KEY_CHECKS = 0;", "SET time_zone = '+00:00';");
|
|
1486
|
+
for (const table of tables) {
|
|
1487
|
+
const escapedTable = table.replaceAll("`", "``");
|
|
1488
|
+
if (!args.noSchema) {
|
|
1489
|
+
const createSql = (await client.query(`SHOW CREATE TABLE \`${escapedTable}\``))[0]?.["Create Table"];
|
|
1490
|
+
if (createSql) parts.push(`${String(createSql)};`);
|
|
1491
|
+
}
|
|
1492
|
+
if (!args.noData) {
|
|
1493
|
+
const rows = await client.query(`SELECT * FROM \`${escapedTable}\``);
|
|
1494
|
+
for (const row of rows) {
|
|
1495
|
+
const columns = Object.keys(row);
|
|
1496
|
+
const values = columns.map((column) => formatMySqlExportValue(row[column]));
|
|
1497
|
+
const names = columns.map((column) => `\`${column.replaceAll("`", "``")}\``);
|
|
1498
|
+
parts.push(`INSERT INTO \`${escapedTable}\` (${names.join(", ")}) VALUES (${values.join(", ")});`);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
parts.push("");
|
|
1502
|
+
}
|
|
1503
|
+
parts.push("SET FOREIGN_KEY_CHECKS = 1;", "");
|
|
1504
|
+
};
|
|
1505
|
+
await withMySqlClient(root, exportTables, { textValues: true });
|
|
1506
|
+
const output = parts.join("\n");
|
|
1507
|
+
if (args.output) {
|
|
1508
|
+
writeFileSync(resolve(root, args.output), output);
|
|
1509
|
+
printSuccess(`Exported to ${args.output}`);
|
|
1510
|
+
} else process.stdout.write(output);
|
|
1511
|
+
return;
|
|
1512
|
+
}
|
|
1513
|
+
const { openSqliteDatabase } = await import("./runner-CUNtS5x7.mjs");
|
|
1514
|
+
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
1515
|
+
if (!existsSync(dbPath)) {
|
|
1516
|
+
log.error("No local database found. Start the dev server first.", errOut);
|
|
1517
|
+
process.exit(1);
|
|
1518
|
+
}
|
|
1519
|
+
const db = await openSqliteDatabase(dbPath, { readonly: true });
|
|
1520
|
+
try {
|
|
1521
|
+
let tables;
|
|
1522
|
+
if (args.table) {
|
|
1523
|
+
if (!db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?").get(args.table)) {
|
|
1524
|
+
log.error(`db: Table '${args.table}' not found.`, errOut);
|
|
1525
|
+
process.exit(1);
|
|
1526
|
+
}
|
|
1527
|
+
tables = [args.table];
|
|
1528
|
+
} 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));
|
|
1529
|
+
const parts = [];
|
|
1530
|
+
for (const table of tables) {
|
|
1531
|
+
if (!args.noSchema) {
|
|
1532
|
+
const row = db.prepare("SELECT sql FROM sqlite_master WHERE type='table' AND name=?").get(table);
|
|
1533
|
+
parts.push(row.sql + ";");
|
|
1534
|
+
}
|
|
1535
|
+
if (!args.noData) {
|
|
1536
|
+
const insertableColumns = new Set(db.prepare(`PRAGMA table_xinfo(${quoteSqlIdentifier(table)})`).all().filter((column) => column.hidden === 0).map((column) => column.name));
|
|
1537
|
+
const rows = db.prepare(`SELECT * FROM ${quoteSqlIdentifier(table)}`).all();
|
|
1538
|
+
for (const row of rows) {
|
|
1539
|
+
const cols = Object.keys(row).filter((column) => insertableColumns.has(column));
|
|
1540
|
+
const vals = cols.map((column) => formatSqliteExportValue(row[column]));
|
|
1541
|
+
parts.push(`INSERT INTO ${quoteSqlIdentifier(table)} (${cols.map(quoteSqlIdentifier).join(", ")}) VALUES (${vals.join(", ")});`);
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
parts.push("");
|
|
1545
|
+
}
|
|
1546
|
+
if (!args.noData && db.prepare("SELECT name FROM sqlite_master WHERE name='sqlite_sequence'").get()) {
|
|
1547
|
+
const sequences = db.prepare("SELECT name, seq FROM sqlite_sequence").all();
|
|
1548
|
+
for (const sequence of sequences) if (tables.includes(sequence.name)) {
|
|
1549
|
+
const name = quoteSqlString(sequence.name);
|
|
1550
|
+
parts.push(`DELETE FROM sqlite_sequence WHERE name = ${name};`);
|
|
1551
|
+
parts.push(`INSERT INTO sqlite_sequence (name, seq) VALUES (${name}, ${sequence.seq});`);
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
if (!args.noSchema) {
|
|
1555
|
+
const schemaObjects = db.prepare("SELECT type, name, tbl_name, sql FROM sqlite_master WHERE type IN ('index','trigger','view') AND sql IS NOT NULL ORDER BY rowid").all();
|
|
1556
|
+
for (const type of [
|
|
1557
|
+
"index",
|
|
1558
|
+
"view",
|
|
1559
|
+
"trigger"
|
|
1560
|
+
]) for (const object of schemaObjects) {
|
|
1561
|
+
if (object.type !== type) continue;
|
|
1562
|
+
if (type === "view") {
|
|
1563
|
+
if (args.table || isInternalTable(object.name, dialect)) continue;
|
|
1564
|
+
} else if (!tables.includes(object.tbl_name)) continue;
|
|
1565
|
+
parts.push(object.sql.trim().replace(/;?$/, ";"));
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
const output = parts.join("\n");
|
|
1569
|
+
if (args.output) {
|
|
1570
|
+
writeFileSync(resolve(root, args.output), output);
|
|
1571
|
+
printSuccess(`Exported to ${args.output}`);
|
|
1572
|
+
} else process.stdout.write(output);
|
|
1573
|
+
} finally {
|
|
1574
|
+
db.close();
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
async function runSetUrl(root, dialect) {
|
|
1578
|
+
if (dialect === "sqlite") {
|
|
1579
|
+
log.error("db: This command is only for PostgreSQL and MySQL projects. Set \"database\" to \"pg\" or \"mysql\" in bwf.config.ts.");
|
|
1580
|
+
process.exit(1);
|
|
1581
|
+
}
|
|
1582
|
+
const token = getToken(root);
|
|
1583
|
+
if (!token) {
|
|
1584
|
+
log.error("No auth token found. Run `bwf account login` first.");
|
|
1585
|
+
process.exit(1);
|
|
1586
|
+
}
|
|
1587
|
+
const projectConfig = readProjectConfig(root);
|
|
1588
|
+
if (!projectConfig) {
|
|
1589
|
+
log.error("No project linked. Run `bwf deploy` first or link a project.");
|
|
1590
|
+
process.exit(1);
|
|
1591
|
+
}
|
|
1592
|
+
const connectionString = await text({
|
|
1593
|
+
message: `Enter your ${dialect === "mysql" ? "MySQL" : "PostgreSQL"} connection string:`,
|
|
1594
|
+
placeholder: dialect === "mysql" ? "mysql://user:pass@host:3306/dbname" : "postgresql://user:pass@host:5432/dbname",
|
|
1595
|
+
validate(value = "") {
|
|
1596
|
+
if (dialect === "mysql") {
|
|
1597
|
+
if (!value.startsWith("mysql://")) return "Connection string must start with \"mysql://\"";
|
|
1598
|
+
} else if (!value.startsWith("postgres://") && !value.startsWith("postgresql://")) return "Connection string must start with \"postgres://\" or \"postgresql://\"";
|
|
1599
|
+
}
|
|
1600
|
+
});
|
|
1601
|
+
if (isCancel(connectionString)) process.exit(0);
|
|
1602
|
+
await new PlatformClient(token, { root }).setDatabaseUrl(projectConfig.projectId, connectionString);
|
|
1603
|
+
printSuccess("Database URL updated.");
|
|
1604
|
+
}
|
|
1605
|
+
function resolveSeedTarget(root, file) {
|
|
1606
|
+
if (file) return toSeedTarget(root, resolve(root, file), file);
|
|
1607
|
+
const paths = readProjectPaths(root);
|
|
1608
|
+
const defaults = DEFAULT_SEED_FILES.map((candidate) => paths.sourceRelative(candidate)).filter((candidate) => existsSync(join(root, candidate)));
|
|
1609
|
+
if (defaults.length === 0) {
|
|
1610
|
+
log.error(`db: No seed file found. Create one of: ${DEFAULT_SEED_FILES.map((candidate) => paths.sourceRelative(candidate)).join(", ")} or pass --file <path>.`);
|
|
1611
|
+
process.exit(1);
|
|
1612
|
+
}
|
|
1613
|
+
if (defaults.length > 1) {
|
|
1614
|
+
log.error(`db: Multiple default seed files found: ${defaults.join(", ")}. Use --file <path> to choose one.`);
|
|
1615
|
+
process.exit(1);
|
|
1616
|
+
}
|
|
1617
|
+
const [seedPath] = defaults;
|
|
1618
|
+
return toSeedTarget(root, join(root, seedPath), seedPath);
|
|
1619
|
+
}
|
|
1620
|
+
function toSeedTarget(root, seedPath, displayPath) {
|
|
1621
|
+
if (!existsSync(seedPath)) {
|
|
1622
|
+
log.error(`db: Seed file '${seedPath}' not found.`);
|
|
1623
|
+
process.exit(1);
|
|
1624
|
+
}
|
|
1625
|
+
const ext = extname(seedPath);
|
|
1626
|
+
const normalizedDisplay = (displayPath ?? relative(root, seedPath)).replaceAll("\\", "/");
|
|
1627
|
+
if (ext === ".sql") return {
|
|
1628
|
+
path: seedPath,
|
|
1629
|
+
displayPath: normalizedDisplay,
|
|
1630
|
+
kind: "sql"
|
|
1631
|
+
};
|
|
1632
|
+
if (MODULE_SEED_EXTENSIONS.has(ext)) return {
|
|
1633
|
+
path: seedPath,
|
|
1634
|
+
displayPath: normalizedDisplay,
|
|
1635
|
+
kind: "module"
|
|
1636
|
+
};
|
|
1637
|
+
log.error(`db: Unsupported seed file '${normalizedDisplay}'. Use .sql, .ts, .mts, .js, or .mjs.`);
|
|
1638
|
+
process.exit(1);
|
|
1639
|
+
}
|
|
1640
|
+
async function runSeedModule(root, seed, dialect) {
|
|
1641
|
+
const schema = await loadSeedSchema(root);
|
|
1642
|
+
const casing = getDatabaseCasing(readConfig(root));
|
|
1643
|
+
if (dialect === "postgresql") {
|
|
1644
|
+
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
1645
|
+
await withPgClient(root, async (client) => {
|
|
1646
|
+
const options = getDrizzleSchemaOptions(schema, casing);
|
|
1647
|
+
const drizzleClient = client;
|
|
1648
|
+
await seed({
|
|
1649
|
+
dialect,
|
|
1650
|
+
db: options ? drizzle(drizzleClient, options) : drizzle(drizzleClient),
|
|
1651
|
+
schema
|
|
1652
|
+
});
|
|
1653
|
+
});
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1656
|
+
if (dialect === "mysql") {
|
|
1657
|
+
const { drizzle } = await import("drizzle-orm/mysql2");
|
|
1658
|
+
const { createConnection } = await import("mysql2/promise");
|
|
1659
|
+
const connection = await createConnection(getLocalDatabaseUrl(root, "mysql"));
|
|
1660
|
+
try {
|
|
1661
|
+
const options = getDrizzleSchemaOptions(schema, casing);
|
|
1662
|
+
await seed({
|
|
1663
|
+
dialect,
|
|
1664
|
+
db: options ? drizzle(connection, {
|
|
1665
|
+
...options,
|
|
1666
|
+
mode: "default"
|
|
1667
|
+
}) : drizzle(connection),
|
|
1668
|
+
schema
|
|
1669
|
+
});
|
|
1670
|
+
} finally {
|
|
1671
|
+
await connection.end();
|
|
1672
|
+
}
|
|
1673
|
+
return;
|
|
1674
|
+
}
|
|
1675
|
+
const { drizzle } = await import("drizzle-orm/better-sqlite3");
|
|
1676
|
+
const { openSqliteDatabase } = await import("./runner-CUNtS5x7.mjs");
|
|
1677
|
+
const { databasePath: dbPath } = getLocalD1Target(root);
|
|
1678
|
+
const sqlite = await openSqliteDatabase(dbPath);
|
|
1679
|
+
try {
|
|
1680
|
+
const options = getDrizzleSchemaOptions(schema, casing);
|
|
1681
|
+
await seed({
|
|
1682
|
+
dialect,
|
|
1683
|
+
db: options ? drizzle(sqlite, options) : drizzle(sqlite),
|
|
1684
|
+
schema
|
|
1685
|
+
});
|
|
1686
|
+
} finally {
|
|
1687
|
+
sqlite.close();
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
async function loadSeedFunction(seedPath) {
|
|
1691
|
+
const mod = await importLocalModule(seedPath);
|
|
1692
|
+
const seed = typeof mod.default === "function" ? mod.default : typeof mod.seed === "function" ? mod.seed : void 0;
|
|
1693
|
+
if (!seed) throw new Error(`db: Seed module '${seedPath}' must export a default function or a named "seed" function.`);
|
|
1694
|
+
return seed;
|
|
1695
|
+
}
|
|
1696
|
+
async function loadSeedSchema(root) {
|
|
1697
|
+
const { discoverSchema } = await import("./discover-EVuydEoM.mjs");
|
|
1698
|
+
const location = discoverSchema(root, readProjectPaths(root));
|
|
1699
|
+
if (!location) return {};
|
|
1700
|
+
if (location.type === "file") {
|
|
1701
|
+
const mod = await importLocalModule(location.path);
|
|
1702
|
+
return Object.fromEntries(Object.entries(mod).filter(([name]) => name !== "default" && name !== "__esModule"));
|
|
1703
|
+
}
|
|
1704
|
+
const files = collectSchemaModuleFiles(location.path);
|
|
1705
|
+
const parts = await Promise.all(files.map((file) => importLocalModule(file)));
|
|
1706
|
+
return Object.assign({}, ...parts.map((mod) => Object.fromEntries(Object.entries(mod).filter(([name]) => name !== "default"))));
|
|
1707
|
+
}
|
|
1708
|
+
function collectSchemaModuleFiles(dir) {
|
|
1709
|
+
const files = [];
|
|
1710
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1711
|
+
const fullPath = join(dir, entry.name);
|
|
1712
|
+
if (entry.isDirectory()) {
|
|
1713
|
+
files.push(...collectSchemaModuleFiles(fullPath));
|
|
1714
|
+
continue;
|
|
1715
|
+
}
|
|
1716
|
+
if (MODULE_SEED_EXTENSIONS.has(extname(entry.name)) && !entry.name.endsWith(".d.ts") && !entry.name.endsWith(".d.mts")) files.push(fullPath);
|
|
1717
|
+
}
|
|
1718
|
+
return files.sort();
|
|
1719
|
+
}
|
|
1720
|
+
async function importLocalModule(modulePath) {
|
|
1721
|
+
return createJiti(import.meta.url, {
|
|
1722
|
+
fsCache: false,
|
|
1723
|
+
moduleCache: false,
|
|
1724
|
+
interopDefault: false
|
|
1725
|
+
}).import(modulePath);
|
|
1726
|
+
}
|
|
1727
|
+
/** The schema and casing that `@builtbyfriends/bwf/db` gives drizzle, or undefined when neither is set. */
|
|
1728
|
+
function getDrizzleSchemaOptions(schema, casing) {
|
|
1729
|
+
const options = {
|
|
1730
|
+
...Object.keys(schema).length > 0 ? { schema } : {},
|
|
1731
|
+
...casing ? { casing } : {}
|
|
1732
|
+
};
|
|
1733
|
+
return Object.keys(options).length > 0 ? options : void 0;
|
|
1734
|
+
}
|
|
1735
|
+
export { runDbCommand };
|