<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20251117150000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Adds mycmcm_request_category tables with hierarchical structure and document requirements';
}
public function up(Schema $schema): void
{
$this->skipIf(
true === $schema->hasTable('mycmcm_request_category'),
'The mycmcm_request_category table was already created!'
);
// Create mycmcm_request_category table
$table = $schema->createTable('mycmcm_request_category');
$table->addColumn('id', Types::GUID)->setNotnull(true);
$table->addColumn('icon', Types::STRING, ['length' => 80])->setNotnull(false);
$table->addColumn('parent_id', Types::GUID)->setNotnull(false);
$table->setPrimaryKey(['id']);
$table->addForeignKeyConstraint(
'mycmcm_request_category',
['parent_id'],
['id'],
['onDelete' => 'CASCADE'],
'fk_mycmcm_request_category_parent'
);
// Create mycmcm_request_category_translation table
$table = $schema->createTable('mycmcm_request_category_translation');
$table->addColumn('id', Types::GUID)->setNotnull(true);
$table->addColumn('translatable_id', Types::GUID)->setNotnull(true);
$table->addColumn('language', Types::STRING, ['length' => 10])->setNotnull(true);
$table->addColumn('name', Types::STRING, ['length' => 255])->setNotnull(true);
$table->addColumn('description', Types::TEXT)->setNotnull(false);
$table->addColumn('title', Types::STRING, ['length' => 255])->setNotnull(false);
$table->addColumn('note', Types::TEXT)->setNotnull(false);
$table->setPrimaryKey(['id']);
$table->addForeignKeyConstraint(
'mycmcm_request_category',
['translatable_id'],
['id'],
[],
'fk_mycmcm_request_category_translation'
);
// Create mycmcm_request_category_document table
$table = $schema->createTable('mycmcm_request_category_document');
$table->addColumn('id', Types::GUID)->setNotnull(true);
$table->addColumn('category_id', Types::GUID)->setNotnull(true);
$table->addColumn('document_type_id', Types::GUID)->setNotnull(true);
$table->addColumn('is_required', Types::BOOLEAN)->setNotnull(true)->setDefault(false);
$table->addColumn('sort_order', Types::INTEGER)->setNotnull(true)->setDefault(0);
$table->setPrimaryKey(['id']);
$table->addForeignKeyConstraint(
'mycmcm_request_category',
['category_id'],
['id'],
['onDelete' => 'CASCADE'],
'fk_mycmcm_request_category_document_category'
);
$table->addForeignKeyConstraint(
'document_type',
['document_type_id'],
['id'],
[],
'fk_mycmcm_request_category_document_type'
);
// Create mycmcm_request_category_document_translation table
$table = $schema->createTable('mycmcm_request_category_document_translation');
$table->addColumn('id', Types::GUID)->setNotnull(true);
$table->addColumn('translatable_id', Types::GUID)->setNotnull(true);
$table->addColumn('language', Types::STRING, ['length' => 10])->setNotnull(true);
$table->addColumn('name', Types::STRING, ['length' => 255])->setNotnull(true);
$table->addColumn('note', Types::TEXT)->setNotnull(false);
$table->setPrimaryKey(['id']);
$table->addForeignKeyConstraint(
'mycmcm_request_category_document',
['translatable_id'],
['id'],
[],
'fk_mycmcm_request_category_document_translation'
);
}
public function down(Schema $schema): void
{
$this->skipIf(
false === $schema->hasTable('mycmcm_request_category'),
'The mycmcm_request_category table was already removed!'
);
$schema->dropTable('mycmcm_request_category_document_translation');
$schema->dropTable('mycmcm_request_category_document');
$schema->dropTable('mycmcm_request_category_translation');
$schema->dropTable('mycmcm_request_category');
}
}