<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20230605112501 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(
false === $schema->getTable('sport_federation_health_mutual')->hasColumn('federation_id'),
'The federation_id field already removed from the sport_federation_health_mutual table!'
);
$schema->getTable('sport_federation_health_mutual')->dropColumn('federation_id');
$schema->getTable('sport_federation_health_mutual')->getColumn('sport_federation_id')->setNotnull(true);
$schema->getTable('sport_federation_health_mutual')->addForeignKeyConstraint(
'sport_federation',
['sport_federation_id'],
['id'],
[],
'fk_sport_federation_sport_federation_health_mutual'
);
}
public function down(Schema $schema): void
{
$this->skipIf(
true === $schema->getTable('sport_federation_health_mutual')->hasColumn('federation_id'),
'The federation_id is already set in the sport_federation_health_mutual table!'
);
$schema->getTable('sport_federation_health_mutual')
->addColumn('federation_id', Types::STRING, ['notnull' => false, 'length' => 255]);
}
public function postDown(Schema $schema): void
{
$this->connection->executeQuery('UPDATE sport_federation_health_mutual SET federation_id=sport_federation_id');
}
}