migrations/Version20230327133101.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. /** Renaming column additional_line to street_line2 in two migrations */
  8. final class Version20230327133101 extends AbstractMigration
  9. {
  10.     public function getDescription(): string
  11.     {
  12.         return 'Update additionalLine field to streetLine2 the address table';
  13.     }
  14.     public function up(Schema $schema): void
  15.     {
  16.         $this->skipIf(
  17.             false === $schema->getTable('address')->hasColumn('additional_line'),
  18.             'The street is already removed from the address table!'
  19.         );
  20.         $schema->getTable('address')->dropColumn('additional_line');
  21.     }
  22.     public function down(Schema $schema): void
  23.     {
  24.         $this->skipIf(
  25.             true === $schema->getTable('address')->hasColumn('additional_line'),
  26.             'The additional_line is already set in the address table!'
  27.         );
  28.         $schema->getTable('address')
  29.             ->addColumn('additional_line'Types::STRING, [
  30.                 'length' => 255,
  31.             ])->setNotnull(false);
  32.     }
  33.     public function postDown(Schema $schema): void
  34.     {
  35.         $this->connection->executeQuery('UPDATE address SET additional_line=street_line2');
  36.     }
  37. }