prole/tmp/reset_gitlab_db.sh
chrisfu b4fc5641db checkpoint: sanitize prole config for host portability
- fix conf/prod/prole.cfg by replacing hardcoded /Users/chrisfu paths with /Users/chrisfu

- remove injected [update.sh] log lines and stray password artifacts so config is executable

- include latest pending updates across deployment config, UI/core flow, vault/network artifacts, and helper scripts
2026-04-10 05:58:40 -07:00

46 lines
1.6 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
export KUBECONFIG=/Users/chrisfu/dev/prole/prole-k3s.kubeconfig
echo "==> Finding CNPG primary pod..."
PRIMARY=$(kubectl -n knoe-db get pods \
-l "cnpg.io/cluster=knoe-db,cnpg.io/instanceRole=primary" \
--no-headers -o name | head -1)
echo "Primary: $PRIMARY"
echo "==> Dropping and recreating gitlabhq_production DB..."
kubectl -n knoe-db exec "$PRIMARY" -- \
psql -U postgres -c "
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = 'gitlabhq_production' AND pid <> pg_backend_pid();
DROP DATABASE IF EXISTS gitlabhq_production;
CREATE DATABASE gitlabhq_production OWNER root;
GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production TO root;
" 2>&1
echo "==> Deleting failed migration jobs so operator recreates them..."
kubectl -n gitea delete job \
gitlab-migrations-5f05f2c-f73-1 \
gitlab-migrations-5f05f2c-f73-2 \
--ignore-not-found
echo "==> Deleting shared-secrets jobs to force regeneration..."
kubectl -n gitea delete job \
gitlab-shared-secrets-2454dc7 \
gitlab-shared-secrets-d79f1fc \
--ignore-not-found 2>/dev/null || true
kubectl -n gitea delete pods -l app=shared-secrets --ignore-not-found 2>/dev/null || true
echo "==> Deleting gitlab-rails-secret to force new key generation..."
kubectl -n gitea delete secret gitlab-rails-secret --ignore-not-found
echo "==> Waiting 60s for operator to recreate shared-secrets + migrations..."
sleep 60
echo "==> New jobs:"
kubectl -n gitea get jobs --no-headers 2>&1 | grep -E "migrations|shared-secrets"
echo "==> New pods:"
kubectl -n gitea get pods --no-headers | grep -E "migrations|shared-secrets"