migrations/Version20250728105738.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 Version20250728105738 extends AbstractMigration
  8. {
  9.     public function getDescription(): string
  10.     {
  11.         return 'Add my_cmcm_user_id column to inquiry table';
  12.     }
  13.     public function up(Schema $schema): void
  14.     {
  15.         $this->skipIf(
  16.             $schema->getTable('inquiry')->hasColumn('my_cmcm_user_id'),
  17.             'The my_cmcm_user_id column already exists in the inquiry table'
  18.         );
  19.         $table $schema->getTable('inquiry');
  20.         $table->addColumn('my_cmcm_user_id'Types::STRING)
  21.             ->setLength(255)
  22.             ->setNotnull(false)
  23.             ->setDefault(null);
  24.         $table->addForeignKeyConstraint(
  25.             'mycmcm_user',
  26.             ['my_cmcm_user_id'],
  27.             ['id'],
  28.             ['onDelete' => 'SET NULL'],
  29.             'fk_inquiry_mycmcm_user'
  30.         );
  31.     }
  32.     public function down(Schema $schema): void
  33.     {
  34.         $this->skipIf(
  35.             !$schema->getTable('inquiry')->hasColumn('my_cmcm_user_id'),
  36.             'The my_cmcm_user_id column does not exist in the inquiry table'
  37.         );
  38.         $table $schema->getTable('inquiry');
  39.         // Drop the foreign key constraint first
  40.         if ($table->hasForeignKey('fk_inquiry_mycmcm_user')) {
  41.             $table->removeForeignKey('fk_inquiry_mycmcm_user');
  42.         }
  43.         // Then drop the column
  44.         $table->dropColumn('my_cmcm_user_id');
  45.     }
  46. }