migrations/Version20190829043821.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20190829043821 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'Add \'one-to-one\' relation between user and manager / developer';
  14.     }
  15.     /**
  16.      * @throws \Doctrine\DBAL\DBALException
  17.      */
  18.     public function up(Schema $schema): void
  19.     {
  20.         // this up() migration is auto-generated, please modify it to your needs
  21.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql''Migration can only be executed safely on \'postgresql\'.');
  22.         $this->addSql('ALTER TABLE hub_user ADD manager_id UUID DEFAULT NULL');
  23.         $this->addSql('ALTER TABLE hub_user ADD developer_id UUID DEFAULT NULL');
  24.         $this->addSql('COMMENT ON COLUMN hub_user.manager_id IS \'(DC2Type:uuid)\'');
  25.         $this->addSql('COMMENT ON COLUMN hub_user.developer_id IS \'(DC2Type:uuid)\'');
  26.         $this->addSql('ALTER TABLE hub_user ADD CONSTRAINT FK_8BD464F5783E3463 FOREIGN KEY (manager_id) REFERENCES manager (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  27.         $this->addSql('ALTER TABLE hub_user ADD CONSTRAINT FK_8BD464F564DD9267 FOREIGN KEY (developer_id) REFERENCES developer (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  28.         $this->addSql('CREATE UNIQUE INDEX UNIQ_8BD464F5783E3463 ON hub_user (manager_id)');
  29.         $this->addSql('CREATE UNIQUE INDEX UNIQ_8BD464F564DD9267 ON hub_user (developer_id)');
  30.         $this->addSql('DROP INDEX idx_65fb8b9aa76ed395');
  31.         $this->addSql('CREATE UNIQUE INDEX UNIQ_65FB8B9AA76ED395 ON developer (user_id)');
  32.         $this->addSql('DROP INDEX idx_fa2425b9a76ed395');
  33.         $this->addSql('CREATE UNIQUE INDEX UNIQ_FA2425B9A76ED395 ON manager (user_id)');
  34.     }
  35.     /**
  36.      * @throws \Doctrine\DBAL\DBALException
  37.      */
  38.     public function down(Schema $schema): void
  39.     {
  40.         // this down() migration is auto-generated, please modify it to your needs
  41.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql''Migration can only be executed safely on \'postgresql\'.');
  42.         $this->addSql('DROP INDEX UNIQ_65FB8B9AA76ED395');
  43.         $this->addSql('CREATE INDEX idx_65fb8b9aa76ed395 ON developer (user_id)');
  44.         $this->addSql('DROP INDEX UNIQ_FA2425B9A76ED395');
  45.         $this->addSql('CREATE INDEX idx_fa2425b9a76ed395 ON manager (user_id)');
  46.         $this->addSql('ALTER TABLE hub_user DROP CONSTRAINT FK_8BD464F5783E3463');
  47.         $this->addSql('ALTER TABLE hub_user DROP CONSTRAINT FK_8BD464F564DD9267');
  48.         $this->addSql('DROP INDEX UNIQ_8BD464F5783E3463');
  49.         $this->addSql('DROP INDEX UNIQ_8BD464F564DD9267');
  50.         $this->addSql('ALTER TABLE hub_user DROP manager_id');
  51.         $this->addSql('ALTER TABLE hub_user DROP developer_id');
  52.     }
  53. }