261 lines
7 KiB
Bash
Executable file
261 lines
7 KiB
Bash
Executable file
#!/bin/bash
|
||
# cleanup-uuid-migration.sh
|
||
# Script de nettoyage des fichiers legacy de la migration UUID
|
||
# À exécuter depuis la racine du monorepo
|
||
|
||
set -e # Stop on error
|
||
|
||
echo "=========================================="
|
||
echo "🧹 Nettoyage Migration UUID - Veza"
|
||
echo "=========================================="
|
||
echo ""
|
||
|
||
# Couleurs pour output
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
NC='\033[0m' # No Color
|
||
|
||
# Fonction pour afficher les erreurs
|
||
error() {
|
||
echo -e "${RED}❌ $1${NC}" >&2
|
||
}
|
||
|
||
success() {
|
||
echo -e "${GREEN}✅ $1${NC}"
|
||
}
|
||
|
||
warning() {
|
||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||
}
|
||
|
||
info() {
|
||
echo -e "ℹ️ $1"
|
||
}
|
||
|
||
# Vérifier qu'on est à la racine du monorepo
|
||
if [ ! -d "veza-backend-api" ] || [ ! -d "veza-chat-server" ]; then
|
||
error "Ce script doit être exécuté depuis la racine du monorepo"
|
||
exit 1
|
||
fi
|
||
|
||
echo "=== Étape 1: Vérification pré-cleanup ==="
|
||
echo ""
|
||
|
||
# Vérifier qu'on est sur la bonne branche
|
||
CURRENT_BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown")
|
||
if [ "$CURRENT_BRANCH" = "unknown" ] || [ -z "$CURRENT_BRANCH" ]; then
|
||
warning "Git n'est pas initialisé ou vous n'êtes pas dans un repo git"
|
||
read -p "Continuer quand même ? (y/N) " -n 1 -r
|
||
echo
|
||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||
exit 1
|
||
fi
|
||
else
|
||
info "Branche actuelle : $CURRENT_BRANCH"
|
||
|
||
if [ "$CURRENT_BRANCH" != "cleanup/uuid-migration" ] && [ "$CURRENT_BRANCH" != "cleanup/uuid-cleanup" ]; then
|
||
warning "Vous n'êtes pas sur une branche cleanup/uuid-*"
|
||
read -p "Créer une branche cleanup/uuid-cleanup ? (y/N) " -n 1 -r
|
||
echo
|
||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||
git checkout -b cleanup/uuid-cleanup
|
||
success "Branche cleanup/uuid-cleanup créée"
|
||
fi
|
||
fi
|
||
fi
|
||
|
||
# Vérifier que les tests passent (optionnel, peut être long)
|
||
read -p "Voulez-vous lancer les tests avant le nettoyage ? (y/N) " -n 1 -r
|
||
echo
|
||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||
info "🧪 Vérification des tests backend..."
|
||
cd veza-backend-api
|
||
if go test ./... -v 2>&1 | head -20; then
|
||
success "Tests backend OK"
|
||
else
|
||
error "Tests backend échoués"
|
||
cd ..
|
||
read -p "Continuer quand même ? (y/N) " -n 1 -r
|
||
echo
|
||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||
exit 1
|
||
fi
|
||
fi
|
||
cd ..
|
||
|
||
info "🧪 Vérification des tests chat-server..."
|
||
cd veza-chat-server
|
||
if cargo test 2>&1 | head -30; then
|
||
success "Tests chat-server OK"
|
||
else
|
||
error "Tests chat-server échoués"
|
||
cd ..
|
||
read -p "Continuer quand même ? (y/N) " -n 1 -r
|
||
echo
|
||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||
exit 1
|
||
fi
|
||
fi
|
||
cd ..
|
||
else
|
||
warning "Tests ignorés - assurez-vous qu'ils passent avant de continuer"
|
||
fi
|
||
|
||
echo ""
|
||
echo "=== Étape 2: Backup ==="
|
||
echo ""
|
||
|
||
BACKUP_DIR="backup-pre-cleanup-$(date +%Y%m%d-%H%M%S)"
|
||
mkdir -p "$BACKUP_DIR"
|
||
info "📦 Création du backup dans $BACKUP_DIR..."
|
||
|
||
# Backup migrations_legacy
|
||
if [ -d "veza-backend-api/migrations_legacy" ]; then
|
||
tar -czf "$BACKUP_DIR/migrations_legacy.tar.gz" veza-backend-api/migrations_legacy/ 2>/dev/null
|
||
if [ $? -eq 0 ]; then
|
||
success "migrations_legacy/ sauvegardé"
|
||
else
|
||
error "Échec du backup de migrations_legacy/"
|
||
exit 1
|
||
fi
|
||
else
|
||
warning "migrations_legacy/ n'existe pas (déjà supprimé ?)"
|
||
fi
|
||
|
||
# Backup main.go.legacy
|
||
if [ -f "veza-backend-api/cmd/main.go.legacy" ]; then
|
||
cp veza-backend-api/cmd/main.go.legacy "$BACKUP_DIR/" 2>/dev/null
|
||
if [ $? -eq 0 ]; then
|
||
success "main.go.legacy sauvegardé"
|
||
else
|
||
warning "Échec du backup de main.go.legacy (non critique)"
|
||
fi
|
||
else
|
||
info "main.go.legacy n'existe pas (déjà supprimé ?)"
|
||
fi
|
||
|
||
# Créer un fichier README dans le backup
|
||
cat > "$BACKUP_DIR/README.txt" << EOF
|
||
Backup créé le $(date)
|
||
Contenu :
|
||
- migrations_legacy.tar.gz : Dossier complet des migrations legacy
|
||
- main.go.legacy : Ancien point d'entrée (si présent)
|
||
|
||
Ce backup peut être supprimé après vérification que le nettoyage fonctionne correctement.
|
||
EOF
|
||
|
||
success "Backup créé dans $BACKUP_DIR"
|
||
|
||
echo ""
|
||
echo "=== Étape 3: Suppressions ==="
|
||
echo ""
|
||
|
||
# Supprimer migrations_legacy
|
||
if [ -d "veza-backend-api/migrations_legacy" ]; then
|
||
info "🗑️ Suppression de veza-backend-api/migrations_legacy/..."
|
||
rm -rf veza-backend-api/migrations_legacy/
|
||
success "migrations_legacy/ supprimé"
|
||
else
|
||
info "migrations_legacy/ n'existe pas (déjà supprimé ?)"
|
||
fi
|
||
|
||
# Supprimer main.go.legacy
|
||
if [ -f "veza-backend-api/cmd/main.go.legacy" ]; then
|
||
info "🗑️ Suppression de veza-backend-api/cmd/main.go.legacy..."
|
||
rm veza-backend-api/cmd/main.go.legacy
|
||
success "main.go.legacy supprimé"
|
||
else
|
||
info "main.go.legacy n'existe pas (déjà supprimé ?)"
|
||
fi
|
||
|
||
# Vérifier archive du chat-server
|
||
if [ -d "veza-chat-server/migrations/archive" ]; then
|
||
warning "veza-chat-server/migrations/archive/ existe"
|
||
info "Ce dossier contient des migrations archivées"
|
||
read -p "Voulez-vous le supprimer ? (y/N) " -n 1 -r
|
||
echo
|
||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||
rm -rf veza-chat-server/migrations/archive/
|
||
success "archive/ supprimé"
|
||
else
|
||
info "archive/ conservé"
|
||
fi
|
||
fi
|
||
|
||
echo ""
|
||
echo "=== Étape 4: Vérification post-cleanup ==="
|
||
echo ""
|
||
|
||
# Build backend
|
||
info "🔨 Build backend..."
|
||
cd veza-backend-api
|
||
if go build ./cmd/api 2>&1 | head -10; then
|
||
success "Build backend OK"
|
||
else
|
||
error "Build backend échoué"
|
||
cd ..
|
||
exit 1
|
||
fi
|
||
cd ..
|
||
|
||
# Build chat-server
|
||
info "🔨 Build chat-server..."
|
||
cd veza-chat-server
|
||
if cargo build --release 2>&1 | tail -5; then
|
||
success "Build chat-server OK"
|
||
else
|
||
error "Build chat-server échoué"
|
||
cd ..
|
||
exit 1
|
||
fi
|
||
cd ..
|
||
|
||
# Tests (optionnel)
|
||
read -p "Voulez-vous lancer les tests après le nettoyage ? (y/N) " -n 1 -r
|
||
echo
|
||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||
info "🧪 Tests backend..."
|
||
cd veza-backend-api
|
||
if go test ./... -v 2>&1 | head -20; then
|
||
success "Tests backend OK"
|
||
else
|
||
error "Tests backend échoués"
|
||
cd ..
|
||
exit 1
|
||
fi
|
||
cd ..
|
||
|
||
info "🧪 Tests chat-server..."
|
||
cd veza-chat-server
|
||
if cargo test 2>&1 | tail -10; then
|
||
success "Tests chat-server OK"
|
||
else
|
||
error "Tests chat-server échoués"
|
||
cd ..
|
||
exit 1
|
||
fi
|
||
cd ..
|
||
else
|
||
warning "Tests ignorés - assurez-vous de les lancer manuellement"
|
||
fi
|
||
|
||
echo ""
|
||
echo "=========================================="
|
||
echo -e "${GREEN}✅ Cleanup terminé${NC}"
|
||
echo "=========================================="
|
||
echo ""
|
||
echo "📊 Résumé :"
|
||
echo " - Backup créé dans : $BACKUP_DIR"
|
||
echo " - migrations_legacy/ : Supprimé"
|
||
echo " - main.go.legacy : Supprimé"
|
||
echo ""
|
||
echo "📝 Prochaines étapes :"
|
||
echo " 1. Review les changements : git diff"
|
||
echo " 2. Commit : git commit -m 'chore: remove legacy UUID migration files'"
|
||
echo " 3. Push : git push origin $CURRENT_BRANCH"
|
||
echo ""
|
||
echo "💡 Pour restaurer le backup :"
|
||
echo " tar -xzf $BACKUP_DIR/migrations_legacy.tar.gz"
|
||
echo ""
|
||
|