feat: Deploy IA context tables to architect and corp servers

Desplegadas tablas de contexto IA en architect (69.62.126.110) y corp (92.112.181.188).

Cambios:
- Schema completo con 5 tablas: ia_contexts, ia_messages, ia_embeddings, ia_tool_calls, ia_context_metrics
- Vista ia_context_summary para consultas agregadas
- 2 funciones PL/pgSQL y triggers para actualización automática
- 13 índices optimizados para consultas frecuentes
- Script de despliegue automatizado
- Documentación completa del deployment

Tests:
-  architect: Tablas funcionando, triggers activos
-  corp: Tablas funcionando, triggers activos
- ⚠️  deck: Servidor no disponible (pendiente)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
ARCHITECT
2025-12-24 00:08:26 +00:00
parent 0e09ef9f47
commit 03ef4696f3
3 changed files with 433 additions and 0 deletions

128
scripts/deploy_ia_tables.sh Executable file
View File

@@ -0,0 +1,128 @@
#!/bin/bash
# Script de despliegue de tablas de contexto IA
# Para servidores: architect (local), deck, corp
# Fecha: 2024-12-24
set -e # Exit on error
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCHEMA_FILE="${SCRIPT_DIR}/ia_context_schema.sql"
SSH_KEY="$HOME/.ssh/tzzr"
# Colores para output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "============================================================================"
echo "TZZR - Despliegue de Tablas de Contexto IA"
echo "============================================================================"
echo ""
# Función para desplegar en un servidor
deploy_to_server() {
local server_name=$1
local server_host=$2
local is_local=$3
echo -e "${YELLOW}Desplegando en ${server_name} (${server_host})...${NC}"
if [ "$is_local" = "true" ]; then
# Despliegue local en architect
echo " → Ejecutando SQL en PostgreSQL local..."
if sudo -u postgres psql -f "$SCHEMA_FILE" 2>&1 | tee /tmp/deploy_${server_name}.log; then
echo -e "${GREEN}${server_name}: Deployment exitoso${NC}"
return 0
else
echo -e "${RED}${server_name}: Error en deployment${NC}"
cat /tmp/deploy_${server_name}.log
return 1
fi
else
# Despliegue remoto vía SSH
echo " → Copiando schema al servidor..."
if ! scp -i "$SSH_KEY" -o StrictHostKeyChecking=no "$SCHEMA_FILE" "root@${server_host}:/tmp/ia_context_schema.sql" 2>&1; then
echo -e "${RED}${server_name}: Error copiando archivo${NC}"
return 1
fi
echo " → Ejecutando SQL en PostgreSQL remoto..."
if ssh -i "$SSH_KEY" -o StrictHostKeyChecking=no "root@${server_host}" \
"sudo -u postgres psql -f /tmp/ia_context_schema.sql && rm /tmp/ia_context_schema.sql" 2>&1 | tee /tmp/deploy_${server_name}.log; then
echo -e "${GREEN}${server_name}: Deployment exitoso${NC}"
return 0
else
echo -e "${RED}${server_name}: Error en deployment${NC}"
cat /tmp/deploy_${server_name}.log
return 1
fi
fi
}
# Verificar que el schema existe
if [ ! -f "$SCHEMA_FILE" ]; then
echo -e "${RED}Error: No se encuentra el archivo de schema: ${SCHEMA_FILE}${NC}"
exit 1
fi
echo "Schema a desplegar: $SCHEMA_FILE"
echo ""
# Contadores
total=0
success=0
failed=0
# Desplegar en architect (local)
total=$((total + 1))
if deploy_to_server "architect" "localhost" "true"; then
success=$((success + 1))
else
failed=$((failed + 1))
fi
echo ""
# Desplegar en deck (remoto)
total=$((total + 1))
echo "Verificando conectividad a deck..."
if ssh -i "$SSH_KEY" -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@72.62.1.113 "echo 'OK'" &>/dev/null; then
if deploy_to_server "deck" "72.62.1.113" "false"; then
success=$((success + 1))
else
failed=$((failed + 1))
fi
else
echo -e "${YELLOW} ⚠️ deck: Servidor no disponible (SSH connection refused)${NC}"
failed=$((failed + 1))
fi
echo ""
# Desplegar en corp (remoto)
total=$((total + 1))
if deploy_to_server "corp" "92.112.181.188" "false"; then
success=$((success + 1))
else
failed=$((failed + 1))
fi
echo ""
# Resumen
echo "============================================================================"
echo "RESUMEN DE DESPLIEGUE"
echo "============================================================================"
echo "Total servidores: $total"
echo -e "${GREEN}Exitosos: $success${NC}"
echo -e "${RED}Fallidos: $failed${NC}"
echo ""
if [ $success -eq $total ]; then
echo -e "${GREEN}✅ DEPLOYMENT COMPLETADO EXITOSAMENTE EN TODOS LOS SERVIDORES${NC}"
exit 0
elif [ $success -gt 0 ]; then
echo -e "${YELLOW}⚠️ DEPLOYMENT COMPLETADO CON ERRORES PARCIALES${NC}"
exit 1
else
echo -e "${RED}❌ DEPLOYMENT FALLÓ EN TODOS LOS SERVIDORES${NC}"
exit 1
fi