migrations/Expediting/Version20200310151649_ExpeditingShippingPlan.php line 1
<?php
declare(strict_types=1);
namespace DoctrineMigrations\Expediting;
use App\Doctrine\Type\Expediting\ShippingPlanStatus;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200310151649_ExpeditingShippingPlan extends AbstractMigration
{
public function getDescription(): string
{
return 'Add shipping plan table';
}
public function up(Schema $schema): void
{
$shippingPlanStatusType = ShippingPlanStatus::getName();
$defaultStatus = ShippingPlanStatus::DRAFTED->value;
$this->addSql("CREATE TABLE expediting_shipping_plan (
id SERIAL PRIMARY KEY,
identifier UUID NOT NULL,
work_order_id INTEGER REFERENCES public.work_order (id),
shipment_id INTEGER REFERENCES public.expediting_shipment (id),
original_plan_id INTEGER REFERENCES public.expediting_shipping_plan (id),
status {$shippingPlanStatusType} NOT NULL DEFAULT '{$defaultStatus}',
created_by INTEGER NOT NULL REFERENCES public.user (id),
updated_by INTEGER REFERENCES public.user (id),
created_at TIMESTAMP(0) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP(0) WITH TIME ZONE,
deleted_at TIMESTAMP(0) WITH TIME ZONE,
CONSTRAINT expediting_shipping_plan_original_plan_id_key UNIQUE (original_plan_id),
CONSTRAINT expediting_shipping_plan_identifier_key UNIQUE (identifier),
CONSTRAINT expediting_shipping_plan_xor_shipment CHECK (
(work_order_id IS NOT NULL AND shipment_id IS NULL) OR
(work_order_id IS NULL AND shipment_id IS NOT NULL)
)
)");
$this->addSql("COMMENT ON COLUMN expediting_shipping_plan.identifier IS '(DC2Type:ulid)'");
$this->addSql("CREATE INDEX expediting_shipping_plan_original_plan_id_idx ON expediting_shipping_plan (original_plan_id)");
$this->addSql("CREATE INDEX expediting_shipping_plan_work_order_id_idx ON expediting_shipping_plan (work_order_id)");
$this->addSql("CREATE INDEX expediting_shipping_plan_shipment_id_idx ON expediting_shipping_plan (shipment_id)");
$this->addSql("CREATE INDEX expediting_shipping_plan_created_by_idx ON expediting_shipping_plan (created_by)");
$this->addSql("CREATE INDEX expediting_shipping_plan_updated_by_idx ON expediting_shipping_plan (updated_by)");
}
public function down(Schema $schema): void
{
$this->addSql("DROP TABLE IF EXISTS expediting_shipping_plan");
}
}