apiVersion: batch/v1
kind: Job
metadata:
  name: gumbo-schema-init
  namespace: ai-agents-gumbo
  annotations:
    argocd.argoproj.io/hook: PreSync
    argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
  template:
    spec:
      restartPolicy: OnFailure
      containers:
        - name: schema-init
          image: postgres:16-alpine
          command:
            - sh
            - -c
            - |
              psql "$PGURL" -c "
              CREATE TABLE IF NOT EXISTS gumbo_summaries (
                id bigserial PRIMARY KEY,
                workflow_id text NOT NULL,
                object_key text NOT NULL,
                summary text NOT NULL,
                created_at timestamptz NOT NULL DEFAULT now()
              );"
          env:
            - name: PGURL
              valueFrom:
                secretKeyRef:
                  name: gumbo-results-db
                  key: dsn
            - name: PGDATABASE
              value: gumbo
