version: "3.9"

services:
  db:
    image: mysql:8.0
    container_name: pubquiz_mysql
    restart: always
    environment:
      MYSQL_DATABASE: "pubquiz_db"
      MYSQL_USER: "pubquiz_user"
      MYSQL_PASSWORD: "pubquiz_pass"
      MYSQL_ROOT_PASSWORD: "root_pass"
    ports:
      - "3306:3306"
    tmpfs:
      - /var/lib/mysql  # Use RAM-based ephemeral storage instead of persistent volume
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p$$MYSQL_ROOT_PASSWORD"]
      interval: 5s
      timeout: 5s
      retries: 20

  app:
    build: .
    container_name: pubquiz_app
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    environment:
      DB_HOST: "db"
      DB_PORT: "3306"
      DB_NAME: "pubquiz_db"
      DB_USER: "pubquiz_user"
      DB_PASS: "pubquiz_pass"
      PYTHONUNBUFFERED: "1"
      LEAGUELEDGER_BASE_URL: "https://rover.leagueledger.net"  # Base URL for QR codes
    command: uvicorn app.main:app --host 0.0.0.0 --reload
    ports:
      - "8000:8000"
    volumes:
      - ./:/app:delegated

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: pubquiz_phpmyadmin
    restart: unless-stopped
    depends_on:
      - db
    environment:
      PMA_HOST: db
      PMA_PORT: 3306
      PMA_USER: pubquiz_user
      PMA_PASSWORD: pubquiz_pass
    ports:
      - "8001:80"

# No persistent volumes defined - database will reset when container stops
