migrations/Version20190817123213.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 Version20190817123213 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'Tmetric data tables and relations';
  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('CREATE TABLE tmetric_user (
  23.             id UUID NOT NULL, 
  24.             user_id UUID DEFAULT NULL, 
  25.             user_profile_id INT DEFAULT NULL, 
  26.             active_account_id INT DEFAULT NULL, 
  27.             user_name VARCHAR(255) DEFAULT NULL, 
  28.             date_format VARCHAR(255) DEFAULT \'DD.MM.YYYY\' NOT NULL, 
  29.             time_format VARCHAR(255) DEFAULT \'H:mm\' NOT NULL, 
  30.             show_breaks BOOLEAN DEFAULT \'true\' NOT NULL, 
  31.             registration_date TIMESTAMP(0) WITH TIME ZONE NOT NULL, 
  32.             time_zone_info VARCHAR(255) DEFAULT \'Asia/Yekaterinburg\' NOT NULL, 
  33.             is_registered BOOLEAN DEFAULT \'true\' NOT NULL, 
  34.             email VARCHAR(255) NOT NULL, PRIMARY KEY(id))'
  35.         );
  36.         $this->addSql('CREATE UNIQUE INDEX UNIQ_35F74956A76ED395 ON tmetric_user (user_id)');
  37.         $this->addSql('COMMENT ON COLUMN tmetric_user.id IS \'(DC2Type:uuid)\'');
  38.         $this->addSql('COMMENT ON COLUMN tmetric_user.user_id IS \'(DC2Type:uuid)\'');
  39.         $this->addSql('CREATE TABLE tmetric_account (
  40.             id UUID NOT NULL, 
  41.             api_key VARCHAR(255) DEFAULT NULL, 
  42.             account_id VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'
  43.         );
  44.         $this->addSql('COMMENT ON COLUMN tmetric_account.id IS \'(DC2Type:uuid)\'');
  45.         $this->addSql('CREATE TABLE tmetric_project (
  46.             id UUID NOT NULL, 
  47.             account_id UUID DEFAULT NULL, 
  48.             project_id UUID DEFAULT NULL, 
  49.             remote_id VARCHAR(255) DEFAULT NULL, 
  50.             project_name VARCHAR(255) DEFAULT NULL, 
  51.             project_code VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'
  52.         );
  53.         $this->addSql('CREATE INDEX IDX_84CF078F9B6B5FBA ON tmetric_project (account_id)');
  54.         $this->addSql('CREATE UNIQUE INDEX UNIQ_84CF078F166D1F9C ON tmetric_project (project_id)');
  55.         $this->addSql('COMMENT ON COLUMN tmetric_project.id IS \'(DC2Type:uuid)\'');
  56.         $this->addSql('COMMENT ON COLUMN tmetric_project.account_id IS \'(DC2Type:uuid)\'');
  57.         $this->addSql('COMMENT ON COLUMN tmetric_project.project_id IS \'(DC2Type:uuid)\'');
  58.         $this->addSql('ALTER TABLE tmetric_user ADD CONSTRAINT FK_35F74956A76ED395 FOREIGN KEY (user_id) REFERENCES hub_user (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  59.         $this->addSql('ALTER TABLE tmetric_project ADD CONSTRAINT FK_84CF078F9B6B5FBA FOREIGN KEY (account_id) REFERENCES tmetric_account (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  60.         $this->addSql('ALTER TABLE tmetric_project ADD CONSTRAINT FK_84CF078F166D1F9C FOREIGN KEY (project_id) REFERENCES project (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  61.         $this->addSql('ALTER TABLE hub_user ADD tmetric_id UUID DEFAULT NULL');
  62.         $this->addSql('COMMENT ON COLUMN hub_user.tmetric_id IS \'(DC2Type:uuid)\'');
  63.         $this->addSql('ALTER TABLE hub_user ADD CONSTRAINT FK_8BD464F553738CB9 FOREIGN KEY (tmetric_id) REFERENCES tmetric_user (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  64.         $this->addSql('CREATE UNIQUE INDEX UNIQ_8BD464F553738CB9 ON hub_user (tmetric_id)');
  65.         $this->addSql('ALTER TABLE project ADD tmetric_id UUID DEFAULT NULL');
  66.         $this->addSql('COMMENT ON COLUMN project.tmetric_id IS \'(DC2Type:uuid)\'');
  67.         $this->addSql('ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EE53738CB9 FOREIGN KEY (tmetric_id) REFERENCES tmetric_project (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  68.         $this->addSql('CREATE UNIQUE INDEX UNIQ_2FB3D0EE53738CB9 ON project (tmetric_id)');
  69.     }
  70.     /**
  71.      * @throws \Doctrine\DBAL\DBALException
  72.      */
  73.     public function down(Schema $schema): void
  74.     {
  75.         // this down() migration is auto-generated, please modify it to your needs
  76.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql''Migration can only be executed safely on \'postgresql\'.');
  77.         $this->addSql('ALTER TABLE hub_user DROP CONSTRAINT FK_8BD464F553738CB9');
  78.         $this->addSql('ALTER TABLE tmetric_project DROP CONSTRAINT FK_84CF078F9B6B5FBA');
  79.         $this->addSql('ALTER TABLE project DROP CONSTRAINT FK_2FB3D0EE53738CB9');
  80.         $this->addSql('DROP TABLE tmetric_user');
  81.         $this->addSql('DROP TABLE tmetric_account');
  82.         $this->addSql('DROP TABLE tmetric_project');
  83.         $this->addSql('DROP INDEX UNIQ_2FB3D0EE53738CB9');
  84.         $this->addSql('ALTER TABLE project DROP tmetric_id');
  85.         $this->addSql('DROP INDEX UNIQ_8BD464F553738CB9');
  86.         $this->addSql('ALTER TABLE hub_user DROP tmetric_id');
  87.     }
  88. }