Passed
Push — master ( 13e36e...a9fdac )
by Yannick
06:45 queued 14s
created

Version20230405123419::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
6
7
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
8
use Doctrine\DBAL\Schema\Schema;
9
10
final class Version20230405123419 extends AbstractMigrationChamilo
11
{
12
    public function getDescription(): string
13
    {
14
        return 'Resize c_document.filetype to VARCHAR(15) to allow for more types (i.e. certificate)';
15
    }
16
17
    public function up(Schema $schema): void
18
    {
19
        if ($schema->hasTable('c_document')) {
20
            $this->addSql(
21
                'ALTER TABLE c_document MODIFY filetype VARCHAR(15);'
22
            );
23
        }
24
        if ($schema->hasTable('gradebook_category')) {
25
            $this->addSql(
26
                'ALTER TABLE gradebook_category ADD CONSTRAINT FK_96A4C705C33F7837 FOREIGN KEY (document_id) REFERENCES c_document (iid) ON DELETE SET NULL;'
27
            );
28
            $this->addSql(
29
                'CREATE UNIQUE INDEX UNIQ_96A4C705C33F7837 ON gradebook_category (document_id);'
30
            );
31
        }
32
    }
33
34
    public function down(Schema $schema): void
35
    {
36
        if ($schema->hasTable('gradebook_category')) {
37
            $this->addSql(
38
                'ALTER TABLE gradebook_category DROP CONSTRAINT FK_96A4C705C33F7837;'
39
            );
40
            $this->addSql(
41
                'ALTER TABLE gradebook_category DROP INDEX UNIQ_96A4C705C33F7837;'
42
            );
43
        }
44
        if ($schema->hasTable('c_document')) {
45
            $this->addSql(
46
                'ALTER TABLE c_document MODIFY filetype VARCHAR(10);'
47
            );
48
        }
49
    }
50
}
51