apiVersion: batch/v1
kind: Job
metadata:
  name: postiz-temporal-schema-1-2-0-1
  labels:
    app.kubernetes.io/component: database
    app.kubernetes.io/name: temporal
    helm.sh/chart: temporal-1.2.0
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/instance: postiz
    app.kubernetes.io/version: "1.31.0"
    app.kubernetes.io/part-of: temporal
  annotations:
    "helm.sh/hook": pre-install,pre-upgrade
    "helm.sh/hook-weight": "0"
    "helm.sh/hook-delete-policy": before-hook-creation
spec:
  backoffLimit: 100
  ttlSecondsAfterFinished: 86400
  template:
    metadata:
      name: postiz-temporal-schema-1-2-0-1
      labels:
        app.kubernetes.io/component: database
        app.kubernetes.io/name: temporal
        helm.sh/chart: temporal-1.2.0
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/instance: postiz
        app.kubernetes.io/version: "1.31.0"
        app.kubernetes.io/part-of: temporal
    spec:
      serviceAccountName: default
      restartPolicy: OnFailure
      initContainers:
        - name: create-default-store
          image: "temporalio/admin-tools:1.31.0@sha256:3e68adcd54195a7c1222e99f2dbc32a4fdbf44ad69e3bb48e21e85c4bf417c2e"
          imagePullPolicy: IfNotPresent
          command: ['temporal-sql-tool', 'create-database']
          env:
            - name: SQL_PLUGIN
              value: postgres12
            - name: SQL_HOST
              value: postiz-postgresql-18-cluster-rw.postiz
            - name: SQL_PORT
              value: "5432"
            - name: SQL_DATABASE
              value: temporal
            - name: SQL_USER
              value: "postgres"
            - name: SQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postiz-postgresql-18-cluster-superuser
                  key: password
            - name: SQL_TLS
              value: "false"
        - name: manage-schema-default-store
          image: "temporalio/admin-tools:1.31.0@sha256:3e68adcd54195a7c1222e99f2dbc32a4fdbf44ad69e3bb48e21e85c4bf417c2e"
          imagePullPolicy: IfNotPresent
          command: ['sh', '-c']
          args:
            - temporal-sql-tool setup-schema -v 0.0 && temporal-sql-tool update-schema --schema-dir /etc/temporal/schema/postgresql/v12/temporal/versioned
          env:
            - name: SQL_PLUGIN
              value: postgres12
            - name: SQL_HOST
              value: postiz-postgresql-18-cluster-rw.postiz
            - name: SQL_PORT
              value: "5432"
            - name: SQL_DATABASE
              value: temporal
            - name: SQL_USER
              value: "postgres"
            - name: SQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postiz-postgresql-18-cluster-superuser
                  key: password
            - name: SQL_TLS
              value: "false"
          volumeMounts:
            - name: shims
              mountPath: /usr/local/sbin/temporal-elasticsearch-tool
              subPath: temporal-elasticsearch-tool
        - name: create-visibility-store
          image: "temporalio/admin-tools:1.31.0@sha256:3e68adcd54195a7c1222e99f2dbc32a4fdbf44ad69e3bb48e21e85c4bf417c2e"
          imagePullPolicy: IfNotPresent
          command: ['temporal-sql-tool', 'create-database']
          env:
            - name: SQL_PLUGIN
              value: postgres12
            - name: SQL_HOST
              value: postiz-postgresql-18-cluster-rw.postiz
            - name: SQL_PORT
              value: "5432"
            - name: SQL_DATABASE
              value: temporal_visibility
            - name: SQL_USER
              value: "postgres"
            - name: SQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postiz-postgresql-18-cluster-superuser
                  key: password
            - name: SQL_TLS
              value: "false"
        - name: manage-schema-visibility-store
          image: "temporalio/admin-tools:1.31.0@sha256:3e68adcd54195a7c1222e99f2dbc32a4fdbf44ad69e3bb48e21e85c4bf417c2e"
          imagePullPolicy: IfNotPresent
          command: ['sh', '-c']
          args:
            - temporal-sql-tool setup-schema -v 0.0 && temporal-sql-tool update-schema --schema-dir /etc/temporal/schema/postgresql/v12/visibility/versioned
          env:
            - name: SQL_PLUGIN
              value: postgres12
            - name: SQL_HOST
              value: postiz-postgresql-18-cluster-rw.postiz
            - name: SQL_PORT
              value: "5432"
            - name: SQL_DATABASE
              value: temporal_visibility
            - name: SQL_USER
              value: "postgres"
            - name: SQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postiz-postgresql-18-cluster-superuser
                  key: password
            - name: SQL_TLS
              value: "false"
          volumeMounts:
            - name: shims
              mountPath: /usr/local/sbin/temporal-elasticsearch-tool
              subPath: temporal-elasticsearch-tool
      containers:
        - name: done
          image: "temporalio/admin-tools:1.31.0@sha256:3e68adcd54195a7c1222e99f2dbc32a4fdbf44ad69e3bb48e21e85c4bf417c2e"
          imagePullPolicy: IfNotPresent
          command: ['sh', '-c', 'echo "Store setup completed"']
      volumes:
        - name: shims
          configMap:
            name: "postiz-temporal-shims"
            defaultMode: 0555
