migrations/Sales/Version20200303104729_Contract.php line 1
<?php
declare(strict_types=1);
namespace DoctrineMigrations\Sales;
use App\Doctrine\Type\Sales\ContractStatus;
use App\Doctrine\Type\Sales\ContractType;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200303104729_Contract extends AbstractMigration
{
public function getDescription(): string
{
return 'Add contract table';
}
public function up(Schema $schema): void
{
$this->addSql(ContractType::getRegistrationSQL());
$this->addSql(ContractStatus::getRegistrationSQL());
$contractTypeType = ContractType::getName();
$contractStatusType = ContractStatus::getName();
$defaultStatus = ContractStatus::ONGOING->value;
$this->addSql("CREATE TABLE contract (
id SERIAL PRIMARY KEY,
slug CHARACTER VARYING NOT NULL,
number CHARACTER VARYING NOT NULL,
tenant_id INTEGER NOT NULL REFERENCES public.company (id),
client_id INTEGER NOT NULL REFERENCES public.company (id),
starting_on DATE NOT NULL DEFAULT CURRENT_DATE,
ending_on DATE,
type {$contractTypeType} NOT NULL,
status {$contractStatusType} 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 contract_slug_key UNIQUE (slug),
CONSTRAINT contract_number_key UNIQUE (number)
)");
$this->addSql("CREATE INDEX contract_tenant_id_idx ON contract (tenant_id)");
$this->addSql("CREATE INDEX contract_client_id_idx ON contract (client_id)");
$this->addSql("CREATE INDEX contract_created_by_idx ON contract (created_by)");
$this->addSql("CREATE INDEX contract_updated_by_idx ON contract (updated_by)");
}
public function down(Schema $schema): void
{
$this->addSql("DROP TABLE IF EXISTS contract");
$this->addSql(ContractStatus::getDeletionSQL());
$this->addSql(ContractType::getDeletionSQL());
}
}