migrations/Version20230605112501.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\Migrations\AbstractMigration;
  7. final class Version20230605112501 extends AbstractMigration
  8. {
  9.     public function getDescription(): string
  10.     {
  11.         return 'Rename federation_id to sport_federation_id in relation table sport_federation_health_mutual';
  12.     }
  13.     public function up(Schema $schema): void
  14.     {
  15.         $this->skipIf(
  16.             false === $schema->getTable('sport_federation_health_mutual')->hasColumn('federation_id'),
  17.             'The federation_id field already removed from the sport_federation_health_mutual table!'
  18.         );
  19.         $schema->getTable('sport_federation_health_mutual')->dropColumn('federation_id');
  20.         $schema->getTable('sport_federation_health_mutual')->getColumn('sport_federation_id')->setNotnull(true);
  21.         $schema->getTable('sport_federation_health_mutual')->addForeignKeyConstraint(
  22.             'sport_federation',
  23.             ['sport_federation_id'],
  24.             ['id'],
  25.             [],
  26.             'fk_sport_federation_sport_federation_health_mutual'
  27.         );
  28.     }
  29.     public function down(Schema $schema): void
  30.     {
  31.         $this->skipIf(
  32.             true === $schema->getTable('sport_federation_health_mutual')->hasColumn('federation_id'),
  33.             'The federation_id is already set in the sport_federation_health_mutual table!'
  34.         );
  35.         $schema->getTable('sport_federation_health_mutual')
  36.             ->addColumn('federation_id'Types::STRING, ['notnull' => false'length' => 255]);
  37.     }
  38.     public function postDown(Schema $schema): void
  39.     {
  40.         $this->connection->executeQuery('UPDATE sport_federation_health_mutual SET federation_id=sport_federation_id');
  41.     }
  42. }