👷 Add expired records database cleanup scripts
This commit is contained in:
@@ -21,7 +21,7 @@ const bulkUpdate = async () => {
|
|||||||
|
|
||||||
const results = (await prisma.result.findMany({
|
const results = (await prisma.result.findMany({
|
||||||
where: {
|
where: {
|
||||||
variables: { isEmpty: false },
|
variables: { equals: [] },
|
||||||
},
|
},
|
||||||
select: { variables: true, id: true },
|
select: { variables: true, id: true },
|
||||||
})) as Pick<Result, 'variables' | 'id'>[]
|
})) as Pick<Result, 'variables' | 'id'>[]
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ export const cleanDatabase = async () => {
|
|||||||
|
|
||||||
console.log('Starting database cleanup...')
|
console.log('Starting database cleanup...')
|
||||||
await deleteOldChatSessions()
|
await deleteOldChatSessions()
|
||||||
|
await deleteExpiredAppSessions()
|
||||||
|
await deleteExpiredVerificationTokens()
|
||||||
console.log('Done!')
|
console.log('Done!')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,4 +26,30 @@ const deleteOldChatSessions = async () => {
|
|||||||
console.log(`Deleted ${count} old chat sessions.`)
|
console.log(`Deleted ${count} old chat sessions.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deleteExpiredAppSessions = async () => {
|
||||||
|
const threeDaysAgo = new Date()
|
||||||
|
threeDaysAgo.setDate(threeDaysAgo.getDate() - 3)
|
||||||
|
const { count } = await prisma.session.deleteMany({
|
||||||
|
where: {
|
||||||
|
expires: {
|
||||||
|
lte: threeDaysAgo,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
console.log(`Deleted ${count} expired user sessions.`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteExpiredVerificationTokens = async () => {
|
||||||
|
const threeDaysAgo = new Date()
|
||||||
|
threeDaysAgo.setDate(threeDaysAgo.getDate() - 3)
|
||||||
|
const { count } = await prisma.verificationToken.deleteMany({
|
||||||
|
where: {
|
||||||
|
expires: {
|
||||||
|
lte: threeDaysAgo,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
console.log(`Deleted ${count} expired verifiations tokens.`)
|
||||||
|
}
|
||||||
|
|
||||||
cleanDatabase().then()
|
cleanDatabase().then()
|
||||||
|
|||||||
Reference in New Issue
Block a user