apiVersion: v1
kind: Pod
metadata:
  name: create-batch2-tables
spec:
  containers:
  - name: create-batch2-tables
    image: "{{ batch2_tables_image.image }}"
    command:
     - /bin/bash
     - -c
     - |
       set -ex
       # index creation isn't idempotent, don't create if a table exists
       JOBS=$(echo "SHOW TABLES LIKE 'jobs';" | mysql --defaults-extra-file=/secrets/batch-admin/sql-config.cnf -s)
       if [ "$JOBS" != "jobs" ]; then
         mysql --defaults-extra-file=/secrets/batch-admin/sql-config.cnf < ./create-batch-tables.sql
       fi
    volumeMounts:
      - mountPath: /secrets/batch-admin
        readOnly: true
        name: batch2-admin-secret
  volumes:
    - name: batch2-admin-secret
      secret:
        secretName: "{{ batch2_database.admin_secret_name }}"
  restartPolicy: Never
