1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SWP\Migrations; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Schema\Schema; |
8
|
|
|
use Doctrine\Migrations\AbstractMigration; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Auto-generated Migration: Please modify to your needs! |
12
|
|
|
*/ |
13
|
|
View Code Duplication |
final class Version20191113081727 extends AbstractMigration |
14
|
|
|
{ |
15
|
|
|
public function up(Schema $schema): void |
16
|
|
|
{ |
17
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
18
|
|
|
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); |
19
|
|
|
|
20
|
|
|
$this->addSql('DROP SEQUENCE swp_article_events_id_seq CASCADE'); |
21
|
|
|
$this->addSql('DROP TABLE swp_article_events'); |
22
|
|
|
$this->addSql('ALTER TABLE swp_author ALTER biography TYPE TEXT'); |
23
|
|
|
$this->addSql('ALTER TABLE swp_author ALTER biography DROP DEFAULT'); |
24
|
|
|
$this->addSql('ALTER TABLE swp_author ALTER biography TYPE TEXT'); |
25
|
|
|
$this->addSql('ALTER TABLE swp_package ALTER genre TYPE TEXT'); |
26
|
|
|
$this->addSql('ALTER TABLE swp_package ALTER genre DROP DEFAULT'); |
27
|
|
|
$this->addSql('DROP INDEX swp_article_slug_null_deleted_at_idx'); |
28
|
|
|
$this->addSql('DROP INDEX swp_article_slug_not_null_deleted_at_idx'); |
29
|
|
|
$this->addSql('CREATE UNIQUE INDEX swp_article_slug_null_deleted_at_idx ON swp_article ( |
30
|
|
|
slug, tenant_code, organization_id |
31
|
|
|
) |
32
|
|
|
WHERE |
33
|
|
|
deleted_at IS NULL'); |
34
|
|
|
$this->addSql('CREATE UNIQUE INDEX swp_article_slug_not_null_deleted_at_idx ON swp_article ( |
35
|
|
|
slug, tenant_code, organization_id, |
36
|
|
|
deleted_at |
37
|
|
|
) |
38
|
|
|
WHERE |
39
|
|
|
deleted_at IS NOT NULL'); |
40
|
|
|
$this->addSql('ALTER TABLE swp_image ALTER length TYPE DOUBLE PRECISION'); |
41
|
|
|
$this->addSql('ALTER TABLE swp_image ALTER length DROP DEFAULT'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function down(Schema $schema): void |
45
|
|
|
{ |
46
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
47
|
|
|
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); |
48
|
|
|
|
49
|
|
|
$this->addSql('CREATE SEQUENCE swp_article_events_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); |
50
|
|
|
$this->addSql('CREATE TABLE swp_article_events ( |
51
|
|
|
id INT NOT NULL, |
52
|
|
|
article_statistics_id INT NOT NULL, |
53
|
|
|
route_id INT DEFAULT NULL, |
54
|
|
|
article_id INT DEFAULT NULL, |
55
|
|
|
action VARCHAR(255) DEFAULT NULL, |
56
|
|
|
impression_type VARCHAR(255) DEFAULT NULL, |
57
|
|
|
tenant_code VARCHAR(255) NOT NULL, |
58
|
|
|
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, |
59
|
|
|
updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, |
60
|
|
|
page_view_source VARCHAR(255) DEFAULT NULL, |
61
|
|
|
PRIMARY KEY(id) |
62
|
|
|
)'); |
63
|
|
|
$this->addSql('CREATE INDEX idx_ed5f19e434ecb4e6 ON swp_article_events (route_id)'); |
64
|
|
|
$this->addSql('CREATE INDEX idx_ed5f19e47294869c ON swp_article_events (article_id)'); |
65
|
|
|
$this->addSql('CREATE INDEX idx_ed5f19e41dfe7a17 ON swp_article_events (article_statistics_id)'); |
66
|
|
|
$this->addSql('CREATE INDEX idx_article_events ON swp_article_events ( |
67
|
|
|
article_statistics_id, tenant_code, |
68
|
|
|
created_at |
69
|
|
|
)'); |
70
|
|
|
$this->addSql('ALTER TABLE |
71
|
|
|
swp_article_events |
72
|
|
|
ADD |
73
|
|
|
CONSTRAINT fk_ed5f19e41dfe7a17 FOREIGN KEY (article_statistics_id) REFERENCES swp_article_statistics (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
74
|
|
|
$this->addSql('ALTER TABLE |
75
|
|
|
swp_article_events |
76
|
|
|
ADD |
77
|
|
|
CONSTRAINT fk_ed5f19e434ecb4e6 FOREIGN KEY (route_id) REFERENCES swp_route (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
78
|
|
|
$this->addSql('ALTER TABLE |
79
|
|
|
swp_article_events |
80
|
|
|
ADD |
81
|
|
|
CONSTRAINT fk_ed5f19e47294869c FOREIGN KEY (article_id) REFERENCES swp_article (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); |
82
|
|
|
$this->addSql('ALTER TABLE swp_package ALTER genre TYPE TEXT'); |
83
|
|
|
$this->addSql('ALTER TABLE swp_package ALTER genre DROP DEFAULT'); |
84
|
|
|
$this->addSql('ALTER TABLE swp_image ALTER length TYPE NUMERIC(10, 0)'); |
85
|
|
|
$this->addSql('ALTER TABLE swp_image ALTER length DROP DEFAULT'); |
86
|
|
|
$this->addSql('DROP INDEX swp_article_slug_not_null_deleted_at_idx'); |
87
|
|
|
$this->addSql('DROP INDEX swp_article_slug_null_deleted_at_idx'); |
88
|
|
|
$this->addSql('CREATE UNIQUE INDEX swp_article_slug_not_null_deleted_at_idx ON swp_article ( |
89
|
|
|
slug, tenant_code, organization_id, |
90
|
|
|
deleted_at |
91
|
|
|
) |
92
|
|
|
WHERE |
93
|
|
|
(deleted_at IS NOT NULL)'); |
94
|
|
|
$this->addSql('CREATE UNIQUE INDEX swp_article_slug_null_deleted_at_idx ON swp_article ( |
95
|
|
|
slug, tenant_code, organization_id |
96
|
|
|
) |
97
|
|
|
WHERE |
98
|
|
|
(deleted_at IS NULL)'); |
99
|
|
|
$this->addSql('ALTER TABLE swp_author ALTER biography TYPE VARCHAR(460)'); |
100
|
|
|
$this->addSql('ALTER TABLE swp_author ALTER biography DROP DEFAULT'); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|