version: '3.8'

services:
  timescaledb:
    image: timescale/timescaledb:latest-pg16
    container_name: meta_timescaledb
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: meta_insights
      POSTGRES_USER: meta_user
      POSTGRES_PASSWORD: meta_password
    volumes:
      - timescale_data:/var/lib/postgresql/data
      - ./src/meta_api_grabber/db_schema.sql:/docker-entrypoint-initdb.d/01-schema.sql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U meta_user -d meta_insights"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  # Optional: Grafana for visualization
  grafana:
    image: grafana/grafana:latest
    container_name: meta_grafana
    ports:
      - "3000:3000"
    environment:
      GF_SECURITY_ADMIN_USER: admin
      GF_SECURITY_ADMIN_PASSWORD: admin
      GF_INSTALL_PLUGINS: grafana-clock-panel
    volumes:
      - grafana_data:/var/lib/grafana
    depends_on:
      timescaledb:
        condition: service_healthy
    restart: unless-stopped

volumes:
  timescale_data:
  grafana_data:
