fix: use configurable db username in dbinit job instead of hardcoded root

Root user doesn't have access on external DB. Now uses the same
database username helper as the main deployment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sagar Patil 2026-04-09 16:40:49 +05:30
parent e7899972e2
commit 53d86cd48b

View File

@ -50,12 +50,12 @@ spec:
- name: MYSQL_DATABASE - name: MYSQL_DATABASE
value: {{ include "hades.databaseName" . | quote }} value: {{ include "hades.databaseName" . | quote }}
- name: MYSQL_USER - name: MYSQL_USER
value: "root" value: {{ include "hades.databaseUsername" . | quote }}
- name: MYSQL_PWD - name: MYSQL_PWD
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: {{ include "hades.databaseSecretName" . }} name: {{ include "hades.databaseSecretName" . }}
key: mysql-root-password key: mysql-password
command: command:
- /bin/bash - /bin/bash
- -c - -c
@ -72,7 +72,7 @@ spec:
# Test connection # Test connection
echo "Testing database connection..." echo "Testing database connection..."
if ! mysql -h"${MYSQL_HOST}" -P"${MYSQL_PORT}" -u"root" -e "SELECT 1" "${MYSQL_DATABASE}" &> /dev/null; then if ! mysql -h"${MYSQL_HOST}" -P"${MYSQL_PORT}" -u"${MYSQL_USER}" -e "SELECT 1" "${MYSQL_DATABASE}" &> /dev/null; then
echo "ERROR: Cannot connect to database" echo "ERROR: Cannot connect to database"
exit 1 exit 1
fi fi
@ -94,7 +94,7 @@ spec:
echo -n "Applying $filename... " echo -n "Applying $filename... "
if mysql -h"${MYSQL_HOST}" -P"${MYSQL_PORT}" -u"root" "${MYSQL_DATABASE}" < "$sql_file" 2>/tmp/migration_error.log; then if mysql -h"${MYSQL_HOST}" -P"${MYSQL_PORT}" -u"${MYSQL_USER}" "${MYSQL_DATABASE}" < "$sql_file" 2>/tmp/migration_error.log; then
echo "✓ SUCCESS" echo "✓ SUCCESS"
SUCCESS=$((SUCCESS + 1)) SUCCESS=$((SUCCESS + 1))
else else