Branding: bulk rename across 50+ files (Go, JS, CSS, HTML, YAML, JSON, shell scripts). Fix Helm chart description and git repo URLs. Fix test helper taglines. Admin surface: strip 14 gutted tabs (providers, models, personas, roles, knowledge, memory, tasks, health, routing, capabilities, channels, dashboard, usage, stats). Collapse to 4 categories: People, Workflows, System, Monitoring. Settings surface: strip 11 gutted tabs (models, personas, providers, roles, knowledge, memory, usage, workflows, tasks, data, gitkeys). Keep: general, appearance, profile, teams, connections, notifications. Team-admin surface: strip 5 gutted tabs (personas, providers, knowledge, tasks, usage). Keep: members, groups, connections, workflows, settings, activity. Components: delete chat-pane/ (13 files, 1938 lines) and notes-pane/ (10 files, 2381 lines). main.go: remove stale Health.Prune maintenance goroutine. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
62 lines
2.7 KiB
Bash
62 lines
2.7 KiB
Bash
#!/bin/bash
|
|
# ============================================
|
|
# Switchboard Core - Database Bootstrap
|
|
# ============================================
|
|
# Idempotent: safe to run on every CI build.
|
|
# Creates the app role and database if they
|
|
# don't exist. Runs as the Postgres superuser.
|
|
#
|
|
# Required env vars:
|
|
# PGHOST, PGPORT, PGUSER, PGPASSWORD — admin connection
|
|
# APP_USER, APP_PASSWORD — app-level credentials
|
|
# DB_NAME — target database name
|
|
# ============================================
|
|
|
|
set -euo pipefail
|
|
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "Database bootstrap: ${DB_NAME}"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
|
|
# ── 1. Create role if not exists ─────────────
|
|
ROLE_EXISTS=$(psql -tAc "SELECT 1 FROM pg_roles WHERE rolname = '${APP_USER}';" postgres)
|
|
|
|
if [[ "${ROLE_EXISTS}" == "1" ]]; then
|
|
echo "✓ Role '${APP_USER}' already exists"
|
|
# Update password in case it changed
|
|
psql -c "ALTER ROLE ${APP_USER} WITH PASSWORD '${APP_PASSWORD}';" postgres
|
|
echo "✓ Password synced"
|
|
else
|
|
psql -c "CREATE ROLE ${APP_USER} WITH LOGIN PASSWORD '${APP_PASSWORD}';" postgres
|
|
echo "✓ Role '${APP_USER}' created"
|
|
fi
|
|
|
|
# ── 2. Create database if not exists ─────────
|
|
DB_EXISTS=$(psql -tAc "SELECT 1 FROM pg_database WHERE datname = '${DB_NAME}';" postgres)
|
|
|
|
if [[ "${DB_EXISTS}" == "1" ]]; then
|
|
echo "✓ Database '${DB_NAME}' already exists"
|
|
else
|
|
psql -c "CREATE DATABASE ${DB_NAME} OWNER ${APP_USER};" postgres
|
|
echo "✓ Database '${DB_NAME}' created"
|
|
fi
|
|
|
|
# ── 3. Ensure extensions (requires superuser) ─
|
|
psql -d "${DB_NAME}" <<'SQL'
|
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
|
|
CREATE EXTENSION IF NOT EXISTS "vector";
|
|
SQL
|
|
echo "✓ Extensions verified (uuid-ossp, pgcrypto, vector)"
|
|
|
|
# ── 4. Grant privileges ─────────────────────
|
|
psql -d "${DB_NAME}" -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${APP_USER};"
|
|
psql -d "${DB_NAME}" -c "GRANT ALL PRIVILEGES ON SCHEMA public TO ${APP_USER};"
|
|
psql -d "${DB_NAME}" -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO ${APP_USER};"
|
|
psql -d "${DB_NAME}" -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO ${APP_USER};"
|
|
echo "✓ Privileges granted"
|
|
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "Bootstrap complete: ${DB_NAME}"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|