migrations/Version20210805143105.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20210805143105 extends AbstractMigration
  10. {
  11.     public function getDescription() : string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema) : void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->addSql("
  19.         ALTER TABLE `std_attributes_values`
  20.         ADD COLUMN `attribute_id` INT(10) UNSIGNED NOT NULL COMMENT 'Attribute unique identifier' AFTER `attribute_machine_name`;
  21.         ");
  22.         $this->addSql("
  23.         UPDATE std_attributes_values av SET av.attribute_id=(SELECT id FROM std_attributes WHERE machine_name =av.attribute_machine_name);
  24.         ");
  25.         $this->addSql("
  26.         ALTER TABLE `std_attributes_values`
  27.         ADD CONSTRAINT `FK_std_attributes_values_std_attributes` FOREIGN KEY (`attribute_id`) REFERENCES `std_attributes` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION;        
  28.         ");
  29.     }
  30.     public function down(Schema $schema) : void
  31.     {
  32.         // this down() migration is auto-generated, please modify it to your needs
  33.         $this->addSql("
  34.         ALTER TABLE `std_attributes_values`
  35.         DROP FOREIGN KEY `FK_std_attributes_values_std_attributes`;
  36.         ");
  37.         $this->addSql("
  38.         ALTER TABLE `std_attributes_values`
  39.         DROP INDEX `FK_std_attributes_values_std_attributes`;
  40.         ");
  41.         $this->addSql("
  42.         ALTER TABLE `std_attributes_values`
  43.         DROP COLUMN `attribute_id`;
  44.         ");
  45.     }
  46. }