feat(migrator): add multi-site support to migration

This commit is contained in:
jslocomotor 2026-04-30 23:15:58 +02:00
parent 815946194c
commit ae221ebf7a
2 changed files with 12 additions and 13 deletions

View file

@ -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 | | |

View file

@ -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