<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version2025040810000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add description, gedModelName, gedCategory, isOutgoing, isDeleted to document_type table';
}
public function up(Schema $schema): void
{
$this->skipIf($schema->getTable('document_type')->hasColumn('ged_model_name'), 'Table document_type already have ged_model_name column');
$documentTypeTable = $schema->getTable('document_type');
$documentTypeTable->addColumn('ged_category', Types::STRING)->setNotnull(false)->setDefault(null);
$documentTypeTable->addColumn('ged_model_name', Types::STRING)->setNotnull(false)->setDefault(null);
$documentTypeTable->addColumn('description', Types::TEXT)->setNotnull(false)->setDefault(null);
$documentTypeTable->addColumn('is_deleted', Types::BOOLEAN)->setNotnull(true)->setDefault(false);
$documentTypeTable->addColumn('is_outgoing', Types::BOOLEAN)->setNotnull(true)->setDefault(true);
}
public function postUp(Schema $schema): void
{
$this->connection->executeStatement('UPDATE document_type SET ged_model_name = vendor_meta_tag WHERE ged_model_name IS NULL');
}
public function down(Schema $schema): void
{
$this->skipIf(
false === $schema->getTable('document_type')->hasColumn('ged_model_name'),
'The ged_model_name is already removed from the document_type table!'
);
$documentTypeTable = $schema->getTable('document_type');
$documentTypeTable->dropColumn('description');
$documentTypeTable->dropColumn('ged_model_name');
$documentTypeTable->dropColumn('ged_category');
$documentTypeTable->dropColumn('is_outgoing');
$documentTypeTable->dropColumn('is_deleted');
}
}