Passed
Pull Request — master (#7158)
by
unknown
11:01
created

Version20200101020000::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 11
rs 10
c 1
b 0
f 0
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
final class Version20200101020000 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Add language_id foreign keys to resource_node and resource_file (nullable, for indexing and variants).';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        // resource_node.language_id
22
        $this->addSql('ALTER TABLE resource_node ADD language_id INT DEFAULT NULL');
23
        $this->addSql('ALTER TABLE resource_node ADD CONSTRAINT FK_8A5F48FF82F1BAF4 FOREIGN KEY (language_id) REFERENCES language (id) ON DELETE SET NULL');
24
        $this->addSql('CREATE INDEX IDX_8A5F48FF82F1BAF4 ON resource_node (language_id)');
25
26
        // resource_file.language_id
27
        $this->addSql('ALTER TABLE resource_file ADD language_id INT DEFAULT NULL');
28
        $this->addSql('ALTER TABLE resource_file ADD CONSTRAINT FK_83BF96AA82F1BAF4 FOREIGN KEY (language_id) REFERENCES language (id) ON DELETE SET NULL');
29
        $this->addSql('CREATE INDEX IDX_83BF96AA82F1BAF4 ON resource_file (language_id)');
30
    }
31
32
    public function down(Schema $schema): void
33
    {
34
        // Drop resource_node FK/index/column
35
        $this->addSql('ALTER TABLE resource_node DROP FOREIGN KEY FK_8A5F48FF82F1BAF4');
36
        $this->addSql('DROP INDEX IDX_8A5F48FF82F1BAF4 ON resource_node');
37
        $this->addSql('ALTER TABLE resource_node DROP language_id');
38
39
        // Drop resource_file FK/index/column
40
        $this->addSql('ALTER TABLE resource_file DROP FOREIGN KEY FK_83BF96AA82F1BAF4');
41
        $this->addSql('DROP INDEX IDX_83BF96AA82F1BAF4 ON resource_file');
42
        $this->addSql('ALTER TABLE resource_file DROP language_id');
43
    }
44
}
45