- 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>
77 lines
2.0 KiB
Bash
Executable File
77 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# sync-to-mysql.sh - Sincronização ficheiros → MySQL
|
|
# Autor: Descomplicar
|
|
# Data: 2026-02-04
|
|
|
|
# Este script é chamado manualmente ou via /descomplicar:sync
|
|
# Requer: mysql client, jq
|
|
|
|
PLUGIN_ROOT="$(dirname "$(dirname "$(readlink -f "$0")")")"
|
|
LOG_FILE="${PLUGIN_ROOT}/logs/sync.log"
|
|
|
|
# Configuração BD (usar variáveis de ambiente ou .env)
|
|
DB_HOST="${DESK_DB_HOST:-localhost}"
|
|
DB_USER="${DESK_DB_USER:-ealmeida_desk}"
|
|
DB_PASS="${DESK_DB_PASS:-}"
|
|
DB_NAME="${DESK_DB_NAME:-ealmeida_desk24}"
|
|
|
|
# Ficheiros fonte
|
|
AGENTS_FILE="$HOME/.claude/sdks/_resources/agents.json"
|
|
SKILLS_FILE="$HOME/.claude/sdks/_resources/skills.json"
|
|
MCPS_FILE="$HOME/.claude/sdks/_resources/mcps.json"
|
|
REGISTRY_FILE="$HOME/.claude/sdks/_registry.json"
|
|
|
|
# Timestamp
|
|
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
|
|
|
|
log() {
|
|
echo "[$TIMESTAMP] $1" >> "$LOG_FILE"
|
|
echo "$1"
|
|
}
|
|
|
|
# Verificar dependências
|
|
check_deps() {
|
|
if ! command -v jq &> /dev/null; then
|
|
log "ERROR: jq is required but not installed"
|
|
exit 1
|
|
fi
|
|
if ! command -v mysql &> /dev/null; then
|
|
log "ERROR: mysql client is required but not installed"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Contar items em JSON
|
|
count_json() {
|
|
local file="$1"
|
|
local key="$2"
|
|
if [[ -f "$file" ]]; then
|
|
jq -r ".$key | length" "$file" 2>/dev/null || echo "0"
|
|
else
|
|
echo "0"
|
|
fi
|
|
}
|
|
|
|
# Main
|
|
main() {
|
|
log "Starting sync..."
|
|
|
|
check_deps
|
|
|
|
# Contar items locais
|
|
AGENTS_LOCAL=$(count_json "$AGENTS_FILE" "agents")
|
|
SKILLS_LOCAL=$(count_json "$SKILLS_FILE" "skills")
|
|
MCPS_LOCAL=$(count_json "$MCPS_FILE" "mcps")
|
|
SDKS_LOCAL=$(jq -r '.sdks | length' "$REGISTRY_FILE" 2>/dev/null || echo "0")
|
|
|
|
log "Local counts: Agents=$AGENTS_LOCAL, Skills=$SKILLS_LOCAL, MCPs=$MCPS_LOCAL, SDKs=$SDKS_LOCAL"
|
|
|
|
# Nota: A sincronização real com MySQL seria feita via MCP desk-crm-v3
|
|
# Este script serve como documentação e pode ser expandido
|
|
|
|
log "Sync completed (dry-run mode)"
|
|
log "Use /descomplicar:sync for full sync via MCP"
|
|
}
|
|
|
|
main "$@"
|