Files
natureinpots_community/entrypoint.sh
2025-06-27 17:43:50 -05:00

50 lines
1.2 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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 <<EOF
from app import create_app, db
app = create_app()
with app.app_context():
db.create_all()
EOF
# Optional seeding
if [ "$ENABLE_DB_SEEDING" = "true" ] || [ "$ENABLE_DB_SEEDING" = "1" ]; then
echo "[🌱] Seeding Data"
flask preload-data
fi
echo "[🚀] Starting Flask"
exec "$@"