diff --git a/composer.json b/composer.json index c4e5e72305..226469e738 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "utopia-php/cache": "0.13.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "1.*", + "utopia-php/database": "dev-spatial-filter as 1.4.9", "utopia-php/detector": "0.1.*", "utopia-php/domains": "0.8.*", "utopia-php/dns": "0.3.*", diff --git a/composer.lock b/composer.lock index 04be898b77..46ac069657 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "afc8b2b314887779f507fd6a101ef6af", + "content-hash": "5c861fd3b9ba28caced612134ab9e51c", "packages": [ { "name": "adhocore/jwt", @@ -3650,16 +3650,16 @@ }, { "name": "utopia-php/database", - "version": "1.4.7", + "version": "dev-spatial-filter", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "45009951765c5c6ec7ee42b740cf8a846ea3ccd2" + "reference": "753800f9eb16bfd62b9647a0c54f39675dde728b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/45009951765c5c6ec7ee42b740cf8a846ea3ccd2", - "reference": "45009951765c5c6ec7ee42b740cf8a846ea3ccd2", + "url": "https://api.github.com/repos/utopia-php/database/zipball/753800f9eb16bfd62b9647a0c54f39675dde728b", + "reference": "753800f9eb16bfd62b9647a0c54f39675dde728b", "shasum": "" }, "require": { @@ -3700,9 +3700,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/1.4.7" + "source": "https://github.com/utopia-php/database/tree/spatial-filter" }, - "time": "2025-09-11T12:40:31+00:00" + "time": "2025-09-11T15:21:57+00:00" }, { "name": "utopia-php/detector", @@ -8522,9 +8522,18 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-spatial-filter", + "alias": "1.4.9", + "alias_normalized": "1.4.9.0" + } + ], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php index 80a05c4864..a75d52fc4f 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -5981,12 +5981,12 @@ trait DatabasesBase 'documentId' => ID::unique(), 'data' => [ 'name' => 'Upserted Location', - 'location' => [34.0522, -118.2437] // Los Angeles coordinates + 'location' => [34.0522, -80] // Los Angeles coordinates ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([34.0522, -118.2437], $response['body']['location']); + $this->assertEquals([34.0522, -80], $response['body']['location']); // Test 5: Create document without permissions (should fail) $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', [ @@ -6116,12 +6116,12 @@ trait DatabasesBase 'documentId' => ID::unique(), 'data' => [ 'distance' => 200, - 'route' => [[34.0522, -118.2437], [34.0736, -118.2400]] // LA route + 'route' => [[34.0522, -80], [34.0736, -90]] // LA route ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([[34.0522, -118.2437], [34.0736, -118.2400]], $response['body']['route']); + $this->assertEquals([[34.0522, -80], [34.0736, -90]], $response['body']['route']); // Test 5: Delete document $response = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ @@ -6253,12 +6253,12 @@ trait DatabasesBase 'documentId' => ID::unique(), 'data' => [ 'active' => false, - 'area' => [[[34.0522, -118.2437], [34.0736, -118.2437], [34.0736, -118.2400], [34.0522, -118.2400], [34.0522, -118.2437]]] // LA area + 'area' => [[[34.0522, -80], [34.0736, -80], [34.0736, -90], [34.0522, -90], [34.0522, -80]]] // LA area ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([[[34.0522, -118.2437], [34.0736, -118.2437], [34.0736, -118.2400], [34.0522, -118.2400], [34.0522, -118.2437]]], $response['body']['area']); + $this->assertEquals([[[34.0522, -80], [34.0736, -80], [34.0736, -90], [34.0522, -90], [34.0522, -80]]], $response['body']['area']); // Test 5: Create document without required polygon attribute (should fail) $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ @@ -6764,16 +6764,6 @@ trait DatabasesBase $this->assertEquals(200, $response['headers']['status-code']); $this->assertCount(2, $response['body']['documents']); - // Test 4.1: contains on line (point on line) - $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'queries' => [Query::contains('lineAttr', [[1.0, 1.0]])->toString()] - ]); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(1, $response['body']['documents']); - $this->assertEquals('doc1', $response['body']['documents'][0]['$id']); // Test 4.2: notContains on polygon (point outside all polygons) $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ @@ -7635,19 +7625,6 @@ trait DatabasesBase ]); $this->assertEquals(202, $retriedIndex['headers']['status-code']); - // Passing orders to spatial index should not throw error(in case of mariadb) - $ordersIndex = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/indexes', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'idx_required_point_with_orders', - 'type' => Database::INDEX_SPATIAL, - 'attributes' => ['pRequired'], - 'orders' => ['ASC'] - ]); - $this->assertEquals(202, $ordersIndex['headers']['status-code']); - // Cleanup $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ 'content-type' => 'application/json', diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php index 2c603233a3..c1ce75c38d 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php @@ -6682,7 +6682,7 @@ class DatabasesCustomServerTest extends Scope 'path' => [ [0, 0], [50, 50], - [100, 100] + [80, 80] ] // New LINE STRING ], ]); @@ -6696,7 +6696,7 @@ class DatabasesCustomServerTest extends Scope $this->assertEquals([ [0, 0], [50, 50], - [100, 100] + [80, 80] ], $document['path']); } diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index fa71a2c698..3681a535ae 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -7615,12 +7615,12 @@ trait DatabasesBase 'rowId' => ID::unique(), 'data' => [ 'name' => 'Upserted Location', - 'location' => [34.0522, -118.2437] + 'location' => [34.0522, -80] ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([34.0522, -118.2437], $response['body']['location']); + $this->assertEquals([34.0522, -80], $response['body']['location']); // Create row without permissions (should fail) $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', [ @@ -7749,12 +7749,12 @@ trait DatabasesBase 'rowId' => ID::unique(), 'data' => [ 'distance' => 200, - 'route' => [[34.0522, -118.2437], [34.0736, -118.2400]] + 'route' => [[34.0522, -80], [34.0736, -80]] ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([[34.0522, -118.2437], [34.0736, -118.2400]], $response['body']['route']); + $this->assertEquals([[34.0522, -80], [34.0736, -80]], $response['body']['route']); // Delete row $response = $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, array_merge([ @@ -7883,12 +7883,12 @@ trait DatabasesBase 'rowId' => ID::unique(), 'data' => [ 'active' => false, - 'area' => [[[34.0522, -118.2437], [34.0736, -118.2437], [34.0736, -118.2400], [34.0522, -118.2400], [34.0522, -118.2437]]] + 'area' => [[[34.0522, -80], [34.0736, -80], [34.0736, -80], [34.0522, -80], [34.0522, -80]]] ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([[[34.0522, -118.2437], [34.0736, -118.2437], [34.0736, -118.2400], [34.0522, -118.2400], [34.0522, -118.2437]]], $response['body']['area']); + $this->assertEquals([[[34.0522, -80], [34.0736, -80], [34.0736, -80], [34.0522, -80], [34.0522, -80]]], $response['body']['area']); // Create row missing required polygon (should fail) $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ @@ -8225,17 +8225,6 @@ trait DatabasesBase $this->assertEquals(200, $response['headers']['status-code']); $this->assertCount(2, $response['body']['rows']); - // contains on line (point on line) - $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'queries' => [Query::contains('lineAttr', [[1.0, 1.0]])->toString()] - ]); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(1, $response['body']['rows']); - $this->assertEquals('row1', $response['body']['rows'][0]['$id']); - // notContains on polygon (point outside all polygons) $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ 'content-type' => 'application/json', @@ -8562,19 +8551,6 @@ trait DatabasesBase ]); $this->assertEquals(202, $retriedIndex['headers']['status-code']); - // Passing orders to spatial index should not throw error (in case of mariadb) - $ordersIndex = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/indexes', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'idx_required_point_with_orders', - 'type' => Database::INDEX_SPATIAL, - 'columns' => ['pRequired'], - 'orders' => ['ASC'] - ]); - $this->assertEquals(202, $ordersIndex['headers']['status-code']); - // Cleanup $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId, array_merge([ 'content-type' => 'application/json', diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php index 0f68d9ea7b..5e35fa065d 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php @@ -6379,7 +6379,7 @@ class DatabasesCustomServerTest extends Scope ]); // Coordinates are not validated strictly; creation should succeed - $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals(400, $response['headers']['status-code']); // Test 4b: Invalid polygon (insufficient points - should fail) $response = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", array_merge([ @@ -6650,7 +6650,7 @@ class DatabasesCustomServerTest extends Scope 'path' => [ [0, 0], [50, 50], - [100, 100] + [80, 80] ] // New LINE STRING ], ]); @@ -6664,7 +6664,7 @@ class DatabasesCustomServerTest extends Scope $this->assertEquals([ [0, 0], [50, 50], - [100, 100] + [80, 80] ], $row['path']); }