migrations/Common/Version20200301104321_Company.php line 1
<?php
declare(strict_types=1);
namespace DoctrineMigrations\Common;
use App\Doctrine\Type\Common\CompanyStatus;
use App\Doctrine\Type\Common\CompanyType;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200301104321_Company extends AbstractMigration
{
public function getDescription(): string
{
return 'Add company table';
}
public function up(Schema $schema): void
{
$this->addSql(CompanyType::getRegistrationSQL());
$this->addSql(CompanyStatus::getRegistrationSQL());
$companyTypesType = CompanyType::getName(asArray: true);
$companyStatusType = CompanyStatus::getName();
$defaultStatus = CompanyStatus::ACTIVE->value;
$this->addSql("CREATE TABLE company (
id SERIAL PRIMARY KEY,
parent_id INTEGER REFERENCES public.company (id),
slug CHARACTER VARYING NOT NULL,
name CHARACTER VARYING NOT NULL,
code CHARACTER VARYING NOT NULL,
trade_register CHARACTER VARYING,
tax_identification_number CHARACTER VARYING,
types {$companyTypesType},
served_continents JSON,
served_countries JSON,
status {$companyStatusType} NOT NULL DEFAULT '{$defaultStatus}',
logo_id INTEGER REFERENCES public.file (id),
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 company_slug_key UNIQUE (slug),
CONSTRAINT company_name_key UNIQUE (name),
CONSTRAINT company_code_key UNIQUE (code)
)");
$this->addSql("CREATE INDEX company_logo_id_idx ON company (logo_id)");
$this->addSql("CREATE INDEX company_parent_id_idx ON company (parent_id)");
$this->addSql("CREATE INDEX company_created_by_idx ON company (created_by)");
$this->addSql("CREATE INDEX company_updated_by_idx ON company (updated_by)");
}
public function down(Schema $schema): void
{
$this->addSql("DROP TABLE IF EXISTS company");
$this->addSql(CompanyType::getDeletionSQL());
$this->addSql(CompanyStatus::getDeletionSQL());
}
}