module.exports = { async up(knex) { console.log(`MIGRATION-- 2024-07-04-add-fansly-id-to-vtuber.js`); // Check if the 'fansly_id' column already exists in the 'vtubers' table const hasColumn = await knex.schema.hasColumn('vtubers', 'fansly_id'); if (!hasColumn) { console.log(`Adding the 'fansly_id' column to the 'vtubers' table`); await knex.schema.table('vtubers', (table) => { table.string('fansly_id'); }); } // Get all vtubers from the database const vtubers = await knex.select('*').from('vtubers'); // For each vtuber, populate fansly_id if it's null or undefined for (const [_, vtuber] of vtubers.entries()) { if (!vtuber.fansly_id) { await knex('vtubers').update({ fansly_id: '' }).where({ id: vtuber.id }); } } }, };