From dcc8354bfaf392d6507762ecb6630225a0ea10ee Mon Sep 17 00:00:00 2001 From: Ronnie Friman <L4168@student.jamk.fi> Date: Sat, 6 Jul 2019 15:22:37 +0300 Subject: [PATCH] added onDelete --- src/draw/coordinate.entity.ts | 20 ++++++++++++++++--- src/faction/faction.entity.ts | 18 ++++++++--------- src/game/game.entity.ts | 23 ++++++++++++++-------- src/notifications/notification.entity.ts | 25 +++++++++++++++++------- src/score/score.entity.ts | 4 +++- src/task/task.entity.ts | 4 +++- src/tracking/tracking.entity.ts | 4 +++- 7 files changed, 68 insertions(+), 30 deletions(-) diff --git a/src/draw/coordinate.entity.ts b/src/draw/coordinate.entity.ts index 8f5c4e1..ef5447f 100644 --- a/src/draw/coordinate.entity.ts +++ b/src/draw/coordinate.entity.ts @@ -21,7 +21,9 @@ export class MapDrawingEntity { onDelete: 'CASCADE', }) faction: FactionEntity; - @ManyToOne(type => GameEntity, gameEntity => gameEntity.id) + @ManyToOne(type => GameEntity, gameEntity => gameEntity.id, { + onDelete: 'CASCADE', + }) gameId: GameEntity; } @@ -30,8 +32,20 @@ export class Game_Person_MapDrawingEntity { @PrimaryGeneratedColumn('uuid') GPmapDrawingId: string; @Column({ type: 'timestamp' }) GPCTimeStamp: Timestamp; - @ManyToOne(type => Game_PersonEntity, game_person => game_person.gamepersonId) + @ManyToOne( + type => Game_PersonEntity, + game_person => game_person.gamepersonId, + { + onDelete: 'CASCADE', + }, + ) game_person: Game_PersonEntity; - @ManyToOne(type => MapDrawingEntity, map_drawing => map_drawing.mapDrawingId) + @ManyToOne( + type => MapDrawingEntity, + map_drawing => map_drawing.mapDrawingId, + { + onDelete: 'CASCADE', + }, + ) map_drawing: MapDrawingEntity; } diff --git a/src/faction/faction.entity.ts b/src/faction/faction.entity.ts index ba2fff0..3aa74cf 100644 --- a/src/faction/faction.entity.ts +++ b/src/faction/faction.entity.ts @@ -26,15 +26,13 @@ export class FactionEntity { @Column({ type: 'text' }) factionPassword: string; - @OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction, { - onDelete: 'SET NULL', - }) + @OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction) game_persons: Game_PersonEntity[]; - @ManyToOne(type => GameEntity, game => game.factions) - game: GameEntity; - @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.faction, { + @ManyToOne(type => GameEntity, game => game.factions, { onDelete: 'CASCADE', }) + game: GameEntity; + @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.faction) mapDrawings: MapDrawingEntity[]; factionObject() { @@ -47,7 +45,7 @@ export class FactionEntity { } } -@Entity('PowerUp') +/* @Entity('PowerUp') export class PowerUpEntity { @PrimaryGeneratedColumn('uuid') powerUpId: string; @Column({ type: 'text' }) powerUpName: string; @@ -55,7 +53,9 @@ export class PowerUpEntity { @Column({ type: 'int' }) amount: number; @Column({ type: 'time' }) cooldown: string; - @OneToMany(type => FactionEntity, factions => factions.factionId) + @OneToMany(type => FactionEntity, factions => factions.factionId, { + onDelete: 'CASCADE', + }) factions: Faction_PowerUpEntity[]; } @@ -81,7 +81,7 @@ export class FP_HistoryEntity { faction_PowerUp => faction_PowerUp.histories, ) faction_PowerUp: Faction_PowerUpEntity; -} +} */ @Entity('GameGroup') export class GameGroupEntity { diff --git a/src/game/game.entity.ts b/src/game/game.entity.ts index 761a14b..7ae6e29 100644 --- a/src/game/game.entity.ts +++ b/src/game/game.entity.ts @@ -57,19 +57,19 @@ export class Game_PersonEntity { @PrimaryGeneratedColumn('uuid') gamepersonId: string; @Column({ type: 'text', nullable: true }) role: string; @ManyToOne(type => FactionEntity, faction => faction.game_persons, { - onDelete: 'SET NULL', + onDelete: 'CASCADE', }) faction: FactionEntity; - @ManyToOne(type => GameEntity, game => game.id) + @ManyToOne(type => GameEntity, game => game.id, { + onDelete: 'CASCADE', + }) game: GameEntity; @ManyToOne(type => PersonEntity, person => person.id) person: PersonEntity; - @OneToOne(type => GameGroupEntity, group => group.leader, { - onDelete: 'CASCADE', - }) + @OneToOne(type => GameGroupEntity, group => group.leader) leaderGroup: GameGroupEntity; @ManyToOne(type => GameGroupEntity, group => group.players, { - onDelete: 'CASCADE', + onDelete: 'NO ACTION', }) @JoinColumn({ name: 'group' }) group: GameGroupEntity; @@ -81,9 +81,13 @@ export class ObjectivePointEntity { @Column({ type: 'text' }) objectivePointDescription: string; @Column({ type: 'float' }) objectivePointMultiplier: number; - @ManyToOne(type => MapDrawingEntity, coordinate => coordinate.data) + @ManyToOne(type => MapDrawingEntity, coordinate => coordinate.data, { + onDelete: 'CASCADE', + }) coordinate: MapDrawingEntity; - @ManyToOne(type => GameEntity, game => game.objective_points) + @ManyToOne(type => GameEntity, game => game.objective_points, { + onDelete: 'CASCADE', + }) game: GameEntity; } @@ -103,6 +107,9 @@ export class ObjectivePoint_HistoryEntity { @ManyToOne( type => ObjectivePointEntity, objective_point => objective_point.objectivePointId, + { + onDelete: 'CASCADE', + }, ) objective_point: string; } diff --git a/src/notifications/notification.entity.ts b/src/notifications/notification.entity.ts index 3f87816..3df76ac 100644 --- a/src/notifications/notification.entity.ts +++ b/src/notifications/notification.entity.ts @@ -1,11 +1,22 @@ -import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn } from "typeorm"; +import { + Entity, + PrimaryGeneratedColumn, + Column, + CreateDateColumn, + ManyToOne, +} from 'typeorm'; + +import { GameEntity } from '../game/game.entity'; // temporary table for warning notifications @Entity('Notifications') export class NotificationEntity { - @PrimaryGeneratedColumn('uuid') id: string; - @Column({type: 'text'}) message: string; - @CreateDateColumn() issued: Date; - // TODO: - // when game creation has been implemented, add logic so that the notifications are tied to games -} \ No newline at end of file + @PrimaryGeneratedColumn('uuid') id: string; + @Column({ type: 'text' }) message: string; + @CreateDateColumn() issued: Date; + + @ManyToOne(type => GameEntity, game => game.id, { + onDelete: 'CASCADE', + }) + game: GameEntity; +} diff --git a/src/score/score.entity.ts b/src/score/score.entity.ts index 58c8ec3..6ca9ab7 100644 --- a/src/score/score.entity.ts +++ b/src/score/score.entity.ts @@ -14,6 +14,8 @@ export class ScoreEntity { @Column({ type: 'float' }) score: number; @CreateDateColumn({ type: 'timestamp' }) scoreTimeStamp: Timestamp; - @ManyToOne(type => FactionEntity, factionName => factionName.factionId) + @ManyToOne(type => FactionEntity, factionName => factionName.factionId, { + onDelete: 'CASCADE', + }) faction: string; } diff --git a/src/task/task.entity.ts b/src/task/task.entity.ts index c8f7d62..f1c1cf1 100644 --- a/src/task/task.entity.ts +++ b/src/task/task.entity.ts @@ -24,7 +24,9 @@ export class TaskEntity { onDelete: 'CASCADE', }) taskWinner: FactionEntity; - @ManyToOne(type => GameEntity, game => game.id) + @ManyToOne(type => GameEntity, game => game.id, { + onDelete: 'CASCADE', + }) @JoinColumn({ name: 'taskGame' }) taskGame: GameEntity; } diff --git a/src/tracking/tracking.entity.ts b/src/tracking/tracking.entity.ts index b312391..cabe141 100644 --- a/src/tracking/tracking.entity.ts +++ b/src/tracking/tracking.entity.ts @@ -5,6 +5,8 @@ import { Game_PersonEntity } from '../game/game.entity'; export class TrackingEntity { @PrimaryGeneratedColumn('uuid') id: string; @Column({ type: 'json', nullable: true }) data: JSON; - @ManyToOne(type => Game_PersonEntity, person => person.gamepersonId) + @ManyToOne(type => Game_PersonEntity, person => person.gamepersonId, { + onDelete: 'CASCADE', + }) gamepersonId: Game_PersonEntity; } -- GitLab