🧑💻 (s3) Correctly delete the files when deleting resources
This commit is contained in:
@ -1,9 +1,3 @@
|
||||
import { destroyUser } from './helpers/destroyUser'
|
||||
import { promptAndSetEnvironment } from './utils'
|
||||
|
||||
const runDestroyUser = async () => {
|
||||
await promptAndSetEnvironment('production')
|
||||
return destroyUser()
|
||||
}
|
||||
|
||||
runDestroyUser()
|
||||
destroyUser()
|
||||
|
@ -1,6 +1,10 @@
|
||||
import { isCancel, text, confirm } from '@clack/prompts'
|
||||
import { Plan, PrismaClient } from '@typebot.io/prisma'
|
||||
import { PrismaClient } from '@typebot.io/prisma'
|
||||
import { writeFileSync } from 'fs'
|
||||
import {
|
||||
removeObjectsFromUser,
|
||||
removeObjectsFromWorkspace,
|
||||
} from '@typebot.io/lib/s3/removeObjectsRecursively'
|
||||
|
||||
export const destroyUser = async (userEmail?: string) => {
|
||||
const prisma = new PrismaClient()
|
||||
@ -50,8 +54,16 @@ export const destroyUser = async (userEmail?: string) => {
|
||||
}
|
||||
|
||||
console.log(
|
||||
'Workspaces plans:',
|
||||
workspaces.map((w) => w.plan)
|
||||
'Workspaces:',
|
||||
JSON.stringify(
|
||||
workspaces.map((w) => ({
|
||||
id: w.id,
|
||||
plan: w.plan,
|
||||
members: w.members,
|
||||
})),
|
||||
null,
|
||||
2
|
||||
)
|
||||
)
|
||||
|
||||
const proceed = await confirm({ message: 'Proceed?' })
|
||||
@ -61,13 +73,15 @@ export const destroyUser = async (userEmail?: string) => {
|
||||
}
|
||||
|
||||
for (const workspace of workspaces) {
|
||||
const hasResults = workspace.typebots.some((t) => t.results.length > 0)
|
||||
if (hasResults) {
|
||||
const totalResults = workspace.typebots.reduce(
|
||||
(acc, typebot) => acc + typebot.results.length,
|
||||
0
|
||||
)
|
||||
|
||||
if (totalResults > 0) {
|
||||
console.log(
|
||||
`Workspace ${workspace.name} has results. Deleting results first...`,
|
||||
workspace.typebots.filter((t) => t.results.length > 0)
|
||||
`Workspace ${workspace.name} has ${totalResults} results. We should delete them first...`
|
||||
)
|
||||
console.log(JSON.stringify({ members: workspace.members }, null, 2))
|
||||
const proceed = await confirm({ message: 'Proceed?' })
|
||||
if (!proceed || typeof proceed !== 'boolean') {
|
||||
console.log('Aborting')
|
||||
@ -82,9 +96,11 @@ export const destroyUser = async (userEmail?: string) => {
|
||||
}
|
||||
}
|
||||
await prisma.workspace.delete({ where: { id: workspace.id } })
|
||||
await removeObjectsFromWorkspace(workspace.id)
|
||||
}
|
||||
|
||||
const user = await prisma.user.delete({ where: { email } })
|
||||
await removeObjectsFromUser(user.id)
|
||||
|
||||
console.log(`Deleted user ${JSON.stringify(user, null, 2)}`)
|
||||
console.log(`User deleted.`, JSON.stringify(user, null, 2))
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
"insertUsersInBrevoList": "tsx insertUsersInBrevoList.ts",
|
||||
"getUsage": "tsx getUsage.ts",
|
||||
"suspendWorkspace": "tsx suspendWorkspace.ts",
|
||||
"destroyUser": "tsx destroyUser.ts",
|
||||
"destroyUser": "SKIP_ENV_CHECK=true dotenv -e ./.env.production -- tsx destroyUser.ts",
|
||||
"updateTypebot": "tsx updateTypebot.ts",
|
||||
"updateWorkspace": "tsx updateWorkspace.ts",
|
||||
"inspectTypebot": "tsx inspectTypebot.ts",
|
||||
|
Reference in New Issue
Block a user