const db = require('../models'); const Users = db.users; const ImageEdits = db.image_edits; const Teams = db.teams; const Companies = db.companies; const ImageEditsData = [ { title: 'Sunset Enhancement', // type code here for "relation_one" field // type code here for "relation_one" field status: 'Pending', // type code here for "files" field // type code here for "files" field // type code here for "relation_one" field }, { title: 'Portrait Retouch', // type code here for "relation_one" field // type code here for "relation_one" field status: 'Processing', // type code here for "files" field // type code here for "files" field // type code here for "relation_one" field }, { title: 'Landscape Adjustment', // type code here for "relation_one" field // type code here for "relation_one" field status: 'Pending', // type code here for "files" field // type code here for "files" field // type code here for "relation_one" field }, ]; const TeamsData = [ { name: 'Bhavesh Rajgor', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Fernanda Bollain', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Creative Team', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const CompaniesData = [ { name: 'PS Retouch Service', }, { name: 'Creative Edits Co.', }, { name: 'Image Innovators', }, ]; // Similar logic for "relation_many" async function associateUserWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setCompany) { await User0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setCompany) { await User1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setCompany) { await User2.setCompany(relatedCompany2); } } async function associateImageEditWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ImageEdit0 = await ImageEdits.findOne({ order: [['id', 'ASC']], offset: 0, }); if (ImageEdit0?.setUser) { await ImageEdit0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ImageEdit1 = await ImageEdits.findOne({ order: [['id', 'ASC']], offset: 1, }); if (ImageEdit1?.setUser) { await ImageEdit1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ImageEdit2 = await ImageEdits.findOne({ order: [['id', 'ASC']], offset: 2, }); if (ImageEdit2?.setUser) { await ImageEdit2.setUser(relatedUser2); } } async function associateImageEditWithTeam() { const relatedTeam0 = await Teams.findOne({ offset: Math.floor(Math.random() * (await Teams.count())), }); const ImageEdit0 = await ImageEdits.findOne({ order: [['id', 'ASC']], offset: 0, }); if (ImageEdit0?.setTeam) { await ImageEdit0.setTeam(relatedTeam0); } const relatedTeam1 = await Teams.findOne({ offset: Math.floor(Math.random() * (await Teams.count())), }); const ImageEdit1 = await ImageEdits.findOne({ order: [['id', 'ASC']], offset: 1, }); if (ImageEdit1?.setTeam) { await ImageEdit1.setTeam(relatedTeam1); } const relatedTeam2 = await Teams.findOne({ offset: Math.floor(Math.random() * (await Teams.count())), }); const ImageEdit2 = await ImageEdits.findOne({ order: [['id', 'ASC']], offset: 2, }); if (ImageEdit2?.setTeam) { await ImageEdit2.setTeam(relatedTeam2); } } async function associateImageEditWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const ImageEdit0 = await ImageEdits.findOne({ order: [['id', 'ASC']], offset: 0, }); if (ImageEdit0?.setCompany) { await ImageEdit0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const ImageEdit1 = await ImageEdits.findOne({ order: [['id', 'ASC']], offset: 1, }); if (ImageEdit1?.setCompany) { await ImageEdit1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const ImageEdit2 = await ImageEdits.findOne({ order: [['id', 'ASC']], offset: 2, }); if (ImageEdit2?.setCompany) { await ImageEdit2.setCompany(relatedCompany2); } } async function associateTeamWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Team0 = await Teams.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Team0?.setCompany) { await Team0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Team1 = await Teams.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Team1?.setCompany) { await Team1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Team2 = await Teams.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Team2?.setCompany) { await Team2.setCompany(relatedCompany2); } } // Similar logic for "relation_many" async function associateTeamWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Team0 = await Teams.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Team0?.setCompany) { await Team0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Team1 = await Teams.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Team1?.setCompany) { await Team1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Team2 = await Teams.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Team2?.setCompany) { await Team2.setCompany(relatedCompany2); } } module.exports = { up: async (queryInterface, Sequelize) => { await ImageEdits.bulkCreate(ImageEditsData); await Teams.bulkCreate(TeamsData); await Companies.bulkCreate(CompaniesData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithCompany(), await associateImageEditWithUser(), await associateImageEditWithTeam(), await associateImageEditWithCompany(), await associateTeamWithCompany(), // Similar logic for "relation_many" await associateTeamWithCompany(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('image_edits', null, {}); await queryInterface.bulkDelete('teams', null, {}); await queryInterface.bulkDelete('companies', null, {}); }, };