migrations/Version20221102132633.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\Migrations\AbstractMigration;
  6. final class Version20221102132633 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return '';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->skipIf(
  15.             true === $schema->getTable('tariff')->hasColumn('cns_tariff'),
  16.             'The cns_tariff field already exists in the tariff table!'
  17.         );
  18.         $this->addSql('ALTER TABLE tariff ADD cns_tariff DOUBLE PRECISION NOT NULL;');
  19.         $this->addSql('UPDATE tariff SET cns_tariff = tariff');
  20.         $this->addSql('ALTER TABLE tariff DROP COLUMN tariff');
  21.     }
  22.     public function down(Schema $schema): void
  23.     {
  24.         $this->skipIf(
  25.             false === $schema->getTable('tariff')->hasColumn('tariff'),
  26.             'The tariff field already exists in the tariff table!'
  27.         );
  28.         $this->addSql('ALTER TABLE tariff ADD tariff DOUBLE PRECISION NOT NULL;');
  29.         $this->addSql('UPDATE tariff SET tariff = cns_tariff');
  30.         $this->addSql('ALTER TABLE tariff DROP COLUMN cns_tariff');
  31.     }
  32. }