|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace DoctrineMigrations; |
| 6 | + |
| 7 | +use Doctrine\DBAL\Schema\Schema; |
| 8 | +use Doctrine\Migrations\AbstractMigration; |
| 9 | + |
| 10 | +/** |
| 11 | + * Auto-generated Migration: Please modify to your needs! |
| 12 | + */ |
| 13 | +final class Version20240825115643 extends AbstractMigration |
| 14 | +{ |
| 15 | + // All remaining foreign keys are now cascade. |
| 16 | + // There is one exception: immutable_executable.immutable_execid is still referenced and removal is restricted. |
| 17 | + public function getDescription(): string |
| 18 | + { |
| 19 | + return 'Recreate \'restrict foreign key constraints\', cascading or setting to null where needed.'; |
| 20 | + } |
| 21 | + |
| 22 | + public function up(Schema $schema): void |
| 23 | + { |
| 24 | + $this->dropKeys(); |
| 25 | + $this->addKeys(true); |
| 26 | + } |
| 27 | + |
| 28 | + public function down(Schema $schema): void |
| 29 | + { |
| 30 | + $this->dropKeys(); |
| 31 | + |
| 32 | + // Reinstate the 'restrict' keys. |
| 33 | + $this->addKeys(false); |
| 34 | + } |
| 35 | + |
| 36 | + public function dropKeys(): void |
| 37 | + { |
| 38 | + $this->addSql('ALTER TABLE debug_package DROP CONSTRAINT FK_9E17399BE0E4FC3E'); |
| 39 | + $this->addSql('ALTER TABLE version DROP CONSTRAINT FK_BF1CD3C32271845'); |
| 40 | + $this->addSql('ALTER TABLE version DROP CONSTRAINT FK_BF1CD3C3E0E4FC3E'); |
| 41 | + $this->addSql('ALTER TABLE judging_run DROP CONSTRAINT FK_29A6E6E13CBA64F2'); |
| 42 | + $this->addSql('ALTER TABLE judging_run DROP CONSTRAINT judging_run_ibfk_1'); |
| 43 | + $this->addSql('ALTER TABLE judgetask DROP CONSTRAINT judgetask_ibfk_1'); |
| 44 | + } |
| 45 | + |
| 46 | + public function addKeys(bool $suffix): void |
| 47 | + { |
| 48 | + // foreign-keys that are related to judgehosts are set to null so that no data is lost. |
| 49 | + $cascadeClause = $suffix ? 'ON DELETE CASCADE' : ''; |
| 50 | + $nullClause = $suffix ? 'ON DELETE SET NULL' : ''; |
| 51 | + |
| 52 | + $this->addSql('ALTER TABLE version ADD CONSTRAINT `FK_BF1CD3C32271845` FOREIGN KEY (`langid`) REFERENCES `language` (`langid`) ' . $cascadeClause); |
| 53 | + $this->addSql('ALTER TABLE version ADD CONSTRAINT `FK_BF1CD3C3E0E4FC3E` FOREIGN KEY (`judgehostid`) REFERENCES `judgehost` (`judgehostid`) ' . $nullClause); |
| 54 | + $this->addSql('ALTER TABLE judging_run ADD CONSTRAINT `FK_29A6E6E13CBA64F2` FOREIGN KEY (`judgetaskid`) REFERENCES `judgetask` (`judgetaskid`) ' . $cascadeClause); |
| 55 | + $this->addSql('ALTER TABLE judging_run ADD CONSTRAINT `judging_run_ibfk_1` FOREIGN KEY (`testcaseid`) REFERENCES `testcase` (`testcaseid`) ' . $cascadeClause); |
| 56 | + $this->addSql('ALTER TABLE judgetask ADD CONSTRAINT `judgetask_ibfk_1` FOREIGN KEY (`judgehostid`) REFERENCES `judgehost` (`judgehostid`) ' . $nullClause); |
| 57 | + $this->addSql('ALTER TABLE debug_package ADD CONSTRAINT `FK_9E17399BE0E4FC3E` FOREIGN KEY (`judgehostid`) REFERENCES `judgehost` (`judgehostid`) ' . $nullClause); |
| 58 | + } |
| 59 | + |
| 60 | + public function isTransactional(): bool |
| 61 | + { |
| 62 | + return false; |
| 63 | + } |
| 64 | +} |
0 commit comments