migrations/Version20180823153923.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 Version20180823153923 extends AbstractMigration
  10. {
  11.     public function up(Schema $schema): void
  12.     {
  13.         // this up() migration is auto-generated, please modify it to your needs
  14.         $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
  15.         $this->addSql('RENAME TABLE customers_status_history TO customer_status_log');
  16.         $this->addSql('ALTER TABLE customer_status_log ENGINE = InnoDB');
  17.         $this->addSql('ALTER TABLE customer_status_log CHARACTER SET = utf8mb4');
  18.         $this->addSql('ALTER TABLE customer_status_log ADD modified_at DATETIME DEFAULT NULL');
  19.         $this->addSql('UPDATE customer_status_log SET modified_at = date_added');
  20.         $this->addSql('
  21.             ALTER TABLE customer_status_log
  22.                 DROP notified,
  23.                 CHANGE customers_id customer_id INT DEFAULT NULL,
  24.                 CHANGE administrators_id user_id INT DEFAULT NULL,
  25.                 CHANGE customers_status_id status_id INT DEFAULT NULL,
  26.                 CHANGE outcome outcome_id INT DEFAULT NULL,
  27.                 CHANGE comments message LONGTEXT DEFAULT NULL,
  28.                 CHANGE color color VARCHAR(6) DEFAULT NULL,
  29.                 CHANGE date_added created_at DATETIME NOT NULL,
  30.                 CHANGE modified_at modified_at DATETIME NOT NULL
  31.         ');
  32.         $this->addSql('UPDATE customer_status_log SET color = \'0000ff\' WHERE color = \'00a4ec\'');
  33.         $this->addSql('UPDATE customer_status_log SET color = \'a020f0\' WHERE color = \'800080\'');
  34.         $this->addSql('UPDATE customer_status_log SET color = \'006400\' WHERE color = \'8dad23\'');
  35.         $this->addSql('UPDATE customer_status_log SET color = \'ff0000\' WHERE color = \'f00000\'');
  36.         $this->addSql('UPDATE customer_status_log SET color = \'eeee00\' WHERE color = \'ffd700\'');
  37.         $this->addSql('DROP INDEX idx_customers_id ON customer_status_log');
  38.         $this->addSql('DROP INDEX idx_administrators_id ON customer_status_log');
  39.         $this->addSql('DROP INDEX idx_customers_status_id ON customer_status_log');
  40.         $this->addSql('CREATE INDEX IDX_AC993CE59395C3F3 ON customer_status_log (customer_id)');
  41.         $this->addSql('CREATE INDEX IDX_AC993CE5A76ED395 ON customer_status_log (user_id)');
  42.         $this->addSql('CREATE INDEX IDX_AC993CE56BF700BD ON customer_status_log (status_id)');
  43.         $this->addSql('CREATE INDEX IDX_AC993CE5E6EE6D63 ON customer_status_log (outcome_id)');
  44.         $this->addSql('DELETE FROM customer_status_log WHERE customer_id NOT IN (SELECT id FROM customer)');
  45.         $this->addSql('UPDATE customer_status_log SET user_id = NULL WHERE user_id NOT IN (SELECT id FROM user)');
  46.         $this->addSql('UPDATE customer_status_log SET status_id = NULL WHERE status_id NOT IN (SELECT id FROM customer_status)');
  47.         $this->addSql('UPDATE customer_status_log SET outcome_id = NULL WHERE outcome_id NOT IN (SELECT id FROM config_status_outcome)');
  48.         $this->addSql('ALTER TABLE customer_status_log ADD CONSTRAINT FK_AC993CE59395C3F3 FOREIGN KEY (customer_id) REFERENCES customer (id) ON DELETE CASCADE');
  49.         $this->addSql('ALTER TABLE customer_status_log ADD CONSTRAINT FK_AC993CE5A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE SET NULL');
  50.         $this->addSql('ALTER TABLE customer_status_log ADD CONSTRAINT FK_AC993CE56BF700BD FOREIGN KEY (status_id) REFERENCES customer_status (id) ON DELETE SET NULL');
  51.         $this->addSql('ALTER TABLE customer_status_log ADD CONSTRAINT FK_AC993CE5E6EE6D63 FOREIGN KEY (outcome_id) REFERENCES config_status_outcome (id) ON DELETE SET NULL');
  52.     }
  53.     public function down(Schema $schema): void
  54.     {
  55.         // this down() migration is auto-generated, please modify it to your needs
  56.         $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
  57.         $this->addSql('ALTER TABLE customer_status_log DROP FOREIGN KEY FK_AC993CE5E6EE6D63');
  58.         $this->addSql('ALTER TABLE customer_status_log DROP FOREIGN KEY FK_AC993CE56BF700BD');
  59.         $this->addSql('ALTER TABLE customer_status_log DROP FOREIGN KEY FK_AC993CE5A76ED395');
  60.         $this->addSql('ALTER TABLE customer_status_log DROP FOREIGN KEY FK_AC993CE59395C3F3');
  61.         $this->addSql('RENAME TABLE customer_status_log TO customers_status_history');
  62.         $this->addSql('ALTER TABLE customers_status_history ENGINE = InnoDB');
  63.         $this->addSql('ALTER TABLE customers_status_history CHARACTER SET = utf8mb4');
  64.         $this->addSql('
  65.             ALTER TABLE customers_status_history
  66.                 DROP modified_at,
  67.                 ADD notified TINYINT(1) DEFAULT \'0\' AFTER customers_status_id,
  68.                 CHANGE customer_id customers_id INT NOT NULL,
  69.                 CHANGE user_id administrators_id INT NOT NULL,
  70.                 CHANGE status_id customers_status_id INT NOT NULL,
  71.                 CHANGE outcome_id outcome TINYINT(1) DEFAULT NULL,
  72.                 CHANGE message comments TEXT DEFAULT NULL,
  73.                 CHANGE color color VARCHAR(6) DEFAULT NULL,
  74.                 CHANGE created_at date_added DATETIME DEFAULT NULL
  75.         ');
  76.         $this->addSql('DROP INDEX IDX_AC993CE59395C3F3 ON customers_status_history');
  77.         $this->addSql('DROP INDEX IDX_AC993CE5A76ED395 ON customers_status_history');
  78.         $this->addSql('DROP INDEX IDX_AC993CE56BF700BD ON customers_status_history');
  79.         $this->addSql('DROP INDEX IDX_AC993CE5E6EE6D63 ON customers_status_history');
  80.         $this->addSql('CREATE INDEX idx_administrators_id ON customers_status_history (administrators_id)');
  81.         $this->addSql('CREATE INDEX idx_customers_id ON customers_status_history (customers_id)');
  82.         $this->addSql('CREATE INDEX idx_customers_status_id ON customers_status_history (customers_status_id)');
  83.     }
  84. }