<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20191119045012 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE baseProducts ADD thumbnail VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE product ADD thumbnail VARCHAR(255) DEFAULT NULL, ADD image VARCHAR(255) DEFAULT NULL');
// migrate data here
$this->addSql('UPDATE baseProducts
LEFT JOIN attachments ON attachments.id=baseProducts.idThumbnail
SET baseProducts.thumbnail=attachments.storageName');
$this->addSql('UPDATE product
LEFT JOIN attachments ON attachments.id=product.idThumbnail
SET product.thumbnail=attachments.storageName');
$this->addSql('UPDATE product
LEFT JOIN attachments ON attachments.id=product.idImage
SET product.image=attachments.storageName');
$this->addSql('ALTER TABLE baseProducts DROP FOREIGN KEY FK_A8260153FBD0DB0');
$this->addSql('ALTER TABLE product DROP FOREIGN KEY FK_DB3A4D933FBD0DB0');
$this->addSql('ALTER TABLE product DROP FOREIGN KEY FK_DB3A4D93D2F94742');
$this->addSql('DROP TABLE attachments');
$this->addSql('DROP INDEX IDX_A8260153FBD0DB0 ON baseProducts');
$this->addSql('ALTER TABLE baseProducts DROP idThumbnail');
$this->addSql('DROP INDEX IDX_D34A04AD3FBD0DB0 ON product');
$this->addSql('DROP INDEX IDX_D34A04ADD2F94742 ON product');
$this->addSql('ALTER TABLE product DROP idThumbnail, DROP idImage');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$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 = \'\' ');
$this->addSql('ALTER TABLE baseProducts ADD idThumbnail INT DEFAULT NULL, DROP thumbnail');
$this->addSql('ALTER TABLE baseProducts ADD CONSTRAINT FK_A8260153FBD0DB0 FOREIGN KEY (idThumbnail) REFERENCES attachments (id)');
$this->addSql('CREATE INDEX IDX_A8260153FBD0DB0 ON baseProducts (idThumbnail)');
$this->addSql('ALTER TABLE product ADD idThumbnail INT DEFAULT NULL, ADD idImage INT DEFAULT NULL, DROP thumbnail, DROP originalName');
$this->addSql('ALTER TABLE product ADD CONSTRAINT FK_DB3A4D933FBD0DB0 FOREIGN KEY (idThumbnail) REFERENCES attachments (id)');
$this->addSql('ALTER TABLE product ADD CONSTRAINT FK_DB3A4D93D2F94742 FOREIGN KEY (idImage) REFERENCES attachments (id)');
$this->addSql('CREATE INDEX IDX_D34A04AD3FBD0DB0 ON product (idThumbnail)');
$this->addSql('CREATE INDEX IDX_D34A04ADD2F94742 ON product (idImage)');
}
}