<?php
declare(strict_types=1);
namespace LabelsBundleMigrations;
use App\Services\ObjectSerialize;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\Uid\UuidV6;
final class Version20221206230248 extends AbstractMigration
{
private ObjectSerialize $objectSerialize;
public function setObjectSerialize(ObjectSerialize $objectSerialize)
{
$this->objectSerialize = $objectSerialize;
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE labels_bundle__label (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', product_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', declination_id BINARY(16) DEFAULT 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)\', name VARCHAR(255) NOT NULL, source VARCHAR(255) DEFAULT NULL, summary LONGTEXT DEFAULT NULL, description LONGTEXT DEFAULT NULL, reference VARCHAR(255) DEFAULT NULL, reference_brand VARCHAR(255) DEFAULT NULL, ean13 VARCHAR(13) DEFAULT NULL, wholesale_price NUMERIC(20, 6) DEFAULT NULL, sell_price NUMERIC(20, 6) DEFAULT NULL, attribute VARCHAR(255) DEFAULT NULL, batch_number VARCHAR(64) DEFAULT NULL, date_type_name VARCHAR(50) DEFAULT NULL, date_type_long_name VARCHAR(255) DEFAULT NULL, limit_date DATETIME DEFAULT NULL, custom_text LONGTEXT DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_18741D9C4584665A (product_id), INDEX IDX_18741D9C9941A932 (declination_id), INDEX IDX_18741D9CB03A8386 (created_by_id), INDEX IDX_18741D9C896DBBDE (updated_by_id), INDEX IDX_18741D9CC76F1F52 (deleted_by_id), INDEX name (name), INDEX source (source), INDEX attribute (attribute), 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('CREATE TABLE labels_bundle__label_context (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', label_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', context_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', INDEX IDX_2810AB2733B92F39 (label_id), INDEX IDX_2810AB276B00C1CF (context_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE labels_bundle__label_translations (id INT AUTO_INCREMENT NOT NULL, object_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', locale VARCHAR(8) NOT NULL, field VARCHAR(32) NOT NULL, content LONGTEXT DEFAULT NULL, INDEX IDX_FA0E8E67232D562B (object_id), FULLTEXT INDEX content (content), UNIQUE INDEX lookup_unique_idx (locale, object_id, field), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE labels_bundle__template (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', context_id BINARY(16) DEFAULT 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)\', name VARCHAR(255) NOT NULL, content LONGTEXT DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, is_default TINYINT(1) NOT NULL, INDEX IDX_9E956D3F6B00C1CF (context_id), INDEX IDX_9E956D3FB03A8386 (created_by_id), INDEX IDX_9E956D3F896DBBDE (updated_by_id), INDEX IDX_9E956D3FC76F1F52 (deleted_by_id), INDEX name (name), INDEX is_default (is_default), 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 labels_bundle__label ADD CONSTRAINT FK_18741D9C4584665A FOREIGN KEY (product_id) REFERENCES products_bundle__product (id)');
$this->addSql('ALTER TABLE labels_bundle__label ADD CONSTRAINT FK_18741D9C9941A932 FOREIGN KEY (declination_id) REFERENCES products_bundle__declination (id)');
$this->addSql('ALTER TABLE labels_bundle__label ADD CONSTRAINT FK_18741D9CB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE labels_bundle__label ADD CONSTRAINT FK_18741D9C896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE labels_bundle__label ADD CONSTRAINT FK_18741D9CC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE labels_bundle__label_context ADD CONSTRAINT FK_2810AB2733B92F39 FOREIGN KEY (label_id) REFERENCES labels_bundle__label (id)');
$this->addSql('ALTER TABLE labels_bundle__label_context ADD CONSTRAINT FK_2810AB276B00C1CF FOREIGN KEY (context_id) REFERENCES context (id)');
$this->addSql('ALTER TABLE labels_bundle__label_translations ADD CONSTRAINT FK_FA0E8E67232D562B FOREIGN KEY (object_id) REFERENCES labels_bundle__label (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE labels_bundle__template ADD CONSTRAINT FK_9E956D3F6B00C1CF FOREIGN KEY (context_id) REFERENCES context (id)');
$this->addSql('ALTER TABLE labels_bundle__template ADD CONSTRAINT FK_9E956D3FB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE labels_bundle__template ADD CONSTRAINT FK_9E956D3F896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE labels_bundle__template ADD CONSTRAINT FK_9E956D3FC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE labels_bundle__label DROP FOREIGN KEY FK_18741D9C4584665A');
$this->addSql('ALTER TABLE labels_bundle__label DROP FOREIGN KEY FK_18741D9C9941A932');
$this->addSql('ALTER TABLE labels_bundle__label DROP FOREIGN KEY FK_18741D9CB03A8386');
$this->addSql('ALTER TABLE labels_bundle__label DROP FOREIGN KEY FK_18741D9C896DBBDE');
$this->addSql('ALTER TABLE labels_bundle__label DROP FOREIGN KEY FK_18741D9CC76F1F52');
$this->addSql('ALTER TABLE labels_bundle__label_context DROP FOREIGN KEY FK_2810AB2733B92F39');
$this->addSql('ALTER TABLE labels_bundle__label_context DROP FOREIGN KEY FK_2810AB276B00C1CF');
$this->addSql('ALTER TABLE labels_bundle__label_translations DROP FOREIGN KEY FK_FA0E8E67232D562B');
$this->addSql('ALTER TABLE labels_bundle__template DROP FOREIGN KEY FK_9E956D3F6B00C1CF');
$this->addSql('ALTER TABLE labels_bundle__template DROP FOREIGN KEY FK_9E956D3FB03A8386');
$this->addSql('ALTER TABLE labels_bundle__template DROP FOREIGN KEY FK_9E956D3F896DBBDE');
$this->addSql('ALTER TABLE labels_bundle__template DROP FOREIGN KEY FK_9E956D3FC76F1F52');
$this->addSql('DROP TABLE labels_bundle__label');
$this->addSql('DROP TABLE labels_bundle__label_context');
$this->addSql('DROP TABLE labels_bundle__label_translations');
$this->addSql('DROP TABLE labels_bundle__template');
}
public function postUp(Schema $schema): void
{
parent::postUp($schema);
$now = (new \DateTime())->format('Y-m-d H:i:s');
$this->connection->insert('configuration', [
'id' => (new UuidV6())->toBinary(),
'name' => 'labels_bundle__default_number_prints',
'context_id' => null,
'value' => $this->objectSerialize->add((object) ['value' => '10']),
'created_at' => $now,
'updated_at' => $now
]);
$this->connection->insert('configuration', [
'id' => (new UuidV6())->toBinary(),
'name' => 'labels_bundle__shared_labels',
'context_id' => null,
'value' => $this->objectSerialize->add((object) ['value' => '0']),
'created_at' => $now,
'updated_at' => $now
]);
$fixtureFile = dirname(__FILE__) . '/../src/Resources/views/Pdf/Fixtures/label.html.twig';
$content = file_get_contents($fixtureFile);
$this->connection->insert('labels_bundle__template', [
'id' => (new UuidV6())->toBinary(),
'name' => 'Default',
'content' => $content,
'is_default' => 1,
'created_at' => $now,
'updated_at' => $now
]);
}
}