From a628f9044f9a199b11504788249c27f4a798a7e9 Mon Sep 17 00:00:00 2001 From: u1 Date: Sat, 10 Jan 2026 00:52:10 +0000 Subject: [PATCH] feat(db): add postgres migrate job --- kustomize/base/postgres/job-migrate.yaml | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 kustomize/base/postgres/job-migrate.yaml diff --git a/kustomize/base/postgres/job-migrate.yaml b/kustomize/base/postgres/job-migrate.yaml new file mode 100644 index 0000000..e09e3fb --- /dev/null +++ b/kustomize/base/postgres/job-migrate.yaml @@ -0,0 +1,36 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: postgres-migrate + annotations: + argocd.argoproj.io/hook: Sync + argocd.argoproj.io/hook-delete-policy: BeforeHookCreation,HookSucceeded + argocd.argoproj.io/sync-wave: "2" +spec: + backoffLimit: 3 + template: + spec: + restartPolicy: OnFailure + containers: + - name: postgres-migrate + image: postgres:16 + imagePullPolicy: IfNotPresent + envFrom: + - secretRef: + name: trade-postgres + command: + - sh + - -ec + - | + export PGPASSWORD="$POSTGRES_PASSWORD" + until pg_isready -h postgres -U "$POSTGRES_USER" -d "$POSTGRES_DB"; do sleep 1; done + psql -h postgres -U "$POSTGRES_USER" -d "$POSTGRES_DB" -v ON_ERROR_STOP=1 -f /migrations/001_init.sql + volumeMounts: + - name: migrations + mountPath: /migrations/001_init.sql + subPath: 001_init.sql + readOnly: true + volumes: + - name: migrations + configMap: + name: postgres-initdb