feat: Update Prisma seed script to populate missing options, validation, and UI config for existing profile fields.
This commit is contained in:
@@ -1139,7 +1139,7 @@ async function main() {
|
|||||||
console.log(` ✅ Updated isRepeatable to ${sectionInfo.isRepeatable}`);
|
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) {
|
for (const fieldData of fields) {
|
||||||
const existingField = await prisma.profileField.findFirst({
|
const existingField = await prisma.profileField.findFirst({
|
||||||
where: {
|
where: {
|
||||||
@@ -1156,6 +1156,28 @@ async function main() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log(` ✅ Created field: ${fieldData.name}`);
|
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<string, unknown> = {};
|
||||||
|
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 {
|
} else {
|
||||||
@@ -1211,7 +1233,7 @@ async function main() {
|
|||||||
if (section) {
|
if (section) {
|
||||||
console.log(` ⚠️ Section "${sectionInfo.name}" for ${agentTypeName} already exists`);
|
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) {
|
for (const fieldData of fields) {
|
||||||
const existingField = await prisma.profileField.findFirst({
|
const existingField = await prisma.profileField.findFirst({
|
||||||
where: {
|
where: {
|
||||||
@@ -1228,6 +1250,28 @@ async function main() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log(` ✅ Created field: ${fieldData.name}`);
|
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<string, unknown> = {};
|
||||||
|
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 {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user