Files

76 lines
2.0 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Simple Database Import Script
# Fixes definer issues and imports the database
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
error() {
echo -e "${RED}❌ ERROR: $1${NC}"
exit 1
}
success() {
echo -e "${GREEN}$1${NC}"
}
info() {
echo -e "${BLUE}$1${NC}"
}
BACKUP_FILE="/tmp/tilbudgivern_migration/tilbudgivern_backup_20251010_083710.sql"
CLEANED_FILE="/tmp/tilbudgivern_migration/cleaned_backup.sql"
if [ ! -f "$BACKUP_FILE" ]; then
error "Backup file not found: $BACKUP_FILE"
fi
info "Cleaning backup file to remove definer issues..."
# Remove definer clauses and other problematic elements
sed -e 's/DEFINER=[^*]*\*/\*/g' \
-e 's/SQL SECURITY DEFINER//g' \
-e '/^\/\*!50017 DEFINER=/d' \
"$BACKUP_FILE" > "$CLEANED_FILE"
success "Backup file cleaned"
info "Importing database (this may take a few minutes)..."
# Import with error handling
if mysql -u tilbuduser -p"${DB_PASSWORD}" tilbudgivern < "$CLEANED_FILE"; then
success "Database imported successfully!"
else
error "Database import failed"
fi
# Verify import
info "Verifying database import..."
TABLE_COUNT=$(mysql -u tilbuduser -p"${DB_PASSWORD}" -e "USE tilbudgivern; SHOW TABLES;" 2>/dev/null | wc -l)
if [ "$TABLE_COUNT" -gt 1 ]; then
success "Database verification OK - Found $(($TABLE_COUNT - 1)) tables"
# Show some basic stats
echo ""
info "Database import summary:"
mysql -u tilbuduser -p"${DB_PASSWORD}" -e "
USE tilbudgivern;
SELECT 'Tables imported:' as info, COUNT(*) as count FROM information_schema.tables WHERE table_schema = 'tilbudgivern'
UNION ALL
SELECT 'customer_projects', COUNT(*) FROM customer_projects
UNION ALL
SELECT 'project_quotes', COUNT(*) FROM project_quotes;
" 2>/dev/null
else
error "Database verification failed - No tables found"
fi
success "Database migration completed successfully!"