From 4421a8fcbf90ca05402184c2fa3670b592604d6e Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Sun, 1 Feb 2026 23:20:26 +0530 Subject: [PATCH] feat: Update Prisma seed script to populate missing options, validation, and UI config for existing profile fields. --- prisma/seed.ts | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/prisma/seed.ts b/prisma/seed.ts index 5f96949..002c6c1 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1139,7 +1139,7 @@ async function main() { console.log(` ✅ Updated isRepeatable to ${sectionInfo.isRepeatable}`); } - // Still check and create missing fields + // Still check and create missing fields, or update existing fields with options for (const fieldData of fields) { const existingField = await prisma.profileField.findFirst({ where: { @@ -1156,6 +1156,28 @@ async function main() { }, }); 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 any; // Cast to any to access optional properties + + 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 { @@ -1211,7 +1233,7 @@ async function main() { if (section) { console.log(` ⚠️ Section "${sectionInfo.name}" for ${agentTypeName} already exists`); - // Still check and create missing fields + // Still check and create missing fields, or update existing fields with options for (const fieldData of fields) { const existingField = await prisma.profileField.findFirst({ where: { @@ -1228,6 +1250,28 @@ async function main() { }, }); 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 any; // Cast to any to access optional properties + + 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 {