Completed
Push — 1.5 ( 846d5e...6d7d0e )
by Paweł
07:53
created

Version20190709090034::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
dl 22
loc 22
rs 9.568
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 View Code Duplication
final class Version20190709090034 extends AbstractMigration
11
{
12
    public function up(Schema $schema): void
13
    {
14
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
15
16
        $this->addSql('DROP INDEX swp_article_slug_idx');
17
        $this->addSql('
18
            CREATE UNIQUE INDEX swp_article_slug_not_null_deleted_at_idx 
19
            ON swp_article (
20
              slug, tenant_code, organization_id, 
21
              deleted_at
22
            ) 
23
            WHERE deleted_at IS NOT NULL
24
        ');
25
26
        $this->addSql('
27
            CREATE UNIQUE INDEX swp_article_slug_null_deleted_at_idx 
28
            ON swp_article (
29
              slug, tenant_code, organization_id
30
            ) 
31
            WHERE deleted_at IS NULL
32
        ');
33
    }
34
35
    public function down(Schema $schema): void
36
    {
37
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
38
39
        $this->addSql('DROP INDEX swp_article_slug_not_null_deleted_at_idx');
40
        $this->addSql('DROP INDEX swp_article_slug_null_deleted_at_idx');
41
        $this->addSql('CREATE UNIQUE INDEX swp_article_slug_idx ON swp_article (
42
          slug, tenant_code, organization_id, 
43
          deleted_at
44
        )');
45
    }
46
}
47