apiVersion: batch/v1
kind: Job
metadata:
  name: clean-and-migrate-user-research-env
spec:
  template:
    spec:
      securityContext:
        runAsUser: 100
      containers:
        - name: clean-and-migrate-user-research-env
          image: flyway/flyway:7.7.0-alpine
          env:
            - name: POSTGRES_URI
              valueFrom:
                secretKeyRef:
                  name: postgres
                  key: rds_instance_endpoint
            - name: POSTGRES_DB
              valueFrom:
                secretKeyRef:
                  name: postgres
                  key: database_name
            - name: POSTGRES_USERNAME
              valueFrom:
                secretKeyRef:
                  name: postgres
                  key: database_username
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgres
                  key: database_password
          command: ["flyway", "-url=jdbc:postgresql://$(POSTGRES_URI)/$(POSTGRES_DB)", "-user=$(POSTGRES_USERNAME)", "-password=$(POSTGRES_PASSWORD)", "clean"]
      restartPolicy: Never
  backoffLimit: 4
