From 78c2a693896f56b9a47874720b43caf93291b56a Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Thu, 16 Oct 2025 03:06:53 -0400 Subject: [PATCH] Script to reassign attributes (#24496) --- scripts/reassign-attributes.ts | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 scripts/reassign-attributes.ts diff --git a/scripts/reassign-attributes.ts b/scripts/reassign-attributes.ts new file mode 100644 index 0000000000..f9cb062907 --- /dev/null +++ b/scripts/reassign-attributes.ts @@ -0,0 +1,41 @@ +import { prisma } from "@calcom/prisma"; + +const reassignAttributes = async () => { + const orgId = 0; + + // Add attribute option id that we want to search against + const lookupAttributeId = ""; + + // Add attribute option ids that we want to assign to users + const attributeIdsToAssign = []; + + // Find all users who have the lookupAttributeId + const usersWithAttribute = await prisma.attributeToUser.findMany({ + where: { + attributeOptionId: lookupAttributeId, + member: { + teamId: orgId, + }, + }, + select: { + memberId: true, + }, + }); + + console.log(`Found ${usersWithAttribute.length} users with attribute ${lookupAttributeId}`); + + // Assign the new attributes to these users + for (const attributeId of attributeIdsToAssign) { + const results = await prisma.attributeToUser.createMany({ + data: usersWithAttribute.map((user) => ({ + memberId: user.memberId, + attributeOptionId: attributeId, + })), + skipDuplicates: true, // Skip if user already has this attribute + }); + + console.log(`Assigned attribute ${attributeId} to ${results.count} users`); + } +}; + +export default reassignAttributes();