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 Version20190804190330 extends AbstractMigration |
11
|
|
|
{ |
12
|
|
|
public function getDescription(): string |
13
|
|
|
{ |
14
|
|
|
return 'Add bookmarks'; |
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_bookmark ( |
22
|
|
|
uuid UUID NOT NULL, |
23
|
|
|
user_uuid UUID DEFAULT NULL, |
24
|
|
|
lesson_uuid UUID NOT NULL, |
25
|
|
|
title VARCHAR(255) NOT NULL, |
26
|
|
|
time_in_seconds INT NOT NULL, |
27
|
|
|
created TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, |
28
|
|
|
updated TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, |
29
|
|
|
PRIMARY KEY(uuid) |
30
|
|
|
)'); |
31
|
|
|
$this->addSql('CREATE INDEX IDX_8E334C53ABFE1C6F ON npd_bookmark (user_uuid)'); |
32
|
|
|
$this->addSql('CREATE INDEX IDX_8E334C53E80E96C2 ON npd_bookmark (lesson_uuid)'); |
33
|
|
|
$this->addSql('COMMENT ON COLUMN npd_bookmark.uuid IS \'(DC2Type:uuid)\''); |
34
|
|
|
$this->addSql('COMMENT ON COLUMN npd_bookmark.user_uuid IS \'(DC2Type:uuid)\''); |
35
|
|
|
$this->addSql('COMMENT ON COLUMN npd_bookmark.lesson_uuid IS \'(DC2Type:uuid)\''); |
36
|
|
|
$this->addSql('ALTER TABLE |
37
|
|
|
npd_bookmark |
38
|
|
|
ADD |
39
|
|
|
CONSTRAINT FK_8E334C53ABFE1C6F FOREIGN KEY (user_uuid) REFERENCES npd_user (uuid) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
40
|
|
|
$this->addSql('ALTER TABLE |
41
|
|
|
npd_bookmark |
42
|
|
|
ADD |
43
|
|
|
CONSTRAINT FK_8E334C53E80E96C2 FOREIGN KEY (lesson_uuid) REFERENCES npd_lesson (uuid) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function down(Schema $schema): void |
47
|
|
|
{ |
48
|
|
|
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); |
49
|
|
|
|
50
|
|
|
$this->addSql('DROP TABLE npd_bookmark'); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|