const db = require('../models'); const Users = db.users; const Categories = db.categories; const Subscriptions = db.subscriptions; const Suggestions = db.suggestions; const Tags = db.tags; const Videos = db.videos; const CategoriesData = [ { name: 'technology', }, { name: 'education', }, { name: 'cooking', }, { name: 'lifestyle', }, ]; const SubscriptionsData = [ { name: 'Basic Plan', price: 9.99, billing_cycle: 'monthly', }, { name: 'Standard Plan', price: 19.99, billing_cycle: 'monthly', }, { name: 'Premium Plan', price: 29.99, billing_cycle: 'yearly', }, { name: 'Annual Basic Plan', price: 99.99, billing_cycle: 'yearly', }, ]; const SuggestionsData = [ { // type code here for "relation_one" field // type code here for "relation_many" field }, { // type code here for "relation_one" field // type code here for "relation_many" field }, { // type code here for "relation_one" field // type code here for "relation_many" field }, { // type code here for "relation_one" field // type code here for "relation_many" field }, ]; const TagsData = [ { name: 'AI', }, { name: 'machine learning', }, { name: 'cooking', }, { name: 'beginner', }, ]; const VideosData = [ { title: 'Introduction to AI', description: 'A comprehensive guide to AI technologies.', release_date: new Date('2023-01-15T10:00:00Z'), // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Cooking Basics', description: "Learn the basics of cooking with this beginner's guide.", release_date: new Date('2023-02-20T12:00:00Z'), // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Yoga for Beginners', description: 'Start your yoga journey with these simple exercises.', release_date: new Date('2023-03-10T08:30:00Z'), // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Travel Vlog: Japan', description: 'Explore the beautiful landscapes of Japan.', release_date: new Date('2023-04-05T14:00:00Z'), // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, ]; // Similar logic for "relation_many" async function associateSuggestionWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Suggestion0 = await Suggestions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Suggestion0?.setUser) { await Suggestion0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Suggestion1 = await Suggestions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Suggestion1?.setUser) { await Suggestion1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Suggestion2 = await Suggestions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Suggestion2?.setUser) { await Suggestion2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Suggestion3 = await Suggestions.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Suggestion3?.setUser) { await Suggestion3.setUser(relatedUser3); } } // Similar logic for "relation_many" // Similar logic for "relation_many" // Similar logic for "relation_many" async function associateVideoWithUploaded_by() { const relatedUploaded_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Video0 = await Videos.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Video0?.setUploaded_by) { await Video0.setUploaded_by(relatedUploaded_by0); } const relatedUploaded_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Video1 = await Videos.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Video1?.setUploaded_by) { await Video1.setUploaded_by(relatedUploaded_by1); } const relatedUploaded_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Video2 = await Videos.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Video2?.setUploaded_by) { await Video2.setUploaded_by(relatedUploaded_by2); } const relatedUploaded_by3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Video3 = await Videos.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Video3?.setUploaded_by) { await Video3.setUploaded_by(relatedUploaded_by3); } } module.exports = { up: async (queryInterface, Sequelize) => { await Categories.bulkCreate(CategoriesData); await Subscriptions.bulkCreate(SubscriptionsData); await Suggestions.bulkCreate(SuggestionsData); await Tags.bulkCreate(TagsData); await Videos.bulkCreate(VideosData); await Promise.all([ // Similar logic for "relation_many" await associateSuggestionWithUser(), // Similar logic for "relation_many" // Similar logic for "relation_many" // Similar logic for "relation_many" await associateVideoWithUploaded_by(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('categories', null, {}); await queryInterface.bulkDelete('subscriptions', null, {}); await queryInterface.bulkDelete('suggestions', null, {}); await queryInterface.bulkDelete('tags', null, {}); await queryInterface.bulkDelete('videos', null, {}); }, };