migrations/Identity/Version20200227100835_UserPassport.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations\Identity;
  4. use App\Doctrine\Type\Identity\PassportType;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. /**
  8.  * Auto-generated Migration: Please modify to your needs!
  9.  */
  10. final class Version20200227100835_UserPassport extends AbstractMigration
  11. {
  12.     public function getDescription(): string
  13.     {
  14.         return 'Create identity table';
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         $passportType PassportType::getName();
  19.         $this->addSql("CREATE TABLE user_passport (
  20.             id                  SERIAL PRIMARY KEY,
  21.             owner_id            INTEGER                     NOT NULL REFERENCES public.user (id),
  22.             value               CHARACTER VARYING           NOT NULL,
  23.             verified            BOOLEAN,
  24.             is_main             BOOLEAN,
  25.             type                {$passportType}             NOT NULL,
  26.             created_by          INTEGER                              REFERENCES public.user (id),
  27.             updated_by          INTEGER                              REFERENCES public.user (id),
  28.             created_at          TIMESTAMP(0) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
  29.             updated_at          TIMESTAMP(0) WITH TIME ZONE,
  30.             deleted_at          TIMESTAMP(0) WITH TIME ZONE,
  31.             CONSTRAINT user_passport_value_key UNIQUE (value)
  32.         )");
  33.         $this->addSql("CREATE INDEX user_passport_owner_id_idx ON user_passport (owner_id)");
  34.         $this->addSql("CREATE INDEX user_passport_created_by_idx ON user_passport (created_by)");
  35.         $this->addSql("CREATE INDEX user_passport_updated_by_idx ON user_passport (updated_by)");
  36.     }
  37.     public function down(Schema $schema): void
  38.     {
  39.         $this->addSql("DROP TABLE IF EXISTS user_passport");
  40.     }
  41. }