<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20221103161806 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->skipIf(
true === $schema->hasTable('page'),
'The page table was already created!'
);
$pageTable = $schema->createTable('page');
$pageTable->addColumn('id', Types::GUID)->setNotnull(true);
$pageTable->addColumn('name', Types::STRING, ['length' => 255])->setNotnull(true);
$pageTable->setPrimaryKey(['id']);
$pageTranslationTable = $schema->createTable('page_translation');
$pageTranslationTable->addColumn('id', Types::GUID)->setNotnull(true);
$pageTranslationTable->addColumn('translatable_id', Types::STRING, ['length' => 255])->setNotnull(true);
$pageTranslationTable->addColumn('title', Types::STRING, ['length' => 255])->setNotnull(true);
$pageTranslationTable->addColumn('content', Types::TEXT)->setNotnull(true);
$pageTranslationTable->addColumn('language', Types::STRING, ['length' => 10])->setNotnull(true);
$pageTranslationTable->setPrimaryKey(['id']);
$pageTranslationTable->addForeignKeyConstraint(
$pageTable,
['translatable_id'],
['id'],
[],
'fk_page_page_translation'
);
$pageTranslationTable->addIndex(['translatable_id'], 'idx_page_translation_translatable_id');
}
public function down(Schema $schema): void
{
$this->skipIf(
false === $schema->hasTable('page'),
'The page tables was already removed!'
);
$schema->dropTable('page');
$schema->dropTable('page_translation');
}
}