apiVersion: batch/v1
kind: Job
metadata:
  name: archive-db-bootstrap
spec:
  template:
    spec:
      containers:
      - name: create-db
        image: bitnami/postgresql
        command: ["bash", "-c"]
        args: ["PGPASSWORD={{ .Values.postgresql.postgresqlPassword }} createdb --username {{ .Values.postgresql.postgresqlUsername }} --host {{ tpl .Values.archive.postgresHost . }} --port {{ .Values.archive.postgresPort }} --echo {{ .Values.archive.postgresDB}}"]
      - name: import-schema
        image: bitnami/postgresql
        command: ["bash", "-c"]
        args: ["PGPASSWORD={{ .Values.postgresql.postgresqlPassword }} psql --username {{ .Values.postgresql.postgresqlUsername }} --host {{ tpl .Values.archive.postgresHost . }} --port {{ .Values.archive.postgresPort }} --dbname {{ .Values.archive.postgresDB}} -f <(curl -Ls {{ .Values.archive.remoteSchemaFile }})"]
      restartPolicy: Never
  backoffLimit: 10
