name: Alembic Migration Tester
on:
  pull_request:
    paths:
      - '**.py'
  workflow_dispatch:
jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    services:
      postgres:
        image: pgvector/pgvector:pg17
        ports:
          - 5432:5432
        env:
          POSTGRES_HOST_AUTH_METHOD: trust
          POSTGRES_DB: postgres
          POSTGRES_USER: postgres
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - run: psql -h localhost -U postgres -d postgres -c 'CREATE EXTENSION vector'

      - name: Set up python 3.11
        id: setup-python
        uses: actions/setup-python@v5
        with:
          python-version: 3.11

      - name: Install uv
        run: |
          curl -LsSf https://astral.sh/uv/install.sh | sh
          echo "$HOME/.cargo/bin" >> $GITHUB_PATH

      - name: Install Dependencies
        run: |
          uv sync --all-extras

      - name: Test alembic migration
        env:
          LETTA_PG_PORT: 5432
          LETTA_PG_USER: postgres
          LETTA_PG_PASSWORD: postgres
          LETTA_PG_DB: postgres
          LETTA_PG_HOST: localhost
        run: |
          uv run alembic upgrade head
          uv run alembic check
