version: "2"

services:
  mariadb-primary:
    image: mariadb:latest
    container_name: ${MARIA_HOST}
    command: 
      - --innodb_buffer_pool_size=536870912
      - --key_buffer_size=67108864
      - --query_cache_type=1
      - --query_cache_size=134217728
      - --query-cache-strip-comments=1
      - --max-connections=256
      - --log_bin=log_bin
      - --binlog_format=ROW
      - --server-id=1
    ports:
      - "3306:3306"
    networks:
      - repl      
    volumes:
      - mariadb-primary-data:/var/lib/mysql
    environment:
      MARIADB_USER: ${MARIA_USER}
      MARIADB_PASSWORD: ${MARIA_PASS}
      MYSQL_DATABASE: ${MARIA_NAME}
      MYSQL_ROOT_PASSWORD: ${MARIA_PASS}
    restart: always

  mariadb-secondary:
    image: mariadb:latest
    container_name: ${MARIA_SECONDARY_HOST}
    command:
      - --innodb_buffer_pool_size=536870912
      - --key_buffer_size=67108864
      - --max-connections=256
      - --server-id=2
      - --read_only=ON
      - --relay-log=relay-log
      # - --log_bin=log_bin
      # - --binlog_format=ROW
    ports:
      - "3307:3306"
    networks:
      - repl
    volumes:
      - mariadb-secondary-data:/var/lib/mysql
    environment:
      MARIADB_USER: ${MARIA_USER}
      MARIADB_PASSWORD: ${MARIA_PASS}
      MYSQL_DATABASE: ${MARIA_NAME}
      MYSQL_ROOT_PASSWORD: ${MARIA_PASS}
    restart: always
    depends_on:
      - mariadb-primary

  # postgresql:
  #   container_name: ${POSTGRES_HOST}
  #   restart: always
  #   image: postgres:18
  #   networks:
  #     repl:
  #   ports:
  #     - 5432:5432
  #   volumes:
  #     - postgres-data:/var/lib/postgresql:Z
  #   command: postgres -c shared_buffers=512MB -c work_mem=16MB  -c maintenance_work_mem=256MB -c effective_cache_size=4GB -c max_connections=20
  #   environment:
  #     POSTGRES_USER: ${POSTGRES_USER}
  #     POSTGRES_PASSWORD: ${POSTGRES_PASS}
  #     POSTGRES_DB: ${POSTGRES_NAME}       


networks:
  repl:
    name: repl
volumes:
  mariadb-primary-data:
    driver: local
  mariadb-secondary-data:
    driver: local
  postgres-data:
    driver: local      
