migrations/Version20191119045012.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 Version20191119045012 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->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql''Migration can only be executed safely on \'mysql\'.');
  19.         $this->addSql('ALTER TABLE baseProducts ADD thumbnail VARCHAR(255) DEFAULT NULL');
  20.         $this->addSql('ALTER TABLE product ADD thumbnail VARCHAR(255) DEFAULT NULL, ADD image VARCHAR(255) DEFAULT NULL');
  21.         // migrate data here
  22.         $this->addSql('UPDATE baseProducts 
  23.                        LEFT JOIN attachments ON attachments.id=baseProducts.idThumbnail
  24.                        SET baseProducts.thumbnail=attachments.storageName');
  25.         $this->addSql('UPDATE product 
  26.                        LEFT JOIN attachments ON attachments.id=product.idThumbnail
  27.                        SET product.thumbnail=attachments.storageName');
  28.         $this->addSql('UPDATE product 
  29.                        LEFT JOIN attachments ON attachments.id=product.idImage
  30.                        SET product.image=attachments.storageName');
  31.         $this->addSql('ALTER TABLE baseProducts DROP FOREIGN KEY FK_A8260153FBD0DB0');
  32.         $this->addSql('ALTER TABLE product DROP FOREIGN KEY FK_DB3A4D933FBD0DB0');
  33.         $this->addSql('ALTER TABLE product DROP FOREIGN KEY FK_DB3A4D93D2F94742');
  34.         $this->addSql('DROP TABLE attachments');
  35.         $this->addSql('DROP INDEX IDX_A8260153FBD0DB0 ON baseProducts');
  36.         $this->addSql('ALTER TABLE baseProducts DROP idThumbnail');
  37.         $this->addSql('DROP INDEX IDX_D34A04AD3FBD0DB0 ON product');
  38.         $this->addSql('DROP INDEX IDX_D34A04ADD2F94742 ON product');
  39.         $this->addSql('ALTER TABLE product DROP idThumbnail, DROP idImage');
  40.     }
  41.     public function down(Schema $schema): void
  42.     {
  43.         // this down() migration is auto-generated, please modify it to your needs
  44.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql''Migration can only be executed safely on \'mysql\'.');
  45.         $this->addSql('CREATE TABLE attachments (id INT AUTO_INCREMENT NOT NULL, originalName VARCHAR(255) CHARACTER SET utf8 DEFAULT NULL COLLATE `utf8_unicode_ci`, storageName VARCHAR(32) CHARACTER SET utf8 DEFAULT NULL COLLATE `utf8_unicode_ci`, mimeType VARCHAR(32) CHARACTER SET utf8 DEFAULT NULL COLLATE `utf8_unicode_ci`, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
  46.         $this->addSql('ALTER TABLE baseProducts ADD idThumbnail INT DEFAULT NULL, DROP thumbnail');
  47.         $this->addSql('ALTER TABLE baseProducts ADD CONSTRAINT FK_A8260153FBD0DB0 FOREIGN KEY (idThumbnail) REFERENCES attachments (id)');
  48.         $this->addSql('CREATE INDEX IDX_A8260153FBD0DB0 ON baseProducts (idThumbnail)');
  49.         $this->addSql('ALTER TABLE product ADD idThumbnail INT DEFAULT NULL, ADD idImage INT DEFAULT NULL, DROP thumbnail, DROP originalName');
  50.         $this->addSql('ALTER TABLE product ADD CONSTRAINT FK_DB3A4D933FBD0DB0 FOREIGN KEY (idThumbnail) REFERENCES attachments (id)');
  51.         $this->addSql('ALTER TABLE product ADD CONSTRAINT FK_DB3A4D93D2F94742 FOREIGN KEY (idImage) REFERENCES attachments (id)');
  52.         $this->addSql('CREATE INDEX IDX_D34A04AD3FBD0DB0 ON product (idThumbnail)');
  53.         $this->addSql('CREATE INDEX IDX_D34A04ADD2F94742 ON product (idImage)');
  54.     }
  55. }