services:
  # 메인 애플리케이션 DB
  postgres:
    image: postgis/postgis:17-3.5
    platform: linux/amd64
    container_name: incheon-postgres-local
    environment:
      POSTGRES_DB: incheon
      POSTGRES_USER: incheon
      POSTGRES_PASSWORD: incheon
      POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --locale=C"
    ports:
      - "5433:5432"
    volumes:
      - postgres_data_local:/var/lib/postgresql/data
      - ./init-scripts/01-main-schema.sh:/docker-entrypoint-initdb.d/01-main-schema.sh
      - ../../src/main/resources/db/01-schema.sql:/docker-entrypoint-initdb.d/02-schema.sql
      - ../../src/main/resources/db/02-data.sql:/docker-entrypoint-initdb.d/03-data.sql
      - ../../src/main/resources/db/03-g2f.sql:/docker-entrypoint-initdb.d/04-g2f.sql
    networks:
      - incheon-local
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U incheon -d incheon"]
      interval: 30s
      timeout: 10s
      retries: 3

  # 외부 DB 시뮬레이션용 (연동 테스트, 데이터 마이그레이션 등)
  postgres-external:
    image: postgis/postgis:16-3.4
    platform: linux/amd64
    container_name: incheon-postgres-external
    environment:
      POSTGRES_DB: incheon
      POSTGRES_USER: incheon
      POSTGRES_PASSWORD: incheon
      POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --locale=C"
    ports:
      - "15432:5432" # 외부 DB용 포트
    volumes:
      - postgres_external_data:/var/lib/postgresql/data
      - ./init-scripts/01-external-schema.sh:/docker-entrypoint-initdb.d/01-external-schema.sh
      - ../../src/main/resources/db-ext/01-schema.sql:/docker-entrypoint-initdb.d/02-schema.sql
      - ../../src/main/resources/db-ext/02-data.sql:/docker-entrypoint-initdb.d/03-data.sql
    networks:
      - incheon-local
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U incheon -d incheon"]
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  postgres_data_local:
    driver: local
  postgres_external_data:
    driver: local

networks:
  incheon-local:
    driver: bridge
