Version0_15_0::down()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 37
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 33
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 37
rs 9.392
1
<?php
2
3
namespace App\Migration;
4
5
use Doctrine\DBAL\Schema\Schema;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Schema\Schema was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Doctrine\Migrations\AbstractMigration;
0 ignored issues
show
Bug introduced by
The type Doctrine\Migrations\AbstractMigration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Doctrine\DBAL\Migrations\Version;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Migrations\Version was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Ds\Component\Acl\Migration\Version0_15_0 as Acl;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Acl\Migration\Version0_15_0 was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Ds\Component\Config\Migration\Version0_15_0 as Config;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Config\Migration\Version0_15_0 was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Ds\Component\Container\Attribute;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Container\Attribute was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Ds\Component\Database\Util\Objects;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Database\Util\Objects was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Ds\Component\Database\Util\Parameters;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Database\Util\Parameters was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Ds\Component\Metadata\Migration\Version0_15_0 as Metadata;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Metadata\Migration\Version0_15_0 was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Ds\Component\Parameter\Migration\Version0_15_0 as Parameter;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Parameter\Migration\Version0_15_0 was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Ds\Component\Tenant\Migration\Version0_15_0 as Tenant;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Tenant\Migration\Version0_15_0 was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...ContainerAwareInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
/**
19
 * Class Version0_15_0
20
 */
