<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20230605112500 extends AbstractMigration
{
public function getDescription(): string
{
return 'Rename federation_id to sport_federation_id in relation table sport_federation_health_mutual';
}
public function up(Schema $schema): void
{
$this->skipIf(
true === $schema->getTable('sport_federation_health_mutual')->hasColumn('sport_federation_id'),
'The sport_federation_id column already exist in sport_federation_health_mutual table!'
);
$schema->getTable('sport_federation_health_mutual')
->addColumn('sport_federation_id', Types::STRING, ['notnull' => false, 'length' => 255]);
}
public function postUp(Schema $schema): void
{
$this->connection->executeQuery('UPDATE sport_federation_health_mutual SET sport_federation_id=federation_id');
}
public function down(Schema $schema): void
{
$this->skipIf(
false === $schema->getTable('sport_federation_health_mutual')->hasColumn('sport_federation_id'),
'The sport_federation_id is already removed from the sport_federation_health_mutual table!'
);
$schema->getTable('sport_federation_health_mutual')->dropColumn('sport_federation_id');
$schema->getTable('sport_federation_health_mutual')->getColumn('federation_id')->setNotnull(true);
$schema->getTable('sport_federation_health_mutual')->addForeignKeyConstraint(
'sport_federation',
['federation_id'],
['id'],
[],
'fk_sport_federation_federation_health_mutual'
);
}
}