Passed
Pull Request — master (#6795)
by
unknown
12:13 queued 03:39
created

Version20250918170500::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
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 Version20250918170500 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Dropbox: link c_dropbox_file to resource_node with FK + unique index, and set integer defaults.';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        // Add resource_node_id and normalize defaults (idempotent at SQL level depends on platform)
22
        $this->addSql("
23
            ALTER TABLE c_dropbox_file
24
                ADD resource_node_id INT DEFAULT NULL,
25
                CHANGE c_id c_id INT DEFAULT 0 NOT NULL,
26
                CHANGE filesize filesize INT DEFAULT 0 NOT NULL,
27
                CHANGE cat_id cat_id INT DEFAULT 0 NOT NULL,
28
                CHANGE session_id session_id INT DEFAULT 0 NOT NULL
29
        ");
30
31
        // Add FK to resource_node(id)
32
        $this->addSql("
33
            ALTER TABLE c_dropbox_file
34
                ADD CONSTRAINT FK_4D71B46C1BAD783F
35
                FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE
36
        ");
37
38
        // Make the 1:1 explicit (unique on resource_node_id).
39
        // Note: MySQL allows multiple NULLs in a UNIQUE index, so this will not block rows without link.
40
        $this->addSql("
41
            CREATE UNIQUE INDEX UNIQ_4D71B46C1BAD783F ON c_dropbox_file (resource_node_id)
42
        ");
43
    }
44
45
    public function down(Schema $schema): void
46
    {
47
        // Drop unique index + FK + column (best-effort rollback)
48
        $this->addSql("DROP INDEX UNIQ_4D71B46C1BAD783F ON c_dropbox_file");
49
        $this->addSql("ALTER TABLE c_dropbox_file DROP FOREIGN KEY FK_4D71B46C1BAD783F");
50
        $this->addSql("ALTER TABLE c_dropbox_file DROP COLUMN resource_node_id");
51
    }
52
}
53