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
|
|
|
$table = $schema->getTable('analytics_facts'); |
49
|
|
|
if (!$table->hasColumn('value')) { |
50
|
|
|
$table->addColumn('value', 'decimal', [ |
51
|
|
|
'notnull' => false, |
52
|
|
|
'precision' => 15, |
53
|
|
|
'scale' => 2, |
54
|
|
|
'default' => 0, |
55
|
|
|
]); |
56
|
|
|
} |
57
|
|
|
if (!$table->hasColumn('timestamp')) { |
58
|
|
|
$table->addColumn('timestamp', 'integer', [ |
59
|
|
|
'notnull' => false, |
60
|
|
|
'default' => 0, |
61
|
|
|
]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$table = $schema->getTable('analytics_dataset'); |
65
|
|
|
if (!$table->hasColumn('value')) { |
66
|
|
|
$table->addColumn('value', 'string', [ |
67
|
|
|
'notnull' => false, |
68
|
|
|
'length' => 64, |
69
|
|
|
]); |
70
|
|
|
} |
71
|
|
|
$column = $table->getColumn('link'); |
72
|
|
|
if ($column->getLength() !== 500) { |
73
|
|
|
$column->setLength(500); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$table = $schema->getTable('analytics_threshold'); |
77
|
|
|
if (!$table->hasColumn('value')) { |
78
|
|
|
$table->addColumn('value', 'decimal', [ |
79
|
|
|
'notnull' => false, |
80
|
|
|
'precision' => 15, |
81
|
|
|
'scale' => 2, |
82
|
|
|
'default' => 0, |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $schema; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param IOutput $output |
91
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
92
|
|
|
* @param array $options |
93
|
|
|
*/ |
94
|
|
|
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) |
95
|
|
|
{ |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|