-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script to delete animes with <= 5 quotes
- Loading branch information
1 parent
36b32d0
commit ee0b6fb
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
})(); |