<?php
declare(strict_types=1);
namespace Boldr\Cms\CmsBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Boldr\Cms\CmsBundle\BoldrCmsMigration;
final class Version1__13_0 extends BoldrCmsMigration
{
public function getBundle(): string { return 'boldr/cms-bundle'; }
public function getVersion(): ?string { return '1.13.0'; }
public function up(Schema $schema): void
{
// Rename attachment to upload in table names and field names
$this->addSql('RENAME TABLE cms_attachment TO cms_upload');
$this->addSql('RENAME TABLE cms_attachment_folder TO cms_upload_folder');
$this->addSql('RENAME TABLE cms_attachment_translation TO cms_upload_translation');
$this->addSql('RENAME TABLE cms_attachment_folder_attachment TO cms_upload_folder_upload');
$this->addSql('ALTER TABLE cms_upload_folder_upload CHANGE attachment_id upload_id INT UNSIGNED NOT NULL');
$this->addSql('ALTER TABLE cms_upload_folder_upload CHANGE attachment_folder_id upload_folder_id INT UNSIGNED NOT NULL');
$this->addSql('ALTER TABLE cms_upload_translation CHANGE attachment_id upload_id INT UNSIGNED NOT NULL');
// Rename indices
$this->addSql('ALTER TABLE cms_upload_folder_upload DROP FOREIGN KEY FK_EDAB6295464E68B');
$this->addSql('ALTER TABLE cms_upload_folder_upload DROP FOREIGN KEY FK_EDAB629560F4EB61');
$this->addSql('DROP INDEX idx_edab6295464e68b ON cms_upload_folder_upload');
$this->addSql('CREATE INDEX IDX_9F749ABECCCFBA31 ON cms_upload_folder_upload (upload_id)');
$this->addSql('DROP INDEX idx_edab629560f4eb61 ON cms_upload_folder_upload');
$this->addSql('CREATE INDEX IDX_9F749ABE2BB35B6D ON cms_upload_folder_upload (upload_folder_id)');
$this->addSql('ALTER TABLE cms_upload_folder_upload ADD CONSTRAINT FK_EDAB6295464E68B FOREIGN KEY (upload_id) REFERENCES cms_upload (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE cms_upload_folder_upload ADD CONSTRAINT FK_EDAB629560F4EB61 FOREIGN KEY (upload_folder_id) REFERENCES cms_upload_folder (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE cms_upload_translation DROP FOREIGN KEY FK_C5C14BFF464E68B');
$this->addSql('DROP INDEX idx_c5c14bff464e68b ON cms_upload_translation');
$this->addSql('CREATE INDEX IDX_EAAC1044CCCFBA31 ON cms_upload_translation (upload_id)');
$this->addSql('ALTER TABLE cms_upload_translation ADD CONSTRAINT FK_C5C14BFF464E68B FOREIGN KEY (upload_id) REFERENCES cms_upload (id)');
// Create cms_upload_track
$this->addSql('CREATE TABLE cms_upload_track (id INT UNSIGNED AUTO_INCREMENT NOT NULL, upload_id INT UNSIGNED NOT NULL, document_id INT UNSIGNED NOT NULL, locale VARCHAR(10) NOT NULL, type VARCHAR(255) NOT NULL, label VARCHAR(255) NOT NULL, INDEX IDX_7E9D42C3CCCFBA31 (upload_id), INDEX IDX_7E9D42C3C33F7837 (document_id), PRIMARY KEY(id)) ENGINE = InnoDB');
$this->addSql('ALTER TABLE cms_upload_track ADD CONSTRAINT FK_7E9D42C3CCCFBA31 FOREIGN KEY (upload_id) REFERENCES cms_upload (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE cms_upload_track ADD CONSTRAINT FK_7E9D42C3C33F7837 FOREIGN KEY (document_id) REFERENCES cms_upload (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE cms_upload CHANGE attachment public_name VARCHAR(255) NOT NULL, ADD type SMALLINT DEFAULT 3 NOT NULL, ADD width INT DEFAULT NULL, ADD height INT DEFAULT NULL, CHANGE size size INT DEFAULT NULL, ADD derivatives JSON DEFAULT NULL, ADD enqueued_derivatives JSON DEFAULT NULL, CHANGE path storage_identifier VARCHAR(255) NOT NULL');
$this->addSql('UPDATE cms_upload SET `type` = 0 WHERE mime_type LIKE \'image/%\'');
$this->addSql('UPDATE cms_upload SET `type` = 0, mime_type = \'image/svg+xml\' WHERE public_name LIKE \'%.svg\'');
$this->addSql('UPDATE cms_upload SET `type` = 1 WHERE mime_type LIKE \'video/%\'');
$this->addSql('UPDATE cms_upload SET `type` = 2 WHERE mime_type LIKE \'audio/%\'');
}
}