migrations/Version20240726045328.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 Version20240726045328 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 `dp_workorder_ship_history` (
  18.             `id` int NOT NULL AUTO_INCREMENT,
  19.             `workorder_id` int NOT NULL,
  20.             `product_id` int NOT NULL,
  21.             `product_var_id` int DEFAULT NULL,
  22.             `company_id` int NOT NULL,
  23.             `quantity` int NOT NULL,
  24.             `ship_date` datetime NOT NULL,
  25.             `created_at` datetime NOT NULL,
  26.             `created_by` int NOT NULL,
  27.             PRIMARY KEY (`id`),
  28.             KEY `work_order_id` (`workorder_id`),
  29.             KEY `created_by` (`created_by`),
  30.             KEY `company_id` (`company_id`),
  31.             KEY `workorder_id` (`workorder_id`),
  32.             KEY `product_id` (`product_id`),
  33.             KEY `product_var_id` (`product_var_id`),
  34.             CONSTRAINT `dp_workorder_ship_history_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  35.             CONSTRAINT `dp_workorder_ship_history_ibfk_2` FOREIGN KEY (`workorder_id`) REFERENCES `dp_workorder` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  36.             CONSTRAINT `dp_workorder_ship_history_ibfk_3` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  37.             CONSTRAINT `dp_workorder_ship_history_ibfk_4` FOREIGN KEY (`product_id`) REFERENCES `dp_products` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  38.             CONSTRAINT `dp_workorder_ship_history_ibfk_5` FOREIGN KEY (`product_var_id`) REFERENCES `dp_product_variants` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
  39.             ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
  40.             );
  41.     
  42.             $this->addSql(
  43.                 "CREATE TABLE `dp_workorder_allocated_quantity` (
  44.                     `id` int NOT NULL AUTO_INCREMENT,
  45.                     `level_id` int NOT NULL,
  46.                     `company_id` int NOT NULL,
  47.                     `workorder_id` int NOT NULL,
  48.                     `product_id` int DEFAULT NULL,
  49.                     `product_var_id` int DEFAULT NULL,
  50.                     `total_allocated_qty` int NOT NULL DEFAULT '0',
  51.                     `allocated_qty` int NOT NULL DEFAULT '0',
  52.                     `created_by` int NOT NULL,
  53.                     `created_at` datetime NOT NULL,
  54.                     `updated_by` int DEFAULT NULL,
  55.                     `updated_at` datetime DEFAULT NULL,
  56.                     PRIMARY KEY (`id`),
  57.                     KEY `work_order_id` (`workorder_id`),
  58.                     KEY `created_by` (`created_by`),
  59.                     KEY `updated_by` (`updated_by`),
  60.                     KEY `company_id` (`company_id`),
  61.                     KEY `level_id` (`level_id`),
  62.                     KEY `product_id` (`product_id`),
  63.                     KEY `product_var_id` (`product_var_id`),
  64.                     CONSTRAINT `dp_workorder_allocated_quantity_ibfk_1` FOREIGN KEY (`workorder_id`) REFERENCES `dp_workorder` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  65.                     CONSTRAINT `dp_workorder_allocated_quantity_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  66.                     CONSTRAINT `dp_workorder_allocated_quantity_ibfk_3` FOREIGN KEY (`updated_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  67.                     CONSTRAINT `dp_workorder_allocated_quantity_ibfk_4` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  68.                     CONSTRAINT `dp_workorder_allocated_quantity_ibfk_5` FOREIGN KEY (`level_id`) REFERENCES `dp_levels` (`level_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  69.                     CONSTRAINT `dp_workorder_allocated_quantity_ibfk_6` FOREIGN KEY (`product_id`) REFERENCES `dp_products` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  70.                     CONSTRAINT `dp_workorder_allocated_quantity_ibfk_7` FOREIGN KEY (`product_var_id`) REFERENCES `dp_product_variants` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
  71.                     ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4"
  72.                 );
  73.     
  74.             $this->addSql(
  75.                 "CREATE TABLE `dp_workorder_ship_quantity` (
  76.                 `id` int NOT NULL AUTO_INCREMENT,
  77.                 `workorder_id` int NOT NULL,
  78.                 `company_id` int NOT NULL,
  79.                 `product_id` int NOT NULL,
  80.                 `product_var_id` int DEFAULT NULL,
  81.                 `shipped_qty` int NOT NULL,
  82.                 `last_shipped_date` int NOT NULL,
  83.                 `fully_shipped` int NOT NULL,
  84.                 `created_by` int NOT NULL,
  85.                 `created_at` int NOT NULL,
  86.                 `updated_by` int DEFAULT NULL,
  87.                 `updated_at` int DEFAULT NULL,
  88.                 PRIMARY KEY (`id`),
  89.                 KEY `work_order_id` (`workorder_id`),
  90.                 KEY `created_by` (`created_by`),
  91.                 KEY `updated_by` (`updated_by`),
  92.                 KEY `company_id` (`company_id`),
  93.                 KEY `product_id` (`product_id`),
  94.                 KEY `product_var_id` (`product_var_id`),
  95.                 CONSTRAINT `dp_workorder_ship_quantity_ibfk_1` FOREIGN KEY (`workorder_id`) REFERENCES `dp_workorder` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  96.                 CONSTRAINT `dp_workorder_ship_quantity_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  97.                 CONSTRAINT `dp_workorder_ship_quantity_ibfk_3` FOREIGN KEY (`updated_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  98.                 CONSTRAINT `dp_workorder_ship_quantity_ibfk_4` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  99.                 CONSTRAINT `dp_workorder_ship_quantity_ibfk_5` FOREIGN KEY (`product_id`) REFERENCES `dp_products` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  100.                 CONSTRAINT `dp_workorder_ship_quantity_ibfk_6` FOREIGN KEY (`product_var_id`) REFERENCES `dp_product_variants` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
  101.                 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
  102.                 );
  103.             $this->addSql(
  104.                 "CREATE TABLE `dp_scrap_reasons` (
  105.                 `id` int NOT NULL AUTO_INCREMENT,
  106.                 `comment` text NOT NULL,
  107.                 `company_id` int NOT NULL,
  108.                 `created_by` int NOT NULL,
  109.                 `created_at` datetime NOT NULL,
  110.                 PRIMARY KEY (`id`),
  111.                 KEY `company_id` (`company_id`),
  112.                 KEY `created_by` (`created_by`),
  113.                 CONSTRAINT `dp_scrap_reasons_ibfk_1` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  114.                 CONSTRAINT `dp_scrap_reasons_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
  115.                 ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4"
  116.                 );
  117.             
  118.     
  119.             $this->addSql("ALTER TABLE tc_production_history ADD scrap_reason_id INT");
  120.             $this->addSql("ALTER TABLE tc_production_history ADD CONSTRAINT tc_production_history_ibfk_6 FOREIGN KEY (scrap_reason_id) REFERENCES dp_scrap_reasons(id)");
  121.             $this->addSql("ALTER TABLE `tc_production_history` CHANGE `action` `action` ENUM('qty_added','move_to_stock','scrap_qty') CHARACTER SET utf8mb4");
  122.             $this->addSql("ALTER TABLE tc_production_history ADD company_id INT");
  123.             $this->addSql("ALTER TABLE `tc_production_history` ADD FOREIGN KEY (`company_id`) REFERENCES `company`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT");
  124.             $this->addSql("ALTER TABLE `tc_stock_quantity` ADD `company_id` INT NULL AFTER `total_stock`");
  125.             $this->addSql("ALTER TABLE `tc_stock_quantity` ADD FOREIGN KEY (`company_id`) REFERENCES `company`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT");
  126.             $this->addSql("ALTER TABLE `tc_production_history` ADD `product_id` INT DEFAULT NULL AFTER `company_id`");
  127.             $this->addSql("ALTER TABLE `tc_production_history` ADD FOREIGN KEY (`product_id`) REFERENCES `dp_products` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT");
  128.             $this->addSql("ALTER TABLE `tc_production_history` ADD `product_var_id` INT DEFAULT NULL AFTER `product_id`");
  129.             $this->addSql("ALTER TABLE `tc_production_history` ADD FOREIGN KEY (`product_var_id`) REFERENCES `dp_product_variants` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT");
  130.             $this->addSql("INSERT INTO dp_scrap_reasons (id, comment, company_id, created_by, created_at) VALUES
  131.             (1, 'reason no 1', 1, 1, '2024-07-26 10:22:11'),
  132.             (2, 'reason no 2', 1, 1, '2024-07-26 07:06:48'),
  133.             (3, 'missing ', 1, 1, '2024-07-30 09:39:55')");
  134.     }   
  135.     public function down(Schema $schema): void
  136.     {
  137.         $this->addSql('DROP TABLE dp_workorder_ship_history');
  138.         $this->addSql('DROP TABLE dp_workorder_allocated_quantity');
  139.         $this->addSql('DROP TABLE dp_workorder_ship_quantity');
  140.         $this->addSql('ALTER TABLE tc_production_history DROP FOREIGN KEY tc_production_history_ibfk_6');
  141.         $this->addSql('ALTER TABLE tc_production_history DROP COLUMN scrap_reason_id');
  142.         $this->addSql("ALTER TABLE `tc_production_history` CHANGE `action` `action` ENUM('qty_added','move_to_stock') CHARACTER SET utf8mb4");
  143.         $this->addSql("ALTER TABLE `tc_production_history` DROP FOREIGN KEY `tc_production_history_ibfk_7`");
  144.         $this->addSql("ALTER TABLE `tc_production_history` DROP COLUMN `company_id`");
  145.         
  146.         $this->addSql("ALTER TABLE `tc_stock_quantity` DROP FOREIGN KEY `fk_company_id`");
  147.         $this->addSql("ALTER TABLE `tc_stock_quantity` DROP COLUMN `company_id`");
  148.     }
  149. }