migrations/Expediting/Version20200308155022_ExpeditingItem.php line 1
<?php
declare(strict_types=1);
namespace DoctrineMigrations\Expediting;
use App\Doctrine\Type\Expediting\DeliveryPriority;
use App\Doctrine\Type\Expediting\ExpeditableStatus;
use App\Doctrine\Type\Expediting\ItemType;
use App\Doctrine\Type\Expediting\UnitOfMeasurement;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200308155022_ExpeditingItem extends AbstractMigration
{
public function getDescription(): string
{
return 'Add item table';
}
public function up(Schema $schema): void
{
$itemTypeType = ItemType::getName();
$expeditableStatusType = ExpeditableStatus::getName();
$unitOfMeasurementType = UnitOfMeasurement::getName();
$deliveryPriorityType = DeliveryPriority::getName();
$defaultPriority = DeliveryPriority::NORMAL->value;
$this->addSql("CREATE TABLE expediting_item (
id SERIAL PRIMARY KEY,
identifier UUID NOT NULL,
freight_id INTEGER NOT NULL REFERENCES public.expediting_freight (id),
customer_id INTEGER NOT NULL REFERENCES public.company (id),
asset_id INTEGER REFERENCES public.company_asset (id),
flow_id INTEGER REFERENCES public.purchasing_flow (id),
order_id INTEGER REFERENCES public.purchasing_order (id),
line_item_id INTEGER REFERENCES public.purchasing_line_item (id),
item_id INTEGER REFERENCES public.expediting_item (id),
type {$itemTypeType} NOT NULL,
slug CHARACTER VARYING NOT NULL,
status {$expeditableStatusType} NOT NULL,
reference CHARACTER VARYING,
number CHARACTER VARYING,
material_number CHARACTER VARYING,
package_number CHARACTER VARYING,
unit_of_measurement {$unitOfMeasurementType},
requested_delivery_on DATE,
supplier_description CHARACTER VARYING,
client_description CHARACTER VARYING,
quantity INTEGER,
unit_price DECIMAL(18, 5),
value DECIMAL(18, 5),
packed BOOLEAN DEFAULT false,
-- Shipping
priority {$deliveryPriorityType} DEFAULT '{$defaultPriority}',
high_value BOOLEAN DEFAULT false,
high_volume BOOLEAN DEFAULT false,
high_risk BOOLEAN DEFAULT false,
expeditable BOOLEAN DEFAULT false,
dangerous BOOLEAN DEFAULT false,
prohibited BOOLEAN DEFAULT false,
-- QA/QC
certified BOOLEAN DEFAULT false,
fat_required BOOLEAN DEFAULT false,
-- Catalogue
unique_part BOOLEAN DEFAULT false,
manufactured BOOLEAN DEFAULT false,
listed BOOLEAN DEFAULT false,
retired BOOLEAN DEFAULT false,
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_item_slug_key UNIQUE (slug),
CONSTRAINT expediting_item_reference_key UNIQUE (reference),
CONSTRAINT expediting_item_identifier_key UNIQUE (identifier)
)");
//, CONSTRAINT expediting_item_package_number_key UNIQUE (line_item_id, package_number)
$this->addSql("COMMENT ON COLUMN expediting_item.identifier IS '(DC2Type:ulid)'");
$this->addSql("CREATE INDEX expediting_item_freight_id_idx ON expediting_item (freight_id)");
$this->addSql("CREATE INDEX expediting_item_item_id_idx ON expediting_item (item_id)");
$this->addSql("CREATE INDEX expediting_item_order_id_idx ON expediting_item (order_id)");
$this->addSql("CREATE INDEX expediting_item_line_item_id_idx ON expediting_item (line_item_id)");
$this->addSql("CREATE INDEX expediting_item_customer_id_idx ON expediting_item (customer_id)");
$this->addSql("CREATE INDEX expediting_item_asset_id_idx ON expediting_item (asset_id)");
$this->addSql("CREATE INDEX expediting_item_flow_id_idx ON expediting_item (flow_id)");
$this->addSql("CREATE INDEX expediting_item_created_by_idx ON expediting_item (created_by)");
$this->addSql("CREATE INDEX expediting_item_updated_by_idx ON expediting_item (updated_by)");
}
public function down(Schema $schema): void
{
$this->addSql("DROP TABLE IF EXISTS expediting_item");
}
}