fix(tenant): route runtime traffic to tenant databases
Some checks failed
CI / Backend Tests (push) Has been cancelled
CI / Frontend Tests (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
CI / Naming Conventions (push) Has been cancelled
CI / Build Check (push) Has been cancelled

Wire Doctrine's default connection to the tenant database resolved from the subdomain for HTTP requests and tenant-scoped Messenger messages while keeping master-only services on the master connection.

This removes the production inconsistency where demo data, migrations and tenant commands used the tenant database but the web runtime still read from master.
This commit is contained in:
2026-03-10 23:38:26 +01:00
parent 0f3e57c6e6
commit 8c70ed1324
16 changed files with 840 additions and 4 deletions

View File

@@ -21,6 +21,8 @@ Options:
--zone ZONE School zone: A, B or C. Default: B
--period-type TYPE Academic period type: trimester or semester.
Default: trimester
--target TARGET Where to write demo data: master or tenant.
Default: tenant
--env-file PATH Override env file path. Default: ${ENV_FILE}
--compose-file PATH Override compose file path. Default: ${COMPOSE_FILE}
--service NAME Override PHP service name. Default: ${PHP_SERVICE}
@@ -30,6 +32,7 @@ Examples:
./deploy/vps/generate-demo-data.sh
./deploy/vps/generate-demo-data.sh --password 'Demo2026!'
./deploy/vps/generate-demo-data.sh --tenant demo --school 'College de demo'
./deploy/vps/generate-demo-data.sh --target master
EOF
}
@@ -70,6 +73,7 @@ PASSWORD="DemoPassword123!"
SCHOOL=""
ZONE="B"
PERIOD_TYPE="trimester"
TARGET="tenant"
while [ "$#" -gt 0 ]; do
case "$1" in
@@ -113,6 +117,14 @@ while [ "$#" -gt 0 ]; do
PERIOD_TYPE="${1#*=}"
shift
;;
--target)
TARGET="${2:-}"
shift 2
;;
--target=*)
TARGET="${1#*=}"
shift
;;
--env-file)
ENV_FILE="${2:-}"
shift 2
@@ -172,6 +184,15 @@ if [ -z "${TENANT}" ]; then
exit 1
fi
case "${TARGET}" in
master|tenant)
;;
*)
echo "Invalid target: ${TARGET}. Expected 'master' or 'tenant'." >&2
exit 1
;;
esac
if [ -z "${SCHOOL}" ] && [ -t 0 ]; then
SCHOOL=$(prompt_with_default "School name (optional)" "")
fi
@@ -188,6 +209,10 @@ COMMAND=(
"--period-type=${PERIOD_TYPE}"
)
if [ "${TARGET}" = "master" ]; then
COMMAND+=("--internal-run")
fi
if [ -n "${SCHOOL}" ]; then
COMMAND+=("--school=${SCHOOL}")
fi
@@ -195,6 +220,7 @@ fi
echo "Running demo data generator for tenant: ${TENANT}"
echo "Compose file: ${COMPOSE_FILE}"
echo "Env file: ${ENV_FILE}"
echo "Target database: ${TARGET}"
echo
"${COMMAND[@]}"