-
Notifications
You must be signed in to change notification settings - Fork 276
Change cascading of most 'restrict' foreign keys #2658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+73
−7
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.