migrations/Version20221229182400.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. use Ramsey\Uuid\Uuid;
  7. /**
  8.  * Auto-generated Migration: Please modify to your needs!
  9.  */
  10. final class Version20221229182400 extends AbstractMigration
  11. {
  12.     public function getDescription(): string
  13.     {
  14.         return '';
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         // this up() migration is auto-generated, please modify it to your needs
  19.         $this->addSql('CREATE TABLE position (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', name VARCHAR(255) NOT NULL, sort_order INT DEFAULT NULL, created_at DATETIME NOT NULL, modified_at DATETIME NOT NULL, INDEX idx_name (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  20.         $this->addSql('ALTER TABLE user ADD position VARCHAR(255) DEFAULT NULL, ADD bio LONGTEXT DEFAULT NULL, ADD twitter_username VARCHAR(255) DEFAULT NULL, ADD linked_in_username VARCHAR(255) DEFAULT NULL, ADD location VARCHAR(255) DEFAULT NULL');
  21.         $this->addSql('ALTER TABLE workspace ADD website VARCHAR(255) DEFAULT NULL, ADD body LONGTEXT DEFAULT NULL');
  22.         foreach ($this->getPositions() as $index => $position) {
  23.             $now = (new \DateTime())->format('Y-m-d H:i:s');
  24.             $this->addSql('INSERT INTO position (id, name, sort_order, created_at, modified_at) VALUES (:id, :name, :sort_order, :created_at, :modified_at)', [
  25.                 'id' => Uuid::uuid4(),
  26.                 'name' => $position,
  27.                 'sort_order' => $index 1,
  28.                 'created_at' => $now,
  29.                 'modified_at' => $now,
  30.             ]);
  31.         }
  32.     }
  33.     public function down(Schema $schema): void
  34.     {
  35.         // this down() migration is auto-generated, please modify it to your needs
  36.         $this->addSql('DROP TABLE position');
  37.         $this->addSql('ALTER TABLE user DROP position, DROP bio, DROP twitter_username, DROP linked_in_username, DROP location');
  38.         $this->addSql('ALTER TABLE workspace DROP website, DROP body');
  39.     }
  40.     private function getPositions(): array
  41.     {
  42.         return [
  43.             'CEO/Founder',
  44.             'Leadership',
  45.             'Management',
  46.             'Operations',
  47.             'Marketing',
  48.             'Development',
  49.             'Freelance',
  50.             'Finance',
  51.             'Legal',
  52.             'Sales',
  53.             'HR',
  54.             'Other',
  55.         ];
  56.     }
  57. }