mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-10 23:38:27 +00:00
feat: clean up Neo4j graph nodes when deleting user account
This commit is contained in:
parent
1db2628af4
commit
170eed76fb
@ -2,6 +2,7 @@ import type { Prisma, User } from "@core/database";
|
||||
import type { GoogleProfile } from "@coji/remix-auth-google";
|
||||
import { prisma } from "~/db.server";
|
||||
import { env } from "~/env.server";
|
||||
import { runQuery } from "~/lib/neo4j.server";
|
||||
export type { User } from "@core/database";
|
||||
|
||||
type FindOrCreateMagicLink = {
|
||||
@ -252,6 +253,23 @@ export async function deleteUser(id: User["id"]) {
|
||||
throw new Error("User not found");
|
||||
}
|
||||
|
||||
// Delete all user-related nodes from the Neo4j knowledge graph
|
||||
try {
|
||||
// Delete all nodes (Episodes, Entities, Statements, Spaces, Documents, Clusters)
|
||||
// and their relationships where userId matches
|
||||
await runQuery(
|
||||
`
|
||||
MATCH (n {userId: $userId})
|
||||
DETACH DELETE n
|
||||
`,
|
||||
{ userId: id }
|
||||
);
|
||||
console.log(`Deleted all graph nodes for user ${id}`);
|
||||
} catch (error) {
|
||||
console.error("Failed to delete graph nodes:", error);
|
||||
// Continue with deletion even if graph cleanup fails
|
||||
}
|
||||
|
||||
// If workspace exists, delete all workspace-related data
|
||||
// Most models DON'T have onDelete: Cascade, so we must delete manually
|
||||
if (user.Workspace) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user