const db = require('../models'); const Users = db.users; const Files = db.files; const FilesData = [ { file_name: 'report_2023.txt', // type code here for "files" field file_format: 'csv', download_count: 5, // type code here for "relation_one" field }, { file_name: 'sales_data.csv', // type code here for "files" field file_format: 'txt', download_count: 12, // type code here for "relation_one" field }, { file_name: 'project_plan.txt', // type code here for "files" field file_format: 'csv', download_count: 8, // type code here for "relation_one" field }, ]; // Similar logic for "relation_many" async function associateFileWithUploaded_by() { const relatedUploaded_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const File0 = await Files.findOne({ order: [['id', 'ASC']], offset: 0, }); if (File0?.setUploaded_by) { await File0.setUploaded_by(relatedUploaded_by0); } const relatedUploaded_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const File1 = await Files.findOne({ order: [['id', 'ASC']], offset: 1, }); if (File1?.setUploaded_by) { await File1.setUploaded_by(relatedUploaded_by1); } const relatedUploaded_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const File2 = await Files.findOne({ order: [['id', 'ASC']], offset: 2, }); if (File2?.setUploaded_by) { await File2.setUploaded_by(relatedUploaded_by2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Files.bulkCreate(FilesData); await Promise.all([ // Similar logic for "relation_many" await associateFileWithUploaded_by(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('files', null, {}); }, };