version: "3.8"

services:
  postgres:
    image: postgres:15
    container_name: onescribe_local_db
    restart: unless-stopped
    environment:
      POSTGRES_DB: onescribe_local
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres123
      POSTGRES_HOST_AUTH_METHOD: trust
    ports:
      - "5433:5432" # Using 5433 to avoid conflicts with system PostgreSQL
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./local-database:/docker-entrypoint-initdb.d
    command: >
      postgres -c log_statement=all
               -c log_destination=stderr
               -c log_min_duration_statement=0
               -c shared_preload_libraries=pg_stat_statements
               -c pg_stat_statements.track=all

  # Optional: pgAdmin for web-based database management
  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: onescribe_pgadmin
    restart: unless-stopped
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@example.com
      PGADMIN_DEFAULT_PASSWORD: admin123
      PGADMIN_CONFIG_SERVER_MODE: "False"
    ports:
      - "5050:80"
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    depends_on:
      - postgres

volumes:
  postgres_data:
  pgadmin_data:
