diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6b191eb6..6dad4957 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest services: postgres: - image: postgres:12 + image: postgres:15 env: POSTGRES_PASSWORD: postgres POSTGRES_HOST_AUTH_METHOD: trust @@ -50,7 +50,7 @@ jobs: env: CTMS_DB_URL: postgresql://postgres:postgres@172.17.0.1:5432/postgres # pragma: allowlist secret CTMS_SECRET_KEY: secret_${{ github.sha }} # pragma: allowlist secret - + build_production_image: runs-on: ubuntu-latest steps: @@ -58,7 +58,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Build production image + - name: Build production image uses: docker/build-push-action@v6 with: context: . diff --git a/ctms/crud.py b/ctms/crud.py index 0896f4f5..9a5382ee 100644 --- a/ctms/crud.py +++ b/ctms/crud.py @@ -59,12 +59,18 @@ def count_total_contacts(db: Session) -> int: This metadata is refreshed on `VACUUM` or `ANALYSIS` which is run regularly by default on our database instances. """ - query = text( - "SELECT reltuples AS estimate " - "FROM pg_class " - f"where relname = '{Email.__tablename__}'" - ) - result = db.execute(query).scalar() + result = db.execute( + text( + "SELECT reltuples AS estimate " + "FROM pg_class " + f"where relname = '{Email.__tablename__}'" + ) + ).scalar() + if result is None or result < 0: + # Fall back to a full count if the estimate is not available. + result = db.execute( + text(f"SELECT COUNT(*) FROM {Email.__tablename__}") + ).scalar() if result is None: return -1 return int(result) diff --git a/docker-compose.yaml b/docker-compose.yaml index 7cb3b044..10233aef 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -22,7 +22,7 @@ services: timeout: 1s retries: 10 postgres: - image: postgres:12 + image: postgres:15 ports: - 5432:5432 environment: