-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/populate materailized view #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1b9291f
c00310f
00c3bb1
29855d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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: | ||||||||||||||
| - name: secrets | ||||||||||||||
| mountPath: "/secrets" | ||||||||||||||
| readOnly: true | ||||||||||||||
|
|
||||||||||||||
| volumes: | ||||||||||||||
| - name: secrets | ||||||||||||||
| secret: | ||||||||||||||
| secretName: {{ .name }} | ||||||||||||||
|
Comment on lines
+60
to
+62
|
||||||||||||||
| - name: secrets | |
| secret: | |
| secretName: {{ .name }} | |
| - name: secrets | |
| secret: | |
| secretName: {{ .name }} |
Copilot
AI
Feb 20, 2026
There was a problem hiding this comment.
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.
| schedule: "0 */3 * * *" # Every 3 hours | |
| schedules: | |
| - "0 */3 * * *" # Every 3 hours |
| 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # 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
AI
Feb 20, 2026
There was a problem hiding this comment.
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.
| # 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;" |
There was a problem hiding this comment.
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 awith .Values.<component>block like other templates, so.namewill render as<no value>and breakenvFrom/secretName. Use a value that exists in the current scope (e.g. add a.Values.updateMaterializedViews.nameand wrap the file in{{- with ... }}) and ensure the corresponding ConfigMap/Secret resources are created.