Passed
Push — master ( 9dd64d...b10a3a )
by
unknown
09:53
created

Version20200101010000::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
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 Version20200101010000 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Add parent_id column to resource_link to store per-context document hierarchy.';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        // Add parent_id column on resource_link
22
        $this->addSql('ALTER TABLE resource_link ADD parent_id INT DEFAULT NULL');
23
24
        // Add foreign key to self (hierarchical links)
25
        $this->addSql(
26
            'ALTER TABLE resource_link
27
             ADD CONSTRAINT FK_398C394B727ACA70
28
             FOREIGN KEY (parent_id) REFERENCES resource_link (id)
29
             ON DELETE SET NULL'
30
        );
31
32
        // Add index for faster lookups by parent
33
        $this->addSql('CREATE INDEX idx_resource_link_parent ON resource_link (parent_id)');
34
    }
35
36
    public function down(Schema $schema): void
37
    {
38
        // Drop foreign key, index and column to rollback schema change
39
        $this->addSql('ALTER TABLE resource_link DROP FOREIGN KEY FK_398C394B727ACA70');
40
        $this->addSql('DROP INDEX idx_resource_link_parent ON resource_link');
41
        $this->addSql('ALTER TABLE resource_link DROP parent_id');
42
    }
43
}
44