<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20251119094112 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add my_cmcm_request_category_id to cmcm_request table';
}
public function up(Schema $schema): void
{
$this->skipIf(
true === $schema->getTable('cmcm_request')->hasColumn('my_cmcm_request_category_id'),
'The my_cmcm_request_category_id column already exists in cmcm_request table!'
);
$table = $schema->getTable('cmcm_request');
$table->addColumn('my_cmcm_request_category_id', Types::STRING)->setNotnull(false);
$table->addForeignKeyConstraint(
'mycmcm_request_category',
['my_cmcm_request_category_id'],
['id'],
['onDelete' => 'SET NULL'],
'fk_cmcm_request_mycmcm_request_category'
);
}
public function down(Schema $schema): void
{
$table = $schema->getTable('cmcm_request');
$table->removeForeignKey('fk_cmcm_request_mycmcm_request_category');
$table->dropColumn('my_cmcm_request_category_id');
}
}