services:
  postgres-main:
    image: postgres:15
    container_name: postgres-main
    ports:
      - "5434:5432"
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: postgres
    volumes:
      - postgres-main-data:/var/lib/postgresql/data
    restart: unless-stopped

  clickhouse:
    image: clickhouse/clickhouse-server:latest
    container_name: clickhouse
    ports:
      - "8123:8123"
      - "9000:9000"
    environment:
      CLICKHOUSE_DB: default
      CLICKHOUSE_USER: default
      CLICKHOUSE_PASSWORD: clickhouse
      CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
    volumes:
      - clickhouse-data:/var/lib/clickhouse
      - clickhouse-logs:/var/log/clickhouse-server
    ulimits:
      nofile:
        soft: 262144
        hard: 262144
    restart: unless-stopped

  dbgate:
    image: dbgate/dbgate:latest
    container_name: dbgate
    ports:
      - "3300:3000"
    environment:
      CONNECTIONS: "con1,con2"
      LABEL_con1: PostgreSQL
      SERVER_con1: postgres-main
      USER_con1: postgres
      PASSWORD_con1: postgres
      PORT_con1: 5432
      ENGINE_con1: postgres@dbgate-plugin-postgres
      LABEL_con2: ClickHouse
      SERVER_con2: clickhouse
      USER_con2: default
      PASSWORD_con2: clickhouse
      PORT_con2: 8123
      ENGINE_con2: clickhouse@dbgate-plugin-clickhouse
    depends_on:
      - postgres-main
      - clickhouse
    restart: unless-stopped

volumes:
  postgres-main-data:
  clickhouse-data:
  clickhouse-logs:
