const Database = require('better-sqlite3');
const path = require('path');

const dbPath = path.join(__dirname, '../data/fitai.db');
const db = new Database(dbPath);

console.log('Migrating fitness_profiles table...');

try {
    // Check if columns exist
    const tableInfo = db.prepare('PRAGMA table_info(fitness_profiles)').all();
    const columns = tableInfo.map(c => c.name);

    if (!columns.includes('allergies')) {
        console.log('Adding allergies column...');
        db.prepare('ALTER TABLE fitness_profiles ADD COLUMN allergies TEXT').run();
    } else {
        console.log('allergies column already exists.');
    }

    if (!columns.includes('injuries')) {
        console.log('Adding injuries column...');
        db.prepare('ALTER TABLE fitness_profiles ADD COLUMN injuries TEXT').run();
    } else {
        console.log('injuries column already exists.');
    }

    console.log('Migration completed successfully.');
} catch (error) {
    console.error('Migration failed:', error);
} finally {
    db.close();
}
