migrations/Sales/Version20200303132432_WorkOrder.php line 1
<?php
declare(strict_types=1);
namespace DoctrineMigrations\Sales;
use App\Doctrine\Type\Sales\Incoterm;
use App\Doctrine\Type\Sales\WorkOrderStatus;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200303132432_WorkOrder extends AbstractMigration
{
public function getDescription(): string
{
return 'Add work order table';
}
public function up(Schema $schema): void
{
$this->addSql(Incoterm::getRegistrationSQL());
$this->addSql(WorkOrderStatus::getRegistrationSQL());
$incotermType = Incoterm::getName();
$workOrderStatusType = WorkOrderStatus::getName();
$defaultStatus = WorkOrderStatus::DRAFTED->value;
$this->addSql("CREATE TABLE work_order (
id SERIAL PRIMARY KEY,
slug CHARACTER VARYING NOT NULL,
reference CHARACTER VARYING NOT NULL,
issued_by INTEGER REFERENCES public.user (id),
client_id INTEGER NOT NULL REFERENCES public.company (id),
supplier_id INTEGER REFERENCES public.company (id),
contract_id INTEGER REFERENCES public.contract (id),
place_of_loading_id INTEGER NOT NULL REFERENCES public.place (id),
place_of_discharge_id INTEGER NOT NULL REFERENCES public.place (id),
source_id INTEGER REFERENCES public.file (id),
datasheet JSONB NOT NULL,
status {$workOrderStatusType} NOT NULL DEFAULT '{$defaultStatus}',
incoterm {$incotermType},
requested_on DATE NOT NULL,
available_on DATE NOT NULL,
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 work_order_slug_key UNIQUE (slug),
CONSTRAINT work_order_reference_key UNIQUE (reference),
CONSTRAINT work_order_source_id_key UNIQUE (source_id)
)");
$this->addSql("COMMENT ON COLUMN work_order.datasheet IS '(DC2Type:json_document)'");
$this->addSql("CREATE INDEX work_order_issued_by_idx ON work_order (issued_by)");
$this->addSql("CREATE INDEX work_order_client_id_idx ON work_order (client_id)");
$this->addSql("CREATE INDEX work_order_supplier_id_idx ON work_order (supplier_id)");
$this->addSql("CREATE INDEX work_order_contract_id_idx ON work_order (contract_id)");
$this->addSql("CREATE INDEX work_order_place_of_loading_id_idx ON work_order (place_of_loading_id)");
$this->addSql("CREATE INDEX work_order_place_of_discharge_id_idx ON work_order (place_of_discharge_id)");
$this->addSql("CREATE INDEX work_order_source_id_idx ON work_order (source_id)");
$this->addSql("CREATE INDEX work_order_created_by_idx ON work_order (created_by)");
$this->addSql("CREATE INDEX work_order_updated_by_idx ON work_order (updated_by)");
}
public function down(Schema $schema): void
{
$this->addSql("DROP TABLE IF EXISTS work_order");
$this->addSql(WorkOrderStatus::getDeletionSQL());
$this->addSql(Incoterm::getDeletionSQL());
}
}