Skip to content

Commit 1edcdbc

Browse files
committed
Skip database creation on repeated migration job runs (#35)
Signed-off-by: Imtiaz Uddin <imtiaz@appscode.com>
1 parent 1176711 commit 1edcdbc

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

charts/inbox-server/templates/job.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,19 @@ spec:
4949
secretKeyRef:
5050
name: "{{ .Values.postgresql.auth.secretName }}"
5151
key: password
52+
command:
53+
- /bin/sh
5254
args:
53-
- psql
5455
- -c
55-
- "CREATE DATABASE {{ .Values.postgresql.auth.database }} WITH ENCODING 'UTF8' OWNER postgres;"
56+
- |
57+
DBNAME="{{ .Values.postgresql.auth.database }}";
58+
echo "Checking if database $DBNAME exists...";
59+
if [ "$(psql -tAc "SELECT 1 FROM pg_database WHERE datname='$DBNAME'" )" != "1" ]; then
60+
echo "Database $DBNAME does not exist. Creating...";
61+
psql -c "CREATE DATABASE $DBNAME WITH ENCODING 'UTF8' OWNER postgres;";
62+
else
63+
echo "Database $DBNAME already exists.";
64+
fi
5665
resources:
5766
{{- toYaml .Values.migrate.resources | nindent 12 }}
5867
{{- with .Values.migrate.nodeSelector }}

0 commit comments

Comments
 (0)