Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ enabled = false
persist = true
head_sampling_rate = 1

[build]
command = "bash migrate.sh"
Comment on lines +59 to +60

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files =="
git ls-files | rg '(^|/)(wrangler\.toml|migrate\.sh|package\.json)$' || true

echo "== wrangler relevant =="
if [ -f wrangler.toml ]; then
  nl -ba wrangler.toml | sed -n '1,120p'
fi

echo "== migrate =="
if [ -f migrate.sh ]; then
  nl -ba migrate.sh | sed -n '1,220p'
fi

echo "== other occurrences =="
rg -n "WRANGLER_COMMAND|migrate\.sh|education_db|CLOUDFLARE_API_TOKEN|wrangler" -S . --glob '!node_modules' --glob '!dist' --glob '!build' || true

Repository: alphaonelabs/learn

Length of output: 257


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate files =="
printf '%s\n' "migrate.sh" "wrangler.toml"

echo "== wrangler.toml lines =="
awk '{printf "%6d  %s\n", NR, $0}' wrangler.toml | sed -n '1,120p'

echo "== migrate.sh lines =="
awk '{printf "%6d  %s\n", NR, $0}' migrate.sh | sed -n '1,220p'

echo "== relevant occurrences =="
grep -RInE "WRANGLER_COMMAND|migrate\.sh|education_db|CLOUDFLARE_API_TOKEN|wrangler|build|command" . --exclude-dir=node_modules --exclude-dir=dist --exclude-dir=build || true

Repository: alphaonelabs/learn

Length of output: 25007


🌐 Web query:

Cloudflare Wrangler custom builds command runs during wrangler dev and deploy WRANGLER_COMMAND

💡 Result:

In Cloudflare Wrangler, you can define a custom build process by adding a [build] section to your wrangler.toml (or wrangler.jsonc) configuration file [1][2][3]. When configured, this custom build command executes as part of the wrangler dev, wrangler deploy, and other lifecycle commands [1][4][3]. To differentiate the execution context within your build script, Wrangler provides the WRANGLER_COMMAND environment variable [1][4]. When your custom build command runs, this variable is automatically set by Wrangler, allowing you to trigger different logic (e.g., development vs. production builds) based on which command initiated the process [1][3]. The possible values for WRANGLER_COMMAND include: - dev: Triggered by wrangler dev [1][3] - deploy: Triggered by wrangler deploy [1][3] - versions upload: Triggered by wrangler versions upload [1][3] - types: Triggered by wrangler types [1][3] Example usage in a shell script: #!/bin/bash if [ "$WRANGLER_COMMAND" = "dev" ]; then echo "Building for development..." # run development build commands else echo "Building for production..." # run production build commands fi Configuration Options: - command (string): The command to run to build your Worker. On Linux and macOS, it executes in sh; on Windows, it uses cmd [1][3]. - cwd (string, optional): The directory where the command is executed [1][3]. - watch_dir (string | string[], optional): The directory or directories to monitor for changes during wrangler dev, which will re-trigger the custom build [1][3].

Citations:


Run remote D1 migrations only for deployments.

[build].command applies during both wrangler dev and wrangler deploy, so a local session with CLOUDFLARE_API_TOKEN can change the remote education_db. Use WRANGLER_COMMAND to run remote migrations only when Wrangler invokes deploy, and fail the build if credentials are missing in that path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@wrangler.toml` around lines 59 - 60, Update the [build].command configuration
so remote D1 migrations run only when WRANGLER_COMMAND indicates deploy, while
preserving local development without migration. In the deploy path, require
CLOUDFLARE_API_TOKEN and fail when it is missing; continue the build command
without remote migration for other Wrangler commands.


[triggers]
crons = ["0 13 * * *"]
Loading