const db = require('../models'); const Users = db.users; const Skills = db.skills; const Transactions = db.transactions; const SkillsData = [ { name: 'Web Development', description: 'Learn to build websites using HTML, CSS, and JavaScript.', // type code here for "relation_many" field // type code here for "relation_many" field }, { name: 'Data Science', description: 'Introduction to data analysis and machine learning.', // type code here for "relation_many" field // type code here for "relation_many" field }, { name: 'Graphic Design', description: 'Basics of design principles and Adobe tools.', // type code here for "relation_many" field // type code here for "relation_many" field }, ]; const TransactionsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field start_date: new Date('2023-10-01T10:00:00Z'), end_date: new Date('2023-10-01T12:00:00Z'), amount: 50, }, { // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field start_date: new Date('2023-10-02T14:00:00Z'), end_date: new Date('2023-10-02T16:00:00Z'), amount: 75, }, { // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field start_date: new Date('2023-10-03T09:00:00Z'), end_date: new Date('2023-10-03T11:00:00Z'), amount: 60, }, ]; // Similar logic for "relation_many" // Similar logic for "relation_many" // Similar logic for "relation_many" async function associateTransactionWithLearner() { const relatedLearner0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Transaction0 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Transaction0?.setLearner) { await Transaction0.setLearner(relatedLearner0); } const relatedLearner1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Transaction1 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Transaction1?.setLearner) { await Transaction1.setLearner(relatedLearner1); } const relatedLearner2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Transaction2 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Transaction2?.setLearner) { await Transaction2.setLearner(relatedLearner2); } } async function associateTransactionWithInstructor() { const relatedInstructor0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Transaction0 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Transaction0?.setInstructor) { await Transaction0.setInstructor(relatedInstructor0); } const relatedInstructor1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Transaction1 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Transaction1?.setInstructor) { await Transaction1.setInstructor(relatedInstructor1); } const relatedInstructor2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Transaction2 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Transaction2?.setInstructor) { await Transaction2.setInstructor(relatedInstructor2); } } async function associateTransactionWithSkill() { const relatedSkill0 = await Skills.findOne({ offset: Math.floor(Math.random() * (await Skills.count())), }); const Transaction0 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Transaction0?.setSkill) { await Transaction0.setSkill(relatedSkill0); } const relatedSkill1 = await Skills.findOne({ offset: Math.floor(Math.random() * (await Skills.count())), }); const Transaction1 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Transaction1?.setSkill) { await Transaction1.setSkill(relatedSkill1); } const relatedSkill2 = await Skills.findOne({ offset: Math.floor(Math.random() * (await Skills.count())), }); const Transaction2 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Transaction2?.setSkill) { await Transaction2.setSkill(relatedSkill2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Skills.bulkCreate(SkillsData); await Transactions.bulkCreate(TransactionsData); await Promise.all([ // Similar logic for "relation_many" // Similar logic for "relation_many" // Similar logic for "relation_many" await associateTransactionWithLearner(), await associateTransactionWithInstructor(), await associateTransactionWithSkill(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('skills', null, {}); await queryInterface.bulkDelete('transactions', null, {}); }, };