1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace OCA\Analytics\Migration; |
6
|
|
|
|
7
|
|
|
use Closure; |
8
|
|
|
use OCP\DB\ISchemaWrapper; |
9
|
|
|
use OCP\IDBConnection; |
10
|
|
|
use OCP\Migration\IOutput; |
11
|
|
|
use OCP\Migration\SimpleMigrationStep; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Auto-generated migration step: Please modify to your needs! |
15
|
|
|
* sudo -u www-data php /var/www/nextcloud/occ migrations:execute analytics 3005Date20210508180000 |
16
|
|
|
*/ |
17
|
|
|
class Version3005Date20210508180000 extends SimpleMigrationStep |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** @var IDBConnection */ |
21
|
|
|
private $connection; |
22
|
|
|
|
23
|
|
|
public function __construct(IDBConnection $connection) |
24
|
|
|
{ |
25
|
|
|
$this->connection = $connection; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param IOutput $output |
30
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
31
|
|
|
* @param array $options |
32
|
|
|
*/ |
33
|
|
|
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) |
34
|
|
|
{ |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param IOutput $output |
39
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
40
|
|
|
* @param array $options |
41
|
|
|
* @return null|ISchemaWrapper |
42
|
|
|
*/ |
43
|
|
|
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) |
44
|
|
|
{ |
45
|
|
|
/** @var Schema $schema */ |
46
|
|
|
$schema = $schemaClosure(); |
47
|
|
|
|
48
|
|
|
if (!$schema->hasTable('analytics_dataset')) { |
49
|
|
|
$table = $schema->createTable('analytics_dataset'); |
50
|
|
|
$table->addColumn('id', 'integer', [ |
51
|
|
|
'autoincrement' => true, |
52
|
|
|
'notnull' => true, |
53
|
|
|
]); |
54
|
|
|
$table->addColumn('user_id', 'string', [ |
55
|
|
|
'notnull' => true, |
56
|
|
|
'length' => 64, |
57
|
|
|
]); |
58
|
|
|
$table->addColumn('name', 'string', [ |
59
|
|
|
'notnull' => true, |
60
|
|
|
'length' => 64, |
61
|
|
|
]); |
62
|
|
|
$table->addColumn('subheader', 'string', [ |
63
|
|
|
'notnull' => false, |
64
|
|
|
'length' => 256, |
65
|
|
|
]); |
66
|
|
|
$table->addColumn('type', 'integer', [ |
67
|
|
|
'notnull' => false, |
68
|
|
|
]); |
69
|
|
|
$table->addColumn('link', 'string', [ |
70
|
|
|
'notnull' => false, |
71
|
|
|
'length' => 500, |
72
|
|
|
]); |
73
|
|
|
$table->addColumn('visualization', 'string', [ |
74
|
|
|
'notnull' => false, |
75
|
|
|
'length' => 10, |
76
|
|
|
]); |
77
|
|
|
$table->addColumn('chart', 'string', [ |
78
|
|
|
'notnull' => false, |
79
|
|
|
'length' => 256, |
80
|
|
|
]); |
81
|
|
|
$table->addColumn('parent', 'integer', [ |
82
|
|
|
'notnull' => false, |
83
|
|
|
]); |
84
|
|
|
$table->addColumn('dimension1', 'string', [ |
85
|
|
|
'notnull' => false, |
86
|
|
|
'length' => 64, |
87
|
|
|
]); |
88
|
|
|
$table->addColumn('dimension2', 'string', [ |
89
|
|
|
'notnull' => false, |
90
|
|
|
'length' => 64, |
91
|
|
|
]); |
92
|
|
|
$table->addColumn('dimension3', 'string', [ |
93
|
|
|
'notnull' => false, |
94
|
|
|
'length' => 64, |
95
|
|
|
]); |
96
|
|
|
$table->addColumn('value', 'string', [ |
97
|
|
|
'notnull' => false, |
98
|
|
|
'length' => 64, |
99
|
|
|
]); |
100
|
|
|
$table->addColumn('chartoptions', 'string', [ |
101
|
|
|
'notnull' => false, |
102
|
|
|
'length' => 1000, |
103
|
|
|
]); |
104
|
|
|
$table->addColumn('dataoptions', 'string', [ |
105
|
|
|
'notnull' => false, |
106
|
|
|
'length' => 1000, |
107
|
|
|
]); |
108
|
|
|
$table->addColumn('filteroptions', 'string', [ |
109
|
|
|
'notnull' => false, |
110
|
|
|
'length' => 1000, |
111
|
|
|
]); |
112
|
|
|
$table->setPrimaryKey(['id']); |
113
|
|
|
$table->addIndex(['user_id'], 'analytics_dataset_user_id_idx'); |
114
|
|
|
} else { |
115
|
|
|
$table = $schema->getTable('analytics_dataset'); |
116
|
|
|
if (!$table->hasColumn('value')) { |
117
|
|
|
$table->addColumn('value', 'string', [ |
118
|
|
|
'notnull' => false, |
119
|
|
|
'length' => 64, |
120
|
|
|
]); |
121
|
|
|
} |
122
|
|
|
$column = $table->getColumn('link'); |
123
|
|
|
if ($column->getLength() !== 500) { |
124
|
|
|
$column->setLength(500); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
if (!$table->hasColumn('dataoptions')) { |
128
|
|
|
$table->addColumn('dataoptions', 'string', [ |
129
|
|
|
'notnull' => false, |
130
|
|
|
'length' => 1000, |
131
|
|
|
]); |
132
|
|
|
} |
133
|
|
|
if (!$table->hasColumn('filteroptions')) { |
134
|
|
|
$table->addColumn('filteroptions', 'string', [ |
135
|
|
|
'notnull' => false, |
136
|
|
|
'length' => 1000, |
137
|
|
|
]); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
if (!$schema->hasTable('analytics_facts')) { |
142
|
|
|
$table = $schema->createTable('analytics_facts'); |
143
|
|
|
$table->addColumn('id', 'integer', [ |
144
|
|
|
'autoincrement' => true, |
145
|
|
|
'notnull' => true, |
146
|
|
|
]); |
147
|
|
|
$table->addColumn('user_id', 'string', [ |
148
|
|
|
'notnull' => true, |
149
|
|
|
'length' => 64, |
150
|
|
|
]); |
151
|
|
|
$table->addColumn('dataset', 'integer', [ |
152
|
|
|
'notnull' => true, |
153
|
|
|
]); |
154
|
|
|
$table->addColumn('dimension1', 'string', [ |
155
|
|
|
'notnull' => false, |
156
|
|
|
'length' => 64, |
157
|
|
|
]); |
158
|
|
|
$table->addColumn('dimension2', 'string', [ |
159
|
|
|
'notnull' => false, |
160
|
|
|
'length' => 64, |
161
|
|
|
]); |
162
|
|
|
$table->addColumn('dimension3', 'decimal', [ |
163
|
|
|
'notnull' => false, |
164
|
|
|
]); |
165
|
|
|
$table->addColumn('value', 'decimal', [ |
166
|
|
|
'notnull' => false, |
167
|
|
|
'precision' => 15, |
168
|
|
|
'scale' => 2, |
169
|
|
|
'default' => 0, |
170
|
|
|
]); |
171
|
|
|
$table->addColumn('timestamp', 'integer', [ |
172
|
|
|
'notnull' => false, |
173
|
|
|
'default' => 0, |
174
|
|
|
]); |
175
|
|
|
$table->setPrimaryKey(['id']); |
176
|
|
|
$table->addIndex(['dataset'], 'analytics_facts_dataset_idx'); |
177
|
|
|
} else { |
178
|
|
|
$table = $schema->getTable('analytics_facts'); |
179
|
|
|
if (!$table->hasColumn('value')) { |
180
|
|
|
$table->addColumn('value', 'decimal', [ |
181
|
|
|
'notnull' => false, |
182
|
|
|
'precision' => 15, |
183
|
|
|
'scale' => 2, |
184
|
|
|
'default' => 0, |
185
|
|
|
]); |
186
|
|
|
} |
187
|
|
|
if (!$table->hasColumn('timestamp')) { |
188
|
|
|
$table->addColumn('timestamp', 'integer', [ |
189
|
|
|
'notnull' => false, |
190
|
|
|
'default' => 0, |
191
|
|
|
]); |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
if (!$schema->hasTable('analytics_share')) { |
196
|
|
|
$table = $schema->createTable('analytics_share'); |
197
|
|
|
$table->addColumn('id', 'integer', [ |
198
|
|
|
'autoincrement' => true, |
199
|
|
|
'notnull' => true, |
200
|
|
|
]); |
201
|
|
|
$table->addColumn('dataset', 'integer', [ |
202
|
|
|
'notnull' => true, |
203
|
|
|
]); |
204
|
|
|
$table->addColumn('type', 'integer', [ |
205
|
|
|
'notnull' => false, |
206
|
|
|
]); |
207
|
|
|
$table->addColumn('uid_owner', 'string', [ |
208
|
|
|
'notnull' => false, |
209
|
|
|
'length' => 64, |
210
|
|
|
]); |
211
|
|
|
$table->addColumn('uid_initiator', 'string', [ |
212
|
|
|
'notnull' => true, |
213
|
|
|
'length' => 64, |
214
|
|
|
]); |
215
|
|
|
$table->addColumn('permissions', 'integer', [ |
216
|
|
|
'notnull' => false, |
217
|
|
|
]); |
218
|
|
|
$table->addColumn('token', 'string', [ |
219
|
|
|
'notnull' => false, |
220
|
|
|
'length' => 32, |
221
|
|
|
]); |
222
|
|
|
$table->addColumn('password', 'string', [ |
223
|
|
|
'notnull' => false, |
224
|
|
|
'length' => 64, |
225
|
|
|
]); |
226
|
|
|
$table->setPrimaryKey(['id']); |
227
|
|
|
$table->addIndex(['dataset'], 'analytics_share_dataset_idx'); |
228
|
|
|
$table->addIndex(['uid_owner'], 'analytics_share_uid_owner_idx'); |
229
|
|
|
$table->addIndex(['token'], 'analytics_share_token_idx'); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
if (!$schema->hasTable('analytics_threshold')) { |
233
|
|
|
$table = $schema->createTable('analytics_threshold'); |
234
|
|
|
$table->addColumn('id', 'integer', [ |
235
|
|
|
'autoincrement' => true, |
236
|
|
|
'notnull' => true, |
237
|
|
|
]); |
238
|
|
|
$table->addColumn('user_id', 'string', [ |
239
|
|
|
'notnull' => true, |
240
|
|
|
'length' => 64, |
241
|
|
|
]); |
242
|
|
|
$table->addColumn('dataset', 'integer', [ |
243
|
|
|
'notnull' => true, |
244
|
|
|
]); |
245
|
|
|
$table->addColumn('name', 'string', [ |
246
|
|
|
'notnull' => false, |
247
|
|
|
'length' => 64, |
248
|
|
|
]); |
249
|
|
|
$table->addColumn('dimension1', 'string', [ |
250
|
|
|
'notnull' => false, |
251
|
|
|
'length' => 64, |
252
|
|
|
]); |
253
|
|
|
$table->addColumn('dimension2', 'string', [ |
254
|
|
|
'notnull' => false, |
255
|
|
|
'length' => 64, |
256
|
|
|
]); |
257
|
|
|
$table->addColumn('dimension3', 'decimal', [ |
258
|
|
|
'notnull' => false, |
259
|
|
|
]); |
260
|
|
|
$table->addColumn('value', 'decimal', [ |
261
|
|
|
'notnull' => false, |
262
|
|
|
'precision' => 15, |
263
|
|
|
'scale' => 2, |
264
|
|
|
'default' => 0, |
265
|
|
|
]); |
266
|
|
|
$table->addColumn('option', 'string', [ |
267
|
|
|
'notnull' => false, |
268
|
|
|
'length' => 5, |
269
|
|
|
]); |
270
|
|
|
$table->addColumn('severity', 'integer', [ |
271
|
|
|
'notnull' => true, |
272
|
|
|
]); |
273
|
|
|
$table->setPrimaryKey(['id']); |
274
|
|
|
$table->addIndex(['dataset'], 'analytics_threshold_dset_idx'); |
275
|
|
|
} else { |
276
|
|
|
$table = $schema->getTable('analytics_threshold'); |
277
|
|
|
if (!$table->hasColumn('value')) { |
278
|
|
|
$table->addColumn('value', 'decimal', [ |
279
|
|
|
'notnull' => false, |
280
|
|
|
'precision' => 15, |
281
|
|
|
'scale' => 2, |
282
|
|
|
'default' => 0, |
283
|
|
|
]); |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
if (!$schema->hasTable('analytics_dataload')) { |
288
|
|
|
$table = $schema->createTable('analytics_dataload'); |
289
|
|
|
$table->addColumn('id', 'integer', [ |
290
|
|
|
'autoincrement' => true, |
291
|
|
|
'notnull' => true, |
292
|
|
|
]); |
293
|
|
|
$table->addColumn('user_id', 'string', [ |
294
|
|
|
'notnull' => true, |
295
|
|
|
'length' => 64, |
296
|
|
|
]); |
297
|
|
|
$table->addColumn('dataset', 'integer', [ |
298
|
|
|
'notnull' => true, |
299
|
|
|
]); |
300
|
|
|
$table->addColumn('datasource', 'integer', [ |
301
|
|
|
'notnull' => true, |
302
|
|
|
]); |
303
|
|
|
$table->addColumn('name', 'string', [ |
304
|
|
|
'notnull' => false, |
305
|
|
|
'length' => 64, |
306
|
|
|
]); |
307
|
|
|
$table->addColumn('option', 'string', [ |
308
|
|
|
'notnull' => false, |
309
|
|
|
'length' => 500, |
310
|
|
|
]); |
311
|
|
|
$table->addColumn('schedule', 'string', [ |
312
|
|
|
'notnull' => false, |
313
|
|
|
'length' => 1, |
314
|
|
|
]); |
315
|
|
|
$table->setPrimaryKey(['id']); |
316
|
|
|
$table->addIndex(['dataset'], 'analytics_dataload_dataset_idx'); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
if (!$schema->hasTable('analytics_whats_new')) { |
320
|
|
|
$table = $schema->createTable('analytics_whats_new'); |
321
|
|
|
$table->addColumn('id', 'integer', [ |
322
|
|
|
'autoincrement' => true, |
323
|
|
|
'notnull' => true, |
324
|
|
|
'length' => 4, |
325
|
|
|
'unsigned' => true, |
326
|
|
|
]); |
327
|
|
|
$table->addColumn('version', 'string', [ |
328
|
|
|
'notnull' => true, |
329
|
|
|
'length' => 64, |
330
|
|
|
'default' => '11', |
331
|
|
|
]); |
332
|
|
|
$table->addColumn('etag', 'string', [ |
333
|
|
|
'notnull' => true, |
334
|
|
|
'length' => 64, |
335
|
|
|
'default' => '', |
336
|
|
|
]); |
337
|
|
|
$table->addColumn('last_check', 'integer', [ |
338
|
|
|
'notnull' => true, |
339
|
|
|
'length' => 4, |
340
|
|
|
'unsigned' => true, |
341
|
|
|
'default' => 0, |
342
|
|
|
]); |
343
|
|
|
$table->addColumn('data', 'text', [ |
344
|
|
|
'notnull' => true, |
345
|
|
|
'default' => '', |
346
|
|
|
]); |
347
|
|
|
$table->setPrimaryKey(['id']); |
348
|
|
|
$table->addUniqueIndex(['version'], 'analytics_whats_new_v_idx'); |
349
|
|
|
$table->addIndex(['version', 'etag'], 'analytics_whats_new_v_e_idx'); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
return $schema; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* @param IOutput $output |
357
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
358
|
|
|
* @param array $options |
359
|
|
|
*/ |
360
|
|
|
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) |
361
|
|
|
{ |
362
|
|
|
} |
363
|
|
|
} |
364
|
|
|
|