<?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 Version20241209064741 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql("CREATE TABLE `dp_product_variant_versions` (
`id` int NOT NULL,
`product_id` int DEFAULT NULL,
`product_variant_id` int DEFAULT NULL,
`company_id` int NOT NULL,
`hitachi_part_no` varchar(255) DEFAULT NULL,
`model_no` varchar(255) DEFAULT NULL,
`hitachi_uk_code` varchar(255) DEFAULT NULL,
`project` varchar(255) DEFAULT NULL,
`production_colour` varchar(255) DEFAULT NULL,
`customer_id` int DEFAULT NULL,
`packaging` int DEFAULT NULL,
`connector` int DEFAULT NULL,
`checksum` varchar(255) DEFAULT NULL,
`box` int DEFAULT NULL,
`comment` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`is_deleted` tinyint NOT NULL DEFAULT '0',
`created_by` int DEFAULT NULL,
`updated_by` int DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`deleted_by` int DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;"
);
$this->addSql("ALTER TABLE `dp_product_variant_versions` ADD PRIMARY KEY (`id`);");
$this->addSql("ALTER TABLE `dp_product_variant_versions` MODIFY `id` int NOT NULL AUTO_INCREMENT;");
$this->addSql("ALTER TABLE `dp_product_variant_versions` ADD `version` INT NOT NULL DEFAULT '1' AFTER `deleted_at`;");
$this->addSql("ALTER TABLE `dp_product_variant_versions`
ADD FOREIGN KEY (`created_by`) REFERENCES `user`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
ADD FOREIGN KEY (`updated_by`) REFERENCES `user`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
ADD FOREIGN KEY (`deleted_by`) REFERENCES `user`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
ADD FOREIGN KEY (`company_id`) REFERENCES `company`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
ADD FOREIGN KEY (`customer_id`) REFERENCES `dp_customers`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
ADD FOREIGN KEY (`product_id`) REFERENCES `dp_products`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
ADD FOREIGN KEY (`packaging`) REFERENCES `dp_manage_package`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;"
);
$this->addSql("ALTER TABLE `dp_product_variant_versions`
ADD FOREIGN KEY (`product_variant_id`) REFERENCES `dp_product_variants`(`id`)
ON DELETE RESTRICT ON UPDATE RESTRICT;"
);
//add product_variant_version_id in dp_product_variants table
$this->addSql("ALTER TABLE `dp_product_variants` ADD `latest_version_id` INT NULL;");
//add foriegn key
$this->addSql("ALTER TABLE `dp_product_variants` ADD FOREIGN KEY (`latest_version_id`) REFERENCES `dp_product_variant_versions`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;");
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE `dp_product_variant_versions` DROP FOREIGN KEY `dp_product_variant_versions_ibfk_8`;');
$this->addSql('ALTER TABLE `dp_product_variant_versions` DROP FOREIGN KEY `dp_product_variant_versions_ibfk_7`;');
$this->addSql('ALTER TABLE `dp_product_variant_versions` DROP FOREIGN KEY `dp_product_variant_versions_ibfk_6`;');
$this->addSql('ALTER TABLE `dp_product_variant_versions` DROP FOREIGN KEY `dp_product_variant_versions_ibfk_5`;');
$this->addSql('ALTER TABLE `dp_product_variant_versions` DROP FOREIGN KEY `dp_product_variant_versions_ibfk_4`;');
$this->addSql('ALTER TABLE `dp_product_variant_versions` DROP FOREIGN KEY `dp_product_variant_versions_ibfk_3`;');
$this->addSql('ALTER TABLE `dp_product_variant_versions` DROP FOREIGN KEY `dp_product_variant_versions_ibfk_2`;');
$this->addSql('ALTER TABLE `dp_product_variant_versions` DROP FOREIGN KEY `dp_product_variant_versions_ibfk_1`;');
//drop product_variant_version_id in dp_product_variants table
$this->addSql('ALTER TABLE `dp_product_variants` DROP FOREIGN KEY `dp_product_variants_ibfk_10`;');
$this->addSql('ALTER TABLE `dp_product_variants` DROP `latest_version_id`;');
//drop table dp_product_variant_versions
$this->addSql('DROP TABLE `dp_product_variant_versions`');
}
}