mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Ensure webhook BAP configuration table is created on startup
Adds a new TypeScript file to programmatically create the `webhook_bap_config` table in the database if it doesn't exist, and inserts a default configuration upon application startup in production environments. 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
This commit is contained in:
1 parent
4ef702f44b
commit
5b338b224e
2 files changed
+65
-2
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import { sql } from 'drizzle-orm';
|
||||
import { db } from './db.js';
|
||||
|
||||
export async function ensureWebhookBapConfigTable() {
|
||||
console.log('🔧 [STARTUP] Vérification table webhook_bap_config...');
|
||||
|
||||
try {
|
||||
// Vérifier si la table existe
|
||||
const tableExists = await db.execute(sql`
|
||||
SELECT EXISTS (
|
||||
SELECT FROM information_schema.tables
|
||||
WHERE table_schema='public' AND table_name='webhook_bap_config'
|
||||
);
|
||||
`);
|
||||
|
||||
const exists = tableExists.rows[0]?.exists;
|
||||
|
||||
if (exists) {
|
||||
console.log('✅ [STARTUP] Table webhook_bap_config existe déjà');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('🔧 [STARTUP] Création de la table webhook_bap_config...');
|
||||
|
||||
// Créer la table
|
||||
await db.execute(sql`
|
||||
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
|
||||
);
|
||||
`);
|
||||
|
||||
// Insérer la configuration par défaut
|
||||
await db.execute(sql`
|
||||
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
|
||||
);
|
||||
`);
|
||||
|
||||
// Ajouter un commentaire
|
||||
await db.execute(sql`
|
||||
COMMENT ON TABLE webhook_bap_config IS 'Configuration pour webhook BAP n8n';
|
||||
`);
|
||||
|
||||
console.log('✅ [STARTUP] Table webhook_bap_config créée avec succès!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ [STARTUP] Erreur lors de la création de la table webhook_bap_config:', error);
|
||||
// Ne pas arrêter l'application si la création échoue
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -2,8 +2,11 @@ import express, { type Request, Response, NextFunction } from "express";
|
||||
import { registerRoutes } from "./routes.js";
|
||||
import { setupVite, serveStatic } from "./vite.js";
|
||||
|
||||
// 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');
|
||||
// Forcer la création de la table webhook_bap_config au démarrage de l'application
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
const { ensureWebhookBapConfigTable } = await import('./createWebhookTable.js');
|
||||
await ensureWebhookBapConfigTable();
|
||||
}
|
||||
|
||||
// Initialize weather system
|
||||
console.log('🌤️ [STARTUP] Initializing weather system...');
|
||||
|
||||
Reference in new issue
Block a user