feat: auto-run migrations via psql init container on scheduler startup
ci/woodpecker/push/woodpecker Pipeline failed
Build and Push / lint-and-test (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.adapters.broker_adapter name:broker-adapter]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.aggregation.worker name:aggregation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.extractor.worker name:extractor]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.ingestion.worker name:ingestion]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.lake_publisher.worker name:lake-publisher]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.parser.worker name:parser]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.recommendation.worker name:recommendation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.scheduler.app name:scheduler]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.api.app:app --host 0.0.0.0 --port 8000 name:query-api]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.risk.app:app --host 0.0.0.0 --port 8000 name:risk]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.symbol_registry.app:app --host 0.0.0.0 --port 8000 name:symbol-registry]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.trading.app:app --host 0.0.0.0 --port 8000 name:trading-engine]) (push) Has been cancelled
Build and Push / build-dashboard (push) Has been cancelled
Build and Push / build-superset (push) Has been cancelled
Build and Push / integration-test (push) Has been cancelled

This commit is contained in:
Celes Renata
2026-04-19 22:37:50 +00:00
parent 5c63264393
commit 021efba294
3 changed files with 49 additions and 4 deletions
@@ -28,6 +28,38 @@ spec:
{{- end }}
securityContext:
{{- include "stonks.podSecurityContext" $root | nindent 8 }}
{{- if eq $svc.image "scheduler" }}
initContainers:
- name: run-migrations
image: {{ $root.Values.image.registry }}/{{ $svc.image }}:{{ $root.Values.image.tag }}
imagePullPolicy: {{ $root.Values.image.pullPolicy }}
command: ["sh", "-c"]
args:
- |
for f in $(ls /app/infra/migrations/*.sql 2>/dev/null | sort); do
echo "Applying $(basename $f)..."
PGPASSWORD="$POSTGRES_PASSWORD" psql \
-h "$POSTGRES_HOST" -p "$POSTGRES_PORT" \
-U "$POSTGRES_USER" -d "$POSTGRES_DB" \
-f "$f" -v ON_ERROR_STOP=0 2>&1 | tail -1 || true
done
echo "Migrations complete."
securityContext:
{{- include "stonks.containerSecurityContext" $root | nindent 12 }}
envFrom:
- configMapRef:
name: stonks-config
{{- range $svc.secrets }}
- secretRef:
name: {{ . }}
{{- end }}
resources:
requests: { cpu: 50m, memory: 64Mi }
limits: { cpu: 200m, memory: 128Mi }
volumeMounts:
- name: tmp
mountPath: /tmp
{{- end }}
containers:
- name: {{ $svc.image }}
image: {{ $root.Values.image.registry }}/{{ $svc.image }}:{{ $root.Values.image.tag }}