services:
  clickhouse-server:
    image: clickhouse/clickhouse-server:24-alpine
    container_name: clickhouse-server-1
    hostname: clickhouse-server-1
    ports:
      - "8123:8123"
      - "9000:9000"
      - "9004:9004"
    expose:
      - 8123
      - 9009
    configs:
     - source: clickhouse_init
       target: /docker-entrypoint-initdb.d/init-db.sh

  clickhouse-ui:
    image: "ghcr.io/caioricciuti/ch-ui:latest"
    ports:
      - 5521:5521
    environment:
      - VITE_CLICKHOUSE_URL=http://localhost:8123
      - VITE_CLICKHOUSE_USER=default
      #- VITE_CLICKHOUSE_PASS=default
    depends_on:
      - clickhouse-server

configs:
  clickhouse_init:
    content: |
      #!/bin/bash
      set -e
      
      clickhouse client -n <<-EOSQL
        CREATE table click_stats(
            clicks_count Int64,
            ad_id Int64
        )ENGINE = ReplacingMergeTree
        PRIMARY KEY (ad_id);
          
      EOSQL