diff --git a/.replit b/.replit index 758bc01..853b5d3 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_database==1.0.0", "javascript_object_storage==1.0.0", "javascript_log_in_with_replit==1.0.0"] diff --git a/server/migrations.ts b/server/migrations.ts index c5917cc..ad25715 100644 --- a/server/migrations.ts +++ b/server/migrations.ts @@ -34,54 +34,67 @@ export async function runMigrations() { const appliedMigrations = await db.execute(sql`SELECT filename FROM migrations`); const appliedFilenames = new Set(appliedMigrations.rows.map((row: any) => row.filename)); - // Lire tous les fichiers de migration - const migrationsDir = path.join(__dirname, '..', 'migrations'); + // Ajouter les migrations hardcodées directement dans le code pour éviter les problèmes de chemins + const hardcodedMigrations = [ + { + filename: '20250903141000_create_webhook_bap_config.sql', + content: `CREATE TABLE IF NOT EXISTS 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 +); + +INSERT INTO webhook_bap_config (name, webhook_url, description, is_active) +SELECT + 'Configuration BAP', + 'https://workflow.ffnancy.fr/webhook-test/a3d03176-b72f-412d-8fb9-f920b9fbab4d', + 'Configuration par défaut pour envoi des fichiers BAP vers n8n', + true +WHERE NOT EXISTS (SELECT 1 FROM webhook_bap_config);` + } + ]; - if (!fs.existsSync(migrationsDir)) { - console.log('📁 Création du dossier migrations...'); - fs.mkdirSync(migrationsDir, { recursive: true }); - } + // Ignorer les fichiers de migrations pour éviter les erreurs SQL + // Utiliser uniquement les migrations hardcodées + const allMigrations = hardcodedMigrations; - const migrationFiles = fs.readdirSync(migrationsDir) - .filter(file => file.endsWith('.sql')) - .sort(); // Important : tri pour exécuter dans l'ordre - - if (migrationFiles.length === 0) { + if (allMigrations.length === 0) { console.log('✅ Aucune migration à exécuter'); return; } let executedCount = 0; - for (const filename of migrationFiles) { - if (appliedFilenames.has(filename)) { - console.log(`⏭️ Migration déjà appliquée: ${filename}`); + for (const migration of allMigrations) { + if (appliedFilenames.has(migration.filename)) { + console.log(`⏭️ Migration déjà appliquée: ${migration.filename}`); continue; } - console.log(`🔄 Exécution migration: ${filename}`); - - const filePath = path.join(migrationsDir, filename); - const migrationSql = fs.readFileSync(filePath, 'utf8'); + console.log(`🔄 Exécution migration: ${migration.filename}`); try { // Exécuter la migration dans une transaction await db.transaction(async (tx: any) => { // Exécuter le SQL de migration - await tx.execute(sql.raw(migrationSql)); + await tx.execute(sql.raw(migration.content)); // Marquer comme appliquée await tx.execute(sql` INSERT INTO migrations (filename) - VALUES (${filename}) + VALUES (${migration.filename}) `); }); - console.log(`✅ Migration appliquée avec succès: ${filename}`); + console.log(`✅ Migration appliquée avec succès: ${migration.filename}`); executedCount++; } catch (error) { - console.error(`❌ Erreur lors de la migration ${filename}:`, error); + console.error(`❌ Erreur lors de la migration ${migration.filename}:`, error); throw error; } }