apiVersion: batch/v1
kind: Job
metadata:
    name: dbupgrade
    generateName: run-migration-
    annotations:
      argocd.argoproj.io/hook: PreSync
      argocd.argoproj.io/sync-wave: "1"
      argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
spec:
  activeDeadlineSeconds: 3000
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "false"
    spec:
        containers:
        - name: dbupgrade
          image: "{{ .Values.global.repository_backend }}:{{ .Values.global.tag_backend }}"
          env:
            - name: tenant_name
              value: ""
            - name: data_service_url
              value: "http://data-service-http.{{ .Values.global.namespace }}.svc.cluster.local"
            - name: file_system__name
              value: s3
            - name: file_system__params__bucket
              valueFrom:
                secretKeyRef:
                  name: app-secret
                  key: S3_FS_BUCKET
            - name: app
              value: romee
            - name: message_bus__url
              valueFrom:
                secretKeyRef:
                  name: app-secret
                  key: KATE_BROKER_URL
            - name: PYTHONPATH
              value: /volumes/dependencies/site-packages
            - name: ENV
              value: multi_tenant
            - name: SQLALCHEMY_DATABASE_URI
              valueFrom:
                secretKeyRef:
                  name: app-secret
                  key: SQLALCHEMY_DATABASE_URI
            - name: AWS_DEFAULT_REGION
              valueFrom:
                secretKeyRef:
                  name: aws-secret
                  key: AWS_DEFAULT_REGION
            - name: AWS_SECRET_ACCESS_KEY
              valueFrom:
                secretKeyRef:
                  name: aws-secret
                  key: AWS_SECRET_ACCESS_KEY
            - name: AWS_ACCESS_KEY_ID
              valueFrom:
                secretKeyRef:
                  name: aws-secret
                  key: AWS_ACCESS_KEY_ID  
            - name: S3_FS_BUCKET
              valueFrom:
                secretKeyRef:
                  name: app-secret
                  key: S3_FS_BUCKET                        
          imagePullPolicy: IfNotPresent
          command: ["bash",  "-c", " alembic --name db upgrade head"]
          resources:
            requests:
              memory: "1Gi"
              cpu: "1"
            limits:
              memory: "8Gi"
              cpu: "8"
        restartPolicy: Never
  backoffLimit: 5
