Passed
Push — master ( 8d1a37...25babe )
by Julito
22:45
created

Version20170525123900   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 46
dl 0
loc 92
rs 10
c 1
b 1
f 1
wmc 17

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
A down() 0 2 1
F up() 0 80 15
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8
9
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10
use Doctrine\DBAL\Schema\Schema;
11
12
class Version20170525123900 extends AbstractMigrationChamilo
13
{
14
    public function up(Schema $schema): void
15
    {
16
        $table = $schema->getTable('usergroup');
17
        if (!$table->hasForeignKey('FK_4A6478171BAD783F')) {
18
            $this->addSql('ALTER TABLE usergroup ADD CONSTRAINT FK_4A6478171BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
19
        }
20
21
        if (!$table->hasIndex('UNIQ_4A6478171BAD783F')) {
22
            $this->addSql('CREATE UNIQUE INDEX UNIQ_4A6478171BAD783F ON usergroup (resource_node_id)');
23
        }
24
25
        $table = $schema->getTable('usergroup');
26
27
        $this->addSql('ALTER TABLE usergroup_rel_course CHANGE usergroup_id usergroup_id INT DEFAULT NULL');
28
        $this->addSql('ALTER TABLE usergroup_rel_course CHANGE course_id course_id INT DEFAULT NULL');
29
30
        if (!$table->hasForeignKey('FK_4A8DF159D2112630')) {
31
            $this->addSql(
32
                'ALTER TABLE usergroup_rel_course ADD CONSTRAINT FK_4A8DF159D2112630 FOREIGN KEY (usergroup_id) REFERENCES usergroup (id) ON DELETE CASCADE'
33
            );
34
        }
35
36
        if (!$table->hasForeignKey('FK_4A8DF159591CC992')) {
37
            $this->addSql(
38
                'ALTER TABLE usergroup_rel_course ADD CONSTRAINT FK_4A8DF159591CC992 FOREIGN KEY (course_id) REFERENCES course (id) ON DELETE CASCADE'
39
            );
40
        }
41
42
        if (!$table->hasIndex('IDX_4A8DF159D2112630')) {
43
            $this->addSql('CREATE INDEX IDX_4A8DF159D2112630 ON usergroup_rel_course (usergroup_id)');
44
        }
45
        if (!$table->hasIndex('IDX_4A8DF159591CC992')) {
46
            $this->addSql('CREATE INDEX IDX_4A8DF159591CC992 ON usergroup_rel_course (course_id)');
47
        }
48
49
        $table = $schema->getTable('usergroup_rel_question');
50
51
        $this->addSql('ALTER TABLE usergroup_rel_question CHANGE question_id question_id INT DEFAULT NULL');
52
        $this->addSql('ALTER TABLE usergroup_rel_question CHANGE usergroup_id usergroup_id INT DEFAULT NULL');
53
54
        if (!$table->hasForeignKey('FK_FF3E58F21E27F6BF')) {
55
            $this->addSql(
56
                'ALTER TABLE usergroup_rel_question ADD CONSTRAINT FK_FF3E58F21E27F6BF FOREIGN KEY (question_id) REFERENCES c_quiz_question (iid) ON DELETE CASCADE'
57
            );
58
        }
59
        if (!$table->hasForeignKey('FK_FF3E58F2D2112630')) {
60
            $this->addSql(
61
                'ALTER TABLE usergroup_rel_question ADD CONSTRAINT FK_FF3E58F2D2112630 FOREIGN KEY (usergroup_id) REFERENCES usergroup (id) ON DELETE CASCADE'
62
            );
63
        }
64
65
        if (!$table->hasIndex('IDX_FF3E58F21E27F6BF')) {
66
            $this->addSql('CREATE INDEX IDX_FF3E58F21E27F6BF ON usergroup_rel_question (question_id)');
67
        }
68
69
        if (!$table->hasIndex('IDX_FF3E58F2D2112630')) {
70
            $this->addSql('CREATE INDEX IDX_FF3E58F2D2112630 ON usergroup_rel_question (usergroup_id)');
71
        }
72
73
        $table = $schema->getTable('usergroup_rel_session');
74
75
        $this->addSql('ALTER TABLE usergroup_rel_session CHANGE usergroup_id usergroup_id INT DEFAULT NULL');
76
        $this->addSql('ALTER TABLE usergroup_rel_session CHANGE session_id session_id INT DEFAULT NULL');
77
78
        if (!$table->hasForeignKey('FK_70122432D2112630')) {
79
            $this->addSql(
80
                'ALTER TABLE usergroup_rel_session ADD CONSTRAINT FK_70122432D2112630 FOREIGN KEY (usergroup_id) REFERENCES usergroup (id) ON DELETE CASCADE'
81
            );
82
        }
83
        if (!$table->hasForeignKey('FK_70122432613FECDF')) {
84
            $this->addSql(
85
                'ALTER TABLE usergroup_rel_session ADD CONSTRAINT FK_70122432613FECDF FOREIGN KEY (session_id) REFERENCES session (id) ON DELETE CASCADE'
86
            );
87
        }
88
89
        if (!$table->hasIndex('IDX_70122432D2112630')) {
90
            $this->addSql('CREATE INDEX IDX_70122432D2112630 ON usergroup_rel_session (usergroup_id)');
91
        }
92
        if (!$table->hasIndex('IDX_70122432613FECDF')) {
93
            $this->addSql('CREATE INDEX IDX_70122432613FECDF ON usergroup_rel_session (session_id)');
94
        }
95
    }
96
97
    public function down(Schema $schema): void
98
    {
99
    }
100
101
    public function getDescription(): string
102
    {
103
        return 'Resources changes';
104
    }
105
}
106