<?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 Version20180823153923 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 customers_status_history TO customer_status_log');
$this->addSql('ALTER TABLE customer_status_log ENGINE = InnoDB');
$this->addSql('ALTER TABLE customer_status_log CHARACTER SET = utf8mb4');
$this->addSql('ALTER TABLE customer_status_log ADD modified_at DATETIME DEFAULT NULL');
$this->addSql('UPDATE customer_status_log SET modified_at = date_added');
$this->addSql('
ALTER TABLE customer_status_log
DROP notified,
CHANGE customers_id customer_id INT DEFAULT NULL,
CHANGE administrators_id user_id INT DEFAULT NULL,
CHANGE customers_status_id status_id INT DEFAULT NULL,
CHANGE outcome outcome_id INT DEFAULT NULL,
CHANGE comments message LONGTEXT DEFAULT NULL,
CHANGE color color VARCHAR(6) DEFAULT NULL,
CHANGE date_added created_at DATETIME NOT NULL,
CHANGE modified_at modified_at DATETIME NOT NULL
');
$this->addSql('UPDATE customer_status_log SET color = \'0000ff\' WHERE color = \'00a4ec\'');
$this->addSql('UPDATE customer_status_log SET color = \'a020f0\' WHERE color = \'800080\'');
$this->addSql('UPDATE customer_status_log SET color = \'006400\' WHERE color = \'8dad23\'');
$this->addSql('UPDATE customer_status_log SET color = \'ff0000\' WHERE color = \'f00000\'');
$this->addSql('UPDATE customer_status_log SET color = \'eeee00\' WHERE color = \'ffd700\'');
$this->addSql('DROP INDEX idx_customers_id ON customer_status_log');
$this->addSql('DROP INDEX idx_administrators_id ON customer_status_log');
$this->addSql('DROP INDEX idx_customers_status_id ON customer_status_log');
$this->addSql('CREATE INDEX IDX_AC993CE59395C3F3 ON customer_status_log (customer_id)');
$this->addSql('CREATE INDEX IDX_AC993CE5A76ED395 ON customer_status_log (user_id)');
$this->addSql('CREATE INDEX IDX_AC993CE56BF700BD ON customer_status_log (status_id)');
$this->addSql('CREATE INDEX IDX_AC993CE5E6EE6D63 ON customer_status_log (outcome_id)');
$this->addSql('DELETE FROM customer_status_log WHERE customer_id NOT IN (SELECT id FROM customer)');
$this->addSql('UPDATE customer_status_log SET user_id = NULL WHERE user_id NOT IN (SELECT id FROM user)');
$this->addSql('UPDATE customer_status_log SET status_id = NULL WHERE status_id NOT IN (SELECT id FROM customer_status)');
$this->addSql('UPDATE customer_status_log SET outcome_id = NULL WHERE outcome_id NOT IN (SELECT id FROM config_status_outcome)');
$this->addSql('ALTER TABLE customer_status_log ADD CONSTRAINT FK_AC993CE59395C3F3 FOREIGN KEY (customer_id) REFERENCES customer (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE customer_status_log ADD CONSTRAINT FK_AC993CE5A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE customer_status_log ADD CONSTRAINT FK_AC993CE56BF700BD FOREIGN KEY (status_id) REFERENCES customer_status (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE customer_status_log ADD CONSTRAINT FK_AC993CE5E6EE6D63 FOREIGN KEY (outcome_id) REFERENCES config_status_outcome (id) ON DELETE SET NULL');
}
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_status_log DROP FOREIGN KEY FK_AC993CE5E6EE6D63');
$this->addSql('ALTER TABLE customer_status_log DROP FOREIGN KEY FK_AC993CE56BF700BD');
$this->addSql('ALTER TABLE customer_status_log DROP FOREIGN KEY FK_AC993CE5A76ED395');
$this->addSql('ALTER TABLE customer_status_log DROP FOREIGN KEY FK_AC993CE59395C3F3');
$this->addSql('RENAME TABLE customer_status_log TO customers_status_history');
$this->addSql('ALTER TABLE customers_status_history ENGINE = InnoDB');
$this->addSql('ALTER TABLE customers_status_history CHARACTER SET = utf8mb4');
$this->addSql('
ALTER TABLE customers_status_history
DROP modified_at,
ADD notified TINYINT(1) DEFAULT \'0\' AFTER customers_status_id,
CHANGE customer_id customers_id INT NOT NULL,
CHANGE user_id administrators_id INT NOT NULL,
CHANGE status_id customers_status_id INT NOT NULL,
CHANGE outcome_id outcome TINYINT(1) DEFAULT NULL,
CHANGE message comments TEXT DEFAULT NULL,
CHANGE color color VARCHAR(6) DEFAULT NULL,
CHANGE created_at date_added DATETIME DEFAULT NULL
');
$this->addSql('DROP INDEX IDX_AC993CE59395C3F3 ON customers_status_history');
$this->addSql('DROP INDEX IDX_AC993CE5A76ED395 ON customers_status_history');
$this->addSql('DROP INDEX IDX_AC993CE56BF700BD ON customers_status_history');
$this->addSql('DROP INDEX IDX_AC993CE5E6EE6D63 ON customers_status_history');
$this->addSql('CREATE INDEX idx_administrators_id ON customers_status_history (administrators_id)');
$this->addSql('CREATE INDEX idx_customers_id ON customers_status_history (customers_id)');
$this->addSql('CREATE INDEX idx_customers_status_id ON customers_status_history (customers_status_id)');
}
}