migrations/Version20241204120000.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\DBAL\Types\Types;
  6. use Doctrine\Migrations\AbstractMigration;
  7. final class Version20241204120000 extends AbstractMigration
  8. {
  9.     public function getDescription(): string
  10.     {
  11.         return 'Add auth_code to employee table';
  12.     }
  13.     public function up(Schema $schema): void
  14.     {
  15.         $this->skipIf(
  16.             true === $schema->getTable('employee')->hasColumn('auth_code'),
  17.             'The auth_code field already exists in the employee table!'
  18.         );
  19.         $employeeTable $schema->getTable('employee');
  20.         $employeeTable->addColumn('auth_code'Types::STRING)->setLength(255)->setNotnull(false)->setDefault(null);
  21.         $employeeTable->addColumn('auth_code_created_at'Types::DATETIME_IMMUTABLE)->setNotnull(false)->setDefault(null);
  22.     }
  23.     public function down(Schema $schema): void
  24.     {
  25.         $this->skipIf(
  26.             false === $schema->getTable('employee')->hasColumn('auth_code'),
  27.             'The auth_code is already removed from the employee table!'
  28.         );
  29.         $employeeTable $schema->getTable('employee');
  30.         $employeeTable->dropColumn('auth_code');
  31.         $employeeTable->dropColumn('auth_code_created_at');
  32.     }
  33. }