<?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 Version20180821162559 extends AbstractMigration
{
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('RENAME TABLE documents_log TO customer_document_log');
$this->addSql('ALTER TABLE customer_document_log ENGINE = InnoDB');
$this->addSql('ALTER TABLE customer_document_log CHARACTER SET = utf8mb4');
$this->addSql('
ALTER TABLE customer_document_log
CHANGE customers_id customer_id INT DEFAULT NULL,
CHANGE administrators_id user_id INT DEFAULT NULL,
CHANGE documents_id document_id INT DEFAULT NULL,
CHANGE request_id token VARCHAR(255) NOT NULL,
CHANGE sent_via sent_via VARCHAR(255) DEFAULT NULL,
CHANGE date_added created_at DATETIME NOT NULL
');
$this->addSql('UPDATE customer_document_log SET sent_via = \'email\' WHERE sent_via = \'Email\'');
$this->addSql('UPDATE customer_document_log SET sent_via = \'text\' WHERE sent_via = \'Text\'');
$this->addSql('ALTER TABLE customer_document_log CHANGE sent_via sent_via ENUM(\'email\', \'text\') DEFAULT NULL COMMENT \'(DC2Type:SentViaType)\'');
$this->addSql('DROP INDEX idx_customers_id ON customer_document_log');
$this->addSql('DROP INDEX idx_administrators_id ON customer_document_log');
$this->addSql('DROP INDEX idx_documents ON customer_document_log');
$this->addSql('CREATE INDEX IDX_524D59389395C3F3 ON customer_document_log (customer_id)');
$this->addSql('CREATE INDEX IDX_524D5938A76ED395 ON customer_document_log (user_id)');
$this->addSql('CREATE INDEX IDX_524D5938C33F7837 ON customer_document_log (document_id)');
$this->addSql('CREATE INDEX idx_token ON customer_document_log (token)');
$this->addSql('DELETE FROM customer_document_log WHERE customer_id NOT IN (SELECT id FROM customer)');
$this->addSql('UPDATE customer_document_log SET user_id = NULL WHERE user_id NOT IN (SELECT id FROM user)');
$this->addSql('DELETE FROM customer_document_log WHERE document_id NOT IN (SELECT id FROM config_document)');
$this->addSql('ALTER TABLE customer_document_log ADD CONSTRAINT FK_524D59389395C3F3 FOREIGN KEY (customer_id) REFERENCES customer (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE customer_document_log ADD CONSTRAINT FK_524D5938A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE customer_document_log ADD CONSTRAINT FK_524D5938C33F7837 FOREIGN KEY (document_id) REFERENCES config_document (id) ON DELETE CASCADE');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE customer_document_log DROP FOREIGN KEY FK_524D5938C33F7837');
$this->addSql('ALTER TABLE customer_document_log DROP FOREIGN KEY FK_524D5938A76ED395');
$this->addSql('ALTER TABLE customer_document_log DROP FOREIGN KEY FK_524D59389395C3F3');
$this->addSql('RENAME TABLE customer_document_log TO documents_log');
$this->addSql('ALTER TABLE documents_log ENGINE = InnoDB');
$this->addSql('ALTER TABLE documents_log CHARACTER SET = utf8mb4');
$this->addSql('
ALTER TABLE documents_log
CHANGE customer_id customers_id INT NOT NULL,
CHANGE user_id administrators_id INT NOT NULL,
CHANGE document_id documents_id INT NOT NULL,
CHANGE token request_id VARCHAR(32) NOT NULL DEFAULT \'\',
CHANGE sent_via sent_via VARCHAR(255) DEFAULT NULL,
CHANGE created_at date_added DATETIME DEFAULT NULL
');
$this->addSql('UPDATE documents_log SET sent_via = \'Email\' WHERE sent_via = \'email\'');
$this->addSql('UPDATE documents_log SET sent_via = \'Text\' WHERE sent_via = \'text\'');
$this->addSql('ALTER TABLE documents_log CHANGE sent_via sent_via ENUM(\'Email\', \'Text\') DEFAULT \'Email\'');
$this->addSql('DROP INDEX IDX_524D59389395C3F3 ON documents_log');
$this->addSql('DROP INDEX IDX_524D5938A76ED395 ON documents_log');
$this->addSql('DROP INDEX IDX_524D5938C33F7837 ON documents_log');
$this->addSql('DROP INDEX idx_token ON documents_log');
$this->addSql('CREATE INDEX idx_documents ON documents_log (documents_id)');
$this->addSql('CREATE INDEX idx_administrators_id ON documents_log (administrators_id)');
$this->addSql('CREATE INDEX idx_customers_id ON documents_log (customers_id)');
}
}