Passed
Pull Request — master (#5720)
by
unknown
07:05
created

Version20170524110000::down()   B

Complexity

Conditions 7
Paths 64

Size

Total Lines 33
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 20
c 0
b 0
f 0
nc 64
nop 1
dl 0
loc 33
rs 8.6666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
6
7
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
8
use Doctrine\DBAL\Schema\Schema;
9
10
final class Version20170524110000 extends AbstractMigrationChamilo
11
{
12
    public function getDescription(): string
13
    {
14
        return 'Replace "name" with "title" fields in tables (part 2)';
15
    }
16
17
    public function up(Schema $schema): void
18
    {
19
        if ($schema->hasTable('skill_level')) {
20
            $this->addSql(
21
                'ALTER TABLE skill_level CHANGE short_name short_title VARCHAR(255) NOT NULL'
22
            );
23
        }
24
25
        if ($schema->hasTable('c_chat_conversation')) {
26
            $this->addSql(
27
                'ALTER TABLE c_chat_conversation CHANGE name title VARCHAR(255) NOT NULL'
28
            );
29
        }
30
31
        if ($schema->hasTable('c_wiki_category')) {
32
            $this->addSql(
33
                'ALTER TABLE c_wiki_category CHANGE name title VARCHAR(255) NOT NULL'
34
            );
35
        }
36
37
        if ($schema->hasTable('track_e_hotpotatoes')) {
38
            $this->addSql(
39
                'ALTER TABLE track_e_hotpotatoes CHANGE exe_name title VARCHAR(255) NOT NULL'
40
            );
41
        }
42
    }
43
44
    public function down(Schema $schema): void
45
    {
46
        $table = $schema->getTable('track_e_hotpotatoes');
47
        if ($table->hasColumn('title')) {
48
            $this->addSql('ALTER TABLE track_e_hotpotatoes CHANGE title exe_name VARCHAR(255) NOT NULL');
49
        }
50
51
        $table = $schema->getTable('tool');
52
        if ($table->hasIndex('UNIQ_20F33ED12B36786B')) {
53
            $this->addSql(
54
                'DROP INDEX UNIQ_20F33ED12B36786B on tool'
55
            );
56
        }
57
        if ($table->hasColumn('title')) {
58
            $this->addSql('ALTER TABLE tool CHANGE title name VARCHAR(255) NOT NULL');
59
        }
60
        $this->addSql(
61
            'CREATE UNIQUE INDEX UNIQ_20F33ED15E237E06 ON tool (title)'
62
        );
63
64
        $table = $schema->getTable('c_wiki_category');
65
        if ($table->hasColumn('title')) {
66
            $this->addSql('ALTER TABLE c_wiki_category CHANGE title name VARCHAR(255) NOT NULL');
67
        }
68
69
        $table = $schema->getTable('c_chat_conversation');
70
        if ($table->hasColumn('title')) {
71
            $this->addSql('ALTER TABLE c_chat_conversation CHANGE title name VARCHAR(255) NOT NULL');
72
        }
73
74
        $table = $schema->getTable('skill_level');
75
        if ($table->hasColumn('short_title')) {
76
            $this->addSql('ALTER TABLE skill_level CHANGE short_title short_name VARCHAR(255) NOT NULL');
77
        }
78
    }
79
}
80