This guide will help you set up SportSQL for local development using PostgreSQL instead of the expensive GCP MySQL database.
brew install postgresql
brew services start postgresql
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
sudo systemctl enable postgresql
Download and install from PostgreSQL official website
# Connect to PostgreSQL
sudo -u postgres psql
# Create database and user
CREATE DATABASE sportsql_local;
CREATE USER sportsql_user WITH PASSWORD 'your_local_password';
GRANT ALL PRIVILEGES ON DATABASE sportsql_local TO sportsql_user;
\q
Create a .env file in the SportSQL directory:
# Local PostgreSQL Configuration
LOCAL_DATABASE_HOST=localhost
LOCAL_DATABASE_PORT=5432
LOCAL_DATABASE_USER=sportsql_user
LOCAL_DATABASE_PASSWORD=your_local_password
LOCAL_DATABASE_NAME=sportsql_local
# Remote MySQL Configuration (keep existing for production)
DATABASE_HOST=35.184.21.229
DATABASE_USER=naman
DATABASE_NAME=sport-sql
DATABASE_PORT=3306
DATABASE_PASSWORD=your_gcp_password
# Gemini API
API_KEY=your_gemini_api_key
GEMINI_MODEL=gemini-2.0-flash
pip install -r requirements.txt
Run the setup script to create tables and populate data:
python setup_local_db.py
This script will:
python app.py --server local
python app.py --server remote
python setup_local_db.py
python update_db.py --server remote
The application now supports two database configurations:
# macOS
brew services list | grep postgresql
# Linux
sudo systemctl status postgresql
psql -h localhost -U sportsql_user -d sportsql_local -c "SELECT version();"
python -c "from db_config import get_db_config; print(get_db_config('local').get_database_info())"
pip install psycopg2-binaryThe application automatically detects the --server flag:
# Use local PostgreSQL
python app.py --server local --port 5000
# Use remote MySQL
python app.py --server remote --port 5000
# Default is remote for backward compatibility
python app.py
Start local development:
python app.py --server local
Test with fresh data:
python setup_local_db.py # Refresh local data
python app.py --server local
Test production setup:
python app.py --server remote
Deploy to production:
✅ Cost Savings: No GCP charges during development
✅ Speed: Local database = faster queries
✅ Offline Development: Work without internet
✅ Easy Testing: Quick database resets
✅ Production Parity: Same application code
✅ Flexible: Switch between local/remote anytime
SportSQL/
├── app.py # Main Flask application (updated)
├── db_config.py # Database configuration manager (new)
├── setup_local_db.py # Local database setup script (new)
├── mariadb_access.py # Database access layer (updated)
├── gemini_api.py # Gemini API integration (updated)
├── update_db.py # Database update script (updated)
├── requirements.txt # Dependencies (updated)
├── LOCAL_SETUP.md # This setup guide (new)
└── .env # Environment variables (create)
python app.py --server local--server remote only when you need production dataFor questions or issues, check the troubleshooting section above.