Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions webapp/migrations/Version20240825115643.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240825115643 extends AbstractMigration
{
// All remaining foreign keys are now cascade.
// There is one exception: immutable_executable.immutable_execid is still referenced and removal is restricted.
public function getDescription(): string
{
return 'Recreate \'restrict foreign key constraints\', cascading or setting to null where needed.';
}

public function up(Schema $schema): void
{
$this->dropKeys();
$this->addKeys(true);
}

public function down(Schema $schema): void
{
$this->dropKeys();
$this->addKeys(false);
}

public function dropKeys(): void
{
$this->addSql('ALTER TABLE debug_package DROP CONSTRAINT FK_9E17399BE0E4FC3E');
$this->addSql('ALTER TABLE version DROP CONSTRAINT FK_BF1CD3C32271845');
$this->addSql('ALTER TABLE version DROP CONSTRAINT FK_BF1CD3C3E0E4FC3E');
$this->addSql('ALTER TABLE judging_run DROP CONSTRAINT FK_29A6E6E13CBA64F2');
$this->addSql('ALTER TABLE judging_run DROP CONSTRAINT judging_run_ibfk_1');
$this->addSql('ALTER TABLE judgetask DROP CONSTRAINT judgetask_ibfk_1');
$this->addSql('ALTER TABLE submission DROP FOREIGN KEY FK_DB055AF3F132696E');
}

public function addKeys(bool $isUp): void
{
// foreign-keys that are related to judgehosts are set to null so that no data is lost.
$cascadeClause = $isUp ? 'ON DELETE CASCADE' : '';
$nullClause = $isUp ? 'ON DELETE SET NULL' : '';

$this->addSql('ALTER TABLE version ADD CONSTRAINT `FK_BF1CD3C32271845` FOREIGN KEY (`langid`) REFERENCES `language` (`langid`) ' . $cascadeClause);
$this->addSql('ALTER TABLE version ADD CONSTRAINT `FK_BF1CD3C3E0E4FC3E` FOREIGN KEY (`judgehostid`) REFERENCES `judgehost` (`judgehostid`) ' . $nullClause);
$this->addSql('ALTER TABLE judging_run ADD CONSTRAINT `FK_29A6E6E13CBA64F2` FOREIGN KEY (`judgetaskid`) REFERENCES `judgetask` (`judgetaskid`) ' . $cascadeClause);
$this->addSql('ALTER TABLE judging_run ADD CONSTRAINT `judging_run_ibfk_1` FOREIGN KEY (`testcaseid`) REFERENCES `testcase` (`testcaseid`) ' . $cascadeClause);
$this->addSql('ALTER TABLE judgetask ADD CONSTRAINT `judgetask_ibfk_1` FOREIGN KEY (`judgehostid`) REFERENCES `judgehost` (`judgehostid`) ' . $nullClause);
$this->addSql('ALTER TABLE debug_package ADD CONSTRAINT `FK_9E17399BE0E4FC3E` FOREIGN KEY (`judgehostid`) REFERENCES `judgehost` (`judgehostid`) ' . $nullClause);

$clause = $isUp ? 'ON DELETE SET NULL' : 'ON DELETE CASCADE';
$this->addSql('ALTER TABLE submission ADD CONSTRAINT FK_DB055AF3F132696E FOREIGN KEY (userid) REFERENCES user (userid) ' . $clause);
}

public function isTransactional(): bool
{
return false;
}
}
2 changes: 1 addition & 1 deletion webapp/src/Entity/DebugPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DebugPackage
private string $filename;

#[ORM\ManyToOne]
#[ORM\JoinColumn(name: 'judgehostid', referencedColumnName: 'judgehostid')]
#[ORM\JoinColumn(name: 'judgehostid', referencedColumnName: 'judgehostid', onDelete: 'SET NULL')]
private Judgehost $judgehost;

public function getDebugPackageId(): int
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Entity/JudgeTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class JudgeTask
private int $judgetaskid;

#[ORM\ManyToOne(inversedBy: 'judgetasks')]
#[ORM\JoinColumn(name: 'judgehostid', referencedColumnName: 'judgehostid')]
#[ORM\JoinColumn(name: 'judgehostid', referencedColumnName: 'judgehostid', onDelete: 'SET NULL')]
#[Serializer\Exclude]
private ?Judgehost $judgehost = null;

Expand Down
4 changes: 2 additions & 2 deletions webapp/src/Entity/JudgingRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class JudgingRun extends BaseApiEntity
private Judging $judging;

#[ORM\ManyToOne(inversedBy: 'judging_runs')]
#[ORM\JoinColumn(name: 'testcaseid', referencedColumnName: 'testcaseid')]
#[ORM\JoinColumn(name: 'testcaseid', referencedColumnName: 'testcaseid', onDelete: 'CASCADE')]
#[Serializer\Exclude]
private Testcase $testcase;

Expand All @@ -82,7 +82,7 @@ class JudgingRun extends BaseApiEntity
private Collection $output;

#[ORM\ManyToOne(inversedBy: 'judging_runs')]
#[ORM\JoinColumn(name: 'judgetaskid', referencedColumnName: 'judgetaskid')]
#[ORM\JoinColumn(name: 'judgetaskid', referencedColumnName: 'judgetaskid', onDelete: 'CASCADE')]
#[Serializer\Exclude]
private ?JudgeTask $judgetask = null;

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Entity/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Submission extends BaseApiEntity implements
private Team $team;

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

Expand Down
4 changes: 2 additions & 2 deletions webapp/src/Entity/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class Version
private ?string $compilerVersionCommand = null;

#[ORM\ManyToOne(targetEntity: Language::class, inversedBy: "versions")]
#[ORM\JoinColumn(name: 'langid', referencedColumnName: 'langid')]
#[ORM\JoinColumn(name: 'langid', referencedColumnName: 'langid', onDelete: 'CASCADE')]
private Language $language;

#[ORM\ManyToOne(targetEntity: Judgehost::class)]
#[ORM\JoinColumn(name: 'judgehostid', referencedColumnName: 'judgehostid')]
#[ORM\JoinColumn(name: 'judgehostid', referencedColumnName: 'judgehostid', onDelete: 'SET NULL')]
private Judgehost $judgehost;

#[ORM\Column(
Expand Down
Loading