addSql(<<<'SQL' DELETE FROM bovin_shipment bs USING ( SELECT id, ROW_NUMBER() OVER (PARTITION BY shipment_id ORDER BY id DESC) AS rn FROM bovin_shipment WHERE shipment_id IS NOT NULL ) d WHERE bs.id = d.id AND d.rn > 1 SQL); $this->addSql('DROP INDEX IF EXISTS uniq_bovin_shipment'); $this->addSql('CREATE UNIQUE INDEX uniq_bovin_shipment_one_type ON bovin_shipment (shipment_id)'); } public function down(Schema $schema): void { $this->addSql('DROP INDEX IF EXISTS uniq_bovin_shipment_one_type'); $this->addSql('CREATE UNIQUE INDEX uniq_bovin_shipment ON bovin_shipment (shipment_id, shipment_type_id)'); } }