Passed
Pull Request — develop (#54)
by Mario
01:35
created

Version0_19_0::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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_19_0 as Acl;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Acl\Migration\Version0_19_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
10
/**
11
 * Class Version0_19_0
12
 */
13
final class Version0_19_0 extends AbstractMigration
14
{
15
    /**
16
     * @var \Ds\Component\Acl\Migration\Version0_19_0
17
     */
18
    private $acl;
19
20
    /**
21
     * Constructor
22
     *
23
     * @param \Doctrine\DBAL\Migrations\Version  $version
24
     */
25
    public function __construct(Version $version)
26
    {
27
        parent::__construct($version);
28
        $this->acl = new Acl($version);
29
    }
30
31
    /**
32
     * Up migration
33
     *
34
     * @param \Doctrine\DBAL\Schema\Schema $schema
35
     */
36
    public function up(Schema $schema)
37
    {
38
        $this->acl->up($schema);
39
        $this->addSql('ALTER TABLE app_anonymous_role ADD entity_uuids JSON DEFAULT NULL');
40
        $this->addSql('COMMENT ON COLUMN app_anonymous_role.entity_uuids IS \'(DC2Type:json_array)\'');
41
        $this->addSql('ALTER TABLE app_individual_role ADD entity_uuids JSON DEFAULT NULL');
42
        $this->addSql('COMMENT ON COLUMN app_individual_role.entity_uuids IS \'(DC2Type:json_array)\'');
43
        $this->addSql('ALTER TABLE app_organization_role ADD entity_uuids JSON DEFAULT NULL');
44
        $this->addSql('COMMENT ON COLUMN app_organization_role.entity_uuids IS \'(DC2Type:json_array)\'');
45
        $this->addSql('ALTER TABLE app_staff_role ADD entity_uuids JSON DEFAULT NULL');
46
        $this->addSql('COMMENT ON COLUMN app_staff_role.entity_uuids IS \'(DC2Type:json_array)\'');
47
        $this->addSql('ALTER TABLE app_system_role ADD entity_uuids JSON DEFAULT NULL');
48
        $this->addSql('COMMENT ON COLUMN app_system_role.entity_uuids IS \'(DC2Type:json_array)\'');
49
        $this->addSql('
50
            UPDATE
51
                app_anonymous_role
52
            SET
53
                entity_uuids = (
54
                    SELECT
55
                        array_to_json(array_agg(app_bu.uuid))
56
                    FROM
57
                        app_anonymous_role_bu
58
                    INNER JOIN
59
                        app_bu ON
60
                        app_bu.id = app_anonymous_role_bu.business_unit_id
61
                    WHERE
62
                        app_anonymous_role_bu.anonymous_role_id = app_anonymous_role.id
63
                )
64
        ');
65
        $this->addSql('UPDATE app_anonymous_role SET entity_uuids = \'[]\' WHERE entity_uuids IS NULL');
66
        $this->addSql('
67
            UPDATE
68
                app_individual_role
69
            SET
70
                entity_uuids = (
71
                    SELECT
72
                        array_to_json(array_agg(app_bu.uuid))
73
                    FROM
74
                        app_individual_role_bu
75
                    INNER JOIN
76
                        app_bu ON
77
                        app_bu.id = app_individual_role_bu.business_unit_id
78
                    WHERE
79
                        app_individual_role_bu.individual_role_id = app_individual_role.id
80
                )
81
        ');
82
        $this->addSql('UPDATE app_individual_role SET entity_uuids = \'[]\' WHERE entity_uuids IS NULL');
83
        $this->addSql('
84
            UPDATE
85
                app_organization_role
86
            SET
87
                entity_uuids = (
88
                    SELECT
89
                        array_to_json(array_agg(app_bu.uuid))
90
                    FROM
91
                        app_organization_role_bu
92
                    INNER JOIN
93
                        app_bu ON
94
                        app_bu.id = app_organization_role_bu.business_unit_id
95
                    WHERE
96
                        app_organization_role_bu.organization_role_id = app_organization_role.id
97
                )
98
        ');
99
        $this->addSql('UPDATE app_organization_role SET entity_uuids = \'[]\' WHERE entity_uuids IS NULL');
100
        $this->addSql('
101
            UPDATE
102
                app_staff_role
103
            SET
104
                entity_uuids = (
105
                    SELECT
106
                        array_to_json(array_agg(app_bu.uuid))
107
                    FROM
108
                        app_staff_role_bu
109
                    INNER JOIN
110
                        app_bu ON
111
                        app_bu.id = app_staff_role_bu.business_unit_id
112
                    WHERE
113
                        app_staff_role_bu.staff_role_id = app_staff_role.id
114
                )
115
        ');
116
        $this->addSql('UPDATE app_staff_role SET entity_uuids = \'[]\' WHERE entity_uuids IS NULL');
117
        $this->addSql('
118
            UPDATE
119
                app_system_role
120
            SET
121
                entity_uuids = (
122
                    SELECT
123
                        array_to_json(array_agg(app_bu.uuid))
124
                    FROM
125
                        app_system_role_bu
126
                    INNER JOIN
127
                        app_bu ON
128
                        app_bu.id = app_system_role_bu.business_unit_id
129
                    WHERE
130
                        app_system_role_bu.system_role_id = app_system_role.id
131
                )
132
        ');
133
        $this->addSql('UPDATE app_system_role SET entity_uuids = \'[]\' WHERE entity_uuids IS NULL');
134
        $this->addSql('ALTER TABLE app_anonymous_role ALTER entity_uuids SET NOT NULL');
135
        $this->addSql('ALTER TABLE app_individual_role ALTER entity_uuids SET NOT NULL');
136
        $this->addSql('ALTER TABLE app_organization_role ALTER entity_uuids SET NOT NULL');
137
        $this->addSql('ALTER TABLE app_staff_role ALTER entity_uuids SET NOT NULL');
138
        $this->addSql('ALTER TABLE app_system_role ALTER entity_uuids SET NOT NULL');
139
        $this->addSql('DROP TABLE app_anonymous_role_bu');
140
        $this->addSql('DROP TABLE app_individual_role_bu');
141
        $this->addSql('DROP TABLE app_organization_role_bu');
142
        $this->addSql('DROP TABLE app_staff_role_bu');
143
        $this->addSql('DROP TABLE app_system_role_bu');
144
        $this->addSql('CREATE SEQUENCE app_bu_role_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
145
        $this->addSql('CREATE TABLE app_bu_role (id INT NOT NULL, business_unit_id INT DEFAULT NULL, role_id INT DEFAULT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, entity_uuids JSON NOT NULL, version INT DEFAULT 1 NOT NULL, tenant UUID NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
146
        $this->addSql('CREATE UNIQUE INDEX UNIQ_FB9993E1D17F50A6 ON app_bu_role (uuid)');
147
        $this->addSql('CREATE INDEX IDX_FB9993E1A58ECB40 ON app_bu_role (business_unit_id)');
148
        $this->addSql('CREATE INDEX IDX_FB9993E1D60322AC ON app_bu_role (role_id)');
149
        $this->addSql('COMMENT ON COLUMN app_bu_role.entity_uuids IS \'(DC2Type:json_array)\'');
150
        $this->addSql('ALTER TABLE app_bu_role ADD CONSTRAINT FK_A2DAA637A58ECB40 FOREIGN KEY (business_unit_id) REFERENCES app_bu (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
151
        $this->addSql('ALTER TABLE app_bu_role ADD CONSTRAINT FK_A2DAA637D60322AC FOREIGN KEY (role_id) REFERENCES app_role (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
152
    }
153
154
    /**
155
     * Down migration
156
     *
157
     * @param \Doctrine\DBAL\Schema\Schema $schema
158
     */
159
    public function down(Schema $schema)
160
    {
161
        $this->acl->down($schema);
162
        $this->addSql('CREATE TABLE app_anonymous_role_bu (anonymous_role_id INT NOT NULL, business_unit_id INT NOT NULL, PRIMARY KEY(anonymous_role_id, business_unit_id))');
163
        $this->addSql('CREATE INDEX IDX_B09CAAD23089E0B ON app_anonymous_role_bu (anonymous_role_id)');
164
        $this->addSql('CREATE INDEX IDX_B09CAADA58ECB40 ON app_anonymous_role_bu (business_unit_id)');
165
        $this->addSql('CREATE TABLE app_individual_role_bu (individual_role_id INT NOT NULL, business_unit_id INT NOT NULL, PRIMARY KEY(individual_role_id, business_unit_id))');
166
        $this->addSql('CREATE INDEX IDX_68A9160EFDFA321 ON app_individual_role_bu (individual_role_id)');
167
        $this->addSql('CREATE INDEX IDX_68A9160A58ECB40 ON app_individual_role_bu (business_unit_id)');
168
        $this->addSql('CREATE TABLE app_organization_role_bu (organization_role_id INT NOT NULL, business_unit_id INT NOT NULL, PRIMARY KEY(organization_role_id, business_unit_id))');
169
        $this->addSql('CREATE INDEX IDX_79C5DB011BD1AAEF ON app_organization_role_bu (organization_role_id)');
170
        $this->addSql('CREATE INDEX IDX_79C5DB01A58ECB40 ON app_organization_role_bu (business_unit_id)');
171
        $this->addSql('CREATE TABLE app_staff_role_bu (staff_role_id INT NOT NULL, business_unit_id INT NOT NULL, PRIMARY KEY(staff_role_id, business_unit_id))');
172
        $this->addSql('CREATE INDEX IDX_998CF18F8AB5351A ON app_staff_role_bu (staff_role_id)');
173
        $this->addSql('CREATE INDEX IDX_998CF18FA58ECB40 ON app_staff_role_bu (business_unit_id)');
174
        $this->addSql('CREATE TABLE app_system_role_bu (system_role_id INT NOT NULL, business_unit_id INT NOT NULL, PRIMARY KEY(system_role_id, business_unit_id))');
175
        $this->addSql('CREATE INDEX IDX_6CCE35F83A705E3F ON app_system_role_bu (system_role_id)');
176
        $this->addSql('CREATE INDEX IDX_6CCE35F8A58ECB40 ON app_system_role_bu (business_unit_id)');
177
        $this->addSql('
178
            INSERT INTO app_anonymous_role_bu (
179
                anonymous_role_id,
180
                business_unit_id
181
            )
182
            SELECT
183
                app_anonymous_role.id,
184
                app_bu.id
185
            FROM
186
                app_anonymous_role,
187
                app_bu
188
            WHERE
189
                app_anonymous_role.entity_uuids::text LIKE CONCAT(\'%\', app_bu.uuid, \'%\')
190
        ');
191
        $this->addSql('
192
            INSERT INTO app_individual_role_bu (
193
                individual_role_id,
194
                business_unit_id
195
            )
196
            SELECT
197
                app_individual_role.id,
198
                app_bu.id
199
            FROM
200
                app_individual_role,
201
                app_bu
202
            WHERE
203
                app_individual_role.entity_uuids::text LIKE CONCAT(\'%\', app_bu.uuid, \'%\')
204
        ');
205
        $this->addSql('
206
            INSERT INTO app_organization_role_bu (
207
                organization_role_id,
208
                business_unit_id
209
            )
210
            SELECT
211
                app_organization_role.id,
212
                app_bu.id
213
            FROM
214
                app_organization_role,
215
                app_bu
216
            WHERE
217
                app_organization_role.entity_uuids::text LIKE CONCAT(\'%\', app_bu.uuid, \'%\')
218
        ');
219
        $this->addSql('
220
            INSERT INTO app_staff_role_bu (
221
                staff_role_id,
222
                business_unit_id
223
            )
224
            SELECT
225
                app_staff_role.id,
226
                app_bu.id
227
            FROM
228
                app_staff_role,
229
                app_bu
230
            WHERE
231
                app_staff_role.entity_uuids::text LIKE CONCAT(\'%\', app_bu.uuid, \'%\')
232
        ');
233
        $this->addSql('
234
            INSERT INTO app_system_role_bu (
235
                system_role_id,
236
                business_unit_id
237
            )
238
            SELECT
239
                app_system_role.id,
240
                app_bu.id
241
            FROM
242
                app_system_role,
243
                app_bu
244
            WHERE
245
                app_system_role.entity_uuids::text LIKE CONCAT(\'%\', app_bu.uuid, \'%\')
246
        ');
247
        $this->addSql('ALTER TABLE app_anonymous_role DROP entity_uuids');
248
        $this->addSql('ALTER TABLE app_individual_role DROP entity_uuids');
249
        $this->addSql('ALTER TABLE app_organization_role DROP entity_uuids');
250
        $this->addSql('ALTER TABLE app_staff_role DROP entity_uuids');
251
        $this->addSql('ALTER TABLE app_system_role DROP entity_uuids');
252
        $this->addSql('DROP TABLE app_bu_role');
253
        $this->addSql('DROP SEQUENCE app_bu_role_id_seq CASCADE');
254
    }
255
}
256