workspace/knowledge-base/reference/erp-inmobiliaria-legacy/gamilit/backend/migrations/P0-000-pre-migration-backup.sh
rckrdmrd ea1879f4ad feat: Initial workspace structure with multi-level Git configuration
- Configure workspace Git repository with comprehensive .gitignore
- Add Odoo as submodule for ERP reference code
- Include documentation: SETUP.md, GIT-STRUCTURE.md
- Add gitignore templates for projects (backend, frontend, database)
- Structure supports independent repos per project/subproject level

Workspace includes:
- core/ - Reusable patterns, modules, orchestration system
- projects/ - Active projects (erp-suite, gamilit, trading-platform, etc.)
- knowledge-base/ - Reference code and patterns (includes Odoo submodule)
- devtools/ - Development tools and templates
- customers/ - Client implementations template

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-08 10:44:23 -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