# .github/workflows/db-checks.yml
# Nightly GitHub Actions job that opens a short-lived database
# connection using AlmaForge workload identity.
#
# permissions.id-token: write is the GitHub side of the contract. It
# tells the runner to mint an OIDC token the job can present. The
# ALMA_* env vars tell alma which Token to use and how to identify
# the workload.
name: orders-db-checks
on:
  schedule:
    - cron: '17 2 * * *'
  workflow_dispatch:
permissions:
  id-token: write
jobs:
  query:
    runs-on: ubuntu-latest
    env:
      ALMA_PROXY: almaforge.example.com:443
      ALMA_CLIENT_ID: ci-orders-readonly
      ALMA_JOIN_METHOD: github
    steps:
      - name: install alma
        run: curl -fL https://get.almaforge.com/install.sh | sh
      - name: run nightly query
        run: |
          alma db login --db-user=readonly --db-name=orders dev-orders-pg
          alma exec db/dev-orders-pg --user=readonly --db-name=orders \
            <<< "SELECT count(*) FROM orders;"
