workspace-v1/shared/knowledge-base/reference/erp-inmobiliaria-legacy/gamilit/backend/migrations/P0-000-pre-migration-backup.sh
rckrdmrd 66161b1566 feat: Workspace-v1 complete migration with NEXUS v3.4
Sistema NEXUS v3.4 migrado con:

Estructura principal:
- core/orchestration: Sistema SIMCO + CAPVED (27 directivas, 28 perfiles)
- core/catalog: Catalogo de funcionalidades reutilizables
- shared/knowledge-base: Base de conocimiento compartida
- devtools/scripts: Herramientas de desarrollo
- control-plane/registries: Control de servicios y CI/CD
- orchestration/: Configuracion de orquestacion de agentes

Proyectos incluidos (11):
- gamilit (submodule -> GitHub)
- trading-platform (OrbiquanTIA)
- erp-suite con 5 verticales:
  - erp-core, construccion, vidrio-templado
  - mecanicas-diesel, retail, clinicas
- betting-analytics
- inmobiliaria-analytics
- platform_marketing_content
- pos-micro, erp-basico

Configuracion:
- .gitignore completo para Node.js/Python/Docker
- gamilit como submodule (git@github.com:rckrdmrd/gamilit-workspace.git)
- Sistema de puertos estandarizado (3005-3199)

Generated with NEXUS v3.4 Migration System
EPIC-010: Configuracion Git y Repositorios
2026-01-04 03:37:42 -06:00

96 lines
2.7 KiB
Bash

#!/bin/bash
###############################################################################
# P0-000: Pre-Migration Backup Script
#
# Creates a backup of gamification_system.user_stats before running
# the MayaRank migration (P0-001).
#
# Usage:
# chmod +x P0-000-pre-migration-backup.sh
# ./P0-000-pre-migration-backup.sh
#
# Environment variables:
# DB_HOST - PostgreSQL host (default: localhost)
# DB_PORT - PostgreSQL port (default: 5432)
# DB_NAME - Database name (default: gamilit_platform)
# DB_USER - Database user (default: gamilit_user)
# DB_PASSWORD - Database password (required)
###############################################################################
set -e # Exit on error
set -u # Exit on undefined variable
# Configuration
DB_HOST="${DB_HOST:-localhost}"
DB_PORT="${DB_PORT:-5432}"
DB_NAME="${DB_NAME:-gamilit_platform}"
DB_USER="${DB_USER:-gamilit_user}"
# Validate required variables
if [ -z "${DB_PASSWORD:-}" ]; then
echo "ERROR: DB_PASSWORD environment variable is required"
echo "Usage: DB_PASSWORD='your_password' ./P0-000-pre-migration-backup.sh"
exit 1
fi
# Backup directory
BACKUP_DIR="./backups"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/user_stats_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "${BACKUP_DIR}"
echo "========================================"
echo "PRE-MIGRATION BACKUP"
echo "========================================"
echo "Database: ${DB_NAME}"
echo "Host: ${DB_HOST}:${DB_PORT}"
echo "User: ${DB_USER}"
echo "Backup file: ${BACKUP_FILE}"
echo "========================================"
echo ""
# Export password for pg_dump
export PGPASSWORD="${DB_PASSWORD}"
# Create backup of user_stats table
echo "Creating backup of gamification_system.user_stats..."
pg_dump \
-h "${DB_HOST}" \
-p "${DB_PORT}" \
-U "${DB_USER}" \
-d "${DB_NAME}" \
--table=gamification_system.user_stats \
--data-only \
--column-inserts \
> "${BACKUP_FILE}"
if [ $? -eq 0 ]; then
echo "✓ Backup created successfully: ${BACKUP_FILE}"
echo ""
# Show backup file size
BACKUP_SIZE=$(du -h "${BACKUP_FILE}" | cut -f1)
echo "Backup size: ${BACKUP_SIZE}"
# Count records in backup
RECORD_COUNT=$(grep -c "INSERT INTO" "${BACKUP_FILE}" || true)
echo "Records backed up: ${RECORD_COUNT}"
echo ""
echo "========================================"
echo "BACKUP COMPLETED SUCCESSFULLY"
echo "========================================"
echo "You can now proceed with the migration:"
echo " psql -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USER} -d ${DB_NAME} -f P0-001-migrate-maya-rank-values.sql"
echo ""
else
echo "✗ Backup failed!"
exit 1
fi
# Cleanup
unset PGPASSWORD