From 1e69999fcd43e6e13fef04e4ca81eff011fa28a2 Mon Sep 17 00:00:00 2001 From: dvirlabs Date: Mon, 8 Dec 2025 07:27:56 +0200 Subject: [PATCH] Update db-schema of my-recipes app --- .../templates/db-migration-job.yaml | 31 +-------- .../templates/db-schema-configmap.yaml | 69 ------------------- 2 files changed, 2 insertions(+), 98 deletions(-) diff --git a/charts/my-recipes-chart/templates/db-migration-job.yaml b/charts/my-recipes-chart/templates/db-migration-job.yaml index 065a4e5..bc0d442 100644 --- a/charts/my-recipes-chart/templates/db-migration-job.yaml +++ b/charts/my-recipes-chart/templates/db-migration-job.yaml @@ -1,30 +1,3 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ .Release.Name }}-db-migration - namespace: {{ .Values.global.namespace }} -data: - migrate.sql: | - -- Add made_by column if it doesn't exist - DO $$ - BEGIN - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_name = 'recipes' AND column_name = 'made_by' - ) THEN - ALTER TABLE recipes ADD COLUMN made_by TEXT; - END IF; - END $$; - - -- Create index if it doesn't exist - CREATE INDEX IF NOT EXISTS idx_recipes_made_by ON recipes (made_by); - - -- Verify schema - SELECT column_name, data_type - FROM information_schema.columns - WHERE table_name = 'recipes' - ORDER BY ordinal_position; ---- apiVersion: batch/v1 kind: Job metadata: @@ -34,8 +7,8 @@ metadata: app: {{ .Release.Name }}-db-migration component: migration annotations: - "helm.sh/hook": post-upgrade,post-install - "helm.sh/hook-weight": "5" + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-weight": "-5" "helm.sh/hook-delete-policy": before-hook-creation spec: ttlSecondsAfterFinished: 300 diff --git a/charts/my-recipes-chart/templates/db-schema-configmap.yaml b/charts/my-recipes-chart/templates/db-schema-configmap.yaml index 1063dd9..ad62dec 100644 --- a/charts/my-recipes-chart/templates/db-schema-configmap.yaml +++ b/charts/my-recipes-chart/templates/db-schema-configmap.yaml @@ -71,72 +71,3 @@ data: FROM information_schema.columns WHERE table_name = 'recipes' ORDER BY ordinal_position; ---- -apiVersion: batch/v1 -kind: Job -metadata: - name: {{ .Release.Name }}-db-migration-{{ .Release.Revision }} - namespace: {{ .Values.global.namespace }} - labels: - app: {{ .Release.Name }}-db-migration - component: migration - annotations: - "helm.sh/hook": pre-install,pre-upgrade - "helm.sh/hook-weight": "-5" - "helm.sh/hook-delete-policy": before-hook-creation -spec: - ttlSecondsAfterFinished: 300 - template: - metadata: - labels: - app: {{ .Release.Name }}-db-migration - spec: - restartPolicy: Never - containers: - - name: migrate - image: postgres:16-alpine - command: - - /bin/sh - - -c - - | - echo "Waiting for database to be ready..." - until pg_isready -h $DB_HOST -U $DB_USER; do - echo "Database not ready, waiting..." - sleep 2 - done - echo "Database is ready, running migration..." - PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -U $DB_USER -d $DB_NAME -f /migration/migrate.sql - echo "Migration completed successfully" - env: - - name: DB_HOST - valueFrom: - secretKeyRef: - name: {{ .Release.Name }}-db-credentials - key: DB_HOST - - name: DB_PORT - valueFrom: - secretKeyRef: - name: {{ .Release.Name }}-db-credentials - key: DB_PORT - - name: DB_NAME - valueFrom: - secretKeyRef: - name: {{ .Release.Name }}-db-credentials - key: DB_NAME - - name: DB_USER - valueFrom: - secretKeyRef: - name: {{ .Release.Name }}-db-credentials - key: DB_USER - - name: DB_PASSWORD - valueFrom: - secretKeyRef: - name: {{ .Release.Name }}-db-credentials - key: DB_PASSWORD - volumeMounts: - - name: migration-script - mountPath: /migration - volumes: - - name: migration-script - configMap: - name: {{ .Release.Name }}-db-migration