<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20230316124700 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add payment_frequency field to the member_application table';
}
public function up(Schema $schema): void
{
$this->skipIf(
true === $schema->getTable('member_application')->hasColumn('payment_frequency'),
'The payment_frequency field already exists in the member_application table!'
);
$schema->getTable('member_application')
->addColumn('payment_frequency', Types::STRING, [
'length' => 30,
])
->setNotnull(false);
}
public function postUp(Schema $schema): void
{
$this->connection->executeQuery('UPDATE member_application SET payment_frequency="annual"');
}
public function down(Schema $schema): void
{
$this->skipIf(
false === $schema->getTable('member_application')->hasColumn('payment_frequency'),
'The payment_frequency is already removed from the member_application table!'
);
$schema->getTable('member_application')
->dropColumn('payment_frequency');
}
}