const db = require('../models'); const Users = db.users; const Contacts = db.contacts; const Lifegroups = db.lifegroups; const ContactsData = [ { full_name: 'John Doe', gender: 'Male', age: 30, contact_information: '123-456-7890', location: 'Downtown', decision_for_christ: 'Yes', other_church_affiliation: true, notes_prayer_needs: 'Pray for job stability', status: 'Baptized', // type code here for "relation_one" field }, { full_name: 'Jane Smith', gender: 'Male', age: 25, contact_information: '987-654-3210', location: 'Uptown', decision_for_christ: 'No', other_church_affiliation: true, notes_prayer_needs: 'Health issues', status: 'Baptized', // type code here for "relation_one" field }, { full_name: 'Michael Johnson', gender: 'Female', age: 40, contact_information: '555-123-4567', location: 'Suburb', decision_for_christ: 'No', other_church_affiliation: true, notes_prayer_needs: 'Family reconciliation', status: 'Evangelized', // type code here for "relation_one" field }, { full_name: 'Emily Davis', gender: 'Other', age: 35, contact_information: '444-555-6666', location: 'City Center', decision_for_christ: 'Yes', other_church_affiliation: true, notes_prayer_needs: 'Guidance in faith', status: 'InLifegroup', // type code here for "relation_one" field }, { full_name: 'Chris Brown', gender: 'Other', age: 28, contact_information: '333-222-1111', location: 'Old Town', decision_for_christ: 'Undecided', other_church_affiliation: true, notes_prayer_needs: 'Career direction', status: 'BeingDiscipled', // type code here for "relation_one" field }, ]; const LifegroupsData = [ { name: 'Downtown Disciples', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Uptown Believers', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Suburb Saints', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'City Center Seekers', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Old Town Outreach', // type code here for "relation_many" field // type code here for "relation_one" field }, ]; // Similar logic for "relation_many" async function associateContactWithAssigned_follow_up_leader() { const relatedAssigned_follow_up_leader0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contact0 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Contact0?.setAssigned_follow_up_leader) { await Contact0.setAssigned_follow_up_leader( relatedAssigned_follow_up_leader0, ); } const relatedAssigned_follow_up_leader1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contact1 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Contact1?.setAssigned_follow_up_leader) { await Contact1.setAssigned_follow_up_leader( relatedAssigned_follow_up_leader1, ); } const relatedAssigned_follow_up_leader2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contact2 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Contact2?.setAssigned_follow_up_leader) { await Contact2.setAssigned_follow_up_leader( relatedAssigned_follow_up_leader2, ); } const relatedAssigned_follow_up_leader3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contact3 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Contact3?.setAssigned_follow_up_leader) { await Contact3.setAssigned_follow_up_leader( relatedAssigned_follow_up_leader3, ); } const relatedAssigned_follow_up_leader4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contact4 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Contact4?.setAssigned_follow_up_leader) { await Contact4.setAssigned_follow_up_leader( relatedAssigned_follow_up_leader4, ); } } // Similar logic for "relation_many" async function associateLifegroupWithLeader() { const relatedLeader0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lifegroup0 = await Lifegroups.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Lifegroup0?.setLeader) { await Lifegroup0.setLeader(relatedLeader0); } const relatedLeader1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lifegroup1 = await Lifegroups.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Lifegroup1?.setLeader) { await Lifegroup1.setLeader(relatedLeader1); } const relatedLeader2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lifegroup2 = await Lifegroups.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Lifegroup2?.setLeader) { await Lifegroup2.setLeader(relatedLeader2); } const relatedLeader3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lifegroup3 = await Lifegroups.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Lifegroup3?.setLeader) { await Lifegroup3.setLeader(relatedLeader3); } const relatedLeader4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lifegroup4 = await Lifegroups.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Lifegroup4?.setLeader) { await Lifegroup4.setLeader(relatedLeader4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Contacts.bulkCreate(ContactsData); await Lifegroups.bulkCreate(LifegroupsData); await Promise.all([ // Similar logic for "relation_many" await associateContactWithAssigned_follow_up_leader(), // Similar logic for "relation_many" await associateLifegroupWithLeader(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('contacts', null, {}); await queryInterface.bulkDelete('lifegroups', null, {}); }, };