21
final class Version0_15_0 extends AbstractMigration implements ContainerAwareInterface
22
{
23
    use Attribute\Container;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Container\Attribute\Container was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
25
    /**
26
     * @cont string
27
     */
28
    const DIRECTORY = '/srv/api/config/migrations';
29
30
    /**
31
     * @var \Ds\Component\Acl\Migration\Version0_15_0
32
     */
33
    private $acl;
34
35
    /**
36
     * @var \Ds\Component\Config\Migration\Version0_15_0
37
     */
38
    private $config;
39
40
    /**
41
     * @var \Ds\Component\Metadata\Migration\Version0_15_0
42
     */
43
    private $metadata;
44
45
    /**
46
     * @var \Ds\Component\Parameter\Migration\Version0_15_0
47
     */
48
    private $parameter;
49
50
    /**
51
     * @var \Ds\Component\Tenant\Migration\Version0_15_0
52
     */
53
    private $tenant;
54
55
    /**
56
     * Constructor
57
     *
58
     * @param \Doctrine\DBAL\Migrations\Version  $version
59
     */
60
    public function __construct(Version $version)
61
    {
62
        parent::__construct($version);
63
        $this->acl = new Acl($version);
64
        $this->config = new Config($version);
65
        $this->metadata = new Metadata($version);
66
        $this->parameter = new Parameter($version);
67
        $this->tenant = new Tenant($version);
68
    }
69
70
    /**
71
     * Up migration
72
     *
73
     * @param \Doctrine\DBAL\Schema\Schema $schema
74
     */
75
    public function up(Schema $schema)
76
    {
77
        $parameters = Parameters::parseFile(static::DIRECTORY.'/parameters.yaml');
78
        $this->acl->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/acl.yaml', $parameters));
79
        $this->config->setContainer($this->container)->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/config.yaml', $parameters));
80
        $this->metadata->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/metadata.yaml', $parameters));
81
        $this->parameter->setContainer($this->container)->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/system/parameter.yaml', $parameters));
82
        $this->tenant->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/system/tenant.yaml', $parameters));
83
84
        switch ($this->platform->getName()) {
85
            case 'postgresql':
86
                $this->addSql('CREATE SEQUENCE app_category_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
87
                $this->addSql('CREATE SEQUENCE app_category_trans_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
88
                $this->addSql('CREATE SEQUENCE app_scenario_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
89
                $this->addSql('CREATE SEQUENCE app_scenario_trans_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
90
                $this->addSql('CREATE SEQUENCE app_service_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
91
                $this->addSql('CREATE SEQUENCE app_service_trans_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
92
                $this->addSql('CREATE SEQUENCE app_submission_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
93
                $this->addSql('CREATE TABLE app_category (id INT NOT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, slug VARCHAR(255) NOT NULL, enabled BOOLEAN NOT NULL, weight SMALLINT NOT NULL, version INT DEFAULT 1 NOT NULL, tenant UUID NOT NULL, deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
94
                $this->addSql('CREATE UNIQUE INDEX UNIQ_ECC796CD17F50A6 ON app_category (uuid)');
95
                $this->addSql('CREATE UNIQUE INDEX UNIQ_ECC796C989D9B624E59C462 ON app_category (slug, tenant)');
96
                $this->addSql('CREATE TABLE app_category_trans (id INT NOT NULL, translatable_id INT DEFAULT NULL, title VARCHAR(255) DEFAULT NULL, description TEXT DEFAULT NULL, presentation TEXT DEFAULT NULL, data JSON NOT NULL, locale VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
97
                $this->addSql('CREATE INDEX IDX_47E8C30A2C2AC5D3 ON app_category_trans (translatable_id)');
98
                $this->addSql('CREATE UNIQUE INDEX app_category_trans_unique_translation ON app_category_trans (translatable_id, locale)');
99
                $this->addSql('COMMENT ON COLUMN app_category_trans.data IS \'(DC2Type:json_array)\'');
100
                $this->addSql('CREATE TABLE app_scenario (id INT NOT NULL, service_id INT DEFAULT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, "type" VARCHAR(255) NOT NULL, config JSON NOT NULL, slug VARCHAR(255) NOT NULL, enabled BOOLEAN NOT NULL, weight SMALLINT NOT NULL, version INT DEFAULT 1 NOT NULL, tenant UUID NOT NULL, deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
101
                $this->addSql('CREATE UNIQUE INDEX UNIQ_36C5A875D17F50A6 ON app_scenario (uuid)');
102
                $this->addSql('CREATE INDEX IDX_36C5A875ED5CA9E6 ON app_scenario (service_id)');
103
                $this->addSql('CREATE UNIQUE INDEX UNIQ_36C5A875ED5CA9E6989D9B62 ON app_scenario (service_id, slug)');
104
                $this->addSql('COMMENT ON COLUMN app_scenario.config IS \'(DC2Type:json_array)\'');
105
                $this->addSql('CREATE TABLE app_scenario_trans (id INT NOT NULL, translatable_id INT DEFAULT NULL, title VARCHAR(255) DEFAULT NULL, description TEXT DEFAULT NULL, presentation TEXT DEFAULT NULL, data JSON NOT NULL, locale VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
106
                $this->addSql('CREATE INDEX IDX_80D43D122C2AC5D3 ON app_scenario_trans (translatable_id)');
107
                $this->addSql('CREATE UNIQUE INDEX app_scenario_trans_unique_translation ON app_scenario_trans (translatable_id, locale)');
108
                $this->addSql('COMMENT ON COLUMN app_scenario_trans.data IS \'(DC2Type:json_array)\'');
109
                $this->addSql('CREATE TABLE app_service (id INT NOT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, slug VARCHAR(255) NOT NULL, enabled BOOLEAN NOT NULL, weight SMALLINT NOT NULL, version INT DEFAULT 1 NOT NULL, tenant UUID NOT NULL, deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
110
                $this->addSql('CREATE UNIQUE INDEX UNIQ_CC01A9FD17F50A6 ON app_service (uuid)');
111
                $this->addSql('CREATE UNIQUE INDEX UNIQ_CC01A9F989D9B624E59C462 ON app_service (slug, tenant)');
112
                $this->addSql('CREATE TABLE app_service_category (service_id INT NOT NULL, category_id INT NOT NULL, PRIMARY KEY(service_id, category_id))');
113
                $this->addSql('CREATE INDEX IDX_6B04A35DED5CA9E6 ON app_service_category (service_id)');
114
                $this->addSql('CREATE INDEX IDX_6B04A35D12469DE2 ON app_service_category (category_id)');
115
                $this->addSql('CREATE TABLE app_service_trans (id INT NOT NULL, translatable_id INT DEFAULT NULL, title VARCHAR(255) DEFAULT NULL, description TEXT DEFAULT NULL, presentation TEXT DEFAULT NULL, data JSON NOT NULL, locale VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
116
                $this->addSql('CREATE INDEX IDX_432ECEF62C2AC5D3 ON app_service_trans (translatable_id)');
117
                $this->addSql('CREATE UNIQUE INDEX app_service_trans_unique_translation ON app_service_trans (translatable_id, locale)');
118
                $this->addSql('COMMENT ON COLUMN app_service_trans.data IS \'(DC2Type:json_array)\'');
119
                $this->addSql('CREATE TABLE app_submission (id INT NOT NULL, scenario_id INT DEFAULT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, identity VARCHAR(255) DEFAULT NULL, identity_uuid UUID DEFAULT NULL, data JSON NOT NULL, state SMALLINT NOT NULL, version INT DEFAULT 1 NOT NULL, tenant UUID NOT NULL, deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
120
                $this->addSql('CREATE UNIQUE INDEX UNIQ_8D1EF18FD17F50A6 ON app_submission (uuid)');
121
                $this->addSql('CREATE INDEX IDX_8D1EF18FE04E49DF ON app_submission (scenario_id)');
122
                $this->addSql('COMMENT ON COLUMN app_submission.data IS \'(DC2Type:json_array)\'');
123
                $this->addSql('ALTER TABLE app_category_trans ADD CONSTRAINT FK_47E8C30A2C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES app_category (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
124
                $this->addSql('ALTER TABLE app_scenario ADD CONSTRAINT FK_36C5A875ED5CA9E6 FOREIGN KEY (service_id) REFERENCES app_service (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
125
                $this->addSql('ALTER TABLE app_scenario_trans ADD CONSTRAINT FK_80D43D122C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES app_scenario (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
126
                $this->addSql('ALTER TABLE app_service_category ADD CONSTRAINT FK_6B04A35DED5CA9E6 FOREIGN KEY (service_id) REFERENCES app_service (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
127
                $this->addSql('ALTER TABLE app_service_category ADD CONSTRAINT FK_6B04A35D12469DE2 FOREIGN KEY (category_id) REFERENCES app_category (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
128
                $this->addSql('ALTER TABLE app_service_trans ADD CONSTRAINT FK_432ECEF62C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES app_service (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
129
                $this->addSql('ALTER TABLE app_submission ADD CONSTRAINT FK_8D1EF18FE04E49DF FOREIGN KEY (scenario_id) REFERENCES app_scenario (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
130
                break;
131
132
            default:
133
                $this->abortIf(true,'Migration cannot be executed on "'.$this->platform->getName().'".');
134
                break;
135
        }
136
    }
137
138
    /**
139
     * Down migration
140
     *
141
     * @param \Doctrine\DBAL\Schema\Schema $schema
142
     */
143
    public function down(Schema $schema)
144
    {
145
        $this->acl->down($schema);
146
        $this->config->setContainer($this->container)->down($schema);
147
        $this->metadata->down($schema);
148
        $this->parameter->setContainer($this->container)->down($schema);
149
        $this->tenant->down($schema);
150
151
        switch ($this->platform->getName()) {
152
            case 'postgresql':
153
                $this->addSql('ALTER TABLE app_category_trans DROP CONSTRAINT FK_47E8C30A2C2AC5D3');
154
                $this->addSql('ALTER TABLE app_service_category DROP CONSTRAINT FK_6B04A35D12469DE2');
155
                $this->addSql('ALTER TABLE app_scenario_trans DROP CONSTRAINT FK_80D43D122C2AC5D3');
156
                $this->addSql('ALTER TABLE app_submission DROP CONSTRAINT FK_8D1EF18FE04E49DF');
157
                $this->addSql('ALTER TABLE app_scenario DROP CONSTRAINT FK_36C5A875ED5CA9E6');
158
                $this->addSql('ALTER TABLE app_service_category DROP CONSTRAINT FK_6B04A35DED5CA9E6');
159
                $this->addSql('ALTER TABLE app_service_trans DROP CONSTRAINT FK_432ECEF62C2AC5D3');
160
                $this->addSql('DROP SEQUENCE app_category_id_seq CASCADE');
161
                $this->addSql('DROP SEQUENCE app_category_trans_id_seq CASCADE');
162
                $this->addSql('DROP SEQUENCE app_scenario_id_seq CASCADE');
163
                $this->addSql('DROP SEQUENCE app_scenario_trans_id_seq CASCADE');
164
                $this->addSql('DROP SEQUENCE app_service_id_seq CASCADE');
165
                $this->addSql('DROP SEQUENCE app_service_trans_id_seq CASCADE');
166
                $this->addSql('DROP SEQUENCE app_submission_id_seq CASCADE');
167
                $this->addSql('DROP TABLE app_category');
168
                $this->addSql('DROP TABLE app_category_trans');
169
                $this->addSql('DROP TABLE app_scenario');
170
                $this->addSql('DROP TABLE app_scenario_trans');
171
                $this->addSql('DROP TABLE app_service');
172
                $this->addSql('DROP TABLE app_service_category');
173
                $this->addSql('DROP TABLE app_service_trans');
174
                $this->addSql('DROP TABLE app_submission');
175
                break;
176
177
            default:
178
                $this->abortIf(true,'Migration cannot be executed on "'.$this->platform->getName().'".');
179
                break;
180
        }
181
    }
182
}
183