fix(postgresql): init job correct quote

This commit is contained in:
WrenIX 2024-02-13 19:47:19 +01:00
parent 2198203fe9
commit b41a2a9f45
Signed by: wrenix
GPG key ID: 7AFDB012974B1BB5
5 changed files with 19 additions and 11 deletions

View file

@ -4,7 +4,7 @@ name: "postgresql"
description: "A Helm chart for running PostgreSQL (Postgres) database"
icon: https://wiki.postgresql.org/images/a/a4/PostgreSQL_logo.3colors.svg
type: "application"
version: "0.1.6"
version: "0.1.7"
# renovate: image=docker.io/library/postgres
appVersion: "16.1-alpine"
maintainers:

View file

@ -2,7 +2,7 @@
= postgresql
image::https://img.shields.io/badge/Version-0.1.6-informational?style=flat-square[Version: 0.1.6]
image::https://img.shields.io/badge/Version-0.1.7-informational?style=flat-square[Version: 0.1.7]
image::https://img.shields.io/badge/Version-application-informational?style=flat-square[Type: application]
image::https://img.shields.io/badge/AppVersion-16.1-alpine-informational?style=flat-square[AppVersion: 16.1-alpine]
== Maintainers

View file

@ -0,0 +1,8 @@
job:
users:
user-name: "RandomPassword0#"
databases:
"name_of_database":
owner: "existing_user_which_will_get_grant"
additionalParams: ""

View file

@ -1,10 +1,10 @@
{{- range $username, $password := .Values.job.users }}
echo 'user "{{ $username }}":'
psql -tc "SELECT 1 FROM pg_user WHERE usename = '{{ $username }}'" | grep -q 1;
echo 'user {{ $username | quote }}:'
psql -tc "SELECT 1 FROM pg_user WHERE usename = {{ $username | squote }}" | grep -q 1;
if [ $? -ne 0 ]; then
psql -c "CREATE USER {{ $username }} WITH ENCRYPTED PASSWORD '{{ $password }}'";
psql -c "CREATE USER \"{{ $username }}\" WITH ENCRYPTED PASSWORD {{ $password | squote }}";
else
psql -c "ALTER USER {{ $username }} WITH ENCRYPTED PASSWORD '{{ $password }}'";
psql -c "ALTER USER \"{{ $username }}\" WITH ENCRYPTED PASSWORD {{ $password | squote }}";
fi
echo ""
{{- end }}

View file

@ -1,10 +1,10 @@
{{- range $name, $config := .Values.job.databases }}
echo 'database "{{ $name }}":'
psql -tc "SELECT 1 FROM pg_database WHERE datname = '{{ $name }}'" | grep -q 1
echo 'database {{ $name | quote }}:'
psql -tc "SELECT 1 FROM pg_database WHERE datname = {{ $name | squote }}" | grep -q 1
if [ $? -ne 0 ]; then
psql -c "CREATE DATABASE {{ $name }} {{ with $config.additionalParams }}{{ . }} {{ end }}";
psql -c 'CREATE DATABASE {{ $name | quote }} {{ with $config.additionalParams }}{{ . }} {{ end }}';
fi
psql -c "ALTER DATABASE {{ $name }} OWNER TO {{ $config.owner }}";
psql -c "GRANT ALL PRIVILEGES ON DATABASE {{ $name }} TO {{ $config.owner }}";
psql -c 'ALTER DATABASE {{ $name | quote }} OWNER TO {{ $config.owner | quote }}';
psql -c 'GRANT ALL PRIVILEGES ON DATABASE {{ $name | quote }} TO {{ $config.owner | quote }}';
echo ""
{{- end }}