addSql('DELETE FROM attachments WHERE class_name = "PartDB\\\\Part" AND NOT EXISTS (SELECT id FROM parts WHERE id = attachments.element_id)'); $this->addSql('DELETE FROM attachments WHERE class_name = "PartDB\\\\Device" AND NOT EXISTS (SELECT id FROM projects WHERE id = attachments.element_id)'); // Replace all attachments where class_name is the legacy "PartDB\Part" with the new version "Part" //We have to use 4 backslashes here, as PHP reduces them to 2 backslashes, which MySQL interprets as an escaped backslash. $this->addSql('UPDATE attachments SET class_name = "Part" WHERE class_name = "PartDB\\\\Part"'); //Do the same with PartDB\Device and Device $this->addSql('UPDATE attachments SET class_name = "Device" WHERE class_name = "PartDB\\\\Device"'); } public function mySQLDown(Schema $schema): void { // We can not revert this migration, because we don't know the old class name. } public function sqLiteUp(Schema $schema): void { //As legacy database can only be migrated to MySQL, we don't need to implement this method. //Dont skip here, as this causes this migration always to be executed. Do nothing instead. } public function sqLiteDown(Schema $schema): void { //As we done nothing, we don't need to implement this method. } }