migrations/Version20190824083121.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 Version20190824083121 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'Join table for projects and users';
  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 project_user (
  23.             project_id UUID NOT NULL, 
  24.             user_id UUID NOT NULL, 
  25.         PRIMARY KEY(project_id, user_id))');
  26.         $this->addSql('CREATE INDEX IDX_B4021E51166D1F9C ON project_user (project_id)');
  27.         $this->addSql('CREATE INDEX IDX_B4021E51A76ED395 ON project_user (user_id)');
  28.         $this->addSql('COMMENT ON COLUMN project_user.project_id IS \'(DC2Type:uuid)\'');
  29.         $this->addSql('COMMENT ON COLUMN project_user.user_id IS \'(DC2Type:uuid)\'');
  30.         $this->addSql('ALTER TABLE project_user ADD CONSTRAINT FK_B4021E51166D1F9C FOREIGN KEY (project_id) REFERENCES tmetric_project (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
  31.         $this->addSql('ALTER TABLE project_user ADD CONSTRAINT FK_B4021E51A76ED395 FOREIGN KEY (user_id) REFERENCES tmetric_user (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
  32.     }
  33.     /**
  34.      * @throws \Doctrine\DBAL\DBALException
  35.      */
  36.     public function down(Schema $schema): void
  37.     {
  38.         // this down() migration is auto-generated, please modify it to your needs
  39.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql''Migration can only be executed safely on \'postgresql\'.');
  40.         $this->addSql('DROP TABLE project_user');
  41.     }
  42. }