Passed
Push — master ( 7dce27...7fa20f )
by Yannick
08:15
created

Version20250706203800::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
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8
9
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10
use Doctrine\DBAL\Schema\Schema;
11
12
class Version20250706203800 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Create tables page_layout_template and page_layout for page layout templates feature';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $this->addSql("
22
            CREATE TABLE page_layout_template (
23
                id INT AUTO_INCREMENT NOT NULL,
24
                name VARCHAR(255) NOT NULL,
25
                layout LONGTEXT NOT NULL COMMENT 'JSON structure describing the layout template',
26
                PRIMARY KEY(id)
27
            ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;
28
        ");
29
30
        $this->addSql("
31
            CREATE TABLE page_layout (
32
                id INT AUTO_INCREMENT NOT NULL,
33
                page_layout_template_id INT DEFAULT NULL,
34
                created_by INT DEFAULT NULL,
35
                updated_by INT DEFAULT NULL,
36
                url TEXT NOT NULL COMMENT 'URL or page identifier where the layout applies',
37
                roles TEXT DEFAULT NULL COMMENT 'Comma-separated list of role identifiers',
38
                layout LONGTEXT NOT NULL COMMENT 'JSON describing the final layout with blocks and structure',
39
                created_at DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime)',
40
                updated_at DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime)',
41
                INDEX IDX_PAGE_LAYOUT_TEMPLATE_ID (page_layout_template_id),
42
                INDEX IDX_PAGE_LAYOUT_CREATED_BY (created_by),
43
                INDEX IDX_PAGE_LAYOUT_UPDATED_BY (updated_by),
44
                PRIMARY KEY(id)
45
            ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;
46
        ");
47
48
        $this->addSql("
49
            ALTER TABLE page_layout
50
                ADD CONSTRAINT FK_PAGE_LAYOUT_TEMPLATE
51
                    FOREIGN KEY (page_layout_template_id) REFERENCES page_layout_template (id) ON DELETE SET NULL;
52
        ");
53
54
        $this->addSql("
55
            ALTER TABLE page_layout
56
                ADD CONSTRAINT FK_PAGE_LAYOUT_CREATED_BY
57
                    FOREIGN KEY (created_by) REFERENCES user (id) ON DELETE SET NULL;
58
        ");
59
60
        $this->addSql("
61
            ALTER TABLE page_layout
62
                ADD CONSTRAINT FK_PAGE_LAYOUT_UPDATED_BY
63
                    FOREIGN KEY (updated_by) REFERENCES user (id) ON DELETE SET NULL;
64
        ");
65
    }
66
67
    public function down(Schema $schema): void
68
    {
69
        $this->addSql("ALTER TABLE page_layout DROP FOREIGN KEY FK_PAGE_LAYOUT_TEMPLATE;");
70
        $this->addSql("ALTER TABLE page_layout DROP FOREIGN KEY FK_PAGE_LAYOUT_CREATED_BY;");
71
        $this->addSql("ALTER TABLE page_layout DROP FOREIGN KEY FK_PAGE_LAYOUT_UPDATED_BY;");
72
        $this->addSql("DROP TABLE IF EXISTS page_layout;");
73
        $this->addSql("DROP TABLE IF EXISTS page_layout_template;");
74
    }
75
}
76