migrations/Expediting/Version20200308115049_ExpeditingFreight.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations\Expediting;
  4. use App\Doctrine\Type\Expediting\DeliveryPriority;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. /**
  8.  * Auto-generated Migration: Please modify to your needs!
  9.  */
  10. final class Version20200308115049_ExpeditingFreight extends AbstractMigration
  11. {
  12.     public function getDescription(): string
  13.     {
  14.         return 'Add freight table';
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         $deliveryPriorityType DeliveryPriority::getName();
  19.         $defaultPriority DeliveryPriority::NORMAL->value;
  20.         $this->addSql("CREATE TABLE expediting_freight (
  21.             id                              SERIAL PRIMARY KEY,
  22.             slug                            CHARACTER VARYING           NOT NULL,
  23.             reference                       CHARACTER VARYING           NOT NULL,
  24.             identifier                      UUID                        NOT NULL,
  25.             work_order_id                   INTEGER                     NOT NULL REFERENCES public.work_order (id),
  26.             order_id                        INTEGER                              REFERENCES public.purchasing_order (id),
  27.             available_on                    DATE                        NOT NULL,
  28.             value                           DECIMAL(18, 5),
  29.             invoices_numbers                JSON,
  30.             -- Shipping
  31.             priority                        {$deliveryPriorityType}              DEFAULT '{$defaultPriority}',
  32.             high_value                      BOOLEAN                              DEFAULT false,
  33.             high_volume                     BOOLEAN                              DEFAULT false,
  34.             high_risk                       BOOLEAN                              DEFAULT false,
  35.             expeditable                     BOOLEAN                              DEFAULT false,
  36.             dangerous                       BOOLEAN                              DEFAULT false,
  37.             prohibited                      BOOLEAN                              DEFAULT false,
  38.             -- Tracking
  39.             delayed                         BOOLEAN                              DEFAULT false,
  40.             location                        CHARACTER VARYING,
  41.             created_by                      INTEGER                     NOT NULL REFERENCES public.user (id),
  42.             updated_by                      INTEGER                              REFERENCES public.user (id),
  43.             created_at                      TIMESTAMP(0) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
  44.             updated_at                      TIMESTAMP(0) WITH TIME ZONE,
  45.             deleted_at                      TIMESTAMP(0) WITH TIME ZONE,
  46.             CONSTRAINT expediting_freight_identifier_key UNIQUE (identifier)
  47.         )");
  48.         $this->addSql("COMMENT ON COLUMN expediting_freight.identifier IS '(DC2Type:ulid)'");
  49.         $this->addSql("CREATE INDEX expediting_freight_work_order_id_idx ON expediting_freight (work_order_id)");
  50.         $this->addSql("CREATE INDEX expediting_freight_order_id_idx ON expediting_freight (order_id)");
  51.         $this->addSql("CREATE INDEX expediting_freight_created_by_idx ON expediting_freight (created_by)");
  52.         $this->addSql("CREATE INDEX expediting_freight_updated_by_idx ON expediting_freight (updated_by)");
  53.     }
  54.     public function down(Schema $schema): void
  55.     {
  56.         $this->addSql("DROP TABLE IF EXISTS expediting_freight");
  57.     }
  58. }