Passed
Pull Request — master (#5625)
by Angel Fernando Quiroz
13:00 queued 05:41
created

Version20240702222600::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
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 Version20240702222600 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Migration resource_node --* resource_file (during development)';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $tblResourceFile = $schema->getTable('resource_file');
22
        $tblResourceNode = $schema->getTable('resource_node');
23
24
        if (!$tblResourceFile->hasColumn('resource_node_id')) {
25
            $this->addSql('ALTER TABLE resource_file ADD resource_node_id INT DEFAULT NULL');
26
        }
27
28
        if (!$tblResourceFile->hasForeignKey('FK_83BF96AA1BAD783F')) {
29
            $this->addSql('ALTER TABLE resource_file ADD CONSTRAINT FK_83BF96AA1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id)');
30
        }
31
32
        if (!$tblResourceFile->hasIndex('IDX_83BF96AA1BAD783F')) {
33
            $this->addSql('CREATE INDEX IDX_83BF96AA1BAD783F ON resource_file (resource_node_id)');
34
        }
35
36
        if ($tblResourceNode->hasForeignKey('FK_8A5F48FFCE6B9E84')) {
37
            $this->addSql('ALTER TABLE resource_node DROP FOREIGN KEY FK_8A5F48FFCE6B9E84');
38
        }
39
40
        if ($tblResourceNode->hasIndex('UNIQ_8A5F48FFCE6B9E84')) {
41
            $this->addSql('DROP INDEX UNIQ_8A5F48FFCE6B9E84 ON resource_node');
42
        }
43
44
        if ($tblResourceNode->hasColumn('resource_file_id')) {
45
            $this->addSql('ALTER TABLE resource_node DROP resource_file_id');
46
        }
47
    }
48
}
49