version: '3.1'

services:

  db:
    image: postgres:13-alpine
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
    ports:
      - "5432:5432"
    volumes:
      - ./sql/:/docker-entrypoint-initdb.d

  build: &build
    build: .
    environment:
      PGHOST: db
      PGUSER: postgres
      PGDATABASE: postgres
      PGPASSWORD: password
    volumes:
      - ../../:/app
    working_dir: /app/packages/example
    restart: on-failure
    depends_on:
      - db
    command: npx pgtyped --config config.json

  watch:
    <<: *build
    command: npx pgtyped --watch --config config.json

  test:
    <<: *build
    depends_on:
      - build
    command: npx ts-node src/index.ts

