Passed
Push — master ( 7e6742...fd303e )
by
unknown
28:00 queued 14s
created

Version20250221120000::up()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 18
rs 10
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 Version20250221120000 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Adds ON DELETE CASCADE to the skill_rel_user_id foreign key in skill_rel_user_comment table';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $connection = $this->connection;
22
23
        $constraint = $connection->fetchOne('
24
        SELECT CONSTRAINT_NAME
25
        FROM information_schema.KEY_COLUMN_USAGE
26
        WHERE TABLE_NAME = "skill_rel_user_comment"
27
        AND COLUMN_NAME = "skill_rel_user_id"
28
        AND CONSTRAINT_SCHEMA = DATABASE()
29
        LIMIT 1
30
    ');
31
32
        if ($constraint) {
33
            $connection->executeStatement("ALTER TABLE skill_rel_user_comment DROP FOREIGN KEY `$constraint`");
34
        }
35
36
        $connection->executeStatement('
37
        ALTER TABLE skill_rel_user_comment
38
        ADD CONSTRAINT FK_7AE9F6B6484A9317
39
        FOREIGN KEY (skill_rel_user_id)
40
        REFERENCES skill_rel_user (id)
41
        ON DELETE CASCADE
42
        ON UPDATE CASCADE
43
    ');
44
    }
45
}
46