From 957cc8f38c2958d1741e777c6cfce41f6a5192d2 Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 12 Nov 2023 16:05:51 -0500 Subject: [PATCH] cascade deletes of auth method/session FKs --- src/lib/server/entity/AuthMethod.ts | 5 ++++- src/lib/server/entity/AuthSession.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/server/entity/AuthMethod.ts b/src/lib/server/entity/AuthMethod.ts index 9f2f927..bcc5e48 100644 --- a/src/lib/server/entity/AuthMethod.ts +++ b/src/lib/server/entity/AuthMethod.ts @@ -15,7 +15,10 @@ export class AuthMethod { @Column({type: 'varchar', length: 500, nullable: false}) userIdentifier!: string; - @ManyToOne(() => User, user => user.authMethods) + @ManyToOne(() => User, user => user.authMethods, { + cascade: ['remove'], + onDelete: 'CASCADE', + }) user!: User; @BeforeInsert() diff --git a/src/lib/server/entity/AuthSession.ts b/src/lib/server/entity/AuthSession.ts index f5cf201..91d2e16 100644 --- a/src/lib/server/entity/AuthSession.ts +++ b/src/lib/server/entity/AuthSession.ts @@ -10,7 +10,10 @@ export class AuthSession { @PrimaryColumn({type: 'varchar', length: 26, nullable: false}) id = ulidMonotonic(); - @ManyToOne(() => AuthMethod, authMethod => authMethod.id, {nullable: false}) + @ManyToOne(() => AuthMethod, authMethod => authMethod.id, { + cascade: ['remove'], + onDelete: 'CASCADE', + }) authMethod!: AuthMethod; // TODO expiration of sessions?