<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240726045328 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->addSql("CREATE TABLE `dp_workorder_ship_history` (
`id` int NOT NULL AUTO_INCREMENT,
`workorder_id` int NOT NULL,
`product_id` int NOT NULL,
`product_var_id` int DEFAULT NULL,
`company_id` int NOT NULL,
`quantity` int NOT NULL,
`ship_date` datetime NOT NULL,
`created_at` datetime NOT NULL,
`created_by` int NOT NULL,
PRIMARY KEY (`id`),
KEY `work_order_id` (`workorder_id`),
KEY `created_by` (`created_by`),
KEY `company_id` (`company_id`),
KEY `workorder_id` (`workorder_id`),
KEY `product_id` (`product_id`),
KEY `product_var_id` (`product_var_id`),
CONSTRAINT `dp_workorder_ship_history_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_ship_history_ibfk_2` FOREIGN KEY (`workorder_id`) REFERENCES `dp_workorder` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_ship_history_ibfk_3` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_ship_history_ibfk_4` FOREIGN KEY (`product_id`) REFERENCES `dp_products` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_ship_history_ibfk_5` FOREIGN KEY (`product_var_id`) REFERENCES `dp_product_variants` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
);
$this->addSql(
"CREATE TABLE `dp_workorder_allocated_quantity` (
`id` int NOT NULL AUTO_INCREMENT,
`level_id` int NOT NULL,
`company_id` int NOT NULL,
`workorder_id` int NOT NULL,
`product_id` int DEFAULT NULL,
`product_var_id` int DEFAULT NULL,
`total_allocated_qty` int NOT NULL DEFAULT '0',
`allocated_qty` int NOT NULL DEFAULT '0',
`created_by` int NOT NULL,
`created_at` datetime NOT NULL,
`updated_by` int DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `work_order_id` (`workorder_id`),
KEY `created_by` (`created_by`),
KEY `updated_by` (`updated_by`),
KEY `company_id` (`company_id`),
KEY `level_id` (`level_id`),
KEY `product_id` (`product_id`),
KEY `product_var_id` (`product_var_id`),
CONSTRAINT `dp_workorder_allocated_quantity_ibfk_1` FOREIGN KEY (`workorder_id`) REFERENCES `dp_workorder` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_allocated_quantity_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_allocated_quantity_ibfk_3` FOREIGN KEY (`updated_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_allocated_quantity_ibfk_4` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_allocated_quantity_ibfk_5` FOREIGN KEY (`level_id`) REFERENCES `dp_levels` (`level_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_allocated_quantity_ibfk_6` FOREIGN KEY (`product_id`) REFERENCES `dp_products` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_allocated_quantity_ibfk_7` FOREIGN KEY (`product_var_id`) REFERENCES `dp_product_variants` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4"
);
$this->addSql(
"CREATE TABLE `dp_workorder_ship_quantity` (
`id` int NOT NULL AUTO_INCREMENT,
`workorder_id` int NOT NULL,
`company_id` int NOT NULL,
`product_id` int NOT NULL,
`product_var_id` int DEFAULT NULL,
`shipped_qty` int NOT NULL,
`last_shipped_date` int NOT NULL,
`fully_shipped` int NOT NULL,
`created_by` int NOT NULL,
`created_at` int NOT NULL,
`updated_by` int DEFAULT NULL,
`updated_at` int DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `work_order_id` (`workorder_id`),
KEY `created_by` (`created_by`),
KEY `updated_by` (`updated_by`),
KEY `company_id` (`company_id`),
KEY `product_id` (`product_id`),
KEY `product_var_id` (`product_var_id`),
CONSTRAINT `dp_workorder_ship_quantity_ibfk_1` FOREIGN KEY (`workorder_id`) REFERENCES `dp_workorder` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_ship_quantity_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_ship_quantity_ibfk_3` FOREIGN KEY (`updated_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_ship_quantity_ibfk_4` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_ship_quantity_ibfk_5` FOREIGN KEY (`product_id`) REFERENCES `dp_products` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_workorder_ship_quantity_ibfk_6` FOREIGN KEY (`product_var_id`) REFERENCES `dp_product_variants` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
);
$this->addSql(
"CREATE TABLE `dp_scrap_reasons` (
`id` int NOT NULL AUTO_INCREMENT,
`comment` text NOT NULL,
`company_id` int NOT NULL,
`created_by` int NOT NULL,
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `company_id` (`company_id`),
KEY `created_by` (`created_by`),
CONSTRAINT `dp_scrap_reasons_ibfk_1` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_scrap_reasons_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4"
);
$this->addSql("ALTER TABLE tc_production_history ADD scrap_reason_id INT");
$this->addSql("ALTER TABLE tc_production_history ADD CONSTRAINT tc_production_history_ibfk_6 FOREIGN KEY (scrap_reason_id) REFERENCES dp_scrap_reasons(id)");
$this->addSql("ALTER TABLE `tc_production_history` CHANGE `action` `action` ENUM('qty_added','move_to_stock','scrap_qty') CHARACTER SET utf8mb4");
$this->addSql("ALTER TABLE tc_production_history ADD company_id INT");
$this->addSql("ALTER TABLE `tc_production_history` ADD FOREIGN KEY (`company_id`) REFERENCES `company`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT");
$this->addSql("ALTER TABLE `tc_stock_quantity` ADD `company_id` INT NULL AFTER `total_stock`");
$this->addSql("ALTER TABLE `tc_stock_quantity` ADD FOREIGN KEY (`company_id`) REFERENCES `company`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT");
$this->addSql("ALTER TABLE `tc_production_history` ADD `product_id` INT DEFAULT NULL AFTER `company_id`");
$this->addSql("ALTER TABLE `tc_production_history` ADD FOREIGN KEY (`product_id`) REFERENCES `dp_products` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT");
$this->addSql("ALTER TABLE `tc_production_history` ADD `product_var_id` INT DEFAULT NULL AFTER `product_id`");
$this->addSql("ALTER TABLE `tc_production_history` ADD FOREIGN KEY (`product_var_id`) REFERENCES `dp_product_variants` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT");
$this->addSql("INSERT INTO dp_scrap_reasons (id, comment, company_id, created_by, created_at) VALUES
(1, 'reason no 1', 1, 1, '2024-07-26 10:22:11'),
(2, 'reason no 2', 1, 1, '2024-07-26 07:06:48'),
(3, 'missing ', 1, 1, '2024-07-30 09:39:55')");
}
public function down(Schema $schema): void
{
$this->addSql('DROP TABLE dp_workorder_ship_history');
$this->addSql('DROP TABLE dp_workorder_allocated_quantity');
$this->addSql('DROP TABLE dp_workorder_ship_quantity');
$this->addSql('ALTER TABLE tc_production_history DROP FOREIGN KEY tc_production_history_ibfk_6');
$this->addSql('ALTER TABLE tc_production_history DROP COLUMN scrap_reason_id');
$this->addSql("ALTER TABLE `tc_production_history` CHANGE `action` `action` ENUM('qty_added','move_to_stock') CHARACTER SET utf8mb4");
$this->addSql("ALTER TABLE `tc_production_history` DROP FOREIGN KEY `tc_production_history_ibfk_7`");
$this->addSql("ALTER TABLE `tc_production_history` DROP COLUMN `company_id`");
$this->addSql("ALTER TABLE `tc_stock_quantity` DROP FOREIGN KEY `fk_company_id`");
$this->addSql("ALTER TABLE `tc_stock_quantity` DROP COLUMN `company_id`");
}
}