Passed
Push — dev ( 1c3353...ed00e7 )
by Nico
29:47
created

Version20241024092428_TutorialRemake::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
ccs 0
cts 11
cp 0
crap 2
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Migrations;
6
7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\Migrations\AbstractMigration;
9
10
final class Version20241024092428_TutorialRemake extends AbstractMigration
11
{
12
    public function getDescription(): string
13
    {
14
        return 'Add new entities for user tutorial remake.';
15
    }
16
17
    public function up(Schema $schema): void
18
    {
19
        $this->addSql('CREATE TABLE stu_tutorial_step (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, module VARCHAR(50) NOT NULL, view VARCHAR(100) NOT NULL, previous_step_id INT DEFAULT NULL, next_steps JSON NOT NULL, payload JSON NOT NULL, sort INT NOT NULL, PRIMARY KEY(id))');
20
        $this->addSql('CREATE INDEX tutorial_view_idx ON stu_tutorial_step (module, view)');
21
        $this->addSql('CREATE INDEX tutorial_sort_idx ON stu_tutorial_step (sort)');
22
        $this->addSql('CREATE TABLE stu_user_tutorial (user_id INT NOT NULL, tutorial_step_id INT NOT NULL, PRIMARY KEY(user_id, tutorial_step_id))');
23
        $this->addSql('CREATE INDEX IDX_9840DDF3A76ED395 ON stu_user_tutorial (user_id)');
24
        $this->addSql('CREATE INDEX IDX_9840DDF3D356979 ON stu_user_tutorial (tutorial_step_id)');
25
        $this->addSql('CREATE INDEX IDX_82D9BF6B4229744F ON stu_tutorial_step (previous_step_id)');
26
        $this->addSql('ALTER TABLE stu_user_tutorial ADD CONSTRAINT FK_9840DDF3A76ED395 FOREIGN KEY (user_id) REFERENCES stu_user (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
27
        $this->addSql('ALTER TABLE stu_user_tutorial ADD CONSTRAINT FK_9840DDF3D356979 FOREIGN KEY (tutorial_step_id) REFERENCES stu_tutorial_step (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
28
        $this->addSql('ALTER TABLE stu_tutorial_step ADD CONSTRAINT FK_82D9BF6B4229744F FOREIGN KEY (previous_step_id) REFERENCES stu_tutorial_step (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
29
    }
30
31
    public function down(Schema $schema): void
32
    {
33
        $this->addSql('ALTER TABLE stu_user_tutorial DROP CONSTRAINT FK_9840DDF3A76ED395');
34
        $this->addSql('ALTER TABLE stu_user_tutorial DROP CONSTRAINT FK_9840DDF3D356979');
35
        $this->addSql('ALTER TABLE stu_tutorial_step DROP CONSTRAINT FK_82D9BF6B4229744F');
36
        $this->addSql('DROP TABLE stu_tutorial_step');
37
        $this->addSql('DROP TABLE stu_user_tutorial');
38
    }
39
}
40