Skip to content

Commit 4e288b3

Browse files
committed
Migrations: Fix error if table created in migration Version20240811221700 and already contains the index and FK - refs BT#21599
1 parent 4a0897d commit 4e288b3

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/CoreBundle/Migrations/Schema/V200/Version20240811221980.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,35 @@ public function up(Schema $schema): void
5050
$this->addSql('ALTER TABLE justification_document_rel_users CHANGE justification_document_id justification_document_id INT DEFAULT NULL;');
5151
}
5252

53-
$this->addSql('ALTER TABLE lti_external_tool DROP INDEX IF EXISTS FK_DB0E04E41BAD783F, ADD UNIQUE INDEX UNIQ_DB0E04E41BAD783F (resource_node_id);');
53+
$this->addSql('ALTER TABLE lti_external_tool DROP INDEX IF EXISTS FK_DB0E04E41BAD783F;');
54+
$table = $schema->getTable('lti_external_tool');
55+
if (false === $table->hasIndex('UNIQ_DB0E04E41BAD783F')) {
56+
$this->addSql('ALTER TABLE lti_external_tool ADD UNIQUE INDEX UNIQ_DB0E04E41BAD783F (resource_node_id);');
57+
}
5458
$this->addSql('ALTER TABLE lti_external_tool DROP FOREIGN KEY IF EXISTS FK_DB0E04E482F80D8B;');
5559
$this->addSql('ALTER TABLE lti_external_tool DROP FOREIGN KEY IF EXISTS FK_DB0E04E491D79BD3;');
5660
$this->addSql('ALTER TABLE lti_external_tool DROP FOREIGN KEY IF EXISTS FK_DB0E04E4727ACA70;');
5761
$this->addSql('DROP INDEX IF EXISTS fk_db0e04e491d79bd3 ON lti_external_tool;');
58-
$this->addSql('CREATE INDEX IDX_DB0E04E491D79BD3 ON lti_external_tool (c_id);');
62+
if (false === $table->hasIndex('IDX_DB0E04E491D79BD3')) {
63+
$this->addSql('CREATE INDEX IDX_DB0E04E491D79BD3 ON lti_external_tool (c_id);');
64+
}
5965
$this->addSql('DROP INDEX IF EXISTS fk_db0e04e482f80d8b ON lti_external_tool;');
60-
$this->addSql('CREATE INDEX IDX_DB0E04E482F80D8B ON lti_external_tool (gradebook_eval_id);');
66+
if (false === $table->hasIndex('IDX_DB0E04E482F80D8B')) {
67+
$this->addSql('CREATE INDEX IDX_DB0E04E482F80D8B ON lti_external_tool (gradebook_eval_id);');
68+
}
6169
$this->addSql('DROP INDEX IF EXISTS fk_db0e04e4727aca70 ON lti_external_tool;');
62-
$this->addSql('CREATE INDEX IDX_DB0E04E4727ACA70 ON lti_external_tool (parent_id);');
63-
$this->addSql('ALTER TABLE lti_external_tool ADD CONSTRAINT FK_DB0E04E482F80D8B FOREIGN KEY (gradebook_eval_id) REFERENCES gradebook_evaluation (id) ON DELETE SET NULL;');
64-
$this->addSql('ALTER TABLE lti_external_tool ADD CONSTRAINT FK_DB0E04E491D79BD3 FOREIGN KEY (c_id) REFERENCES course (id);');
65-
$this->addSql('ALTER TABLE lti_external_tool ADD CONSTRAINT FK_DB0E04E4727ACA70 FOREIGN KEY (parent_id) REFERENCES lti_external_tool (id);');
70+
if (false === $table->hasIndex('IDX_DB0E04E4727ACA70')) {
71+
$this->addSql('CREATE INDEX IDX_DB0E04E4727ACA70 ON lti_external_tool (parent_id);');
72+
}
73+
if (!$table->hasForeignKey('FK_DB0E04E482F80D8B')) {
74+
$this->addSql('ALTER TABLE lti_external_tool ADD CONSTRAINT FK_DB0E04E482F80D8B FOREIGN KEY (gradebook_eval_id) REFERENCES gradebook_evaluation (id) ON DELETE SET NULL;');
75+
}
76+
if (!$table->hasForeignKey('FK_DB0E04E491D79BD3')) {
77+
$this->addSql('ALTER TABLE lti_external_tool ADD CONSTRAINT FK_DB0E04E491D79BD3 FOREIGN KEY (c_id) REFERENCES course (id);');
78+
}
79+
if (!$table->hasForeignKey('FK_DB0E04E4727ACA70')) {
80+
$this->addSql('ALTER TABLE lti_external_tool ADD CONSTRAINT FK_DB0E04E4727ACA70 FOREIGN KEY (parent_id) REFERENCES lti_external_tool (id);');
81+
}
6682
}
6783

6884
public function down(Schema $schema): void {}

0 commit comments

Comments
 (0)