mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-23 11:28:32 +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 type { GoogleProfile } from "@coji/remix-auth-google";
|
||||||
import { prisma } from "~/db.server";
|
import { prisma } from "~/db.server";
|
||||||
import { env } from "~/env.server";
|
import { env } from "~/env.server";
|
||||||
|
import { runQuery } from "~/lib/neo4j.server";
|
||||||
export type { User } from "@core/database";
|
export type { User } from "@core/database";
|
||||||
|
|
||||||
type FindOrCreateMagicLink = {
|
type FindOrCreateMagicLink = {
|
||||||
@ -252,6 +253,23 @@ export async function deleteUser(id: User["id"]) {
|
|||||||
throw new Error("User not found");
|
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
|
// If workspace exists, delete all workspace-related data
|
||||||
// Most models DON'T have onDelete: Cascade, so we must delete manually
|
// Most models DON'T have onDelete: Cascade, so we must delete manually
|
||||||
if (user.Workspace) {
|
if (user.Workspace) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user