Skip to content

Commit

Permalink
Script to delete animes with <= 5 quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
rocktimsaikia committed Dec 24, 2024
1 parent 36b32d0 commit ee0b6fb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions server/scripts/fix-duplicate-anime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { prisma } from "~/libs/prisma";

(async () => {
// First get the IDs of animes to delete
const animesToDelete = await prisma.anime.findMany({
where: {
altName: null,
},
select: {
id: true,
_count: {
select: {
quotes: true,
},
},
},
});

const idsToDelete = animesToDelete
.filter((anime) => anime._count.quotes <= 5)
.map((anime) => anime.id);

// Then delete them
const deleteResult = await prisma.anime.deleteMany({
where: {
id: {
in: idsToDelete,
},
},
});

console.log(`Deleted ${deleteResult.count} animes`);
})();

0 comments on commit ee0b6fb

Please sign in to comment.