# Database Notes playground: the four databases the site uses, with its sample shop data loaded.
#   Start:  docker compose up -d --wait     (the first start downloads the images: about 3.7 GB on disk)
#   Reset:  docker compose down && docker compose up -d --wait   (fresh sample data; your changes are gone)
#   Stop:   docker compose stop    (data kept)       Remove:  docker compose down
# Ports listen on 127.0.0.1 only, so nothing outside this computer can reach them. Password everywhere: study.
name: db-notes
services:
  mysql:
    image: mysql:9.7
    environment:
      MYSQL_ROOT_PASSWORD: study
      MYSQL_DATABASE: shop
      LANG: C.UTF-8   # the mysql prompt drops letters like é as you type them without a UTF-8 locale
    ports: ["127.0.0.1:3307:3306"]
    volumes:
      - ./mysql/load.sh:/docker-entrypoint-initdb.d/load.sh:ro
      - ./mysql/shop.sql:/seed/shop.sql:ro
      - ./mysql/practice.sql:/seed/practice.sql:ro
      - ./mysql/client.cnf:/root/.my.cnf:ro
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "--protocol=tcp"]
      interval: 3s
      retries: 60
  postgres:
    image: postgres:18
    environment:
      POSTGRES_PASSWORD: study
      POSTGRES_DB: shop
    ports: ["127.0.0.1:5433:5432"]
    volumes:
      - ./postgres/shop.sql:/docker-entrypoint-initdb.d/shop.sql:ro
    healthcheck:
      test: ["CMD", "pg_isready", "-h", "127.0.0.1", "-U", "postgres", "-d", "shop"]
      interval: 3s
      retries: 60
  mongo:
    image: mongo:9.0
    command: ["--replSet", "rs0", "--bind_ip_all"]
    ports: ["127.0.0.1:27018:27017"]
    volumes:
      - ./mongo/shop.js:/docker-entrypoint-initdb.d/shop.js:ro
    # Healthy once the real server is up (the seed runs first on a temporary one that only listens inside the container).
    healthcheck:
      test: ["CMD", "mongosh", "--quiet", "--eval", "const net = db.serverCmdLineOpts().parsed.net; quit(db.hello().isWritablePrimary && net.bindIp === '*' ? 0 : 1)"]
      interval: 3s
      retries: 60
  redis:
    image: redis:8.10
    ports: ["127.0.0.1:6380:6379"]
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 3s
      retries: 20
