sistema-de-chamados/scripts/remove-legacy-demo-users.mjs
2025-10-18 01:32:19 -03:00

49 lines
1.4 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import "dotenv/config"
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
const EMAILS_TO_REMOVE = [
"cliente.demo@sistema.dev",
"luciana.prado@omnisaude.com.br",
"ricardo.matos@omnisaude.com.br",
"aline.rezende@atlasengenharia.com.br",
"joao.ramos@atlasengenharia.com.br",
"fernanda.lima@omnisaude.com.br",
"mariana.andrade@atlasengenharia.com.br",
"renanzera@gmail.com",
].map((email) => email.toLowerCase())
async function deleteAuthUserByEmail(email) {
const authUser = await prisma.authUser.findUnique({
where: { email },
select: { id: true, email: true },
})
if (!authUser) {
console.log(` Usuário não encontrado, ignorando: ${email}`)
return
}
await prisma.authSession.deleteMany({ where: { userId: authUser.id } })
await prisma.authAccount.deleteMany({ where: { userId: authUser.id } })
await prisma.authInvite.deleteMany({ where: { email } })
await prisma.user.deleteMany({ where: { email } })
await prisma.authUser.delete({ where: { id: authUser.id } })
console.log(`🧹 Removido: ${email}`)
}
async function main() {
for (const email of EMAILS_TO_REMOVE) {
await deleteAuthUserByEmail(email)
}
}
main()
.catch((error) => {
console.error("Falha ao remover usuários legado", error)
process.exitCode = 1
})
.finally(async () => {
await prisma.$disconnect()
})