apiVersion: batch/v1
kind: Job
metadata:
  name: init-schema
spec:
  template:
    spec:
      restartPolicy: Never
      containers:
        - name: init
          image: postgres:16
          command: ["sh", "-c"]
          args:
            - |
              PGPASSWORD=$POSTGRES_PASSWORD psql \
                -h cameleer-postgres.cameleer.svc.cluster.local \
                -U $POSTGRES_USER -d cameleer \
                -c "CREATE SCHEMA IF NOT EXISTS BRANCH_SCHEMA"
          env:
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: cameleer-postgres-credentials
                  key: POSTGRES_USER
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: cameleer-postgres-credentials
                  key: POSTGRES_PASSWORD
  backoffLimit: 3
