#!/bin/bash # Test Migration Workflow Script # Automates the complete migration testing process set -e # Exit on any error echo "==========================================" echo "๐Ÿงช POSTGRESQL MIGRATION TESTING WORKFLOW" echo "==========================================" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color print_step() { echo -e "\n${BLUE}๐Ÿ“‹ Step $1: $2${NC}" } print_success() { echo -e "${GREEN}โœ… $1${NC}" } print_warning() { echo -e "${YELLOW}โš ๏ธ $1${NC}" } print_error() { echo -e "${RED}โŒ $1${NC}" } # Check if Docker containers are running print_step 1 "Checking Docker containers" if docker ps | grep -q "sba_postgres"; then print_success "PostgreSQL container is running" else print_error "PostgreSQL container not found - run: docker-compose up postgres -d" exit 1 fi if docker ps | grep -q "sba_adminer"; then print_success "Adminer container is running" else print_warning "Adminer container not running - run: docker-compose up adminer -d" fi # Test PostgreSQL connectivity print_step 2 "Testing PostgreSQL connectivity" if python test_postgres.py > /dev/null 2>&1; then print_success "PostgreSQL connection test passed" else print_error "PostgreSQL connection test failed" echo "Run: python test_postgres.py for details" exit 1 fi # Reset PostgreSQL database print_step 3 "Resetting PostgreSQL database" if python reset_postgres.py > /dev/null 2>&1; then print_success "PostgreSQL database reset complete" else print_error "Database reset failed" echo "Run: python reset_postgres.py for details" exit 1 fi # Check SQLite source data print_step 4 "Checking SQLite source data" if [ -f "storage/sba_master.db" ]; then SIZE=$(du -h storage/sba_master.db | cut -f1) print_success "SQLite database found (${SIZE})" else print_error "SQLite database not found at storage/sba_master.db" exit 1 fi # Run migration print_step 5 "Running data migration" echo "This may take several minutes depending on data size..." if python migrate_to_postgres.py; then print_success "Migration completed successfully" else print_error "Migration failed" exit 1 fi # Validate migration print_step 6 "Validating migration results" if python validate_migration.py; then print_success "Migration validation passed" else print_error "Migration validation failed" exit 1 fi # Final summary echo -e "\n==========================================" echo -e "${GREEN}๐ŸŽ‰ MIGRATION TEST COMPLETE${NC}" echo "==========================================" echo -e "๐Ÿ“Š View data in Adminer: ${BLUE}http://localhost:8080${NC}" echo " Server: postgres" echo " Username: sba_admin" echo " Password: sba_dev_password_2024" echo " Database: sba_master" echo "" echo -e "๐Ÿ”„ To test again: ${YELLOW}./test_migration_workflow.sh${NC}" echo -e "๐Ÿ—‘๏ธ To reset only: ${YELLOW}python reset_postgres.py${NC}" echo "=========================================="