const db = require('../models'); const Users = db.users; const Batches = db.batches; const Logs = db.logs; const ScannedDocuments = db.scanned_documents; const BatchesData = [ { batch_number: 'BATCH001', // type code here for "relation_many" field submitted_at: new Date('2023-10-06T15:00:00Z'), status: 'Error', // type code here for "relation_one" field }, { batch_number: 'BATCH002', // type code here for "relation_many" field submitted_at: new Date('2023-10-07T16:00:00Z'), status: 'Pending', // type code here for "relation_one" field }, { batch_number: 'BATCH003', // type code here for "relation_many" field submitted_at: new Date('2023-10-08T17:00:00Z'), status: 'Processing', // type code here for "relation_one" field }, { batch_number: 'BATCH004', // type code here for "relation_many" field submitted_at: new Date('2023-10-09T18:00:00Z'), status: 'Completed', // type code here for "relation_one" field }, ]; const LogsData = [ { action: 'Uploaded document', timestamp: new Date('2023-10-01T10:05:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { action: 'Submitted batch', timestamp: new Date('2023-10-06T15:05:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { action: 'Processed batch', timestamp: new Date('2023-10-07T16:10:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { action: 'Completed batch', timestamp: new Date('2023-10-08T17:15:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const ScannedDocumentsData = [ { file_name: 'claim_form_001.pdf', // type code here for "files" field uploaded_at: new Date('2023-10-01T10:00:00Z'), // type code here for "relation_one" field }, { file_name: 'claim_form_002.pdf', // type code here for "files" field uploaded_at: new Date('2023-10-02T11:00:00Z'), // type code here for "relation_one" field }, { file_name: 'claim_form_003.pdf', // type code here for "files" field uploaded_at: new Date('2023-10-03T12:00:00Z'), // type code here for "relation_one" field }, { file_name: 'claim_form_004.pdf', // type code here for "files" field uploaded_at: new Date('2023-10-04T13:00:00Z'), // type code here for "relation_one" field }, ]; // Similar logic for "relation_many" // Similar logic for "relation_many" async function associateBatchWithSubmitted_by() { const relatedSubmitted_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Batch0 = await Batches.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Batch0?.setSubmitted_by) { await Batch0.setSubmitted_by(relatedSubmitted_by0); } const relatedSubmitted_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Batch1 = await Batches.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Batch1?.setSubmitted_by) { await Batch1.setSubmitted_by(relatedSubmitted_by1); } const relatedSubmitted_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Batch2 = await Batches.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Batch2?.setSubmitted_by) { await Batch2.setSubmitted_by(relatedSubmitted_by2); } const relatedSubmitted_by3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Batch3 = await Batches.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Batch3?.setSubmitted_by) { await Batch3.setSubmitted_by(relatedSubmitted_by3); } } async function associateLogWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Log0 = await Logs.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Log0?.setUser) { await Log0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Log1 = await Logs.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Log1?.setUser) { await Log1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Log2 = await Logs.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Log2?.setUser) { await Log2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Log3 = await Logs.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Log3?.setUser) { await Log3.setUser(relatedUser3); } } async function associateLogWithBatch() { const relatedBatch0 = await Batches.findOne({ offset: Math.floor(Math.random() * (await Batches.count())), }); const Log0 = await Logs.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Log0?.setBatch) { await Log0.setBatch(relatedBatch0); } const relatedBatch1 = await Batches.findOne({ offset: Math.floor(Math.random() * (await Batches.count())), }); const Log1 = await Logs.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Log1?.setBatch) { await Log1.setBatch(relatedBatch1); } const relatedBatch2 = await Batches.findOne({ offset: Math.floor(Math.random() * (await Batches.count())), }); const Log2 = await Logs.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Log2?.setBatch) { await Log2.setBatch(relatedBatch2); } const relatedBatch3 = await Batches.findOne({ offset: Math.floor(Math.random() * (await Batches.count())), }); const Log3 = await Logs.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Log3?.setBatch) { await Log3.setBatch(relatedBatch3); } } async function associateScannedDocumentWithUploaded_by() { const relatedUploaded_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ScannedDocument0 = await ScannedDocuments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (ScannedDocument0?.setUploaded_by) { await ScannedDocument0.setUploaded_by(relatedUploaded_by0); } const relatedUploaded_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ScannedDocument1 = await ScannedDocuments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (ScannedDocument1?.setUploaded_by) { await ScannedDocument1.setUploaded_by(relatedUploaded_by1); } const relatedUploaded_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ScannedDocument2 = await ScannedDocuments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (ScannedDocument2?.setUploaded_by) { await ScannedDocument2.setUploaded_by(relatedUploaded_by2); } const relatedUploaded_by3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ScannedDocument3 = await ScannedDocuments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (ScannedDocument3?.setUploaded_by) { await ScannedDocument3.setUploaded_by(relatedUploaded_by3); } } module.exports = { up: async (queryInterface, Sequelize) => { await Batches.bulkCreate(BatchesData); await Logs.bulkCreate(LogsData); await ScannedDocuments.bulkCreate(ScannedDocumentsData); await Promise.all([ // Similar logic for "relation_many" // Similar logic for "relation_many" await associateBatchWithSubmitted_by(), await associateLogWithUser(), await associateLogWithBatch(), await associateScannedDocumentWithUploaded_by(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('batches', null, {}); await queryInterface.bulkDelete('logs', null, {}); await queryInterface.bulkDelete('scanned_documents', null, {}); }, };