Passed
Push — develop ( 0ad590...d57bb3 )
by Mario
02:51
created

Version0_13_0   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 362
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 248
dl 0
loc 362
rs 10
c 0
b 0
f 0
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
B up() 0 294 7
A down() 0 51 2
1
<?php
2
3
namespace AppBundle\Migrations;
4
5
use Doctrine\DBAL\Migrations\AbstractMigration;
6
use Doctrine\DBAL\Schema\Schema;
7
use Ds\Component\Container\Attribute;
8
use Ramsey\Uuid\Uuid;
9
use stdClass;
10
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
11
use Symfony\Component\Yaml\Yaml;
12
13
/**
14
 * Class Version0_13_0
15
 */
16
class Version0_13_0 extends AbstractMigration implements ContainerAwareInterface
17
{
18
    use Attribute\Container;
19
20
    /**
21
     * Up
22
     *
23
     * @param \Doctrine\DBAL\Schema\Schema $schema
24
     */
25
    public function up(Schema $schema)
26
    {
27
        $platform = $this->connection->getDatabasePlatform()->getName();
28
        $cipherService = $this->container->get('ds_encryption.service.cipher');
29
30
        switch ($platform) {
31
            case 'postgresql':
32
                // Schema
33
                $this->addSql('CREATE SEQUENCE ds_config_id_seq INCREMENT BY 1 MINVALUE 1 START 19');
34
                $this->addSql('CREATE SEQUENCE ds_parameter_id_seq INCREMENT BY 1 MINVALUE 1 START 4');
35
                $this->addSql('CREATE SEQUENCE ds_metadata_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
36
                $this->addSql('CREATE SEQUENCE ds_metadata_trans_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
37
                $this->addSql('CREATE SEQUENCE ds_access_id_seq INCREMENT BY 1 MINVALUE 1 START 3');
38
                $this->addSql('CREATE SEQUENCE ds_access_permission_id_seq INCREMENT BY 1 MINVALUE 1 START 7');
39
                $this->addSql('CREATE SEQUENCE ds_tenant_id_seq INCREMENT BY 1 MINVALUE 1 START 2');
40
                $this->addSql('CREATE SEQUENCE app_category_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
41
                $this->addSql('CREATE SEQUENCE app_category_trans_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
42
                $this->addSql('CREATE SEQUENCE app_scenario_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
43
                $this->addSql('CREATE SEQUENCE app_scenario_trans_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
44
                $this->addSql('CREATE SEQUENCE app_service_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
45
                $this->addSql('CREATE SEQUENCE app_service_trans_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
46
                $this->addSql('CREATE SEQUENCE app_submission_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
47
                $this->addSql('CREATE TABLE ds_config (id INT NOT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, "key" VARCHAR(255) NOT NULL, value TEXT DEFAULT 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))');
48
                $this->addSql('CREATE UNIQUE INDEX UNIQ_758C45F4D17F50A6 ON ds_config (uuid)');
49
                $this->addSql('CREATE UNIQUE INDEX UNIQ_758C45F48A90ABA94E59C462 ON ds_config (key, tenant)');
50
                $this->addSql('CREATE TABLE ds_parameter (id INT NOT NULL, "key" VARCHAR(255) NOT NULL, value TEXT DEFAULT NULL, PRIMARY KEY(id))');
51
                $this->addSql('CREATE UNIQUE INDEX UNIQ_B3C0FD91F48571EB ON ds_parameter ("key")');
52
                $this->addSql('CREATE TABLE ds_metadata (id INT NOT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, slug VARCHAR(255) NOT NULL, type VARCHAR(255) DEFAULT NULL, data JSON 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))');
53
                $this->addSql('CREATE UNIQUE INDEX UNIQ_11290F17D17F50A6 ON ds_metadata (uuid)');
54
                $this->addSql('CREATE UNIQUE INDEX UNIQ_11290F17989D9B624E59C462 ON ds_metadata (slug, tenant)');
55
                $this->addSql('CREATE TABLE ds_metadata_trans (id INT NOT NULL, translatable_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, locale VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
56
                $this->addSql('CREATE INDEX IDX_A6447E202C2AC5D3 ON ds_metadata_trans (translatable_id)');
57
                $this->addSql('CREATE UNIQUE INDEX ds_metadata_trans_unique_translation ON ds_metadata_trans (translatable_id, locale)');
58
                $this->addSql('CREATE TABLE ds_access (id INT NOT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, assignee VARCHAR(255) DEFAULT NULL, assignee_uuid UUID DEFAULT 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))');
59
                $this->addSql('CREATE UNIQUE INDEX UNIQ_A76F41DCD17F50A6 ON ds_access (uuid)');
60
                $this->addSql('CREATE TABLE ds_access_permission (id INT NOT NULL, access_id INT DEFAULT NULL, scope VARCHAR(255) DEFAULT NULL, entity VARCHAR(255) DEFAULT NULL, entity_uuid UUID DEFAULT NULL, "key" VARCHAR(255) NOT NULL, attributes JSON NOT NULL, tenant UUID NOT NULL, PRIMARY KEY(id))');
61
                $this->addSql('CREATE INDEX IDX_D46DD4D04FEA67CF ON ds_access_permission (access_id)');
62
                $this->addSql('CREATE TABLE ds_tenant (id INT NOT NULL, uuid UUID NOT NULL, data JSON NOT NULL, version INT DEFAULT 1 NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
63
                $this->addSql('CREATE UNIQUE INDEX UNIQ_EF5FAEEAD17F50A6 ON ds_tenant (uuid)');
64
                $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))');
65
                $this->addSql('CREATE UNIQUE INDEX UNIQ_8D1EF18FD17F50A6 ON app_submission (uuid)');
66
                $this->addSql('CREATE INDEX IDX_8D1EF18FE04E49DF ON app_submission (scenario_id)');
67
                $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))');
68
                $this->addSql('CREATE UNIQUE INDEX UNIQ_ECC796CD17F50A6 ON app_category (uuid)');
69
                $this->addSql('CREATE UNIQUE INDEX UNIQ_ECC796C989D9B624E59C462 ON app_category (slug, tenant)');
70
                $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))');
71
                $this->addSql('CREATE INDEX IDX_47E8C30A2C2AC5D3 ON app_category_trans (translatable_id)');
72
                $this->addSql('CREATE UNIQUE INDEX app_category_trans_unique_translation ON app_category_trans (translatable_id, locale)');
73
                $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))');
74
                $this->addSql('CREATE UNIQUE INDEX UNIQ_36C5A875D17F50A6 ON app_scenario (uuid)');
75
                $this->addSql('CREATE INDEX IDX_36C5A875ED5CA9E6 ON app_scenario (service_id)');
76
                $this->addSql('CREATE UNIQUE INDEX UNIQ_36C5A875ED5CA9E6989D9B62 ON app_scenario (service_id, slug)');
77
                $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))');
78
                $this->addSql('CREATE INDEX IDX_80D43D122C2AC5D3 ON app_scenario_trans (translatable_id)');
79
                $this->addSql('CREATE UNIQUE INDEX app_scenario_trans_unique_translation ON app_scenario_trans (translatable_id, locale)');
80
                $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))');
81
                $this->addSql('CREATE UNIQUE INDEX UNIQ_CC01A9FD17F50A6 ON app_service (uuid)');
82
                $this->addSql('CREATE UNIQUE INDEX UNIQ_CC01A9F989D9B624E59C462 ON app_service (slug, tenant)');
83
                $this->addSql('CREATE TABLE app_service_category (service_id INT NOT NULL, category_id INT NOT NULL, PRIMARY KEY(service_id, category_id))');
84
                $this->addSql('CREATE INDEX IDX_6B04A35DED5CA9E6 ON app_service_category (service_id)');
85
                $this->addSql('CREATE INDEX IDX_6B04A35D12469DE2 ON app_service_category (category_id)');
86
                $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))');
