the-tip-top-backend/scripts/apply-newsletter-migration.js
soufiane 4759ce99e7 feat: add newsletter subscription feature
- Add newsletter database table migration
- Create newsletter controller with subscribe/unsubscribe endpoints
- Add newsletter routes and validation
- Implement newsletter service with email validation
- Add setup documentation and migration scripts
- Include test page for newsletter functionality

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 00:07:44 +01:00

48 lines
1.4 KiB
JavaScript

/**
* Script pour appliquer la migration newsletter
*/
import { pool } from '../db.js';
import fs from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
async function applyMigration() {
try {
console.log('📦 Application de la migration newsletter...');
// Lire le fichier SQL
const migrationPath = join(__dirname, '../database/migrations/add-newsletter-table.sql');
const sql = fs.readFileSync(migrationPath, 'utf8');
console.log('📄 Fichier SQL lu:', migrationPath);
// Exécuter la migration
await pool.query(sql);
console.log('✅ Migration appliquée avec succès!');
console.log('📊 Table newsletters créée');
// Vérifier que la table existe
const result = await pool.query(
"SELECT table_name FROM information_schema.tables WHERE table_name = 'newsletters'"
);
if (result.rows.length > 0) {
console.log('✅ Vérification: Table newsletters trouvée dans la base de données');
} else {
console.log('❌ Erreur: Table newsletters non trouvée après migration');
}
process.exit(0);
} catch (error) {
console.error('❌ Erreur lors de l\'application de la migration:', error.message);
console.error(error);
process.exit(1);
}
}
applyMigration();