/** * Appliquer la migration pour le gros lot */ import 'dotenv/config'; import { pool } from '../db.js'; import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); async function applyMigration() { console.log('🔧 Application de la migration: add-grand-prize-type\n'); try { // Étape 1: Ajouter le type GRAND_PRIZE Ă  l'enum (transaction sĂ©parĂ©e) console.log('📝 Ajout du type GRAND_PRIZE...'); await pool.query(`ALTER TYPE prize_type ADD VALUE IF NOT EXISTS 'GRAND_PRIZE'`); console.log('✅ Type GRAND_PRIZE ajoutĂ©\n'); // Étape 2: VĂ©rifier si le lot existe dĂ©jĂ  const existing = await pool.query(`SELECT id FROM prizes WHERE name = 'An de thĂ©'`); if (existing.rows.length > 0) { console.log('⚠ Le lot existe dĂ©jĂ , mise Ă  jour...'); await pool.query(` UPDATE prizes SET type = 'GRAND_PRIZE', description = 'Gros lot du tirage final - Un an de thĂ© d''exception', value = '360.00', stock = 1, probability = 0, is_active = TRUE WHERE name = 'An de thĂ©' `); } else { console.log('📝 CrĂ©ation du gros lot...'); await pool.query(` INSERT INTO prizes ( type, name, description, value, stock, probability, is_active ) VALUES ( 'GRAND_PRIZE', 'An de thĂ©', 'Gros lot du tirage final - Un an de thĂ© d''exception', '360.00', 1, 0, TRUE ) `); } console.log('✅ Migration appliquĂ©e avec succĂšs!\n'); // VĂ©rifier const result = await pool.query(` SELECT name, type, value, stock, is_active FROM prizes WHERE name = 'An de thĂ©' `); if (result.rows.length > 0) { console.log('🎁 Gros lot créé:'); console.log(JSON.stringify(result.rows[0], null, 2)); } else { console.log('⚠ Le lot n\'a pas Ă©tĂ© créé'); } // Afficher tous les lots console.log('\n📋 Tous les lots:'); const allPrizes = await pool.query(` SELECT name, type, value, stock, probability, is_active FROM prizes ORDER BY CAST(value AS DECIMAL) DESC `); console.table(allPrizes.rows); } catch (error) { console.error('❌ Erreur:', error.message); console.error(error); } finally { await pool.end(); } } applyMigration();