Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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]>
  • Loading branch information
marcelklehr authored and backportbot[bot] committed Jul 28, 2025
commit ebff1c7d8d5e9b2fb113d72f7db2d16627579182
6 changes: 3 additions & 3 deletions .github/workflows/phpunit-mariadb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
matrix:
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
mariadb-versions: ['10.6', '10.11']
mariadb-versions: ['10.6', '10.11', '11.8']

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

Expand All @@ -84,8 +84,8 @@ jobs:
ports:
- 4444:3306/tcp
env:
MYSQL_ROOT_PASSWORD: rootpassword
options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 5
MARIADB_ROOT_PASSWORD: rootpassword
options: --health-cmd="mariadb-admin ping" --health-interval 5s --health-timeout 2s --health-retries 5

steps:
- name: Set app env
Expand Down
21 changes: 13 additions & 8 deletions lib/Db/FaceDetection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@
* @method float getY()
* @method float getHeight()
* @method float getWidth()
* @method float[] getVector()
* @method setVector(array $vector)
* @method setX(float $x)
* @method setY(float $y)
* @method setHeight(float $height)
* @method setWidth(float $width)
* @method setClusterId(int|null $clusterId)
* @method int|null getClusterId()
* @method float getThreshold()
* @method setThreshold(float $threshold)
* @method setThreshold(float $threshold)
*/
class FaceDetection extends Entity {
protected $fileId;
Expand All @@ -39,17 +37,17 @@ class FaceDetection extends Entity {
protected $y;
protected $height;
protected $width;
protected $vector;
protected $faceVector;
protected $clusterId;
protected $threshold;
/**
* @var string[]
*/
public static $columns = ['id', 'user_id', 'file_id', 'x', 'y', 'height', 'width', 'vector', 'cluster_id', 'threshold'];
public static $columns = ['id', 'user_id', 'file_id', 'x', 'y', 'height', 'width', 'face_vector', 'cluster_id', 'threshold'];
/**
* @var string[]
*/
public static $fields = ['id', 'userId', 'fileId', 'x', 'y', 'height', 'width', 'vector', 'clusterId', 'threshold'];
public static $fields = ['id', 'userId', 'fileId', 'x', 'y', 'height', 'width', 'faceVector', 'clusterId', 'threshold'];

public function __construct() {
// add types in constructor
Expand All @@ -60,19 +58,26 @@ public function __construct() {
$this->addType('y', 'float');
$this->addType('height', 'float');
$this->addType('width', 'float');
$this->addType('vector', 'json');
$this->addType('faceVector', 'json');
$this->addType('clusterId', 'integer');
$this->addType('threshold', 'float');
}

public function toArray(): array {
$array = [];
foreach (static::$fields as $field) {
if ($field === 'vector') {
if ($field === 'faceVector') {
continue;
}
$array[$field] = $this->{$field};
}
return $array;
}

public function getVector(): array {
return $this->getter('faceVector');
}
public function setVector(array $vector): void {
$this->setter('faceVector', [$vector]);
}
}
2 changes: 1 addition & 1 deletion lib/Migration/Version002002000Date20220614094721.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$table->addColumn('width', Types::FLOAT, [
'notnull' => false,
]);
$table->addColumn('vector', Types::TEXT, [
$table->addColumn('face_vector', Types::TEXT, [
'notnull' => true,
]);
$table->addColumn('cluster_id', 'bigint', [
Expand Down
78 changes: 78 additions & 0 deletions lib/Migration/Version010000001Date20250727094721.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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' => true,
]);
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;
}

$selectQuery = $this->db->getQueryBuilder();
$selectQuery->select('id', 'vector')
->from('recognize_face_detections');
$updateQuery = $this->db->getQueryBuilder();
$updateQuery->update('recognize_face_detections')
->set('face_vector', $updateQuery->createParameter('face_vector'))
->where($updateQuery->expr()->eq('id', $updateQuery->createParameter('id')));
$result = $selectQuery->executeQuery();
while ($row = $result->fetch()) {
$updateQuery->setParameter('id', $row['id']);
$updateQuery->setParameter('face_vector', $row['vector']);
$updateQuery->executeStatement();
}
$result->closeCursor();
}
}
39 changes: 39 additions & 0 deletions lib/Migration/Version010000001Date20250727094821.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

final class Version010000001Date20250727094821 extends SimpleMigrationStep {

/**
* @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('vector')) {
$table->dropColumn('vector');
return $schema;
}
}
return null;
}
}