fp/packages/strapi/database/migrations/2024-07-04-add-fansly-id-to...

29 lines
923 B
JavaScript
Raw Normal View History

2024-07-04 21:20:29 +00:00
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 });
}
}
},
};