From 3304d1c9128503ed1804ad98a540a00b072d19bc Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Wed, 3 Sep 2025 13:58:55 +0000 Subject: [PATCH] Add automatic creation of webhook configuration table during database migration Modify the auto-migrate script to check for and create the `webhook_bap_config` table if it does not exist, including a default entry and description. Remove explicit migration calls from `server/index.ts` as they are now handled by the Docker entrypoint script. Replit-Commit-Author: Agent Replit-Commit-Session-Id: cfbfe47c-0c9a-4ebf-8a41-2937407eccff Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/cfbfe47c-0c9a-4ebf-8a41-2937407eccff/qkkp1hi --- .replit | 2 +- scripts/auto-migrate-production.sh | 34 +++++++++++++++++++++++++++++- server/index.ts | 17 ++------------- 3 files changed, 36 insertions(+), 17 deletions(-) mode change 100755 => 100644 scripts/auto-migrate-production.sh diff --git a/.replit b/.replit index 758bc01..2e1a3ae 100644 --- a/.replit +++ b/.replit @@ -37,4 +37,4 @@ args = "npm run dev" waitForPort = 5000 [agent] -integrations = ["javascript_database==1.0.0", "javascript_log_in_with_replit==1.0.0", "javascript_object_storage==1.0.0"] +integrations = ["javascript_object_storage==1.0.0", "javascript_database==1.0.0", "javascript_log_in_with_replit==1.0.0"] diff --git a/scripts/auto-migrate-production.sh b/scripts/auto-migrate-production.sh old mode 100755 new mode 100644 index 24b4995..3904da9 --- a/scripts/auto-migrate-production.sh +++ b/scripts/auto-migrate-production.sh @@ -79,4 +79,36 @@ else echo "ℹ️ [AUTO-MIGRATE] Colonnes stock épuisé existent déjà" fi -echo "✅ [AUTO-MIGRATE] Migration terminée!" \ No newline at end of file +# Vérifier si la table webhook_bap_config existe +echo "🔄 [AUTO-MIGRATE] Vérification de la table webhook_bap_config..." +if psql "$DATABASE_URL" -tAc "SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema='public' AND table_name='webhook_bap_config');" | grep -q "f"; then + echo "🔧 [AUTO-MIGRATE] Création de la table webhook_bap_config..." + psql "$DATABASE_URL" << 'EOF' +CREATE TABLE webhook_bap_config ( + id SERIAL PRIMARY KEY, + name VARCHAR(100) NOT NULL DEFAULT 'Configuration BAP', + webhook_url TEXT NOT NULL, + description TEXT, + is_active BOOLEAN NOT NULL DEFAULT true, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +-- Configuration par défaut webhook BAP +INSERT INTO webhook_bap_config (name, webhook_url, description, is_active) +VALUES ( + 'Configuration BAP', + 'https://workflow.ffnancy.fr/webhook/a3d03176-b72f-412d-8fb9-f920b9fbab4d', + 'Configuration par défaut pour envoi des fichiers BAP vers n8n', + true +); + +-- Commentaire sur la table +COMMENT ON TABLE webhook_bap_config IS 'Configuration pour webhook BAP n8n'; +EOF + echo "✅ [AUTO-MIGRATE] Table webhook_bap_config créée avec succès" +else + echo "ℹ️ [AUTO-MIGRATE] Table webhook_bap_config existe déjà - aucune action nécessaire" +fi + +echo "✅ [AUTO-MIGRATE] Migration terminée avec succès - webhook_bap_config incluse!" \ No newline at end of file diff --git a/server/index.ts b/server/index.ts index 7c41528..6167bc5 100644 --- a/server/index.ts +++ b/server/index.ts @@ -2,21 +2,8 @@ import express, { type Request, Response, NextFunction } from "express"; import { registerRoutes } from "./routes.js"; import { setupVite, serveStatic } from "./vite.js"; -// Run database migrations first - FORCER EN PRODUCTION -console.log('🔄 [STARTUP] Running database migrations...'); -console.log('🔍 [STARTUP] Environment:', process.env.NODE_ENV); -console.log('🔍 [STARTUP] Has DATABASE_URL:', !!process.env.DATABASE_URL); - -try { - const { runMigrations } = await import('./migrations.js'); - await runMigrations(); - console.log('✅ [STARTUP] Database migrations completed'); -} catch (error) { - console.error('❌ [STARTUP] Database migrations failed:', error); - console.error('❌ [STARTUP] Error details:', JSON.stringify(error, null, 2)); - // NE PAS arrêter l'app pour éviter les boucles de redémarrage - console.warn('⚠️ [STARTUP] Continuing without migrations to avoid restart loop'); -} +// Les migrations sont gérées par docker-entrypoint.sh -> auto-migrate-production.sh +console.log('ℹ️ [STARTUP] Migrations gérées par le script Docker au démarrage du conteneur'); // Initialize weather system console.log('🌤️ [STARTUP] Initializing weather system...');