From b155d8c3276407ca4847699fb6f8034663091f0c Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Fri, 10 Oct 2025 17:27:55 +0000 Subject: [PATCH] Fix: Reorder company generation before parks --- supabase/functions/seed-test-data/index.ts | 117 +++++++++++---------- 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/supabase/functions/seed-test-data/index.ts b/supabase/functions/seed-test-data/index.ts index d471280f..147db1e2 100644 --- a/supabase/functions/seed-test-data/index.ts +++ b/supabase/functions/seed-test-data/index.ts @@ -334,6 +334,65 @@ Deno.serve(async (req) => { return { submissionId, itemId, typeId: null }; } + // Create companies FIRST so parks can reference operators/owners + const companyTypes = ['manufacturer', 'operator', 'designer', 'property_owner']; + for (const compType of companyTypes) { + if (entityTypes.includes(compType + 's') || entityTypes.includes(compType === 'manufacturer' ? 'manufacturers' : compType === 'property_owner' ? 'property_owners' : compType + 's')) { + const count = Math.floor(plan.companies / 4); + for (let i = 0; i < count; i++) { + const level = getPopulationLevel(fieldDensity, i); + const companyData: any = { + name: `Test ${compType.replace('_', ' ')} ${i + 1}`, + slug: `test-${compType}-${i + 1}`, + company_type: compType + }; + + if (level >= 1) { + companyData.description = `Leading ${compType.replace('_', ' ')} in the amusement industry.`; + companyData.person_type = compType === 'designer' && Math.random() > 0.5 ? 'individual' : 'company'; + } + + if (level >= 2) { + companyData.founded_year = randomInt(1950, 2020); + const location = randomItem(CITIES); + companyData.headquarters_location = `${location.city}, ${location.country}`; + } + + if (level >= 3) { + companyData.website_url = `https://test-${compType}-${i + 1}.example.com`; + companyData.logo_url = `https://imagedelivery.net/test/${compType}-${i + 1}/logo`; + } + + if (level >= 4) { + companyData.card_image_id = `test-${compType}-card-${i + 1}`; + companyData.card_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/card`; + companyData.banner_image_id = `test-${compType}-banner-${i + 1}`; + companyData.banner_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/banner`; + } + + const { itemId } = await createSubmission(user.id, compType, companyData); + + // Track created submission item + createdSubmissionItems[compType].push(itemId); + + // Register newly created company in the registry + const companySlug = `test-${compType}-${i + 1}`; + const { data: approvedCompany } = await supabase + .from('companies') + .select('id') + .eq('slug', companySlug) + .maybeSingle(); + + if (approvedCompany) { + await registerTestEntity(supabase, compType, companySlug, approvedCompany.id, itemId, sessionId); + } + + createdCompanies[compType].push(companySlug); + summary.companies++; + } + } + } + // Create parks if (entityTypes.includes('parks')) { for (let i = 0; i < plan.parks; i++) { @@ -429,64 +488,6 @@ Deno.serve(async (req) => { } } - // Create companies - const companyTypes = ['manufacturer', 'operator', 'designer', 'property_owner']; - for (const compType of companyTypes) { - if (entityTypes.includes(compType + 's') || entityTypes.includes(compType === 'manufacturer' ? 'manufacturers' : compType === 'property_owner' ? 'property_owners' : compType + 's')) { - const count = Math.floor(plan.companies / 4); - for (let i = 0; i < count; i++) { - const level = getPopulationLevel(fieldDensity, i); - const companyData: any = { - name: `Test ${compType.replace('_', ' ')} ${i + 1}`, - slug: `test-${compType}-${i + 1}`, - company_type: compType - }; - - if (level >= 1) { - companyData.description = `Leading ${compType.replace('_', ' ')} in the amusement industry.`; - companyData.person_type = compType === 'designer' && Math.random() > 0.5 ? 'individual' : 'company'; - } - - if (level >= 2) { - companyData.founded_year = randomInt(1950, 2020); - const location = randomItem(CITIES); - companyData.headquarters_location = `${location.city}, ${location.country}`; - } - - if (level >= 3) { - companyData.website_url = `https://test-${compType}-${i + 1}.example.com`; - companyData.logo_url = `https://imagedelivery.net/test/${compType}-${i + 1}/logo`; - } - - if (level >= 4) { - companyData.card_image_id = `test-${compType}-card-${i + 1}`; - companyData.card_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/card`; - companyData.banner_image_id = `test-${compType}-banner-${i + 1}`; - companyData.banner_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/banner`; - } - - const { itemId } = await createSubmission(user.id, compType, companyData); - - // Track created submission item - createdSubmissionItems[compType].push(itemId); - - // Register newly created company in the registry - const companySlug = `test-${compType}-${i + 1}`; - const { data: approvedCompany } = await supabase - .from('companies') - .select('id') - .eq('slug', companySlug) - .maybeSingle(); - - if (approvedCompany) { - await registerTestEntity(supabase, compType, companySlug, approvedCompany.id, itemId, sessionId); - } - - createdCompanies[compType].push(companySlug); - summary.companies++; - } - } - } // Create rides if (entityTypes.includes('rides') && includeDependencies && createdParks.length > 0) {