From e8a2ed354997d13c9f2f412ab5388a7bae0de0c0 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Sun, 27 Jul 2025 11:09:06 +0200 Subject: [PATCH 1/2] fix(mariadb): Rename vector col to face_vector 'vector' is a reserved keyword now in mariadb see #1295 Signed-off-by: Marcel Klehr --- .github/workflows/phpunit-mariadb.yml | 6 +- lib/Db/FaceDetection.php | 21 +++-- .../Version002002000Date20220614094721.php | 2 +- .../Version010000001Date20250727094721.php | 78 +++++++++++++++++++ .../Version010000001Date20250727094821.php | 39 ++++++++++ 5 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 lib/Migration/Version010000001Date20250727094721.php create mode 100644 lib/Migration/Version010000001Date20250727094821.php diff --git a/.github/workflows/phpunit-mariadb.yml b/.github/workflows/phpunit-mariadb.yml index 02082a5a..0b9dead1 100644 --- a/.github/workflows/phpunit-mariadb.yml +++ b/.github/workflows/phpunit-mariadb.yml @@ -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 }} @@ -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 diff --git a/lib/Db/FaceDetection.php b/lib/Db/FaceDetection.php index abbceda5..fcd5e833 100644 --- a/lib/Db/FaceDetection.php +++ b/lib/Db/FaceDetection.php @@ -21,8 +21,6 @@ * @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) @@ -30,7 +28,7 @@ * @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; @@ -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 @@ -60,7 +58,7 @@ 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'); } @@ -68,11 +66,18 @@ public function __construct() { 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]); + } } diff --git a/lib/Migration/Version002002000Date20220614094721.php b/lib/Migration/Version002002000Date20220614094721.php index 17879ff4..0a902f81 100644 --- a/lib/Migration/Version002002000Date20220614094721.php +++ b/lib/Migration/Version002002000Date20220614094721.php @@ -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', [ diff --git a/lib/Migration/Version010000001Date20250727094721.php b/lib/Migration/Version010000001Date20250727094721.php new file mode 100644 index 00000000..93129501 --- /dev/null +++ b/lib/Migration/Version010000001Date20250727094721.php @@ -0,0 +1,78 @@ +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(); + } +} diff --git a/lib/Migration/Version010000001Date20250727094821.php b/lib/Migration/Version010000001Date20250727094821.php new file mode 100644 index 00000000..591dfdd9 --- /dev/null +++ b/lib/Migration/Version010000001Date20250727094821.php @@ -0,0 +1,39 @@ +hasTable('recognize_face_detections')) { + $table = $schema->getTable('recognize_face_detections'); + if ($table->hasColumn('vector')) { + $table->dropColumn('vector'); + return $schema; + } + } + return null; + } +} From 2d3109e0cb212eabeeadfd9d8a95a82a96a0f6ca Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Sun, 27 Jul 2025 16:01:16 +0200 Subject: [PATCH 2/2] Update lib/Migration/Version010000001Date20250727094721.php Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Marcel Klehr --- .../Version010000001Date20250727094721.php | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/Migration/Version010000001Date20250727094721.php b/lib/Migration/Version010000001Date20250727094721.php index 93129501..5a264eca 100644 --- a/lib/Migration/Version010000001Date20250727094721.php +++ b/lib/Migration/Version010000001Date20250727094721.php @@ -60,19 +60,9 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array 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(); + $query = $this->db->getQueryBuilder(); + $query->update('recognize_face_detections') + ->set('face_vector', 'vector'); + $query->executeStatement(); } }