const db = require('../models'); const Users = db.users; const Ads = db.ads; const Downloads = db.downloads; const Feedback = db.feedback; const Subscriptions = db.subscriptions; const Videos = db.videos; const AdsData = [ { ad_provider: 'Google AdSense', revenue: 150.75, clicks: 300, }, { ad_provider: 'Media.net', revenue: 200.5, clicks: 400, }, { ad_provider: 'Ezoic', revenue: 100.25, clicks: 150, }, { ad_provider: 'AdThrive', revenue: 250, clicks: 500, }, { ad_provider: 'Sovrn', revenue: 175, clicks: 350, }, ]; const DownloadsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field downloaded_at: new Date('2023-10-01T10:00:00Z'), ip_address: '192.168.1.1', }, { // type code here for "relation_one" field // type code here for "relation_one" field downloaded_at: new Date('2023-10-02T11:30:00Z'), ip_address: '192.168.1.2', }, { // type code here for "relation_one" field // type code here for "relation_one" field downloaded_at: new Date('2023-10-03T12:45:00Z'), ip_address: '192.168.1.3', }, { // type code here for "relation_one" field // type code here for "relation_one" field downloaded_at: new Date('2023-10-04T14:00:00Z'), ip_address: '192.168.1.4', }, { // type code here for "relation_one" field // type code here for "relation_one" field downloaded_at: new Date('2023-10-05T15:15:00Z'), ip_address: '192.168.1.5', }, ]; const FeedbackData = [ { user_feedback: 'Fast & smooth download experience!', feedback_type: 'negative', // type code here for "relation_one" field }, { user_feedback: 'Download failed, please fix.', feedback_type: 'positive', // type code here for "relation_one" field }, { user_feedback: 'Great quality videos!', feedback_type: 'positive', // type code here for "relation_one" field }, { user_feedback: 'Encountered an error, needs improvement.', feedback_type: 'negative', // type code here for "relation_one" field }, { user_feedback: 'Easy to use interface.', feedback_type: 'positive', // type code here for "relation_one" field }, ]; const SubscriptionsData = [ { // type code here for "relation_one" field status: 'premium', start_date: new Date('2023-09-01T00:00:00Z'), end_date: new Date('2023-12-01T00:00:00Z'), }, { // type code here for "relation_one" field status: 'trial', start_date: new Date('2023-09-01T00:00:00Z'), end_date: new Date('2023-12-01T00:00:00Z'), }, { // type code here for "relation_one" field status: 'trial', start_date: new Date('2023-09-15T00:00:00Z'), end_date: new Date('2023-10-15T00:00:00Z'), }, { // type code here for "relation_one" field status: 'premium', start_date: new Date('2023-09-01T00:00:00Z'), end_date: new Date('2023-12-01T00:00:00Z'), }, { // type code here for "relation_one" field status: 'trial', start_date: new Date('2023-09-01T00:00:00Z'), end_date: new Date('2023-12-01T00:00:00Z'), }, ]; const VideosData = [ { url: 'https://youtube.com/watch?v=abc123', title: 'Amazing Tech Review', thumbnail: 'https://img.youtube.com/vi/abc123/0.jpg', resolution: '720p', file_size: 150.5, // type code here for "relation_many" field }, { url: 'https://youtube.com/watch?v=def456', title: 'Cooking Masterclass', thumbnail: 'https://img.youtube.com/vi/def456/0.jpg', resolution: '720p', file_size: 200, // type code here for "relation_many" field }, { url: 'https://youtube.com/watch?v=ghi789', title: 'Travel Vlog', thumbnail: 'https://img.youtube.com/vi/ghi789/0.jpg', resolution: '4K', file_size: 500, // type code here for "relation_many" field }, { url: 'https://youtube.com/watch?v=jkl012', title: 'Music Video', thumbnail: 'https://img.youtube.com/vi/jkl012/0.jpg', resolution: '360p', file_size: 50, // type code here for "relation_many" field }, { url: 'https://youtube.com/watch?v=mno345', title: 'Fitness Routine', thumbnail: 'https://img.youtube.com/vi/mno345/0.jpg', resolution: '4K', file_size: 250, // type code here for "relation_many" field }, ]; // Similar logic for "relation_many" async function associateDownloadWithVideo() { const relatedVideo0 = await Videos.findOne({ offset: Math.floor(Math.random() * (await Videos.count())), }); const Download0 = await Downloads.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Download0?.setVideo) { await Download0.setVideo(relatedVideo0); } const relatedVideo1 = await Videos.findOne({ offset: Math.floor(Math.random() * (await Videos.count())), }); const Download1 = await Downloads.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Download1?.setVideo) { await Download1.setVideo(relatedVideo1); } const relatedVideo2 = await Videos.findOne({ offset: Math.floor(Math.random() * (await Videos.count())), }); const Download2 = await Downloads.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Download2?.setVideo) { await Download2.setVideo(relatedVideo2); } const relatedVideo3 = await Videos.findOne({ offset: Math.floor(Math.random() * (await Videos.count())), }); const Download3 = await Downloads.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Download3?.setVideo) { await Download3.setVideo(relatedVideo3); } const relatedVideo4 = await Videos.findOne({ offset: Math.floor(Math.random() * (await Videos.count())), }); const Download4 = await Downloads.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Download4?.setVideo) { await Download4.setVideo(relatedVideo4); } } async function associateDownloadWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Download0 = await Downloads.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Download0?.setUser) { await Download0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Download1 = await Downloads.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Download1?.setUser) { await Download1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Download2 = await Downloads.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Download2?.setUser) { await Download2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Download3 = await Downloads.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Download3?.setUser) { await Download3.setUser(relatedUser3); } const relatedUser4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Download4 = await Downloads.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Download4?.setUser) { await Download4.setUser(relatedUser4); } } async function associateFeedbackWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Feedback0 = await Feedback.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 Feedback.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 Feedback.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Feedback2?.setUser) { await Feedback2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Feedback3 = await Feedback.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Feedback3?.setUser) { await Feedback3.setUser(relatedUser3); } const relatedUser4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Feedback4 = await Feedback.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Feedback4?.setUser) { await Feedback4.setUser(relatedUser4); } } 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); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Subscription3 = await Subscriptions.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Subscription3?.setUser) { await Subscription3.setUser(relatedUser3); } const relatedUser4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Subscription4 = await Subscriptions.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Subscription4?.setUser) { await Subscription4.setUser(relatedUser4); } } // Similar logic for "relation_many" module.exports = { up: async (queryInterface, Sequelize) => { await Ads.bulkCreate(AdsData); await Downloads.bulkCreate(DownloadsData); await Feedback.bulkCreate(FeedbackData); await Subscriptions.bulkCreate(SubscriptionsData); await Videos.bulkCreate(VideosData); await Promise.all([ // Similar logic for "relation_many" await associateDownloadWithVideo(), await associateDownloadWithUser(), await associateFeedbackWithUser(), await associateSubscriptionWithUser(), // Similar logic for "relation_many" ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('ads', null, {}); await queryInterface.bulkDelete('downloads', null, {}); await queryInterface.bulkDelete('feedback', null, {}); await queryInterface.bulkDelete('subscriptions', null, {}); await queryInterface.bulkDelete('videos', null, {}); }, };