addSql('DELETE FROM doctor_expertise WHERE service_id NOT IN (SELECT id FROM doctor_services)'); // Add FK constraint to doctor_expertise $this->addSql('ALTER TABLE doctor_expertise ADD CONSTRAINT FK_ED88BE60ED5CA9E6 FOREIGN KEY (service_id) REFERENCES doctor_services (id)'); $this->addSql('CREATE INDEX IDX_ED88BE60ED5CA9E6 ON doctor_expertise (service_id)'); // doctor_cities: category_id → city_id with FK to cities $this->addSql('DELETE FROM doctor_cities WHERE category_id NOT IN (SELECT id FROM cities)'); $this->addSql('ALTER TABLE doctor_cities DROP FOREIGN KEY `FK_7DC181E612469DE2`'); $this->addSql('DROP INDEX IDX_7DC181E612469DE2 ON doctor_cities'); $this->addSql('ALTER TABLE doctor_cities CHANGE category_id city_id INT NOT NULL, DROP PRIMARY KEY, ADD PRIMARY KEY (doctor_id, city_id)'); $this->addSql('ALTER TABLE doctor_cities ADD CONSTRAINT FK_7DC181E68BAC62AF FOREIGN KEY (city_id) REFERENCES cities (id)'); $this->addSql('CREATE INDEX IDX_7DC181E68BAC62AF ON doctor_cities (city_id)'); // Drop the now-unused categories table $this->addSql('DROP TABLE categories'); } public function down(Schema $schema): void { $this->addSql('ALTER TABLE doctor_expertise DROP FOREIGN KEY FK_ED88BE60ED5CA9E6'); $this->addSql('DROP INDEX IDX_ED88BE60ED5CA9E6 ON doctor_expertise'); $this->addSql('ALTER TABLE doctor_cities DROP FOREIGN KEY FK_7DC181E68BAC62AF'); $this->addSql('DROP INDEX IDX_7DC181E68BAC62AF ON doctor_cities'); $this->addSql('ALTER TABLE doctor_cities CHANGE city_id category_id INT NOT NULL, DROP PRIMARY KEY, ADD PRIMARY KEY (doctor_id, category_id)'); $this->addSql(" CREATE TABLE categories ( id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, bundle VARCHAR(32) NOT NULL, label VARCHAR(255) DEFAULT NULL, status SMALLINT NOT NULL, parent_id INT DEFAULT NULL, weight INT NOT NULL, logo_id INT DEFAULT NULL, title VARCHAR(255) DEFAULT NULL, representation_id INT DEFAULT NULL, contact_phone VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, description LONGTEXT DEFAULT NULL, slogan VARCHAR(255) DEFAULT NULL, domain VARCHAR(255) DEFAULT NULL, keywords VARCHAR(255) DEFAULT NULL, footer_description LONGTEXT DEFAULT NULL, footer_disclaimer LONGTEXT DEFAULT NULL, social_media LONGTEXT DEFAULT NULL, logo_url VARCHAR(500) DEFAULT NULL, PRIMARY KEY (id) ) DEFAULT CHARACTER SET utf8mb4 "); $this->addSql('ALTER TABLE doctor_cities ADD CONSTRAINT `FK_7DC181E612469DE2` FOREIGN KEY (category_id) REFERENCES categories (id)'); $this->addSql('CREATE INDEX IDX_7DC181E612469DE2 ON doctor_cities (category_id)'); } }