🗃️ Remove updatedAt field from Result
This commit is contained in:
@ -1133,10 +1133,6 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "date-time"
|
"format": "date-time"
|
||||||
},
|
},
|
||||||
"updatedAt": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "date-time"
|
|
||||||
},
|
|
||||||
"typebotId": {
|
"typebotId": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -1188,7 +1184,6 @@
|
|||||||
"required": [
|
"required": [
|
||||||
"id",
|
"id",
|
||||||
"createdAt",
|
"createdAt",
|
||||||
"updatedAt",
|
|
||||||
"typebotId",
|
"typebotId",
|
||||||
"variables",
|
"variables",
|
||||||
"isCompleted",
|
"isCompleted",
|
||||||
|
@ -242,7 +242,6 @@ model PublicTypebot {
|
|||||||
model Result {
|
model Result {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
|
||||||
typebotId String
|
typebotId String
|
||||||
variables Json
|
variables Json
|
||||||
isCompleted Boolean
|
isCompleted Boolean
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Result" DROP COLUMN "updatedAt";
|
@ -223,7 +223,6 @@ model PublicTypebot {
|
|||||||
model Result {
|
model Result {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
|
||||||
typebotId String
|
typebotId String
|
||||||
variables Json
|
variables Json
|
||||||
isCompleted Boolean
|
isCompleted Boolean
|
||||||
|
@ -9,7 +9,6 @@ export const resultSchema = schemaForType<ResultPrisma>()(
|
|||||||
z.object({
|
z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date(),
|
|
||||||
typebotId: z.string(),
|
typebotId: z.string(),
|
||||||
variables: z.array(variableWithValueSchema),
|
variables: z.array(variableWithValueSchema),
|
||||||
isCompleted: z.boolean(),
|
isCompleted: z.boolean(),
|
||||||
|
@ -10,9 +10,48 @@ export const cleanDatabase = async () => {
|
|||||||
await deleteOldChatSessions()
|
await deleteOldChatSessions()
|
||||||
await deleteExpiredAppSessions()
|
await deleteExpiredAppSessions()
|
||||||
await deleteExpiredVerificationTokens()
|
await deleteExpiredVerificationTokens()
|
||||||
|
const isFirstOfMonth = new Date().getDate() === 1
|
||||||
|
if (isFirstOfMonth) {
|
||||||
|
await deleteArchivedTypebots()
|
||||||
|
await deleteArchivedResults()
|
||||||
|
}
|
||||||
console.log('Done!')
|
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 deleteOldChatSessions = async () => {
|
||||||
const threeDaysAgo = new Date()
|
const threeDaysAgo = new Date()
|
||||||
threeDaysAgo.setDate(threeDaysAgo.getDate() - 3)
|
threeDaysAgo.setDate(threeDaysAgo.getDate() - 3)
|
||||||
|
Reference in New Issue
Block a user