<?php
declare(strict_types=1);
namespace ManufacturingBundleMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\Uid\UuidV6;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20221208143855 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE manufacturing_bundle__product_options (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', product_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', disabled TINYINT(1) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_6DC38EA14584665A (product_id), INDEX IDX_6DC38EA1B03A8386 (created_by_id), INDEX IDX_6DC38EA1896DBBDE (updated_by_id), INDEX IDX_6DC38EA1C76F1F52 (deleted_by_id), INDEX disabled (disabled), INDEX deleted_at (deleted_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE manufacturing_bundle__product_options ADD CONSTRAINT FK_6DC38EA14584665A FOREIGN KEY (product_id) REFERENCES products_bundle__product (id)');
$this->addSql('ALTER TABLE manufacturing_bundle__product_options ADD CONSTRAINT FK_6DC38EA1B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE manufacturing_bundle__product_options ADD CONSTRAINT FK_6DC38EA1896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE manufacturing_bundle__product_options ADD CONSTRAINT FK_6DC38EA1C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE manufacturing_bundle__product_options DROP FOREIGN KEY FK_6DC38EA14584665A');
$this->addSql('ALTER TABLE manufacturing_bundle__product_options DROP FOREIGN KEY FK_6DC38EA1B03A8386');
$this->addSql('ALTER TABLE manufacturing_bundle__product_options DROP FOREIGN KEY FK_6DC38EA1896DBBDE');
$this->addSql('ALTER TABLE manufacturing_bundle__product_options DROP FOREIGN KEY FK_6DC38EA1C76F1F52');
$this->addSql('DROP TABLE manufacturing_bundle__product_options');
}
public function postUp(Schema $schema): void
{
parent::postUp($schema);
$now = (new \DateTime())->format('Y-m-d H:i:s');
$configuration = $this->connection
->executeQuery('SELECT value FROM configuration WHERE context_id IS NULL AND name = \'stocks_bundle__default_stock_movement_reason__removal\'')
->fetchOne();
if ($configuration) {
$this->connection->insert('configuration', [
'id' => (new UuidV6())->toBinary(),
'name' => 'manufacturing_bundle__transformation_stock_reason',
'context_id' => null,
'value' => $configuration,
'created_at' => $now,
'updated_at' => $now
]);
}
}
}