const db = require('../models'); const Users = db.users; const Dashboards = db.dashboards; const Posts = db.posts; const Sentiments = db.sentiments; const Companies = db.companies; const DashboardsData = [ { title: 'AI Trends Overview', // type code here for "relation_many" field // type code here for "relation_many" field }, { title: 'Healthcare AI Insights', // type code here for "relation_many" field // type code here for "relation_many" field }, { title: 'Education AI Analysis', // type code here for "relation_many" field // type code here for "relation_many" field }, { title: 'Sustainable Energy AI', // type code here for "relation_many" field // type code here for "relation_many" field }, ]; const PostsData = [ { content: 'Exploring the latest in AI advancements.', posted_at: new Date('2023-10-01T10:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { content: 'AI is transforming the healthcare industry.', posted_at: new Date('2023-10-02T11:30:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { content: 'The impact of AI on education.', posted_at: new Date('2023-10-03T09:15:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { content: 'AI and its role in sustainable energy.', posted_at: new Date('2023-10-04T14:45:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const SentimentsData = [ { sentiment_type: 'neutral', score: 0.85, // type code here for "relation_one" field // type code here for "relation_one" field }, { sentiment_type: 'neutral', score: 0.5, // type code here for "relation_one" field // type code here for "relation_one" field }, { sentiment_type: 'positive', score: 0.3, // type code here for "relation_one" field // type code here for "relation_one" field }, { sentiment_type: 'positive', score: 0.9, // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const CompaniesData = [ { name: 'Tech Innovators', }, { name: 'Green Solutions', }, { name: 'Health First', }, { name: 'EduTech', }, ]; // Similar logic for "relation_many" async function associateUserWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setCompany) { await User0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setCompany) { await User1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setCompany) { await User2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setCompany) { await User3.setCompany(relatedCompany3); } } // Similar logic for "relation_many" // Similar logic for "relation_many" async function associatePostWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Post0 = await Posts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Post0?.setCompany) { await Post0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Post1 = await Posts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Post1?.setCompany) { await Post1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Post2 = await Posts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Post2?.setCompany) { await Post2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Post3 = await Posts.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Post3?.setCompany) { await Post3.setCompany(relatedCompany3); } } async function associatePostWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Post0 = await Posts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Post0?.setCompany) { await Post0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Post1 = await Posts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Post1?.setCompany) { await Post1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Post2 = await Posts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Post2?.setCompany) { await Post2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Post3 = await Posts.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Post3?.setCompany) { await Post3.setCompany(relatedCompany3); } } async function associateSentimentWithPost() { const relatedPost0 = await Posts.findOne({ offset: Math.floor(Math.random() * (await Posts.count())), }); const Sentiment0 = await Sentiments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Sentiment0?.setPost) { await Sentiment0.setPost(relatedPost0); } const relatedPost1 = await Posts.findOne({ offset: Math.floor(Math.random() * (await Posts.count())), }); const Sentiment1 = await Sentiments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Sentiment1?.setPost) { await Sentiment1.setPost(relatedPost1); } const relatedPost2 = await Posts.findOne({ offset: Math.floor(Math.random() * (await Posts.count())), }); const Sentiment2 = await Sentiments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Sentiment2?.setPost) { await Sentiment2.setPost(relatedPost2); } const relatedPost3 = await Posts.findOne({ offset: Math.floor(Math.random() * (await Posts.count())), }); const Sentiment3 = await Sentiments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Sentiment3?.setPost) { await Sentiment3.setPost(relatedPost3); } } async function associateSentimentWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Sentiment0 = await Sentiments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Sentiment0?.setCompany) { await Sentiment0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Sentiment1 = await Sentiments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Sentiment1?.setCompany) { await Sentiment1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Sentiment2 = await Sentiments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Sentiment2?.setCompany) { await Sentiment2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Sentiment3 = await Sentiments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Sentiment3?.setCompany) { await Sentiment3.setCompany(relatedCompany3); } } module.exports = { up: async (queryInterface, Sequelize) => { await Dashboards.bulkCreate(DashboardsData); await Posts.bulkCreate(PostsData); await Sentiments.bulkCreate(SentimentsData); await Companies.bulkCreate(CompaniesData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithCompany(), // Similar logic for "relation_many" // Similar logic for "relation_many" await associatePostWithCompany(), await associatePostWithCompany(), await associateSentimentWithPost(), await associateSentimentWithCompany(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('dashboards', null, {}); await queryInterface.bulkDelete('posts', null, {}); await queryInterface.bulkDelete('sentiments', null, {}); await queryInterface.bulkDelete('companies', null, {}); }, };