-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathVersion010000001Date20250727094721.php
More file actions
68 lines (58 loc) · 1.75 KB
/
Version010000001Date20250727094721.php
File metadata and controls
68 lines (58 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*
* Copyright (c) 2020-2025 The Recognize contributors.
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
*/
declare(strict_types=1);
namespace OCA\Recognize\Migration;
use Closure;
use Doctrine\DBAL\Schema\SchemaException;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
final class Version010000001Date20250727094721 extends SimpleMigrationStep {
public function __construct(
private IDBConnection $db,
) {
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*
* @return ?ISchemaWrapper
* @throws SchemaException
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if ($schema->hasTable('recognize_face_detections')) {
$table = $schema->getTable('recognize_face_detections');
if (!$table->hasColumn('face_vector')) {
$table->addColumn('face_vector', Types::TEXT, [
'notnull' => false,
]);
return $schema;
}
}
return null;
}
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if (!$schema->hasTable('recognize_face_detections')) {
return;
}
$table = $schema->getTable('recognize_face_detections');
$copyData = $table->hasColumn('face_vector') && $table->hasColumn('vector');
if (!$copyData) {
return;
}
$query = $this->db->getQueryBuilder();
$query->update('recognize_face_detections')
->set('face_vector', 'vector');
$query->executeStatement();
}
}