From ae221ebf7ab6b7db467a7c9242801188cb1673f4 Mon Sep 17 00:00:00 2001 From: jslocomotor <210083531+jslocomotor@users.noreply.github.com> Date: Thu, 30 Apr 2026 23:15:58 +0200 Subject: [PATCH] feat(migrator): add multi-site support to migration --- docs/02-setup/05-overrides.md | 2 +- overrides/compose.migrator.yaml | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/docs/02-setup/05-overrides.md b/docs/02-setup/05-overrides.md index f10c6045..ee3f64af 100644 --- a/docs/02-setup/05-overrides.md +++ b/docs/02-setup/05-overrides.md @@ -26,7 +26,7 @@ docker compose -f compose.yaml -f overrides/compose.mariadb.yaml -f overrides/co | **Redis** | | | | compose.redis.yaml | Adds Redis service for caching and background job queuing | | | **Services** | | | -| compose.migrator.yaml | Runs a dedicated migration container performing `bench migrate` on a site at every start | Set `SITE_NAME` | +| compose.migrator.yaml | Runs a dedicated migration container performing `bench --site all migrate` on a site at every start | Control via `MIGRATE_SITES` - defaults to true | | **TBD** | **The following overrides are available but lack documentation. If you use them and understand their purpose, please consider contributing to this documentation.** | | | compose.backup-cron.yaml | | | | compose.custom-domain-ssl.yaml | | | diff --git a/overrides/compose.migrator.yaml b/overrides/compose.migrator.yaml index aebc30a8..8a96107f 100644 --- a/overrides/compose.migrator.yaml +++ b/overrides/compose.migrator.yaml @@ -1,5 +1,4 @@ # Provides a service for automated migration of a given site. -# Add SITE_NAME to .env # Compose extension fields of base compose.yaml. See https://github.com/frappe/frappe_docker/blob/main/compose.yaml # Needed for merging compose files. @@ -30,16 +29,16 @@ services: - -c command: - > - if [ -z "$$SITE_NAME" ]; then - echo "[migrator] SITE_NAME is not set"; - exit 1; + if [ "$$MIGRATE_SITES" != "true" ]; then + echo "[migrator] Migration disabled"; + exit 0; fi; - if [ -d "sites/$$SITE_NAME" ]; then - echo "[migrator] Migrating $$SITE_NAME"; - bench --site $$SITE_NAME migrate; - else - echo "[migrator] Site $$SITE_NAME not found, skipping migrate"; - fi + if [ -z "$$(find sites -mindepth 2 -maxdepth 2 -name site_config.json 2>/dev/null)" ]; then + echo "[migrator] No sites found, skipping migration"; + exit 0; + fi; + echo "[migrator] Migrating all sites"; + bench --site all migrate; environment: - SITE_NAME: ${SITE_NAME} - restart: on-failure + MIGRATE_SITES: ${MIGRATE_SITES:-true} + restart: on-failure:5