47 lines
1.6 KiB
Bash
47 lines
1.6 KiB
Bash
#!/bin/bash
|
|
|
|
# Script per identificare e rimuovere migration duplicate
|
|
# Uso: ./clean-migrations.sh
|
|
|
|
echo "🔍 Ricerca migration duplicate..."
|
|
|
|
MIGRATION_DIR="database/migrations"
|
|
|
|
# Trova migration duplicate per nome di tabella
|
|
echo "📋 Analisi migration duplicate:"
|
|
|
|
# Trova file che creano la stessa tabella
|
|
echo "🔍 Tabelle create multiple volte:"
|
|
grep -l "create_.*_table" $MIGRATION_DIR/*.php | xargs basename -s .php | sort | uniq -d
|
|
|
|
# Mostra tutte le migration in ordine cronologico
|
|
echo ""
|
|
echo "📅 Ordine cronologico migration:"
|
|
ls -1 $MIGRATION_DIR/*.php | sort | sed 's/.*\///' | nl
|
|
|
|
# Identifica pattern problematici
|
|
echo ""
|
|
echo "⚠️ Pattern problematici identificati:"
|
|
|
|
# Cerca migration che droppano tabelle
|
|
echo "🗑️ Migration che eliminano tabelle:"
|
|
grep -l "drop.*table\|Schema::drop" $MIGRATION_DIR/*.php 2>/dev/null | sed 's/.*\///' || echo " Nessuna trovata"
|
|
|
|
# Cerca migration che aggiungono foreign key
|
|
echo "🔗 Migration che aggiungono foreign key:"
|
|
grep -l "foreign\|constraint" $MIGRATION_DIR/*.php 2>/dev/null | sed 's/.*\///' || echo " Nessuna trovata"
|
|
|
|
# Cerca migration con nomi simili
|
|
echo "📛 Migration con nomi simili (potenziali duplicati):"
|
|
ls $MIGRATION_DIR/*.php | sed 's/.*[0-9]_//' | sort | uniq -d | while read table; do
|
|
echo " Tabella: $table"
|
|
ls $MIGRATION_DIR/*$table | sed 's/.*\///'
|
|
done
|
|
|
|
echo ""
|
|
echo "✅ Analisi completata!"
|
|
echo "💡 Suggerimenti:"
|
|
echo " - Rimuovi migration duplicate per la stessa tabella"
|
|
echo " - Verifica che migration DROP vengano prima delle CREATE"
|
|
echo " - Controlla che foreign key vengano aggiunte dopo la creazione tabelle"
|