migrations/Expediting/Version20200310151649_ExpeditingShippingPlan.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations\Expediting;
  4. use App\Doctrine\Type\Expediting\ShippingPlanStatus;
  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 Version20200310151649_ExpeditingShippingPlan extends AbstractMigration
  11. {
  12.     public function getDescription(): string
  13.     {
  14.         return 'Add shipping plan table';
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         $shippingPlanStatusType ShippingPlanStatus::getName();
  19.         $defaultStatus ShippingPlanStatus::DRAFTED->value;
  20.         $this->addSql("CREATE TABLE expediting_shipping_plan (
  21.             id                              SERIAL PRIMARY KEY,
  22.             identifier                      UUID                          NOT NULL,
  23.             work_order_id                   INTEGER                                REFERENCES public.work_order (id),
  24.             shipment_id                     INTEGER                                REFERENCES public.expediting_shipment (id),
  25.             original_plan_id                INTEGER                                REFERENCES public.expediting_shipping_plan (id),
  26.             status                          {$shippingPlanStatusType}     NOT NULL DEFAULT '{$defaultStatus}',
  27.             created_by                      INTEGER                       NOT NULL REFERENCES public.user (id),
  28.             updated_by                      INTEGER                                REFERENCES public.user (id),
  29.             created_at                      TIMESTAMP(0) WITH TIME ZONE   NOT NULL DEFAULT CURRENT_TIMESTAMP,
  30.             updated_at                      TIMESTAMP(0) WITH TIME ZONE,
  31.             deleted_at                      TIMESTAMP(0) WITH TIME ZONE,
  32.             CONSTRAINT expediting_shipping_plan_original_plan_id_key UNIQUE (original_plan_id),
  33.             CONSTRAINT expediting_shipping_plan_identifier_key UNIQUE (identifier),
  34.             CONSTRAINT expediting_shipping_plan_xor_shipment CHECK (
  35.                 (work_order_id IS NOT NULL AND shipment_id IS     NULL) OR
  36.                 (work_order_id IS     NULL AND shipment_id IS NOT NULL)
  37.             )
  38.         )");
  39.         $this->addSql("COMMENT ON COLUMN expediting_shipping_plan.identifier IS '(DC2Type:ulid)'");
  40.         $this->addSql("CREATE INDEX expediting_shipping_plan_original_plan_id_idx ON expediting_shipping_plan (original_plan_id)");
  41.         $this->addSql("CREATE INDEX expediting_shipping_plan_work_order_id_idx ON expediting_shipping_plan (work_order_id)");
  42.         $this->addSql("CREATE INDEX expediting_shipping_plan_shipment_id_idx ON expediting_shipping_plan (shipment_id)");
  43.         $this->addSql("CREATE INDEX expediting_shipping_plan_created_by_idx ON expediting_shipping_plan (created_by)");
  44.         $this->addSql("CREATE INDEX expediting_shipping_plan_updated_by_idx ON expediting_shipping_plan (updated_by)");
  45.     }
  46.     public function down(Schema $schema): void
  47.     {
  48.         $this->addSql("DROP TABLE IF EXISTS expediting_shipping_plan");
  49.     }
  50. }