Skip to content

Commit 038fd3d

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 228cf0b commit 038fd3d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

webapp/migrations/Version20240825115643.php

Lines changed: 5 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,8 @@ 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');
3438
}
3539

3640
public function dropKeys(): void
@@ -41,6 +45,7 @@ public function dropKeys(): void
4145
$this->addSql('ALTER TABLE judging_run DROP CONSTRAINT FK_29A6E6E13CBA64F2');
4246
$this->addSql('ALTER TABLE judging_run DROP CONSTRAINT judging_run_ibfk_1');
4347
$this->addSql('ALTER TABLE judgetask DROP CONSTRAINT judgetask_ibfk_1');
48+
$this->addSql('ALTER TABLE submission DROP FOREIGN KEY FK_DB055AF3F132696E');
4449
}
4550

4651
public function addKeys(bool $suffix): void

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)