mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Ensure database tables are created automatically in production environments
Add a new script to synchronize missing database migrations and update the Docker entrypoint to execute it before starting the application. Replit-Commit-Author: Agent Replit-Commit-Session-Id: f9197b9b-a5b3-4469-a27d-930a9e9ee736 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/f9197b9b-a5b3-4469-a27d-930a9e9ee736/i2gFnxm
This commit is contained in:
1 parent
3645922bdb
commit
b383363e45
4 files changed
+240
-2
No files matched your search
+2
-2
@@ -114,5 +114,5 @@ RUN chmod +x /app/scripts/auto-migrate-production.sh && \
|
|||||||
ls -la /app/scripts/ && \
|
ls -la /app/scripts/ && \
|
||||||
test -f /app/scripts/docker-entrypoint.sh || echo "ERREUR: docker-entrypoint.sh manquant"
|
test -f /app/scripts/docker-entrypoint.sh || echo "ERREUR: docker-entrypoint.sh manquant"
|
||||||
|
|
||||||
# Start application normally (migration applied separately)
|
# Apply migrations and start application
|
||||||
CMD ["node", "dist/index.js"]
|
CMD ["sh", "-c", "if [ -f /app/scripts/auto-sync-migrations.sh ]; then /app/scripts/auto-sync-migrations.sh; fi && node dist/index.js"]
|
||||||
@@ -8,6 +8,13 @@
|
|||||||
"when": 1752862907657,
|
"when": 1752862907657,
|
||||||
"tag": "0000_flashy_blur",
|
"tag": "0000_flashy_blur",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 1,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1755510400000,
|
||||||
|
"tag": "002_add_dlc_stock_epuise",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Executable
+94
@@ -0,0 +1,94 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Script de synchronisation automatique des migrations
|
||||||
|
# Applique toutes les migrations SQL manquantes et synchronise le schéma
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🔄 [SYNC] Synchronisation automatique des migrations"
|
||||||
|
echo "=================================================="
|
||||||
|
|
||||||
|
# Fonction de logging
|
||||||
|
log() {
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Vérification de la connexion base de données
|
||||||
|
if [ -z "$DATABASE_URL" ]; then
|
||||||
|
log "❌ DATABASE_URL non défini"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "🔍 Connexion à la base de données..."
|
||||||
|
|
||||||
|
# Test de connexion
|
||||||
|
if ! psql "$DATABASE_URL" -c "SELECT 1;" > /dev/null 2>&1; then
|
||||||
|
log "❌ Impossible de se connecter à la base de données"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "✅ Connexion base de données réussie"
|
||||||
|
|
||||||
|
# Vérifier si la table dlc_products existe
|
||||||
|
log "🔍 Vérification de la table dlc_products..."
|
||||||
|
|
||||||
|
if ! psql "$DATABASE_URL" -tAc "SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name='dlc_products');" | grep -q "t"; then
|
||||||
|
log "❌ Table dlc_products non trouvée - exécution de la migration initiale nécessaire"
|
||||||
|
|
||||||
|
# Appliquer la migration initiale depuis 0000_flashy_blur.sql
|
||||||
|
if [ -f "migrations/0000_flashy_blur.sql" ]; then
|
||||||
|
log "🔄 Application de la migration initiale..."
|
||||||
|
psql "$DATABASE_URL" -f "migrations/0000_flashy_blur.sql"
|
||||||
|
log "✅ Migration initiale appliquée"
|
||||||
|
else
|
||||||
|
log "❌ Fichier de migration initiale non trouvé"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Vérifier si les colonnes stock_epuise existent
|
||||||
|
log "🔍 Vérification des colonnes DLC stock épuisé..."
|
||||||
|
|
||||||
|
COLUMNS_EXIST=$(psql "$DATABASE_URL" -tAc "
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_name='dlc_products'
|
||||||
|
AND column_name IN ('stock_epuise', 'stock_epuise_by', 'stock_epuise_at');
|
||||||
|
")
|
||||||
|
|
||||||
|
if [ "$COLUMNS_EXIST" != "3" ]; then
|
||||||
|
log "🔄 Application de la migration DLC stock épuisé ($COLUMNS_EXIST/3 colonnes trouvées)..."
|
||||||
|
|
||||||
|
# Appliquer la migration DLC
|
||||||
|
psql "$DATABASE_URL" -f "migrations/002_add_dlc_stock_epuise.sql"
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
log "✅ Migration DLC stock épuisé appliquée"
|
||||||
|
else
|
||||||
|
log "❌ Erreur lors de la migration DLC"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log "✅ Colonnes DLC stock épuisé déjà présentes"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Vérification finale
|
||||||
|
log "🔍 Vérification finale des colonnes..."
|
||||||
|
|
||||||
|
FINAL_CHECK=$(psql "$DATABASE_URL" -tAc "
|
||||||
|
SELECT column_name
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_name='dlc_products'
|
||||||
|
AND column_name IN ('stock_epuise', 'stock_epuise_by', 'stock_epuise_at')
|
||||||
|
ORDER BY column_name;
|
||||||
|
")
|
||||||
|
|
||||||
|
if [ $(echo "$FINAL_CHECK" | wc -l) -eq 3 ]; then
|
||||||
|
log "✅ Toutes les colonnes DLC sont présentes:"
|
||||||
|
echo "$FINAL_CHECK" | sed 's/^/ - /'
|
||||||
|
else
|
||||||
|
log "❌ Colonnes manquantes détectées"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "🎉 Synchronisation des migrations terminée avec succès"
|
||||||
Executable
+137
@@ -0,0 +1,137 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Script de correction des migrations pour la production
|
||||||
|
# Solution complète pour appliquer automatiquement les migrations DLC
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🚨 [PRODUCTION FIX] Correction automatique des migrations"
|
||||||
|
echo "========================================================"
|
||||||
|
|
||||||
|
# Fonction de logging avec timestamp
|
||||||
|
log() {
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Vérification de Docker Compose
|
||||||
|
if ! command -v docker-compose &> /dev/null; then
|
||||||
|
log "❌ docker-compose non trouvé"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Vérification que le conteneur PostgreSQL est actif
|
||||||
|
log "🔍 Vérification du conteneur PostgreSQL..."
|
||||||
|
|
||||||
|
if ! docker-compose ps | grep -q logiflow-db; then
|
||||||
|
log "❌ Conteneur logiflow-db non actif"
|
||||||
|
log "📋 Conteneurs disponibles:"
|
||||||
|
docker-compose ps
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "✅ Conteneur PostgreSQL actif"
|
||||||
|
|
||||||
|
# Application de toutes les migrations manquantes
|
||||||
|
log "🔄 Application des migrations manquantes..."
|
||||||
|
|
||||||
|
# Migration 1: Vérification et création de la structure de base
|
||||||
|
log "📂 Étape 1: Vérification de la structure de base..."
|
||||||
|
|
||||||
|
docker-compose exec -T logiflow-db psql -U logiflow_admin -d logiflow_db << 'EOF'
|
||||||
|
-- Vérifier que la table dlc_products existe
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'dlc_products') THEN
|
||||||
|
RAISE NOTICE 'Table dlc_products manquante - création nécessaire';
|
||||||
|
-- La table sera créée par la migration initiale si nécessaire
|
||||||
|
ELSE
|
||||||
|
RAISE NOTICE 'Table dlc_products trouvée';
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Migration 2: Application de la migration DLC stock épuisé
|
||||||
|
log "📂 Étape 2: Application de la migration DLC stock épuisé..."
|
||||||
|
|
||||||
|
docker-compose exec -T logiflow-db psql -U logiflow_admin -d logiflow_db << 'EOF'
|
||||||
|
-- Migration DLC Stock Épuisé - Version de production sécurisée
|
||||||
|
DO $$
|
||||||
|
DECLARE
|
||||||
|
column_count integer;
|
||||||
|
BEGIN
|
||||||
|
-- Compter les colonnes existantes
|
||||||
|
SELECT COUNT(*) INTO column_count
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_name = 'dlc_products'
|
||||||
|
AND column_name IN ('stock_epuise', 'stock_epuise_by', 'stock_epuise_at');
|
||||||
|
|
||||||
|
RAISE NOTICE 'Colonnes DLC stock épuisé trouvées: %', column_count;
|
||||||
|
|
||||||
|
-- Ajouter les colonnes manquantes
|
||||||
|
IF column_count < 3 THEN
|
||||||
|
RAISE NOTICE 'Application de la migration DLC...';
|
||||||
|
|
||||||
|
-- Ajouter les colonnes avec protection IF NOT EXISTS
|
||||||
|
ALTER TABLE dlc_products
|
||||||
|
ADD COLUMN IF NOT EXISTS stock_epuise boolean DEFAULT false NOT NULL,
|
||||||
|
ADD COLUMN IF NOT EXISTS stock_epuise_by varchar(255),
|
||||||
|
ADD COLUMN IF NOT EXISTS stock_epuise_at timestamp;
|
||||||
|
|
||||||
|
-- Créer l'index
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_dlc_products_stock_epuise ON dlc_products(stock_epuise);
|
||||||
|
|
||||||
|
-- Initialiser les valeurs existantes
|
||||||
|
UPDATE dlc_products
|
||||||
|
SET stock_epuise = false
|
||||||
|
WHERE stock_epuise IS NULL;
|
||||||
|
|
||||||
|
RAISE NOTICE 'Migration DLC appliquée avec succès';
|
||||||
|
ELSE
|
||||||
|
RAISE NOTICE 'Migration DLC déjà appliquée';
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
|
||||||
|
-- Vérification finale
|
||||||
|
SELECT
|
||||||
|
'Migration DLC - Verification finale' as status,
|
||||||
|
COUNT(*) as colonnes_dlc_trouvees
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_name = 'dlc_products'
|
||||||
|
AND column_name IN ('stock_epuise', 'stock_epuise_by', 'stock_epuise_at');
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
log "✅ Migration DLC appliquée avec succès"
|
||||||
|
else
|
||||||
|
log "❌ Erreur lors de la migration DLC"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Redémarrage de l'application
|
||||||
|
log "🔄 Redémarrage de l'application..."
|
||||||
|
docker-compose restart logiflow
|
||||||
|
|
||||||
|
# Attendre que l'application redémarre
|
||||||
|
log "⏳ Attente du redémarrage (30 secondes)..."
|
||||||
|
sleep 30
|
||||||
|
|
||||||
|
# Vérification finale
|
||||||
|
log "🔍 Vérification finale de l'API DLC..."
|
||||||
|
|
||||||
|
# Test de l'API DLC
|
||||||
|
HEALTH_CHECK=$(docker-compose logs logiflow 2>&1 | tail -20 | grep -c "Error fetching DLC products" || echo "0")
|
||||||
|
|
||||||
|
if [ "$HEALTH_CHECK" -eq 0 ]; then
|
||||||
|
log "✅ API DLC fonctionne correctement"
|
||||||
|
else
|
||||||
|
log "⚠️ Des erreurs DLC persistent - vérification manuelle nécessaire"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "🎉 CORRECTION DE PRODUCTION TERMINÉE"
|
||||||
|
echo "=================================="
|
||||||
|
echo "✅ Migrations DLC appliquées"
|
||||||
|
echo "✅ Application redémarrée"
|
||||||
|
echo "✅ L'erreur 'column does not exist' devrait être résolue"
|
||||||
|
echo ""
|
||||||
|
echo "Vérifiez maintenant votre interface DLC pour confirmer que tout fonctionne."
|
||||||
Reference in new issue
Block a user