Completed
Push — master ( 19732d...076741 )
by Paweł
11:47
created

Version20180710095419::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SWP\Migrations;
6
7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\Migrations\AbstractMigration;
9
10
/**
11
 * Auto-generated Migration: Please modify to your needs!
12
 */
13
final class Version20180710095419 extends AbstractMigration
14
{
15
    public function up(Schema $schema): void
16
    {
17
        // this up() migration is auto-generated, please modify it to your needs
18
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
19
20
        $this->addSql('ALTER TABLE swp_article_events ADD route_id INT');
21
        $this->addSql('ALTER TABLE swp_article_events ADD article_id INT');
22
        $this->addSql('ALTER TABLE swp_article_events RENAME COLUMN value TO impression_type');
23
        $this->addSql('ALTER TABLE 
24
          swp_article_events 
25
        ADD 
26
          CONSTRAINT FK_ED5F19E434ECB4E6 FOREIGN KEY (route_id) REFERENCES swp_route (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
27
        $this->addSql('ALTER TABLE 
28
          swp_article_events 
29
        ADD 
30
          CONSTRAINT FK_ED5F19E47294869C FOREIGN KEY (article_id) REFERENCES swp_article (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
31
        $this->addSql('CREATE INDEX IDX_ED5F19E434ECB4E6 ON swp_article_events (route_id)');
32
        $this->addSql('CREATE INDEX IDX_ED5F19E47294869C ON swp_article_events (article_id)');
33
    }
34
35
    public function down(Schema $schema): void
36
    {
37
        // this down() migration is auto-generated, please modify it to your needs
38
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
39
40
        $this->addSql('ALTER TABLE swp_article_events DROP CONSTRAINT FK_ED5F19E434ECB4E6');
41
        $this->addSql('ALTER TABLE swp_article_events DROP CONSTRAINT FK_ED5F19E47294869C');
42
        $this->addSql('DROP INDEX IDX_ED5F19E434ECB4E6');
43
        $this->addSql('DROP INDEX IDX_ED5F19E47294869C');
44
        $this->addSql('ALTER TABLE swp_article_events DROP route_id');
45
        $this->addSql('ALTER TABLE swp_article_events DROP article_id');
46
        $this->addSql('ALTER TABLE swp_article_events RENAME COLUMN impression_type TO value');
47
    }
48
}
49