migrations/Identity/Version20200227095952_User.php line 1
<?php
declare(strict_types=1);
namespace DoctrineMigrations\Identity;
use App\Doctrine\Type\Identity\UserGender;
use App\Doctrine\Type\Identity\UserRole;
use App\Doctrine\Type\Identity\UserStatus;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200227095952_User extends AbstractMigration
{
public function getDescription(): string
{
return 'Create user table';
}
public function up(Schema $schema): void
{
$userRolesType = UserRole::getName(asArray: true);
$userGenderType = UserGender::getName();
$userStatusType = UserStatus::getName();
$defaultRole = UserRole::ROLE_USER->value;
$defaultStatus = UserStatus::CREATED->value;
$this->addSql("CREATE TABLE public.user (
id SERIAL PRIMARY KEY,
identifier UUID NOT NULL,
company_id INTEGER,
avatar_id INTEGER,
password CHARACTER VARYING,
position CHARACTER VARYING,
first_name CHARACTER VARYING,
last_name CHARACTER VARYING,
born_on DATE,
roles {$userRolesType} NOT NULL DEFAULT '{{$defaultRole}}',
status {$userStatusType} NOT NULL DEFAULT '{$defaultStatus}',
gender {$userGenderType},
settings JSONB NOT NULL,
created_by INTEGER 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 user_identifier_key UNIQUE (identifier)
)");
$this->addSql("COMMENT ON COLUMN public.user.identifier IS '(DC2Type:ulid)'");
$this->addSql("COMMENT ON COLUMN public.user.settings IS '(DC2Type:json_document)'");
$this->addSql("CREATE INDEX user_avatar_id_idx ON public.user (avatar_id)");
$this->addSql("CREATE INDEX user_company_id_idx ON public.user (company_id)");
$this->addSql("CREATE INDEX user_created_by_idx ON public.user (created_by)");
$this->addSql("CREATE INDEX user_updated_by_idx ON public.user (updated_by)");
}
public function down(Schema $schema): void
{
$this->addSql("DROP TABLE IF EXISTS public.user");
}
}