apiVersion: batch/v1
kind: Job

metadata:
  name: db-migrate
  annotations:
    # Now that we have mandated that database migrations should be
    # forwards-compatible, this can be run concurrently with the rest of
    # the deployments.
    argocd.argoproj.io/hook: Sync
    argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
spec:
  template:
    metadata:
      labels:
        app.kubernetes.io/name: db-migrate
        app.kubernetes.io/part-of: frontend
    spec:
      containers:
      - name: db-migrate
        image: omegaup/frontend-sidecar
        imagePullPolicy: IfNotPresent
        command: [
          '/opt/omegaup/stuff/db-migrate.py',
          '--verbose',
          '--log-json',
          '--lower-timeout',
          '--kill-blocking-connections',
          '--username=root',
          '--password=omegaup',
          '--hostname=mysql-service',
          '--port=3306',
          'migrate',
          '--databases=omegaup',
        ]
        volumeMounts:
        - name: omegaup
          mountPath: /opt/omegaup
      initContainers:
      - name: init-volume
        image: omegaup/frontend
        imagePullPolicy: IfNotPresent
        command: ['rsync', '-az', '/opt/omegaup/', '/mnt/omegaup/']
        volumeMounts:
        - name: omegaup
          mountPath: /mnt/omegaup
      volumes:
      - name: omegaup
        emptyDir: {}
      restartPolicy: Never
  parallelism: 1
  completions: 1
  backoffLimit: 1
