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