migrations/Version20230605112500.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 Version20230605112500 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.             true === $schema->getTable('sport_federation_health_mutual')->hasColumn('sport_federation_id'),
  17.             'The sport_federation_id column already exist in sport_federation_health_mutual table!'
  18.         );
  19.         $schema->getTable('sport_federation_health_mutual')
  20.             ->addColumn('sport_federation_id'Types::STRING, ['notnull' => false'length' => 255]);
  21.     }
  22.     public function postUp(Schema $schema): void
  23.     {
  24.         $this->connection->executeQuery('UPDATE sport_federation_health_mutual SET sport_federation_id=federation_id');
  25.     }
  26.     public function down(Schema $schema): void
  27.     {
  28.         $this->skipIf(
  29.             false === $schema->getTable('sport_federation_health_mutual')->hasColumn('sport_federation_id'),
  30.             'The sport_federation_id is already removed from the sport_federation_health_mutual table!'
  31.         );
  32.         $schema->getTable('sport_federation_health_mutual')->dropColumn('sport_federation_id');
  33.         $schema->getTable('sport_federation_health_mutual')->getColumn('federation_id')->setNotnull(true);
  34.         $schema->getTable('sport_federation_health_mutual')->addForeignKeyConstraint(
  35.             'sport_federation',
  36.             ['federation_id'],
  37.             ['id'],
  38.             [],
  39.             'fk_sport_federation_federation_health_mutual'
  40.         );
  41.     }
  42. }