const db = require('../models'); const Users = db.users; const Assessments = db.assessments; const Phones = db.phones; const AssessmentsData = [ { // type code here for "relation_one" field assessment_date: new Date('2023-10-01T10:00:00Z'), hardware_status: 'Good condition', software_status: 'Up to date', is_functional: true, }, { // type code here for "relation_one" field assessment_date: new Date('2023-10-02T11:00:00Z'), hardware_status: 'Minor scratches', software_status: 'Needs update', is_functional: true, }, { // type code here for "relation_one" field assessment_date: new Date('2023-10-03T12:00:00Z'), hardware_status: 'Excellent', software_status: 'Up to date', is_functional: true, }, ]; const PhonesData = [ { model: 'Galaxy S21', manufacturer: 'Samsung', os: 'iOS', screen_size: 6.2, battery_capacity: 4000, // type code here for "relation_one" field }, { model: 'iPhone 13', manufacturer: 'Apple', os: 'Android', screen_size: 6.1, battery_capacity: 3095, // type code here for "relation_one" field }, { model: 'Pixel 6', manufacturer: 'Google', os: 'iOS', screen_size: 6.4, battery_capacity: 4614, // type code here for "relation_one" field }, ]; // Similar logic for "relation_many" async function associateAssessmentWithPhone() { const relatedPhone0 = await Phones.findOne({ offset: Math.floor(Math.random() * (await Phones.count())), }); const Assessment0 = await Assessments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Assessment0?.setPhone) { await Assessment0.setPhone(relatedPhone0); } const relatedPhone1 = await Phones.findOne({ offset: Math.floor(Math.random() * (await Phones.count())), }); const Assessment1 = await Assessments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Assessment1?.setPhone) { await Assessment1.setPhone(relatedPhone1); } const relatedPhone2 = await Phones.findOne({ offset: Math.floor(Math.random() * (await Phones.count())), }); const Assessment2 = await Assessments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Assessment2?.setPhone) { await Assessment2.setPhone(relatedPhone2); } } async function associatePhoneWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Phone0 = await Phones.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Phone0?.setUser) { await Phone0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Phone1 = await Phones.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Phone1?.setUser) { await Phone1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Phone2 = await Phones.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Phone2?.setUser) { await Phone2.setUser(relatedUser2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Assessments.bulkCreate(AssessmentsData); await Phones.bulkCreate(PhonesData); await Promise.all([ // Similar logic for "relation_many" await associateAssessmentWithPhone(), await associatePhoneWithUser(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('assessments', null, {}); await queryInterface.bulkDelete('phones', null, {}); }, };