migrations/Identity/Version20200227095952_User.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations\Identity;
  4. use App\Doctrine\Type\Identity\UserGender;
  5. use App\Doctrine\Type\Identity\UserRole;
  6. use App\Doctrine\Type\Identity\UserStatus;
  7. use Doctrine\DBAL\Schema\Schema;
  8. use Doctrine\Migrations\AbstractMigration;
  9. /**
  10.  * Auto-generated Migration: Please modify to your needs!
  11.  */
  12. final class Version20200227095952_User extends AbstractMigration
  13. {
  14.     public function getDescription(): string
  15.     {
  16.         return 'Create user table';
  17.     }
  18.     public function up(Schema $schema): void
  19.     {
  20.         $userRolesType UserRole::getName(asArraytrue);
  21.         $userGenderType UserGender::getName();
  22.         $userStatusType UserStatus::getName();
  23.         $defaultRole UserRole::ROLE_USER->value;
  24.         $defaultStatus UserStatus::CREATED->value;
  25.         $this->addSql("CREATE TABLE public.user (
  26.             id                  SERIAL PRIMARY KEY,
  27.             identifier          UUID                        NOT NULL,
  28.             company_id          INTEGER,
  29.             avatar_id           INTEGER,
  30.             password            CHARACTER VARYING,
  31.             position            CHARACTER VARYING,
  32.             first_name          CHARACTER VARYING,
  33.             last_name           CHARACTER VARYING,
  34.             born_on             DATE,
  35.             roles               {$userRolesType}            NOT NULL DEFAULT '{{$defaultRole}}',
  36.             status              {$userStatusType}           NOT NULL DEFAULT '{$defaultStatus}',
  37.             gender              {$userGenderType},
  38.             settings            JSONB                       NOT NULL,
  39.             created_by          INTEGER                              REFERENCES public.user (id),
  40.             updated_by          INTEGER                              REFERENCES public.user (id),
  41.             created_at          TIMESTAMP(0) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
  42.             updated_at          TIMESTAMP(0) WITH TIME ZONE,
  43.             deleted_at          TIMESTAMP(0) WITH TIME ZONE,
  44.             CONSTRAINT user_identifier_key UNIQUE (identifier)
  45.         )");
  46.         $this->addSql("COMMENT ON COLUMN public.user.identifier IS '(DC2Type:ulid)'");
  47.         $this->addSql("COMMENT ON COLUMN public.user.settings IS '(DC2Type:json_document)'");
  48.         $this->addSql("CREATE INDEX user_avatar_id_idx ON public.user (avatar_id)");
  49.         $this->addSql("CREATE INDEX user_company_id_idx ON public.user (company_id)");
  50.         $this->addSql("CREATE INDEX user_created_by_idx ON public.user (created_by)");
  51.         $this->addSql("CREATE INDEX user_updated_by_idx ON public.user (updated_by)");
  52.     }
  53.     public function down(Schema $schema): void
  54.     {
  55.         $this->addSql("DROP TABLE IF EXISTS public.user");
  56.     }
  57. }