migrations/Version20241017063922.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 Version20241017063922 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {        
  17.         $this->addSql("CREATE TABLE IF NOT EXISTS `dp_manage_package` (
  18.             `id` int NOT NULL AUTO_INCREMENT,
  19.             `company_id` int NOT NULL,
  20.             `label` varchar(255) NOT NULL,
  21.             `type` enum('product','product_variant') NOT NULL DEFAULT 'product',
  22.             `created_by` int NOT NULL,
  23.             `created_at` datetime NOT NULL,
  24.             `updated_by` int DEFAULT NULL,
  25.             `updated_at` datetime DEFAULT NULL,
  26.             `is_deleted` int NOT NULL DEFAULT '0',
  27.             `deleted_by` int DEFAULT NULL,
  28.             `deleted_at` datetime DEFAULT NULL,
  29.             PRIMARY KEY (`id`),
  30.             KEY `company_id` (`company_id`) USING BTREE,
  31.             KEY `created_by` (`created_by`) USING BTREE,
  32.             KEY `updated_by` (`updated_by`),
  33.             KEY `deleted_by` (`deleted_by`),
  34.             CONSTRAINT `dp_manage_package_ibfk_1` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  35.             CONSTRAINT `dp_manage_package_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  36.             CONSTRAINT `dp_manage_package_ibfk_3` FOREIGN KEY (`updated_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  37.             CONSTRAINT `dp_manage_package_ibfk_4` FOREIGN KEY (`deleted_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
  38.           ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
  39.         ");
  40.         $this->addSql("ALTER TABLE `dp_products` CHANGE `packaging` `packaging` INT NULL DEFAULT NULL;");
  41.         $this->addSql("UPDATE dp_products SET packaging = NULL;");
  42.         $this->addSql("ALTER TABLE `dp_products` ADD CONSTRAINT `dp_products_ibfk_6` FOREIGN KEY (`packaging`) REFERENCES `dp_manage_package`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;");
  43.         $this->addSql("ALTER TABLE `dp_product_variants` CHANGE `packaging` `packaging` INT NULL DEFAULT NULL;");
  44.         $this->addSql("UPDATE dp_product_variants SET packaging = NULL;");
  45.         $this->addSql("ALTER TABLE `dp_product_variants` ADD CONSTRAINT `dp_product_variants_ibfk_9` FOREIGN KEY (`packaging`) REFERENCES `dp_manage_package`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;");
  46.         
  47.         
  48.     }
  49.     public function down(Schema $schema): void
  50.     {
  51.         $this->addSql("ALTER TABLE `dp_products` DROP FOREIGN KEY `dp_products_ibfk_6`;");
  52.         $this->addSql("ALTER TABLE `dp_products` CHANGE `packaging` `packaging` ENUM('magazine') NOT NULL  DEFAULT 'magazine';");
  53.         $this->addSql("ALTER TABLE `dp_product_variants` DROP FOREIGN KEY `dp_product_variants_ibfk_9`;");
  54.         $this->addSql("ALTER TABLE `dp_product_variants` CHANGE `packaging` `packaging` ENUM('green_plastic', 'cardboard') NULL;");   
  55.         $this->addSql("DROP TABLE IF EXISTS `dp_manage_package`");     
  56.     }
  57. }