<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20190829043821 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add \'one-to-one\' relation between user and manager / developer';
}
/**
* @throws \Doctrine\DBAL\DBALException
*/
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE hub_user ADD manager_id UUID DEFAULT NULL');
$this->addSql('ALTER TABLE hub_user ADD developer_id UUID DEFAULT NULL');
$this->addSql('COMMENT ON COLUMN hub_user.manager_id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN hub_user.developer_id IS \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE hub_user ADD CONSTRAINT FK_8BD464F5783E3463 FOREIGN KEY (manager_id) REFERENCES manager (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE hub_user ADD CONSTRAINT FK_8BD464F564DD9267 FOREIGN KEY (developer_id) REFERENCES developer (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8BD464F5783E3463 ON hub_user (manager_id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8BD464F564DD9267 ON hub_user (developer_id)');
$this->addSql('DROP INDEX idx_65fb8b9aa76ed395');
$this->addSql('CREATE UNIQUE INDEX UNIQ_65FB8B9AA76ED395 ON developer (user_id)');
$this->addSql('DROP INDEX idx_fa2425b9a76ed395');
$this->addSql('CREATE UNIQUE INDEX UNIQ_FA2425B9A76ED395 ON manager (user_id)');
}
/**
* @throws \Doctrine\DBAL\DBALException
*/
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('DROP INDEX UNIQ_65FB8B9AA76ED395');
$this->addSql('CREATE INDEX idx_65fb8b9aa76ed395 ON developer (user_id)');
$this->addSql('DROP INDEX UNIQ_FA2425B9A76ED395');
$this->addSql('CREATE INDEX idx_fa2425b9a76ed395 ON manager (user_id)');
$this->addSql('ALTER TABLE hub_user DROP CONSTRAINT FK_8BD464F5783E3463');
$this->addSql('ALTER TABLE hub_user DROP CONSTRAINT FK_8BD464F564DD9267');
$this->addSql('DROP INDEX UNIQ_8BD464F5783E3463');
$this->addSql('DROP INDEX UNIQ_8BD464F564DD9267');
$this->addSql('ALTER TABLE hub_user DROP manager_id');
$this->addSql('ALTER TABLE hub_user DROP developer_id');
}
}