migrations/Version20210607135529.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 Version20210607135529 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'Migration fuji, discriminants';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $this->addSql('SET foreign_key_checks = 0');
  18.         //Tables  creations
  19.         $this->addSql('CREATE TABLE details_operation (id CHAR(36) NOT NULL, object_id CHAR(36) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, discr VARCHAR(255) NOT NULL, INDEX IDX_6381AAB6232D562B (object_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  20.         $this->addSql('CREATE TABLE details_participation (id CHAR(36) NOT NULL, participation_id CHAR(36) DEFAULT NULL, amount DOUBLE PRECISION NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, discr VARCHAR(255) NOT NULL, INDEX IDX_E3CABD916ACE3B73 (participation_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  21.         $this->addSql('CREATE TABLE ean_participation (id CHAR(36) NOT NULL, ean_id CHAR(36) DEFAULT NULL, participation_id CHAR(36) DEFAULT NULL, quantity INT NOT NULL, validated_amount DOUBLE PRECISION DEFAULT NULL, barcode_status VARCHAR(1) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, discr VARCHAR(255) NOT NULL, INDEX IDX_A37ED019F50FDA5 (ean_id), INDEX IDX_A37ED0196ACE3B73 (participation_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  22.         //Tables updates
  23.         $this->addSql('ALTER TABLE details_operation ADD CONSTRAINT FK_6381AAB6232D562B FOREIGN KEY (object_id) REFERENCES operation (id)');
  24.         $this->addSql('ALTER TABLE details_participation ADD CONSTRAINT FK_E3CABD916ACE3B73 FOREIGN KEY (participation_id) REFERENCES participation (id)');
  25.         $this->addSql('ALTER TABLE ean_participation ADD CONSTRAINT FK_A37ED019F50FDA5 FOREIGN KEY (ean_id) REFERENCES ean (id)');
  26.         $this->addSql('ALTER TABLE ean_participation ADD CONSTRAINT FK_A37ED0196ACE3B73 FOREIGN KEY (participation_id) REFERENCES participation (id)');
  27.         $this->addSql('ALTER TABLE ean CHANGE details_step_id details_operation_id CHAR(36) DEFAULT NULL');
  28.         $this->addSql('ALTER TABLE ean DROP CONSTRAINT FK_67B1C66095E1678D');
  29.         $this->addSql('DROP INDEX IDX_67B1C66095E1678D ON ean');
  30.         $this->addSql('ALTER TABLE ean ADD CONSTRAINT FK_67B1C66069C5A024 FOREIGN KEY (details_operation_id) REFERENCES details_operation (id)');
  31.         $this->addSql('CREATE INDEX IDX_67B1C66069C5A024 ON ean (details_operation_id)');
  32.         //Data migrations
  33.         $this->addSql('INSERT INTO `details_participation` SELECT `id`, `participation_id`, `amount`, `created_at`, `updated_at`, "details_step" FROM `details_participation_step`');
  34.         $this->addSql('INSERT INTO `details_operation` SELECT `id`, `step_id` AS `object_id`, `created_at`, `updated_at`, "details_step" FROM `details_step`');
  35.         $this->addSql('INSERT INTO `ean_participation` SELECT `id`, `ean_id`, `participation_step_id` AS `participation_id`, `quantity`, `validated_amount`, `barcode_status`, `created_at`, `updated_at`, "ean_step" FROM `ean_step`');
  36.         $this->addSql('SET foreign_key_checks = 1');
  37.     }
  38.     public function down(Schema $schema): void
  39.     {
  40.     }
  41. }