feat: initialize database with demo data on first run and update README
Some checks failed
Backend CI / lint-and-test (push) Failing after 1m33s
Frontend CI / lint-and-build (push) Successful in 17s

This commit is contained in:
2025-10-11 21:52:30 +02:00
parent 25ca7ab196
commit f9086d2d04
4 changed files with 27 additions and 4 deletions

View File

@@ -178,6 +178,15 @@ PowerShell / Bash
docker compose up --build docker compose up --build
This starts all services (Postgres, Redis, backend, frontend) and automatically initializes the database with demo data on first run. The backend waits for the database to be ready before running migrations and loading OSM fixtures.
**Services:**
- Backend API: `http://localhost:8000`
- Frontend: `http://localhost:8080`
- Postgres: `localhost:5432`
- Redis: `localhost:6379`
This expects a working Docker environment and may require you to set DB URLs to point to the containerized Postgres service if one is defined in `docker-compose.yml`. This expects a working Docker environment and may require you to set DB URLs to point to the containerized Postgres service if one is defined in `docker-compose.yml`.
## Troubleshooting ## Troubleshooting

View File

@@ -8,15 +8,26 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
WORKDIR /app WORKDIR /app
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential libpq-dev \ && apt-get install -y --no-install-recommends build-essential libpq-dev postgresql-client \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
COPY backend/requirements/base.txt ./backend/requirements/base.txt COPY backend/requirements/base.txt ./backend/requirements/base.txt
RUN pip install --upgrade pip \ RUN pip install --upgrade pip \
&& pip install -r backend/requirements/base.txt && pip install -r backend/requirements/base.txt
COPY scripts ./scripts
COPY .env.example ./.env.example
COPY .env* ./
COPY backend ./backend COPY backend ./backend
EXPOSE 8000 EXPOSE 8000
CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "8000"] # Initialize database with demo data if INIT_DEMO_DB is set
CMD ["sh", "-c", "\
export PYTHONPATH=/app && \
echo 'Waiting for database...' && \
while ! pg_isready -h db -p 5432 -U railgame >/dev/null 2>&1; do sleep 1; done && \
echo 'Database is ready!' && \
if [ \"$INIT_DEMO_DB\" = \"true\" ]; then python scripts/init_demo_db.py; fi && \
uvicorn backend.app.main:app --host 0.0.0.0 --port 8000"]

View File

@@ -1,5 +1,3 @@
version: "3.9"
services: services:
db: db:
build: build:
@@ -27,6 +25,7 @@ services:
DATABASE_URL: postgresql+psycopg://railgame:railgame@db:5432/railgame_dev DATABASE_URL: postgresql+psycopg://railgame:railgame@db:5432/railgame_dev
TEST_DATABASE_URL: postgresql+psycopg://railgame:railgame@db:5432/railgame_test TEST_DATABASE_URL: postgresql+psycopg://railgame:railgame@db:5432/railgame_test
REDIS_URL: redis://redis:6379/0 REDIS_URL: redis://redis:6379/0
INIT_DEMO_DB: "true"
depends_on: depends_on:
- db - db
- redis - redis

View File

@@ -32,6 +32,10 @@ except ImportError:
def check_virtualenv(): def check_virtualenv():
"""Check if we're running in a virtual environment.""" """Check if we're running in a virtual environment."""
# Skip virtualenv check in Docker containers
if os.getenv('INIT_DEMO_DB') == 'true':
return
if not hasattr(sys, 'real_prefix') and not (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix): if not hasattr(sys, 'real_prefix') and not (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
print("ERROR: Virtual environment not activated. Run:") print("ERROR: Virtual environment not activated. Run:")
print(" .venv\\Scripts\\Activate.ps1 (PowerShell)") print(" .venv\\Scripts\\Activate.ps1 (PowerShell)")