migrations/Version20251119094112.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 Version20251119094112 extends AbstractMigration
  8. {
  9.     public function getDescription(): string
  10.     {
  11.         return 'Add my_cmcm_request_category_id to cmcm_request table';
  12.     }
  13.     public function up(Schema $schema): void
  14.     {
  15.         $this->skipIf(
  16.             true === $schema->getTable('cmcm_request')->hasColumn('my_cmcm_request_category_id'),
  17.             'The my_cmcm_request_category_id column already exists in cmcm_request table!'
  18.         );
  19.         $table $schema->getTable('cmcm_request');
  20.         $table->addColumn('my_cmcm_request_category_id'Types::STRING)->setNotnull(false);
  21.         $table->addForeignKeyConstraint(
  22.             'mycmcm_request_category',
  23.             ['my_cmcm_request_category_id'],
  24.             ['id'],
  25.             ['onDelete' => 'SET NULL'],
  26.             'fk_cmcm_request_mycmcm_request_category'
  27.         );
  28.     }
  29.     public function down(Schema $schema): void
  30.     {
  31.         $table $schema->getTable('cmcm_request');
  32.         $table->removeForeignKey('fk_cmcm_request_mycmcm_request_category');
  33.         $table->dropColumn('my_cmcm_request_category_id');
  34.     }
  35. }