<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20250728105738 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add my_cmcm_user_id column to inquiry table';
}
public function up(Schema $schema): void
{
$this->skipIf(
$schema->getTable('inquiry')->hasColumn('my_cmcm_user_id'),
'The my_cmcm_user_id column already exists in the inquiry table'
);
$table = $schema->getTable('inquiry');
$table->addColumn('my_cmcm_user_id', Types::STRING)
->setLength(255)
->setNotnull(false)
->setDefault(null);
$table->addForeignKeyConstraint(
'mycmcm_user',
['my_cmcm_user_id'],
['id'],
['onDelete' => 'SET NULL'],
'fk_inquiry_mycmcm_user'
);
}
public function down(Schema $schema): void
{
$this->skipIf(
!$schema->getTable('inquiry')->hasColumn('my_cmcm_user_id'),
'The my_cmcm_user_id column does not exist in the inquiry table'
);
$table = $schema->getTable('inquiry');
// Drop the foreign key constraint first
if ($table->hasForeignKey('fk_inquiry_mycmcm_user')) {
$table->removeForeignKey('fk_inquiry_mycmcm_user');
}
// Then drop the column
$table->dropColumn('my_cmcm_user_id');
}
}