





















const db = require('../models');
const Users = db.users;






const PlaceCategories = db.place_categories;

const Places = db.places;

const PlaceOpeningHours = db.place_opening_hours;

const PlaceFeatures = db.place_features;

const PlaceFeatureLinks = db.place_feature_links;

const Reviews = db.reviews;

const Favorites = db.favorites;

const SearchLogs = db.search_logs;

const Reports = db.reports;







const PlaceCategoriesData = [
    
    {
    
        
        
            
                "name": "Toko Interior",
            
        
    
        
        
            
                "slug": "toko-interior",
            
        
    
        
        
            
                "description": "Tempat belanja perabot dan jasa desain interior.",
            
        
    
        
        
            
                "color_hex": "#2563EB",
            
        
    
        
        
            
                "icon_name": "mdiSofa",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Cafe Melayu",
            
        
    
        
        
            
                "slug": "cafe-melayu",
            
        
    
        
        
            
                "description": "Cafe dengan menu khas Melayu dan suasana tradisional.",
            
        
    
        
        
            
                "color_hex": "#16A34A",
            
        
    
        
        
            
                "icon_name": "mdiCoffeeOutline",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Bengkel Mobil",
            
        
    
        
        
            
                "slug": "bengkel-mobil",
            
        
    
        
        
            
                "description": "Servis dan perbaikan kendaraan roda empat.",
            
        
    
        
        
            
                "color_hex": "#DC2626",
            
        
    
        
        
            
                "icon_name": "mdiCarWrench",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
];



const PlacesData = [
    
    {
    
        
        
            
                "name": "Riau Interior Studio",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "short_description": "Toko interior dan custom furniture dekat pusat kota.",
            
        
    
        
        
            
                "full_description": "Melayani desain interior, kitchen set, lemari, dan partisi. Estimasi pengerjaan jelas dan konsultasi gratis.",
            
        
    
        
        
            
                "address": "Jl. Riau No. 45, Pekanbaru",
            
        
    
        
        
            
                "city": "Pekanbaru",
            
        
    
        
        
            
                "province": "Riau",
            
        
    
        
        
            
                "postal_code": "28112",
            
        
    
        
        
            
                "latitude": 0.5199,
            
        
    
        
        
            
                "longitude": 101.4512,
            
        
    
        
        
            
                "phone_number": "+62761234567",
            
        
    
        
        
            
                "whatsapp_number": "+6281270001111",
            
        
    
        
        
            
                "email": "cs@riauinteriorstudio.id",
            
        
    
        
        
            
                "website_url": "https://riauinteriorstudio.id",
            
        
    
        
        
            
                "google_maps_url": "https://maps.google.com/?q=0.5199,101.4512",
            
        
    
        
        
            
                // type code here for "images" field
            
        
    
        
        
            
                "price_level": "budget",
            
        
    
        
        
            
                "average_price": 2500000,
            
        
    
        
        
            
                "rating_average": 4.6,
            
        
    
        
        
            
                "rating_count": 128,
            
        
    
        
        
            
                "status": "draft",
            
        
    
        
        
            
                "is_verified": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Kopi Selasih Melayu",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "short_description": "Cafe khas Melayu dengan menu kopi dan kue tradisional.",
            
        
    
        
        
            
                "full_description": "Menu unggulan: kopi saring, teh tarik, roti jala, dan lempeng kelapa. Cocok untuk keluarga.",
            
        
    
        
        
            
                "address": "Jl. Sudirman No. 120, Pekanbaru",
            
        
    
        
        
            
                "city": "Pekanbaru",
            
        
    
        
        
            
                "province": "Riau",
            
        
    
        
        
            
                "postal_code": "28116",
            
        
    
        
        
            
                "latitude": 0.5095,
            
        
    
        
        
            
                "longitude": 101.4549,
            
        
    
        
        
            
                "phone_number": "+62761876543",
            
        
    
        
        
            
                "whatsapp_number": "+6281270002222",
            
        
    
        
        
            
                "email": "hello@kopiselasih.co",
            
        
    
        
        
            
                "website_url": "https://kopiselasih.co",
            
        
    
        
        
            
                "google_maps_url": "https://maps.google.com/?q=0.5095,101.4549",
            
        
    
        
        
            
                // type code here for "images" field
            
        
    
        
        
            
                "price_level": "midrange",
            
        
    
        
        
            
                "average_price": 35000,
            
        
    
        
        
            
                "rating_average": 4.4,
            
        
    
        
        
            
                "rating_count": 342,
            
        
    
        
        
            
                "status": "draft",
            
        
    
        
        
            
                "is_verified": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Bengkel Mobil Mandiri Jaya",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "short_description": "Bengkel mobil umum dengan layanan cepat dan transparan.",
            
        
    
        
        
            
                "full_description": "Layanan: servis berkala, ganti oli, tune up, kaki-kaki, dan diagnosa. Estimasi biaya sebelum pengerjaan.",
            
        
    
        
        
            
                "address": "Jl. Arifin Ahmad No. 18, Pekanbaru",
            
        
    
        
        
            
                "city": "Pekanbaru",
            
        
    
        
        
            
                "province": "Riau",
            
        
    
        
        
            
                "postal_code": "28125",
            
        
    
        
        
            
                "latitude": 0.4989,
            
        
    
        
        
            
                "longitude": 101.4231,
            
        
    
        
        
            
                "phone_number": "+62761123456",
            
        
    
        
        
            
                "whatsapp_number": "+6281270003333",
            
        
    
        
        
            
                "email": "service@mandirijaya-auto.id",
            
        
    
        
        
            
                "website_url": "https://mandirijaya-auto.id",
            
        
    
        
        
            
                "google_maps_url": "https://maps.google.com/?q=0.4989,101.4231",
            
        
    
        
        
            
                // type code here for "images" field
            
        
    
        
        
            
                "price_level": "unknown",
            
        
    
        
        
            
                "average_price": 400000,
            
        
    
        
        
            
                "rating_average": 4.5,
            
        
    
        
        
            
                "rating_count": 211,
            
        
    
        
        
            
                "status": "archived",
            
        
    
        
        
            
                "is_verified": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const PlaceOpeningHoursData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "day_of_week": "sunday",
            
        
    
        
        
            
                "open_time": "09:00",
            
        
    
        
        
            
                "close_time": "18:00",
            
        
    
        
        
            
                "is_closed": true,
            
        
    
        
        
            
                "is_24_hours": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "day_of_week": "sunday",
            
        
    
        
        
            
                "open_time": "10:00",
            
        
    
        
        
            
                "close_time": "22:00",
            
        
    
        
        
            
                "is_closed": true,
            
        
    
        
        
            
                "is_24_hours": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "day_of_week": "tuesday",
            
        
    
        
        
            
                "open_time": "08:00",
            
        
    
        
        
            
                "close_time": "17:00",
            
        
    
        
        
            
                "is_closed": false,
            
        
    
        
        
            
                "is_24_hours": false,
            
        
    
    },
    
];



const PlaceFeaturesData = [
    
    {
    
        
        
            
                "name": "Parkir Luas",
            
        
    
        
        
            
                "description": "Area parkir memadai untuk mobil dan motor.",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "WiFi Gratis",
            
        
    
        
        
            
                "description": "Akses WiFi untuk pengunjung tanpa biaya tambahan.",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Musholla",
            
        
    
        
        
            
                "description": "Tersedia fasilitas ibadah yang bersih dan nyaman.",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
];



const PlaceFeatureLinksData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const ReviewsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "rating": 5,
            
        
    
        
        
            
                "comment": "Tempat nyaman, menu roti jala enak dan kopi wangi.",
            
        
    
        
        
            
                // type code here for "images" field
            
        
    
        
        
            
                "moderation_status": "pending",
            
        
    
        
        
            
                "visited_at": new Date('2026-05-28T12:10:00Z'),
            
        
    
        
        
            
                "is_anonymous": false,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "rating": 4,
            
        
    
        
        
            
                "comment": "Servis cepat dan biaya dijelaskan di awal, ruang tunggu cukup nyaman.",
            
        
    
        
        
            
                // type code here for "images" field
            
        
    
        
        
            
                "moderation_status": "pending",
            
        
    
        
        
            
                "visited_at": new Date('2026-06-02T08:40:00Z'),
            
        
    
        
        
            
                "is_anonymous": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "rating": 5,
            
        
    
        
        
            
                "comment": "Konsultasi desain membantu, hasil kitchen set rapi dan sesuai waktu.",
            
        
    
        
        
            
                // type code here for "images" field
            
        
    
        
        
            
                "moderation_status": "pending",
            
        
    
        
        
            
                "visited_at": new Date('2026-06-06T10:15:00Z'),
            
        
    
        
        
            
                "is_anonymous": true,
            
        
    
    },
    
];



