carservice: initial commit

This commit is contained in:
Hermes
2026-07-20 21:17:12 +01:00
commit d315323191
69 changed files with 9255 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
(async () => {
const dups = await prisma.part.groupBy({
by: ['name', 'carId'],
where: { isGlobal: false },
_count: { id: true },
having: { id: { _count: { gt: 1 } } },
});
console.log('duplicate groups', dups.length);
for (const g of dups) {
const rows = await prisma.part.findMany({
where: { name: g.name, carId: g.carId, isGlobal: false },
orderBy: { createdAt: 'asc' },
});
const keep = rows[0];
const removeIds = rows.slice(1).map(r => r.id);
console.log('keep', keep.id, 'remove', removeIds, 'for', g.name, g.carId);
for (const id of removeIds) {
await prisma.taskPart.updateMany({ where: { partId: id }, data: { partId: keep.id } });
await prisma.part.delete({ where: { id } });
}
}
console.log('done deduping private parts');
})().catch(e => { console.error(e); process.exit(1); });