Changeset 0.9.0 (#50)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# ============================================
|
||||
# Chat Switchboard - Schema Validation
|
||||
# Chat Switchboard - Schema Validation (v0.9)
|
||||
# ============================================
|
||||
# Verifies the database schema is correct after
|
||||
# migration. Checks expected tables, key columns,
|
||||
@@ -48,19 +48,6 @@ check_column() {
|
||||
fi
|
||||
}
|
||||
|
||||
# ── Helper: check index exists ───────────────
|
||||
check_index() {
|
||||
local index="$1"
|
||||
local exists
|
||||
exists=$(psql -tAc "SELECT 1 FROM pg_indexes WHERE schemaname='public' AND indexname='${index}';")
|
||||
if [[ "${exists}" == "1" ]]; then
|
||||
echo " ✓ index: ${index}"
|
||||
else
|
||||
echo " ✗ MISSING index: ${index}"
|
||||
ERRORS=$((ERRORS + 1))
|
||||
fi
|
||||
}
|
||||
|
||||
# ── Helper: check extension ──────────────────
|
||||
check_extension() {
|
||||
local ext="$1"
|
||||
@@ -77,7 +64,6 @@ check_extension() {
|
||||
# ── 1. Extensions ────────────────────────────
|
||||
echo ""
|
||||
echo "Extensions:"
|
||||
check_extension "uuid-ossp"
|
||||
check_extension "pgcrypto"
|
||||
|
||||
# ── 2. Migration tracking ───────────────────
|
||||
@@ -90,128 +76,112 @@ echo " ✓ ${MIGRATION_COUNT} migrations applied"
|
||||
LATEST=$(psql -tAc "SELECT version FROM schema_migrations ORDER BY version DESC LIMIT 1;" 2>/dev/null || echo "none")
|
||||
echo " ✓ latest: ${LATEST}"
|
||||
|
||||
# ── 3. Core tables (001 schema, renamed in 006) ─
|
||||
# ── 3. Core tables ──────────────────────────
|
||||
echo ""
|
||||
echo "Core tables:"
|
||||
check_table "users"
|
||||
check_table "api_configs"
|
||||
check_table "provider_configs"
|
||||
check_table "channels"
|
||||
check_table "messages"
|
||||
check_table "teams"
|
||||
check_table "team_members"
|
||||
check_table "refresh_tokens"
|
||||
check_table "global_settings"
|
||||
|
||||
# Key columns
|
||||
# ── 4. Users ────────────────────────────────
|
||||
echo ""
|
||||
echo "Users:"
|
||||
check_column "users" "id"
|
||||
check_column "users" "username"
|
||||
check_column "users" "email"
|
||||
check_column "users" "role"
|
||||
check_column "api_configs" "user_id"
|
||||
check_column "api_configs" "provider"
|
||||
check_column "api_configs" "api_key_encrypted"
|
||||
check_column "users" "is_active"
|
||||
check_column "users" "avatar_url"
|
||||
check_column "users" "display_name"
|
||||
check_column "users" "settings"
|
||||
|
||||
# ── 5. Provider Configs (replaces api_configs) ─
|
||||
echo ""
|
||||
echo "Provider Configs:"
|
||||
check_column "provider_configs" "scope"
|
||||
check_column "provider_configs" "owner_id"
|
||||
check_column "provider_configs" "provider"
|
||||
check_column "provider_configs" "endpoint"
|
||||
check_column "provider_configs" "api_key_enc"
|
||||
check_column "provider_configs" "headers"
|
||||
check_column "provider_configs" "settings"
|
||||
check_column "provider_configs" "is_active"
|
||||
|
||||
# ── 6. Model Catalog (replaces model_configs) ─
|
||||
echo ""
|
||||
echo "Model Catalog:"
|
||||
check_table "model_catalog"
|
||||
check_column "model_catalog" "provider_config_id"
|
||||
check_column "model_catalog" "model_id"
|
||||
check_column "model_catalog" "display_name"
|
||||
check_column "model_catalog" "capabilities"
|
||||
check_column "model_catalog" "pricing"
|
||||
check_column "model_catalog" "visibility"
|
||||
|
||||
# ── 7. Personas (replaces model_presets) ────
|
||||
echo ""
|
||||
echo "Personas:"
|
||||
check_table "personas"
|
||||
check_column "personas" "scope"
|
||||
check_column "personas" "owner_id"
|
||||
check_column "personas" "name"
|
||||
check_column "personas" "base_model_id"
|
||||
check_column "personas" "provider_config_id"
|
||||
check_column "personas" "system_prompt"
|
||||
check_column "personas" "created_by"
|
||||
|
||||
# ── 8. Channels ─────────────────────────────
|
||||
echo ""
|
||||
echo "Channels:"
|
||||
check_column "channels" "user_id"
|
||||
check_column "channels" "type"
|
||||
check_column "channels" "provider_config_id"
|
||||
check_column "channels" "team_id"
|
||||
check_column "channels" "settings"
|
||||
check_table "channel_members"
|
||||
check_table "channel_models"
|
||||
check_table "channel_cursors"
|
||||
|
||||
# ── 9. Messages ─────────────────────────────
|
||||
echo ""
|
||||
echo "Messages:"
|
||||
check_column "messages" "channel_id"
|
||||
check_column "messages" "role"
|
||||
check_column "messages" "parent_id"
|
||||
|
||||
# ── 4. Refresh tokens (002) ─────────────────
|
||||
echo ""
|
||||
echo "Auth tables:"
|
||||
check_table "refresh_tokens"
|
||||
check_column "refresh_tokens" "token_hash"
|
||||
check_column "refresh_tokens" "user_id"
|
||||
|
||||
# ── 5. Global settings (003) ────────────────
|
||||
echo ""
|
||||
echo "Settings tables:"
|
||||
check_table "global_settings"
|
||||
check_column "global_settings" "key"
|
||||
check_column "global_settings" "value"
|
||||
|
||||
# ── 6. Model configs (004) ──────────────────
|
||||
echo ""
|
||||
echo "Model tables:"
|
||||
check_table "model_configs"
|
||||
check_column "model_configs" "api_config_id"
|
||||
check_column "model_configs" "model_id"
|
||||
check_column "model_configs" "capabilities"
|
||||
|
||||
# ── 7. Provider capabilities (005) ──────────
|
||||
echo ""
|
||||
echo "Provider capabilities:"
|
||||
check_column "api_configs" "custom_headers"
|
||||
check_column "api_configs" "is_global"
|
||||
check_column "api_configs" "team_id"
|
||||
check_table "user_model_preferences"
|
||||
check_column "user_model_preferences" "user_id"
|
||||
check_column "user_model_preferences" "model_config_id"
|
||||
check_column "user_model_preferences" "model_id"
|
||||
check_column "user_model_preferences" "hidden"
|
||||
|
||||
# ── 8. Channel unification (006-008) ────────
|
||||
echo ""
|
||||
echo "Channel model (006-008):"
|
||||
check_column "channels" "description"
|
||||
check_column "messages" "participant_type"
|
||||
check_column "messages" "participant_id"
|
||||
check_table "channel_members"
|
||||
check_column "channel_members" "channel_id"
|
||||
check_column "channel_members" "user_id"
|
||||
check_table "channel_models"
|
||||
check_column "channel_models" "channel_id"
|
||||
check_column "channel_models" "model_id"
|
||||
check_table "channel_cursors"
|
||||
check_column "channel_cursors" "active_leaf_id"
|
||||
|
||||
# ── 9. Folders & Projects (009) ─────────────
|
||||
echo ""
|
||||
echo "Organization (009):"
|
||||
check_table "folders"
|
||||
check_column "folders" "user_id"
|
||||
check_table "projects"
|
||||
check_column "projects" "user_id"
|
||||
check_table "project_channels"
|
||||
|
||||
# ── 10. Banners (010) ───────────────────────
|
||||
echo ""
|
||||
echo "Banners (010):"
|
||||
# Banner config is seeded into global_settings; just verify the key exists
|
||||
BANNER_KEY=$(psql -tAc "SELECT 1 FROM global_settings WHERE key = 'banner';" 2>/dev/null || echo "0")
|
||||
if [[ "${BANNER_KEY}" == "1" ]]; then
|
||||
echo " ✓ global_settings: banner"
|
||||
else
|
||||
echo " ✗ MISSING global_settings key: banner"
|
||||
ERRORS=$((ERRORS + 1))
|
||||
fi
|
||||
|
||||
# ── 11. Model Presets (012) ─────────────────
|
||||
echo ""
|
||||
echo "Model Presets (012):"
|
||||
check_table "model_presets"
|
||||
check_column "model_presets" "name"
|
||||
check_column "model_presets" "base_model_id"
|
||||
check_column "model_presets" "api_config_id"
|
||||
check_column "model_presets" "system_prompt"
|
||||
check_column "model_presets" "scope"
|
||||
check_column "model_presets" "created_by"
|
||||
check_column "model_presets" "is_active"
|
||||
|
||||
# ── Migration 013: Message Forking ───────────
|
||||
echo ""
|
||||
echo "Migration 013: Message Forking"
|
||||
check_column "messages" "deleted_at"
|
||||
check_column "messages" "sibling_index"
|
||||
check_column "messages" "deleted_at"
|
||||
check_column "messages" "participant_type"
|
||||
|
||||
# ── Migration 014: Notes ─────────────────────
|
||||
# ── 10. Organization ────────────────────────
|
||||
echo ""
|
||||
echo "Migration 014: Notes"
|
||||
echo "Organization:"
|
||||
check_table "folders"
|
||||
check_table "projects"
|
||||
check_table "notes"
|
||||
check_column "notes" "user_id"
|
||||
check_column "notes" "title"
|
||||
check_column "notes" "content"
|
||||
check_column "notes" "folder_path"
|
||||
check_column "notes" "tags"
|
||||
check_column "notes" "metadata"
|
||||
check_column "notes" "source_channel_id"
|
||||
check_column "notes" "search_vector"
|
||||
|
||||
# ── 11. User Model Settings ────────────────
|
||||
echo ""
|
||||
echo "User Model Settings:"
|
||||
check_table "user_model_settings"
|
||||
check_column "user_model_settings" "user_id"
|
||||
check_column "user_model_settings" "model_id"
|
||||
check_column "user_model_settings" "hidden"
|
||||
check_column "user_model_settings" "sort_order"
|
||||
|
||||
# ── 12. Audit Log ───────────────────────────
|
||||
echo ""
|
||||
echo "Audit Log:"
|
||||
check_table "audit_log"
|
||||
check_column "audit_log" "actor_id"
|
||||
check_column "audit_log" "action"
|
||||
check_column "audit_log" "resource_type"
|
||||
|
||||
# ═══════════════════════════════════════════
|
||||
# ADD NEW MIGRATION CHECKS ABOVE THIS LINE
|
||||
# ═══════════════════════════════════════════
|
||||
|
||||
Reference in New Issue
Block a user