module.exports = {
  async up(manager) {
    console.log('  - 添加奖品来源字段...');
    
    // 添加source字段，默认值为purchase
    await manager.executeSql(`
      ALTER TABLE Prizes ADD COLUMN source TEXT DEFAULT 'purchase';
    `);
    
    // 添加sponsor字段
    await manager.executeSql(`
      ALTER TABLE Prizes ADD COLUMN sponsor TEXT;
    `);
    
    // 为现有数据设置默认值
    await manager.executeSql(`
      UPDATE Prizes SET source = 'purchase' WHERE source IS NULL;
    `);
    
    console.log('  - 奖品来源字段添加完成');
  },
  
  async down(manager) {
    console.log('  - 移除奖品来源字段...');
    
    // SQLite不支持DROP COLUMN，需要重建表
    await manager.executeSql(`
      CREATE TABLE Prizes_backup AS SELECT 
        id, activityId, name, level, description, image, quantity, sortOrder, createdAt, updatedAt
      FROM Prizes;
    `);
    
    await manager.executeSql(`DROP TABLE Prizes;`);
    
    await manager.executeSql(`ALTER TABLE Prizes_backup RENAME TO Prizes;`);
    
    console.log('  - 奖品来源字段移除完成');
  }
};
