vendor/bluue/shipments-bundle/migrations/Version20221207121143.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace ShipmentsBundleMigrations;
  4. use App\Services\ObjectSerialize;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. use Symfony\Component\Uid\UuidV6;
  8. final class Version20221207121143 extends AbstractMigration
  9. {
  10.     private ObjectSerialize $objectSerialize;
  11.     public function setObjectSerialize(ObjectSerialize $objectSerialize)
  12.     {
  13.         $this->objectSerialize $objectSerialize;
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $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');
  18.         $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');
  19.         $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');
  20.         $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');
  21.         $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');
  22.         $this->addSql('ALTER TABLE shipments_bundle__burst ADD CONSTRAINT FK_561AB417B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  23.         $this->addSql('ALTER TABLE shipments_bundle__burst ADD CONSTRAINT FK_561AB417896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  24.         $this->addSql('ALTER TABLE shipments_bundle__burst ADD CONSTRAINT FK_561AB417C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  25.         $this->addSql('ALTER TABLE shipments_bundle__carrier ADD CONSTRAINT FK_BCA5246BB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  26.         $this->addSql('ALTER TABLE shipments_bundle__carrier ADD CONSTRAINT FK_BCA5246B896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  27.         $this->addSql('ALTER TABLE shipments_bundle__carrier ADD CONSTRAINT FK_BCA5246BC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  28.         $this->addSql('ALTER TABLE shipments_bundle__carrier_context ADD CONSTRAINT FK_BC80A02921DFC797 FOREIGN KEY (carrier_id) REFERENCES shipments_bundle__carrier (id)');
  29.         $this->addSql('ALTER TABLE shipments_bundle__carrier_context ADD CONSTRAINT FK_BC80A0296B00C1CF FOREIGN KEY (context_id) REFERENCES context (id)');
  30.         $this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB18D9F6D38 FOREIGN KEY (order_id) REFERENCES sales_bundle__order (id)');
  31.         $this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB1CC799A1F FOREIGN KEY (burst_id) REFERENCES shipments_bundle__burst (id)');
  32.         $this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB12CF3B78B FOREIGN KEY (delivery_note_id) REFERENCES sales_bundle__delivery_note (id)');
  33.         $this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB121DFC797 FOREIGN KEY (carrier_id) REFERENCES shipments_bundle__carrier (id)');
  34.         $this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB1B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  35.         $this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB1896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  36.         $this->addSql('ALTER TABLE shipments_bundle__order_options ADD CONSTRAINT FK_3F7A5CB1C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  37.         $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)');
  38.     }
  39.     public function down(Schema $schema): void
  40.     {
  41.         $this->addSql('ALTER TABLE shipments_bundle__burst DROP FOREIGN KEY FK_561AB417B03A8386');
  42.         $this->addSql('ALTER TABLE shipments_bundle__burst DROP FOREIGN KEY FK_561AB417896DBBDE');
  43.         $this->addSql('ALTER TABLE shipments_bundle__burst DROP FOREIGN KEY FK_561AB417C76F1F52');
  44.         $this->addSql('ALTER TABLE shipments_bundle__carrier DROP FOREIGN KEY FK_BCA5246BB03A8386');
  45.         $this->addSql('ALTER TABLE shipments_bundle__carrier DROP FOREIGN KEY FK_BCA5246B896DBBDE');
  46.         $this->addSql('ALTER TABLE shipments_bundle__carrier DROP FOREIGN KEY FK_BCA5246BC76F1F52');
  47.         $this->addSql('ALTER TABLE shipments_bundle__carrier_context DROP FOREIGN KEY FK_BC80A02921DFC797');
  48.         $this->addSql('ALTER TABLE shipments_bundle__carrier_context DROP FOREIGN KEY FK_BC80A0296B00C1CF');
  49.         $this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB18D9F6D38');
  50.         $this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB1CC799A1F');
  51.         $this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB12CF3B78B');
  52.         $this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB121DFC797');
  53.         $this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB1B03A8386');
  54.         $this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB1896DBBDE');
  55.         $this->addSql('ALTER TABLE shipments_bundle__order_options DROP FOREIGN KEY FK_3F7A5CB1C76F1F52');
  56.         $this->addSql('ALTER TABLE shipments_bundle__order_state_for_burst DROP FOREIGN KEY FK_8656E32EE420DE70');
  57.         $this->addSql('DROP TABLE shipments_bundle__burst');
  58.         $this->addSql('DROP TABLE shipments_bundle__carrier');
  59.         $this->addSql('DROP TABLE shipments_bundle__carrier_context');
  60.         $this->addSql('DROP TABLE shipments_bundle__order_options');
  61.         $this->addSql('DROP TABLE shipments_bundle__order_state_for_burst');
  62.     }
  63.     public function postUp(Schema $schema): void
  64.     {
  65.         parent::postUp($schema);
  66.         $now = (new \DateTime())->format('Y-m-d H:i:s');
  67.         $fixtureFile dirname(__FILE__) . '/../src/Resources/views/Pdf/Fixtures/label.html.twig';
  68.         $configurations = [
  69.             'shipments_bundle__company_name' => 'Nom société',
  70.             'shipments_bundle__address' => 'adresse',
  71.             'shipments_bundle__city' => 'Troyes',
  72.             'shipments_bundle__zip_code' => '10000',
  73.             'shipments_bundle__phone' => '0123456789',
  74.             'shipments_bundle__language_iso' => 'FR',
  75.             'shipments_bundle__country_iso' => 'FR',
  76.             'shipments_bundle__delivery_note_and_label_merged' => 1,
  77.             'shipments_bundle__number_of_orders_per_burst' => 10,
  78.             'shipments_bundle__click_and_collect_pdf' => file_get_contents($fixtureFile),
  79.             'shipments_bundle__shared_carrier' => 1
  80.         ];
  81.         foreach ($configurations as $configuration => $value) {
  82.             $this->connection->insert('configuration', [
  83.                 'id' => (new UuidV6())->toBinary(),
  84.                 'name' => $configuration,
  85.                 'context_id' => null,
  86.                 'value' => $this->objectSerialize->add((object) ['value' => $value]),
  87.                 'created_at' => $now,
  88.                 'updated_at' => $now
  89.             ]);
  90.         }
  91.         $carrierId = (new UuidV6())->toBinary();
  92.         $this->connection->insert('shipments_bundle__carrier', [
  93.             'id' => $carrierId,
  94.             'name' => 'Click & Collect',
  95.             'module' => 'click_and_collect',
  96.             'created_at' => $now,
  97.             'updated_at' => $now
  98.         ]);
  99.         $contexts $this->connection->executeQuery('SELECT * FROM context WHERE deleted_at IS NULL')
  100.             ->fetchAllAssociative();
  101.         foreach ($contexts as $context) {
  102.             $carrierContextId = (new UuidV6())->toBinary();
  103.             $this->connection->insert('shipments_bundle__carrier_context', [
  104.                 'id' => $carrierContextId,
  105.                 'carrier_id' => $carrierId,
  106.                 'context_id' => $context['id']
  107.             ]);
  108.         }
  109.     }
  110. }