1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Circles - Bring cloud-users closer together. |
8
|
|
|
* |
9
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
10
|
|
|
* later. See the COPYING file. |
11
|
|
|
* |
12
|
|
|
* @author Maxence Lange <[email protected]> |
13
|
|
|
* @copyright 2021 |
14
|
|
|
* @license GNU AGPL version 3 or any later version |
15
|
|
|
* |
16
|
|
|
* This program is free software: you can redistribute it and/or modify |
17
|
|
|
* it under the terms of the GNU Affero General Public License as |
18
|
|
|
* published by the Free Software Foundation, either version 3 of the |
19
|
|
|
* License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU Affero General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU Affero General Public License |
27
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
namespace OCA\Circles\Migration; |
33
|
|
|
|
34
|
|
|
use Closure; |
35
|
|
|
use Doctrine\DBAL\Schema\SchemaException; |
36
|
|
|
use Doctrine\DBAL\Types\Types; |
37
|
|
|
use OCP\DB\ISchemaWrapper; |
38
|
|
|
use OCP\IDBConnection; |
39
|
|
|
use OCP\Migration\IOutput; |
40
|
|
|
use OCP\Migration\SimpleMigrationStep; |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Class Version0022Date20220526113601 |
45
|
|
|
* |
46
|
|
|
* @package OCA\Circles\Migration |
47
|
|
|
*/ |
48
|
|
|
class Version0022Date20220526113601 extends SimpleMigrationStep { |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param IDBConnection $connection |
53
|
|
|
*/ |
54
|
|
|
public function __construct(IDBConnection $connection) { |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param IOutput $output |
60
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
61
|
|
|
* @param array $options |
62
|
|
|
* |
63
|
|
|
* @return null|ISchemaWrapper |
64
|
|
|
* @throws SchemaException |
65
|
|
|
*/ |
66
|
|
|
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
67
|
|
|
/** @var ISchemaWrapper $schema */ |
68
|
|
|
$schema = $schemaClosure(); |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* CIRCLES_CIRCLE |
73
|
|
|
*/ |
74
|
|
|
if (!$schema->hasTable('circles_circle')) { |
75
|
|
|
$table = $schema->createTable('circles_circle'); |
76
|
|
|
|
77
|
|
|
$table->addColumn( |
78
|
|
|
'id', 'integer', [ |
79
|
|
|
'autoincrement' => true, |
80
|
|
|
'notnull' => true, |
81
|
|
|
'length' => 4, |
82
|
|
|
'unsigned' => true, |
83
|
|
|
] |
84
|
|
|
); |
85
|
|
|
$table->addColumn( |
86
|
|
|
'unique_id', 'string', [ |
87
|
|
|
'notnull' => true, |
88
|
|
|
'length' => 31, |
89
|
|
|
] |
90
|
|
|
); |
91
|
|
|
$table->addColumn( |
92
|
|
|
'name', 'string', [ |
93
|
|
|
'notnull' => true, |
94
|
|
|
'length' => 127, |
95
|
|
|
] |
96
|
|
|
); |
97
|
|
|
$table->addColumn( |
98
|
|
|
'display_name', 'string', [ |
99
|
|
|
'notnull' => false, |
100
|
|
|
'default' => '', |
101
|
|
|
'length' => 127 |
102
|
|
|
] |
103
|
|
|
); |
104
|
|
|
$table->addColumn( |
105
|
|
|
'instance', 'string', [ |
106
|
|
|
'notnull' => false, |
107
|
|
|
'default' => '', |
108
|
|
|
'length' => 255 |
109
|
|
|
] |
110
|
|
|
); |
111
|
|
|
$table->addColumn( |
112
|
|
|
'config', 'integer', [ |
113
|
|
|
'notnull' => false, |
114
|
|
|
'length' => 11, |
115
|
|
|
'unsigned' => true |
116
|
|
|
] |
117
|
|
|
); |
118
|
|
|
$table->addColumn( |
119
|
|
|
'source', 'integer', [ |
120
|
|
|
'notnull' => false, |
121
|
|
|
'length' => 5, |
122
|
|
|
'unsigned' => true |
123
|
|
|
] |
124
|
|
|
); |
125
|
|
|
$table->addColumn( |
126
|
|
|
'settings', 'text', [ |
127
|
|
|
'notnull' => false |
128
|
|
|
] |
129
|
|
|
); |
130
|
|
|
$table->addColumn( |
131
|
|
|
'description', 'text', [ |
132
|
|
|
'notnull' => false |
133
|
|
|
] |
134
|
|
|
); |
135
|
|
|
$table->addColumn( |
136
|
|
|
'creation', 'datetime', [ |
137
|
|
|
'notnull' => false, |
138
|
|
|
] |
139
|
|
|
); |
140
|
|
|
$table->addColumn( |
141
|
|
|
'contact_addressbook', 'integer', [ |
142
|
|
|
'notnull' => false, |
143
|
|
|
'unsigned' => true, |
144
|
|
|
'length' => 7, |
145
|
|
|
] |
146
|
|
|
); |
147
|
|
|
$table->addColumn( |
148
|
|
|
'contact_groupname', 'string', [ |
149
|
|
|
'notnull' => false, |
150
|
|
|
'length' => 127, |
151
|
|
|
] |
152
|
|
|
); |
153
|
|
|
|
154
|
|
|
$table->setPrimaryKey(['id']); |
155
|
|
|
$table->addUniqueIndex(['unique_id']); |
156
|
|
|
$table->addIndex(['config']); |
157
|
|
|
$table->addIndex(['instance']); |
158
|
|
|
$table->addIndex(['source']); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* CIRCLES_MEMBER |
164
|
|
|
*/ |
165
|
|
|
if (!$schema->hasTable('circles_member')) { |
166
|
|
|
$table = $schema->createTable('circles_member'); |
167
|
|
|
|
168
|
|
|
$table->addColumn( |
169
|
|
|
'id', 'integer', [ |
170
|
|
|
'autoincrement' => true, |
171
|
|
|
'notnull' => true, |
172
|
|
|
'length' => 4, |
173
|
|
|
'unsigned' => true, |
174
|
|
|
] |
175
|
|
|
); |
176
|
|
|
$table->addColumn( |
177
|
|
|
'single_id', 'string', [ |
178
|
|
|
'notnull' => false, |
179
|
|
|
'length' => 31 |
180
|
|
|
] |
181
|
|
|
); |
182
|
|
|
$table->addColumn( |
183
|
|
|
'circle_id', 'string', [ |
184
|
|
|
'notnull' => true, |
185
|
|
|
'length' => 31, |
186
|
|
|
] |
187
|
|
|
); |
188
|
|
|
$table->addColumn( |
189
|
|
|
'member_id', Types::STRING, [ |
190
|
|
|
'notnull' => false, |
191
|
|
|
'length' => 31, |
192
|
|
|
] |
193
|
|
|
); |
194
|
|
|
$table->addColumn( |
195
|
|
|
'user_id', 'string', [ |
196
|
|
|
'notnull' => true, |
197
|
|
|
'length' => 127, |
198
|
|
|
] |
199
|
|
|
); |
200
|
|
|
$table->addColumn( |
201
|
|
|
'user_type', 'smallint', [ |
202
|
|
|
'notnull' => true, |
203
|
|
|
'length' => 1, |
204
|
|
|
'default' => 1, |
205
|
|
|
] |
206
|
|
|
); |
207
|
|
|
$table->addColumn( |
208
|
|
|
'instance', 'string', [ |
209
|
|
|
'default' => '', |
210
|
|
|
'length' => 255 |
211
|
|
|
] |
212
|
|
|
); |
213
|
|
|
$table->addColumn( |
214
|
|
|
'level', 'smallint', [ |
215
|
|
|
'notnull' => true, |
216
|
|
|
'length' => 1, |
217
|
|
|
] |
218
|
|
|
); |
219
|
|
|
$table->addColumn( |
220
|
|
|
'status', 'string', [ |
221
|
|
|
'notnull' => false, |
222
|
|
|
'length' => 15, |
223
|
|
|
] |
224
|
|
|
); |
225
|
|
|
$table->addColumn( |
226
|
|
|
'note', 'text', [ |
227
|
|
|
'notnull' => false |
228
|
|
|
] |
229
|
|
|
); |
230
|
|
|
$table->addColumn( |
231
|
|
|
'cached_name', 'string', [ |
232
|
|
|
'notnull' => false, |
233
|
|
|
'length' => 255, |
234
|
|
|
'default' => '' |
235
|
|
|
] |
236
|
|
|
); |
237
|
|
|
$table->addColumn( |
238
|
|
|
'cached_update', 'datetime', [ |
239
|
|
|
'notnull' => false, |
240
|
|
|
] |
241
|
|
|
); |
242
|
|
|
$table->addColumn( |
243
|
|
|
'contact_id', 'string', [ |
244
|
|
|
'notnull' => false, |
245
|
|
|
'length' => 127, |
246
|
|
|
] |
247
|
|
|
); |
248
|
|
|
$table->addColumn( |
249
|
|
|
'contact_meta', 'text', [ |
250
|
|
|
'notnull' => false |
251
|
|
|
] |
252
|
|
|
); |
253
|
|
|
$table->addColumn( |
254
|
|
|
'joined', 'datetime', [ |
255
|
|
|
'notnull' => false, |
256
|
|
|
] |
257
|
|
|
); |
258
|
|
|
|
259
|
|
|
$table->setPrimaryKey(['id']); |
260
|
|
|
$table->addIndex( |
261
|
|
|
['circle_id', 'single_id', 'user_id', 'user_type', 'instance', 'level'], 'csuil' |
262
|
|
|
); |
263
|
|
|
$table->addIndex(['circle_id', 'single_id'], 'cs'); |
264
|
|
|
$table->addIndex(['contact_id']); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* CIRCLES_REMOTE |
270
|
|
|
*/ |
271
|
|
|
if (!$schema->hasTable('circles_remote')) { |
272
|
|
|
$table = $schema->createTable('circles_remote'); |
273
|
|
|
$table->addColumn( |
274
|
|
|
'id', 'integer', [ |
275
|
|
|
'autoincrement' => true, |
276
|
|
|
'notnull' => true, |
277
|
|
|
'length' => 4, |
278
|
|
|
'unsigned' => true, |
279
|
|
|
] |
280
|
|
|
); |
281
|
|
|
$table->addColumn( |
282
|
|
|
'type', 'string', [ |
283
|
|
|
'notnull' => true, |
284
|
|
|
'length' => 15, |
285
|
|
|
'default' => 'Unknown' |
286
|
|
|
] |
287
|
|
|
); |
288
|
|
|
$table->addColumn( |
289
|
|
|
'interface', 'integer', [ |
290
|
|
|
'notnull' => true, |
291
|
|
|
'length' => 1, |
292
|
|
|
'default' => 0 |
293
|
|
|
] |
294
|
|
|
); |
295
|
|
|
$table->addColumn( |
296
|
|
|
'uid', 'string', [ |
297
|
|
|
'notnull' => false, |
298
|
|
|
'length' => 20, |
299
|
|
|
] |
300
|
|
|
); |
301
|
|
|
$table->addColumn( |
302
|
|
|
'instance', 'string', [ |
303
|
|
|
'notnull' => false, |
304
|
|
|
'length' => 127, |
305
|
|
|
] |
306
|
|
|
); |
307
|
|
|
$table->addColumn( |
308
|
|
|
'href', 'string', [ |
309
|
|
|
'notnull' => false, |
310
|
|
|
'length' => 254, |
311
|
|
|
] |
312
|
|
|
); |
313
|
|
|
$table->addColumn( |
314
|
|
|
'item', 'text', [ |
315
|
|
|
'notnull' => false, |
316
|
|
|
] |
317
|
|
|
); |
318
|
|
|
$table->addColumn( |
319
|
|
|
'creation', 'datetime', [ |
320
|
|
|
'notnull' => false, |
321
|
|
|
] |
322
|
|
|
); |
323
|
|
|
|
324
|
|
|
$table->setPrimaryKey(['id']); |
325
|
|
|
$table->addUniqueIndex(['instance']); |
326
|
|
|
$table->addIndex(['uid']); |
327
|
|
|
$table->addIndex(['href']); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* CIRCLES_EVENT |
333
|
|
|
*/ |
334
|
|
|
if (!$schema->hasTable('circles_event')) { |
335
|
|
|
$table = $schema->createTable('circles_event'); |
336
|
|
|
$table->addColumn( |
337
|
|
|
'token', 'string', [ |
338
|
|
|
'notnull' => false, |
339
|
|
|
'length' => 63, |
340
|
|
|
] |
341
|
|
|
); |
342
|
|
|
$table->addColumn( |
343
|
|
|
'event', 'text', [ |
344
|
|
|
'notnull' => false |
345
|
|
|
] |
346
|
|
|
); |
347
|
|
|
$table->addColumn( |
348
|
|
|
'result', 'text', [ |
349
|
|
|
'notnull' => false |
350
|
|
|
] |
351
|
|
|
); |
352
|
|
|
$table->addColumn( |
353
|
|
|
'instance', 'string', [ |
354
|
|
|
'length' => 255, |
355
|
|
|
'notnull' => false |
356
|
|
|
] |
357
|
|
|
); |
358
|
|
|
$table->addColumn( |
359
|
|
|
'interface', 'integer', [ |
360
|
|
|
'notnull' => true, |
361
|
|
|
'length' => 1, |
362
|
|
|
'default' => 0 |
363
|
|
|
] |
364
|
|
|
); |
365
|
|
|
$table->addColumn( |
366
|
|
|
'severity', 'integer', [ |
367
|
|
|
'length' => 3, |
368
|
|
|
'notnull' => false |
369
|
|
|
] |
370
|
|
|
); |
371
|
|
|
$table->addColumn( |
372
|
|
|
'status', 'integer', [ |
373
|
|
|
'length' => 3, |
374
|
|
|
'notnull' => false |
375
|
|
|
] |
376
|
|
|
); |
377
|
|
|
$table->addColumn( |
378
|
|
|
'creation', 'bigint', [ |
379
|
|
|
'length' => 14, |
380
|
|
|
'notnull' => false |
381
|
|
|
] |
382
|
|
|
); |
383
|
|
|
|
384
|
|
|
$table->addUniqueIndex(['token', 'instance']); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* CIRCLES_MEMBERSHIP |
390
|
|
|
*/ |
391
|
|
|
if (!$schema->hasTable('circles_membership')) { |
392
|
|
|
$table = $schema->createTable('circles_membership'); |
393
|
|
|
|
394
|
|
|
$table->addColumn( |
395
|
|
|
'circle_id', 'string', [ |
396
|
|
|
'notnull' => true, |
397
|
|
|
'length' => 15, |
398
|
|
|
] |
399
|
|
|
); |
400
|
|
|
$table->addColumn( |
401
|
|
|
'single_id', 'string', [ |
402
|
|
|
'notnull' => true, |
403
|
|
|
'length' => 15, |
404
|
|
|
] |
405
|
|
|
); |
406
|
|
|
$table->addColumn( |
407
|
|
|
'level', 'integer', [ |
408
|
|
|
'notnull' => true, |
409
|
|
|
'length' => 1, |
410
|
|
|
'unsigned' => true |
411
|
|
|
] |
412
|
|
|
); |
413
|
|
|
$table->addColumn( |
414
|
|
|
'inheritance_first', 'string', [ |
415
|
|
|
'notnull' => true, |
416
|
|
|
'length' => 15, |
417
|
|
|
] |
418
|
|
|
); |
419
|
|
|
$table->addColumn( |
420
|
|
|
'inheritance_last', 'string', [ |
421
|
|
|
'notnull' => true, |
422
|
|
|
'length' => 15, |
423
|
|
|
] |
424
|
|
|
); |
425
|
|
|
$table->addColumn( |
426
|
|
|
'inheritance_depth', 'integer', [ |
427
|
|
|
'notnull' => true, |
428
|
|
|
'length' => 2, |
429
|
|
|
'unsigned' => true |
430
|
|
|
] |
431
|
|
|
); |
432
|
|
|
$table->addColumn( |
433
|
|
|
'inheritance_path', 'text', [ |
434
|
|
|
'notnull' => true |
435
|
|
|
] |
436
|
|
|
); |
437
|
|
|
|
438
|
|
|
$table->addIndex(['single_id']); |
439
|
|
|
$table->addUniqueIndex(['single_id', 'circle_id']); |
440
|
|
|
$table->addIndex(['inheritance_first', 'inheritance_last', 'circle_id'], 'ifilci'); |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* CIRCLES_MOUNT |
446
|
|
|
*/ |
447
|
|
|
if (!$schema->hasTable('circles_mount')) { |
448
|
|
|
$table = $schema->createTable('circles_mount'); |
449
|
|
|
$table->addColumn( |
450
|
|
|
'id', 'integer', [ |
451
|
|
|
'autoincrement' => true, |
452
|
|
|
'notnull' => true, |
453
|
|
|
'length' => 11, |
454
|
|
|
'unsigned' => true, |
455
|
|
|
] |
456
|
|
|
); |
457
|
|
|
$table->addColumn( |
458
|
|
|
'mount_id', 'string', [ |
459
|
|
|
'notnull' => false, |
460
|
|
|
'length' => 15 |
461
|
|
|
] |
462
|
|
|
); |
463
|
|
|
$table->addColumn( |
464
|
|
|
'circle_id', 'string', [ |
465
|
|
|
'notnull' => false, |
466
|
|
|
'length' => 15 |
467
|
|
|
] |
468
|
|
|
); |
469
|
|
|
$table->addColumn( |
470
|
|
|
'single_id', 'string', [ |
471
|
|
|
'notnull' => false, |
472
|
|
|
'length' => 15 |
473
|
|
|
] |
474
|
|
|
); |
475
|
|
|
$table->addColumn( |
476
|
|
|
'token', 'string', [ |
477
|
|
|
'notnull' => false, |
478
|
|
|
'length' => 63 |
479
|
|
|
] |
480
|
|
|
); |
481
|
|
|
$table->addColumn( |
482
|
|
|
'parent', 'integer', [ |
483
|
|
|
'notnull' => false, |
484
|
|
|
'length' => 11 |
485
|
|
|
] |
486
|
|
|
); |
487
|
|
|
$table->addColumn( |
488
|
|
|
'mountpoint', 'text', [ |
489
|
|
|
'notnull' => false |
490
|
|
|
] |
491
|
|
|
); |
492
|
|
|
$table->addColumn( |
493
|
|
|
'mountpoint_hash', 'string', [ |
494
|
|
|
'notnull' => false, |
495
|
|
|
'length' => 64 |
496
|
|
|
] |
497
|
|
|
); |
498
|
|
|
|
499
|
|
|
$table->setPrimaryKey(['id']); |
500
|
|
|
$table->addIndex(['circle_id', 'mount_id', 'parent', 'token'], 'cmpt'); |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
|
504
|
|
|
/** |
505
|
|
|
* CIRCLES_MOUNTPOINT |
506
|
|
|
*/ |
507
|
|
|
if (!$schema->hasTable('circles_mountpoint')) { |
508
|
|
|
$table = $schema->createTable('circles_mountpoint'); |
509
|
|
|
$table->addColumn( |
510
|
|
|
'id', 'integer', [ |
511
|
|
|
'autoincrement' => true, |
512
|
|
|
'notnull' => true, |
513
|
|
|
'length' => 11, |
514
|
|
|
'unsigned' => true, |
515
|
|
|
] |
516
|
|
|
); |
517
|
|
|
$table->addColumn( |
518
|
|
|
'mount_id', 'string', [ |
519
|
|
|
'notnull' => false, |
520
|
|
|
'length' => 15 |
521
|
|
|
] |
522
|
|
|
); |
523
|
|
|
$table->addColumn( |
524
|
|
|
'single_id', 'string', [ |
525
|
|
|
'notnull' => false, |
526
|
|
|
'length' => 15 |
527
|
|
|
] |
528
|
|
|
); |
529
|
|
|
$table->addColumn( |
530
|
|
|
'mountpoint', 'text', [ |
531
|
|
|
'notnull' => false |
532
|
|
|
] |
533
|
|
|
); |
534
|
|
|
$table->addColumn( |
535
|
|
|
'mountpoint_hash', 'string', [ |
536
|
|
|
'notnull' => false, |
537
|
|
|
'length' => 64 |
538
|
|
|
] |
539
|
|
|
); |
540
|
|
|
|
541
|
|
|
$table->setPrimaryKey(['id']); |
542
|
|
|
$table->addIndex(['mount_id', 'single_id'], 'ms'); |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
|
546
|
|
|
/** |
547
|
|
|
* CIRCLES_SHARE_LOCK |
548
|
|
|
*/ |
549
|
|
|
if (!$schema->hasTable('circles_share_lock')) { |
550
|
|
|
$table = $schema->createTable('circles_share_lock'); |
551
|
|
|
$table->addColumn( |
552
|
|
|
'id', 'integer', [ |
553
|
|
|
'autoincrement' => true, |
554
|
|
|
'notnull' => true, |
555
|
|
|
'length' => 4, |
556
|
|
|
'unsigned' => true, |
557
|
|
|
] |
558
|
|
|
); |
559
|
|
|
$table->addColumn( |
560
|
|
|
'item_id', 'string', [ |
561
|
|
|
'notnull' => true, |
562
|
|
|
'length' => 15 |
563
|
|
|
] |
564
|
|
|
); |
565
|
|
|
$table->addColumn( |
566
|
|
|
'circle_id', 'string', [ |
567
|
|
|
'notnull' => true, |
568
|
|
|
'length' => 15 |
569
|
|
|
] |
570
|
|
|
); |
571
|
|
|
$table->addColumn( |
572
|
|
|
'instance', 'string', [ |
573
|
|
|
'notnull' => true, |
574
|
|
|
'length' => 127, |
575
|
|
|
] |
576
|
|
|
); |
577
|
|
|
|
578
|
|
|
$table->setPrimaryKey(['id']); |
579
|
|
|
$table->addUniqueIndex(['item_id', 'circle_id']); |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
return $schema; |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
|