Skip to content

Commit

Permalink
feat: ✨ create script to update shelters without uuids
Browse files Browse the repository at this point in the history
  • Loading branch information
willMoraes committed Jun 2, 2024
1 parent cfc2171 commit b0b2000
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/populateUUIDs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { PrismaClient } from "@prisma/client";
import cuid from "cuid";

const prisma = new PrismaClient();

async function updateUsersWithUUID() {
try {
const users = await prisma.shelter.findMany({
where: {
uuid: null,
},
});

const updatePromises = users.map((user) => {
return prisma.shelter.update({
where: { id: user.id },
data: { uuid: cuid() },
});
});

await Promise.all(updatePromises);

console.log(`Updated ${users.length} users with UUIDs.`);
} catch (error) {
console.error("Error updating users with UUIDs:", error);
} finally {
await prisma.$disconnect();
}
}

await updateUsersWithUUID();

0 comments on commit b0b2000

Please sign in to comment.