- Execute all 6 migrations on Desk CRM production database - Create missing tables: cr_lsps, cr_agent_lsps, cr_lsp_usage - Create archive tables: cr_*_usage_archive (4 tables) - Create system tables: cr_migrations, cr_maintenance_log - Make all scripts executable (chmod +x) - Total cr_* tables: 38 Migration files: - 001_initial_schema.sql - 002_add_lsps.sql - 003_add_relationships.sql - 004_add_telemetry.sql - 005_add_archive_tables.sql - 006_add_maintenance_log.sql Scripts: - session-init.sh, session-end.sh - inject-context.sh, inject-agent-context.sh - record-usage.sh, db-backup.sh, sync-to-mysql.sh Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
76 lines
2.0 KiB
Bash
Executable File
76 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# record-usage.sh - Regista uso de componentes na telemetria
|
|
# Pode ser chamado manualmente ou via hooks
|
|
# Author: Descomplicar®
|
|
#
|
|
# Uso: ./record-usage.sh <type> <component_slug> [success] [duration_ms]
|
|
# Exemplo: ./record-usage.sh agent wordpress-plugin-developer 1 5200
|
|
|
|
set -e
|
|
|
|
TYPE="${1:-agent}"
|
|
COMPONENT="${2:-unknown}"
|
|
SUCCESS="${3:-1}"
|
|
DURATION="${4:-0}"
|
|
SESSION_ID="${CLAUDE_SESSION_ID:-manual}"
|
|
|
|
# Validar argumentos
|
|
if [[ -z "$COMPONENT" || "$COMPONENT" == "unknown" ]]; then
|
|
echo "Usage: $0 <type> <component_slug> [success] [duration_ms]"
|
|
echo "Types: agent, skill, mcp_tool, lsp"
|
|
exit 1
|
|
fi
|
|
|
|
# Determinar tabela baseado no tipo
|
|
case "$TYPE" in
|
|
agent)
|
|
TABLE="cr_agent_usage"
|
|
ID_COLUMN="agent_id"
|
|
LOOKUP_TABLE="cr_agents"
|
|
;;
|
|
skill)
|
|
TABLE="cr_skill_usage"
|
|
ID_COLUMN="skill_id"
|
|
LOOKUP_TABLE="cr_skills"
|
|
;;
|
|
mcp_tool)
|
|
TABLE="cr_mcp_tool_usage"
|
|
ID_COLUMN="mcp_tool_id"
|
|
LOOKUP_TABLE="cr_mcp_tools"
|
|
;;
|
|
lsp)
|
|
TABLE="cr_lsp_usage"
|
|
ID_COLUMN="lsp_id"
|
|
LOOKUP_TABLE="cr_lsps"
|
|
;;
|
|
*)
|
|
echo "Unknown type: $TYPE"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Gerar SQL para inserção
|
|
# Nota: Este SQL seria executado via desk-crm-v3 MCP
|
|
SQL="INSERT INTO $TABLE ($ID_COLUMN, session_id, success, duration_sec, created_at)
|
|
SELECT id, '$SESSION_ID', $SUCCESS, $((DURATION / 1000)), NOW()
|
|
FROM $LOOKUP_TABLE
|
|
WHERE slug = '$COMPONENT'
|
|
LIMIT 1;"
|
|
|
|
# Output SQL para debug ou execução manual
|
|
echo "-- Record Usage: $TYPE/$COMPONENT"
|
|
echo "$SQL"
|
|
|
|
# Se EXECUTE_SQL=1, tentar executar via mysql client (se disponível)
|
|
if [[ "${EXECUTE_SQL:-0}" == "1" ]]; then
|
|
if command -v mysql &> /dev/null && [[ -n "$MYSQL_HOST" ]]; then
|
|
mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQL_DB" -e "$SQL"
|
|
echo "-- Executed successfully"
|
|
else
|
|
echo "-- MySQL client not available or credentials not set"
|
|
echo "-- Set MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB to execute"
|
|
fi
|
|
fi
|
|
|
|
exit 0
|