const db = require('../src/db');

async function migrate() {
    console.log('🔄 Starting migration: Adding last_upgrade_email_at to users table...');
    try {
        // Check if column exists
        const check = await db.query(`
            SELECT count(*) as count 
            FROM information_schema.COLUMNS 
            WHERE TABLE_SCHEMA = DATABASE() 
            AND TABLE_NAME = 'users' 
            AND COLUMN_NAME = 'last_upgrade_email_at'
        `);
        
        if (check.rows[0].count > 0) {
            console.log('⚠️  Column last_upgrade_email_at already exists. Skipping.');
        } else {
            await db.query(`
                ALTER TABLE users 
                ADD COLUMN last_upgrade_email_at DATETIME DEFAULT NULL
            `);
            console.log('✅ Column last_upgrade_email_at added successfully.');
        }
    } catch (error) {
        console.error('❌ Migration failed:', error);
    } finally {
        process.exit();
    }
}

migrate();
