Passed
Pull Request — master (#4645)
by Yannick
12:39 queued 05:14
created

Version20230315111019::down()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
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 Version20230315111019 extends AbstractMigrationChamilo
11
{
12
    public function getDescription(): string
13
    {
14
        return 'Change field image of table system template as asset';
15
    }
16
17
    public function up(Schema $schema): void
18
    {
19
        $table = $schema->getTable('system_template');
20
        if (false === $table->hasColumn('image_id')) {
21
            $this->addSql("ALTER TABLE system_template ADD image_id BINARY(16) DEFAULT NULL COMMENT '(DC2Type:uuid)', DROP image;");
22
            $this->addSql("ALTER TABLE system_template ADD CONSTRAINT FK_FE8AAE013DA5256D FOREIGN KEY (image_id) REFERENCES asset(id) ON DELETE SET NULL;");
23
            $this->addSql("CREATE INDEX IDX_FE8AAE013DA5256D ON system_template (image_id);");
24
        }
25
    }
26
27
    public function down(Schema $schema): void
28
    {
29
        $table = $schema->getTable('system_template');
30
        if (false !== $table->hasColumn('image_id')) {
31
            $this->addSql("ALTER TABLE system_template DROP FOREIGN KEY FK_FE8AAE013DA5256D;");
32
            $this->addSql("ALTER TABLE system_template DROP INDEX IDX_FE8AAE013DA5256D;");
33
            $this->addSql("ALTER TABLE system_template CHANGE image_id image varchar(250) NOT NULL COMMENT '(DC2Type:uuid)';");
34
        }
35
    }
36
}
37