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

async function migrate() {
    console.log('🔄 Starting migration: Adding registration_source 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 = 'registration_source'
        `);
        
        if (check.rows[0].count > 0) {
            console.log('⚠️  Column registration_source already exists. Skipping.');
        } else {
            await db.query(`
                ALTER TABLE users 
                ADD COLUMN registration_source VARCHAR(50) DEFAULT 'web'
            `);
            console.log('✅ Column registration_source added successfully.');
        }
    } catch (error) {
        console.error('❌ Migration failed:', error);
    } finally {
        process.exit();
    }
}

migrate();
