const db = require('../models'); const Users = db.users; const Anime = db.anime; const Comments = db.comments; const Episodes = db.episodes; const Subscriptions = db.subscriptions; const Aniplay = db.aniplay; const AnimeData = [ { title: 'Naruto', synopsis: 'A young ninja seeks recognition.', genre: 'mystery', rating: 8.5, release_year: 2002, // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Attack on Titan', synopsis: 'Humans fight against giant Titans.', genre: 'fantasy', rating: 9, release_year: 2013, // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'One Piece', synopsis: 'Pirates search for the ultimate treasure.', genre: 'comedy', rating: 8.9, release_year: 1999, // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'My Hero Academia', synopsis: 'Students train to become heroes.', genre: 'fantasy', rating: 8.4, release_year: 2016, // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Demon Slayer', synopsis: 'A boy fights demons to save his sister.', genre: 'sci-fi', rating: 8.7, release_year: 2019, // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const CommentsData = [ { content: 'Amazing episode!', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { content: "Can't wait for the next one!", // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { content: 'This show is a masterpiece.', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { content: 'Loved the character development.', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { content: 'The animation is top-notch.', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const EpisodesData = [ { title: 'Enter: Naruto Uzumaki!', release_date: new Date('2002-10-03T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'To You, in 2000 Years: The Fall of Shiganshina, Part 1', release_date: new Date('2013-04-07T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: "I'm Luffy! The Man Who's Gonna Be King of the Pirates!", release_date: new Date('1999-10-20T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Izuku Midoriya: Origin', release_date: new Date('2016-04-03T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Cruelty', release_date: new Date('2019-04-06T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const SubscriptionsData = [ { plan: 'free', start_date: new Date('2023-01-01T00:00:00Z'), end_date: new Date('2024-01-01T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { plan: 'premium', start_date: new Date('2023-01-01T00:00:00Z'), end_date: new Date('2023-12-31T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { plan: 'free', start_date: new Date('2023-06-01T00:00:00Z'), end_date: new Date('2024-06-01T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { plan: 'premium', start_date: new Date('2023-03-01T00:00:00Z'), end_date: new Date('2024-03-01T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { plan: 'free', start_date: new Date('2023-09-01T00:00:00Z'), end_date: new Date('2024-09-01T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const AniplayData = [ { name: 'Anime World', }, { name: 'Otaku Hub', }, { name: 'Anime Universe', }, { name: 'Manga Stream', }, { name: 'Anime Central', }, ]; // Similar logic for "relation_many" async function associateUserWithAniplay() { const relatedAniplay0 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setAniplay) { await User0.setAniplay(relatedAniplay0); } const relatedAniplay1 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setAniplay) { await User1.setAniplay(relatedAniplay1); } const relatedAniplay2 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setAniplay) { await User2.setAniplay(relatedAniplay2); } const relatedAniplay3 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setAniplay) { await User3.setAniplay(relatedAniplay3); } const relatedAniplay4 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const User4 = await Users.findOne({ order: [['id', 'ASC']], offset: 4, }); if (User4?.setAniplay) { await User4.setAniplay(relatedAniplay4); } } // Similar logic for "relation_many" // Similar logic for "relation_many" async function associateAnimeWithAniplay() { const relatedAniplay0 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Anime0 = await Anime.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Anime0?.setAniplay) { await Anime0.setAniplay(relatedAniplay0); } const relatedAniplay1 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Anime1 = await Anime.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Anime1?.setAniplay) { await Anime1.setAniplay(relatedAniplay1); } const relatedAniplay2 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Anime2 = await Anime.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Anime2?.setAniplay) { await Anime2.setAniplay(relatedAniplay2); } const relatedAniplay3 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Anime3 = await Anime.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Anime3?.setAniplay) { await Anime3.setAniplay(relatedAniplay3); } const relatedAniplay4 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Anime4 = await Anime.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Anime4?.setAniplay) { await Anime4.setAniplay(relatedAniplay4); } } async function associateCommentWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Comment0 = await Comments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Comment0?.setUser) { await Comment0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Comment1 = await Comments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Comment1?.setUser) { await Comment1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Comment2 = await Comments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Comment2?.setUser) { await Comment2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Comment3 = await Comments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Comment3?.setUser) { await Comment3.setUser(relatedUser3); } const relatedUser4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Comment4 = await Comments.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Comment4?.setUser) { await Comment4.setUser(relatedUser4); } } async function associateCommentWithAnime() { const relatedAnime0 = await Anime.findOne({ offset: Math.floor(Math.random() * (await Anime.count())), }); const Comment0 = await Comments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Comment0?.setAnime) { await Comment0.setAnime(relatedAnime0); } const relatedAnime1 = await Anime.findOne({ offset: Math.floor(Math.random() * (await Anime.count())), }); const Comment1 = await Comments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Comment1?.setAnime) { await Comment1.setAnime(relatedAnime1); } const relatedAnime2 = await Anime.findOne({ offset: Math.floor(Math.random() * (await Anime.count())), }); const Comment2 = await Comments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Comment2?.setAnime) { await Comment2.setAnime(relatedAnime2); } const relatedAnime3 = await Anime.findOne({ offset: Math.floor(Math.random() * (await Anime.count())), }); const Comment3 = await Comments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Comment3?.setAnime) { await Comment3.setAnime(relatedAnime3); } const relatedAnime4 = await Anime.findOne({ offset: Math.floor(Math.random() * (await Anime.count())), }); const Comment4 = await Comments.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Comment4?.setAnime) { await Comment4.setAnime(relatedAnime4); } } async function associateCommentWithAniplay() { const relatedAniplay0 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Comment0 = await Comments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Comment0?.setAniplay) { await Comment0.setAniplay(relatedAniplay0); } const relatedAniplay1 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Comment1 = await Comments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Comment1?.setAniplay) { await Comment1.setAniplay(relatedAniplay1); } const relatedAniplay2 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Comment2 = await Comments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Comment2?.setAniplay) { await Comment2.setAniplay(relatedAniplay2); } const relatedAniplay3 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Comment3 = await Comments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Comment3?.setAniplay) { await Comment3.setAniplay(relatedAniplay3); } const relatedAniplay4 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Comment4 = await Comments.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Comment4?.setAniplay) { await Comment4.setAniplay(relatedAniplay4); } } async function associateEpisodeWithAnime() { const relatedAnime0 = await Anime.findOne({ offset: Math.floor(Math.random() * (await Anime.count())), }); const Episode0 = await Episodes.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Episode0?.setAnime) { await Episode0.setAnime(relatedAnime0); } const relatedAnime1 = await Anime.findOne({ offset: Math.floor(Math.random() * (await Anime.count())), }); const Episode1 = await Episodes.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Episode1?.setAnime) { await Episode1.setAnime(relatedAnime1); } const relatedAnime2 = await Anime.findOne({ offset: Math.floor(Math.random() * (await Anime.count())), }); const Episode2 = await Episodes.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Episode2?.setAnime) { await Episode2.setAnime(relatedAnime2); } const relatedAnime3 = await Anime.findOne({ offset: Math.floor(Math.random() * (await Anime.count())), }); const Episode3 = await Episodes.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Episode3?.setAnime) { await Episode3.setAnime(relatedAnime3); } const relatedAnime4 = await Anime.findOne({ offset: Math.floor(Math.random() * (await Anime.count())), }); const Episode4 = await Episodes.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Episode4?.setAnime) { await Episode4.setAnime(relatedAnime4); } } // Similar logic for "relation_many" async function associateEpisodeWithAniplay() { const relatedAniplay0 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Episode0 = await Episodes.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Episode0?.setAniplay) { await Episode0.setAniplay(relatedAniplay0); } const relatedAniplay1 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Episode1 = await Episodes.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Episode1?.setAniplay) { await Episode1.setAniplay(relatedAniplay1); } const relatedAniplay2 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Episode2 = await Episodes.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Episode2?.setAniplay) { await Episode2.setAniplay(relatedAniplay2); } const relatedAniplay3 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Episode3 = await Episodes.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Episode3?.setAniplay) { await Episode3.setAniplay(relatedAniplay3); } const relatedAniplay4 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Episode4 = await Episodes.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Episode4?.setAniplay) { await Episode4.setAniplay(relatedAniplay4); } } 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); } } async function associateSubscriptionWithAniplay() { const relatedAniplay0 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Subscription0 = await Subscriptions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Subscription0?.setAniplay) { await Subscription0.setAniplay(relatedAniplay0); } const relatedAniplay1 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Subscription1 = await Subscriptions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Subscription1?.setAniplay) { await Subscription1.setAniplay(relatedAniplay1); } const relatedAniplay2 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Subscription2 = await Subscriptions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Subscription2?.setAniplay) { await Subscription2.setAniplay(relatedAniplay2); } const relatedAniplay3 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Subscription3 = await Subscriptions.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Subscription3?.setAniplay) { await Subscription3.setAniplay(relatedAniplay3); } const relatedAniplay4 = await Aniplay.findOne({ offset: Math.floor(Math.random() * (await Aniplay.count())), }); const Subscription4 = await Subscriptions.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Subscription4?.setAniplay) { await Subscription4.setAniplay(relatedAniplay4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Anime.bulkCreate(AnimeData); await Comments.bulkCreate(CommentsData); await Episodes.bulkCreate(EpisodesData); await Subscriptions.bulkCreate(SubscriptionsData); await Aniplay.bulkCreate(AniplayData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithAniplay(), // Similar logic for "relation_many" // Similar logic for "relation_many" await associateAnimeWithAniplay(), await associateCommentWithUser(), await associateCommentWithAnime(), await associateCommentWithAniplay(), await associateEpisodeWithAnime(), // Similar logic for "relation_many" await associateEpisodeWithAniplay(), await associateSubscriptionWithUser(), await associateSubscriptionWithAniplay(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('anime', null, {}); await queryInterface.bulkDelete('comments', null, {}); await queryInterface.bulkDelete('episodes', null, {}); await queryInterface.bulkDelete('subscriptions', null, {}); await queryInterface.bulkDelete('aniplay', null, {}); }, };