<?php
declare(strict_types=1);
namespace ShipmentsBundleMigrations;
use App\Services\ObjectSerialize;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\Uid\UuidV6;
final class Version20221207121143 extends AbstractMigration
{
private ObjectSerialize $objectSerialize;
public function setObjectSerialize(ObjectSerialize $objectSerialize)
{
$this->objectSerialize = $objectSerialize;
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE shipments_bundle__burst (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)\', number INT NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, is_active TINYINT(1) DEFAULT 1 NOT NULL, INDEX IDX_561AB417B03A8386 (created_by_id), INDEX IDX_561AB417896DBBDE (updated_by_id), INDEX IDX_561AB417C76F1F52 (deleted_by_id), INDEX number (number), INDEX is_active (is_active), 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 shipments_bundle__carrier (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)\', name VARCHAR(255) NOT NULL, module VARCHAR(128) DEFAULT NULL, product_code VARCHAR(5) DEFAULT NULL, is_relay TINYINT(1) DEFAULT 0, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_BCA5246BB03A8386 (created_by_id), INDEX IDX_BCA5246B896DBBDE (updated_by_id), INDEX IDX_BCA5246BC76F1F52 (deleted_by_id), INDEX name (name), 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 shipments_bundle__carrier_context (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', carrier_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', context_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', INDEX IDX_BC80A02921DFC797 (carrier_id), INDEX IDX_BC80A0296B00C1CF (context_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE shipments_bundle__order_options (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', order_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', burst_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', delivery_note_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', carrier_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)\', weight NUMERIC(20, 6) DEFAULT NULL, shipping_number VARCHAR(128) DEFAULT NULL, relay_number VARCHAR(20) DEFAULT NULL, carrier_global_product_code VARCHAR(20) DEFAULT NULL, status INT NOT NULL, length NUMERIC(20, 6) DEFAULT NULL, width NUMERIC(20, 6) DEFAULT NULL, height NUMERIC(20, 6) DEFAULT NULL, prepared_at DATETIME DEFAULT NULL, last_error VARCHAR(256) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_3F7A5CB18D9F6D38 (order_id), INDEX IDX_3F7A5CB1CC799A1F (burst_id), INDEX IDX_3F7A5CB12CF3B78B (delivery_note_id), INDEX IDX_3F7A5CB121DFC797 (carrier_id), INDEX IDX_3F7A5CB1B03A8386 (created_by_id), INDEX IDX_3F7A5CB1896DBBDE (updated_by_id), INDEX IDX_3F7A5CB1C76F1F52 (deleted_by_id), INDEX status (status), 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 shipments_bundle__order_state_for_burst (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', order_state_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', type VARCHAR(50) DEFAULT NULL, is_show TINYINT(1) NOT NULL, INDEX IDX_8656E32EE420DE70 (order_state_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE shipments_bundle__burst ADD CONSTRAINT FK_561AB417B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE shipments_bundle__burst ADD CONSTRAINT FK_561AB417896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE shipments_bundle__burst ADD CONSTRAINT FK_561AB417C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE shipments_bundle__carrier ADD CONSTRAINT FK_BCA5246BB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE shipments_bundle__carrier ADD CONSTRAINT FK_BCA5246B896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE shipments_bundle__carrier ADD CONSTRAINT FK_BCA5246BC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE shipments_bundle__carrier_context ADD CONSTRAINT FK_BC80A02921DFC797 FOREIGN KEY (carrier_id) REFERENCES shipments_bundle__carrier (id)');
$this->addSql('ALTER TABLE shipments_bundle__carrier_context ADD CONSTRAINT FK_BC80A0296B00C1CF FOREIGN KEY (context_id) REFERENCES context (id)');
$this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB18D9F6D38 FOREIGN KEY (order_id) REFERENCES sales_bundle__order (id)');
$this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB1CC799A1F FOREIGN KEY (burst_id) REFERENCES shipments_bundle__burst (id)');
$this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB12CF3B78B FOREIGN KEY (delivery_note_id) REFERENCES sales_bundle__delivery_note (id)');
$this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB121DFC797 FOREIGN KEY (carrier_id) REFERENCES shipments_bundle__carrier (id)');
$this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB1B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB1896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB1C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE shipments_bundle__order_state_for_burst ADD CONSTRAINT FK_8656E32EE420DE70 FOREIGN KEY (order_state_id) REFERENCES sales_bundle__order_state (id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE shipments_bundle__burst DROP FOREIGN KEY FK_561AB417B03A8386');
$this->addSql('ALTER TABLE shipments_bundle__burst DROP FOREIGN KEY FK_561AB417896DBBDE');
$this->addSql('ALTER TABLE shipments_bundle__burst DROP FOREIGN KEY FK_561AB417C76F1F52');
$this->addSql('ALTER TABLE shipments_bundle__carrier DROP FOREIGN KEY FK_BCA5246BB03A8386');
$this->addSql('ALTER TABLE shipments_bundle__carrier DROP FOREIGN KEY FK_BCA5246B896DBBDE');
$this->addSql('ALTER TABLE shipments_bundle__carrier DROP FOREIGN KEY FK_BCA5246BC76F1F52');
$this->addSql('ALTER TABLE shipments_bundle__carrier_context DROP FOREIGN KEY FK_BC80A02921DFC797');
$this->addSql('ALTER TABLE shipments_bundle__carrier_context DROP FOREIGN KEY FK_BC80A0296B00C1CF');
$this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB18D9F6D38');
$this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB1CC799A1F');
$this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB12CF3B78B');
$this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB121DFC797');
$this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB1B03A8386');
$this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB1896DBBDE');
$this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB1C76F1F52');
$this->addSql('ALTER TABLE shipments_bundle__order_state_for_burst DROP FOREIGN KEY FK_8656E32EE420DE70');
$this->addSql('DROP TABLE shipments_bundle__burst');
$this->addSql('DROP TABLE shipments_bundle__carrier');
$this->addSql('DROP TABLE shipments_bundle__carrier_context');
$this->addSql('DROP TABLE shipments_bundle__order_options');
$this->addSql('DROP TABLE shipments_bundle__order_state_for_burst');
}
public function postUp(Schema $schema): void
{
parent::postUp($schema);
$now = (new \DateTime())->format('Y-m-d H:i:s');
$fixtureFile = dirname(__FILE__) . '/../src/Resources/views/Pdf/Fixtures/label.html.twig';
$configurations = [
'shipments_bundle__company_name' => 'Nom société',
'shipments_bundle__address' => 'adresse',
'shipments_bundle__city' => 'Troyes',
'shipments_bundle__zip_code' => '10000',
'shipments_bundle__phone' => '0123456789',
'shipments_bundle__language_iso' => 'FR',
'shipments_bundle__country_iso' => 'FR',
'shipments_bundle__delivery_note_and_label_merged' => 1,
'shipments_bundle__number_of_orders_per_burst' => 10,
'shipments_bundle__click_and_collect_pdf' => file_get_contents($fixtureFile),
'shipments_bundle__shared_carrier' => 1
];
foreach ($configurations as $configuration => $value) {
$this->connection->insert('configuration', [
'id' => (new UuidV6())->toBinary(),
'name' => $configuration,
'context_id' => null,
'value' => $this->objectSerialize->add((object) ['value' => $value]),
'created_at' => $now,
'updated_at' => $now
]);
}
$carrierId = (new UuidV6())->toBinary();
$this->connection->insert('shipments_bundle__carrier', [
'id' => $carrierId,
'name' => 'Click & Collect',
'module' => 'click_and_collect',
'created_at' => $now,
'updated_at' => $now
]);
$contexts = $this->connection->executeQuery('SELECT * FROM context WHERE deleted_at IS NULL')
->fetchAllAssociative();
foreach ($contexts as $context) {
$carrierContextId = (new UuidV6())->toBinary();
$this->connection->insert('shipments_bundle__carrier_context', [
'id' => $carrierContextId,
'carrier_id' => $carrierId,
'context_id' => $context['id']
]);
}
}
}