159 lines
5.1 KiB
Bash
Executable File
159 lines
5.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Test Migration Workflow Script
|
|
# Automates the complete migration testing process
|
|
|
|
set -e # Exit on any error
|
|
|
|
# Create logs directory if it doesn't exist
|
|
mkdir -p logs
|
|
|
|
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_database"; then
|
|
print_success "Database API container is running"
|
|
else
|
|
print_warning "Database API container not running - run: docker compose up database -d"
|
|
echo "Note: API testing will be skipped without this container"
|
|
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"
|
|
echo "Running table count validation (some missing tables are expected)..."
|
|
if python validate_migration.py; then
|
|
print_success "Migration validation passed"
|
|
else
|
|
print_warning "Migration validation found expected differences (missing newer tables)"
|
|
echo "This is normal - some tables exist only in production"
|
|
fi
|
|
|
|
# API Integration Testing (if database container is running)
|
|
if docker ps | grep -q "sba_database"; then
|
|
print_step 7 "Running API integration tests"
|
|
echo "Testing API endpoints to validate PostgreSQL compatibility..."
|
|
|
|
# Wait for API to be ready
|
|
echo "Waiting for API to be ready..."
|
|
sleep 15
|
|
|
|
if python comprehensive_api_integrity_tests.py --router stratplay > logs/migration_api_test.log 2>&1; then
|
|
print_success "Critical API endpoints validated (stratplay with PostgreSQL fixes)"
|
|
else
|
|
print_warning "Some API tests failed - check logs/migration_api_test.log"
|
|
echo "Note: Many 'failures' are expected environment differences, not migration issues"
|
|
fi
|
|
|
|
# Test a few key routers quickly
|
|
echo "Running quick validation of core routers..."
|
|
for router in teams players standings; do
|
|
if python comprehensive_api_integrity_tests.py --router $router > logs/migration_${router}_test.log 2>&1; then
|
|
print_success "$router router validated"
|
|
else
|
|
print_warning "$router router has differences - check logs/migration_${router}_test.log"
|
|
fi
|
|
done
|
|
else
|
|
print_warning "Skipping API tests - database container not running"
|
|
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 ""
|
|
if docker ps | grep -q "sba_database"; then
|
|
echo -e "🔗 Test API directly: ${BLUE}http://localhost:801/api/v3/teams?season=10${NC}"
|
|
echo ""
|
|
fi
|
|
echo -e "📋 Check detailed logs in: ${BLUE}logs/${NC}"
|
|
echo -e "📊 Migration analysis: ${BLUE}logs/MIGRATION_TEST_ANALYSIS_20250819.md${NC}"
|
|
echo ""
|
|
echo -e "🔄 To test again: ${YELLOW}./test_migration_workflow.sh${NC}"
|
|
echo -e "🗑️ To reset only: ${YELLOW}python reset_postgres.py${NC}"
|
|
echo -e "🧪 Run full API tests: ${YELLOW}python comprehensive_api_integrity_tests.py${NC}"
|
|
echo "==========================================" |