const FavoritesData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "favorited_at": new Date('2026-06-01T19:05:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "favorited_at": new Date('2026-06-03T09:00:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "favorited_at": new Date('2026-06-07T12:00:00Z'),
            
        
    
    },
    
];



const SearchLogsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "query_text": "cafe melayu terdekat",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "search_latitude": 0.5104,
            
        
    
        
        
            
                "search_longitude": 101.4517,
            
        
    
        
        
            
                "radius_km": 3.5,
            
        
    
        
        
            
                "searched_at": new Date('2026-06-12T14:35:00Z'),
            
        
    
        
        
            
                "results_count": 8,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "query_text": "bengkel mobil buka sekarang",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "search_latitude": 0.5002,
            
        
    
        
        
            
                "search_longitude": 101.4256,
            
        
    
        
        
            
                "radius_km": 5,
            
        
    
        
        
            
                "searched_at": new Date('2026-06-13T07:50:00Z'),
            
        
    
        
        
            
                "results_count": 5,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "query_text": "toko interior custom",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "search_latitude": 0.5321,
            
        
    
        
        
            
                "search_longitude": 101.4492,
            
        
    
        
        
            
                "radius_km": 6,
            
        
    
        
        
            
                "searched_at": new Date('2026-06-15T11:10:00Z'),
            
        
    
        
        
            
                "results_count": 12,
            
        
    
    },
    
];



const ReportsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "report_type": "wrong_info",
            
        
    
        
        
            
                "details": "Nomor telepon di papan depan berbeda dengan yang tertera di aplikasi.",
            
        
    
        
        
            
                "status": "in_review",
            
        
    
        
        
            
                "reported_at": new Date('2026-06-09T10:05:00Z'),
            
        
    
        
        
            
                "resolved_at": new Date('2026-06-09T10:05:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "report_type": "closed_permanently",
            
        
    
        
        
            
                "details": "Pin lokasi di peta bergeser sekitar satu blok dari alamat sebenarnya.",
            
        
    
        
        
            
                "status": "rejected",
            
        
    
        
        
            
                "reported_at": new Date('2026-06-11T08:15:00Z'),
            
        
    
        
        
            
                "resolved_at": new Date('2026-06-11T08:15:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "report_type": "duplicate",
            
        
    
        
        
            
                "details": "Toko terlihat tutup selama beberapa hari, mohon verifikasi.",
            
        
    
        
        
            
                "status": "open",
            
        
    
        
        
            
                "reported_at": new Date('2026-06-16T09:40:00Z'),
            
        
    
        
        
            
                "resolved_at": new Date('2026-06-16T09:40:00Z'),
            
        
    
    },
    
];




    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            // Similar logic for "relation_many"
        
    

    
    
    
    
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
    
        
            
            async function associatePlaceWithCategory() {
            
                const relatedCategory0 = await PlaceCategories.findOne({
                    offset: Math.floor(Math.random() * (await PlaceCategories.count())),
                });
                const Place0 = await Places.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Place0?.setCategory)
                {
                    await
                    Place0.
                    setCategory(relatedCategory0);
                }
            
                const relatedCategory1 = await PlaceCategories.findOne({
                    offset: Math.floor(Math.random() * (await PlaceCategories.count())),
                });
                const Place1 = await Places.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Place1?.setCategory)
                {
                    await
                    Place1.
                    setCategory(relatedCategory1);
                }
            
                const relatedCategory2 = await PlaceCategories.findOne({
                    offset: Math.floor(Math.random() * (await PlaceCategories.count())),
                });
                const Place2 = await Places.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Place2?.setCategory)
                {
                    await
                    Place2.
                    setCategory(relatedCategory2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associatePlaceWithOwner() {
            
                const relatedOwner0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Place0 = await Places.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Place0?.setOwner)
                {
                    await
                    Place0.
                    setOwner(relatedOwner0);
                }
            
                const relatedOwner1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Place1 = await Places.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Place1?.setOwner)
                {
                    await
                    Place1.
                    setOwner(relatedOwner1);
                }
            
                const relatedOwner2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Place2 = await Places.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Place2?.setOwner)
                {
                    await
                    Place2.
                    setOwner(relatedOwner2);
                }
            
        }
        
    

    
    
    
        
            
            async function associatePlaceOpeningHourWithPlace() {
            
                const relatedPlace0 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const PlaceOpeningHour0 = await PlaceOpeningHours.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (PlaceOpeningHour0?.setPlace)
                {
                    await
                    PlaceOpeningHour0.
                    setPlace(relatedPlace0);
                }
            
                const relatedPlace1 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const PlaceOpeningHour1 = await PlaceOpeningHours.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (PlaceOpeningHour1?.setPlace)
                {
                    await
                    PlaceOpeningHour1.
                    setPlace(relatedPlace1);
                }
            
                const relatedPlace2 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const PlaceOpeningHour2 = await PlaceOpeningHours.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (PlaceOpeningHour2?.setPlace)
                {
                    await
                    PlaceOpeningHour2.
                    setPlace(relatedPlace2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
    
        
    
        
    

    
    
    
        
            
            async function associatePlaceFeatureLinkWithPlace() {
            
                const relatedPlace0 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const PlaceFeatureLink0 = await PlaceFeatureLinks.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (PlaceFeatureLink0?.setPlace)
                {
                    await
                    PlaceFeatureLink0.
                    setPlace(relatedPlace0);
                }
            
                const relatedPlace1 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const PlaceFeatureLink1 = await PlaceFeatureLinks.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (PlaceFeatureLink1?.setPlace)
                {
                    await
                    PlaceFeatureLink1.
                    setPlace(relatedPlace1);
                }
            
                const relatedPlace2 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const PlaceFeatureLink2 = await PlaceFeatureLinks.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (PlaceFeatureLink2?.setPlace)
                {
                    await
                    PlaceFeatureLink2.
                    setPlace(relatedPlace2);
                }
            
        }
        
    
        
            
            async function associatePlaceFeatureLinkWithFeature() {
            
                const relatedFeature0 = await PlaceFeatures.findOne({
                    offset: Math.floor(Math.random() * (await PlaceFeatures.count())),
                });
                const PlaceFeatureLink0 = await PlaceFeatureLinks.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (PlaceFeatureLink0?.setFeature)
                {
                    await
                    PlaceFeatureLink0.
                    setFeature(relatedFeature0);
                }
            
                const relatedFeature1 = await PlaceFeatures.findOne({
                    offset: Math.floor(Math.random() * (await PlaceFeatures.count())),
                });
                const PlaceFeatureLink1 = await PlaceFeatureLinks.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (PlaceFeatureLink1?.setFeature)
                {
                    await
                    PlaceFeatureLink1.
                    setFeature(relatedFeature1);
                }
            
                const relatedFeature2 = await PlaceFeatures.findOne({
                    offset: Math.floor(Math.random() * (await PlaceFeatures.count())),
                });
                const PlaceFeatureLink2 = await PlaceFeatureLinks.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (PlaceFeatureLink2?.setFeature)
                {
                    await
                    PlaceFeatureLink2.
                    setFeature(relatedFeature2);
                }
            
        }
        
    

    
    
    
        
            
            async function associateReviewWithPlace() {
            
                const relatedPlace0 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const Review0 = await Reviews.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Review0?.setPlace)
                {
                    await
                    Review0.
                    setPlace(relatedPlace0);
                }
            
                const relatedPlace1 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const Review1 = await Reviews.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Review1?.setPlace)
                {
                    await
                    Review1.
                    setPlace(relatedPlace1);
                }
            
                const relatedPlace2 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const Review2 = await Reviews.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Review2?.setPlace)
                {
                    await
                    Review2.
                    setPlace(relatedPlace2);
                }
            
        }
        
    
        
            
            async function associateReviewWithAuthor() {
            
                const relatedAuthor0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Review0 = await Reviews.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Review0?.setAuthor)
                {
                    await
                    Review0.
                    setAuthor(relatedAuthor0);
                }
            
                const relatedAuthor1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Review1 = await Reviews.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Review1?.setAuthor)
                {
                    await
                    Review1.
                    setAuthor(relatedAuthor1);
                }
            
                const relatedAuthor2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Review2 = await Reviews.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Review2?.setAuthor)
                {
                    await
                    Review2.
                    setAuthor(relatedAuthor2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateFavoriteWithUser() {
            
                const relatedUser0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Favorite0 = await Favorites.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Favorite0?.setUser)
                {
                    await
                    Favorite0.
                    setUser(relatedUser0);
                }
            
                const relatedUser1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Favorite1 = await Favorites.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Favorite1?.setUser)
                {
                    await
                    Favorite1.
                    setUser(relatedUser1);
                }
            
                const relatedUser2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Favorite2 = await Favorites.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Favorite2?.setUser)
                {
                    await
                    Favorite2.
                    setUser(relatedUser2);
                }
            
        }
        
    
        
            
            async function associateFavoriteWithPlace() {
            
                const relatedPlace0 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const Favorite0 = await Favorites.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Favorite0?.setPlace)
                {
                    await
                    Favorite0.
                    setPlace(relatedPlace0);
                }
            
                const relatedPlace1 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const Favorite1 = await Favorites.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Favorite1?.setPlace)
                {
                    await
                    Favorite1.
                    setPlace(relatedPlace1);
                }
            
                const relatedPlace2 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const Favorite2 = await Favorites.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Favorite2?.setPlace)
                {
                    await
                    Favorite2.
                    setPlace(relatedPlace2);
                }
            
        }
        
    
        
    

    
    
    
        
            
            async function associateSearchLogWithUser() {
            
                const relatedUser0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const SearchLog0 = await SearchLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (SearchLog0?.setUser)
                {
                    await
                    SearchLog0.
                    setUser(relatedUser0);
                }
            
                const relatedUser1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const SearchLog1 = await SearchLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (SearchLog1?.setUser)
                {
                    await
                    SearchLog1.
                    setUser(relatedUser1);
                }
            
                const relatedUser2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const SearchLog2 = await SearchLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (SearchLog2?.setUser)
                {
                    await
                    SearchLog2.
                    setUser(relatedUser2);
                }
            
        }
        
    
        
    
        
            
            async function associateSearchLogWithCategory() {
            
                const relatedCategory0 = await PlaceCategories.findOne({
                    offset: Math.floor(Math.random() * (await PlaceCategories.count())),
                });
                const SearchLog0 = await SearchLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (SearchLog0?.setCategory)
                {
                    await
                    SearchLog0.
                    setCategory(relatedCategory0);
                }
            
                const relatedCategory1 = await PlaceCategories.findOne({
                    offset: Math.floor(Math.random() * (await PlaceCategories.count())),
                });
                const SearchLog1 = await SearchLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (SearchLog1?.setCategory)
                {
                    await
                    SearchLog1.
                    setCategory(relatedCategory1);
                }
            
                const relatedCategory2 = await PlaceCategories.findOne({
                    offset: Math.floor(Math.random() * (await PlaceCategories.count())),
                });
                const SearchLog2 = await SearchLogs.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (SearchLog2?.setCategory)
                {
                    await
                    SearchLog2.
                    setCategory(relatedCategory2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateReportWithPlace() {
            
                const relatedPlace0 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const Report0 = await Reports.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Report0?.setPlace)
                {
                    await
                    Report0.
                    setPlace(relatedPlace0);
                }
            
                const relatedPlace1 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const Report1 = await Reports.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Report1?.setPlace)
                {
                    await
                    Report1.
                    setPlace(relatedPlace1);
                }
            
                const relatedPlace2 = await Places.findOne({
                    offset: Math.floor(Math.random() * (await Places.count())),
                });
                const Report2 = await Reports.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Report2?.setPlace)
                {
                    await
                    Report2.
                    setPlace(relatedPlace2);
                }
            
        }
        
    
        
            
            async function associateReportWithReporter() {
            
                const relatedReporter0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Report0 = await Reports.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Report0?.setReporter)
                {
                    await
                    Report0.
                    setReporter(relatedReporter0);
                }
            
                const relatedReporter1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Report1 = await Reports.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Report1?.setReporter)
                {
                    await
                    Report1.
                    setReporter(relatedReporter1);
                }
            
                const relatedReporter2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Report2 = await Reports.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Report2?.setReporter)
                {
                    await
                    Report2.
                    setReporter(relatedReporter2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    


module.exports = {
    up: async (queryInterface, Sequelize) => {
        
            
            
            
            
            
                
                await PlaceCategories.bulkCreate(PlaceCategoriesData);
                
            
            
                
                await Places.bulkCreate(PlacesData);
                
            
            
                
                await PlaceOpeningHours.bulkCreate(PlaceOpeningHoursData);
                
            
            
                
                await PlaceFeatures.bulkCreate(PlaceFeaturesData);
                
            
            
                
                await PlaceFeatureLinks.bulkCreate(PlaceFeatureLinksData);
                
            
            
                
                await Reviews.bulkCreate(ReviewsData);
                
            
            
                
                await Favorites.bulkCreate(FavoritesData);
                
            
            
                
                await SearchLogs.bulkCreate(SearchLogsData);
                
            
            
                
                await Reports.bulkCreate(ReportsData);
                
            
            await Promise.all([
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        // Similar logic for "relation_many"
                    
                
            
                
                
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                        
                        await associatePlaceWithCategory(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associatePlaceWithOwner(),
                    
                
            
                
                
                    
                        
                        await associatePlaceOpeningHourWithPlace(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associatePlaceFeatureLinkWithPlace(),
                    
                
                    
                        
                        await associatePlaceFeatureLinkWithFeature(),
                    
                
            
                
                
                    
                        
                        await associateReviewWithPlace(),
                    
                
                    
                        
                        await associateReviewWithAuthor(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateFavoriteWithUser(),
                    
                
                    
                        
                        await associateFavoriteWithPlace(),
                    
                
                    
                
            
                
                
                    
                        
                        await associateSearchLogWithUser(),
                    
                
                    
                
                    
                        
                        await associateSearchLogWithCategory(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateReportWithPlace(),
                    
                
                    
                        
                        await associateReportWithReporter(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            ]);
        
    },

    down: async (queryInterface, Sequelize) => {
        
            
            
            
            
            
            await queryInterface.bulkDelete('place_categories', null, {});
            
            
            await queryInterface.bulkDelete('places', null, {});
            
            
            await queryInterface.bulkDelete('place_opening_hours', null, {});
            
            
            await queryInterface.bulkDelete('place_features', null, {});
            
            
            await queryInterface.bulkDelete('place_feature_links', null, {});
            
            
            await queryInterface.bulkDelete('reviews', null, {});
            
            
            await queryInterface.bulkDelete('favorites', null, {});
            
            
            await queryInterface.bulkDelete('search_logs', null, {});
            
            
            await queryInterface.bulkDelete('reports', null, {});
            
        
    },
};