🗃️ Remove updatedAt field from Result
This commit is contained in:
@@ -10,9 +10,48 @@ export const cleanDatabase = async () => {
|
||||
await deleteOldChatSessions()
|
||||
await deleteExpiredAppSessions()
|
||||
await deleteExpiredVerificationTokens()
|
||||
const isFirstOfMonth = new Date().getDate() === 1
|
||||
if (isFirstOfMonth) {
|
||||
await deleteArchivedTypebots()
|
||||
await deleteArchivedResults()
|
||||
}
|
||||
console.log('Done!')
|
||||
}
|
||||
|
||||
const deleteArchivedTypebots = async () => {
|
||||
const lastDayOfPreviousMonth = new Date()
|
||||
lastDayOfPreviousMonth.setMonth(lastDayOfPreviousMonth.getMonth() - 1)
|
||||
lastDayOfPreviousMonth.setDate(0)
|
||||
|
||||
const { count } = await prisma.typebot.deleteMany({
|
||||
where: {
|
||||
updatedAt: {
|
||||
lte: lastDayOfPreviousMonth,
|
||||
},
|
||||
isArchived: true,
|
||||
},
|
||||
})
|
||||
|
||||
console.log(`Deleted ${count} archived typebots.`)
|
||||
}
|
||||
|
||||
const deleteArchivedResults = async () => {
|
||||
const lastDayOfPreviousMonth = new Date()
|
||||
lastDayOfPreviousMonth.setMonth(lastDayOfPreviousMonth.getMonth() - 1)
|
||||
lastDayOfPreviousMonth.setDate(0)
|
||||
|
||||
const { count } = await prisma.result.deleteMany({
|
||||
where: {
|
||||
createdAt: {
|
||||
lte: lastDayOfPreviousMonth,
|
||||
},
|
||||
isArchived: true,
|
||||
},
|
||||
})
|
||||
|
||||
console.log(`Deleted ${count} archived results.`)
|
||||
}
|
||||
|
||||
const deleteOldChatSessions = async () => {
|
||||
const threeDaysAgo = new Date()
|
||||
threeDaysAgo.setDate(threeDaysAgo.getDate() - 3)
|
||||
|
||||
Reference in New Issue
Block a user