Version20200523034109::getDescription()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Migrations;
6
7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\Migrations\AbstractMigration;
9
10
final class Version20200523034109 extends AbstractMigration
11
{
12
    public function getDescription(): string
13
    {
14
        return 'Add notifications table';
15
    }
16
17
    public function up(Schema $schema): void
18
    {
19
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
20
21
        $this->addSql('CREATE TABLE npd_notification (
22
          uuid UUID NOT NULL, 
23
          title VARCHAR(255) NOT NULL, 
24
          text TEXT NOT NULL, 
25
          url VARCHAR(255) NOT NULL, 
26
          label VARCHAR(255) NOT NULL, 
27
          created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
28
          updated TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, 
29
          PRIMARY KEY(uuid)
30
        )');
31
        $this->addSql('COMMENT ON COLUMN npd_notification.uuid IS \'(DC2Type:uuid)\'');
32
        $this->addSql('CREATE TABLE npd_user_read_notifications (
33
          user_id UUID NOT NULL, 
34
          notification_id UUID NOT NULL, 
35
          PRIMARY KEY(user_id, notification_id)
36
        )');
37
        $this->addSql('CREATE INDEX IDX_62224523A76ED395 ON npd_user_read_notifications (user_id)');
38
        $this->addSql('CREATE INDEX IDX_62224523EF1A9D84 ON npd_user_read_notifications (notification_id)');
39
        $this->addSql('COMMENT ON COLUMN npd_user_read_notifications.user_id IS \'(DC2Type:uuid)\'');
40
        $this->addSql('COMMENT ON COLUMN npd_user_read_notifications.notification_id IS \'(DC2Type:uuid)\'');
41
        $this->addSql('ALTER TABLE 
42
          npd_user_read_notifications 
43
        ADD 
44
          CONSTRAINT FK_62224523A76ED395 FOREIGN KEY (user_id) REFERENCES npd_user (uuid) NOT DEFERRABLE INITIALLY IMMEDIATE');
45
        $this->addSql('ALTER TABLE 
46
          npd_user_read_notifications 
47
        ADD 
48
          CONSTRAINT FK_62224523EF1A9D84 FOREIGN KEY (notification_id) REFERENCES npd_notification (uuid) NOT DEFERRABLE INITIALLY IMMEDIATE');
49
    }
50
51
    public function down(Schema $schema): void
52
    {
53
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
54
55
        $this->addSql('ALTER TABLE npd_user_read_notifications DROP CONSTRAINT FK_62224523EF1A9D84');
56
        $this->addSql('DROP TABLE npd_notification');
57
        $this->addSql('DROP TABLE npd_user_read_notifications');
58
    }
59
}
60