migrations/Version20191118184352.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 Version20191118184352 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
  19.         $this->addSql('CREATE TABLE customer_phase (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, sort_order INT DEFAULT NULL, fault TINYINT(1) NOT NULL, INDEX idx_name (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
  20.         $this->addSql('ALTER TABLE customer ADD phase_id INT DEFAULT NULL');
  21.         $this->addSql('ALTER TABLE customer ADD CONSTRAINT FK_81398E0999091188 FOREIGN KEY (phase_id) REFERENCES customer_phase (id) ON DELETE SET NULL');
  22.         $this->addSql('CREATE INDEX IDX_81398E0999091188 ON customer (phase_id)');
  23.         $this->addSql('
  24.             INSERT INTO customer_phase (id, name, sort_order, fault)
  25.             VALUES
  26.                 (1, \'Archive\', 1, 0),
  27.                 (2, \'New\', 2, 1),
  28.                 (3, \'Follow-up\', 3, 0),
  29.                 (4, \'Interested\', 4, 0),
  30.                 (5, \'Waiting\', 5, 0),
  31.                 (6, \'Docs Signed\', 6, 0),
  32.                 (7, \'Sold\', 7, 0)
  33.         ');
  34.         $this->addSql('UPDATE customer SET phase_id = 2 WHERE status_id = 1'); // Interview
  35.     }
  36.     public function down(Schema $schema): void
  37.     {
  38.         // this down() migration is auto-generated, please modify it to your needs
  39.         $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
  40.         $this->addSql('ALTER TABLE customer DROP FOREIGN KEY FK_81398E0999091188');
  41.         $this->addSql('DROP TABLE customer_phase');
  42.         $this->addSql('DROP INDEX IDX_81398E0999091188 ON customer');
  43.         $this->addSql('ALTER TABLE customer DROP phase_id');
  44.     }
  45. }