<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20230127153600 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add affiliate_number to ticket';
}
public function up(Schema $schema): void
{
$this->skipIf(
true === $schema->getTable('ticket')->hasColumn('affiliate_number'),
'The affiliate_number field already exists in the ticket table!'
);
$table = $schema->getTable('ticket');
$table
->addColumn('my_cmcm_user_id', Types::STRING)
->setNotnull(false);
$table
->addColumn('affiliate_number', Types::STRING, ['length' => 255])
->setNotnull(false);
$table
->addColumn('device_id', Types::STRING, ['length' => 255])
->setNotnull(false);
$table->addIndex(['my_cmcm_user_id'], 'idx_ticket_my_cmcm_user_id');
$table->addIndex(['affiliate_number'], 'idx_ticket_affiliate_number');
$table->addIndex(['device_id'], 'idx_ticket_device_id');
$table
->addForeignKeyConstraint(
'mycmcm_user',
['my_cmcm_user_id'],
['id'],
[],
'fk_mycmcm_user_ticket'
);
}
public function down(Schema $schema): void
{
$this->skipIf(
false === $schema->getTable('ticket')->hasColumn('affiliate_number'),
'The affiliate_number is already removed from the ticket table!'
);
$schema->getTable('ticket')
->dropColumn('affiliate_number')
->dropColumn('device_id')
->dropColumn('my_cmcm_user');
}
}