87
                $this->addSql('CREATE INDEX IDX_432ECEF62C2AC5D3 ON app_service_trans (translatable_id)');
88
                $this->addSql('CREATE UNIQUE INDEX app_service_trans_unique_translation ON app_service_trans (translatable_id, locale)');
89
                $this->addSql('ALTER TABLE ds_metadata_trans ADD CONSTRAINT FK_A6447E202C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES ds_metadata (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
90
                $this->addSql('ALTER TABLE ds_access_permission ADD CONSTRAINT FK_D46DD4D04FEA67CF FOREIGN KEY (access_id) REFERENCES ds_access (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
91
                $this->addSql('ALTER TABLE app_submission ADD CONSTRAINT FK_8D1EF18FE04E49DF FOREIGN KEY (scenario_id) REFERENCES app_scenario (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
92
                $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');
93
                $this->addSql('ALTER TABLE app_scenario ADD CONSTRAINT FK_36C5A875ED5CA9E6 FOREIGN KEY (service_id) REFERENCES app_service (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
94
                $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');
95
                $this->addSql('ALTER TABLE app_service_category ADD CONSTRAINT FK_6B04A35DED5CA9E6 FOREIGN KEY (service_id) REFERENCES app_service (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
96
                $this->addSql('ALTER TABLE app_service_category ADD CONSTRAINT FK_6B04A35D12469DE2 FOREIGN KEY (category_id) REFERENCES app_category (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
97
                $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');
98
                $this->addSql('CREATE TABLE ds_session (id VARCHAR(128) NOT NULL PRIMARY KEY, data BYTEA NOT NULL, time INTEGER NOT NULL, lifetime INTEGER NOT NULL)');
99
100
                // Data
101
                $yml = file_get_contents('/srv/api-platform/src/AppBundle/Resources/migrations/1_0_0.yml');
102
                $data = Yaml::parse($yml);
103
                $i = 0;
104
                $parameters = [
105
                    [
106
                        'key' => 'ds_system.user.username',
107
                        'value' => serialize($data['system']['username'])
108
                    ],
109
                    [
110
                        'key' => 'ds_system.user.password',
111
                        'value' => $cipherService->encrypt($data['system']['password'])
112
                    ],
113
                    [
114
                        'key' => 'ds_tenant.tenant.default',
115
                        'value' => serialize($data['tenant']['uuid'])
116
                    ]
117
                ];
118
119
                foreach ($parameters as $parameter) {
120
                    $this->addSql(sprintf(
121
                        'INSERT INTO ds_parameter (id, key, value) VALUES (%d, %s, %s);',
122
                        ++$i,
123
                        $this->connection->quote($parameter['key']),
124
                        $this->connection->quote($parameter['value'])
125
                    ));
126
                }
127
128
                $i = 0;
129
                $tenants = [
130
                    [
131
                        'uuid' => $data['tenant']['uuid'],
132
                        'data' => '"'.$cipherService->encrypt(new stdClass).'"'
133
                    ]
134
                ];
135
136
                foreach ($tenants as $tenant) {
137
                    $this->addSql(sprintf(
138
                        'INSERT INTO ds_tenant (id, uuid, data, created_at, updated_at) VALUES (%d, %s, %s, %s, %s);',
139
                        ++$i,
140
                        $this->connection->quote($tenant['uuid']),
141
                        $this->connection->quote($tenant['data']),
142
                        'now()',
143
                        'now()'
144
                    ));
145
                }
146
147
                $i = 0;
148
                $configs = [
149
                    [
150
                        'key' => 'ds_api.user.username',
151
                        'value' => serialize($data['user']['system']['username'])
152
                    ],
153
                    [
154
                        'key' => 'ds_api.user.password',
155
                        'value' => $cipherService->encrypt($data['user']['system']['password'])
156
                    ],
157
                    [
158
                        'key' => 'ds_api.user.uuid',
159
                        'value' => serialize($data['user']['system']['uuid'])
160
                    ],
161
                    [
162
                        'key' => 'ds_api.user.roles',
163
                        'value' => serialize([])
164
                    ],
165
                    [
166
                        'key' => 'ds_api.user.identity.roles',
167
                        'value' => serialize([])
168
                    ],
169
                    [
170
                        'key' => 'ds_api.user.identity.type',
171
                        'value' => serialize('System')
172
                    ],
173
                    [
174
                        'key' => 'ds_api.user.identity.uuid',
175
                        'value' => serialize($data['identity']['system']['uuid'])
176
                    ],
177
                    [
178
                        'key' => 'ds_api.user.tenant',
179
                        'value' => serialize($data['tenant']['uuid'])
180
                    ],
181
                    [
182
                        'key' => 'app.bpm.variables.api_url',
183
                        'value' => serialize('api_url')
184
                    ],
185
                    [
186
                        'key' => 'app.bpm.variables.api_user',
187
                        'value' => serialize('api_user')
188
                    ],
189
                    [
190
                        'key' => 'app.bpm.variables.api_key',
191
                        'value' => serialize('api_key')
192
                    ],
193
                    [
194
                        'key' => 'app.bpm.variables.service_uuid',
195
                        'value' => serialize('service_uuid')
196
                    ],
197
                    [
198
                        'key' => 'app.bpm.variables.scenario_uuid',
199
                        'value' => serialize('scenario_uuid')
200
                    ],
201
                    [
202
                        'key' => 'app.bpm.variables.scenario_custom_data',
203
                        'value' => serialize('scenario_custom_data')
204
                    ],
205
                    [
206
                        'key' => 'app.bpm.variables.identity',
207
                        'value' => serialize('identity')
208
                    ],
209
                    [
210
                        'key' => 'app.bpm.variables.identity_uuid',
211
                        'value' => serialize('identity_uuid')
212
                    ],
213
                    [
214
                        'key' => 'app.bpm.variables.submission_uuid',
215
                        'value' => serialize('submission_uuid')
216
                    ],
217
                    [
218
                        'key' => 'app.bpm.variables.start_data',
219
                        'value' => serialize('start_data')
220
                    ]
221
                ];
222
223
                foreach ($configs as $config) {
224
                    $this->addSql(sprintf(
225
                        'INSERT INTO ds_config (id, uuid, owner, owner_uuid, key, value, version, tenant, created_at, updated_at) VALUES (%d, %s, %s, %s, %s, %s, %d, %s, %s, %s);',
226
                        ++$i,
227
                        $this->connection->quote(Uuid::uuid4()->toString()),
228
                        $this->connection->quote('BusinessUnit'),
229
                        $this->connection->quote($data['business_unit']['administration']['uuid']),
230
                        $this->connection->quote($config['key']),
231
                        $this->connection->quote($config['value']),
232
                        1,
233
                        $this->connection->quote($data['tenant']['uuid']),
234
                        'now()',
235
                        'now()'
236
                    ));
237
                }
238
239
                $i = 0;
240
                $j = 0;
241
                $accesses = [
242
                    [
243
                        'owner' => 'System',
244
                        'owner_uuid' => $data['identity']['system']['uuid'],
245
                        'assignee' => 'System',
246
                        'assignee_uuid' => $data['identity']['system']['uuid'],
247
                        'permissions' => [
248
                            [
249
                                'key' => 'entity',
250
                                'attributes' => '["BROWSE","READ","EDIT","ADD","DELETE"]'
251
                            ],
252
                            [
253
                                'key' => 'property',
254
                                'attributes' => '["BROWSE","READ","EDIT"]'
255
                            ],
256
                            [
257
                                'key' => 'generic',
258
                                'attributes' => '["BROWSE","READ","EDIT","ADD","DELETE","EXECUTE"]'
259
                            ]
260
                        ]
261
                    ],
262
                    [
263
                        'owner' => 'BusinessUnit',
264
                        'owner_uuid' => $data['business_unit']['administration']['uuid'],
265
                        'assignee' => 'Staff',
266
                        'assignee_uuid' => $data['identity']['admin']['uuid'],
267
                        'permissions' => [
268
                            [
269
                                'key' => 'entity',
270
                                'attributes' => '["BROWSE","READ","EDIT","ADD","DELETE"]'
271
                            ],
272
                            [
273
                                'key' => 'property',
274
                                'attributes' => '["BROWSE","READ","EDIT"]'
275
                            ],
276
                            [
277
                                'key' => 'generic',
278
                                'attributes' => '["BROWSE","READ","EDIT","ADD","DELETE","EXECUTE"]'
279
                            ]
280
                        ]
281
                    ]
282
                ];
283
284
                foreach ($accesses as $access) {
285
                    $this->addSql(sprintf(
286
                        'INSERT INTO ds_access (id, uuid, owner, owner_uuid, assignee, assignee_uuid, version, tenant, created_at, updated_at) VALUES (%d, %s, %s, %s, %s, %s, %d, %s, %s, %s);',
287
                        ++$i,
288
                        $this->connection->quote(Uuid::uuid4()->toString()),
289
                        $this->connection->quote($access['owner']),
290
                        $this->connection->quote($access['owner_uuid']),
291
                        $this->connection->quote($access['assignee']),
292
                        $this->connection->quote($access['assignee_uuid']),
293
                        1,
294
                        $this->connection->quote($data['tenant']['uuid']),
295
                        'now()',
296
                        'now()'
297
                    ));
298
299
                    foreach ($access['permissions'] as $permission) {
300
                        $this->addSql(sprintf(
301
                            'INSERT INTO ds_access_permission (id, access_id, scope, entity, entity_uuid, key, attributes, tenant) VALUES (%d, %d, %s, %s, %s, %s, %s, %s);',
302
                            ++$j,
303
                            $i,
304
                            $this->connection->quote('generic'),
305
                            'NULL',
306
                            'NULL',
307
                            $this->connection->quote($permission['key']),
308
                            $this->connection->quote($permission['attributes']),
309
                            $this->connection->quote($data['tenant']['uuid'])
310
                        ));
311
                    }
312
                }
313
314
                break;
315
316
            default:
317
                $this->abortIf(true,'Migration cannot be executed on "'.$platform.'".');
318
                break;
319
        }
320
    }
321
322
    /**
323
     * Down
324
     *
325
     * @param \Doctrine\DBAL\Schema\Schema $schema
326
     */
327
    public function down(Schema $schema)
328
    {
329
        $platform = $this->connection->getDatabasePlatform()->getName();
330
331
        switch ($platform) {
332
            case 'postgresql':
333
                // Schema
334
                $this->addSql('ALTER TABLE ds_metadata_trans DROP CONSTRAINT FK_A6447E202C2AC5D3');
335
                $this->addSql('ALTER TABLE ds_access_permission DROP CONSTRAINT FK_D46DD4D04FEA67CF');
336
                $this->addSql('ALTER TABLE app_category_trans DROP CONSTRAINT FK_47E8C30A2C2AC5D3');
337
                $this->addSql('ALTER TABLE app_service_category DROP CONSTRAINT FK_6B04A35D12469DE2');
338
                $this->addSql('ALTER TABLE app_submission DROP CONSTRAINT FK_8D1EF18FE04E49DF');
339
                $this->addSql('ALTER TABLE app_scenario_trans DROP CONSTRAINT FK_80D43D122C2AC5D3');
340
                $this->addSql('ALTER TABLE app_scenario DROP CONSTRAINT FK_36C5A875ED5CA9E6');
341
                $this->addSql('ALTER TABLE app_service_category DROP CONSTRAINT FK_6B04A35DED5CA9E6');
342
                $this->addSql('ALTER TABLE app_service_trans DROP CONSTRAINT FK_432ECEF62C2AC5D3');
343
                $this->addSql('DROP SEQUENCE ds_config_id_seq CASCADE');
344
                $this->addSql('DROP SEQUENCE ds_parameter_id_seq CASCADE');
345
                $this->addSql('DROP SEQUENCE ds_metadata_id_seq CASCADE');
346
                $this->addSql('DROP SEQUENCE ds_metadata_trans_id_seq CASCADE');
347
                $this->addSql('DROP SEQUENCE ds_access_id_seq CASCADE');
348
                $this->addSql('DROP SEQUENCE ds_access_permission_id_seq CASCADE');
349
                $this->addSql('DROP SEQUENCE ds_tenant_id_seq CASCADE');
350
                $this->addSql('DROP SEQUENCE app_submission_id_seq CASCADE');
351
                $this->addSql('DROP SEQUENCE app_category_id_seq CASCADE');
352
                $this->addSql('DROP SEQUENCE app_category_trans_id_seq CASCADE');
353
                $this->addSql('DROP SEQUENCE app_scenario_id_seq CASCADE');
354
                $this->addSql('DROP SEQUENCE app_scenario_trans_id_seq CASCADE');
355
                $this->addSql('DROP SEQUENCE app_service_id_seq CASCADE');
356
                $this->addSql('DROP SEQUENCE app_service_trans_id_seq CASCADE');
357
                $this->addSql('DROP TABLE ds_config');
358
                $this->addSql('DROP TABLE ds_parameter');
359
                $this->addSql('DROP TABLE ds_metadata');
360
                $this->addSql('DROP TABLE ds_metadata_trans');
361
                $this->addSql('DROP TABLE ds_access');
362
                $this->addSql('DROP TABLE ds_access_permission');
363
                $this->addSql('DROP TABLE ds_tenant');
364
                $this->addSql('DROP TABLE app_submission');
365
                $this->addSql('DROP TABLE app_category');
366
                $this->addSql('DROP TABLE app_category_trans');
367
                $this->addSql('DROP TABLE app_scenario');
368
                $this->addSql('DROP TABLE app_scenario_trans');
369
                $this->addSql('DROP TABLE app_service');
370
                $this->addSql('DROP TABLE app_service_category');
371
                $this->addSql('DROP TABLE app_service_trans');
372
                $this->addSql('DROP TABLE ds_session');
373
                break;
374
375
            default:
376
                $this->abortIf(true,'Migration cannot be executed on "'.$platform.'".');
377
                break;
378
        }
379
    }
380
}
381