<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
/** Renaming column additional_line to street_line2 in two migrations */
final class Version20230327133101 extends AbstractMigration
{
public function getDescription(): string
{
return 'Update additionalLine field to streetLine2 the address table';
}
public function up(Schema $schema): void
{
$this->skipIf(
false === $schema->getTable('address')->hasColumn('additional_line'),
'The street is already removed from the address table!'
);
$schema->getTable('address')->dropColumn('additional_line');
}
public function down(Schema $schema): void
{
$this->skipIf(
true === $schema->getTable('address')->hasColumn('additional_line'),
'The additional_line is already set in the address table!'
);
$schema->getTable('address')
->addColumn('additional_line', Types::STRING, [
'length' => 255,
])->setNotnull(false);
}
public function postDown(Schema $schema): void
{
$this->connection->executeQuery('UPDATE address SET additional_line=street_line2');
}
}