const db = require('../models'); const Users = db.users; const Animations = db.animations; const Materials = db.materials; const Objects = db.objects; const Projects = db.projects; const AnimationsData = [ { name: 'Animation One', start_time: new Date('2023-10-01T10:00:00Z'), end_time: new Date('2023-10-01T11:00:00Z'), // type code here for "relation_one" field }, { name: 'Animation Two', start_time: new Date('2023-10-02T10:00:00Z'), end_time: new Date('2023-10-02T11:00:00Z'), // type code here for "relation_one" field }, { name: 'Animation Three', start_time: new Date('2023-10-03T10:00:00Z'), end_time: new Date('2023-10-03T11:00:00Z'), // type code here for "relation_one" field }, { name: 'Animation Four', start_time: new Date('2023-10-04T10:00:00Z'), end_time: new Date('2023-10-04T11:00:00Z'), // type code here for "relation_one" field }, ]; const MaterialsData = [ { name: 'Material A', color: '#FF5733', // type code here for "relation_one" field }, { name: 'Material B', color: '#33FF57', // type code here for "relation_one" field }, { name: 'Material C', color: '#3357FF', // type code here for "relation_one" field }, { name: 'Material D', color: '#FF33A1', // type code here for "relation_one" field }, ]; const ObjectsData = [ { name: 'Cube One', type: 'sphere', // type code here for "relation_one" field }, { name: 'Sphere One', type: 'camera', // type code here for "relation_one" field }, { name: 'Plane One', type: 'cube', // type code here for "relation_one" field }, { name: 'Camera One', type: 'sphere', // type code here for "relation_one" field }, ]; const ProjectsData = [ { name: 'Project Alpha', description: 'A groundbreaking 3D modeling project.', // type code here for "relation_many" field }, { name: 'Project Beta', description: 'An innovative animation project.', // type code here for "relation_many" field }, { name: 'Project Gamma', description: 'A collaborative 3D rendering project.', // type code here for "relation_many" field }, { name: 'Project Delta', description: 'A new approach to 3D design.', // type code here for "relation_many" field }, ]; // Similar logic for "relation_many" async function associateAnimationWithObject() { const relatedObject0 = await Objects.findOne({ offset: Math.floor(Math.random() * (await Objects.count())), }); const Animation0 = await Animations.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Animation0?.setObject) { await Animation0.setObject(relatedObject0); } const relatedObject1 = await Objects.findOne({ offset: Math.floor(Math.random() * (await Objects.count())), }); const Animation1 = await Animations.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Animation1?.setObject) { await Animation1.setObject(relatedObject1); } const relatedObject2 = await Objects.findOne({ offset: Math.floor(Math.random() * (await Objects.count())), }); const Animation2 = await Animations.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Animation2?.setObject) { await Animation2.setObject(relatedObject2); } const relatedObject3 = await Objects.findOne({ offset: Math.floor(Math.random() * (await Objects.count())), }); const Animation3 = await Animations.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Animation3?.setObject) { await Animation3.setObject(relatedObject3); } } async function associateMaterialWithObject() { const relatedObject0 = await Objects.findOne({ offset: Math.floor(Math.random() * (await Objects.count())), }); const Material0 = await Materials.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Material0?.setObject) { await Material0.setObject(relatedObject0); } const relatedObject1 = await Objects.findOne({ offset: Math.floor(Math.random() * (await Objects.count())), }); const Material1 = await Materials.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Material1?.setObject) { await Material1.setObject(relatedObject1); } const relatedObject2 = await Objects.findOne({ offset: Math.floor(Math.random() * (await Objects.count())), }); const Material2 = await Materials.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Material2?.setObject) { await Material2.setObject(relatedObject2); } const relatedObject3 = await Objects.findOne({ offset: Math.floor(Math.random() * (await Objects.count())), }); const Material3 = await Materials.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Material3?.setObject) { await Material3.setObject(relatedObject3); } } async function associateObjectWithProject() { const relatedProject0 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Object0 = await Objects.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Object0?.setProject) { await Object0.setProject(relatedProject0); } const relatedProject1 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Object1 = await Objects.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Object1?.setProject) { await Object1.setProject(relatedProject1); } const relatedProject2 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Object2 = await Objects.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Object2?.setProject) { await Object2.setProject(relatedProject2); } const relatedProject3 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Object3 = await Objects.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Object3?.setProject) { await Object3.setProject(relatedProject3); } } // Similar logic for "relation_many" module.exports = { up: async (queryInterface, Sequelize) => { await Animations.bulkCreate(AnimationsData); await Materials.bulkCreate(MaterialsData); await Objects.bulkCreate(ObjectsData); await Projects.bulkCreate(ProjectsData); await Promise.all([ // Similar logic for "relation_many" await associateAnimationWithObject(), await associateMaterialWithObject(), await associateObjectWithProject(), // Similar logic for "relation_many" ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('animations', null, {}); await queryInterface.bulkDelete('materials', null, {}); await queryInterface.bulkDelete('objects', null, {}); await queryInterface.bulkDelete('projects', null, {}); }, };