59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
import { pool } from '../db.js';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import dotenv from 'dotenv';
|
|
|
|
dotenv.config();
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
async function applyMigration() {
|
|
try {
|
|
console.log('🔧 Application de la migration: add-grand-prize-draw\n');
|
|
|
|
// Lire le fichier de migration
|
|
const migrationPath = path.join(__dirname, '../database/migrations/add-grand-prize-draw.sql');
|
|
const sql = fs.readFileSync(migrationPath, 'utf8');
|
|
|
|
// Exécuter la migration
|
|
await pool.query(sql);
|
|
|
|
console.log('✅ Migration appliquée avec succès!\n');
|
|
|
|
// Vérifier que la table a été créée
|
|
const tableCheck = await pool.query(`
|
|
SELECT table_name
|
|
FROM information_schema.tables
|
|
WHERE table_name = 'grand_prize_draws'
|
|
`);
|
|
|
|
if (tableCheck.rows.length > 0) {
|
|
console.log('✅ Table "grand_prize_draws" créée avec succès!');
|
|
} else {
|
|
console.log('❌ Erreur: Table non créée');
|
|
}
|
|
|
|
// Vérifier les colonnes
|
|
const columnsCheck = await pool.query(`
|
|
SELECT column_name, data_type
|
|
FROM information_schema.columns
|
|
WHERE table_name = 'grand_prize_draws'
|
|
ORDER BY ordinal_position
|
|
`);
|
|
|
|
console.log('\n📋 Colonnes créées:');
|
|
columnsCheck.rows.forEach(col => {
|
|
console.log(` • ${col.column_name} (${col.data_type})`);
|
|
});
|
|
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('❌ Erreur lors de la migration:', error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
applyMigration();
|