version: "3.9"

services:
  db:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: b2b_user
      POSTGRES_PASSWORD: b2b_password
      POSTGRES_DB: b2b_ordering
    ports:
      - "5432:5432"
    volumes:
      - db_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U b2b_user -d b2b_ordering"]
      interval: 5s
      timeout: 5s
      retries: 10

  app:
    build: .
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    environment:
      DATABASE_URL: "postgresql://b2b_user:b2b_password@db:5432/b2b_ordering?schema=public"
      JWT_SECRET: "replace-with-a-long-random-secret"
      NEXT_PUBLIC_APP_NAME: "B2B Order Portal"
    ports:
      - "3000:3000"
    command: sh -c "npx prisma migrate deploy && npm run start"

volumes:
  db_data:
