@@ -285,18 +285,66 @@ tasks:
285285 rm -f "$tmp"
286286
287287 env:migrate :
288- desc : Convert a 1.x .env.docker.local into a 3.x-shaped .env.symfony.migrated
288+ desc : Stage a 3.x-shaped .env.symfony.migrated — from env.3x (preferred) or a 1.x .env.docker.local
289289 cmds :
290290 - |
291+ OUT=.env.symfony.migrated
292+
293+ # Preferred path: env.3x produced by `task upgrade_prep` on the 1.x
294+ # stack (the API's app:utils:convert-env-to-3x command). It already
295+ # carries the loaded values under their 3.x names AND the admin/client
296+ # config.json conversion the sed path below can't see — so when it's
297+ # present we just split off the trailing infrastructure-advisory
298+ # comment block (COMPOSE_*/PHP_*/NGINX_*/MARIADB_* notes) into a
299+ # reminder, and the rest becomes .env.symfony directly.
300+ if [ -f env.3x ]; then
301+ echo "Found env.3x from the 1.x upgrade prep — using it as the source."
302+ # env.3x ends with a trailing advisory block the converter
303+ # introduces with a fixed marker line; everything above it is the
304+ # application env. Split at the marker: app env to .env.symfony,
305+ # the advisory to its own file (surfaced below, not buried in the
306+ # app env).
307+ ADVISORY=.env.symfony.infra-advisory
308+ rm -f "$ADVISORY"
309+ awk -v adv="$ADVISORY" '
310+ /^# The following loaded variables are NOT read/ { infra = 1 }
311+ infra { print > adv; next }
312+ { print }
313+ ' env.3x > "$OUT"
314+ echo "Wrote $OUT (from env.3x)."
315+ if [ -s "$ADVISORY" ]; then
316+ echo ""
317+ echo "Infrastructure variables were split into $ADVISORY."
318+ echo "They do NOT belong in .env.symfony — distribute them across the"
319+ echo "per-service files of the 3.x layout:"
320+ echo " COMPOSE_* -> .env PHP_* -> .env.php"
321+ echo " NGINX_* -> .env.nginx MARIADB_* -> .env.mariadb"
322+ fi
323+ echo ""
324+ echo "Review with: diff -u env.3x $OUT"
325+ echo "Apply with: mv $OUT .env.symfony"
326+ echo ""
327+ echo "Still set by hand: DATABASE_URL serverVersion=11.4.10-MariaDB"
328+ echo "(after the MariaDB upgrade — see UPGRADE.md step 6)."
329+ exit 0
330+ fi
331+
332+ # Fallback path: no env.3x (older 1.x without the converter command, or
333+ # the stack is already down). Convert a 1.x .env.docker.local by sed —
334+ # an APP_ strip plus the per-site renames the converter would do.
291335 if [ -f .env.docker.local ]; then
292336 SRC=.env.docker.local
293337 elif [ -f .env.local ]; then
294338 SRC=.env.local
295339 else
296- echo "Error: neither .env.docker.local nor .env.local exists."
340+ echo "Error: no env.3x, .env.docker.local or .env.local found."
341+ echo "On the 1.x stack, prefer 'task upgrade_prep' to produce env.3x."
297342 exit 1
298343 fi
299- OUT=.env.symfony.migrated
344+ echo "No env.3x found — falling back to the sed conversion of $SRC."
345+ echo "(The env.3x path from 'task upgrade_prep' on 1.x is preferred:"
346+ echo " it also converts the admin/client config.json, which sed can't.)"
347+ echo ""
300348 # Strip APP_ prefix from every key EXCEPT the framework-defined trio
301349 # (APP_ENV, APP_SECRET, APP_DEBUG) — Symfony recognises those by name,
302350 # and renaming them silently breaks env-driven debug/secret/env config.
0 commit comments