apiVersion: batch/v1
kind: Job
metadata:
  name: lti-db-migrate
  namespace: dev-lti
  annotations:
    argocd.argoproj.io/hook: PreSync
    argocd.argoproj.io/hook-delete-policy: BeforeHookCreation,HookSucceeded
spec:
  backoffLimit: 1
  ttlSecondsAfterFinished: 300
  template:
    spec:
      restartPolicy: Never
      containers:
        - name: migrate
          image: 886436954922.dkr.ecr.ap-southeast-3.amazonaws.com/mbugroup/lti-api:dev-f8ca404b
          imagePullPolicy: IfNotPresent
          command: ["/bin/sh", "-c"]
          args:
            - |
              set -eu
              DATABASE_URL="postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=${DB_SSLMODE:-disable}"
              echo "Running migrations on ${DB_HOST}:${DB_PORT}/${DB_NAME}"
              /app/migrate -path /app/migrations -database "$DATABASE_URL" up
          envFrom:
            - secretRef:
                name: lti-env-dev
