volumes:
  postgres-14-data:
  postgres-15-data:
  postgres-16-data:
  postgres-17-data:
  postgres-18-data:
  pg-sockets:

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile

    volumes:
      - ../..:/workspaces:cached
      - pg-sockets:/var/run/postgresql

    environment:
      PGUSER: postgres
      PGPASSWORD: postgres
      PGDATABASE: pgx_test
      PGHOST: localhost
      PGCLIENTENCODING: utf8

      # PGX test env vars target PG18 (port 5432) by default.
      # test.sh overrides these per-target.
      PGX_TEST_DATABASE: "host=localhost port=5432 user=postgres password=postgres dbname=pgx_test"
      PGX_TEST_UNIX_SOCKET_CONN_STRING: "host=/var/run/postgresql port=5432 user=postgres dbname=pgx_test"
      PGX_TEST_TCP_CONN_STRING: "host=127.0.0.1 port=5432 user=pgx_md5 password=secret dbname=pgx_test"
      PGX_TEST_MD5_PASSWORD_CONN_STRING: "host=127.0.0.1 port=5432 user=pgx_md5 password=secret dbname=pgx_test"
      PGX_TEST_SCRAM_PASSWORD_CONN_STRING: "host=localhost port=5432 user=pgx_scram password=secret dbname=pgx_test channel_binding=disable"
      PGX_TEST_SCRAM_PLUS_CONN_STRING: "host=127.0.0.1 port=5432 user=pgx_ssl password=secret sslmode=verify-full sslrootcert=/tmp/ca.pem dbname=pgx_test channel_binding=require"
      PGX_TEST_PLAIN_PASSWORD_CONN_STRING: "host=127.0.0.1 port=5432 user=pgx_pw password=secret dbname=pgx_test"
      PGX_TEST_TLS_CONN_STRING: "host=localhost port=5432 user=pgx_ssl password=secret sslmode=verify-full sslrootcert=/tmp/ca.pem dbname=pgx_test channel_binding=disable"
      PGX_TEST_TLS_CLIENT_CONN_STRING: "host=localhost port=5432 user=pgx_sslcert sslmode=verify-full sslrootcert=/tmp/ca.pem sslcert=/tmp/pgx_sslcert.crt sslkey=/tmp/pgx_sslcert.key dbname=pgx_test"
      PGX_SSL_PASSWORD: certpw

    # Overrides default command so things don't shut down after the process ends.
    command: sleep infinity

  postgres-14:
    image: postgres:14
    restart: unless-stopped
    volumes:
      - postgres-14-data:/var/lib/postgresql
      - ../testsetup/postgresql_setup.sql:/docker-entrypoint-initdb.d/01-setup.sql:ro
      - ../testsetup/pg_ssl_init.sh:/docker-entrypoint-initdb.d/02-ssl-init.sh:ro
      - ../testsetup/pg_hba_devcontainer.conf:/etc/postgresql/pg_hba.conf:ro
      - ../testsetup/certs:/etc/postgresql/ssl:ro
      - ../testsetup/postgresql_ssl.conf:/etc/postgresql/postgresql_ssl.conf:ro
      - pg-sockets:/var/run/postgresql
    network_mode: service:app
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: pgx_test
      POSTGRES_HOSTNAME: localhost
      PGPORT: 5414
    command: postgres -c port=5414 -c hba_file=/etc/postgresql/pg_hba.conf -c unix_socket_directories=/var/run/postgresql

  postgres-15:
    image: postgres:15
    restart: unless-stopped
    volumes:
      - postgres-15-data:/var/lib/postgresql
      - ../testsetup/postgresql_setup.sql:/docker-entrypoint-initdb.d/01-setup.sql:ro
      - ../testsetup/pg_ssl_init.sh:/docker-entrypoint-initdb.d/02-ssl-init.sh:ro
      - ../testsetup/pg_hba_devcontainer.conf:/etc/postgresql/pg_hba.conf:ro
      - ../testsetup/certs:/etc/postgresql/ssl:ro
      - ../testsetup/postgresql_ssl.conf:/etc/postgresql/postgresql_ssl.conf:ro
      - pg-sockets:/var/run/postgresql
    network_mode: service:app
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: pgx_test
      POSTGRES_HOSTNAME: localhost
      PGPORT: 5415
    command: postgres -c port=5415 -c hba_file=/etc/postgresql/pg_hba.conf -c unix_socket_directories=/var/run/postgresql

  postgres-16:
    image: postgres:16
    restart: unless-stopped
    volumes:
      - postgres-16-data:/var/lib/postgresql
      - ../testsetup/postgresql_setup.sql:/docker-entrypoint-initdb.d/01-setup.sql:ro
      - ../testsetup/pg_ssl_init.sh:/docker-entrypoint-initdb.d/02-ssl-init.sh:ro
      - ../testsetup/pg_hba_devcontainer.conf:/etc/postgresql/pg_hba.conf:ro
      - ../testsetup/certs:/etc/postgresql/ssl:ro
      - ../testsetup/postgresql_ssl.conf:/etc/postgresql/postgresql_ssl.conf:ro
      - pg-sockets:/var/run/postgresql
    network_mode: service:app
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: pgx_test
      POSTGRES_HOSTNAME: localhost
      PGPORT: 5416
    command: postgres -c port=5416 -c hba_file=/etc/postgresql/pg_hba.conf -c unix_socket_directories=/var/run/postgresql

  postgres-17:
    image: postgres:17
    restart: unless-stopped
    volumes:
      - postgres-17-data:/var/lib/postgresql
      - ../testsetup/postgresql_setup.sql:/docker-entrypoint-initdb.d/01-setup.sql:ro
      - ../testsetup/pg_ssl_init.sh:/docker-entrypoint-initdb.d/02-ssl-init.sh:ro
      - ../testsetup/pg_hba_devcontainer.conf:/etc/postgresql/pg_hba.conf:ro
      - ../testsetup/certs:/etc/postgresql/ssl:ro
      - ../testsetup/postgresql_ssl.conf:/etc/postgresql/postgresql_ssl.conf:ro
      - pg-sockets:/var/run/postgresql
    network_mode: service:app
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: pgx_test
      POSTGRES_HOSTNAME: localhost
      PGPORT: 5417
    command: postgres -c port=5417 -c hba_file=/etc/postgresql/pg_hba.conf -c unix_socket_directories=/var/run/postgresql

  postgres-18:
    image: postgres:18
    restart: unless-stopped
    volumes:
      - postgres-18-data:/var/lib/postgresql
      - ../testsetup/postgresql_setup.sql:/docker-entrypoint-initdb.d/01-setup.sql:ro
      - ../testsetup/pg_ssl_init.sh:/docker-entrypoint-initdb.d/02-ssl-init.sh:ro
      - ../testsetup/pg_hba_devcontainer.conf:/etc/postgresql/pg_hba.conf:ro
      - ../testsetup/certs:/etc/postgresql/ssl:ro
      - ../testsetup/postgresql_ssl.conf:/etc/postgresql/postgresql_ssl.conf:ro
      - pg-sockets:/var/run/postgresql
    network_mode: service:app
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: pgx_test
      POSTGRES_HOSTNAME: localhost
    command: postgres -c hba_file=/etc/postgresql/pg_hba.conf -c unix_socket_directories=/var/run/postgresql

  cockroachdb:
    image: cockroachdb/cockroach:v25.4.4
    restart: unless-stopped
    network_mode: service:app
    command: start-single-node --insecure --listen-addr=127.0.0.1:26257 --store=type=mem,size=1024MiB
