kind: Job
apiVersion: batch/v1
metadata:
  name: fritzbox-migrate-schema
  annotations:
    argocd.argoproj.io/hook: PostSync
    argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
    helm.sh/hook: post-install,post-upgrade
    helm.sh/hook-delete-policy: before-hook-creation

spec:
  backoffLimit: 1000
  completions: 1
  parallelism: 1

  template:
    spec:
      restartPolicy: OnFailure
      containers:
        - name: migrate
          image: docker.io/liquibase/liquibase:4.5
          env:
            - name: USERNAME
              valueFrom:
                secretKeyRef:
                  name: timescaledb-secret
                  key: admin.username
            - name: PASSWORD
              valueFrom:
                secretKeyRef:
                  name: timescaledb-secret
                  key: admin.password
            - name: DATABASE
              valueFrom:
                configMapKeyRef:
                  name: timescaledb-config
                  key: databaseName
          args:
            - --url=jdbc:postgresql://timescaledb:5432/$(DATABASE)?ssl=false
            - --driver=org.postgresql.Driver
            - --changeLogFile=changelog.sql
            - --username=$(USERNAME)
            - --password=$(PASSWORD)
            - --log-level=debug
            - update
          volumeMounts:
            - mountPath: /liquibase/changelog
              name: schema
      volumes:
        - name: schema
          configMap:
            name: fritzbox-schema
