Completed
Push — improveTravis ( 2b49a6...4c6776 )
by Matias
08:15
created

Version000509Date20191203003814::preSchemaChange()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 1
ccs 0
cts 1
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace OCA\FaceRecognition\Migration;
6
7
use Closure;
8
use OCP\DB\ISchemaWrapper;
9
use OCP\Migration\SimpleMigrationStep;
10
use OCP\Migration\IOutput;
11
12
/**
13
 * Auto-generated migration step: Please modify to your needs!
14
 */
15
class Version000509Date20191203003814 extends SimpleMigrationStep {
16
17
	/**
18
	 * @param IOutput $output
19
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
20
	 * @param array $options
21
	 */
22
	public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
23
	}
24
25
	/**
26
	 * @param IOutput $output
27
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
28
	 * @param array $options
29
	 * @return null|ISchemaWrapper
30
	 */
31
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
32
		/** @var ISchemaWrapper $schema */
33
		$schema = $schemaClosure();
34
35
		if (!$schema->hasTable('facerecog_models')) {
36
			$table = $schema->createTable('facerecog_models');
37
			$table->addColumn('id', 'integer', [
38
				'autoincrement' => true,
39
				'notnull' => true,
40
				'length' => 4,
41
			]);
42
			$table->addColumn('name', 'string', [
43
				'notnull' => true,
44
				'length' => 256,
45
			]);
46
			$table->addColumn('description', 'string', [
47
				'notnull' => false,
48
				'length' => 1024,
49
			]);
50
			$table->setPrimaryKey(['id']);
51
		}
52
53
		if (!$schema->hasTable('facerecog_persons')) {
54
			$table = $schema->createTable('facerecog_persons');
55
			$table->addColumn('id', 'integer', [
56
				'autoincrement' => true,
57
				'notnull' => true,
58
				'unsigned' => true,
59
			]);
60
			$table->addColumn('user', 'string', [
61
				'notnull' => true,
62
				'length' => 64,
63
			]);
64
			$table->addColumn('name', 'string', [
65
				'notnull' => true,
66
				'length' => 256,
67
			]);
68
			$table->addColumn('is_valid', 'boolean', [
69
				'notnull' => true,
70
				'default' => false,
71
			]);
72
			$table->addColumn('last_generation_time', 'datetime', [
73
				'notnull' => false,
74
			]);
75
			$table->addColumn('linked_user', 'string', [
76
				'notnull' => false,
77
				'length' => 64,
78
			]);
79
			$table->setPrimaryKey(['id']);
80
			$table->addIndex(['user'], 'persons_user_idx');
81
		}
82
83
		if (!$schema->hasTable('facerecog_images')) {
84
			$table = $schema->createTable('facerecog_images');
85
			$table->addColumn('id', 'integer', [
86
				'autoincrement' => true,
87
				'notnull' => true,
88
				'length' => 4,
89
			]);
90
			$table->addColumn('user', 'string', [
91
				'notnull' => true,
92
				'length' => 64,
93
			]);
94
			$table->addColumn('file', 'integer', [
95
				'notnull' => true,
96
				'length' => 4,
97
			]);
98
			$table->addColumn('model', 'integer', [
99
				'notnull' => true,
100
				'length' => 4,
101
			]);
102
			$table->addColumn('is_processed', 'boolean', [
103
				'notnull' => true,
104
				'default' => false,
105
			]);
106
			$table->addColumn('error', 'string', [
107
				'notnull' => false,
108
				'length' => 1024,
109
			]);
110
			$table->addColumn('last_processed_time', 'datetime', [
111
				'notnull' => false,
112
			]);
113
			$table->addColumn('processing_duration', 'bigint', [
114
				'notnull' => false,
115
				'length' => 8,
116
			]);
117
			$table->setPrimaryKey(['id']);
118
			$table->addIndex(['user'], 'images_user_idx');
119
			$table->addIndex(['file'], 'images_file_idx');
120
			$table->addIndex(['model'], 'images_model_idx');
121
		}
122
123
		if (!$schema->hasTable('facerecog_faces')) {
124
			$table = $schema->createTable('facerecog_faces');
125
			$table->addColumn('id', 'integer', [
126
				'autoincrement' => true,
127
				'notnull' => true,
128
				'length' => 4,
129
			]);
130
			$table->addColumn('image', 'integer', [
131
				'notnull' => true,
132
				'length' => 4,
133
			]);
134
			$table->addColumn('person', 'integer', [
135
				'notnull' => false,
136
				'length' => 4,
137
			]);
138
			$table->addColumn('left', 'integer', [
139
				'notnull' => true,
140
				'length' => 4,
141
			]);
142
			$table->addColumn('right', 'integer', [
143
				'notnull' => true,
144
				'length' => 4,
145
			]);
146
			$table->addColumn('top', 'integer', [
147
				'notnull' => true,
148
				'length' => 4,
149
			]);
150
			$table->addColumn('bottom', 'integer', [
151
				'notnull' => true,
152
				'length' => 4,
153
			]);
154
			$table->addColumn('confidence', 'float', [
155
				'notnull' => true,
156
				'length' => 4,
157
			]);
158
			$table->addColumn('landmarks', 'json', [
159
				'notnull' => true,
160
			]);
161
			$table->addColumn('descriptor', 'json', [
162
				'notnull' => true,
163
			]);
164
			$table->addColumn('creation_time', 'datetime', [
165
				'notnull' => true,
166
			]);
167
			$table->setPrimaryKey(['id']);
168
			$table->addIndex(['image'], 'faces_image_idx');
169
			$table->addIndex(['person'], 'faces_person_idx');
170
		}
171
		return $schema;
172
	}
173
174
	/**
175
	 * @param IOutput $output
176
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
177
	 * @param array $options
178
	 */
179
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
180
	}
181
}
182