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