migrations/Expediting/Version20200310163721_ExpeditingShippingSegment.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations\Expediting;
  4. use App\Doctrine\Type\Expediting\DeliveryPriority;
  5. use App\Doctrine\Type\Expediting\ExpeditingStatus;
  6. use App\Doctrine\Type\Expediting\ShippingSegmentStatus;
  7. use App\Doctrine\Type\Expediting\ShipmentType;
  8. use App\Doctrine\Type\Expediting\TransportMode;
  9. use App\Doctrine\Type\Expediting\TransportSpecification;
  10. use Doctrine\DBAL\Schema\Schema;
  11. use Doctrine\Migrations\AbstractMigration;
  12. /**
  13.  * Auto-generated Migration: Please modify to your needs!
  14.  */
  15. final class Version20200310163721_ExpeditingShippingSegment extends AbstractMigration
  16. {
  17.     public function getDescription(): string
  18.     {
  19.         return 'Add shipping segments table';
  20.     }
  21.     public function up(Schema $schema): void
  22.     {
  23.         $deliveryPriorityType DeliveryPriority::getName();
  24.         $shippingSegmentStatusType ShippingSegmentStatus::getName();
  25.         $transferTypeType ShipmentType::getName(asArraytrue);
  26.         $transportModeType TransportMode::getName();
  27.         $transportSpecificationType TransportSpecification::getName();
  28.         $defaultPriority DeliveryPriority::NORMAL->value;
  29.         $defaultStatus ExpeditingStatus::PLANNED->value;
  30.         $defaultTransportSpec TransportSpecification::STANDARD->value;
  31.         $this->addSql("CREATE TABLE expediting_shipping_segment (
  32.             id                              SERIAL PRIMARY KEY,
  33.             identifier                      UUID                               NOT NULL,
  34.             shipping_plan_id                INTEGER                            NOT NULL REFERENCES public.expediting_shipping_plan (id),
  35.             status                          {$shippingSegmentStatusType}       NOT NULL DEFAULT '{$defaultStatus}',
  36.             types                           {$transferTypeType},
  37.             etd                             DATE,
  38.             eta                             DATE,
  39.             -- Shipping
  40.             shipper_id                      INTEGER                                REFERENCES public.company (id),
  41.             consignee_id                    INTEGER                                REFERENCES public.company (id),
  42.             notify_party_id                 INTEGER                                REFERENCES public.company (id),
  43.             place_of_loading_id             INTEGER                                REFERENCES public.place (id),
  44.             place_of_discharge_id           INTEGER                                REFERENCES public.place (id),
  45.             currency                        CHARACTER VARYING(3),
  46.             freight_value                   DECIMAL(18, 5),
  47.             -- Transport
  48.             bill_number                     CHARACTER VARYING,
  49.             booking_number                  CHARACTER VARYING,
  50.             vector_reference                CHARACTER VARYING,
  51.             transport_mode                  {$transportModeType}          NOT NULL,
  52.             transport_company_id            INTEGER                                REFERENCES public.company (id),
  53.             driver_id                       INTEGER                                REFERENCES public.fleet_driver (id),
  54.             vehicle_id                      INTEGER                                REFERENCES public.fleet_vehicle (id),
  55.             transport_specification         {$transportSpecificationType} NOT NULL DEFAULT '{$defaultTransportSpec}',
  56.             -- QA/QC
  57.             priority                        {$deliveryPriorityType}                DEFAULT '{$defaultPriority}',
  58.             high_value                      BOOLEAN                                DEFAULT false,
  59.             high_volume                     BOOLEAN                                DEFAULT false,
  60.             high_risk                       BOOLEAN                                DEFAULT false,
  61.             expeditable                     BOOLEAN                                DEFAULT false,
  62.             dangerous                       BOOLEAN                                DEFAULT false,
  63.             prohibited                      BOOLEAN                                DEFAULT false,
  64.             delayed                         BOOLEAN                                DEFAULT false,
  65.             created_by                      INTEGER                            NOT NULL REFERENCES public.user (id),
  66.             updated_by                      INTEGER                                     REFERENCES public.user (id),
  67.             created_at                      TIMESTAMP(0) WITH TIME ZONE        NOT NULL DEFAULT CURRENT_TIMESTAMP,
  68.             updated_at                      TIMESTAMP(0) WITH TIME ZONE,
  69.             deleted_at                      TIMESTAMP(0) WITH TIME ZONE,
  70.             CONSTRAINT expediting_shipping_segment_identifier_key UNIQUE (identifier)
  71.         )");
  72.         $this->addSql("COMMENT ON COLUMN expediting_shipping_segment.identifier IS '(DC2Type:ulid)'");
  73.         $this->addSql("CREATE INDEX expediting_shipping_segment_driver_id_idx ON expediting_shipping_segment (driver_id)");
  74.         $this->addSql("CREATE INDEX expediting_shipping_segment_vehicle_id_idx ON expediting_shipping_segment (vehicle_id)");
  75.         $this->addSql("CREATE INDEX expediting_shipping_segment_shipper_id_idx ON expediting_shipping_segment (shipper_id)");
  76.         $this->addSql("CREATE INDEX expediting_shipping_segment_consignee_id_idx ON expediting_shipping_segment (consignee_id)");
  77.         $this->addSql("CREATE INDEX expediting_shipping_segment_notify_party_id_idx ON expediting_shipping_segment (notify_party_id)");
  78.         $this->addSql("CREATE INDEX expediting_shipping_segment_transport_company_id_idx ON expediting_shipping_segment (transport_company_id)");
  79.         $this->addSql("CREATE INDEX expediting_shipping_segment_shipping_plan_id_idx ON expediting_shipping_segment (shipping_plan_id)");
  80.         $this->addSql("CREATE INDEX expediting_shipping_segment_place_of_loading_id_idx ON expediting_shipping_segment (place_of_loading_id)");
  81.         $this->addSql("CREATE INDEX expediting_shipping_segment_place_of_discharge_id_idx ON expediting_shipping_segment (place_of_discharge_id)");
  82.         $this->addSql("CREATE INDEX expediting_shipping_segment_created_by_idx ON expediting_shipping_segment (created_by)");
  83.         $this->addSql("CREATE INDEX expediting_shipping_segment_updated_by_idx ON expediting_shipping_segment (updated_by)");
  84.     }
  85.     public function down(Schema $schema): void
  86.     {
  87.         $this->addSql("DROP TABLE IF EXISTS expediting_shipping_segment");
  88.     }
  89. }