#!/usr/bin/env bash set -e UPLOAD_DIR="/app/static/uploads" mkdir -p "$UPLOAD_DIR" chown -R 1000:998 "$UPLOAD_DIR" chmod -R 775 "$UPLOAD_DIR" DB_HOST=${DB_HOST:-db} DB_PORT=${DB_PORT:-3306} echo "[âŗ] Waiting for database at $DB_HOST:$DB_PORT..." until nc -z "$DB_HOST" "$DB_PORT"; do sleep 1 done echo "[✔] Database is up" # Initialize Alembic if not present if [ ! -d "./migrations" ]; then echo "[🆕] No migrations directory found; initializing Alembic" flask db init echo "[🆕] Generating initial migration" flask db migrate -m "initial" || echo "[â„šī¸] Nothing to migrate" fi # Autogenerate new migration if needed echo "[đŸ› ī¸] Checking for new schema changes" flask db migrate -m "auto-migrate" || echo "[â„šī¸] No schema changes detected" # Apply migrations echo "[â–ļī¸] Applying database migrations" flask db upgrade # Create any missing tables (edge case fallback) echo "[🔧] Running db.create_all() to ensure full sync" python <