Version20200520135254::up()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 26
rs 9.9
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Migrations;
6
7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\Migrations\AbstractMigration;
9
10
final class Version20200520135254 extends AbstractMigration
11
{
12
    public function getDescription(): string
13
    {
14
        return 'Introduce demo courses and demo lessons';
15
    }
16
17
    public function up(Schema $schema): void
18
    {
19
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
20
21
        $this->addSql('CREATE TABLE npd_demo_lesson (
22
          uuid UUID NOT NULL, 
23
          lesson_uuid UUID NOT NULL, 
24
          created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
25
          updated TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, 
26
          PRIMARY KEY(uuid)
27
        )');
28
        $this->addSql('CREATE UNIQUE INDEX UNIQ_FD5B2AE5E80E96C2 ON npd_demo_lesson (lesson_uuid)');
29
        $this->addSql('COMMENT ON COLUMN npd_demo_lesson.uuid IS \'(DC2Type:uuid)\'');
30
        $this->addSql('COMMENT ON COLUMN npd_demo_lesson.lesson_uuid IS \'(DC2Type:uuid)\'');
31
        $this->addSql('ALTER TABLE 
32
          npd_demo_lesson 
33
        ADD 
34
          CONSTRAINT FK_FD5B2AE5E80E96C2 FOREIGN KEY (lesson_uuid) REFERENCES npd_lesson (uuid) NOT DEFERRABLE INITIALLY IMMEDIATE');
35
        $this->addSql('ALTER TABLE course ADD parent_id INT DEFAULT NULL');
36
        $this->addSql('ALTER TABLE course ADD type VARCHAR(255) DEFAULT \'standard\' NOT NULL');
37
        $this->addSql('ALTER TABLE course ADD purchase_url VARCHAR(255) DEFAULT NULL');
38
        $this->addSql('ALTER TABLE 
39
          course 
40
        ADD 
41
          CONSTRAINT FK_169E6FB9727ACA70 FOREIGN KEY (parent_id) REFERENCES course (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
42
        $this->addSql('CREATE INDEX IDX_169E6FB9727ACA70 ON course (parent_id)');
43
    }
44
45
    public function down(Schema $schema): void
46
    {
47
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
48
49
        $this->addSql('DROP TABLE npd_demo_lesson');
50
        $this->addSql('ALTER TABLE course DROP CONSTRAINT FK_169E6FB9727ACA70');
51
        $this->addSql('DROP INDEX IDX_169E6FB9727ACA70');
52
        $this->addSql('ALTER TABLE course DROP parent_id');
53
        $this->addSql('ALTER TABLE course DROP type');
54
        $this->addSql('ALTER TABLE course DROP purchase_url');
55
    }
56
}
57