services:
  postgres:
    image: ${PG_TRICKLE_IMAGE:-ghcr.io/grove/pg_trickle:latest}
    environment:
      POSTGRES_USER: demo
      POSTGRES_PASSWORD: demo
      POSTGRES_DB: ${DEMO_SCENARIO:-ecommerce}_demo
    ports:
      - "5432:5432"
    volumes:
      - ./postgres/${DEMO_SCENARIO:-ecommerce}/01_schema.sql:/docker-entrypoint-initdb.d/01_schema.sql:ro
      - ./postgres/${DEMO_SCENARIO:-ecommerce}/02_stream_tables.sql:/docker-entrypoint-initdb.d/02_stream_tables.sql:ro
      - pgdata:/var/lib/postgresql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U demo -d ${DEMO_SCENARIO:-ecommerce}_demo"]
      interval: 2s
      timeout: 5s
      retries: 30

  generator:
    build: ./generator
    environment:
      DATABASE_URL: postgresql://demo:demo@postgres/${DEMO_SCENARIO:-ecommerce}_demo
      DEMO_SCENARIO: ${DEMO_SCENARIO:-ecommerce}
    depends_on:
      postgres:
        condition: service_healthy
    restart: unless-stopped

  dashboard:
    build: ./dashboard
    environment:
      DATABASE_URL: postgresql://demo:demo@postgres/${DEMO_SCENARIO:-ecommerce}_demo
      DEMO_SCENARIO: ${DEMO_SCENARIO:-ecommerce}
    ports:
      - "8080:8080"
    depends_on:
      postgres:
        condition: service_healthy
    restart: unless-stopped

volumes:
  pgdata:
