<?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 Version20190817123213 extends AbstractMigration
{
public function getDescription(): string
{
return 'Tmetric data tables and relations';
}
/**
* @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('CREATE TABLE tmetric_user (
id UUID NOT NULL,
user_id UUID DEFAULT NULL,
user_profile_id INT DEFAULT NULL,
active_account_id INT DEFAULT NULL,
user_name VARCHAR(255) DEFAULT NULL,
date_format VARCHAR(255) DEFAULT \'DD.MM.YYYY\' NOT NULL,
time_format VARCHAR(255) DEFAULT \'H:mm\' NOT NULL,
show_breaks BOOLEAN DEFAULT \'true\' NOT NULL,
registration_date TIMESTAMP(0) WITH TIME ZONE NOT NULL,
time_zone_info VARCHAR(255) DEFAULT \'Asia/Yekaterinburg\' NOT NULL,
is_registered BOOLEAN DEFAULT \'true\' NOT NULL,
email VARCHAR(255) NOT NULL, PRIMARY KEY(id))'
);
$this->addSql('CREATE UNIQUE INDEX UNIQ_35F74956A76ED395 ON tmetric_user (user_id)');
$this->addSql('COMMENT ON COLUMN tmetric_user.id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN tmetric_user.user_id IS \'(DC2Type:uuid)\'');
$this->addSql('CREATE TABLE tmetric_account (
id UUID NOT NULL,
api_key VARCHAR(255) DEFAULT NULL,
account_id VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'
);
$this->addSql('COMMENT ON COLUMN tmetric_account.id IS \'(DC2Type:uuid)\'');
$this->addSql('CREATE TABLE tmetric_project (
id UUID NOT NULL,
account_id UUID DEFAULT NULL,
project_id UUID DEFAULT NULL,
remote_id VARCHAR(255) DEFAULT NULL,
project_name VARCHAR(255) DEFAULT NULL,
project_code VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'
);
$this->addSql('CREATE INDEX IDX_84CF078F9B6B5FBA ON tmetric_project (account_id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_84CF078F166D1F9C ON tmetric_project (project_id)');
$this->addSql('COMMENT ON COLUMN tmetric_project.id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN tmetric_project.account_id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN tmetric_project.project_id IS \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE tmetric_user ADD CONSTRAINT FK_35F74956A76ED395 FOREIGN KEY (user_id) REFERENCES hub_user (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE tmetric_project ADD CONSTRAINT FK_84CF078F9B6B5FBA FOREIGN KEY (account_id) REFERENCES tmetric_account (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE tmetric_project ADD CONSTRAINT FK_84CF078F166D1F9C FOREIGN KEY (project_id) REFERENCES project (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE hub_user ADD tmetric_id UUID DEFAULT NULL');
$this->addSql('COMMENT ON COLUMN hub_user.tmetric_id IS \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE hub_user ADD CONSTRAINT FK_8BD464F553738CB9 FOREIGN KEY (tmetric_id) REFERENCES tmetric_user (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8BD464F553738CB9 ON hub_user (tmetric_id)');
$this->addSql('ALTER TABLE project ADD tmetric_id UUID DEFAULT NULL');
$this->addSql('COMMENT ON COLUMN project.tmetric_id IS \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EE53738CB9 FOREIGN KEY (tmetric_id) REFERENCES tmetric_project (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE UNIQUE INDEX UNIQ_2FB3D0EE53738CB9 ON project (tmetric_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('ALTER TABLE hub_user DROP CONSTRAINT FK_8BD464F553738CB9');
$this->addSql('ALTER TABLE tmetric_project DROP CONSTRAINT FK_84CF078F9B6B5FBA');
$this->addSql('ALTER TABLE project DROP CONSTRAINT FK_2FB3D0EE53738CB9');
$this->addSql('DROP TABLE tmetric_user');
$this->addSql('DROP TABLE tmetric_account');
$this->addSql('DROP TABLE tmetric_project');
$this->addSql('DROP INDEX UNIQ_2FB3D0EE53738CB9');
$this->addSql('ALTER TABLE project DROP tmetric_id');
$this->addSql('DROP INDEX UNIQ_8BD464F553738CB9');
$this->addSql('ALTER TABLE hub_user DROP tmetric_id');
}
}