Script to reassign attributes (#24496)

This commit is contained in:
Joe Au-Yeung
2025-10-16 07:06:53 +00:00
committed by GitHub
parent 5a483e75c9
commit 78c2a69389
+41
View File
@@ -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();