From d97657b475ff014409913397f3f72bca33c9d1bf Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Wed, 15 Apr 2026 13:41:29 +0530 Subject: [PATCH] refactor: remove auto-seeding logic for agent-type-specific sections to preserve admin customizations --- prisma/seed.ts | 142 +------------------------------------------------ 1 file changed, 2 insertions(+), 140 deletions(-) diff --git a/prisma/seed.ts b/prisma/seed.ts index acf0f12..cfdd7c7 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1244,146 +1244,8 @@ async function main() { console.log(''); - // ============================================= - // Seed Agent-Type-Specific Sections - // ============================================= - // DISABLED: Professional (Agent) and Lender sections are no longer auto-updated on each seed run - // to prevent admin customizations (labels, options, sortOrder) from being overwritten. - // To re-enable a one-time run, set env var SEED_AGENT_TYPE_SECTIONS=true. - if (process.env.SEED_AGENT_TYPE_SECTIONS === 'true') { - console.log('📋 Seeding Agent-Type-Specific Sections...'); - - // First, delete old global Experience section if exists - const oldExperienceSection = await prisma.profileSection.findUnique({ - where: { slug: 'experience' }, - }); - if (oldExperienceSection) { - await prisma.profileSection.delete({ - where: { slug: 'experience' }, - }); - console.log(' 🗑️ Deleted old global Experience section'); - } - - for (const { agentTypeName, section: sectionData } of agentTypeSections) { - const { fields, ...sectionInfo } = sectionData; - - // Find the agent type - const agentType = await prisma.agentType.findUnique({ - where: { name: agentTypeName }, - }); - - if (!agentType) { - console.log( - ` ⚠️ Agent type "${agentTypeName}" not found, skipping section`, - ); - continue; - } - - // Check if section already exists - let section = await prisma.profileSection.findUnique({ - where: { slug: sectionInfo.slug }, - }); - - if (section) { - console.log( - ` ⚠️ Section "${sectionInfo.name}" for ${agentTypeName} already exists`, - ); - - // Still check and create missing fields, or update existing fields with options - for (const fieldData of fields) { - const existingField = await prisma.profileField.findFirst({ - where: { - sectionId: section.id, - slug: fieldData.slug, - }, - }); - - if (!existingField) { - await prisma.profileField.create({ - data: { - ...fieldData, - sectionId: section.id, - }, - }); - console.log(` ✅ Created field: ${fieldData.name}`); - } else { - // Update existing field with options if options are defined in seed but missing in DB - const updates: Record = {}; - const fd = fieldData as Partial<{ - options: unknown; - validation: unknown; - uiConfig: unknown; - }>; - - if ( - fd.options && - (!existingField.options || - (Array.isArray(existingField.options) && - existingField.options.length === 0)) - ) { - updates.options = fd.options; - } - if (fd.validation && !existingField.validation) { - updates.validation = fd.validation; - } - if (fd.uiConfig && !existingField.uiConfig) { - updates.uiConfig = fd.uiConfig; - } - - if (Object.keys(updates).length > 0) { - await prisma.profileField.update({ - where: { id: existingField.id }, - data: updates, - }); - console.log( - ` ✅ Updated field: ${fieldData.name} (${Object.keys(updates).join(', ')})`, - ); - } - } - } - } else { - // Create section with fields - section = await prisma.profileSection.create({ - data: { - ...sectionInfo, - fields: { - create: fields, - }, - }, - }); - console.log( - ` ✅ Created section: ${sectionInfo.name} for ${agentTypeName} with ${fields.length} fields`, - ); - } - - // Create AgentTypeSection assignment if not exists - const existingAssignment = await prisma.agentTypeSection.findUnique({ - where: { - agentTypeId_sectionId: { - agentTypeId: agentType.id, - sectionId: section.id, - }, - }, - }); - - if (!existingAssignment) { - await prisma.agentTypeSection.create({ - data: { - agentTypeId: agentType.id, - sectionId: section.id, - sortOrder: sectionInfo.sortOrder, - isRequired: false, - }, - }); - console.log(` ✅ Assigned section to ${agentTypeName}`); - } - } - - console.log(''); - } else { - console.log('⏭️ Skipping Agent-Type-Specific Sections (set SEED_AGENT_TYPE_SECTIONS=true to enable)'); - console.log(''); - } + // Agent-Type-Specific Sections (Professional/Lender) are managed exclusively via admin — + // the seed no longer creates or updates them so admin customizations are preserved. // ============================================= // Seed Admin User