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 37'); |
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_user_oauth_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); |
41
|
|
|
$this->addSql('CREATE SEQUENCE app_registration_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); |
42
|
|
|
$this->addSql('CREATE SEQUENCE app_user_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); |
43
|
|
|
$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))'); |
44
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_758C45F4D17F50A6 ON ds_config (uuid)'); |
45
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_758C45F48A90ABA94E59C462 ON ds_config (key, tenant)'); |
46
|
|
|
$this->addSql('CREATE TABLE ds_parameter (id INT NOT NULL, "key" VARCHAR(255) NOT NULL, value TEXT DEFAULT NULL, PRIMARY KEY(id))'); |
47
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_B3C0FD91F48571EB ON ds_parameter ("key")'); |
48
|
|
|
$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))'); |
49
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_11290F17D17F50A6 ON ds_metadata (uuid)'); |
50
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_11290F17989D9B624E59C462 ON ds_metadata (slug, tenant)'); |
51
|
|
|
$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))'); |
52
|
|
|
$this->addSql('CREATE INDEX IDX_A6447E202C2AC5D3 ON ds_metadata_trans (translatable_id)'); |
53
|
|
|
$this->addSql('CREATE UNIQUE INDEX ds_metadata_trans_unique_translation ON ds_metadata_trans (translatable_id, locale)'); |
54
|
|
|
$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))'); |
55
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_A76F41DCD17F50A6 ON ds_access (uuid)'); |
56
|
|
|
$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))'); |
57
|
|
|
$this->addSql('CREATE INDEX IDX_D46DD4D04FEA67CF ON ds_access_permission (access_id)'); |
58
|
|
|
$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))'); |
59
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_EF5FAEEAD17F50A6 ON ds_tenant (uuid)'); |
60
|
|
|
$this->addSql('CREATE TABLE app_user_oauth (id INT NOT NULL, user_id INT DEFAULT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, type VARCHAR(255) NOT NULL, identifier VARCHAR(255) NOT NULL, token VARCHAR(255) 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))'); |
61
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_B00328E0D17F50A6 ON app_user_oauth (uuid)'); |
62
|
|
|
$this->addSql('CREATE INDEX IDX_B00328E0A76ED395 ON app_user_oauth (user_id)'); |
63
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_B00328E08CDE5729772E836A4E59C462 ON app_user_oauth (type, identifier, tenant)'); |
64
|
|
|
$this->addSql('CREATE TABLE app_user (id INT NOT NULL, username VARCHAR(180) NOT NULL, email VARCHAR(180) NOT NULL, enabled BOOLEAN NOT NULL, salt VARCHAR(255) DEFAULT NULL, password VARCHAR(255) NOT NULL, last_login TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, confirmation_token VARCHAR(180) DEFAULT NULL, password_requested_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, roles TEXT NOT 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, version INT DEFAULT 1 NOT NULL, tenant UUID NOT NULL, username_canonical VARCHAR(180) NOT NULL, email_canonical VARCHAR(180) 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_88BDF3E9C05FB297 ON app_user (confirmation_token)'); |
66
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9D17F50A6 ON app_user (uuid)'); |
67
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9F85E06774E59C462 ON app_user (username, tenant)'); |
68
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E992FC23A84E59C462 ON app_user (username_canonical, tenant)'); |
69
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9E7927C744E59C462 ON app_user (email, tenant)'); |
70
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9A0D96FBF4E59C462 ON app_user (email_canonical, tenant)'); |
71
|
|
|
$this->addSql('COMMENT ON COLUMN app_user.roles IS \'(DC2Type:array)\''); |
72
|
|
|
$this->addSql('CREATE TABLE app_registration (id INT NOT NULL, user_id INT DEFAULT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, username VARCHAR(255) NOT NULL, identity 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))'); |
73
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_A026BD26D17F50A6 ON app_registration (uuid)'); |
74
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_A026BD26A76ED395 ON app_registration (user_id)'); |
75
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_A026BD26F85E06774E59C462 ON app_registration (username, tenant)'); |
76
|
|
|
$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'); |
77
|
|
|
$this->addSql('ALTER TABLE ds_access_permission ADD CONSTRAINT FK_D46DD4D04FEA67CF FOREIGN KEY (access_id) REFERENCES ds_access (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
78
|
|
|
$this->addSql('ALTER TABLE app_user_oauth ADD CONSTRAINT FK_B00328E0A76ED395 FOREIGN KEY (user_id) REFERENCES app_user (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
79
|
|
|
$this->addSql('ALTER TABLE app_registration ADD CONSTRAINT FK_A026BD26A76ED395 FOREIGN KEY (user_id) REFERENCES app_user (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); |
80
|
|
|
$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)'); |
81
|
|
|
|
82
|
|
|
// Data |
83
|
|
|
$yml = file_get_contents('/srv/api-platform/src/AppBundle/Resources/migrations/1_0_0.yml'); |
84
|
|
|
$data = Yaml::parse($yml); |
85
|
|
|
$i = 0; |
86
|
|
|
$parameters = [ |
87
|
|
|
[ |
88
|
|
|
'key' => 'ds_system.user.username', |
89
|
|
|
'value' => serialize($data['system']['username']) |
90
|
|
|
], |
91
|
|
|
[ |
92
|
|
|
'key' => 'ds_system.user.password', |
93
|
|
|
'value' => $cipherService->encrypt($data['system']['password']) |
94
|
|
|
], |
95
|
|
|
[ |
96
|
|
|
'key' => 'ds_tenant.tenant.default', |
97
|
|
|
'value' => serialize($data['tenant']['uuid']) |
98
|
|
|
] |
99
|
|
|
]; |
100
|
|
|
|
101
|
|
|
foreach ($parameters as $parameter) { |
102
|
|
|
$this->addSql(sprintf( |
103
|
|
|
'INSERT INTO ds_parameter (id, key, value) VALUES (%d, %s, %s);', |
104
|
|
|
++$i, |
105
|
|
|
$this->connection->quote($parameter['key']), |
106
|
|
|
$this->connection->quote($parameter['value']) |
107
|
|
|
)); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$i = 0; |
111
|
|
|
$tenants = [ |
112
|
|
|
[ |
113
|
|
|
'uuid' => $data['tenant']['uuid'], |
114
|
|
|
'data' => '"'.$cipherService->encrypt(new stdClass).'"' |
115
|
|
|
] |
116
|
|
|
]; |
117
|
|
|
|
118
|
|
|
foreach ($tenants as $tenant) { |
119
|
|
|
$this->addSql(sprintf( |
120
|
|
|
'INSERT INTO ds_tenant (id, uuid, data, created_at, updated_at) VALUES (%d, %s, %s, %s, %s);', |
121
|
|
|
++$i, |
122
|
|
|
$this->connection->quote($tenant['uuid']), |
123
|
|
|
$this->connection->quote($tenant['data']), |
124
|
|
|
'now()', |
125
|
|
|
'now()' |
126
|
|
|
)); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$i = 0; |
130
|
|
|
$configs = [ |
131
|
|
|
[ |
132
|
|
|
'key' => 'ds_api.user.username', |
133
|
|
|
'value' => serialize($data['user']['system']['username']) |
134
|
|
|
], |
135
|
|
|
[ |
136
|
|
|
'key' => 'ds_api.user.password', |
137
|
|
|
'value' => $cipherService->encrypt($data['user']['system']['password']) |
138
|
|
|
], |
139
|
|
|
[ |
140
|
|
|
'key' => 'ds_api.user.uuid', |
141
|
|
|
'value' => serialize($data['user']['system']['uuid']) |
142
|
|
|
], |
143
|
|
|
[ |
144
|
|
|
'key' => 'ds_api.user.roles', |
145
|
|
|
'value' => serialize([]) |
146
|
|
|
], |
147
|
|
|
[ |
148
|
|
|
'key' => 'ds_api.user.identity.roles', |
149
|
|
|
'value' => serialize([]) |
150
|
|
|
], |
151
|
|
|
[ |
152
|
|
|
'key' => 'ds_api.user.identity.type', |
153
|
|
|
'value' => serialize('System') |
154
|
|
|
], |
155
|
|
|
[ |
156
|
|
|
'key' => 'ds_api.user.identity.uuid', |
157
|
|
|
'value' => serialize($data['identity']['system']['uuid']) |
158
|
|
|
], |
159
|
|
|
[ |
160
|
|
|
'key' => 'ds_api.user.tenant', |
161
|
|
|
'value' => serialize($data['tenant']['uuid']) |
162
|
|
|
], |
163
|
|
|
[ |
164
|
|
|
'key' => 'app.spa.admin', |
165
|
|
|
'value' => serialize($data['config']['app.spa.admin']['value']) |
166
|
|
|
], |
167
|
|
|
[ |
168
|
|
|
'key' => 'app.spa.admin.oauth', |
169
|
|
|
'value' => serialize($data['config']['app.spa.admin.oauth']['value']) |
170
|
|
|
], |
171
|
|
|
[ |
172
|
|
|
'key' => 'app.spa.portal', |
173
|
|
|
'value' => serialize($data['config']['app.spa.portal']['value']) |
174
|
|
|
], |
175
|
|
|
[ |
176
|
|
|
'key' => 'app.spa.portal.oauth', |
177
|
|
|
'value' => serialize($data['config']['app.spa.portal.oauth']['value']) |
178
|
|
|
], |
179
|
|
|
[ |
180
|
|
|
'key' => 'app.registration.individual.owner.type', |
181
|
|
|
'value' => serialize('BusinessUnit') |
182
|
|
|
], |
183
|
|
|
[ |
184
|
|
|
'key' => 'app.registration.individual.owner.uuid', |
185
|
|
|
'value' => serialize($data['business_unit']['administration']['uuid']) |
186
|
|
|
], |
187
|
|
|
[ |
188
|
|
|
'key' => 'app.registration.individual.data.github', |
189
|
|
|
'value' => serialize(new stdClass) |
190
|
|
|
], |
191
|
|
|
[ |
192
|
|
|
'key' => 'app.registration.individual.data.google', |
193
|
|
|
'value' => serialize(new stdClass) |
194
|
|
|
], |
195
|
|
|
[ |
196
|
|
|
'key' => 'app.registration.individual.data.twitter', |
197
|
|
|
'value' => serialize(new stdClass) |
198
|
|
|
], |
199
|
|
|
[ |
200
|
|
|
'key' => 'app.registration.individual.roles', |
201
|
|
|
'value' => serialize([]) |
202
|
|
|
], |
203
|
|
|
[ |
204
|
|
|
'key' => 'app.registration.individual.enabled', |
205
|
|
|
'value' => serialize(true) |
206
|
|
|
], |
207
|
|
|
[ |
208
|
|
|
'key' => 'app.registration.organization.owner.type', |
209
|
|
|
'value' => serialize('BusinessUnit') |
210
|
|
|
], |
211
|
|
|
[ |
212
|
|
|
'key' => 'app.registration.organization.owner.uuid', |
213
|
|
|
'value' => serialize($data['business_unit']['administration']['uuid']) |
214
|
|
|
], |
215
|
|
|
[ |
216
|
|
|
'key' => 'app.registration.organization.data.github', |
217
|
|
|
'value' => serialize(new stdClass) |
218
|
|
|
], |
219
|
|
|
[ |
220
|
|
|
'key' => 'app.registration.organization.data.google', |
221
|
|
|
'value' => serialize(new stdClass) |
222
|
|
|
], |
223
|
|
|
[ |
224
|
|
|
'key' => 'app.registration.organization.data.twitter', |
225
|
|
|
'value' => serialize(new stdClass) |
226
|
|
|
], |
227
|
|
|
[ |
228
|
|
|
'key' => 'app.registration.organization.roles', |
229
|
|
|
'value' => serialize([]) |
230
|
|
|
], |
231
|
|
|
[ |
232
|
|
|
'key' => 'app.registration.organization.enabled', |
233
|
|
|
'value' => serialize(true) |
234
|
|
|
], |
235
|
|
|
[ |
236
|
|
|
'key' => 'app.registration.staff.owner.type', |
237
|
|
|
'value' => serialize('BusinessUnit') |
238
|
|
|
], |
239
|
|
|
[ |
240
|
|
|
'key' => 'app.registration.staff.owner.uuid', |
241
|
|
|
'value' => serialize($data['business_unit']['administration']['uuid']) |
242
|
|
|
], |
243
|
|
|
[ |
244
|
|
|
'key' => 'app.registration.staff.data.github', |
245
|
|
|
'value' => serialize(new stdClass) |
246
|
|
|
], |
247
|
|
|
[ |
248
|
|
|
'key' => 'app.registration.staff.data.google', |
249
|
|
|
'value' => serialize(new stdClass) |
250
|
|
|
], |
251
|
|
|
[ |
252
|
|
|
'key' => 'app.registration.staff.data.twitter', |
253
|
|
|
'value' => serialize(new stdClass) |
254
|
|
|
], |
255
|
|
|
[ |
256
|
|
|
'key' => 'app.registration.staff.roles', |
257
|
|
|
'value' => serialize([]) |
258
|
|
|
], |
259
|
|
|
[ |
260
|
|
|
'key' => 'app.registration.staff.enabled', |
261
|
|
|
'value' => serialize(false) |
262
|
|
|
], |
263
|
|
|
[ |
264
|
|
|
'key' => 'app.resetting.email.subject', |
265
|
|
|
'value' => serialize('app.resetting.email.subject') |
266
|
|
|
], |
267
|
|
|
[ |
268
|
|
|
'key' => 'app.resetting.email.body.plain', |
269
|
|
|
'value' => serialize('app.resetting.email.body.plain') |
270
|
|
|
], |
271
|
|
|
[ |
272
|
|
|
'key' => 'app.resetting.email.body.html', |
273
|
|
|
'value' => serialize('app.resetting.email.body.html') |
274
|
|
|
] |
275
|
|
|
]; |
276
|
|
|
|
277
|
|
|
foreach ($configs as $config) { |
278
|
|
|
$this->addSql(sprintf( |
279
|
|
|
'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);', |
280
|
|
|
++$i, |
281
|
|
|
$this->connection->quote(Uuid::uuid4()->toString()), |
282
|
|
|
$this->connection->quote('BusinessUnit'), |
283
|
|
|
$this->connection->quote($data['business_unit']['administration']['uuid']), |
284
|
|
|
$this->connection->quote($config['key']), |
285
|
|
|
$this->connection->quote($config['value']), |
286
|
|
|
1, |
287
|
|
|
$this->connection->quote($data['tenant']['uuid']), |
288
|
|
|
'now()', |
289
|
|
|
'now()' |
290
|
|
|
)); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
$i = 0; |
294
|
|
|
$j = 0; |
295
|
|
|
$accesses = [ |
296
|
|
|
[ |
297
|
|
|
'owner' => 'System', |
298
|
|
|
'owner_uuid' => $data['identity']['system']['uuid'], |
299
|
|
|
'assignee' => 'System', |
300
|
|
|
'assignee_uuid' => $data['identity']['system']['uuid'], |
301
|
|
|
'permissions' => [ |
302
|
|
|
[ |
303
|
|
|
'key' => 'entity', |
304
|
|
|
'attributes' => '["BROWSE","READ","EDIT","ADD","DELETE"]' |
305
|
|
|
], |
306
|
|
|
[ |
307
|
|
|
'key' => 'property', |
308
|
|
|
'attributes' => '["BROWSE","READ","EDIT"]' |
309
|
|
|
], |
310
|
|
|
[ |
311
|
|
|
'key' => 'generic', |
312
|
|
|
'attributes' => '["BROWSE","READ","EDIT","ADD","DELETE","EXECUTE"]' |
313
|
|
|
] |
314
|
|
|
] |
315
|
|
|
], |
316
|
|
|
[ |
317
|
|
|
'owner' => 'BusinessUnit', |
318
|
|
|
'owner_uuid' => $data['business_unit']['administration']['uuid'], |
319
|
|
|
'assignee' => 'Staff', |
320
|
|
|
'assignee_uuid' => $data['identity']['admin']['uuid'], |
321
|
|
|
'permissions' => [ |
322
|
|
|
[ |
323
|
|
|
'key' => 'entity', |
324
|
|
|
'attributes' => '["BROWSE","READ","EDIT","ADD","DELETE"]' |
325
|
|
|
], |
326
|
|
|
[ |
327
|
|
|
'key' => 'property', |
328
|
|
|
'attributes' => '["BROWSE","READ","EDIT"]' |
329
|
|
|
], |
330
|
|
|
[ |
331
|
|
|
'key' => 'generic', |
332
|
|
|
'attributes' => '["BROWSE","READ","EDIT","ADD","DELETE","EXECUTE"]' |
333
|
|
|
] |
334
|
|
|
] |
335
|
|
|
] |
336
|
|
|
]; |
337
|
|
|
|
338
|
|
|
foreach ($accesses as $access) { |
339
|
|
|
$this->addSql(sprintf( |
340
|
|
|
'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);', |
341
|
|
|
++$i, |
342
|
|
|
$this->connection->quote(Uuid::uuid4()->toString()), |
343
|
|
|
$this->connection->quote($access['owner']), |
344
|
|
|
$this->connection->quote($access['owner_uuid']), |
345
|
|
|
$this->connection->quote($access['assignee']), |
346
|
|
|
$this->connection->quote($access['assignee_uuid']), |
347
|
|
|
1, |
348
|
|
|
$this->connection->quote($data['tenant']['uuid']), |
349
|
|
|
'now()', |
350
|
|
|
'now()' |
351
|
|
|
)); |
352
|
|
|
|
353
|
|
|
foreach ($access['permissions'] as $permission) { |
354
|
|
|
$this->addSql(sprintf( |
355
|
|
|
'INSERT INTO ds_access_permission (id, access_id, scope, entity, entity_uuid, key, attributes, tenant) VALUES (%d, %d, %s, %s, %s, %s, %s, %s);', |
356
|
|
|
++$j, |
357
|
|
|
$i, |
358
|
|
|
$this->connection->quote('generic'), |
359
|
|
|
'NULL', |
360
|
|
|
'NULL', |
361
|
|
|
$this->connection->quote($permission['key']), |
362
|
|
|
$this->connection->quote($permission['attributes']), |
363
|
|
|
$this->connection->quote($data['tenant']['uuid']) |
364
|
|
|
)); |
365
|
|
|
} |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
$i = 0; |
369
|
|
|
$users = [ |
370
|
|
|
[ |
371
|
|
|
'username' => '[email protected]', |
372
|
|
|
'password' => password_hash($data['user']['system']['password'], PASSWORD_BCRYPT), |
373
|
|
|
'uuid' => $data['user']['system']['uuid'], |
374
|
|
|
'owner' => 'System', |
375
|
|
|
'owner_uuid' => $data['identity']['system']['uuid'], |
376
|
|
|
'identity' => 'System', |
377
|
|
|
'identity_uuid' => $data['identity']['system']['uuid'] |
378
|
|
|
], |
379
|
|
|
[ |
380
|
|
|
'username' => '[email protected]', |
381
|
|
|
'password' => password_hash($data['user']['anonymous']['password'], PASSWORD_BCRYPT), |
382
|
|
|
'uuid' => $data['user']['anonymous']['uuid'], |
383
|
|
|
'owner' => 'BusinessUnit', |
384
|
|
|
'owner_uuid' => $data['business_unit']['administration']['uuid'], |
385
|
|
|
'identity' => 'Anonymous', |
386
|
|
|
'identity_uuid' => null |
387
|
|
|
], |
388
|
|
|
[ |
389
|
|
|
'username' => '[email protected]', |
390
|
|
|
'password' => password_hash($data['user']['admin']['password'], PASSWORD_BCRYPT), |
391
|
|
|
'uuid' => $data['user']['admin']['uuid'], |
392
|
|
|
'owner' => 'BusinessUnit', |
393
|
|
|
'owner_uuid' => $data['business_unit']['administration']['uuid'], |
394
|
|
|
'identity' => 'Staff', |
395
|
|
|
'identity_uuid' => $data['identity']['admin']['uuid'] |
396
|
|
|
] |
397
|
|
|
]; |
398
|
|
|
|
399
|
|
|
foreach ($users as $user) { |
400
|
|
|
$this->addSql(sprintf( |
401
|
|
|
'INSERT INTO app_user (id, username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles, uuid, owner, owner_uuid, identity, identity_uuid, version, tenant, created_at, updated_at, deleted_at) VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s, %s);', |
402
|
|
|
++$i, |
403
|
|
|
$this->connection->quote($user['username']), |
404
|
|
|
$this->connection->quote($user['username']), |
405
|
|
|
$this->connection->quote($user['username']), |
406
|
|
|
$this->connection->quote($user['username']), |
407
|
|
|
'true', |
408
|
|
|
'NULL', |
409
|
|
|
$this->connection->quote($user['password']), |
410
|
|
|
'NULL', |
411
|
|
|
'NULL', |
412
|
|
|
'NULL', |
413
|
|
|
$this->connection->quote('a:1:{i:0;s:0:"";}'), |
414
|
|
|
$this->connection->quote($user['uuid']), |
415
|
|
|
$this->connection->quote($user['owner']), |
416
|
|
|
$this->connection->quote($user['owner_uuid']), |
417
|
|
|
$this->connection->quote($user['identity']), |
418
|
|
|
null === $user['identity_uuid'] ? 'NULL' : $this->connection->quote($user['identity_uuid']), |
419
|
|
|
1, |
420
|
|
|
$this->connection->quote($data['tenant']['uuid']), |
421
|
|
|
'now()', |
422
|
|
|
'now()', |
423
|
|
|
'NULL' |
424
|
|
|
)); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
break; |
428
|
|
|
|
429
|
|
|
default: |
430
|
|
|
$this->abortIf(true,'Migration cannot be executed on "'.$platform.'".'); |
431
|
|
|
break; |
432
|
|
|
} |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* Down |
437
|
|
|
* |
438
|
|
|
* @param \Doctrine\DBAL\Schema\Schema $schema |
439
|
|
|
*/ |
440
|
|
|
public function down(Schema $schema) |
441
|
|
|
{ |
442
|
|
|
$platform = $this->connection->getDatabasePlatform()->getName(); |
443
|
|
|
|
444
|
|
|
switch ($platform) { |
445
|
|
|
case 'postgresql': |
446
|
|
|
// Schema |
447
|
|
|
$this->addSql('ALTER TABLE ds_metadata_trans DROP CONSTRAINT FK_A6447E202C2AC5D3'); |
448
|
|
|
$this->addSql('ALTER TABLE ds_access_permission DROP CONSTRAINT FK_D46DD4D04FEA67CF'); |
449
|
|
|
$this->addSql('ALTER TABLE app_user_oauth DROP CONSTRAINT FK_B00328E0A76ED395'); |
450
|
|
|
$this->addSql('ALTER TABLE app_registration DROP CONSTRAINT FK_A026BD26A76ED395'); |
451
|
|
|
$this->addSql('DROP SEQUENCE ds_config_id_seq CASCADE'); |
452
|
|
|
$this->addSql('DROP SEQUENCE ds_parameter_id_seq CASCADE'); |
453
|
|
|
$this->addSql('DROP SEQUENCE ds_metadata_id_seq CASCADE'); |
454
|
|
|
$this->addSql('DROP SEQUENCE ds_metadata_trans_id_seq CASCADE'); |
455
|
|
|
$this->addSql('DROP SEQUENCE ds_access_id_seq CASCADE'); |
456
|
|
|
$this->addSql('DROP SEQUENCE ds_access_permission_id_seq CASCADE'); |
457
|
|
|
$this->addSql('DROP SEQUENCE ds_tenant_id_seq CASCADE'); |
458
|
|
|
$this->addSql('DROP SEQUENCE app_user_oauth_id_seq CASCADE'); |
459
|
|
|
$this->addSql('DROP SEQUENCE app_registration_id_seq CASCADE'); |
460
|
|
|
$this->addSql('DROP SEQUENCE app_user_id_seq CASCADE'); |
461
|
|
|
$this->addSql('DROP TABLE ds_config'); |
462
|
|
|
$this->addSql('DROP TABLE ds_parameter'); |
463
|
|
|
$this->addSql('DROP TABLE ds_metadata'); |
464
|
|
|
$this->addSql('DROP TABLE ds_metadata_trans'); |
465
|
|
|
$this->addSql('DROP TABLE ds_access'); |
466
|
|
|
$this->addSql('DROP TABLE ds_access_permission'); |
467
|
|
|
$this->addSql('DROP TABLE ds_tenant'); |
468
|
|
|
$this->addSql('DROP TABLE app_user_oauth'); |
469
|
|
|
$this->addSql('DROP TABLE app_registration'); |
470
|
|
|
$this->addSql('DROP TABLE app_user'); |
471
|
|
|
$this->addSql('DROP TABLE ds_session'); |
472
|
|
|
break; |
473
|
|
|
|
474
|
|
|
default: |
475
|
|
|
$this->abortIf(true,'Migration cannot be executed on "'.$platform.'".'); |
476
|
|
|
break; |
477
|
|
|
} |
478
|
|
|
} |
479
|
|
|
} |
480
|
|
|
|