fp/services/strapi/database/migrations/2023-08-01-relate-vods-to-v...

26 lines
809 B
JavaScript
Raw Normal View History

2024-01-20 16:16:14 +00:00
module.exports = {
async up(knex) {
// ... (Create vods_vtuber_links table if not already created)
// Get vtuber ID for ProjektMelody (assuming it's 1)
const vtuberId = 1;
// Get all VODs from the database
const vods = await knex.select('*').from('vods');
// For each VOD, associate it with the vtuber (vtuber with ID 1) if not already associated
for (const [index, vod] of vods.entries()) {
const existingAssociation = await knex('vods_vtuber_links')
.where({ vtuber_id: vtuberId, vod_id: vod.id })
.first();
if (!existingAssociation) {
await knex('vods_vtuber_links').insert({
vtuber_id: vtuberId,
vod_id: vod.id,
vod_order: index + 1, // Auto-increment the vod_order number
});
}
}
2024-04-11 08:17:51 +00:00
}
2024-01-20 16:16:14 +00:00
};