diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f2832e..6203815 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - Legal pages: replaced home address with virtual office address (c/o COCENTER, Koppoldstr. 1, 86551 Aichach) in all four legal templates (`imprint_de`, `imprint_en`, `privacy_de`, `privacy_en`, `terms_de`) ### Fixed +- Deploy: write nginx router config *before* starting containers so the router health check (`nginx -t`) passes on first deploy or after volume wipe - Deploy: pre-migration DB backup added to `deploy.sh`; on health-check failure the DB is restored to pre-migration state (prevents old slot from running against new schema) - Migrations: removed all `conn.commit()` and `executescript()` calls from `up()` functions in 0000, 0011, 0012, 0013, 0014, 0015 — restores batch-atomicity guarantee (`executescript` issued implicit COMMITs, breaking rollback on failure) - Visual tests: server now builds schema via `migrate()` instead of the deleted `schema.sql`; all 12 Playwright tests pass diff --git a/deploy.sh b/deploy.sh index adfd4e5..ea27c05 100755 --- a/deploy.sh +++ b/deploy.sh @@ -35,25 +35,9 @@ echo "==> Running migrations..." $COMPOSE --profile "$TARGET" run --rm "${TARGET}-app" \ python -m padelnomics.migrations.migrate -# ── Start & health check ─────────────────────────────────── +# ── Write router config (before starting, so nginx -t passes) ── -echo "==> Starting $TARGET (waiting for health check)..." -if ! $COMPOSE --profile "$TARGET" up -d --wait; then - echo "!!! Health check failed — rolling back" - $COMPOSE stop "${TARGET}-app" "${TARGET}-worker" "${TARGET}-scheduler" - LATEST=$($COMPOSE run --rm --entrypoint "" "${TARGET}-app" \ - sh -c "ls -t /app/data/app.db.pre-deploy-* 2>/dev/null | head -1") - if [ -n "$LATEST" ]; then - echo "==> Restoring database from ${LATEST}..." - $COMPOSE run --rm --entrypoint "" "${TARGET}-app" \ - sh -c "cp '${LATEST}' /app/data/app.db" - fi - exit 1 -fi - -# ── Switch router ─────────────────────────────────────────── - -echo "==> Switching router to $TARGET..." +echo "==> Writing router config for $TARGET..." mkdir -p "$(dirname "$ROUTER_CONF")" cat > "$ROUTER_CONF" < Starting $TARGET (waiting for health check)..." +if ! $COMPOSE --profile "$TARGET" up -d --wait; then + echo "!!! Health check failed — rolling back" + $COMPOSE stop "${TARGET}-app" "${TARGET}-worker" "${TARGET}-scheduler" + LATEST=$($COMPOSE run --rm --entrypoint "" "${TARGET}-app" \ + sh -c "ls -t /app/data/app.db.pre-deploy-* 2>/dev/null | head -1") + if [ -n "$LATEST" ]; then + echo "==> Restoring database from ${LATEST}..." + $COMPOSE run --rm --entrypoint "" "${TARGET}-app" \ + sh -c "cp '${LATEST}' /app/data/app.db" + fi + exit 1 +fi + +# ── Reload router to pick up new upstream ─────────────────── + +echo "==> Reloading router..." $COMPOSE exec router nginx -s reload # ── Cleanup old pre-deploy backups (keep last 3) ─────────────