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