# docker-compose-upgrade.yml — Upgrade Testing (Postgres)
#
# Two-phase environment: run the "old" image to seed data, then
# swap in the "new" image and verify data integrity post-upgrade.
#
# Usage:
#   ci/e2e-upgrade-test.sh   (orchestrates build → seed → upgrade → verify)
#
# Manual usage:
#   docker build -t switchboard-core:v-old .
#   docker compose -f docker-compose-upgrade.yml up postgres switchboard-old -d
#   # ... seed data ...
#   docker compose -f docker-compose-upgrade.yml stop switchboard-old
#   docker compose -f docker-compose-upgrade.yml up switchboard-new -d
#   # ... verify data ...
#   docker compose -f docker-compose-upgrade.yml down -v

services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: switchboard_upgrade
      POSTGRES_USER: switchboard
      POSTGRES_PASSWORD: upgrade-password
    ports:
      - "5433:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U switchboard -d switchboard_upgrade"]
      interval: 2s
      timeout: 5s
      retries: 10

  switchboard-old:
    image: switchboard-core:v-old
    environment:
      PORT: "8080"
      BASE_PATH: ""
      DB_DRIVER: postgres
      DATABASE_URL: postgres://switchboard:upgrade-password@postgres:5432/switchboard_upgrade?sslmode=disable
      JWT_SECRET: upgrade-jwt-secret
      ENCRYPTION_KEY: upgrade-encryption-key-32chars!!
      SWITCHBOARD_ADMIN_USERNAME: admin
      SWITCHBOARD_ADMIN_PASSWORD: admin
      STORAGE_BACKEND: pvc
      STORAGE_PATH: /data/storage
      CORS_ALLOWED_ORIGINS: "*"
      EXT_ALLOW_PRIVATE_IPS: "true"
      LOG_FORMAT: text
      LOG_LEVEL: info
      SEED_USERS: "alice:password123:user,bob:password456:user"
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - "3001:80"
    volumes:
      - upgrade_storage:/data/storage

  switchboard-new:
    image: core-switchboard-new
    environment:
      PORT: "8080"
      BASE_PATH: ""
      DB_DRIVER: postgres
      DATABASE_URL: postgres://switchboard:upgrade-password@postgres:5432/switchboard_upgrade?sslmode=disable
      JWT_SECRET: upgrade-jwt-secret
      ENCRYPTION_KEY: upgrade-encryption-key-32chars!!
      SWITCHBOARD_ADMIN_USERNAME: admin
      SWITCHBOARD_ADMIN_PASSWORD: admin
      STORAGE_BACKEND: pvc
      STORAGE_PATH: /data/storage
      CORS_ALLOWED_ORIGINS: "*"
      EXT_ALLOW_PRIVATE_IPS: "true"
      LOG_FORMAT: text
      LOG_LEVEL: info
      SEED_USERS: "alice:password123:user,bob:password456:user"
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - "3001:80"
    volumes:
      - upgrade_storage:/data/storage

volumes:
  upgrade_storage:
