Skip to content

Commit 3bd3df2

Browse files
committed
prevents removing submissions on user delete
The old foreign key was set to cascade, deleting the entire submission when a user got deleted. This feels conceptually wrong since a submission is connected to a team and not to a user. The user of the team of the submission is more 'metadata' than anything else.
1 parent cd0447e commit 3bd3df2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

webapp/migrations/Version20240825115643.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function up(Schema $schema): void
2323
{
2424
$this->dropKeys();
2525
$this->addKeys(true);
26+
27+
$this->addSql('ALTER TABLE submission ADD CONSTRAINT FK_DB055AF3F132696E FOREIGN KEY (userid) REFERENCES user (userid) ON DELETE SET NULL');
2628
}
2729

2830
public function down(Schema $schema): void
@@ -31,6 +33,9 @@ public function down(Schema $schema): void
3133

3234
// Reinstate the 'restrict' keys.
3335
$this->addKeys(false);
36+
37+
$this->addSql('ALTER TABLE submission ADD CONSTRAINT FK_DB055AF3F132696E FOREIGN KEY (userid) REFERENCES user (userid) ON DELETE CASCADE');
38+
3439
}
3540

3641
public function dropKeys(): void
@@ -41,6 +46,7 @@ public function dropKeys(): void
4146
$this->addSql('ALTER TABLE judging_run DROP CONSTRAINT FK_29A6E6E13CBA64F2');
4247
$this->addSql('ALTER TABLE judging_run DROP CONSTRAINT judging_run_ibfk_1');
4348
$this->addSql('ALTER TABLE judgetask DROP CONSTRAINT judgetask_ibfk_1');
49+
$this->addSql('ALTER TABLE submission DROP FOREIGN KEY FK_DB055AF3F132696E');
4450
}
4551

4652
public function addKeys(bool $suffix): void
@@ -55,6 +61,7 @@ public function addKeys(bool $suffix): void
5561
$this->addSql('ALTER TABLE judging_run ADD CONSTRAINT `judging_run_ibfk_1` FOREIGN KEY (`testcaseid`) REFERENCES `testcase` (`testcaseid`) ' . $cascadeClause);
5662
$this->addSql('ALTER TABLE judgetask ADD CONSTRAINT `judgetask_ibfk_1` FOREIGN KEY (`judgehostid`) REFERENCES `judgehost` (`judgehostid`) ' . $null);
5763
$this->addSql('ALTER TABLE debug_package ADD CONSTRAINT `FK_9E17399BE0E4FC3E` FOREIGN KEY (`judgehostid`) REFERENCES `judgehost` (`judgehostid`) ' . $null);
64+
5865
}
5966

6067
public function isTransactional(): bool

webapp/src/Entity/Submission.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Submission extends BaseApiEntity implements
118118
private Team $team;
119119

120120
#[ORM\ManyToOne(inversedBy: 'submissions')]
121-
#[ORM\JoinColumn(name: 'userid', referencedColumnName: 'userid', onDelete: 'CASCADE')]
121+
#[ORM\JoinColumn(name: 'userid', referencedColumnName: 'userid', onDelete: 'SET NULL')]
122122
#[Serializer\Exclude]
123123
private ?User $user = null;
124124

0 commit comments

Comments
 (0)