services:
  # Source database (data to clone FROM)
  source-db:
    image: postgres:18
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: source_db
    volumes:
      - ./test/fixtures/seed.sql:/docker-entrypoint-initdb.d/01-seed.sql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 2s
      timeout: 5s
      retries: 10

  # Test on PostgreSQL 14
  test-pg14:
    build:
      context: .
      args:
        PG_VERSION: "14"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
      SOURCE_CONNINFO: "host=source-db dbname=source_db user=postgres password=testpass"
    depends_on:
      source-db:
        condition: service_healthy

  # Test on PostgreSQL 15
  test-pg15:
    build:
      context: .
      args:
        PG_VERSION: "15"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
      SOURCE_CONNINFO: "host=source-db dbname=source_db user=postgres password=testpass"
    depends_on:
      source-db:
        condition: service_healthy

  # Test on PostgreSQL 16
  test-pg16:
    build:
      context: .
      args:
        PG_VERSION: "16"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
      SOURCE_CONNINFO: "host=source-db dbname=source_db user=postgres password=testpass"
    depends_on:
      source-db:
        condition: service_healthy

  # Test on PostgreSQL 17
  test-pg17:
    build:
      context: .
      args:
        PG_VERSION: "17"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
      SOURCE_CONNINFO: "host=source-db dbname=source_db user=postgres password=testpass"
    depends_on:
      source-db:
        condition: service_healthy

  # Test on PostgreSQL 18
  test-pg18:
    build:
      context: .
      args:
        PG_VERSION: "18"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
      SOURCE_CONNINFO: "host=source-db dbname=source_db user=postgres password=testpass"
    depends_on:
      source-db:
        condition: service_healthy

  # ---- Oracle -> PostgreSQL tests (pgclone.table_from_oracle) ----
  # Oracle Free is published for x86-64 only; on Apple Silicon it runs under
  # emulation (slow first start — enable Rosetta in Docker Desktop).
  oracle-db:
    image: gvenzl/oracle-free:23-slim-faststart
    platform: linux/amd64
    environment:
      ORACLE_PASSWORD: oracle
      APP_USER: app
      APP_USER_PASSWORD: apppass
    healthcheck:
      test: ["CMD", "healthcheck.sh"]
      interval: 10s
      timeout: 5s
      retries: 60
      start_period: 30s

  test-oracle-pg14:
    build:
      context: .
      dockerfile: Dockerfile.oracle
      args:
        PG_VERSION: "14"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
    depends_on:
      oracle-db:
        condition: service_healthy

  test-oracle-pg17:
    build:
      context: .
      dockerfile: Dockerfile.oracle
      args:
        PG_VERSION: "17"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
    depends_on:
      oracle-db:
        condition: service_healthy

  test-oracle-pg18:
    build:
      context: .
      dockerfile: Dockerfile.oracle
      args:
        PG_VERSION: "18"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
    depends_on:
      oracle-db:
        condition: service_healthy

  # ---- SQL Server -> PostgreSQL tests (pgclone.table_from_sqlserver) ----
  # The SQL Server image is published for x86-64 only; on Apple Silicon it runs
  # under emulation (enable Rosetta in Docker Desktop). Needs >= 2 GB RAM.
  sqlserver-db:
    image: mcr.microsoft.com/mssql/server:2022-latest
    platform: linux/amd64
    environment:
      ACCEPT_EULA: "Y"
      MSSQL_SA_PASSWORD: Pgclone_Test1
    healthcheck:
      test: ["CMD-SHELL", "timeout 2 bash -c '</dev/tcp/localhost/1433'"]
      interval: 10s
      timeout: 5s
      retries: 30
      start_period: 20s

  test-sqlserver-pg14:
    build:
      context: .
      dockerfile: Dockerfile.sqlserver
      args:
        PG_VERSION: "14"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
    depends_on:
      sqlserver-db:
        condition: service_healthy

  test-sqlserver-pg17:
    build:
      context: .
      dockerfile: Dockerfile.sqlserver
      args:
        PG_VERSION: "17"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
    depends_on:
      sqlserver-db:
        condition: service_healthy

  test-sqlserver-pg18:
    build:
      context: .
      dockerfile: Dockerfile.sqlserver
      args:
        PG_VERSION: "18"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
    depends_on:
      sqlserver-db:
        condition: service_healthy

  # ---- MySQL -> PostgreSQL tests (pgclone.table_from_mysql) ----
  # mysql_native_password keeps the test client simple (no RSA key exchange
  # needed on a non-TLS connection); the extension itself speaks whatever the
  # client library supports.
  mysql-db:
    image: mysql:8.0
    command: ["--default-authentication-plugin=mysql_native_password"]
    environment:
      MYSQL_ROOT_PASSWORD: Pgclone_Test1
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -uroot -pPgclone_Test1 --silent"]
      interval: 5s
      timeout: 5s
      retries: 40
      start_period: 15s

  test-mysql-pg14:
    build:
      context: .
      dockerfile: Dockerfile.mysql
      args:
        PG_VERSION: "14"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
    depends_on:
      mysql-db:
        condition: service_healthy

  test-mysql-pg17:
    build:
      context: .
      dockerfile: Dockerfile.mysql
      args:
        PG_VERSION: "17"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
    depends_on:
      mysql-db:
        condition: service_healthy

  test-mysql-pg18:
    build:
      context: .
      dockerfile: Dockerfile.mysql
      args:
        PG_VERSION: "18"
    environment:
      POSTGRES_PASSWORD: testpass
      POSTGRES_DB: target_db
    depends_on:
      mysql-db:
        condition: service_healthy
