const db = require('../models'); const Users = db.users; const Commands = db.commands; const Plugins = db.plugins; const Projects = db.projects; const Workflows = db.workflows; const CommandsData = [ { command_text: 'sudo apt update', // type code here for "relation_one" field execution_time: new Date('2023-10-01T10:05:00Z'), }, { command_text: 'nginx -s reload', // type code here for "relation_one" field execution_time: new Date('2023-09-15T09:35:00Z'), }, { command_text: 'systemctl restart apache2', // type code here for "relation_one" field execution_time: new Date('2023-08-20T08:25:00Z'), }, ]; const PluginsData = [ { plugin_name: 'Auto Deployer', active: true, // type code here for "relation_many" field }, { plugin_name: 'Security Scanner', active: false, // type code here for "relation_many" field }, { plugin_name: 'Performance Monitor', active: true, // type code here for "relation_many" field }, ]; const ProjectsData = [ { name: 'AI Website Builder', // type code here for "relation_many" field }, { name: 'VPS Management Tool', // type code here for "relation_many" field }, { name: 'Automated Deployment System', // type code here for "relation_many" field }, ]; const WorkflowsData = [ { workflow_name: 'Daily Backup', // type code here for "relation_many" field enabled: true, }, { workflow_name: 'Weekly Security Scan', // type code here for "relation_many" field enabled: false, }, { workflow_name: 'Monthly Performance Review', // type code here for "relation_many" field enabled: true, }, ]; // Similar logic for "relation_many" async function associateCommandWithExecuted_by() { const relatedExecuted_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Command0 = await Commands.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Command0?.setExecuted_by) { await Command0.setExecuted_by(relatedExecuted_by0); } const relatedExecuted_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Command1 = await Commands.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Command1?.setExecuted_by) { await Command1.setExecuted_by(relatedExecuted_by1); } const relatedExecuted_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Command2 = await Commands.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Command2?.setExecuted_by) { await Command2.setExecuted_by(relatedExecuted_by2); } } // Similar logic for "relation_many" // Similar logic for "relation_many" // Similar logic for "relation_many" module.exports = { up: async (queryInterface, Sequelize) => { await Commands.bulkCreate(CommandsData); await Plugins.bulkCreate(PluginsData); await Projects.bulkCreate(ProjectsData); await Workflows.bulkCreate(WorkflowsData); await Promise.all([ // Similar logic for "relation_many" await associateCommandWithExecuted_by(), // Similar logic for "relation_many" // Similar logic for "relation_many" // Similar logic for "relation_many" ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('commands', null, {}); await queryInterface.bulkDelete('plugins', null, {}); await queryInterface.bulkDelete('projects', null, {}); await queryInterface.bulkDelete('workflows', null, {}); }, };