<?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 Version20241017063922 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->addSql("CREATE TABLE IF NOT EXISTS `dp_manage_package` (
`id` int NOT NULL AUTO_INCREMENT,
`company_id` int NOT NULL,
`label` varchar(255) NOT NULL,
`type` enum('product','product_variant') NOT NULL DEFAULT 'product',
`created_by` int NOT NULL,
`created_at` datetime NOT NULL,
`updated_by` int DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`is_deleted` int NOT NULL DEFAULT '0',
`deleted_by` int DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `company_id` (`company_id`) USING BTREE,
KEY `created_by` (`created_by`) USING BTREE,
KEY `updated_by` (`updated_by`),
KEY `deleted_by` (`deleted_by`),
CONSTRAINT `dp_manage_package_ibfk_1` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_manage_package_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_manage_package_ibfk_3` FOREIGN KEY (`updated_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `dp_manage_package_ibfk_4` FOREIGN KEY (`deleted_by`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
");
$this->addSql("ALTER TABLE `dp_products` CHANGE `packaging` `packaging` INT NULL DEFAULT NULL;");
$this->addSql("UPDATE dp_products SET packaging = NULL;");
$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;");
$this->addSql("ALTER TABLE `dp_product_variants` CHANGE `packaging` `packaging` INT NULL DEFAULT NULL;");
$this->addSql("UPDATE dp_product_variants SET packaging = NULL;");
$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;");
}
public function down(Schema $schema): void
{
$this->addSql("ALTER TABLE `dp_products` DROP FOREIGN KEY `dp_products_ibfk_6`;");
$this->addSql("ALTER TABLE `dp_products` CHANGE `packaging` `packaging` ENUM('magazine') NOT NULL DEFAULT 'magazine';");
$this->addSql("ALTER TABLE `dp_product_variants` DROP FOREIGN KEY `dp_product_variants_ibfk_9`;");
$this->addSql("ALTER TABLE `dp_product_variants` CHANGE `packaging` `packaging` ENUM('green_plastic', 'cardboard') NULL;");
$this->addSql("DROP TABLE IF EXISTS `dp_manage_package`");
}
}