42 lines
1.4 KiB
Bash
Executable File
42 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
REPORTS_DB="$REPO_ROOT/dbt_nba/reports/sources/nba/dbt_nba.duckdb"
|
|
DATA_DB="$REPO_ROOT/data/DB/dbt_nba.duckdb"
|
|
|
|
# Load .env if present
|
|
if [ -f "$REPO_ROOT/.env" ]; then
|
|
set -a
|
|
source "$REPO_ROOT/.env"
|
|
set +a
|
|
fi
|
|
|
|
FORCE_SYNC=0
|
|
for arg in "$@"; do
|
|
if [ "$arg" == "--sync" ] || [ "$arg" == "-s" ]; then
|
|
FORCE_SYNC=1
|
|
fi
|
|
done
|
|
|
|
# Check if database is missing or sync requested
|
|
if [ ! -f "$REPORTS_DB" ] || [ "$FORCE_SYNC" -eq 1 ]; then
|
|
if [ -f "$DATA_DB" ] && [ "$FORCE_SYNC" -eq 0 ]; then
|
|
echo "==> Copying local database to reports path..."
|
|
mkdir -p "$(dirname "$REPORTS_DB")"
|
|
cp "$DATA_DB" "$REPORTS_DB"
|
|
elif [ -n "${S3_ENDPOINT_URL:-}" ] || [ -n "${R2_ENDPOINT_URL:-}" ]; then
|
|
echo "==> Local database missing or --sync requested; downloading latest from Cloudflare R2 / S3..."
|
|
uv run --project "$REPO_ROOT" python "$REPO_ROOT/scripts/db_storage.py" download
|
|
else
|
|
echo "ERROR: Local database file not found at $REPORTS_DB." >&2
|
|
echo "Please either:" >&2
|
|
echo " 1. Run ./scripts/pipeline.sh to extract and build from Postgres, or" >&2
|
|
echo " 2. Configure R2 credentials in .env and run: uv run python scripts/db_storage.py download" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo "==> Starting Streamlit NBA Analytics Dashboard..."
|
|
uv run --project "$REPO_ROOT" streamlit run "$REPO_ROOT/streamlit_app/app.py"
|