# Usage
#   Start:          docker-compose up
#   Stop:           docker-compose down -v

version: "3.8"

services:
  db:
    image: supabase_postgres
    restart: "no"
    healthcheck:
      test: pg_isready -U postgres -h localhost
      interval: 2s
      timeout: 2s
      retries: 10
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}

  pg_prove:
    image: horrendo/pg_prove
    depends_on:
      db:
        condition: service_healthy
      dbmate:
        condition: service_completed_successfully
    environment:
      PGHOST: db
      PGUSER: supabase_admin
      PGDATABASE: postgres
      PGPASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - ./tests:/tests
    command: pg_prove /tests/test.sql

  dbmate:
    build:
      context: .
      dockerfile: Dockerfile.dbmate
    depends_on:
      db:
        condition: service_healthy
    volumes:
      - ./schema.sql:/db/schema.sql
    environment:
      DATABASE_URL: postgres://postgres:${POSTGRES_PASSWORD}@db/postgres?sslmode=disable
    command: dump
