migrations/Version20230316124700.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 Version20230316124700 extends AbstractMigration
  8. {
  9.     public function getDescription(): string
  10.     {
  11.         return 'Add payment_frequency field to the member_application table';
  12.     }
  13.     public function up(Schema $schema): void
  14.     {
  15.         $this->skipIf(
  16.             true === $schema->getTable('member_application')->hasColumn('payment_frequency'),
  17.             'The payment_frequency field already exists in the member_application table!'
  18.         );
  19.         $schema->getTable('member_application')
  20.             ->addColumn('payment_frequency'Types::STRING, [
  21.                 'length' => 30,
  22.             ])
  23.             ->setNotnull(false);
  24.     }
  25.     public function postUp(Schema $schema): void
  26.     {
  27.         $this->connection->executeQuery('UPDATE member_application SET payment_frequency="annual"');
  28.     }
  29.     public function down(Schema $schema): void
  30.     {
  31.         $this->skipIf(
  32.             false === $schema->getTable('member_application')->hasColumn('payment_frequency'),
  33.             'The payment_frequency is already removed from the member_application table!'
  34.         );
  35.         $schema->getTable('member_application')
  36.             ->dropColumn('payment_frequency');
  37.     }
  38. }