services:
  database:
    volumes:
      - ./local_data/postgres:/var/lib/postgresql/data:z
    ports:
      - 3399:5432
    restart: no
    environment:
      POSTGRES_USER: kycnot
      POSTGRES_PASSWORD: kycnot
      POSTGRES_DB: kycnot
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U kycnot -d kycnot"]
      interval: 10s
      timeout: 5s
      retries: 5

  db-admin:
    image: node:20
    working_dir: /app
    volumes:
      - ./web:/app
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-kycnot}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-kycnot}
      POSTGRES_DB: ${POSTGRES_DATABASE:-kycnot}
      DATABASE_URL: "postgresql://${POSTGRES_USER:-kycnot}:${POSTGRES_PASSWORD:-kycnot}@database:5432/${POSTGRES_DATABASE:-kycnot}?schema=public"
    depends_on:
      database:
        condition: service_healthy
    expose:
      - 5555
    ports:
      - "5555:5555"
    command: ["npm", "run", "db-admin"]
    healthcheck:
      test: ["CMD", "curl", "-k", "--silent", "--fail", "http://localhost:5555"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    ports:
      - "6379:6379"
