Only drop the legacy foreign key if migrated from legacy DB.

This commit is contained in:
Jan Böhmer 2023-01-08 18:57:56 +01:00
parent 257c67b6c1
commit e423ef1e09

View file

@ -38,14 +38,18 @@ final class Version20230108165410 extends AbstractMultiPlatformMigration
$this->addSql('ALTER TABLE project_bom_entries ADD CONSTRAINT FK_AFC547992F180363 FOREIGN KEY (id_device) REFERENCES projects (id)');
$this->addSql('ALTER TABLE project_bom_entries ADD CONSTRAINT FK_AFC54799C22F6CC4 FOREIGN KEY (id_part) REFERENCES parts (id)');
$this->addSql('ALTER TABLE projects DROP FOREIGN KEY FK_11074E9A6DEDCEC2');
$this->addSql('ALTER TABLE projects DROP FOREIGN KEY devices_parent_id_fk');
//On old DBs migrated from the legacy Part-DB version the key devices_parent_id_fk is still existing
if ($this->getOldDBVersion() === 99) {
$this->addSql('ALTER TABLE projects DROP FOREIGN KEY devices_parent_id_fk');
}
$this->addSql('ALTER TABLE projects ADD status VARCHAR(64) DEFAULT NULL, ADD description LONGTEXT NOT NULL DEFAULT ""');
$this->addSql('DROP INDEX idx_11074e9a727aca70 ON projects');
$this->addSql('CREATE INDEX IDX_5C93B3A4727ACA70 ON projects (parent_id)');
$this->addSql('DROP INDEX idx_11074e9a6dedcec2 ON projects');
$this->addSql('CREATE INDEX IDX_5C93B3A46DEDCEC2 ON projects (id_preview_attachement)');
$this->addSql('ALTER TABLE projects ADD CONSTRAINT FK_11074E9A6DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES attachments (id)');
$this->addSql('ALTER TABLE projects ADD CONSTRAINT devices_parent_id_fk FOREIGN KEY (parent_id) REFERENCES projects (id)');
$this->addSql('ALTER TABLE projects ADD CONSTRAINT FK_5C93B3A4727ACA70 FOREIGN KEY (parent_id) REFERENCES projects (id)');
}
public function mySQLDown(Schema $schema): void