The after_db_updated.sh Script

The hook that rewrites environment-specific values stored in the database, like the site's own URLs, after a database is synced between environments.

after_db_updated.sh runs after a database has been imported from another environment. Its job is to fix up anything that is stored inside the database and is environment-specific, most commonly the site’s own URLs.

When you copy a database between, say, your local machine and production, the rows still contain the source environment’s domain. Without correction the site would generate links (and sometimes redirect) to the wrong host. This script rewrites those values for the destination.

Where it lives

website/script/unix/<platform>/after_db_updated.sh

Optional per platform. Any platform, including a custom blueprint, can add it.

When Waddle runs it

Operation Where it runs Argument
Download remote DB → import locally Locally Local
Upload local DB → import on remote On the remote Production / Stage / Dev
Manual SQL import (with “Sync DB” enabled) Locally Local
The project’s website URL changes in its configuration Locally Local

Contract

Every implementation of this hook — shipped or custom — must follow the same contract, since Waddle invokes it identically regardless of platform. It is called with one argument, the destination environment (Local, Production, Stage, or Dev); the script resolves that to the matching domain and updates the database accordingly.

  • #!/bin/sh -eu, POSIX-compliant, run from the project root.
  • Exit non-zero (with a usage message) on an unknown argument, so a bad call fails loudly instead of silently leaving stale domains in the database.
  • Be idempotent: replace all known source domains with the destination domain so it is safe to run repeatedly, regardless of which environment the dump came from.

How each shipped platform implements it

Platform What it rewrites
WordPress wp search-replace across all tables (handles serialized data)
Magento config:set web/unsecure/base_url + web/secure/base_url, then cache:flush
PrestaShop ps_shop_url + ps_configuration (PS_SHOP_DOMAIN / _SSL) via SQL
phpBB phpbb_config (server_name, server_protocol, cookie_domain, cookie_secure), then cache purge

Adding it to a custom project

Create website/script/unix/blank/after_db_updated.sh or website/script/unix/webstack/after_db_updated.sh, matching whichever blueprint your project was created with. For example, say your app stores its canonical URL in a settings table’s site_url column. The script could look like this:

#!/bin/sh -eu
if [ -f .env ]; then
    set -a
    . ./.env
    set +a
fi

ENV="${1:-}"

case "$ENV" in
    Local)      TARGET_DOMAIN="{{public.website.url}}" ;;
    Production) TARGET_DOMAIN="{{public.remotes.production.domain}}" ;;
    Stage)      TARGET_DOMAIN="{{public.remotes.stage.domain}}" ;;
    Dev)        TARGET_DOMAIN="{{public.remotes.dev.domain}}" ;;
    *)          echo "Usage: $0 <Local|Production|Stage|Dev>" >&2; exit 1 ;;
esac

[ -z "$TARGET_DOMAIN" ] && exit 0

echo "UPDATE settings SET site_url='https://${TARGET_DOMAIN}' WHERE id=1;" \
    | docker compose exec -i db mysql -u "${WADDLE_DB_USER}" -p"${WADDLE_DB_PASSWORD}" \
        "{{public.website.db_name}}"

See WADDLE_DB_USER and WADDLE_DB_PASSWORD for where those credentials come from.

Values stored in config files rather than the database (e.g. a Laravel APP_URL) belong in The after_project_update.sh Script, not here.