const db = require('../models'); const Users = db.users; const Analyses = db.analyses; const Documents = db.documents; const Notifications = db.notifications; const AnalysesData = [ { // type code here for "relation_one" field summary: 'Summary of Contract Agreement 2023', key_points: 'Key obligations and terms', comments: 'Suggestions for improvement', completed_at: new Date('2023-10-01T12:00:00Z'), }, { // type code here for "relation_one" field summary: 'Summary of Service Terms', key_points: 'Important clauses and conditions', comments: 'Legal clarifications needed', completed_at: new Date('2023-10-02T13:30:00Z'), }, { // type code here for "relation_one" field summary: 'Summary of NDA Template', key_points: 'Confidentiality obligations', comments: 'Review for legal compliance', completed_at: new Date('2023-10-03T11:15:00Z'), }, ]; const DocumentsData = [ { title: 'Contract Agreement 2023', // type code here for "files" field // type code here for "relation_one" field uploaded_at: new Date('2023-10-01T10:00:00Z'), }, { title: 'Service Terms Document', // type code here for "files" field // type code here for "relation_one" field uploaded_at: new Date('2023-10-02T11:30:00Z'), }, { title: 'NDA Template', // type code here for "files" field // type code here for "relation_one" field uploaded_at: new Date('2023-10-03T09:15:00Z'), }, ]; const NotificationsData = [ { // type code here for "relation_one" field message: 'Your document analysis is complete.', read: true, sent_at: new Date('2023-10-01T12:05:00Z'), }, { // type code here for "relation_one" field message: 'New document uploaded successfully.', read: true, sent_at: new Date('2023-10-02T11:35:00Z'), }, { // type code here for "relation_one" field message: 'Analysis report is ready for download.', read: true, sent_at: new Date('2023-10-03T11:20:00Z'), }, ]; // Similar logic for "relation_many" async function associateAnalysisWithDocument() { const relatedDocument0 = await Documents.findOne({ offset: Math.floor(Math.random() * (await Documents.count())), }); const Analysis0 = await Analyses.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Analysis0?.setDocument) { await Analysis0.setDocument(relatedDocument0); } const relatedDocument1 = await Documents.findOne({ offset: Math.floor(Math.random() * (await Documents.count())), }); const Analysis1 = await Analyses.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Analysis1?.setDocument) { await Analysis1.setDocument(relatedDocument1); } const relatedDocument2 = await Documents.findOne({ offset: Math.floor(Math.random() * (await Documents.count())), }); const Analysis2 = await Analyses.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Analysis2?.setDocument) { await Analysis2.setDocument(relatedDocument2); } } async function associateDocumentWithUploaded_by() { const relatedUploaded_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Document0 = await Documents.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Document0?.setUploaded_by) { await Document0.setUploaded_by(relatedUploaded_by0); } const relatedUploaded_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Document1 = await Documents.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Document1?.setUploaded_by) { await Document1.setUploaded_by(relatedUploaded_by1); } const relatedUploaded_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Document2 = await Documents.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Document2?.setUploaded_by) { await Document2.setUploaded_by(relatedUploaded_by2); } } async function associateNotificationWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification0 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Notification0?.setUser) { await Notification0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification1 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Notification1?.setUser) { await Notification1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification2 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Notification2?.setUser) { await Notification2.setUser(relatedUser2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Analyses.bulkCreate(AnalysesData); await Documents.bulkCreate(DocumentsData); await Notifications.bulkCreate(NotificationsData); await Promise.all([ // Similar logic for "relation_many" await associateAnalysisWithDocument(), await associateDocumentWithUploaded_by(), await associateNotificationWithUser(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('analyses', null, {}); await queryInterface.bulkDelete('documents', null, {}); await queryInterface.bulkDelete('notifications', null, {}); }, };