Completed
Push — develop ( 0686ac...7ecc3a )
by Alejandro
18s queued 11s
created

Version20201023090929::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkMigrations;
6
7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\DBAL\Types\Types;
9
use Doctrine\Migrations\AbstractMigration;
10
11
final class Version20201023090929 extends AbstractMigration
12
{
13
    private const IMPORT_SOURCE_COLUMN = 'import_source';
14
15
    public function up(Schema $schema): void
16
    {
17
        $shortUrls = $schema->getTable('short_urls');
18
        $this->skipIf($shortUrls->hasColumn(self::IMPORT_SOURCE_COLUMN));
19
20
        $shortUrls->addColumn(self::IMPORT_SOURCE_COLUMN, Types::STRING, [
21
            'length' => 255,
22
            'notnull' => false,
23
        ]);
24
        $shortUrls->addColumn('import_original_short_code', Types::STRING, [
25
            'length' => 255,
26
            'notnull' => false,
27
        ]);
28
29
        $shortUrls->addUniqueIndex(
30
            [self::IMPORT_SOURCE_COLUMN, 'import_original_short_code', 'domain_id'],
31
            'unique_imports',
32
        );
33
    }
34
35
    public function down(Schema $schema): void
36
    {
37
        $shortUrls = $schema->getTable('short_urls');
38
        $this->skipIf(! $shortUrls->hasColumn(self::IMPORT_SOURCE_COLUMN));
39
40
        $shortUrls->dropColumn(self::IMPORT_SOURCE_COLUMN);
41
        $shortUrls->dropColumn('import_original_short_code');
42
        $shortUrls->dropIndex('unique_imports');
43
    }
44
}
45