const db = require('../models'); const Users = db.users; const Feedbacks = db.feedbacks; const MockTests = db.mock_tests; const Performances = db.performances; const Questions = db.questions; const Subscriptions = db.subscriptions; const FeedbacksData = [ { // type code here for "relation_one" field content: 'Great platform for practice!', submitted_at: new Date('2023-10-01T15:00:00Z'), }, { // type code here for "relation_one" field content: 'Needs more question variety.', submitted_at: new Date('2023-10-02T16:00:00Z'), }, { // type code here for "relation_one" field content: 'Very helpful analytics.', submitted_at: new Date('2023-10-03T17:00:00Z'), }, ]; const MockTestsData = [ { title: 'JEE Physics Mock Test 1', exam_type: 'NEET', // type code here for "relation_many" field }, { title: 'NEET Biology Mock Test 1', exam_type: 'JEE', // type code here for "relation_many" field }, { title: 'JEE Chemistry Mock Test 2', exam_type: 'JEE', // type code here for "relation_many" field }, ]; const PerformancesData = [ { // type code here for "relation_one" field // type code here for "relation_one" field score: 85.5, completed_at: new Date('2023-10-01T10:00:00Z'), }, { // type code here for "relation_one" field // type code here for "relation_one" field score: 78, completed_at: new Date('2023-10-02T11:00:00Z'), }, { // type code here for "relation_one" field // type code here for "relation_one" field score: 92, completed_at: new Date('2023-10-03T12:00:00Z'), }, ]; const QuestionsData = [ { content: 'What is the acceleration due to gravity on Earth?', difficulty: 'hard', question_type: 'MCQ', // type code here for "relation_one" field }, { content: 'Explain the process of photosynthesis.', difficulty: 'medium', question_type: 'descriptive', // type code here for "relation_one" field }, { content: 'Fill in the blank: The chemical symbol for water is ___.', difficulty: 'easy', question_type: 'descriptive', // type code here for "relation_one" field }, ]; const SubscriptionsData = [ { subscription_type: 'monthly', price: 29.99, // type code here for "relation_one" field }, { subscription_type: 'monthly', price: 5.99, // type code here for "relation_one" field }, { subscription_type: 'pay-per-test', price: 29.99, // type code here for "relation_one" field }, ]; // Similar logic for "relation_many" async function associateFeedbackWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Feedback0 = await Feedbacks.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Feedback0?.setUser) { await Feedback0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Feedback1 = await Feedbacks.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Feedback1?.setUser) { await Feedback1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Feedback2 = await Feedbacks.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Feedback2?.setUser) { await Feedback2.setUser(relatedUser2); } } // Similar logic for "relation_many" async function associatePerformanceWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Performance0 = await Performances.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Performance0?.setUser) { await Performance0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Performance1 = await Performances.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Performance1?.setUser) { await Performance1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Performance2 = await Performances.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Performance2?.setUser) { await Performance2.setUser(relatedUser2); } } async function associatePerformanceWithMock_test() { const relatedMock_test0 = await MockTests.findOne({ offset: Math.floor(Math.random() * (await MockTests.count())), }); const Performance0 = await Performances.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Performance0?.setMock_test) { await Performance0.setMock_test(relatedMock_test0); } const relatedMock_test1 = await MockTests.findOne({ offset: Math.floor(Math.random() * (await MockTests.count())), }); const Performance1 = await Performances.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Performance1?.setMock_test) { await Performance1.setMock_test(relatedMock_test1); } const relatedMock_test2 = await MockTests.findOne({ offset: Math.floor(Math.random() * (await MockTests.count())), }); const Performance2 = await Performances.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Performance2?.setMock_test) { await Performance2.setMock_test(relatedMock_test2); } } async function associateQuestionWithMock_test() { const relatedMock_test0 = await MockTests.findOne({ offset: Math.floor(Math.random() * (await MockTests.count())), }); const Question0 = await Questions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Question0?.setMock_test) { await Question0.setMock_test(relatedMock_test0); } const relatedMock_test1 = await MockTests.findOne({ offset: Math.floor(Math.random() * (await MockTests.count())), }); const Question1 = await Questions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Question1?.setMock_test) { await Question1.setMock_test(relatedMock_test1); } const relatedMock_test2 = await MockTests.findOne({ offset: Math.floor(Math.random() * (await MockTests.count())), }); const Question2 = await Questions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Question2?.setMock_test) { await Question2.setMock_test(relatedMock_test2); } } async function associateSubscriptionWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Subscription0 = await Subscriptions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Subscription0?.setUser) { await Subscription0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Subscription1 = await Subscriptions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Subscription1?.setUser) { await Subscription1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Subscription2 = await Subscriptions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Subscription2?.setUser) { await Subscription2.setUser(relatedUser2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Feedbacks.bulkCreate(FeedbacksData); await MockTests.bulkCreate(MockTestsData); await Performances.bulkCreate(PerformancesData); await Questions.bulkCreate(QuestionsData); await Subscriptions.bulkCreate(SubscriptionsData); await Promise.all([ // Similar logic for "relation_many" await associateFeedbackWithUser(), // Similar logic for "relation_many" await associatePerformanceWithUser(), await associatePerformanceWithMock_test(), await associateQuestionWithMock_test(), await associateSubscriptionWithUser(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('feedbacks', null, {}); await queryInterface.bulkDelete('mock_tests', null, {}); await queryInterface.bulkDelete('performances', null, {}); await queryInterface.bulkDelete('questions', null, {}); await queryInterface.bulkDelete('subscriptions', null, {}); }, };