migrations/Version20240213150008.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. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20240213150008 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->addSql('ALTER TABLE product ADD sku VARCHAR(255) NOT NULL');
  19.         $products $this->connection->fetchAllAssociative('SELECT id FROM product');
  20.         foreach ($products as $product) {
  21.             $this->addSql(
  22.                 'UPDATE product SET sku = :sku WHERE id = :id',
  23.                 [
  24.                     'sku' => strtoupper(uniqid('FOX_')),
  25.                     'id' => $product['id'],
  26.                 ]
  27.             );
  28.         }
  29.         $this->addSql('ALTER TABLE order_item ADD free TINYINT(1) DEFAULT 0 NOT NULL');
  30.         $this->addSql('ALTER TABLE order_item ADD external_reference VARCHAR(255) DEFAULT NULL');
  31.         $this->addSql('ALTER TABLE `order` CHANGE items_total items_total INT NOT NULL, CHANGE total total INT NOT NULL');
  32.         $this->addSql('ALTER TABLE order_item CHANGE total total INT NOT NULL');
  33.     }
  34.     public function down(Schema $schema): void
  35.     {
  36.         // this down() migration is auto-generated, please modify it to your needs
  37.         $this->addSql('ALTER TABLE product DROP sku');
  38.         $this->addSql('ALTER TABLE order_item DROP free');
  39.         $this->addSql('ALTER TABLE order_item DROP external_reference');
  40.         $this->addSql('ALTER TABLE `order` CHANGE items_total items_total DOUBLE PRECISION NOT NULL, CHANGE total total DOUBLE PRECISION NOT NULL');
  41.         $this->addSql('ALTER TABLE order_item CHANGE total total DOUBLE PRECISION NOT NULL');
  42.     }
  43. }