Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: update-materialized-views
spec:
entrypoint: update-materialized-views
serviceAccountName: {{ $.Values.common.workflowRbac.serviceAccountName }}
securityContext:
{{- include "common.security.podSecurityContext.restricted" dict | nindent 4 }}
templates:
- name: update-materialized-views
steps:
- - name: update-qty-document-in-qdrant
template: update-materialized-view
arguments:
parameters:
- name: view_name
value: qty_document_in_qdrant
- - name: update-qty-document-in-qdrant-per-corpus
template: update-materialized-view
arguments:
parameters:
- name: view_name
value: qty_document_in_qdrant_per_corpus
- - name: update-qty-document-per-corpus
template: update-materialized-view
arguments:
parameters:
- name: view_name
value: qty_document_per_corpus
- name: update-materialized-view
inputs:
parameters:
- name: view_name
script:
image: postgres:15
command: ["bash"]
source: |
#!/bin/bash
set -e
export DB_NAME="$PG_DATABASE"
export DB_USER="$PG_USER"
export DB_HOST="$PG_HOST"
export DB_PORT="$PG_PORT"
export DB_PASSWORD="$PG_PASSWORD"
export PGPASSWORD="$DB_PASSWORD"

psql "postgresql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME" \
-v ON_ERROR_STOP=1 \
-c "REFRESH MATERIALIZED VIEW CONCURRENTLY {{inputs.parameters.view_name}};"
envFrom:
- configMapRef:
name: {{ .name }}
volumeMounts:
Comment on lines +51 to +54
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This template references {{ .name }} for the ConfigMap/Secret name, but this file is not wrapped in a with .Values.<component> block like other templates, so .name will render as <no value> and break envFrom / secretName. Use a value that exists in the current scope (e.g. add a .Values.updateMaterializedViews.name and wrap the file in {{- with ... }}) and ensure the corresponding ConfigMap/Secret resources are created.

Copilot uses AI. Check for mistakes.
- name: secrets
mountPath: "/secrets"
readOnly: true

volumes:
- name: secrets
secret:
secretName: {{ .name }}
Comment on lines +60 to +62
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

volumes: is followed by a list item that is not indented under it, which makes this manifest invalid YAML. Indent the - name: secrets block so it is a child of volumes: (see other workflow templates in this chart for the expected indentation).

Suggested change
- name: secrets
secret:
secretName: {{ .name }}
- name: secrets
secret:
secretName: {{ .name }}

Copilot uses AI. Check for mistakes.
---
apiVersion: argoproj.io/v1alpha1
kind: CronWorkflow
metadata:
name: update-materialized-views-cron
spec:
schedule: "0 */3 * * *" # Every 3 hours
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this chart, other CronWorkflows use spec.schedules: [...] (array) rather than spec.schedule:. Using schedule here is inconsistent and may not be supported by the Argo version/configuration assumed elsewhere in the chart; align this field with the existing CronWorkflow templates.

Suggested change
schedule: "0 */3 * * *" # Every 3 hours
schedules:
- "0 */3 * * *" # Every 3 hours

Copilot uses AI. Check for mistakes.
securityContext:
{{- include "common.security.podSecurityContext.restricted" dict | nindent 6 }}
workflowSpec:
entrypoint: update-materialized-views
serviceAccountName: {{ $.Values.common.workflowRbac.serviceAccountName }}
workflowTemplateRef:
name: update-materialized-views
ttlStrategy:
secondsAfterCompletion: 300
podGC:
strategy: OnPodCompletion
36 changes: 36 additions & 0 deletions script/update-materialized-view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Script to update a materialized view in PostgreSQL

# Variables are passed as environment variables
DB_NAME=${DB_NAME} # PostgreSQL database name
DB_USER=${DB_USER} # PostgreSQL user
DB_HOST=${DB_HOST:-localhost} # Default to localhost if not set
DB_PORT=${DB_PORT:-5432} # Default to 5432 if not set
DB_PASSWORD=${DB_PASSWORD} # PostgreSQL password

Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script does not verify required connection env vars (DB_NAME/DB_USER/DB_PASSWORD) are set and non-empty. If any are missing, it will fail later with less actionable psql errors; add explicit checks with clear error messages before running the refresh.

Suggested change
# Validate required database connection environment variables
if [ -z "$DB_NAME" ]; then
echo "Error: DB_NAME environment variable is not set or empty." >&2
exit 1
fi
if [ -z "$DB_USER" ]; then
echo "Error: DB_USER environment variable is not set or empty." >&2
exit 1
fi
if [ -z "$DB_PASSWORD" ]; then
echo "Error: DB_PASSWORD environment variable is not set or empty." >&2
exit 1
fi

Copilot uses AI. Check for mistakes.
# Check if the view name is passed as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <materialized_view_name>"
exit 1
fi

VIEW_NAME=$1

# Function to refresh a materialized view
refresh_view() {
local view_name=$1
echo "Refreshing materialized view: $view_name"
PGPASSWORD="$DB_PASSWORD" psql -U "$DB_USER" -h "$DB_HOST" -p "$DB_PORT" -d "$DB_NAME" -c "REFRESH MATERIALIZED VIEW CONCURRENTLY $view_name;"
Comment on lines +20 to +24
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The view name is interpolated directly into SQL, which allows SQL injection if the argument is ever influenced by user input (and also breaks on identifiers needing quoting). Validate view_name against a strict identifier/schema regex and/or quote identifiers safely before building the REFRESH MATERIALIZED VIEW statement.

Suggested change
# Function to refresh a materialized view
refresh_view() {
local view_name=$1
echo "Refreshing materialized view: $view_name"
PGPASSWORD="$DB_PASSWORD" psql -U "$DB_USER" -h "$DB_HOST" -p "$DB_PORT" -d "$DB_NAME" -c "REFRESH MATERIALIZED VIEW CONCURRENTLY $view_name;"
# Validate the materialized view name (allow optional schema prefix).
if [[ ! "$VIEW_NAME" =~ ^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?$ ]]; then
echo "Invalid materialized view name: $VIEW_NAME" >&2
exit 1
fi
# Function to refresh a materialized view
refresh_view() {
local view_name=$1
# Construct a safely quoted identifier for use in SQL.
local view_name_sql
if [[ "$view_name" == *.* ]]; then
local schema=${view_name%%.*}
local name=${view_name#*.}
view_name_sql="\"${schema}\".\"${name}\""
else
view_name_sql="\"${view_name}\""
fi
echo "Refreshing materialized view: $view_name"
PGPASSWORD="$DB_PASSWORD" psql -U "$DB_USER" -h "$DB_HOST" -p "$DB_PORT" -d "$DB_NAME" -c "REFRESH MATERIALIZED VIEW CONCURRENTLY $view_name_sql;"

Copilot uses AI. Check for mistakes.
if [ $? -eq 0 ]; then
echo "Successfully refreshed $view_name"
else
echo "Failed to refresh $view_name" >&2
exit 1
fi
}

# Refresh the specified materialized view
refresh_view "$VIEW_NAME"

echo "Materialized view $VIEW_NAME refreshed successfully."