diff --git a/supabase/functions/seed-test-data/index.ts b/supabase/functions/seed-test-data/index.ts index 911cf2fa..46e18438 100644 --- a/supabase/functions/seed-test-data/index.ts +++ b/supabase/functions/seed-test-data/index.ts @@ -376,18 +376,22 @@ Deno.serve(async (req) => { console.info(`✓ Selected company types (${selectedCompanyTypes.length}):`, selectedCompanyTypes); + // Calculate fair distribution: base amount per type + extras + const basePerType = Math.floor(plan.companies / selectedCompanyTypes.length); + const extras = plan.companies % selectedCompanyTypes.length; + + console.info(`Distribution plan: ${basePerType} base per type, ${extras} extra(s) to first types`); + let companiesCreatedTotal = 0; for (let typeIndex = 0; typeIndex < selectedCompanyTypes.length; typeIndex++) { const compType = selectedCompanyTypes[typeIndex]; const pluralType = pluralizeCompanyType(compType); - // Calculate fair distribution: remaining companies / remaining types - const remainingCompanies = plan.companies - companiesCreatedTotal; - const remainingTypes = selectedCompanyTypes.length - typeIndex; - const count = Math.ceil(remainingCompanies / remainingTypes); + // Each type gets base amount, first N types get +1 extra + const count = basePerType + (typeIndex < extras ? 1 : 0); - console.info(`✓ Generating ${count} companies of type ${compType} (${remainingCompanies} remaining, ${remainingTypes} types left)`); + console.info(`✓ Generating ${count} companies of type ${compType}`); for (let i = 0; i < count; i++) { console.info(` Creating company ${i + 1}/${count} (type: ${compType})`);