apiVersion: batch/v1
kind: Job
metadata:
  name: postcard-create-schema
spec:
  template:
    spec:
      containers:
        - name: postcard-postgres-create-schema
          image: postcard-postgres
          command: ['/bin/sh', '-c']
          args: [
            'PGPASSWORD=$$(cat /run/secrets/POSTCARD_POSTGRES_PASSWORD) psql --no-password --host=$$POSTCARD_POSTGRES_HOST --port=$$POSTCARD_POSTGRES_PORT --username=$$POSTCARD_POSTGRES_USER --dbname=$$POSTCARD_POSTGRES_DB -f /database-schema.sql;',
          ]
          envFrom:
            - configMapRef:
                name: postcard-environment
          volumeMounts:
            - name: postcard-config
              mountPath: '/database-schema.sql'
              readOnly: true
              subPath: database-schema.sql
            - name: postcard-secret
              mountPath: '/run/secrets/POSTCARD_POSTGRES_PASSWORD'
              readOnly: true
              subPath: POSTCARD_POSTGRES_PASSWORD
      restartPolicy: OnFailure
      volumes:
        - name: postcard-config
          configMap:
            name: postcard-config
            items:
              - key: database-schema.sql
                path: database-schema.sql
        - name: postcard-secret
          secret:
            secretName: postcard-secret
            items:
              - key: POSTCARD_POSTGRES_PASSWORD
                path: POSTCARD_POSTGRES_PASSWORD
