mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 09:46:30 -05:00
Entities: Add onDelete CASCADE to entities
To better handle deletion of entities, all necessary other entities got the option onDelete CASCADE set. So everything that does not make any sense if something else is deleted will be deleted along side of it. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
56a46f57fc
commit
e90e2a8e19
6 changed files with 22 additions and 6 deletions
|
@ -21,7 +21,9 @@ export class AuthToken {
|
|||
@Column({ unique: true })
|
||||
keyId: string;
|
||||
|
||||
@ManyToOne((_) => User, (user) => user.authTokens)
|
||||
@ManyToOne((_) => User, (user) => user.authTokens, {
|
||||
onDelete: 'CASCADE', // This deletes the AuthToken, when the associated User is deleted
|
||||
})
|
||||
user: User;
|
||||
|
||||
@Column()
|
||||
|
|
|
@ -36,7 +36,6 @@ export class Group {
|
|||
|
||||
@ManyToMany((_) => User, (user) => user.groups, {
|
||||
eager: true,
|
||||
cascade: true,
|
||||
})
|
||||
@JoinTable()
|
||||
members: User[];
|
||||
|
|
|
@ -23,10 +23,14 @@ export class MediaUpload {
|
|||
@PrimaryColumn()
|
||||
id: string;
|
||||
|
||||
@ManyToOne((_) => Note, { nullable: false })
|
||||
@ManyToOne((_) => Note, (note) => note.mediaUploads, {
|
||||
nullable: false,
|
||||
})
|
||||
note: Note;
|
||||
|
||||
@ManyToOne((_) => User, { nullable: false })
|
||||
@ManyToOne((_) => User, (user) => user.mediaUploads, {
|
||||
nullable: false,
|
||||
})
|
||||
user: User;
|
||||
|
||||
@Column({
|
||||
|
|
|
@ -21,6 +21,7 @@ import { User } from '../users/user.entity';
|
|||
import { AuthorColor } from './author-color.entity';
|
||||
import { Tag } from './tag.entity';
|
||||
import { HistoryEntry } from '../history/history-entry.entity';
|
||||
import { MediaUpload } from '../media/media-upload.entity';
|
||||
|
||||
@Entity()
|
||||
export class Note {
|
||||
|
@ -53,7 +54,9 @@ export class Note {
|
|||
default: 0,
|
||||
})
|
||||
viewCount: number;
|
||||
@ManyToOne((_) => User, (user) => user.ownedNotes, { onDelete: 'CASCADE' })
|
||||
@ManyToOne((_) => User, (user) => user.ownedNotes, {
|
||||
onDelete: 'CASCADE', // This deletes the Note, when the associated User is deleted
|
||||
})
|
||||
owner: User;
|
||||
@OneToMany((_) => Revision, (revision) => revision.note, { cascade: true })
|
||||
revisions: Promise<Revision[]>;
|
||||
|
@ -61,6 +64,8 @@ export class Note {
|
|||
authorColors: AuthorColor[];
|
||||
@OneToMany((_) => HistoryEntry, (historyEntry) => historyEntry.user)
|
||||
historyEntries: HistoryEntry[];
|
||||
@OneToMany((_) => MediaUpload, (mediaUpload) => mediaUpload.note)
|
||||
mediaUploads: MediaUpload[];
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
|
|
|
@ -19,7 +19,9 @@ export class Identity {
|
|||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@ManyToOne((_) => User, (user) => user.identities)
|
||||
@ManyToOne((_) => User, (user) => user.identities, {
|
||||
onDelete: 'CASCADE', // This deletes the Identity, when the associated User is deleted
|
||||
})
|
||||
user: User;
|
||||
|
||||
@Column()
|
||||
|
|
|
@ -17,6 +17,7 @@ import { AuthToken } from '../auth/auth-token.entity';
|
|||
import { Identity } from './identity.entity';
|
||||
import { Group } from '../groups/group.entity';
|
||||
import { HistoryEntry } from '../history/history-entry.entity';
|
||||
import { MediaUpload } from '../media/media-upload.entity';
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
|
@ -62,6 +63,9 @@ export class User {
|
|||
@OneToMany((_) => HistoryEntry, (historyEntry) => historyEntry.user)
|
||||
historyEntries: HistoryEntry[];
|
||||
|
||||
@OneToMany((_) => MediaUpload, (mediaUpload) => mediaUpload.user)
|
||||
mediaUploads: MediaUpload[];
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
private constructor() {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue