|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace OCA\WorkflowEngine\Migration; |
|
6
|
|
|
|
|
7
|
|
|
use Closure; |
|
8
|
|
|
use Doctrine\DBAL\Schema\Table; |
|
9
|
|
|
use Doctrine\DBAL\Types\Type; |
|
10
|
|
|
use OCP\DB\ISchemaWrapper; |
|
11
|
|
|
use OCP\Migration\SimpleMigrationStep; |
|
12
|
|
|
use OCP\Migration\IOutput; |
|
13
|
|
|
|
|
14
|
|
|
class Version2019Date20190808074233 extends SimpleMigrationStep { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @param IOutput $output |
|
18
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
19
|
|
|
* @param array $options |
|
20
|
|
|
* @return null|ISchemaWrapper |
|
21
|
|
|
*/ |
|
22
|
|
|
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
23
|
|
|
/** @var ISchemaWrapper $schema */ |
|
24
|
|
|
$schema = $schemaClosure(); |
|
25
|
|
|
|
|
26
|
|
|
if (!$schema->hasTable('flow_checks')) { |
|
27
|
|
|
$table = $schema->createTable('flow_checks'); |
|
28
|
|
|
$table->addColumn('id', Type::INTEGER, [ |
|
29
|
|
|
'autoincrement' => true, |
|
30
|
|
|
'notnull' => true, |
|
31
|
|
|
'length' => 4, |
|
32
|
|
|
]); |
|
33
|
|
|
$table->addColumn('class', Type::STRING, [ |
|
34
|
|
|
'notnull' => true, |
|
35
|
|
|
'length' => 256, |
|
36
|
|
|
]); |
|
37
|
|
|
$table->addColumn('operator', Type::STRING, [ |
|
38
|
|
|
'notnull' => true, |
|
39
|
|
|
'length' => 16, |
|
40
|
|
|
]); |
|
41
|
|
|
$table->addColumn('value', Type::TEXT, [ |
|
42
|
|
|
'notnull' => false, |
|
43
|
|
|
]); |
|
44
|
|
|
$table->addColumn('hash', Type::STRING, [ |
|
45
|
|
|
'notnull' => true, |
|
46
|
|
|
'length' => 32, |
|
47
|
|
|
]); |
|
48
|
|
|
$table->setPrimaryKey(['id']); |
|
49
|
|
|
$table->addUniqueIndex(['hash'], 'flow_unique_hash'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
if (!$schema->hasTable('flow_operations')) { |
|
53
|
|
|
$table = $schema->createTable('flow_operations'); |
|
54
|
|
|
$table->addColumn('id', Type::INTEGER, [ |
|
55
|
|
|
'autoincrement' => true, |
|
56
|
|
|
'notnull' => true, |
|
57
|
|
|
'length' => 4, |
|
58
|
|
|
]); |
|
59
|
|
|
$table->addColumn('class', Type::STRING, [ |
|
60
|
|
|
'notnull' => true, |
|
61
|
|
|
'length' => 256, |
|
62
|
|
|
]); |
|
63
|
|
|
$table->addColumn('name', Type::STRING, [ |
|
64
|
|
|
'notnull' => true, |
|
65
|
|
|
'length' => 256, |
|
66
|
|
|
]); |
|
67
|
|
|
$table->addColumn('checks', Type::TEXT, [ |
|
68
|
|
|
'notnull' => false, |
|
69
|
|
|
]); |
|
70
|
|
|
$table->addColumn('operation', Type::TEXT, [ |
|
71
|
|
|
'notnull' => false, |
|
72
|
|
|
]); |
|
73
|
|
|
$this->ensureEntityColumns($table); |
|
74
|
|
|
$table->setPrimaryKey(['id']); |
|
75
|
|
|
} else { |
|
76
|
|
|
$table = $schema->getTable('flow_operations'); |
|
77
|
|
|
$this->ensureEntityColumns($table); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
if (!$schema->hasTable('flow_operations_scope')) { |
|
81
|
|
|
$table = $schema->createTable('flow_operations_scope'); |
|
82
|
|
|
$table->addColumn('id', Type::BIGINT, [ |
|
83
|
|
|
'autoincrement' => true, |
|
84
|
|
|
'notnull' => true, |
|
85
|
|
|
'length' => 4, |
|
86
|
|
|
]); |
|
87
|
|
|
$table->addColumn('operation_id', Type::INTEGER, [ |
|
88
|
|
|
'notnull' => true, |
|
89
|
|
|
'length' => 4, |
|
90
|
|
|
]); |
|
91
|
|
|
$table->addColumn('type', Type::INTEGER, [ |
|
92
|
|
|
'notnull' => true, |
|
93
|
|
|
'length' => 4, |
|
94
|
|
|
]); |
|
95
|
|
|
$table->addColumn('value', Type::STRING, [ |
|
96
|
|
|
'notnull' => false, |
|
97
|
|
|
'length' => 64, |
|
98
|
|
|
]); |
|
99
|
|
|
$table->setPrimaryKey(['id']); |
|
100
|
|
|
$table->addUniqueIndex(['operation_id', 'type', 'value'], 'flow_unique_scope'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $schema; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
protected function ensureEntityColumns(Table $table) { |
|
107
|
|
|
if(!$table->hasColumn('entity')) { |
|
108
|
|
|
$table->addColumn('entity', Type::STRING, [ |
|
109
|
|
|
'notnull' => true, |
|
110
|
|
|
'length' => 256, |
|
111
|
|
|
]); |
|
112
|
|
|
} |
|
113
|
|
|
if(!$table->hasColumn('events')) { |
|
114
|
|
|
$table->addColumn('events', Type::TEXT, [ |
|
115
|
|
|
'notnull' => true, |
|
116
|
|
|
'default' => '[]', |
|
117
|
|
|
]); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|