const db = require('../models'); const Users = db.users; const Bots = db.bots; const Logs = db.logs; const Metrics = db.metrics; const BotsData = [ { name: 'WeatherBot', // type code here for "files" field is_running: false, // type code here for "relation_one" field }, { name: 'StockBot', // type code here for "files" field is_running: true, // type code here for "relation_one" field }, { name: 'NewsBot', // type code here for "files" field is_running: true, // type code here for "relation_one" field }, { name: 'CryptoBot', // type code here for "files" field is_running: true, // type code here for "relation_one" field }, ]; const LogsData = [ { message: 'Bot started successfully', timestamp: new Date('2023-10-01T10:00:00Z'), // type code here for "relation_one" field }, { message: 'Error: Missing API key', timestamp: new Date('2023-10-01T11:00:00Z'), // type code here for "relation_one" field }, { message: 'Bot stopped by user', timestamp: new Date('2023-10-01T12:00:00Z'), // type code here for "relation_one" field }, { message: 'Bot paused for maintenance', timestamp: new Date('2023-10-01T13:00:00Z'), // type code here for "relation_one" field }, ]; const MetricsData = [ { cpu_usage: 45, ram_usage: 2048, // type code here for "relation_one" field }, { cpu_usage: 60, ram_usage: 3072, // type code here for "relation_one" field }, { cpu_usage: 30, ram_usage: 1024, // type code here for "relation_one" field }, { cpu_usage: 75, ram_usage: 4096, // type code here for "relation_one" field }, ]; // Similar logic for "relation_many" async function associateBotWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Bot0 = await Bots.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Bot0?.setUser) { await Bot0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Bot1 = await Bots.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Bot1?.setUser) { await Bot1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Bot2 = await Bots.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Bot2?.setUser) { await Bot2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Bot3 = await Bots.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Bot3?.setUser) { await Bot3.setUser(relatedUser3); } } async function associateLogWithBot() { const relatedBot0 = await Bots.findOne({ offset: Math.floor(Math.random() * (await Bots.count())), }); const Log0 = await Logs.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Log0?.setBot) { await Log0.setBot(relatedBot0); } const relatedBot1 = await Bots.findOne({ offset: Math.floor(Math.random() * (await Bots.count())), }); const Log1 = await Logs.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Log1?.setBot) { await Log1.setBot(relatedBot1); } const relatedBot2 = await Bots.findOne({ offset: Math.floor(Math.random() * (await Bots.count())), }); const Log2 = await Logs.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Log2?.setBot) { await Log2.setBot(relatedBot2); } const relatedBot3 = await Bots.findOne({ offset: Math.floor(Math.random() * (await Bots.count())), }); const Log3 = await Logs.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Log3?.setBot) { await Log3.setBot(relatedBot3); } } async function associateMetricWithBot() { const relatedBot0 = await Bots.findOne({ offset: Math.floor(Math.random() * (await Bots.count())), }); const Metric0 = await Metrics.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Metric0?.setBot) { await Metric0.setBot(relatedBot0); } const relatedBot1 = await Bots.findOne({ offset: Math.floor(Math.random() * (await Bots.count())), }); const Metric1 = await Metrics.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Metric1?.setBot) { await Metric1.setBot(relatedBot1); } const relatedBot2 = await Bots.findOne({ offset: Math.floor(Math.random() * (await Bots.count())), }); const Metric2 = await Metrics.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Metric2?.setBot) { await Metric2.setBot(relatedBot2); } const relatedBot3 = await Bots.findOne({ offset: Math.floor(Math.random() * (await Bots.count())), }); const Metric3 = await Metrics.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Metric3?.setBot) { await Metric3.setBot(relatedBot3); } } module.exports = { up: async (queryInterface, Sequelize) => { await Bots.bulkCreate(BotsData); await Logs.bulkCreate(LogsData); await Metrics.bulkCreate(MetricsData); await Promise.all([ // Similar logic for "relation_many" await associateBotWithUser(), await associateLogWithBot(), await associateMetricWithBot(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('bots', null, {}); await queryInterface.bulkDelete('logs', null, {}); await queryInterface.bulkDelete('metrics', null, {}); }, };