27 lines
790 B
JavaScript
27 lines
790 B
JavaScript
|
|
const { PrismaClient } = require('@prisma/client');
|
||
|
|
const prisma = new PrismaClient();
|
||
|
|
|
||
|
|
async function run() {
|
||
|
|
const users = await prisma.user.findMany({ select: { id: true } });
|
||
|
|
const userIds = new Set(users.map((u) => u.id));
|
||
|
|
console.log('Total valid users in DB:', userIds.size);
|
||
|
|
|
||
|
|
const permissions = await prisma.filePermission.findMany();
|
||
|
|
console.log('Total permissions in DB:', permissions.length);
|
||
|
|
|
||
|
|
let orphaned = 0;
|
||
|
|
for (const p of permissions) {
|
||
|
|
if (!userIds.has(p.ownerId) || !userIds.has(p.granteeUserId)) {
|
||
|
|
orphaned++;
|
||
|
|
await prisma.filePermission.delete({ where: { id: p.id } });
|
||
|
|
}
|
||
|
|
}
|
||
|
|
console.log('Cleaned up orphaned permissions:', orphaned);
|
||
|
|
await prisma.$disconnect();
|
||
|
|
}
|
||
|
|
|
||
|
|
run().catch((e) => {
|
||
|
|
console.error(e);
|
||
|
|
process.exit(1);
|
||
|
|
});
|