const db = require('../models'); const Users = db.users; const EventDetails = db.event_details; const HelpDetails = db.help_details; const Images = db.images; const Notifications = db.notifications; const ProductDetails = db.product_details; const Products = db.products; const SessionRequests = db.session_requests; const Sessions = db.sessions; const EventDetailsData = [ { // type code here for "relation_one" field price: 0, deadline: new Date('2023-12-01T00:00:00Z'), status: 'closed', }, { // type code here for "relation_one" field price: 0, deadline: new Date('2023-11-15T00:00:00Z'), status: 'closed', }, { // type code here for "relation_one" field price: 0, deadline: new Date('2023-10-10T00:00:00Z'), status: 'open', }, ]; const HelpDetailsData = [ { // type code here for "relation_one" field deadline: new Date('2023-12-31T00:00:00Z'), status: 'open', }, { // type code here for "relation_one" field deadline: new Date('2023-11-30T00:00:00Z'), status: 'closed', }, { // type code here for "relation_one" field deadline: new Date('2023-10-15T00:00:00Z'), status: 'open', }, ]; const ImagesData = [ { // type code here for "relation_one" field // type code here for "images" field is_primary: true, }, { // type code here for "relation_one" field // type code here for "images" field is_primary: true, }, { // type code here for "relation_one" field // type code here for "images" field is_primary: true, }, ]; const NotificationsData = [ { // type code here for "relation_one" field type: 'session_joined', message: 'You have joined a session.', timestamp: new Date('2023-11-01T12:00:00Z'), read_status: true, // type code here for "relation_one" field // type code here for "relation_one" field }, { // type code here for "relation_one" field type: 'request_accepted', message: 'Your request has been accepted.', timestamp: new Date('2023-11-02T13:00:00Z'), read_status: true, // type code here for "relation_one" field // type code here for "relation_one" field }, { // type code here for "relation_one" field type: 'request_accepted', message: 'You have joined a session.', timestamp: new Date('2023-11-03T14:00:00Z'), read_status: true, // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const ProductDetailsData = [ { // type code here for "relation_one" field price: 20.5, price_unit: 'perlitru', stock_availability: true, }, { // type code here for "relation_one" field price: 15, price_unit: 'perkg', stock_availability: true, }, { // type code here for "relation_one" field price: 0, price_unit: 'perlitru', stock_availability: true, }, ]; const ProductsData = [ { title: 'Organic Honey', description: 'Pure organic honey from local beekeepers.', type: 'event', accepts_cash: true, accepts_online_payment: true, location_address: '123 Village Road', location_lat: 45.9432, location_lng: 24.9668, region: 'Transylvania', social_website: 'http://honeyfarm.com', social_youtube: 'http://youtube.com/honeyfarm', social_instagram: 'http://instagram.com/honeyfarm', social_tiktok: 'http://tiktok.com/honeyfarm', social_facebook: 'http://facebook.com/honeyfarm', }, { title: 'Handmade Pottery', description: 'Beautiful handmade pottery crafted by local artisans.', type: 'sell_product', accepts_cash: true, accepts_online_payment: false, location_address: '456 Artisan Street', location_lat: 46.7704, location_lng: 23.5914, region: 'Cluj', social_website: 'http://potteryart.com', social_youtube: 'http://youtube.com/potteryart', social_instagram: 'http://instagram.com/potteryart', social_tiktok: 'http://tiktok.com/potteryart', social_facebook: 'http://facebook.com/potteryart', }, { title: 'Community Clean-Up', description: 'Join us for a community clean-up event.', type: 'sell_product', accepts_cash: false, accepts_online_payment: true, location_address: '789 Community Park', location_lat: 47.1585, location_lng: 27.6014, region: 'Iasi', social_website: 'http://cleanupcommunity.com', social_youtube: 'http://youtube.com/cleanupcommunity', social_instagram: 'http://instagram.com/cleanupcommunity', social_tiktok: 'http://tiktok.com/cleanupcommunity', social_facebook: 'http://facebook.com/cleanupcommunity', }, ]; const SessionRequestsData = [ { // type code here for "relation_one" field area: 'Transylvania', // type code here for "relation_one" field status: 'pending', }, { // type code here for "relation_one" field area: 'Cluj', // type code here for "relation_one" field status: 'accepted', }, { // type code here for "relation_one" field area: 'Iasi', // type code here for "relation_one" field status: 'declined', }, ]; const SessionsData = [ { // type code here for "relation_one" field trip_type: 'volunteer', session_validity: '48h', car_type: 'van', max_participants: 5, notes_for_applicants: 'Bring your own bags.', departure_location: '123 Village Road', location_lat: 45.9432, location_lng: 24.9668, departure_time: new Date('2023-12-01T08:00:00Z'), personal_fee: 5, status: 'almost_full', // type code here for "relation_many" field }, { // type code here for "relation_one" field trip_type: 'ride_share', session_validity: '6h', car_type: 'smallcar', max_participants: 3, notes_for_applicants: 'Wear comfortable clothes.', departure_location: '456 Artisan Street', location_lat: 46.7704, location_lng: 23.5914, departure_time: new Date('2023-12-02T09:00:00Z'), personal_fee: 0, status: 'full', // type code here for "relation_many" field }, { // type code here for "relation_one" field trip_type: 'ride_share', session_validity: '12h', car_type: 'truck', max_participants: 10, notes_for_applicants: 'Be on time.', departure_location: '789 Community Park', location_lat: 47.1585, location_lng: 27.6014, departure_time: new Date('2023-12-03T10:00:00Z'), personal_fee: 10, status: 'open', // type code here for "relation_many" field }, ]; // Similar logic for "relation_many" async function associateEventDetailWithPost() { const relatedPost0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const EventDetail0 = await EventDetails.findOne({ order: [['id', 'ASC']], offset: 0, }); if (EventDetail0?.setPost) { await EventDetail0.setPost(relatedPost0); } const relatedPost1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const EventDetail1 = await EventDetails.findOne({ order: [['id', 'ASC']], offset: 1, }); if (EventDetail1?.setPost) { await EventDetail1.setPost(relatedPost1); } const relatedPost2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const EventDetail2 = await EventDetails.findOne({ order: [['id', 'ASC']], offset: 2, }); if (EventDetail2?.setPost) { await EventDetail2.setPost(relatedPost2); } } async function associateHelpDetailWithPost() { const relatedPost0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const HelpDetail0 = await HelpDetails.findOne({ order: [['id', 'ASC']], offset: 0, }); if (HelpDetail0?.setPost) { await HelpDetail0.setPost(relatedPost0); } const relatedPost1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const HelpDetail1 = await HelpDetails.findOne({ order: [['id', 'ASC']], offset: 1, }); if (HelpDetail1?.setPost) { await HelpDetail1.setPost(relatedPost1); } const relatedPost2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const HelpDetail2 = await HelpDetails.findOne({ order: [['id', 'ASC']], offset: 2, }); if (HelpDetail2?.setPost) { await HelpDetail2.setPost(relatedPost2); } } async function associateImageWithPost() { const relatedPost0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Image0 = await Images.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Image0?.setPost) { await Image0.setPost(relatedPost0); } const relatedPost1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Image1 = await Images.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Image1?.setPost) { await Image1.setPost(relatedPost1); } const relatedPost2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Image2 = await Images.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Image2?.setPost) { await Image2.setPost(relatedPost2); } } async function associateNotificationWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification0 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Notification0?.setUser) { await Notification0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification1 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Notification1?.setUser) { await Notification1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification2 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Notification2?.setUser) { await Notification2.setUser(relatedUser2); } } async function associateNotificationWithLinked_product() { const relatedLinked_product0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Notification0 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Notification0?.setLinked_product) { await Notification0.setLinked_product(relatedLinked_product0); } const relatedLinked_product1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Notification1 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Notification1?.setLinked_product) { await Notification1.setLinked_product(relatedLinked_product1); } const relatedLinked_product2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Notification2 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Notification2?.setLinked_product) { await Notification2.setLinked_product(relatedLinked_product2); } } async function associateNotificationWithLinked_session() { const relatedLinked_session0 = await Sessions.findOne({ offset: Math.floor(Math.random() * (await Sessions.count())), }); const Notification0 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Notification0?.setLinked_session) { await Notification0.setLinked_session(relatedLinked_session0); } const relatedLinked_session1 = await Sessions.findOne({ offset: Math.floor(Math.random() * (await Sessions.count())), }); const Notification1 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Notification1?.setLinked_session) { await Notification1.setLinked_session(relatedLinked_session1); } const relatedLinked_session2 = await Sessions.findOne({ offset: Math.floor(Math.random() * (await Sessions.count())), }); const Notification2 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Notification2?.setLinked_session) { await Notification2.setLinked_session(relatedLinked_session2); } } async function associateProductDetailWithPost() { const relatedPost0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const ProductDetail0 = await ProductDetails.findOne({ order: [['id', 'ASC']], offset: 0, }); if (ProductDetail0?.setPost) { await ProductDetail0.setPost(relatedPost0); } const relatedPost1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const ProductDetail1 = await ProductDetails.findOne({ order: [['id', 'ASC']], offset: 1, }); if (ProductDetail1?.setPost) { await ProductDetail1.setPost(relatedPost1); } const relatedPost2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const ProductDetail2 = await ProductDetails.findOne({ order: [['id', 'ASC']], offset: 2, }); if (ProductDetail2?.setPost) { await ProductDetail2.setPost(relatedPost2); } } async function associateSessionRequestWithRequested_by() { const relatedRequested_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const SessionRequest0 = await SessionRequests.findOne({ order: [['id', 'ASC']], offset: 0, }); if (SessionRequest0?.setRequested_by) { await SessionRequest0.setRequested_by(relatedRequested_by0); } const relatedRequested_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const SessionRequest1 = await SessionRequests.findOne({ order: [['id', 'ASC']], offset: 1, }); if (SessionRequest1?.setRequested_by) { await SessionRequest1.setRequested_by(relatedRequested_by1); } const relatedRequested_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const SessionRequest2 = await SessionRequests.findOne({ order: [['id', 'ASC']], offset: 2, }); if (SessionRequest2?.setRequested_by) { await SessionRequest2.setRequested_by(relatedRequested_by2); } } async function associateSessionRequestWithLinked_product() { const relatedLinked_product0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const SessionRequest0 = await SessionRequests.findOne({ order: [['id', 'ASC']], offset: 0, }); if (SessionRequest0?.setLinked_product) { await SessionRequest0.setLinked_product(relatedLinked_product0); } const relatedLinked_product1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const SessionRequest1 = await SessionRequests.findOne({ order: [['id', 'ASC']], offset: 1, }); if (SessionRequest1?.setLinked_product) { await SessionRequest1.setLinked_product(relatedLinked_product1); } const relatedLinked_product2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const SessionRequest2 = await SessionRequests.findOne({ order: [['id', 'ASC']], offset: 2, }); if (SessionRequest2?.setLinked_product) { await SessionRequest2.setLinked_product(relatedLinked_product2); } } async function associateSessionWithLinked_post() { const relatedLinked_post0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Session0 = await Sessions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Session0?.setLinked_post) { await Session0.setLinked_post(relatedLinked_post0); } const relatedLinked_post1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Session1 = await Sessions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Session1?.setLinked_post) { await Session1.setLinked_post(relatedLinked_post1); } const relatedLinked_post2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Session2 = await Sessions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Session2?.setLinked_post) { await Session2.setLinked_post(relatedLinked_post2); } } // Similar logic for "relation_many" module.exports = { up: async (queryInterface, Sequelize) => { await EventDetails.bulkCreate(EventDetailsData); await HelpDetails.bulkCreate(HelpDetailsData); await Images.bulkCreate(ImagesData); await Notifications.bulkCreate(NotificationsData); await ProductDetails.bulkCreate(ProductDetailsData); await Products.bulkCreate(ProductsData); await SessionRequests.bulkCreate(SessionRequestsData); await Sessions.bulkCreate(SessionsData); await Promise.all([ // Similar logic for "relation_many" await associateEventDetailWithPost(), await associateHelpDetailWithPost(), await associateImageWithPost(), await associateNotificationWithUser(), await associateNotificationWithLinked_product(), await associateNotificationWithLinked_session(), await associateProductDetailWithPost(), await associateSessionRequestWithRequested_by(), await associateSessionRequestWithLinked_product(), await associateSessionWithLinked_post(), // Similar logic for "relation_many" ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('event_details', null, {}); await queryInterface.bulkDelete('help_details', null, {}); await queryInterface.bulkDelete('images', null, {}); await queryInterface.bulkDelete('notifications', null, {}); await queryInterface.bulkDelete('product_details', null, {}); await queryInterface.bulkDelete('products', null, {}); await queryInterface.bulkDelete('session_requests', null, {}); await queryInterface.bulkDelete('sessions', null, {}); }, };