Skip to content

Commit 56f7233

Browse files
committed
fix(mariadb): Rename vector col to face_vector
'vector' is a reserved keyword now in mariadb see #1295 Signed-off-by: Marcel Klehr <[email protected]>
1 parent f3ee7a4 commit 56f7233

File tree

5 files changed

+132
-10
lines changed

5 files changed

+132
-10
lines changed

.github/workflows/phpunit-mariadb.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
matrix:
7575
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
7676
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
77-
mariadb-versions: ['10.6', '10.11']
77+
mariadb-versions: ['10.6', '10.11', '11.8']
7878

7979
name: MariaDB ${{ matrix.mariadb-versions }} PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
8080

lib/Db/FaceDetection.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@
2121
* @method float getY()
2222
* @method float getHeight()
2323
* @method float getWidth()
24-
* @method float[] getVector()
25-
* @method setVector(array $vector)
2624
* @method setX(float $x)
2725
* @method setY(float $y)
2826
* @method setHeight(float $height)
2927
* @method setWidth(float $width)
3028
* @method setClusterId(int|null $clusterId)
3129
* @method int|null getClusterId()
3230
* @method float getThreshold()
33-
* @method setThreshold(float $threshold)
31+
* @method setThreshold(float $threshold)
3432
*/
3533
class FaceDetection extends Entity {
3634
protected $fileId;
@@ -39,17 +37,17 @@ class FaceDetection extends Entity {
3937
protected $y;
4038
protected $height;
4139
protected $width;
42-
protected $vector;
40+
protected $faceVector;
4341
protected $clusterId;
4442
protected $threshold;
4543
/**
4644
* @var string[]
4745
*/
48-
public static $columns = ['id', 'user_id', 'file_id', 'x', 'y', 'height', 'width', 'vector', 'cluster_id', 'threshold'];
46+
public static $columns = ['id', 'user_id', 'file_id', 'x', 'y', 'height', 'width', 'face_vector', 'cluster_id', 'threshold'];
4947
/**
5048
* @var string[]
5149
*/
52-
public static $fields = ['id', 'userId', 'fileId', 'x', 'y', 'height', 'width', 'vector', 'clusterId', 'threshold'];
50+
public static $fields = ['id', 'userId', 'fileId', 'x', 'y', 'height', 'width', 'faceVector', 'clusterId', 'threshold'];
5351

5452
public function __construct() {
5553
// add types in constructor
@@ -60,19 +58,26 @@ public function __construct() {
6058
$this->addType('y', 'float');
6159
$this->addType('height', 'float');
6260
$this->addType('width', 'float');
63-
$this->addType('vector', 'json');
61+
$this->addType('faceVector', 'json');
6462
$this->addType('clusterId', 'integer');
6563
$this->addType('threshold', 'float');
6664
}
6765

6866
public function toArray(): array {
6967
$array = [];
7068
foreach (static::$fields as $field) {
71-
if ($field === 'vector') {
69+
if ($field === 'faceVector') {
7270
continue;
7371
}
7472
$array[$field] = $this->{$field};
7573
}
7674
return $array;
7775
}
76+
77+
public function getVector(): array {
78+
return $this->getter('faceVector');
79+
}
80+
public function setVector(array $vector): void {
81+
$this->setter('faceVector', [$vector]);
82+
}
7883
}

lib/Migration/Version002002000Date20220614094721.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
6565
$table->addColumn('width', Types::FLOAT, [
6666
'notnull' => false,
6767
]);
68-
$table->addColumn('vector', Types::TEXT, [
68+
$table->addColumn('face_vector', Types::TEXT, [
6969
'notnull' => true,
7070
]);
7171
$table->addColumn('cluster_id', 'bigint', [
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) 2020-2025 The Recognize contributors.
5+
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
6+
*/
7+
declare(strict_types=1);
8+
namespace OCA\Recognize\Migration;
9+
10+
use Closure;
11+
use Doctrine\DBAL\Schema\SchemaException;
12+
use OCP\DB\ISchemaWrapper;
13+
use OCP\DB\Types;
14+
use OCP\IDBConnection;
15+
use OCP\Migration\IOutput;
16+
use OCP\Migration\SimpleMigrationStep;
17+
18+
final class Version010000001Date20250727094721 extends SimpleMigrationStep {
19+
20+
public function __construct(
21+
private IDBConnection $db,
22+
) {
23+
}
24+
25+
/**
26+
* @param IOutput $output
27+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
28+
* @param array $options
29+
*
30+
* @return ?ISchemaWrapper
31+
* @throws SchemaException
32+
*/
33+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
34+
/** @var ISchemaWrapper $schema */
35+
$schema = $schemaClosure();
36+
37+
if ($schema->hasTable('recognize_face_detections')) {
38+
$table = $schema->getTable('recognize_face_detections');
39+
if (!$table->hasColumn('face_vector')) {
40+
$table->addColumn('face_vector', Types::TEXT, [
41+
'notnull' => true,
42+
]);
43+
return $schema;
44+
}
45+
}
46+
return null;
47+
}
48+
49+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
50+
/** @var ISchemaWrapper $schema */
51+
$schema = $schemaClosure();
52+
53+
if (!$schema->hasTable('recognize_face_detections')) {
54+
return;
55+
}
56+
57+
$table = $schema->getTable('recognize_face_detections');
58+
$copyData = $table->hasColumn('face_vector') && $table->hasColumn('vector');
59+
if (!$copyData) {
60+
return;
61+
}
62+
63+
$selectQuery = $this->db->getQueryBuilder();
64+
$selectQuery->select('id', 'vector')
65+
->from('recognize_face_detections');
66+
$updateQuery = $this->db->getQueryBuilder();
67+
$updateQuery->update('recognize_face_detections')
68+
->set('face_vector', $updateQuery->createParameter('face_vector'))
69+
->where($updateQuery->expr()->eq('id', $updateQuery->createParameter('id')));
70+
$result = $selectQuery->executeQuery();
71+
while ($row = $result->fetch()) {
72+
$updateQuery->setParameter('id', $row['id']);
73+
$updateQuery->setParameter('face_vector', $row['vector']);
74+
$updateQuery->executeStatement();
75+
}
76+
$result->closeCursor();
77+
}
78+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) 2020-2025 The Recognize contributors.
5+
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
6+
*/
7+
declare(strict_types=1);
8+
namespace OCA\Recognize\Migration;
9+
10+
use Closure;
11+
use Doctrine\DBAL\Schema\SchemaException;
12+
use OCP\DB\ISchemaWrapper;
13+
use OCP\Migration\IOutput;
14+
use OCP\Migration\SimpleMigrationStep;
15+
16+
final class Version010000001Date20250727094821 extends SimpleMigrationStep {
17+
18+
/**
19+
* @param IOutput $output
20+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
21+
* @param array $options
22+
*
23+
* @return ?ISchemaWrapper
24+
* @throws SchemaException
25+
*/
26+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
27+
/** @var ISchemaWrapper $schema */
28+
$schema = $schemaClosure();
29+
30+
if ($schema->hasTable('recognize_face_detections')) {
31+
$table = $schema->getTable('recognize_face_detections');
32+
if ($table->hasColumn('vector')) {
33+
$table->dropColumn('vector');
34+
return $schema;
35+
}
36+
}
37+
return null;
38+
}
39+
}

0 commit comments

Comments
 (0)