<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20230116130712 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add status to ticket';
}
public function up(Schema $schema): void
{
$this->skipIf(
true === $schema->getTable('ticket')->hasColumn('status'),
'The status field already exists in the ticket table!'
);
$schema->getTable('ticket')
->addColumn('status', Types::STRING, ['length' => 20])
->setNotnull(false);
}
public function postUp(Schema $schema): void
{
$this->connection->executeQuery(
"UPDATE ticket set status='new'"
);
}
public function down(Schema $schema): void
{
$this->skipIf(
false === $schema->getTable('ticket')->hasColumn('status'),
'The status is already removed from the ticket table!'
);
$schema->getTable('ticket')
->dropColumn('status');
}
}