# 05-cronjobs — jobGroups for migrations (Job, PreSync hook) and nightly (CronJob).

jobGroups:

  migrations:
    enabled: true
    kind: Job
    image:
      repository: ghcr.io/example/migrator
      tag: v1.0.0
      pullPolicy: IfNotPresent
    envSecrets:
      - db-credentials                # carries DB_PASSWORD
    hooks:
      argocd:
        hook: PreSync
        syncWave: "-2"                # run before app workloads
        deletePolicy: BeforeHookCreation   # safe with hashSuffix: false; here keep default
    backoffLimit: 2
    ttlSecondsAfterFinished: 3600
    hashSuffix: true
    jobs:
      schema:
        enabled: true
        # Tasks mode — each task becomes an initContainer in the rendered Job pod.
        # Kubernetes runs initContainers sequentially in declared order, and the
        # chart sorts the tasks map alphabetically; the 01-/02- prefix locks the
        # run order to "structure first, then seed".
        tasks:
          01-structure:
            command: |
              psql -c "CREATE TABLE IF NOT EXISTS schema_version (id SERIAL PRIMARY KEY)"
          02-seed:
            args:
              - "seed"
              - "--rows=100"

  nightly:
    enabled: true
    kind: CronJob
    image:
      repository: ghcr.io/example/maintenance
      tag: v0.5.0
    env:
      LOG_LEVEL:
        value: info
    jobs:
      cleanup:
        enabled: true
        schedule: "0 2 * * *"
        timeZone: UTC
        concurrencyPolicy: Forbid
        successfulJobsHistoryLimit: 3
        failedJobsHistoryLimit: 1
        command: ./cleanup.sh
        backoffLimit: 1
      report:
        enabled: true
        schedule: "0 6 * * *"
        timeZone: UTC
        concurrencyPolicy: Replace
        successfulJobsHistoryLimit: 7
        failedJobsHistoryLimit: 3
        command: ./report.sh
        backoffLimit: 0
