🗃️ Remove updatedAt field from Result
This commit is contained in:
@ -1133,10 +1133,6 @@
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"updatedAt": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"typebotId": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -1188,7 +1184,6 @@
|
||||
"required": [
|
||||
"id",
|
||||
"createdAt",
|
||||
"updatedAt",
|
||||
"typebotId",
|
||||
"variables",
|
||||
"isCompleted",
|
||||
|
@ -242,7 +242,6 @@ model PublicTypebot {
|
||||
model Result {
|
||||
id String @id @default(cuid())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
typebotId String
|
||||
variables Json
|
||||
isCompleted Boolean
|
||||
|
@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Result" DROP COLUMN "updatedAt";
|
@ -223,7 +223,6 @@ model PublicTypebot {
|
||||
model Result {
|
||||
id String @id @default(cuid())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
typebotId String
|
||||
variables Json
|
||||
isCompleted Boolean
|
||||
|
@ -9,7 +9,6 @@ export const resultSchema = schemaForType<ResultPrisma>()(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
typebotId: z.string(),
|
||||
variables: z.array(variableWithValueSchema),
|
||||
isCompleted: z.boolean(),
|
||||
|
@ -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