migrations/Version20220203072748.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 Version20220203072748 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('CREATE TABLE order_product (id INT AUTO_INCREMENT NOT NULL, product_id INT NOT NULL, product_variant_id INT DEFAULT NULL, order_id INT NOT NULL, quantity INT DEFAULT NULL, price DOUBLE PRECISION DEFAULT NULL, total_price DOUBLE PRECISION DEFAULT NULL, INDEX IDX_2530ADE64584665A (product_id), INDEX IDX_2530ADE6A80EF684 (product_variant_id), INDEX IDX_2530ADE68D9F6D38 (order_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  19.         $this->addSql('ALTER TABLE order_product ADD CONSTRAINT FK_2530ADE64584665A FOREIGN KEY (product_id) REFERENCES product (id)');
  20.         $this->addSql('ALTER TABLE order_product ADD CONSTRAINT FK_2530ADE6A80EF684 FOREIGN KEY (product_variant_id) REFERENCES product_variant (id)');
  21.         $this->addSql('ALTER TABLE order_product ADD CONSTRAINT FK_2530ADE68D9F6D38 FOREIGN KEY (order_id) REFERENCES orders (id)');
  22.         $this->addSql('ALTER TABLE orders DROP FOREIGN KEY FK_E52FFDEE4584665A');
  23.         $this->addSql('DROP INDEX IDX_E52FFDEE4584665A ON orders');
  24.         $this->addSql('ALTER TABLE orders DROP product_id, DROP product_name, DROP product_variant_name, DROP count, DROP discount');
  25.     }
  26.     public function down(Schema $schema): void
  27.     {
  28.         // this down() migration is auto-generated, please modify it to your needs
  29.         $this->addSql('DROP TABLE order_product');
  30.         $this->addSql('ALTER TABLE orders ADD product_id INT DEFAULT NULL, ADD product_name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, ADD product_variant_name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, ADD count INT NOT NULL, ADD discount INT DEFAULT NULL');
  31.         $this->addSql('ALTER TABLE orders ADD CONSTRAINT FK_E52FFDEE4584665A FOREIGN KEY (product_id) REFERENCES product (id)');
  32.         $this->addSql('CREATE INDEX IDX_E52FFDEE4584665A ON orders (product_id)');
  33.     }
  34. }