From 95f67b274d5323ffedfd4c4f31a7a6110dd2fe9a Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 22 Aug 2025 12:46:48 +0530 Subject: [PATCH 01/50] added docs for the attributes --- docs/references/databases/create-line-attribute.md | 1 + docs/references/databases/create-point-attribute.md | 1 + docs/references/databases/create-polygon-attribute.md | 1 + 3 files changed, 3 insertions(+) create mode 100644 docs/references/databases/create-line-attribute.md create mode 100644 docs/references/databases/create-point-attribute.md create mode 100644 docs/references/databases/create-polygon-attribute.md diff --git a/docs/references/databases/create-line-attribute.md b/docs/references/databases/create-line-attribute.md new file mode 100644 index 0000000000..96f1509936 --- /dev/null +++ b/docs/references/databases/create-line-attribute.md @@ -0,0 +1 @@ +Create a geometric line attribute. \ No newline at end of file diff --git a/docs/references/databases/create-point-attribute.md b/docs/references/databases/create-point-attribute.md new file mode 100644 index 0000000000..fb9b6be24b --- /dev/null +++ b/docs/references/databases/create-point-attribute.md @@ -0,0 +1 @@ +Create a geometric 2d point attribute. \ No newline at end of file diff --git a/docs/references/databases/create-polygon-attribute.md b/docs/references/databases/create-polygon-attribute.md new file mode 100644 index 0000000000..7cb3985ff7 --- /dev/null +++ b/docs/references/databases/create-polygon-attribute.md @@ -0,0 +1 @@ +Create a geometric polygon attribute. \ No newline at end of file From 9fa42e80840c8da6d283ef8dd6593fe8745f61ee Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 22 Aug 2025 12:47:00 +0530 Subject: [PATCH 02/50] added filters --- app/init/constants.php | 3 +++ app/init/database/filters.php | 5 +++++ app/init/database/formats.php | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/app/init/constants.php b/app/init/constants.php index c2d529191b..3b6b553feb 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -46,6 +46,9 @@ const APP_DATABASE_ATTRIBUTE_DATETIME = 'datetime'; const APP_DATABASE_ATTRIBUTE_URL = 'url'; const APP_DATABASE_ATTRIBUTE_INT_RANGE = 'intRange'; const APP_DATABASE_ATTRIBUTE_FLOAT_RANGE = 'floatRange'; +const APP_DATABASE_ATTRIBUTE_POINT = 'point'; +const APP_DATABASE_ATTRIBUTE_LINE = 'line'; +const APP_DATABASE_ATTRIBUTE_POLYGON = 'polygon'; const APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH = 1_073_741_824; // 2^32 bits / 4 bits per char const APP_DATABASE_TIMEOUT_MILLISECONDS_API = 15 * 1000; // 15 seconds const APP_DATABASE_TIMEOUT_MILLISECONDS_WORKER = 300 * 1000; // 5 minutes diff --git a/app/init/database/filters.php b/app/init/database/filters.php index 33f5d8077a..346387125c 100644 --- a/app/init/database/filters.php +++ b/app/init/database/filters.php @@ -92,6 +92,11 @@ Database::addFilter( $filters = $attribute->getAttribute('filters', []); $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); break; + + case Database::VAR_POINT: + case Database::VAR_LINESTRING: + case Database::VAR_POLYGON: + break; } } diff --git a/app/init/database/formats.php b/app/init/database/formats.php index 6c73877576..f8545e3b54 100644 --- a/app/init/database/formats.php +++ b/app/init/database/formats.php @@ -41,3 +41,15 @@ Structure::addFormat(APP_DATABASE_ATTRIBUTE_FLOAT_RANGE, function ($attribute) { $max = $attribute['formatOptions']['max'] ?? INF; return new Range($min, $max, Range::TYPE_FLOAT); }, Database::VAR_FLOAT); + +Structure::addFormat(APP_DATABASE_ATTRIBUTE_POINT, function () { + return new \Utopia\Validator\Text(0, 0); +}, Database::VAR_POINT); + +Structure::addFormat(APP_DATABASE_ATTRIBUTE_LINE, function () { + return new \Utopia\Validator\Text(0, 0); +}, Database::VAR_LINESTRING); + +Structure::addFormat(APP_DATABASE_ATTRIBUTE_POLYGON, function () { + return new \Utopia\Validator\Text(0, 0); +}, Database::VAR_POLYGON); From 110d3d83cd8e9418a2b8bce8795cdbcd554be376 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 22 Aug 2025 12:47:15 +0530 Subject: [PATCH 03/50] added attribute endpoints --- src/Appwrite/GraphQL/Types/Mapper.php | 3 + .../Collections/Attributes/Action.php | 12 +++ .../Collections/Attributes/Line/Create.php | 89 ++++++++++++++++++ .../Collections/Attributes/Line/Update.php | 92 +++++++++++++++++++ .../Collections/Attributes/Point/Create.php | 89 ++++++++++++++++++ .../Collections/Attributes/Point/Update.php | 91 ++++++++++++++++++ .../Collections/Attributes/Polygon/Create.php | 89 ++++++++++++++++++ .../Collections/Attributes/Polygon/Update.php | 92 +++++++++++++++++++ .../TablesDB/Tables/Columns/Line/Create.php | 64 +++++++++++++ .../TablesDB/Tables/Columns/Point/Create.php | 64 +++++++++++++ .../Tables/Columns/Polygon/Create.php | 64 +++++++++++++ .../Services/Registry/Collections.php | 18 ++++ .../Databases/Services/Registry/Tables.php | 12 +++ src/Appwrite/Utopia/Response.php | 18 ++++ .../Utopia/Response/Model/AttributeLine.php | 59 ++++++++++++ .../Utopia/Response/Model/AttributeList.php | 3 + .../Utopia/Response/Model/AttributePoint.php | 59 ++++++++++++ .../Response/Model/AttributePolygon.php | 59 ++++++++++++ .../Utopia/Response/Model/Collection.php | 3 + .../Utopia/Response/Model/ColumnLine.php | 59 ++++++++++++ .../Utopia/Response/Model/ColumnList.php | 3 + .../Utopia/Response/Model/ColumnPoint.php | 59 ++++++++++++ .../Utopia/Response/Model/ColumnPolygon.php | 59 ++++++++++++ src/Appwrite/Utopia/Response/Model/Table.php | 3 + 24 files changed, 1163 insertions(+) create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php create mode 100644 src/Appwrite/Utopia/Response/Model/AttributeLine.php create mode 100644 src/Appwrite/Utopia/Response/Model/AttributePoint.php create mode 100644 src/Appwrite/Utopia/Response/Model/AttributePolygon.php create mode 100644 src/Appwrite/Utopia/Response/Model/ColumnLine.php create mode 100644 src/Appwrite/Utopia/Response/Model/ColumnPoint.php create mode 100644 src/Appwrite/Utopia/Response/Model/ColumnPolygon.php diff --git a/src/Appwrite/GraphQL/Types/Mapper.php b/src/Appwrite/GraphQL/Types/Mapper.php index 1bfb2231c7..e0916da558 100644 --- a/src/Appwrite/GraphQL/Types/Mapper.php +++ b/src/Appwrite/GraphQL/Types/Mapper.php @@ -456,6 +456,9 @@ class Mapper 'boolean' => static::model("{$prefix}Boolean"), 'datetime' => static::model("{$prefix}Datetime"), 'relationship' => static::model("{$prefix}Relationship"), + 'point' => static::model("{$prefix}Point"), + 'linestring' => static::model("{$prefix}Line"), + 'polygon' => static::model("{$prefix}Polygon"), default => throw new Exception('Unknown ' . strtolower($prefix) . ' implementation'), }; } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index bb536bc498..948a993424 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -245,6 +245,18 @@ abstract class Action extends UtopiaAction ? UtopiaResponse::MODEL_ATTRIBUTE_RELATIONSHIP : UtopiaResponse::MODEL_COLUMN_RELATIONSHIP, + Database::VAR_POINT => $isCollections + ? UtopiaResponse::MODEL_ATTRIBUTE_POINT + : UtopiaResponse::MODEL_COLUMN_POINT, + + Database::VAR_LINESTRING => $isCollections + ? UtopiaResponse::MODEL_ATTRIBUTE_LINE + : UtopiaResponse::MODEL_COLUMN_LINE, + + Database::VAR_POLYGON => $isCollections + ? UtopiaResponse::MODEL_ATTRIBUTE_POLYGON + : UtopiaResponse::MODEL_COLUMN_POLYGON, + Database::VAR_STRING => match ($format) { APP_DATABASE_ATTRIBUTE_EMAIL => $isCollections ? UtopiaResponse::MODEL_ATTRIBUTE_EMAIL diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php new file mode 100644 index 0000000000..56bb0e40cb --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php @@ -0,0 +1,89 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_POST) + ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/line') + ->desc('Create line attribute') + ->groups(['api', 'database', 'schema']) + ->label('event', 'databases.[databaseId].collections.[collectionId].attributes.[attributeId].create') + ->label('scope', 'collections.write') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('audits.event', 'attribute.create') + ->label('audits.resource', 'database/{request.databaseId}/collection/{request.collectionId}') + ->label('sdk', new Method( + namespace: $this->getSdkNamespace(), + group: $this->getSdkGroup(), + name: self::getName(), + description: '/docs/references/databases/create-line-attribute.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_ACCEPTED, + model: $this->getResponseModel(), + ) + ], + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createLineColumn', + ), + )) + ->param('databaseId', '', new UID(), 'Database ID.') + ->param('collectionId', '', new UID(), 'Collection ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') + ->param('key', '', new Key(), 'Attribute Key.') + ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') + ->param('default', null, new Text(0, 0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true) + ->param('array', false, new \Utopia\Validator\Boolean(), 'Is attribute an array?', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForDatabase') + ->inject('queueForEvents') + ->callback($this->action(...)); + } + + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + { + $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ + 'key' => $key, + 'type' => Database::VAR_LINESTRING, + 'size' => 0, + 'required' => $required, + 'default' => $default, + 'array' => $array, + ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); + + $response + ->setStatusCode(SwooleResponse::STATUS_CODE_ACCEPTED) + ->dynamic($attribute, $this->getResponseModel()); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php new file mode 100644 index 0000000000..90609977c0 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php @@ -0,0 +1,92 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/line/:key') + ->desc('Update line attribute') + ->groups(['api', 'database', 'schema']) + ->label('scope', 'collections.write') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('event', 'databases.[databaseId].collections.[collectionId].attributes.[attributeId].update') + ->label('audits.event', 'attribute.update') + ->label('audits.resource', 'database/{request.databaseId}/collection/{request.collectionId}') + ->label('sdk', new Method( + namespace: $this->getSdkNamespace(), + group: $this->getSdkGroup(), + name: self::getName(), + description: '/docs/references/databases/update-line-attribute.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: $this->getResponseModel(), + ) + ], + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.updateLineColumn', + ), + )) + ->param('databaseId', '', new UID(), 'Database ID.') + ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).') + ->param('key', '', new Key(), 'Attribute Key.') + ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') + ->param('default', null, new Nullable(new Text(0, 0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.') + ->param('newKey', null, new Key(), 'New attribute key.', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForEvents') + ->callback($this->action(...)); + } + + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void + { + $attribute = $this->updateAttribute( + databaseId: $databaseId, + collectionId: $collectionId, + key: $key, + dbForProject: $dbForProject, + queueForEvents: $queueForEvents, + type: Database::VAR_LINESTRING, + default: $default, + required: $required, + newKey: $newKey + ); + + $response + ->setStatusCode(SwooleResponse::STATUS_CODE_OK) + ->dynamic($attribute, $this->getResponseModel()); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php new file mode 100644 index 0000000000..3807bdc174 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php @@ -0,0 +1,89 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_POST) + ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/point') + ->desc('Create point attribute') + ->groups(['api', 'database', 'schema']) + ->label('event', 'databases.[databaseId].collections.[collectionId].attributes.[attributeId].create') + ->label('scope', 'collections.write') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('audits.event', 'attribute.create') + ->label('audits.resource', 'database/{request.databaseId}/collection/{request.collectionId}') + ->label('sdk', new Method( + namespace: $this->getSdkNamespace(), + group: $this->getSdkGroup(), + name: self::getName(), + description: '/docs/references/databases/create-point-attribute.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_ACCEPTED, + model: $this->getResponseModel(), + ) + ], + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createPointColumn', + ), + )) + ->param('databaseId', '', new UID(), 'Database ID.') + ->param('collectionId', '', new UID(), 'Collection ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') + ->param('key', '', new Key(), 'Attribute Key.') + ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') + ->param('default', null, new Text(0, 0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true) + ->param('array', false, new \Utopia\Validator\Boolean(), 'Is attribute an array?', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForDatabase') + ->inject('queueForEvents') + ->callback($this->action(...)); + } + + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + { + $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ + 'key' => $key, + 'type' => Database::VAR_POINT, + 'size' => 0, + 'required' => $required, + 'default' => $default, + 'array' => $array, + ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); + + $response + ->setStatusCode(SwooleResponse::STATUS_CODE_ACCEPTED) + ->dynamic($attribute, $this->getResponseModel()); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php new file mode 100644 index 0000000000..f276256cf4 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php @@ -0,0 +1,91 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/point/:key') + ->desc('Update point attribute') + ->groups(['api', 'database', 'schema']) + ->label('scope', 'collections.write') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('event', 'databases.[databaseId].collections.[collectionId].attributes.[attributeId].update') + ->label('audits.event', 'attribute.update') + ->label('audits.resource', 'database/{request.databaseId}/collection/{request.collectionId}') + ->label('sdk', new Method( + namespace: $this->getSdkNamespace(), + group: $this->getSdkGroup(), + name: self::getName(), + description: '/docs/references/databases/update-point-attribute.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: $this->getResponseModel(), + ) + ], + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.updatePointColumn', + ), + )) + ->param('databaseId', '', new UID(), 'Database ID.') + ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).') + ->param('key', '', new Key(), 'Attribute Key.') + ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') + ->param('default', null, new Nullable(new \Utopia\Validator\Text(0, 0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.') + ->param('newKey', null, new Key(), 'New attribute key.', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForEvents') + ->callback($this->action(...)); + } + + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void + { + $attribute = $this->updateAttribute( + databaseId: $databaseId, + collectionId: $collectionId, + key: $key, + dbForProject: $dbForProject, + queueForEvents: $queueForEvents, + type: Database::VAR_POINT, + default: $default, + required: $required, + newKey: $newKey + ); + + $response + ->setStatusCode(SwooleResponse::STATUS_CODE_OK) + ->dynamic($attribute, $this->getResponseModel()); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php new file mode 100644 index 0000000000..56c4b4af2e --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php @@ -0,0 +1,89 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_POST) + ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/polygon') + ->desc('Create polygon attribute') + ->groups(['api', 'database', 'schema']) + ->label('event', 'databases.[databaseId].collections.[collectionId].attributes.[attributeId].create') + ->label('scope', 'collections.write') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('audits.event', 'attribute.create') + ->label('audits.resource', 'database/{request.databaseId}/collection/{request.collectionId}') + ->label('sdk', new Method( + namespace: $this->getSdkNamespace(), + group: $this->getSdkGroup(), + name: self::getName(), + description: '/docs/references/databases/create-polygon-attribute.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_ACCEPTED, + model: $this->getResponseModel(), + ) + ], + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createPolygonColumn', + ), + )) + ->param('databaseId', '', new UID(), 'Database ID.') + ->param('collectionId', '', new UID(), 'Collection ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') + ->param('key', '', new Key(), 'Attribute Key.') + ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') + ->param('default', null, new Text(0, 0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true) + ->param('array', false, new \Utopia\Validator\Boolean(), 'Is attribute an array?', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForDatabase') + ->inject('queueForEvents') + ->callback($this->action(...)); + } + + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + { + $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ + 'key' => $key, + 'type' => Database::VAR_POLYGON, + 'size' => 0, + 'required' => $required, + 'default' => $default, + 'array' => $array, + ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); + + $response + ->setStatusCode(SwooleResponse::STATUS_CODE_ACCEPTED) + ->dynamic($attribute, $this->getResponseModel()); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php new file mode 100644 index 0000000000..90d0960f41 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php @@ -0,0 +1,92 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/polygon/:key') + ->desc('Update polygon attribute') + ->groups(['api', 'database', 'schema']) + ->label('scope', 'collections.write') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('event', 'databases.[databaseId].collections.[collectionId].attributes.[attributeId].update') + ->label('audits.event', 'attribute.update') + ->label('audits.resource', 'database/{request.databaseId}/collection/{request.collectionId}') + ->label('sdk', new Method( + namespace: $this->getSdkNamespace(), + group: $this->getSdkGroup(), + name: self::getName(), + description: '/docs/references/databases/update-polygon-attribute.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: $this->getResponseModel(), + ) + ], + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.updatePolygonColumn', + ), + )) + ->param('databaseId', '', new UID(), 'Database ID.') + ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).') + ->param('key', '', new Key(), 'Attribute Key.') + ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') + ->param('default', null, new Nullable(new Text(0, 0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.') + ->param('newKey', null, new Key(), 'New attribute key.', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForEvents') + ->callback($this->action(...)); + } + + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void + { + $attribute = $this->updateAttribute( + databaseId: $databaseId, + collectionId: $collectionId, + key: $key, + dbForProject: $dbForProject, + queueForEvents: $queueForEvents, + type: Database::VAR_POLYGON, + default: $default, + required: $required, + newKey: $newKey + ); + + $response + ->setStatusCode(SwooleResponse::STATUS_CODE_OK) + ->dynamic($attribute, $this->getResponseModel()); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php new file mode 100644 index 0000000000..d8d1fefc11 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php @@ -0,0 +1,64 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_POST) + ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/line') + ->desc('Create line column') + ->groups(['api', 'database', 'schema']) + ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') + ->label('scope', 'tables.write') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('audits.event', 'column.create') + ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') + ->label('sdk', new Method( + namespace: $this->getSdkNamespace(), + group: $this->getSdkGroup(), + name: self::getName(), + description: '/docs/references/tablesdb/create-line-column.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_ACCEPTED, + model: $this->getResponseModel(), + ) + ] + )) + ->param('databaseId', '', new UID(), 'Database ID.') + ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') + ->param('key', '', new Key(), 'Column Key.') + ->param('required', null, new \Utopia\Validator\Boolean(), 'Is column required?') + ->param('default', null, new Text(0, 0), 'Default value for column when not provided. Cannot be set when column is required.', true) + ->param('array', false, new \Utopia\Validator\Boolean(), 'Is column an array?', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForDatabase') + ->inject('queueForEvents') + ->callback($this->action(...)); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php new file mode 100644 index 0000000000..c269af6a68 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php @@ -0,0 +1,64 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_POST) + ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/point') + ->desc('Create point column') + ->groups(['api', 'database', 'schema']) + ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') + ->label('scope', 'tables.write') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('audits.event', 'column.create') + ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') + ->label('sdk', new Method( + namespace: $this->getSdkNamespace(), + group: $this->getSdkGroup(), + name: self::getName(), + description: '/docs/references/tablesdb/create-point-column.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_ACCEPTED, + model: $this->getResponseModel(), + ) + ] + )) + ->param('databaseId', '', new UID(), 'Database ID.') + ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') + ->param('key', '', new Key(), 'Column Key.') + ->param('required', null, new \Utopia\Validator\Boolean(), 'Is column required?') + ->param('default', null, new Text(0, 0), 'Default value for column when not provided. Cannot be set when column is required.', true) + ->param('array', false, new \Utopia\Validator\Boolean(), 'Is column an array?', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForDatabase') + ->inject('queueForEvents') + ->callback($this->action(...)); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php new file mode 100644 index 0000000000..302a5b21df --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php @@ -0,0 +1,64 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_POST) + ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/polygon') + ->desc('Create polygon column') + ->groups(['api', 'database', 'schema']) + ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') + ->label('scope', 'tables.write') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('audits.event', 'column.create') + ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') + ->label('sdk', new Method( + namespace: $this->getSdkNamespace(), + group: $this->getSdkGroup(), + name: self::getName(), + description: '/docs/references/tablesdb/create-polygon-column.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_ACCEPTED, + model: $this->getResponseModel(), + ) + ] + )) + ->param('databaseId', '', new UID(), 'Database ID.') + ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') + ->param('key', '', new Key(), 'Column Key.') + ->param('required', null, new \Utopia\Validator\Boolean(), 'Is column required?') + ->param('default', null, new Text(0, 0), 'Default value for column when not provided. Cannot be set when column is required.', true) + ->param('array', false, new \Utopia\Validator\Boolean(), 'Is column an array?', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForDatabase') + ->inject('queueForEvents') + ->callback($this->action(...)); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Collections.php b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Collections.php index bb0002ed47..404f784611 100644 --- a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Collections.php +++ b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Collections.php @@ -18,6 +18,12 @@ use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\In use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Integer\Update as UpdateIntegerAttribute; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\IP\Create as CreateIPAttribute; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\IP\Update as UpdateIPAttribute; +use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Line\Create as CreateLineAttribute; +use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Line\Update as UpdateLineAttribute; +use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Point\Create as CreatePointAttribute; +use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Point\Update as UpdatePointAttribute; +use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Polygon\Create as CreatePolygonAttribute; +use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Polygon\Update as UpdatePolygonAttribute; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Relationship\Create as CreateRelationshipAttribute; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Relationship\Update as UpdateRelationshipAttribute; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\String\Create as CreateStringAttribute; @@ -132,6 +138,18 @@ class Collections extends Base $service->addAction(CreateIPAttribute::getName(), new CreateIPAttribute()); $service->addAction(UpdateIPAttribute::getName(), new UpdateIPAttribute()); + // Attribute: Line + $service->addAction(CreateLineAttribute::getName(), new CreateLineAttribute()); + $service->addAction(UpdateLineAttribute::getName(), new UpdateLineAttribute()); + + // Attribute: Point + $service->addAction(CreatePointAttribute::getName(), new CreatePointAttribute()); + $service->addAction(UpdatePointAttribute::getName(), new UpdatePointAttribute()); + + // Attribute: Polygon + $service->addAction(CreatePolygonAttribute::getName(), new CreatePolygonAttribute()); + $service->addAction(UpdatePolygonAttribute::getName(), new UpdatePolygonAttribute()); + // Attribute: Relationship $service->addAction(CreateRelationshipAttribute::getName(), new CreateRelationshipAttribute()); $service->addAction(UpdateRelationshipAttribute::getName(), new UpdateRelationshipAttribute()); diff --git a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Tables.php b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Tables.php index 7772aff933..0162da1527 100644 --- a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Tables.php +++ b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Tables.php @@ -21,6 +21,9 @@ use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Integer\Cre use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Integer\Update as UpdateInteger; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\IP\Create as CreateIP; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\IP\Update as UpdateIP; +use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Line\Create as CreateLine; +use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Point\Create as CreatePoint; +use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Polygon\Create as CreatePolygon; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Relationship\Create as CreateRelationship; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Relationship\Update as UpdateRelationship; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\String\Create as CreateString; @@ -134,6 +137,15 @@ class Tables extends Base $service->addAction(CreateIP::getName(), new CreateIP()); $service->addAction(UpdateIP::getName(), new UpdateIP()); + // Column: Line + $service->addAction(CreateLine::getName(), new CreateLine()); + + // Column: Point + $service->addAction(CreatePoint::getName(), new CreatePoint()); + + // Column: Polygon + $service->addAction(CreatePolygon::getName(), new CreatePolygon()); + // Column: Relationship $service->addAction(CreateRelationship::getName(), new CreateRelationship()); $service->addAction(UpdateRelationship::getName(), new UpdateRelationship()); diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index cec275869a..be840fcdee 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -23,7 +23,10 @@ use Appwrite\Utopia\Response\Model\AttributeEnum; use Appwrite\Utopia\Response\Model\AttributeFloat; use Appwrite\Utopia\Response\Model\AttributeInteger; use Appwrite\Utopia\Response\Model\AttributeIP; +use Appwrite\Utopia\Response\Model\AttributeLine; use Appwrite\Utopia\Response\Model\AttributeList; +use Appwrite\Utopia\Response\Model\AttributePoint; +use Appwrite\Utopia\Response\Model\AttributePolygon; use Appwrite\Utopia\Response\Model\AttributeRelationship; use Appwrite\Utopia\Response\Model\AttributeString; use Appwrite\Utopia\Response\Model\AttributeURL; @@ -41,7 +44,10 @@ use Appwrite\Utopia\Response\Model\ColumnFloat; use Appwrite\Utopia\Response\Model\ColumnIndex; use Appwrite\Utopia\Response\Model\ColumnInteger; use Appwrite\Utopia\Response\Model\ColumnIP; +use Appwrite\Utopia\Response\Model\ColumnLine; use Appwrite\Utopia\Response\Model\ColumnList; +use Appwrite\Utopia\Response\Model\ColumnPoint; +use Appwrite\Utopia\Response\Model\ColumnPolygon; use Appwrite\Utopia\Response\Model\ColumnRelationship; use Appwrite\Utopia\Response\Model\ColumnString; use Appwrite\Utopia\Response\Model\ColumnURL; @@ -203,6 +209,9 @@ class Response extends SwooleResponse public const MODEL_ATTRIBUTE_URL = 'attributeUrl'; public const MODEL_ATTRIBUTE_DATETIME = 'attributeDatetime'; public const MODEL_ATTRIBUTE_RELATIONSHIP = 'attributeRelationship'; + public const MODEL_ATTRIBUTE_POINT = 'attributePoint'; + public const MODEL_ATTRIBUTE_LINE = 'attributeLine'; + public const MODEL_ATTRIBUTE_POLYGON = 'attributePolygon'; // Database Columns public const MODEL_COLUMN = 'column'; @@ -217,6 +226,9 @@ class Response extends SwooleResponse public const MODEL_COLUMN_URL = 'columnUrl'; public const MODEL_COLUMN_DATETIME = 'columnDatetime'; public const MODEL_COLUMN_RELATIONSHIP = 'columnRelationship'; + public const MODEL_COLUMN_POINT = 'columnPoint'; + public const MODEL_COLUMN_LINE = 'columnLine'; + public const MODEL_COLUMN_POLYGON = 'columnPolygon'; // Users public const MODEL_ACCOUNT = 'account'; @@ -482,6 +494,9 @@ class Response extends SwooleResponse ->setModel(new AttributeURL()) ->setModel(new AttributeDatetime()) ->setModel(new AttributeRelationship()) + ->setModel(new AttributePoint()) + ->setModel(new AttributeLine()) + ->setModel(new AttributePolygon()) // Table API Models ->setModel(new Table()) ->setModel(new Column()) @@ -496,6 +511,9 @@ class Response extends SwooleResponse ->setModel(new ColumnURL()) ->setModel(new ColumnDatetime()) ->setModel(new ColumnRelationship()) + ->setModel(new ColumnPoint()) + ->setModel(new ColumnLine()) + ->setModel(new ColumnPolygon()) ->setModel(new Index()) ->setModel(new ColumnIndex()) ->setModel(new Row()) diff --git a/src/Appwrite/Utopia/Response/Model/AttributeLine.php b/src/Appwrite/Utopia/Response/Model/AttributeLine.php new file mode 100644 index 0000000000..dce5b61978 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/AttributeLine.php @@ -0,0 +1,59 @@ +addRule('key', [ + 'type' => self::TYPE_STRING, + 'description' => 'Attribute Key.', + 'default' => '', + 'example' => 'route', + ]) + ->addRule('type', [ + 'type' => self::TYPE_JSON, + 'description' => 'Attribute type.', + 'default' => '', + 'example' => 'linestring', + ]) + ->addRule('default', [ + 'type' => self::TYPE_JSON, + 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', + 'default' => null, + 'required' => false, + 'example' => '[[0, 0], [1, 1]]' + ]) + ; + } + + public array $conditions = [ + 'type' => 'linestring' + ]; + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'AttributeLine'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_ATTRIBUTE_LINE; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/AttributeList.php b/src/Appwrite/Utopia/Response/Model/AttributeList.php index 8b04475a14..6b9a7365bd 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeList.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeList.php @@ -27,6 +27,9 @@ class AttributeList extends Model Response::MODEL_ATTRIBUTE_IP, Response::MODEL_ATTRIBUTE_DATETIME, Response::MODEL_ATTRIBUTE_RELATIONSHIP, + Response::MODEL_ATTRIBUTE_POINT, + Response::MODEL_ATTRIBUTE_LINE, + Response::MODEL_ATTRIBUTE_POLYGON, Response::MODEL_ATTRIBUTE_STRING // needs to be last, since its condition would dominate any other string attribute ], 'description' => 'List of attributes.', diff --git a/src/Appwrite/Utopia/Response/Model/AttributePoint.php b/src/Appwrite/Utopia/Response/Model/AttributePoint.php new file mode 100644 index 0000000000..a79a1e7006 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/AttributePoint.php @@ -0,0 +1,59 @@ +addRule('key', [ + 'type' => self::TYPE_STRING, + 'description' => 'Attribute Key.', + 'default' => '', + 'example' => 'location', + ]) + ->addRule('type', [ + 'type' => self::TYPE_JSON, + 'description' => 'Attribute type.', + 'default' => '', + 'example' => 'point', + ]) + ->addRule('default', [ + 'type' => self::TYPE_JSON, + 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', + 'default' => null, + 'required' => false, + 'example' => '[0, 0]' + ]) + ; + } + + public array $conditions = [ + 'type' => 'point' + ]; + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'AttributePoint'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_ATTRIBUTE_POINT; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/AttributePolygon.php b/src/Appwrite/Utopia/Response/Model/AttributePolygon.php new file mode 100644 index 0000000000..e4ed3e93f9 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/AttributePolygon.php @@ -0,0 +1,59 @@ +addRule('key', [ + 'type' => self::TYPE_STRING, + 'description' => 'Attribute Key.', + 'default' => '', + 'example' => 'boundary', + ]) + ->addRule('type', [ + 'type' => self::TYPE_JSON, + 'description' => 'Attribute type.', + 'default' => '', + 'example' => 'polygon', + ]) + ->addRule('default', [ + 'type' => self::TYPE_JSON, + 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', + 'default' => null, + 'required' => false, + 'example' => '[[[0, 0], [0, 10], [10, 10], [0, 0]]]' + ]) + ; + } + + public array $conditions = [ + 'type' => 'polygon' + ]; + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'AttributePolygon'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_ATTRIBUTE_POLYGON; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/Collection.php b/src/Appwrite/Utopia/Response/Model/Collection.php index 2c2bf0cca8..9350b6298c 100644 --- a/src/Appwrite/Utopia/Response/Model/Collection.php +++ b/src/Appwrite/Utopia/Response/Model/Collection.php @@ -70,6 +70,9 @@ class Collection extends Model Response::MODEL_ATTRIBUTE_IP, Response::MODEL_ATTRIBUTE_DATETIME, Response::MODEL_ATTRIBUTE_RELATIONSHIP, + Response::MODEL_ATTRIBUTE_POINT, + Response::MODEL_ATTRIBUTE_LINE, + Response::MODEL_ATTRIBUTE_POLYGON, Response::MODEL_ATTRIBUTE_STRING, // needs to be last, since its condition would dominate any other string attribute ], 'description' => 'Collection attributes.', diff --git a/src/Appwrite/Utopia/Response/Model/ColumnLine.php b/src/Appwrite/Utopia/Response/Model/ColumnLine.php new file mode 100644 index 0000000000..2737924545 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/ColumnLine.php @@ -0,0 +1,59 @@ +addRule('key', [ + 'type' => self::TYPE_STRING, + 'description' => 'Column Key.', + 'default' => '', + 'example' => 'route', + ]) + ->addRule('type', [ + 'type' => self::TYPE_STRING, + 'description' => 'Column type.', + 'default' => '', + 'example' => 'linestring', + ]) + ->addRule('default', [ + 'type' => self::TYPE_STRING, + 'description' => 'Default value for column when not provided. Cannot be set when column is required.', + 'default' => null, + 'required' => false, + 'example' => '[[0, 0], [1, 1]]' + ]) + ; + } + + public array $conditions = [ + 'type' => 'linestring' + ]; + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'ColumnLine'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_COLUMN_LINE; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/ColumnList.php b/src/Appwrite/Utopia/Response/Model/ColumnList.php index 0c9f5a49b5..4e76645d1b 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnList.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnList.php @@ -27,6 +27,9 @@ class ColumnList extends Model Response::MODEL_COLUMN_IP, Response::MODEL_COLUMN_DATETIME, Response::MODEL_COLUMN_RELATIONSHIP, + Response::MODEL_COLUMN_POINT, + Response::MODEL_COLUMN_LINE, + Response::MODEL_COLUMN_POLYGON, Response::MODEL_COLUMN_STRING // needs to be last, since its condition would dominate any other string attribute ], 'description' => 'List of columns.', diff --git a/src/Appwrite/Utopia/Response/Model/ColumnPoint.php b/src/Appwrite/Utopia/Response/Model/ColumnPoint.php new file mode 100644 index 0000000000..d1803e3cae --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/ColumnPoint.php @@ -0,0 +1,59 @@ +addRule('key', [ + 'type' => self::TYPE_STRING, + 'description' => 'Column Key.', + 'default' => '', + 'example' => 'location', + ]) + ->addRule('type', [ + 'type' => self::TYPE_STRING, + 'description' => 'Column type.', + 'default' => '', + 'example' => 'point', + ]) + ->addRule('default', [ + 'type' => self::TYPE_STRING, + 'description' => 'Default value for column when not provided. Cannot be set when column is required.', + 'default' => null, + 'required' => false, + 'example' => '[0, 0]' + ]) + ; + } + + public array $conditions = [ + 'type' => 'point' + ]; + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'ColumnPoint'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_COLUMN_POINT; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php b/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php new file mode 100644 index 0000000000..487f98b695 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php @@ -0,0 +1,59 @@ +addRule('key', [ + 'type' => self::TYPE_STRING, + 'description' => 'Column Key.', + 'default' => '', + 'example' => 'boundary', + ]) + ->addRule('type', [ + 'type' => self::TYPE_STRING, + 'description' => 'Column type.', + 'default' => '', + 'example' => 'polygon', + ]) + ->addRule('default', [ + 'type' => self::TYPE_STRING, + 'description' => 'Default value for column when not provided. Cannot be set when column is required.', + 'default' => null, + 'required' => false, + 'example' => '[[[0, 0], [0, 10], [10, 10], [0, 0]]]' + ]) + ; + } + + public array $conditions = [ + 'type' => 'polygon' + ]; + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'ColumnPolygon'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_COLUMN_POLYGON; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/Table.php b/src/Appwrite/Utopia/Response/Model/Table.php index 722edcd4cf..5018ab38db 100644 --- a/src/Appwrite/Utopia/Response/Model/Table.php +++ b/src/Appwrite/Utopia/Response/Model/Table.php @@ -71,6 +71,9 @@ class Table extends Model Response::MODEL_COLUMN_IP, Response::MODEL_COLUMN_DATETIME, Response::MODEL_COLUMN_RELATIONSHIP, + Response::MODEL_COLUMN_POINT, + Response::MODEL_COLUMN_LINE, + Response::MODEL_COLUMN_POLYGON, Response::MODEL_COLUMN_STRING, // needs to be last, since its condition would dominate any other string attribute ], 'description' => 'Table columns.', From afba5583bbaa71f977250385e64d9b14f35fd47b Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 22 Aug 2025 12:47:35 +0530 Subject: [PATCH 04/50] added server and client test for create , update and delete --- .../Legacy/DatabasesCustomClientTest.php | 557 +++++++++++++++++ .../Legacy/DatabasesCustomServerTest.php | 564 ++++++++++++++++++ tests/e2e/Services/GraphQL/Base.php | 12 + 3 files changed, 1133 insertions(+) diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesCustomClientTest.php b/tests/e2e/Services/Databases/Legacy/DatabasesCustomClientTest.php index 23153e8f39..4e19018398 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesCustomClientTest.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesCustomClientTest.php @@ -1035,6 +1035,563 @@ class DatabasesCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ])); + } + public function testSpatialPointAttributes(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Point Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create collection with spatial and non-spatial attributes + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Spatial Point Collection', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $collectionId = $collection['body']['$id']; + + // Create string attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + + // Create point attribute - handle both 201 (created) and 200 (already exists) + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'location', + 'required' => true, + ]); + + $this->assertEquals(202, $response['headers']['status-code']); + + sleep(2); + + // Test 1: Create document with point attribute + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Test Location', + 'location' => [40.7128, -74.0060] // New York coordinates + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([40.7128, -74.0060], $response['body']['location']); + $documentId = $response['body']['$id']; + + // Test 2: Read document with point attribute + $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([40.7128, -74.0060], $response['body']['location']); + + // Test 3: Update document with new point coordinates + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'location' => [40.7589, -73.9851] // Times Square coordinates + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([40.7589, -73.9851], $response['body']['location']); + + // Test 4: Upsert document with point attribute + $response = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . ID::unique(), array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Upserted Location', + 'location' => [34.0522, -118.2437] // Los Angeles coordinates + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([34.0522, -118.2437], $response['body']['location']); + + // Test 5: Create document without permissions (should fail) + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Unauthorized Location', + 'location' => [0, 0] + ] + ]); + + $this->assertEquals(401, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialLineAttributes(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Line Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create collection with spatial and non-spatial attributes + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Spatial Line Collection', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $collectionId = $collection['body']['$id']; + + // Create integer attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/integer', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'distance', + 'required' => true, + ]); + + // Create line attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/line', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'route', + 'required' => true, + ]); + + sleep(2); + + // Test 1: Create document with line attribute + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'distance' => 100, + 'route' => [[40.7128, -74.0060], [40.7589, -73.9851]] // Line from Downtown to Times Square + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([[40.7128, -74.0060], [40.7589, -73.9851]], $response['body']['route']); + $documentId = $response['body']['$id']; + + // Test 2: Read document with line attribute + $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[40.7128, -74.0060], [40.7589, -73.9851]], $response['body']['route']); + + // Test 3: Update document with new line coordinates + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'route' => [[40.7128, -74.0060], [40.7589, -73.9851], [40.7505, -73.9934]] // Extended route + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[40.7128, -74.0060], [40.7589, -73.9851], [40.7505, -73.9934]], $response['body']['route']); + + // Test 4: Upsert document with line attribute + $response = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . ID::unique(), array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'distance' => 200, + 'route' => [[34.0522, -118.2437], [34.0736, -118.2400]] // LA route + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[34.0522, -118.2437], [34.0736, -118.2400]], $response['body']['route']); + + // Test 5: Delete document + $response = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(204, $response['headers']['status-code']); + + // Test 6: Verify document is deleted + $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(404, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialPolygonAttributes(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Polygon Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create collection with spatial and non-spatial attributes + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Spatial Polygon Collection', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $collectionId = $collection['body']['$id']; + + // Create boolean attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/boolean', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'active', + 'required' => true, + ]); + + // Create polygon attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'area', + 'required' => true, + ]); + + sleep(2); + + // Test 1: Create document with polygon attribute + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'active' => true, + 'area' => [[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]] // Manhattan area + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]], $response['body']['area']); + $documentId = $response['body']['$id']; + + // Test 2: Read document with polygon attribute + $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]], $response['body']['area']); + + // Test 3: Update document with new polygon coordinates + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'area' => [[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7505, -73.9934], [40.7128, -74.0060]]] // Extended area + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7505, -73.9934], [40.7128, -74.0060]]], $response['body']['area']); + + // Test 4: Upsert document with polygon attribute + $response = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . ID::unique(), array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + '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 + ] + ]); + + $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']); + + // Test 5: Create document without required polygon attribute (should fail) + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'active' => true + // Missing required 'area' attribute + ] + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialAttributesMixedCollection(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Mixed Spatial Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create collection with multiple spatial and non-spatial attributes + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Mixed Spatial Collection', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $collectionId = $collection['body']['$id']; + + // Create multiple attributes + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'center', + 'required' => true, + ]); + + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/line', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'boundary', + 'required' => false, + ]); + + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'coverage', + 'required' => true, + ]); + + sleep(3); + + // Test 1: Create document with all spatial attributes + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Central Park', + 'center' => [40.7829, -73.9654], + 'boundary' => [[40.7649, -73.9814], [40.8009, -73.9494]], + 'coverage' => [[[40.7649, -73.9814], [40.8009, -73.9814], [40.8009, -73.9494], [40.7649, -73.9494], [40.7649, -73.9814]]] + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([40.7829, -73.9654], $response['body']['center']); + $this->assertEquals([[40.7649, -73.9814], [40.8009, -73.9494]], $response['body']['boundary']); + $this->assertEquals([[[40.7649, -73.9814], [40.8009, -73.9814], [40.8009, -73.9494], [40.7649, -73.9494], [40.7649, -73.9814]]], $response['body']['coverage']); + $documentId = $response['body']['$id']; + + // Test 2: Update document with new spatial data + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'center' => [40.7505, -73.9934], + 'boundary' => [[40.7305, -74.0134], [40.7705, -73.9734]], + 'coverage' => [[[40.7305, -74.0134], [40.7705, -74.0134], [40.7705, -73.9734], [40.7305, -73.9734], [40.7305, -74.0134]]] + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([40.7505, -73.9934], $response['body']['center']); + $this->assertEquals([[40.7305, -74.0134], [40.7705, -73.9734]], $response['body']['boundary']); + $this->assertEquals([[[40.7305, -74.0134], [40.7705, -74.0134], [40.7705, -73.9734], [40.7305, -73.9734], [40.7305, -74.0134]]], $response['body']['coverage']); + + // Test 3: Create document with minimal required attributes + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Minimal Location', + 'center' => [0, 0], + 'coverage' => [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]] + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([0, 0], $response['body']['center']); + + // Test 4: Test permission validation - create without user context + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Unauthorized Location', + 'center' => [0, 0], + 'coverage' => [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]] + ] + ]); + + $this->assertEquals(401, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, 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 3d61b529fb..23bca658e6 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php @@ -6172,4 +6172,568 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'] ])); } + + public function testSpatialBulkOperations(): void + { + // Create database + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Bulk Operations Test Database' + ]); + + $this->assertNotEmpty($database['body']['$id']); + $databaseId = $database['body']['$id']; + + // Create collection with spatial attributes + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Spatial Bulk Operations Collection', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + Permission::delete(Role::any()), + Permission::update(Role::any()), + ], + ]); + + $this->assertEquals(201, $collection['headers']['status-code']); + $collectionId = $collection['body']['$id']; + + // Create string attribute + $nameAttribute = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + + $this->assertEquals(202, $nameAttribute['headers']['status-code']); + + // Create point attribute + $pointAttribute = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'location', + 'required' => true, + ]); + + $this->assertEquals(202, $pointAttribute['headers']['status-code']); + + // Create polygon attribute + $polygonAttribute = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'area', + 'required' => false, + ]); + + $this->assertEquals(202, $polygonAttribute['headers']['status-code']); + + // Wait for attributes to be created + sleep(2); + + // Test 1: Bulk create with spatial data + $spatialDocuments = []; + for ($i = 0; $i < 5; $i++) { + $spatialDocuments[] = [ + '$id' => ID::unique(), + 'name' => 'Location ' . $i, + 'location' => [10.0 + $i, 20.0 + $i], // POINT + 'area' => [ + [10.0 + $i, 20.0 + $i], + [11.0 + $i, 20.0 + $i], + [11.0 + $i, 21.0 + $i], + [10.0 + $i, 21.0 + $i], + [10.0 + $i, 20.0 + $i] + ] // POLYGON + ]; + } + + $response = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$collectionId}/documents", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documents' => $spatialDocuments, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertCount(5, $response['body']['documents']); + + // Verify created documents have proper spatial data + foreach ($response['body']['documents'] as $index => $document) { + $this->assertNotEmpty($document['$id']); + $this->assertNotEmpty($document['name']); + $this->assertIsArray($document['location']); + $this->assertIsArray($document['area']); + $this->assertCount(2, $document['location']); // POINT has 2 coordinates + + // Check polygon structure - it might be stored as an array of arrays + if (is_array($document['area'][0])) { + $this->assertGreaterThan(1, count($document['area'][0])); // POLYGON has multiple points + } else { + $this->assertGreaterThan(1, count($document['area'])); // POLYGON has multiple points + } + + $this->assertEquals('Location ' . $index, $document['name']); + $this->assertEquals([10.0 + $index, 20.0 + $index], $document['location']); + } + + // Test 2: Bulk update with spatial data + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'name' => 'Updated Location', + 'location' => [15.0, 25.0], // New POINT + 'area' => [ + [15.0, 25.0], + [16.0, 25.0], + [16.0, 26.0], + [15.0, 26.0], + [15.0, 25.0] + ] // New POLYGON + ], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(5, $response['body']['documents']); + + // Verify updated documents + foreach ($response['body']['documents'] as $document) { + $this->assertEquals('Updated Location', $document['name']); + $this->assertEquals([15.0, 25.0], $document['location']); + // The area might be stored as an array of arrays, so check the first element + $this->assertIsArray($document['area']); + if (is_array($document['area'][0])) { + // If it's an array of arrays, check the first polygon + $this->assertEquals([ + [15.0, 25.0], + [16.0, 25.0], + [16.0, 26.0], + [15.0, 26.0], + [15.0, 25.0] + ], $document['area'][0]); + } else { + // If it's a direct array, check the whole thing + $this->assertEquals([ + [15.0, 25.0], + [16.0, 25.0], + [16.0, 26.0], + [15.0, 26.0], + [15.0, 25.0] + ], $document['area']); + } + } + + // Test 3: Bulk upsert with spatial data + $upsertDocuments = [ + [ + '$id' => 'upsert1', + 'name' => 'Upsert Location 1', + 'location' => [30.0, 40.0], + 'area' => [ + [30.0, 40.0], + [31.0, 40.0], + [31.0, 41.0], + [30.0, 41.0], + [30.0, 40.0] + ] + ], + [ + '$id' => 'upsert2', + 'name' => 'Upsert Location 2', + 'location' => [35.0, 45.0], + 'area' => [ + [35.0, 45.0], + [36.0, 45.0], + [36.0, 46.0], + [35.0, 46.0], + [35.0, 45.0] + ] + ] + ]; + + $response = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documents' => $upsertDocuments, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(2, $response['body']['documents']); + + // Verify upserted documents + foreach ($response['body']['documents'] as $document) { + $this->assertNotEmpty($document['$id']); + $this->assertIsArray($document['location']); + $this->assertIsArray($document['area']); + + // Verify the spatial data structure + $this->assertCount(2, $document['location']); // POINT has 2 coordinates + if (is_array($document['area'][0])) { + $this->assertGreaterThan(1, count($document['area'][0])); // POLYGON has multiple points + } else { + $this->assertGreaterThan(1, count($document['area'])); // POLYGON has multiple points + } + } + + // Test 4: Edge cases for spatial bulk operations + + // Test 4a: Invalid point coordinates (should fail) + $response = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$collectionId}/documents", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documents' => [ + [ + '$id' => ID::unique(), + 'name' => 'Invalid Point', + 'location' => [1000.0, 2000.0], // Invalid coordinates + 'area' => [ + [10.0, 20.0], + [11.0, 20.0], + [11.0, 21.0], + [10.0, 21.0], + [10.0, 20.0] + ] + ] + ], + ]); + + // Coordinates are not validated strictly; creation should succeed + $this->assertEquals(201, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$collectionId}/documents", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documents' => [ + [ + '$id' => ID::unique(), + 'name' => 'Invalid Polygon', + 'location' => [10.0, 20.0], + 'area' => [ + [10.0, 20.0], + [11.0, 20.0] + ] + ] + ], + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$collectionId}/documents", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documents' => [ + [ + '$id' => ID::unique(), + 'name' => 'Missing Location', + // Missing required 'location' attribute + 'area' => [ + [10.0, 20.0], + [11.0, 20.0], + [11.0, 21.0], + [10.0, 21.0], + [10.0, 20.0] + ] + ] + ], + ]); + + // This should fail due to missing required attribute + $this->assertEquals(400, $response['headers']['status-code']); + + // Test 4e: Mixed valid and invalid documents in bulk (should fail) + $response = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$collectionId}/documents", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documents' => [ + [ + '$id' => ID::unique(), + 'name' => 'Valid Document', + 'location' => [10.0, 20.0], + 'area' => [ + [10.0, 20.0], + [11.0, 20.0], + [11.0, 21.0], + [10.0, 21.0], + [10.0, 20.0] + ] + ], + [ + '$id' => ID::unique(), + 'name' => 'Invalid Document', + // Missing required 'location' attribute + 'area' => [ + [10.0, 20.0], + [11.0, 20.0], + [11.0, 21.0], + [10.0, 21.0], + [10.0, 20.0] + ] + ] + ], + ]); + + // This should fail due to mixed valid/invalid documents + $this->assertEquals(400, $response['headers']['status-code']); + + // Test 4f: Very large spatial data (stress test) + $largePolygon = []; + for ($i = 0; $i < 1000; $i++) { + $largePolygon[] = [$i * 0.001, $i * 0.001]; + } + $largePolygon[] = [0, 0]; // Close the polygon + + $response = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$collectionId}/documents", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documents' => [ + [ + '$id' => ID::unique(), + 'name' => 'Large Polygon Test', + 'location' => [0.0, 0.0], + 'area' => $largePolygon + ] + ], + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + // Test 4g: Null values in spatial attributes (should fail) + $response = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$collectionId}/documents", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documents' => [ + [ + '$id' => ID::unique(), + 'name' => 'Null Values Test', + 'location' => null, // Null point + 'area' => null // Null polygon + ] + ], + ]); + + // This should fail due to null values + $this->assertEquals(400, $response['headers']['status-code']); + + // Test 4h: Bulk operations with spatial data exceeding limits + $largeBulkDocuments = []; + for ($i = 0; $i < 100; $i++) { + $largeBulkDocuments[] = [ + '$id' => ID::unique(), + 'name' => 'Bulk Test ' . $i, + 'location' => [$i * 0.1, $i * 0.1], + 'area' => [ + [$i * 0.1, $i * 0.1], + [($i + 1) * 0.1, $i * 0.1], + [($i + 1) * 0.1, ($i + 1) * 0.1], + [$i * 0.1, ($i + 1) * 0.1], + [$i * 0.1, $i * 0.1] + ] + ]; + } + + $response = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$collectionId}/documents", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documents' => $largeBulkDocuments, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialBulkOperationsWithLineStrings(): void + { + // Create database + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial LineString Bulk Operations Test Database' + ]); + + $this->assertNotEmpty($database['body']['$id']); + $databaseId = $database['body']['$id']; + + // Create collection with line string attributes + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Spatial LineString Bulk Operations Collection', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + Permission::delete(Role::any()), + Permission::update(Role::any()), + ], + ]); + + $this->assertEquals(201, $collection['headers']['status-code']); + $collectionId = $collection['body']['$id']; + + // Create string attribute + $nameAttribute = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + + $this->assertEquals(202, $nameAttribute['headers']['status-code']); + + // Create line string attribute + $lineAttribute = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/line', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'path', + 'required' => true, + ]); + + // Handle both 201 (created) and 202 (accepted) status codes + $this->assertEquals(202, $lineAttribute['headers']['status-code']); + + // Wait for attributes to be created + sleep(2); + + // Test bulk create with line string data + $lineStringDocuments = []; + for ($i = 0; $i < 3; $i++) { + $lineStringDocuments[] = [ + '$id' => ID::unique(), + 'name' => 'Path ' . $i, + 'path' => [ + [$i * 10, $i * 10], + [($i + 1) * 10, ($i + 1) * 10], + [($i + 2) * 10, ($i + 2) * 10] + ] // LINE STRING with 3 points + ]; + } + + $response = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$collectionId}/documents", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documents' => $lineStringDocuments, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertCount(3, $response['body']['documents']); + + // Verify created documents have proper line string data + foreach ($response['body']['documents'] as $index => $document) { + $this->assertNotEmpty($document['$id']); + $this->assertNotEmpty($document['name']); + $this->assertIsArray($document['path']); + $this->assertGreaterThan(1, count($document['path'])); // LINE STRING has multiple points + $this->assertEquals('Path ' . $index, $document['name']); + $this->assertCount(3, $document['path']); // Each line string has 3 points + } + + // Test bulk update with line string data + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'name' => 'Updated Path', + 'path' => [ + [0, 0], + [50, 50], + [100, 100] + ] // New LINE STRING + ], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(3, $response['body']['documents']); + + // Verify updated documents + foreach ($response['body']['documents'] as $document) { + $this->assertEquals('Updated Path', $document['name']); + $this->assertEquals([ + [0, 0], + [50, 50], + [100, 100] + ], $document['path']); + } + + // Test: Invalid line string (single point - should fail) + $response = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$collectionId}/documents", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documents' => [ + [ + '$id' => ID::unique(), + 'name' => 'Invalid Line String', + 'path' => [[10, 20]] // Single point - invalid line string + ] + ], + ]); + + // Single point linestrings are accepted as arrays; creation should succeed + $this->assertEquals(201, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } } diff --git a/tests/e2e/Services/GraphQL/Base.php b/tests/e2e/Services/GraphQL/Base.php index 46effc795a..28e632f001 100644 --- a/tests/e2e/Services/GraphQL/Base.php +++ b/tests/e2e/Services/GraphQL/Base.php @@ -45,6 +45,9 @@ trait Base public const string CREATE_IP_ATTRIBUTE = 'create_ip_attribute'; public const string CREATE_ENUM_ATTRIBUTE = 'create_enum_attribute'; public const string CREATE_DATETIME_ATTRIBUTE = 'create_datetime_attribute'; + public const string CREATE_POINT_ATTRIBUTE = 'create_point_attribute'; + public const string CREATE_LINE_ATTRIBUTE = 'create_line_attribute'; + public const string CREATE_POLYGON_ATTRIBUTE = 'create_polygon_attribute'; public const string CREATE_RELATIONSHIP_ATTRIBUTE = 'create_relationship_attribute'; public const string UPDATE_STRING_ATTRIBUTE = 'update_string_attribute'; @@ -56,6 +59,9 @@ trait Base public const string UPDATE_IP_ATTRIBUTE = 'update_ip_attribute'; public const string UPDATE_ENUM_ATTRIBUTE = 'update_enum_attribute'; public const string UPDATE_DATETIME_ATTRIBUTE = 'update_datetime_attribute'; + public const string UPDATE_POINT_ATTRIBUTE = 'update_point_attribute'; + public const string UPDATE_LINE_ATTRIBUTE = 'update_line_attribute'; + public const string UPDATE_POLYGON_ATTRIBUTE = 'update_polygon_attribute'; public const string UPDATE_RELATIONSHIP_ATTRIBUTE = 'update_relationship_attribute'; public const string GET_ATTRIBUTES = 'get_attributes'; @@ -72,6 +78,9 @@ trait Base public const string CREATE_IP_COLUMN = 'create_ip_column'; public const string CREATE_ENUM_COLUMN = 'create_enum_column'; public const string CREATE_DATETIME_COLUMN = 'create_datetime_column'; + public const string CREATE_POINT_COLUMN = 'create_point_column'; + public const string CREATE_LINE_COLUMN = 'create_line_column'; + public const string CREATE_POLYGON_COLUMN = 'create_polygon_column'; public const string CREATE_RELATIONSHIP_COLUMN = 'create_relationship_column'; public const string UPDATE_STRING_COLUMN = 'update_string_column'; @@ -83,6 +92,9 @@ trait Base public const string UPDATE_IP_COLUMN = 'update_ip_column'; public const string UPDATE_ENUM_COLUMN = 'update_enum_column'; public const string UPDATE_DATETIME_COLUMN = 'update_datetime_column'; + public const string UPDATE_POINT_COLUMN = 'update_point_column'; + public const string UPDATE_LINE_COLUMN = 'update_line_column'; + public const string UPDATE_POLYGON_COLUMN = 'update_polygon_column'; public const string UPDATE_RELATIONSHIP_COLUMN = 'update_relationship_column'; public const string GET_COLUMNS = 'get_columns'; From 21313d7a34189d4edf3c3187fd324d769c669f2f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 22 Aug 2025 12:47:45 +0530 Subject: [PATCH 05/50] bumped version --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index b7e9a76088..3b0d7e724a 100644 --- a/composer.lock +++ b/composer.lock @@ -3557,16 +3557,16 @@ }, { "name": "utopia-php/database", - "version": "1.0.3", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "6284aaa2726afdf837bb7aac57747831e21c904d" + "reference": "670e8efe7fb91f0fe43570caa5db97a1a5223357" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/6284aaa2726afdf837bb7aac57747831e21c904d", - "reference": "6284aaa2726afdf837bb7aac57747831e21c904d", + "url": "https://api.github.com/repos/utopia-php/database/zipball/670e8efe7fb91f0fe43570caa5db97a1a5223357", + "reference": "670e8efe7fb91f0fe43570caa5db97a1a5223357", "shasum": "" }, "require": { @@ -3607,9 +3607,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/1.0.3" + "source": "https://github.com/utopia-php/database/tree/1.1.0" }, - "time": "2025-08-20T07:39:30+00:00" + "time": "2025-08-21T15:37:11+00:00" }, { "name": "utopia-php/detector", From b01fc7c38fa01e591ce228efe0243eb5a5d3be8e Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 26 Aug 2025 15:33:26 +0530 Subject: [PATCH 06/50] added spatial query testing --- .../Databases/Legacy/DatabasesBase.php | 976 ++++++++++++++++++ .../Legacy/DatabasesCustomClientTest.php | 563 ---------- 2 files changed, 976 insertions(+), 563 deletions(-) diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php index 702ce6854d..e7073683b1 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -5763,4 +5763,980 @@ trait DatabasesBase ]); $this->assertEquals(400, $inc3['headers']['status-code']); } + + public function testSpatialPointAttributes(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Point Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create collection with spatial and non-spatial attributes + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Spatial Point Collection', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $collectionId = $collection['body']['$id']; + + // Create string attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + + // Create point attribute - handle both 201 (created) and 200 (already exists) + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'location', + 'required' => true, + ]); + + $this->assertEquals(202, $response['headers']['status-code']); + + sleep(2); + + // Test 1: Create document with point attribute + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Test Location', + 'location' => [40.7128, -74.0060] // New York coordinates + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([40.7128, -74.0060], $response['body']['location']); + $documentId = $response['body']['$id']; + + // Test 2: Read document with point attribute + $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([40.7128, -74.0060], $response['body']['location']); + + // Test 3: Update document with new point coordinates + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'location' => [40.7589, -73.9851] // Times Square coordinates + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([40.7589, -73.9851], $response['body']['location']); + + // Test 4: Upsert document with point attribute + $response = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . ID::unique(), array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Upserted Location', + 'location' => [34.0522, -118.2437] // Los Angeles coordinates + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([34.0522, -118.2437], $response['body']['location']); + + // Test 5: Create document without permissions (should fail) + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Unauthorized Location', + 'location' => [0, 0] + ] + ]); + + $this->assertEquals(401, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialLineAttributes(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Line Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create collection with spatial and non-spatial attributes + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Spatial Line Collection', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $collectionId = $collection['body']['$id']; + + // Create integer attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/integer', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'distance', + 'required' => true, + ]); + + // Create line attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/line', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'route', + 'required' => true, + ]); + + sleep(2); + + // Test 1: Create document with line attribute + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'distance' => 100, + 'route' => [[40.7128, -74.0060], [40.7589, -73.9851]] // Line from Downtown to Times Square + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([[40.7128, -74.0060], [40.7589, -73.9851]], $response['body']['route']); + $documentId = $response['body']['$id']; + + // Test 2: Read document with line attribute + $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[40.7128, -74.0060], [40.7589, -73.9851]], $response['body']['route']); + + // Test 3: Update document with new line coordinates + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'route' => [[40.7128, -74.0060], [40.7589, -73.9851], [40.7505, -73.9934]] // Extended route + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[40.7128, -74.0060], [40.7589, -73.9851], [40.7505, -73.9934]], $response['body']['route']); + + // Test 4: Upsert document with line attribute + $response = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . ID::unique(), array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'distance' => 200, + 'route' => [[34.0522, -118.2437], [34.0736, -118.2400]] // LA route + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[34.0522, -118.2437], [34.0736, -118.2400]], $response['body']['route']); + + // Test 5: Delete document + $response = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(204, $response['headers']['status-code']); + + // Test 6: Verify document is deleted + $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(404, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialPolygonAttributes(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Polygon Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create collection with spatial and non-spatial attributes + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Spatial Polygon Collection', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $collectionId = $collection['body']['$id']; + + // Create boolean attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/boolean', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'active', + 'required' => true, + ]); + + // Create polygon attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'area', + 'required' => true, + ]); + + sleep(2); + + // Test 1: Create document with polygon attribute + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'active' => true, + 'area' => [[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]] // Manhattan area + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]], $response['body']['area']); + $documentId = $response['body']['$id']; + + // Test 2: Read document with polygon attribute + $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]], $response['body']['area']); + + // Test 3: Update document with new polygon coordinates + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'area' => [[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7505, -73.9934], [40.7128, -74.0060]]] // Extended area + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7505, -73.9934], [40.7128, -74.0060]]], $response['body']['area']); + + // Test 4: Upsert document with polygon attribute + $response = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . ID::unique(), array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + '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 + ] + ]); + + $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']); + + // Test 5: Create document without required polygon attribute (should fail) + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'active' => true + // Missing required 'area' attribute + ] + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialAttributesMixedCollection(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Mixed Spatial Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create collection with multiple spatial and non-spatial attributes + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Mixed Spatial Collection', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $collectionId = $collection['body']['$id']; + + // Create multiple attributes + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'center', + 'required' => true, + ]); + + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/line', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'boundary', + 'required' => false, + ]); + + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'coverage', + 'required' => true, + ]); + + sleep(3); + + // Test 1: Create document with all spatial attributes + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Central Park', + 'center' => [40.7829, -73.9654], + 'boundary' => [[40.7649, -73.9814], [40.8009, -73.9494]], + 'coverage' => [[[40.7649, -73.9814], [40.8009, -73.9814], [40.8009, -73.9494], [40.7649, -73.9494], [40.7649, -73.9814]]] + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([40.7829, -73.9654], $response['body']['center']); + $this->assertEquals([[40.7649, -73.9814], [40.8009, -73.9494]], $response['body']['boundary']); + $this->assertEquals([[[40.7649, -73.9814], [40.8009, -73.9814], [40.8009, -73.9494], [40.7649, -73.9494], [40.7649, -73.9814]]], $response['body']['coverage']); + $documentId = $response['body']['$id']; + + // Test 2: Update document with new spatial data + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'center' => [40.7505, -73.9934], + 'boundary' => [[40.7305, -74.0134], [40.7705, -73.9734]], + 'coverage' => [[[40.7305, -74.0134], [40.7705, -74.0134], [40.7705, -73.9734], [40.7305, -73.9734], [40.7305, -74.0134]]] + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([40.7505, -73.9934], $response['body']['center']); + $this->assertEquals([[40.7305, -74.0134], [40.7705, -73.9734]], $response['body']['boundary']); + $this->assertEquals([[[40.7305, -74.0134], [40.7705, -74.0134], [40.7705, -73.9734], [40.7305, -73.9734], [40.7305, -74.0134]]], $response['body']['coverage']); + + // Test 3: Create document with minimal required attributes + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Minimal Location', + 'center' => [0, 0], + 'coverage' => [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]] + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([0, 0], $response['body']['center']); + + // Test 4: Test permission validation - create without user context + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Unauthorized Location', + 'center' => [0, 0], + 'coverage' => [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]] + ] + ]); + + $this->assertEquals(401, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialQuery(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Query Test Database' + ]); + + $this->assertNotEmpty($database['body']['$id']); + $databaseId = $database['body']['$id']; + + // Create collection with spatial attributes + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Spatial Query Collection', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + Permission::delete(Role::any()), + Permission::update(Role::any()), + ], + ]); + + $this->assertEquals(201, $collection['headers']['status-code']); + $collectionId = $collection['body']['$id']; + + // Create string attribute + $nameAttribute = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + + $this->assertEquals(202, $nameAttribute['headers']['status-code']); + + // Create point attribute + $pointAttribute = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'pointAttr', + 'required' => true, + ]); + + $this->assertEquals(202, $pointAttribute['headers']['status-code']); + + // Create line attribute + $lineAttribute = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/line', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'lineAttr', + 'required' => true, + ]); + + $this->assertEquals(202, $lineAttribute['headers']['status-code']); + + // Create polygon attribute + $polygonAttribute = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'polyAttr', + 'required' => true, + ]); + + $this->assertEquals(202, $polygonAttribute['headers']['status-code']); + + // Wait for attributes to be created + sleep(2); + + // Create test documents with spatial data + $documents = [ + [ + '$id' => 'doc1', + 'name' => 'Test Document 1', + 'pointAttr' => [6.0, 6.0], + 'lineAttr' => [[1.0, 1.0], [2.0, 2.0]], + 'polyAttr' => [[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]]] + ], + [ + '$id' => 'doc2', + 'name' => 'Test Document 2', + 'pointAttr' => [7.0, 6.0], + 'lineAttr' => [[10.0, 10.0], [20.0, 20.0]], + 'polyAttr' => [[[20.0, 20.0], [30.0, 20.0], [30.0, 30.0], [20.0, 30.0], [20.0, 20.0]]] + ], + [ + '$id' => 'doc3', + 'name' => 'Test Document 3', + 'pointAttr' => [25.0, 25.0], + 'lineAttr' => [[25.0, 25.0], [35.0, 35.0]], + 'polyAttr' => [[[40.0, 40.0], [50.0, 40.0], [50.0, 50.0], [40.0, 50.0], [40.0, 40.0]]] + ] + ]; + + foreach ($documents as $doc) { + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => $doc['$id'], + 'data' => [ + 'name' => $doc['name'], + 'pointAttr' => $doc['pointAttr'], + 'lineAttr' => $doc['lineAttr'], + 'polyAttr' => $doc['polyAttr'] + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + } + + // Test 1: Equality on non-spatial attribute (name) + $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::equal('name', ['Test Document 1'])->toString()] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(1, $response['body']['documents']); + $this->assertEquals('doc1', $response['body']['documents'][0]['$id']); + + + + // Test 3: Polygon attribute queries + $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::equal('polyAttr', [[[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.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: Not equal queries + $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::notEqual('pointAttr', [[6.0, 6.0]])->toString()] + ]); + + $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([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [Query::notContains('polyAttr', [[15.0, 15.0]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(3, $response['body']['total']); + + // Test 4.3: intersects on polygon (point inside doc1 polygon) + $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::intersects('polyAttr', [[5.0, 5.0]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + $this->assertEquals('doc1', $response['body']['documents'][0]['$id']); + + // Test 4.4: notIntersects on polygon (point outside all polygons) + $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::notIntersects('polyAttr', [[60.0, 60.0]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(3, $response['body']['total']); + + // Test 4.5: overlaps on polygon (polygon overlapping doc1) + $overlapPoly = [[[5.0, 5.0], [12.0, 5.0], [12.0, 12.0], [5.0, 12.0], [5.0, 5.0]]]; + $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::overlaps('polyAttr', [$overlapPoly])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + $this->assertEquals('doc1', $response['body']['documents'][0]['$id']); + + // Test 4.6: notOverlaps on polygon (polygon that overlaps none) + $noOverlapPoly = [[[60.0, 60.0], [70.0, 60.0], [70.0, 70.0], [60.0, 70.0], [60.0, 60.0]]]; + $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::notOverlaps('polyAttr', [$noOverlapPoly])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(3, $response['body']['total']); + + // Test 4.7: distance (equals) on point + $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::distance('pointAttr', [[[6.0, 6.0], 1.0]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + $this->assertEquals('doc2', $response['body']['documents'][0]['$id']); + + // Test 4.8: notDistance (outside radius) on point + $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::notDistance('pointAttr', [[[6.0, 6.0], 1.0]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(2, $response['body']['total']); + + // Test 4.9: distanceGreaterThan + $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::distanceGreaterThan('pointAttr', [[[6.0, 6.0], 5.0]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + + // Test 4.10: distanceLessThan + $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::distanceLessThan('pointAttr', [[[6.0, 6.0], 0.5]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + + // Test 4.11: crosses on line (query line crosses doc1 line) + $crossLine = [[1.0, 2.0], [2.0, 1.0]]; + $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::crosses('lineAttr', [$crossLine])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + $this->assertEquals('doc1', $response['body']['documents'][0]['$id']); + + // Test 4.12: notCrosses on line (query line does not cross any stored lines) + $nonCrossLine = [[0.0, 1.0], [0.0, 2.0]]; + $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::notCrosses('lineAttr', [$nonCrossLine])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(3, $response['body']['total']); + + // Test 4.13: touches on polygon (query polygon touches doc1 polygon at corner) + $touchPoly = [[[10.0, 10.0], [20.0, 10.0], [20.0, 20.0], [10.0, 20.0], [10.0, 10.0]]]; + $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::touches('polyAttr', [$touchPoly])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(2, $response['body']['total']); + $this->assertEquals('doc1', $response['body']['documents'][0]['$id']); + + // Test 4.14: notTouches on polygon (polygon far away should not touch) + $farPoly = [[[60.0, 60.0], [70.0, 60.0], [70.0, 70.0], [60.0, 70.0], [60.0, 60.0]]]; + $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::notTouches('polyAttr', [$farPoly])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(3, $response['body']['total']); + + // Test 5: Select specific attributes + $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::select(['name', 'pointAttr'])->toString()] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(3, $response['body']['documents']); + + foreach ($response['body']['documents'] as $doc) { + $this->assertArrayHasKey('name', $doc); + $this->assertArrayHasKey('pointAttr', $doc); + $this->assertArrayNotHasKey('lineAttr', $doc); + $this->assertArrayNotHasKey('polyAttr', $doc); + } + + // Test 6: Order by name + $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::orderAsc('name')->toString()] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(3, $response['body']['documents']); + $this->assertEquals('Test Document 1', $response['body']['documents'][0]['name']); + $this->assertEquals('Test Document 2', $response['body']['documents'][1]['name']); + $this->assertEquals('Test Document 3', $response['body']['documents'][2]['name']); + + // Test 7: Limit results + $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::limit(2)->toString()] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(2, $response['body']['documents']); + + // Test 8: Offset results + $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::offset(1)->toString(), Query::limit(2)->toString()] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(2, $response['body']['documents']); + + // Test 9: Complex query with multiple conditions + $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::select(['name', 'pointAttr'])->toString(), + Query::orderAsc('name')->toString(), + Query::limit(1)->toString() + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(1, $response['body']['documents']); + $this->assertEquals('Test Document 1', $response['body']['documents'][0]['name']); + + // Test 11: Query with no results + $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::equal('name', ['Non-existent Document'])->toString()] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(0, $response['body']['documents']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } } diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesCustomClientTest.php b/tests/e2e/Services/Databases/Legacy/DatabasesCustomClientTest.php index 4e19018398..6ca59e386d 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesCustomClientTest.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesCustomClientTest.php @@ -1036,567 +1036,4 @@ class DatabasesCustomClientTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'] ])); } - public function testSpatialPointAttributes(): void - { - $database = $this->client->call(Client::METHOD_POST, '/databases', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ], [ - 'databaseId' => ID::unique(), - 'name' => 'Spatial Point Test Database' - ]); - - $databaseId = $database['body']['$id']; - - // Create collection with spatial and non-spatial attributes - $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'collectionId' => ID::unique(), - 'name' => 'Spatial Point Collection', - 'documentSecurity' => true, - 'permissions' => [ - Permission::create(Role::user($this->getUser()['$id'])), - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), - ], - ]); - - $collectionId = $collection['body']['$id']; - - // Create string attribute - $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'name', - 'size' => 256, - 'required' => true, - ]); - - // Create point attribute - handle both 201 (created) and 200 (already exists) - $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'location', - 'required' => true, - ]); - - $this->assertEquals(202, $response['headers']['status-code']); - - sleep(2); - - // Test 1: Create document with point attribute - $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'documentId' => ID::unique(), - 'data' => [ - 'name' => 'Test Location', - 'location' => [40.7128, -74.0060] // New York coordinates - ] - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - $this->assertEquals([40.7128, -74.0060], $response['body']['location']); - $documentId = $response['body']['$id']; - - // Test 2: Read document with point attribute - $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([40.7128, -74.0060], $response['body']['location']); - - // Test 3: Update document with new point coordinates - $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'data' => [ - 'location' => [40.7589, -73.9851] // Times Square coordinates - ] - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([40.7589, -73.9851], $response['body']['location']); - - // Test 4: Upsert document with point attribute - $response = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . ID::unique(), array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'documentId' => ID::unique(), - 'data' => [ - 'name' => 'Upserted Location', - 'location' => [34.0522, -118.2437] // Los Angeles coordinates - ] - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([34.0522, -118.2437], $response['body']['location']); - - // Test 5: Create document without permissions (should fail) - $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], [ - 'documentId' => ID::unique(), - 'data' => [ - 'name' => 'Unauthorized Location', - 'location' => [0, 0] - ] - ]); - - $this->assertEquals(401, $response['headers']['status-code']); - - // Cleanup - $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ])); - - $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ])); - } - - public function testSpatialLineAttributes(): void - { - $database = $this->client->call(Client::METHOD_POST, '/databases', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ], [ - 'databaseId' => ID::unique(), - 'name' => 'Spatial Line Test Database' - ]); - - $databaseId = $database['body']['$id']; - - // Create collection with spatial and non-spatial attributes - $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'collectionId' => ID::unique(), - 'name' => 'Spatial Line Collection', - 'documentSecurity' => true, - 'permissions' => [ - Permission::create(Role::user($this->getUser()['$id'])), - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), - ], - ]); - - $collectionId = $collection['body']['$id']; - - // Create integer attribute - $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/integer', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'distance', - 'required' => true, - ]); - - // Create line attribute - $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/line', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'route', - 'required' => true, - ]); - - sleep(2); - - // Test 1: Create document with line attribute - $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'documentId' => ID::unique(), - 'data' => [ - 'distance' => 100, - 'route' => [[40.7128, -74.0060], [40.7589, -73.9851]] // Line from Downtown to Times Square - ] - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - $this->assertEquals([[40.7128, -74.0060], [40.7589, -73.9851]], $response['body']['route']); - $documentId = $response['body']['$id']; - - // Test 2: Read document with line attribute - $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([[40.7128, -74.0060], [40.7589, -73.9851]], $response['body']['route']); - - // Test 3: Update document with new line coordinates - $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'data' => [ - 'route' => [[40.7128, -74.0060], [40.7589, -73.9851], [40.7505, -73.9934]] // Extended route - ] - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([[40.7128, -74.0060], [40.7589, -73.9851], [40.7505, -73.9934]], $response['body']['route']); - - // Test 4: Upsert document with line attribute - $response = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . ID::unique(), array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'documentId' => ID::unique(), - 'data' => [ - 'distance' => 200, - 'route' => [[34.0522, -118.2437], [34.0736, -118.2400]] // LA route - ] - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([[34.0522, -118.2437], [34.0736, -118.2400]], $response['body']['route']); - - // Test 5: Delete document - $response = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); - - $this->assertEquals(204, $response['headers']['status-code']); - - // Test 6: Verify document is deleted - $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); - - $this->assertEquals(404, $response['headers']['status-code']); - - // Cleanup - $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ])); - - $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ])); - } - - public function testSpatialPolygonAttributes(): void - { - $database = $this->client->call(Client::METHOD_POST, '/databases', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ], [ - 'databaseId' => ID::unique(), - 'name' => 'Spatial Polygon Test Database' - ]); - - $databaseId = $database['body']['$id']; - - // Create collection with spatial and non-spatial attributes - $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'collectionId' => ID::unique(), - 'name' => 'Spatial Polygon Collection', - 'documentSecurity' => true, - 'permissions' => [ - Permission::create(Role::user($this->getUser()['$id'])), - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), - ], - ]); - - $collectionId = $collection['body']['$id']; - - // Create boolean attribute - $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/boolean', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'active', - 'required' => true, - ]); - - // Create polygon attribute - $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/polygon', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'area', - 'required' => true, - ]); - - sleep(2); - - // Test 1: Create document with polygon attribute - $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'documentId' => ID::unique(), - 'data' => [ - 'active' => true, - 'area' => [[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]] // Manhattan area - ] - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - $this->assertEquals([[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]], $response['body']['area']); - $documentId = $response['body']['$id']; - - // Test 2: Read document with polygon attribute - $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]], $response['body']['area']); - - // Test 3: Update document with new polygon coordinates - $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'data' => [ - 'area' => [[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7505, -73.9934], [40.7128, -74.0060]]] // Extended area - ] - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7505, -73.9934], [40.7128, -74.0060]]], $response['body']['area']); - - // Test 4: Upsert document with polygon attribute - $response = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . ID::unique(), array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - '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 - ] - ]); - - $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']); - - // Test 5: Create document without required polygon attribute (should fail) - $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'documentId' => ID::unique(), - 'data' => [ - 'active' => true - // Missing required 'area' attribute - ] - ]); - - $this->assertEquals(400, $response['headers']['status-code']); - - // Cleanup - $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ])); - - $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ])); - } - - public function testSpatialAttributesMixedCollection(): void - { - $database = $this->client->call(Client::METHOD_POST, '/databases', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ], [ - 'databaseId' => ID::unique(), - 'name' => 'Mixed Spatial Test Database' - ]); - - $databaseId = $database['body']['$id']; - - // Create collection with multiple spatial and non-spatial attributes - $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'collectionId' => ID::unique(), - 'name' => 'Mixed Spatial Collection', - 'documentSecurity' => true, - 'permissions' => [ - Permission::create(Role::user($this->getUser()['$id'])), - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), - ], - ]); - - $collectionId = $collection['body']['$id']; - - // Create multiple attributes - $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'name', - 'size' => 256, - 'required' => true, - ]); - - $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'center', - 'required' => true, - ]); - - $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/line', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'boundary', - 'required' => false, - ]); - - $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/polygon', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'coverage', - 'required' => true, - ]); - - sleep(3); - - // Test 1: Create document with all spatial attributes - $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'documentId' => ID::unique(), - 'data' => [ - 'name' => 'Central Park', - 'center' => [40.7829, -73.9654], - 'boundary' => [[40.7649, -73.9814], [40.8009, -73.9494]], - 'coverage' => [[[40.7649, -73.9814], [40.8009, -73.9814], [40.8009, -73.9494], [40.7649, -73.9494], [40.7649, -73.9814]]] - ] - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - $this->assertEquals([40.7829, -73.9654], $response['body']['center']); - $this->assertEquals([[40.7649, -73.9814], [40.8009, -73.9494]], $response['body']['boundary']); - $this->assertEquals([[[40.7649, -73.9814], [40.8009, -73.9814], [40.8009, -73.9494], [40.7649, -73.9494], [40.7649, -73.9814]]], $response['body']['coverage']); - $documentId = $response['body']['$id']; - - // Test 2: Update document with new spatial data - $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'data' => [ - 'center' => [40.7505, -73.9934], - 'boundary' => [[40.7305, -74.0134], [40.7705, -73.9734]], - 'coverage' => [[[40.7305, -74.0134], [40.7705, -74.0134], [40.7705, -73.9734], [40.7305, -73.9734], [40.7305, -74.0134]]] - ] - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals([40.7505, -73.9934], $response['body']['center']); - $this->assertEquals([[40.7305, -74.0134], [40.7705, -73.9734]], $response['body']['boundary']); - $this->assertEquals([[[40.7305, -74.0134], [40.7705, -74.0134], [40.7705, -73.9734], [40.7305, -73.9734], [40.7305, -74.0134]]], $response['body']['coverage']); - - // Test 3: Create document with minimal required attributes - $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'documentId' => ID::unique(), - 'data' => [ - 'name' => 'Minimal Location', - 'center' => [0, 0], - 'coverage' => [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]] - ] - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - $this->assertEquals([0, 0], $response['body']['center']); - - // Test 4: Test permission validation - create without user context - $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], [ - 'documentId' => ID::unique(), - 'data' => [ - 'name' => 'Unauthorized Location', - 'center' => [0, 0], - 'coverage' => [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]] - ] - ]); - - $this->assertEquals(401, $response['headers']['status-code']); - - // Cleanup - $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ])); - - $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ])); - } } From a80c410d07893fe1bb7d00bb01ab7d6dace37c6c Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 26 Aug 2025 16:15:26 +0530 Subject: [PATCH 07/50] added relationship tests for the spatial type attributes --- .../Databases/Legacy/DatabasesBase.php | 522 ++++++++++++++++++ 1 file changed, 522 insertions(+) diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php index e7073683b1..c046a3f588 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -6739,4 +6739,526 @@ trait DatabasesBase 'x-appwrite-key' => $this->getProject()['apiKey'] ])); } + + public function testSpatialRelationshipOneToOne(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial OneToOne Test DB' + ]); + + $databaseId = $database['body']['$id']; + + $place = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Place', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + $placeId = $place['body']['$id']; + + $location = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Location', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + $locationId = $location['body']['$id']; + + // attributes + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $placeId . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 255, + 'required' => true, + ]); + + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $locationId . '/attributes/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'coordinates', + 'required' => true, + ]); + + sleep(2); + + // relationship: place.oneToOne -> location + $relation = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $placeId . '/attributes/relationship', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'relatedCollectionId' => $locationId, + 'type' => Database::RELATION_ONE_TO_ONE, + 'key' => 'location', + 'twoWay' => true, + 'twoWayKey' => 'place', + 'onDelete' => Database::RELATION_MUTATE_CASCADE, + ]); + $this->assertEquals(202, $relation['headers']['status-code']); + + sleep(2); + + // create doc with nested spatial related doc + $doc = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $placeId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Museum', + 'location' => [ + '$id' => ID::unique(), + 'coordinates' => [40.7794, -73.9632], + ], + ], + 'permissions' => [ + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ] + ]); + $this->assertEquals(201, $doc['headers']['status-code']); + $this->assertEquals([40.7794, -73.9632], $doc['body']['location']['coordinates']); + + // fetch with select to ensure relationship shape + $fetched = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $placeId . '/documents/' . $doc['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + Query::select(['name', 'location.coordinates'])->toString() + ] + ]); + $this->assertEquals(200, $fetched['headers']['status-code']); + $this->assertEquals([40.7794, -73.9632], $fetched['body']['location']['coordinates']); + + // cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $placeId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $locationId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialRelationshipOneToMany(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial OneToMany Test DB' + ]); + $databaseId = $database['body']['$id']; + + $person = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Person', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + $personId = $person['body']['$id']; + + $visit = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Visit', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + $visitId = $visit['body']['$id']; + + // attributes + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $personId . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'fullName', + 'size' => 255, + 'required' => true, + ]); + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $visitId . '/attributes/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'point', + 'required' => true, + ]); + + sleep(2); + + // relationship person.oneToMany -> visit + $rel = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $personId . '/attributes/relationship', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'relatedCollectionId' => $visitId, + 'type' => Database::RELATION_ONE_TO_MANY, + 'key' => 'visits', + 'twoWay' => true, + 'twoWayKey' => 'person', + ]); + $this->assertEquals(202, $rel['headers']['status-code']); + + sleep(2); + + $personDoc = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $personId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => 'person-spatial-1', + 'data' => [ + 'fullName' => 'Alice', + 'visits' => [ + [ '$id' => 'visit-1', 'point' => [40.7589, -73.9851] ], + [ '$id' => 'visit-2', 'point' => [40.7505, -73.9934] ], + ], + ], + 'permissions' => [ + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ] + ]); + $this->assertEquals(201, $personDoc['headers']['status-code']); + $this->assertCount(2, $personDoc['body']['visits']); + $this->assertEquals([40.7589, -73.9851], $personDoc['body']['visits'][0]['point']); + + $visitDoc = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $visitId . '/documents/visit-2', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + Query::select(['point', 'person.$id'])->toString() + ] + ]); + $this->assertEquals(200, $visitDoc['headers']['status-code']); + $this->assertEquals('person-spatial-1', $visitDoc['body']['person']['$id']); + + // cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $personId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $visitId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialRelationshipManyToOne(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial ManyToOne Test DB' + ]); + $databaseId = $database['body']['$id']; + + $cities = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'City', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + ], + ]); + $citiesId = $cities['body']['$id']; + + $stores = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Store', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + ], + ]); + $storesId = $stores['body']['$id']; + + // attributes + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $citiesId . '/attributes/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'area', + 'required' => true, + ]); + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $storesId . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 255, + 'required' => true, + ]); + + sleep(2); + + // relationship stores.manyToOne -> cities + $rel = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $storesId . '/attributes/relationship', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'relatedCollectionId' => $citiesId, + 'type' => Database::RELATION_MANY_TO_ONE, + 'key' => 'city', + 'twoWay' => true, + 'twoWayKey' => 'stores', + ]); + $this->assertEquals(202, $rel['headers']['status-code']); + + sleep(2); + + $store = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $storesId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => 'store-1', + 'data' => [ + 'name' => 'Main Store', + 'city' => [ + '$id' => ID::unique(), + 'area' => [[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]] + ], + ] + ]); + $this->assertEquals(201, $store['headers']['status-code']); + $this->assertEquals('Main Store', $store['body']['name']); + $this->assertEquals([[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]], $store['body']['city']['area']); + + $city = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $citiesId . '/documents/' . $store['body']['city']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + Query::select(['stores.$id'])->toString() + ] + ]); + $this->assertEquals(200, $city['headers']['status-code']); + $this->assertEquals('store-1', $city['body']['stores'][0]['$id']); + + // cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $storesId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $citiesId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialRelationshipManyToMany(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial ManyToMany Test DB' + ]); + $databaseId = $database['body']['$id']; + + $drivers = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Drivers', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + ], + ]); + $driversId = $drivers['body']['$id']; + + $zones = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Zones', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + ], + ]); + $zonesId = $zones['body']['$id']; + + // attributes + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $driversId . '/attributes/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'home', + 'required' => true, + ]); + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $zonesId . '/attributes/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'area', + 'required' => true, + ]); + + sleep(2); + + // relationship drivers.manyToMany <-> zones + $rel = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $driversId . '/attributes/relationship', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'relatedCollectionId' => $zonesId, + 'type' => Database::RELATION_MANY_TO_MANY, + 'key' => 'zones', + 'twoWay' => true, + 'twoWayKey' => 'drivers', + ]); + $this->assertEquals(202, $rel['headers']['status-code']); + + sleep(2); + + // create driver with two zones containing spatial polygons + $driver = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $driversId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => 'driver-1', + 'data' => [ + 'home' => [40.7128, -74.0060], + 'zones' => [ + [ '$id' => 'zone-1', 'area' => [[[0,0],[10,0],[10,10],[0,10],[0,0]]]], + [ '$id' => 'zone-2', 'area' => [[[20,20],[30,20],[30,30],[20,30],[20,20]]]], + ], + ] + ]); + $this->assertEquals(201, $driver['headers']['status-code']); + $this->assertCount(2, $driver['body']['zones']); + $this->assertEquals([40.7128, -74.0060], $driver['body']['home']); + + $zone = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $zonesId . '/documents/zone-1', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + Query::select(['drivers.$id'])->toString() + ] + ]); + $this->assertEquals(200, $zone['headers']['status-code']); + $this->assertEquals('driver-1', $zone['body']['drivers'][0]['$id']); + + // cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $driversId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $zonesId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } } From fb82ba39518533f3d501ce81f3cc5ecb5230b1d9 Mon Sep 17 00:00:00 2001 From: Veeresh <75656445+Veera-mulge@users.noreply.github.com> Date: Tue, 26 Aug 2025 16:41:24 +0530 Subject: [PATCH 08/50] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 27d6dd9006..fe380c130e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,4 @@ -> We just announced Timestamp Overrides for Appwrite Databases - [Learn more](https://appwrite.io/blog/post/announcing-timestamp-overrides) - -> Appwrite Cloud is now Generally Available - [Learn more](https://appwrite.io/cloud-ga) +> Appwrite Databases just got the most significant update to date. We proudly present new terminology, a new TablesDB UI, and a supporting TablesDB API, all built to make working with databases simpler and faster. - [Learn more](https://appwrite.io/blog/post/announcing-appwrite-databases-new-ui) > [Get started with Appwrite](https://apwr.dev/appcloud) From 3755d58d62f3fe8fa45e064008dddb7c0fd7d7db Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 26 Aug 2025 17:07:20 +0530 Subject: [PATCH 09/50] added tests for bulk operation --- .../Databases/TablesDB/DatabasesBase.php | 952 ++++++++++++++++++ .../TablesDB/DatabasesCustomServerTest.php | 566 +++++++++++ 2 files changed, 1518 insertions(+) diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index e36543fd55..ace0778c46 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -7029,4 +7029,956 @@ trait DatabasesBase ]); $this->assertEquals(400, $inc3['headers']['status-code']); } + + public function testSpatialPointColumns(): void + { + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Point Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create table with spatial and non-spatial columns + $table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'tableId' => ID::unique(), + 'name' => 'Spatial Point Table', + 'rowSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $tableId = $table['body']['$id']; + + // Create string column + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + + // Create point column + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'location', + 'required' => true, + ]); + + $this->assertEquals(202, $response['headers']['status-code']); + + sleep(2); + + // Create row with point column + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Test Location', + 'location' => [40.7128, -74.0060] + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([40.7128, -74.0060], $response['body']['location']); + $rowId = $response['body']['$id']; + + // Read row with point column + $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([40.7128, -74.0060], $response['body']['location']); + + // Update row with new point coordinates + $response = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'location' => [40.7589, -73.9851] + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([40.7589, -73.9851], $response['body']['location']); + + // Upsert row with point column + $response = $this->client->call(Client::METHOD_PUT, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . ID::unique(), array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Upserted Location', + 'location' => [34.0522, -118.2437] + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([34.0522, -118.2437], $response['body']['location']); + + // Create row without permissions (should fail) + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Unauthorized Location', + 'location' => [0, 0] + ] + ]); + + $this->assertEquals(401, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialLineColumns(): void + { + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Line Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create table with spatial and non-spatial columns + $table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'tableId' => ID::unique(), + 'name' => 'Spatial Line Table', + 'rowSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $tableId = $table['body']['$id']; + + // Create integer column + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'distance', + 'required' => true, + ]); + + // Create line column + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/line', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'route', + 'required' => true, + ]); + + sleep(2); + + // Create row with line column + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rowId' => ID::unique(), + 'data' => [ + 'distance' => 100, + 'route' => [[40.7128, -74.0060], [40.7589, -73.9851]] + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([[40.7128, -74.0060], [40.7589, -73.9851]], $response['body']['route']); + $rowId = $response['body']['$id']; + + // Read row + $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[40.7128, -74.0060], [40.7589, -73.9851]], $response['body']['route']); + + // Update row + $response = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'route' => [[40.7128, -74.0060], [40.7589, -73.9851], [40.7505, -73.9934]] + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[40.7128, -74.0060], [40.7589, -73.9851], [40.7505, -73.9934]], $response['body']['route']); + + // Upsert row with line column + $response = $this->client->call(Client::METHOD_PUT, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . ID::unique(), array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rowId' => ID::unique(), + 'data' => [ + 'distance' => 200, + 'route' => [[34.0522, -118.2437], [34.0736, -118.2400]] + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[34.0522, -118.2437], [34.0736, -118.2400]], $response['body']['route']); + + // Delete row + $response = $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals(204, $response['headers']['status-code']); + + // Verify row is deleted + $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals(404, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialPolygonColumns(): void + { + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Polygon Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create table with spatial and non-spatial columns + $table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'tableId' => ID::unique(), + 'name' => 'Spatial Polygon Table', + 'rowSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $tableId = $table['body']['$id']; + + // Create boolean column + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/boolean', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'active', + 'required' => true, + ]); + + // Create polygon column + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'area', + 'required' => true, + ]); + + sleep(2); + + // Create row with polygon column + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rowId' => ID::unique(), + 'data' => [ + 'active' => true, + 'area' => [[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]] + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]], $response['body']['area']); + $rowId = $response['body']['$id']; + + // Read row + $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7128, -74.0060]]], $response['body']['area']); + + // Update row with new polygon + $response = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'area' => [[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7505, -73.9934], [40.7128, -74.0060]]] + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([[[40.7128, -74.0060], [40.7589, -74.0060], [40.7589, -73.9851], [40.7128, -73.9851], [40.7505, -73.9934], [40.7128, -74.0060]]], $response['body']['area']); + + // Upsert row with polygon column + $response = $this->client->call(Client::METHOD_PUT, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . ID::unique(), array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + '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]]] + ] + ]); + + $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']); + + // Create row missing required polygon (should fail) + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rowId' => ID::unique(), + 'data' => [ + 'active' => true + ] + ]); + $this->assertEquals(400, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialColumnsMixedTable(): void + { + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Mixed Spatial Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create table with multiple spatial and non-spatial columns + $table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'tableId' => ID::unique(), + 'name' => 'Mixed Spatial Table', + 'rowSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $tableId = $table['body']['$id']; + + // Create multiple columns + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'center', + 'required' => true, + ]); + + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/line', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'boundary', + 'required' => false, + ]); + + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'coverage', + 'required' => true, + ]); + + sleep(3); + + // Create row with all spatial columns + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Central Park', + 'center' => [40.7829, -73.9654], + 'boundary' => [[40.7649, -73.9814], [40.8009, -73.9494]], + 'coverage' => [[[40.7649, -73.9814], [40.8009, -73.9814], [40.8009, -73.9494], [40.7649, -73.9494], [40.7649, -73.9814]]] + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([40.7829, -73.9654], $response['body']['center']); + $this->assertEquals([[40.7649, -73.9814], [40.8009, -73.9494]], $response['body']['boundary']); + $this->assertEquals([[[40.7649, -73.9814], [40.8009, -73.9814], [40.8009, -73.9494], [40.7649, -73.9494], [40.7649, -73.9814]]], $response['body']['coverage']); + $rowId = $response['body']['$id']; + + // Update row with new spatial data + $response = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'center' => [40.7505, -73.9934], + 'boundary' => [[40.7305, -74.0134], [40.7705, -73.9734]], + 'coverage' => [[[40.7305, -74.0134], [40.7705, -74.0134], [40.7705, -73.9734], [40.7305, -73.9734], [40.7305, -74.0134]]] + ] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([40.7505, -73.9934], $response['body']['center']); + $this->assertEquals([[40.7305, -74.0134], [40.7705, -73.9734]], $response['body']['boundary']); + $this->assertEquals([[[40.7305, -74.0134], [40.7705, -74.0134], [40.7705, -73.9734], [40.7305, -73.9734], [40.7305, -74.0134]]], $response['body']['coverage']); + + // Create row with minimal required columns + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Minimal Location', + 'center' => [0, 0], + 'coverage' => [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]] + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([0, 0], $response['body']['center']); + + // Permission validation - create without user context + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Unauthorized Location', + 'center' => [0, 0], + 'coverage' => [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]] + ] + ]); + + $this->assertEquals(401, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialQuery(): void + { + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Query Test Database' + ]); + + $this->assertNotEmpty($database['body']['$id']); + $databaseId = $database['body']['$id']; + + // Create table with spatial columns + $table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'tableId' => ID::unique(), + 'name' => 'Spatial Query Table', + 'rowSecurity' => true, + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + Permission::delete(Role::any()), + Permission::update(Role::any()), + ], + ]); + + $this->assertEquals(201, $table['headers']['status-code']); + $tableId = $table['body']['$id']; + + // Create string column + $nameColumn = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + $this->assertEquals(202, $nameColumn['headers']['status-code']); + + // Create point column + $pointColumn = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'pointAttr', + 'required' => true, + ]); + $this->assertEquals(202, $pointColumn['headers']['status-code']); + + // Create line column + $lineColumn = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/line', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'lineAttr', + 'required' => true, + ]); + $this->assertEquals(202, $lineColumn['headers']['status-code']); + + // Create polygon column + $polygonColumn = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'polyAttr', + 'required' => true, + ]); + $this->assertEquals(202, $polygonColumn['headers']['status-code']); + + // Wait for columns to be created + sleep(2); + + // Create test rows with spatial data + $rows = [ + [ + '$id' => 'row1', + 'name' => 'Test Row 1', + 'pointAttr' => [6.0, 6.0], + 'lineAttr' => [[1.0, 1.0], [2.0, 2.0]], + 'polyAttr' => [[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]]] + ], + [ + '$id' => 'row2', + 'name' => 'Test Row 2', + 'pointAttr' => [7.0, 6.0], + 'lineAttr' => [[10.0, 10.0], [20.0, 20.0]], + 'polyAttr' => [[[20.0, 20.0], [30.0, 20.0], [30.0, 30.0], [20.0, 30.0], [20.0, 20.0]]] + ], + [ + '$id' => 'row3', + 'name' => 'Test Row 3', + 'pointAttr' => [25.0, 25.0], + 'lineAttr' => [[25.0, 25.0], [35.0, 35.0]], + 'polyAttr' => [[[40.0, 40.0], [50.0, 40.0], [50.0, 50.0], [40.0, 50.0], [40.0, 40.0]]] + ] + ]; + + foreach ($rows as $r) { + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rowId' => $r['$id'], + 'data' => [ + 'name' => $r['name'], + 'pointAttr' => $r['pointAttr'], + 'lineAttr' => $r['lineAttr'], + 'polyAttr' => $r['polyAttr'] + ] + ]); + $this->assertEquals(201, $response['headers']['status-code']); + } + + // Equality on non-spatial column (name) + $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::equal('name', ['Test Row 1'])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(1, $response['body']['documents']); + $this->assertEquals('row1', $response['body']['documents'][0]['$id']); + + // Polygon column queries + $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::equal('polyAttr', [[[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]]]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(1, $response['body']['documents']); + $this->assertEquals('row1', $response['body']['documents'][0]['$id']); + + // Not equal queries + $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::notEqual('pointAttr', [[6.0, 6.0]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(2, $response['body']['documents']); + + // 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']['documents']); + $this->assertEquals('row1', $response['body']['documents'][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', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [Query::notContains('polyAttr', [[15.0, 15.0]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(3, $response['body']['total']); + + // intersects on polygon (point inside row1 polygon) + $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::intersects('polyAttr', [[5.0, 5.0]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + $this->assertEquals('row1', $response['body']['documents'][0]['$id']); + + // notIntersects on polygon (point outside all polygons) + $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::notIntersects('polyAttr', [[60.0, 60.0]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(3, $response['body']['total']); + + // overlaps on polygon (polygon overlapping row1) + $overlapPoly = [[[5.0, 5.0], [12.0, 5.0], [12.0, 12.0], [5.0, 12.0], [5.0, 5.0]]]; + $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::overlaps('polyAttr', [$overlapPoly])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + $this->assertEquals('row1', $response['body']['documents'][0]['$id']); + + // notOverlaps on polygon (polygon that overlaps none) + $noOverlapPoly = [[[60.0, 60.0], [70.0, 60.0], [70.0, 70.0], [60.0, 70.0], [60.0, 60.0]]]; + $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::notOverlaps('polyAttr', [$noOverlapPoly])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(3, $response['body']['total']); + + // distance (equals) on point + $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::distance('pointAttr', [[[6.0, 6.0], 1.0]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + $this->assertEquals('row2', $response['body']['documents'][0]['$id']); + + // notDistance (outside radius) on point + $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::notDistance('pointAttr', [[[6.0, 6.0], 1.0]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(2, $response['body']['total']); + + // distanceGreaterThan + $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::distanceGreaterThan('pointAttr', [[[6.0, 6.0], 5.0]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + + // distanceLessThan + $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::distanceLessThan('pointAttr', [[[6.0, 6.0], 0.5]])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + + // crosses on line (query line crosses row1 line) + $crossLine = [[1.0, 2.0], [2.0, 1.0]]; + $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::crosses('lineAttr', [$crossLine])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + $this->assertEquals('row1', $response['body']['documents'][0]['$id']); + + // notCrosses on line (query line does not cross any stored lines) + $nonCrossLine = [[0.0, 1.0], [0.0, 2.0]]; + $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::notCrosses('lineAttr', [$nonCrossLine])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(3, $response['body']['total']); + + // touches on polygon (query polygon touches row1 polygon at corner) + $touchPoly = [[[10.0, 10.0], [20.0, 10.0], [20.0, 20.0], [10.0, 20.0], [10.0, 10.0]]]; + $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::touches('polyAttr', [$touchPoly])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(2, $response['body']['total']); + $this->assertEquals('row1', $response['body']['documents'][0]['$id']); + + // notTouches on polygon (polygon far away should not touch) + $farPoly = [[[60.0, 60.0], [70.0, 60.0], [70.0, 70.0], [60.0, 70.0], [60.0, 60.0]]]; + $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::notTouches('polyAttr', [$farPoly])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(3, $response['body']['total']); + + // Select specific columns + $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::select(['name', 'pointAttr'])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(3, $response['body']['documents']); + foreach ($response['body']['documents'] as $doc) { + $this->assertArrayHasKey('name', $doc); + $this->assertArrayHasKey('pointAttr', $doc); + $this->assertArrayNotHasKey('lineAttr', $doc); + $this->assertArrayNotHasKey('polyAttr', $doc); + } + + // Order by name + $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::orderAsc('name')->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(3, $response['body']['documents']); + $this->assertEquals('Test Row 1', $response['body']['documents'][0]['name']); + $this->assertEquals('Test Row 2', $response['body']['documents'][1]['name']); + $this->assertEquals('Test Row 3', $response['body']['documents'][2]['name']); + + // Limit results + $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::limit(2)->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(2, $response['body']['documents']); + + // Offset results + $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::offset(1)->toString(), Query::limit(2)->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(2, $response['body']['documents']); + + // Complex query with multiple conditions + $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::select(['name', 'pointAttr'])->toString(), + Query::orderAsc('name')->toString(), + Query::limit(1)->toString() + ] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(1, $response['body']['documents']); + $this->assertEquals('Test Row 1', $response['body']['documents'][0]['name']); + + // Query with no results + $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::equal('name', ['Non-existent Row'])->toString()] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(0, $response['body']['documents']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } } diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php index d987019d7a..74f8a0432d 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php @@ -6132,4 +6132,570 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'] ])); } + + public function testSpatialBulkOperations(): void + { + // Create database + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Bulk Operations Test Database' + ]); + + $this->assertNotEmpty($database['body']['$id']); + $databaseId = $database['body']['$id']; + + // Create table with spatial columns + $table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'tableId' => ID::unique(), + 'name' => 'Spatial Bulk Operations Table', + 'rowSecurity' => true, + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + Permission::delete(Role::any()), + Permission::update(Role::any()), + ], + ]); + + $this->assertEquals(201, $table['headers']['status-code']); + $tableId = $table['body']['$id']; + + // Create string column + $nameColumn = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + + $this->assertEquals(202, $nameColumn['headers']['status-code']); + + // Create point column + $pointColumn = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'location', + 'required' => true, + ]); + + $this->assertEquals(202, $pointColumn['headers']['status-code']); + + // Create polygon column + $polygonColumn = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'area', + 'required' => false, + ]); + + $this->assertEquals(202, $polygonColumn['headers']['status-code']); + + // Wait for columns to be created + sleep(2); + + // Test 1: Bulk create with spatial data + $spatialRows = []; + for ($i = 0; $i < 5; $i++) { + $spatialRows[] = [ + '$id' => ID::unique(), + 'name' => 'Location ' . $i, + 'location' => [10.0 + $i, 20.0 + $i], // POINT + 'area' => [ + [10.0 + $i, 20.0 + $i], + [11.0 + $i, 20.0 + $i], + [11.0 + $i, 21.0 + $i], + [10.0 + $i, 21.0 + $i], + [10.0 + $i, 20.0 + $i] + ] // POLYGON + ]; + } + + $response = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rows' => $spatialRows, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertCount(5, $response['body']['rows']); + + // Verify created rows have proper spatial data + foreach ($response['body']['rows'] as $index => $row) { + $this->assertNotEmpty($row['$id']); + $this->assertNotEmpty($row['name']); + $this->assertIsArray($row['location']); + $this->assertIsArray($row['area']); + $this->assertCount(2, $row['location']); // POINT has 2 coordinates + + // Check polygon structure - it might be stored as an array of arrays + if (is_array($row['area'][0])) { + $this->assertGreaterThan(1, count($row['area'][0])); // POLYGON has multiple points + } else { + $this->assertGreaterThan(1, count($row['area'])); // POLYGON has multiple points + } + + $this->assertEquals('Location ' . $index, $row['name']); + $this->assertEquals([10.0 + $index, 20.0 + $index], $row['location']); + } + + // Test 2: Bulk update with spatial data + $response = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'name' => 'Updated Location', + 'location' => [15.0, 25.0], // New POINT + 'area' => [ + [15.0, 25.0], + [16.0, 25.0], + [16.0, 26.0], + [15.0, 26.0], + [15.0, 25.0] + ] // New POLYGON + ], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(5, $response['body']['rows']); + + // Verify updated rows + foreach ($response['body']['rows'] as $row) { + $this->assertEquals('Updated Location', $row['name']); + $this->assertEquals([15.0, 25.0], $row['location']); + // The area might be stored as an array of arrays, so check the first element + $this->assertIsArray($row['area']); + if (is_array($row['area'][0])) { + // If it's an array of arrays, check the first polygon + $this->assertEquals([ + [15.0, 25.0], + [16.0, 25.0], + [16.0, 26.0], + [15.0, 26.0], + [15.0, 25.0] + ], $row['area'][0]); + } else { + // If it's a direct array, check the whole thing + $this->assertEquals([ + [15.0, 25.0], + [16.0, 25.0], + [16.0, 26.0], + [15.0, 26.0], + [15.0, 25.0] + ], $row['area']); + } + } + + // Test 3: Bulk upsert with spatial data + $upsertRows = [ + [ + '$id' => 'upsert1', + 'name' => 'Upsert Location 1', + 'location' => [30.0, 40.0], + 'area' => [ + [30.0, 40.0], + [31.0, 40.0], + [31.0, 41.0], + [30.0, 41.0], + [30.0, 40.0] + ] + ], + [ + '$id' => 'upsert2', + 'name' => 'Upsert Location 2', + 'location' => [35.0, 45.0], + 'area' => [ + [35.0, 45.0], + [36.0, 45.0], + [36.0, 46.0], + [35.0, 46.0], + [35.0, 45.0] + ] + ] + ]; + + $response = $this->client->call(Client::METHOD_PUT, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rows' => $upsertRows, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(2, $response['body']['rows']); + + // Verify upserted rows + foreach ($response['body']['rows'] as $row) { + $this->assertNotEmpty($row['$id']); + $this->assertIsArray($row['location']); + $this->assertIsArray($row['area']); + + // Verify the spatial data structure + $this->assertCount(2, $row['location']); // POINT has 2 coordinates + if (is_array($row['area'][0])) { + $this->assertGreaterThan(1, count($row['area'][0])); // POLYGON has multiple points + } else { + $this->assertGreaterThan(1, count($row['area'])); // POLYGON has multiple points + } + } + + // Test 4: Edge cases for spatial bulk operations + + // Test 4a: Invalid point coordinates (should fail) + $response = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rows' => [ + [ + '$id' => ID::unique(), + 'name' => 'Invalid Point', + 'location' => [1000.0, 2000.0], // Invalid coordinates + 'area' => [ + [10.0, 20.0], + [11.0, 20.0], + [11.0, 21.0], + [10.0, 21.0], + [10.0, 20.0] + ] + ] + ], + ]); + + // Coordinates are not validated strictly; creation should succeed + $this->assertEquals(201, $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([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rows' => [ + [ + '$id' => ID::unique(), + 'name' => 'Invalid Polygon', + 'location' => [10.0, 20.0], + 'area' => [ + [10.0, 20.0], + [11.0, 20.0] + ] + ] + ], + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + // Test 4c: Missing required location (should fail) + $response = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rows' => [ + [ + '$id' => ID::unique(), + 'name' => 'Missing Location', + // Missing required 'location' attribute + 'area' => [ + [10.0, 20.0], + [11.0, 20.0], + [11.0, 21.0], + [10.0, 21.0], + [10.0, 20.0] + ] + ] + ], + ]); + + // This should fail due to missing required attribute + $this->assertEquals(400, $response['headers']['status-code']); + + // Test 4d: Mixed valid and invalid rows in bulk (should fail) + $response = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rows' => [ + [ + '$id' => ID::unique(), + 'name' => 'Valid Row', + 'location' => [10.0, 20.0], + 'area' => [ + [10.0, 20.0], + [11.0, 20.0], + [11.0, 21.0], + [10.0, 21.0], + [10.0, 20.0] + ] + ], + [ + '$id' => ID::unique(), + 'name' => 'Invalid Row', + // Missing required 'location' attribute + 'area' => [ + [10.0, 20.0], + [11.0, 20.0], + [11.0, 21.0], + [10.0, 21.0], + [10.0, 20.0] + ] + ] + ], + ]); + + // This should fail due to mixed valid/invalid rows + $this->assertEquals(400, $response['headers']['status-code']); + + // Test 4e: Very large spatial data (stress test) + $largePolygon = []; + for ($i = 0; $i < 1000; $i++) { + $largePolygon[] = [$i * 0.001, $i * 0.001]; + } + $largePolygon[] = [0, 0]; // Close the polygon + + $response = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rows' => [ + [ + '$id' => ID::unique(), + 'name' => 'Large Polygon Test', + 'location' => [0.0, 0.0], + 'area' => $largePolygon + ] + ], + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + // Test 4f: Null values in spatial attributes (should fail) + $response = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rows' => [ + [ + '$id' => ID::unique(), + 'name' => 'Null Values Test', + 'location' => null, // Null point + 'area' => null // Null polygon + ] + ], + ]); + + // This should fail due to null values + $this->assertEquals(400, $response['headers']['status-code']); + + // Test 4g: Bulk operations with spatial data exceeding limits + $largeBulkRows = []; + for ($i = 0; $i < 100; $i++) { + $largeBulkRows[] = [ + '$id' => ID::unique(), + 'name' => 'Bulk Test ' . $i, + 'location' => [$i * 0.1, $i * 0.1], + 'area' => [ + [$i * 0.1, $i * 0.1], + [($i + 1) * 0.1, $i * 0.1], + [($i + 1) * 0.1, ($i + 1) * 0.1], + [$i * 0.1, ($i + 1) * 0.1], + [$i * 0.1, $i * 0.1] + ] + ]; + } + + $response = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rows' => $largeBulkRows, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialBulkOperationsWithLineStrings(): void + { + // Create database + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial LineString Bulk Operations Test Database' + ]); + + $this->assertNotEmpty($database['body']['$id']); + $databaseId = $database['body']['$id']; + + // Create table with line string columns + $table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'tableId' => ID::unique(), + 'name' => 'Spatial LineString Bulk Operations Table', + 'rowSecurity' => true, + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + Permission::delete(Role::any()), + Permission::update(Role::any()), + ], + ]); + + $this->assertEquals(201, $table['headers']['status-code']); + $tableId = $table['body']['$id']; + + // Create string column + $nameColumn = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + + $this->assertEquals(202, $nameColumn['headers']['status-code']); + + // Create line string column + $lineColumn = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/line', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'path', + 'required' => true, + ]); + + // Handle both 201 (created) and 202 (accepted) status codes + $this->assertEquals(202, $lineColumn['headers']['status-code']); + + // Wait for columns to be created + sleep(2); + + // Test bulk create with line string data + $lineStringRows = []; + for ($i = 0; $i < 3; $i++) { + $lineStringRows[] = [ + '$id' => ID::unique(), + 'name' => 'Path ' . $i, + 'path' => [ + [$i * 10, $i * 10], + [($i + 1) * 10, ($i + 1) * 10], + [($i + 2) * 10, ($i + 2) * 10] + ] // LINE STRING with 3 points + ]; + } + + $response = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rows' => $lineStringRows, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertCount(3, $response['body']['rows']); + + // Verify created rows have proper line string data + foreach ($response['body']['rows'] as $index => $row) { + $this->assertNotEmpty($row['$id']); + $this->assertNotEmpty($row['name']); + $this->assertIsArray($row['path']); + $this->assertGreaterThan(1, count($row['path'])); // LINE STRING has multiple points + $this->assertEquals('Path ' . $index, $row['name']); + $this->assertCount(3, $row['path']); // Each line string has 3 points + } + + // Test bulk update with line string data + $response = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'name' => 'Updated Path', + 'path' => [ + [0, 0], + [50, 50], + [100, 100] + ] // New LINE STRING + ], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(3, $response['body']['rows']); + + // Verify updated rows + foreach ($response['body']['rows'] as $row) { + $this->assertEquals('Updated Path', $row['name']); + $this->assertEquals([ + [0, 0], + [50, 50], + [100, 100] + ], $row['path']); + } + + // Test: Invalid line string (single point - should fail) + $response = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rows' => [ + [ + '$id' => ID::unique(), + 'name' => 'Invalid Line String', + 'path' => [[10, 20]] // Single point - invalid line string + ] + ], + ]); + + // Single point linestrings are accepted as arrays; creation should succeed + $this->assertEquals(201, $response['headers']['status-code']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } } From ca2bdc1cd2c66b58d63907aa575654fb3eb2e64b Mon Sep 17 00:00:00 2001 From: Veeresh <75656445+Veera-mulge@users.noreply.github.com> Date: Tue, 26 Aug 2025 17:41:49 +0530 Subject: [PATCH 10/50] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fe380c130e..c210784737 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -> Appwrite Databases just got the most significant update to date. We proudly present new terminology, a new TablesDB UI, and a supporting TablesDB API, all built to make working with databases simpler and faster. - [Learn more](https://appwrite.io/blog/post/announcing-appwrite-databases-new-ui) +> We just announced a brand new TablesDB UI for Appwrite Databases - [Learn more](https://appwrite.io/blog/post/announcing-appwrite-databases-new-ui) + +> Appwrite Cloud is now Generally Available - [Learn more](https://appwrite.io/cloud-ga) > [Get started with Appwrite](https://apwr.dev/appcloud) From b28ec182d795b2828e5e07acfa1682849cd820e1 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 26 Aug 2025 20:54:55 +0530 Subject: [PATCH 11/50] added spatial index tests --- .../Databases/Collections/Indexes/Create.php | 26 ++++- .../Http/TablesDB/Tables/Indexes/Create.php | 2 +- .../Databases/Legacy/DatabasesBase.php | 100 ++++++++++++++++++ .../Databases/TablesDB/DatabasesBase.php | 100 ++++++++++++++++++ 4 files changed, 223 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php index 04baa093d8..93f095e1dd 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php @@ -71,7 +71,7 @@ class Create extends Action ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', null, new Key(), 'Index Key.') - ->param('type', null, new WhiteList([Database::INDEX_KEY, Database::INDEX_FULLTEXT, Database::INDEX_UNIQUE]), 'Index type.') + ->param('type', null, new WhiteList([Database::INDEX_KEY, Database::INDEX_FULLTEXT, Database::INDEX_UNIQUE, Database::INDEX_SPATIAL]), 'Index type.') ->param('attributes', null, new ArrayList(new Key(true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of attributes to index. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' attributes are allowed, each 32 characters long.') ->param('orders', [], new ArrayList(new WhiteList(['ASC', 'DESC'], false, Database::VAR_STRING), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of index orders. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' orders are allowed.', true) ->param('lengths', [], new ArrayList(new Nullable(new Integer()), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Length of index. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE, optional: true) @@ -190,11 +190,29 @@ class Create extends Action 'orders' => $orders, ]); + // Determine adapter capabilities. For TablesDB, be permissive to accept requests + // and let the background worker enforce engine-specific constraints. + $maxIndexLength = $dbForProject->getAdapter()->getMaxIndexLength(); + $internalIndexesKeys = $dbForProject->getAdapter()->getInternalIndexesKeys(); + $supportForIndexArray = $dbForProject->getAdapter()->getSupportForIndexArray(); + $supportForSpatialAttributes = $dbForProject->getAdapter()->getSupportForSpatialAttributes(); + $supportForSpatialIndexNull = $dbForProject->getAdapter()->getSupportForSpatialIndexNull(); + $supportForSpatialIndexOrder = $dbForProject->getAdapter()->getSupportForSpatialIndexOrder(); + + if (!$this->isCollectionsAPI()) { + // Relax spatial constraints for TablesDB API + $supportForSpatialIndexNull = true; + $supportForSpatialIndexOrder = true; + } + $validator = new IndexValidator( $collection->getAttribute('attributes'), - $dbForProject->getAdapter()->getMaxIndexLength(), - $dbForProject->getAdapter()->getInternalIndexesKeys(), - $dbForProject->getAdapter()->getSupportForIndexArray() + $maxIndexLength, + $internalIndexesKeys, + $supportForIndexArray, + $supportForSpatialAttributes, + $supportForSpatialIndexNull, + $supportForSpatialIndexOrder ); if (!$validator->isValid($index)) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Create.php index 34d594bebd..dbcdbc90d1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Create.php @@ -58,7 +58,7 @@ class Create extends IndexCreate ->param('databaseId', '', new UID(), 'Database ID.') ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', null, new Key(), 'Index Key.') - ->param('type', null, new WhiteList([Database::INDEX_KEY, Database::INDEX_FULLTEXT, Database::INDEX_UNIQUE]), 'Index type.') + ->param('type', null, new WhiteList([Database::INDEX_KEY, Database::INDEX_FULLTEXT, Database::INDEX_UNIQUE, Database::INDEX_SPATIAL]), 'Index type.') ->param('columns', null, new ArrayList(new Key(true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of columns to index. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' columns are allowed, each 32 characters long.') ->param('orders', [], new ArrayList(new WhiteList(['ASC', 'DESC'], false, Database::VAR_STRING), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of index orders. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' orders are allowed.', true) ->param('lengths', [], new ArrayList(new Nullable(new Integer()), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Length of index. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE, optional: true) diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php index c046a3f588..ede9abf658 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -7261,4 +7261,104 @@ trait DatabasesBase 'x-appwrite-key' => $this->getProject()['apiKey'] ])); } + + public function testSpatialIndex(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Index Test DB' + ]); + $this->assertEquals(201, $database['headers']['status-code']); + $databaseId = $database['body']['$id']; + + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'SpatialIdx', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + ]); + $this->assertEquals(201, $collection['headers']['status-code']); + $collectionId = $collection['body']['$id']; + + // Create spatial attributes: one required, one optional + $reqPoint = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'pRequired', + 'required' => true, + ]); + $this->assertEquals(202, $reqPoint['headers']['status-code']); + + $optPoint = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'pOptional', + 'required' => false, + ]); + $this->assertEquals(202, $optPoint['headers']['status-code']); + + // Ensure attributes are available + sleep(2); + + // Create index on required spatial attribute (should succeed) + $okIndex = $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', + 'type' => Database::INDEX_SPATIAL, + 'attributes' => ['pRequired'], + ]); + $this->assertEquals(202, $okIndex['headers']['status-code']); + + // Create index on optional spatial attribute (should fail in case of mariadb) + $badIndex = $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_optional_point', + 'type' => Database::INDEX_SPATIAL, + 'attributes' => ['pOptional'], + ]); + $this->assertEquals(400, $badIndex['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', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } } diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index ace0778c46..8c0670e191 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -7969,6 +7969,106 @@ trait DatabasesBase $this->assertEquals(200, $response['headers']['status-code']); $this->assertCount(0, $response['body']['documents']); + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + + public function testSpatialIndex(): void + { + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Index Test DB' + ]); + $this->assertEquals(201, $database['headers']['status-code']); + $databaseId = $database['body']['$id']; + + $table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'tableId' => ID::unique(), + 'name' => 'SpatialIdx', + 'rowSecurity' => true, + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + ]); + $this->assertEquals(201, $table['headers']['status-code']); + $tableId = $table['body']['$id']; + + // Create spatial columns: one required, one optional + $reqPoint = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'pRequired', + 'required' => true, + ]); + $this->assertEquals(202, $reqPoint['headers']['status-code']); + + $optPoint = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'pOptional', + 'required' => false, + ]); + $this->assertEquals(202, $optPoint['headers']['status-code']); + + // Ensure columns are available + sleep(2); + + // Create index on required spatial column (should succeed) + $okIndex = $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', + 'type' => Database::INDEX_SPATIAL, + 'columns' => ['pRequired'], + ]); + $this->assertEquals(202, $okIndex['headers']['status-code']); + + // Create index on optional spatial column (should fail in case of mariadb) + $badIndex = $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_optional_point', + 'type' => Database::INDEX_SPATIAL, + 'columns' => ['pOptional'], + ]); + $this->assertEquals(202, $badIndex['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', From 0aee34185a3b8b19f5cfd3b7efafc3cdeabcda81 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 26 Aug 2025 21:11:30 +0530 Subject: [PATCH 12/50] updated distance queries --- composer.json | 8 +- composer.lock | 87 ++++++++++++++----- .../Databases/Legacy/DatabasesBase.php | 8 +- .../Databases/TablesDB/DatabasesBase.php | 54 ++++++------ 4 files changed, 101 insertions(+), 56 deletions(-) diff --git a/composer.json b/composer.json index 0c662c775f..cb8ac9c744 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,12 @@ "Appwrite\\Tests\\": "tests/extensions" } }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/ArnabChatterjee20k/php-utopia-database.git" + } + ], "require": { "php": ">=8.3.0", "ext-curl": "*", @@ -52,7 +58,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-attribute-support as 1.1.6", "utopia-php/detector": "0.1.*", "utopia-php/domains": "0.8.*", "utopia-php/dns": "0.3.*", diff --git a/composer.lock b/composer.lock index 3b0d7e724a..d36f3cc2b9 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": "0da713ee5642eba1d30bc51c1a04a723", + "content-hash": "cc71910a644cb4707dcf1b9503acc458", "packages": [ { "name": "adhocore/jwt", @@ -3557,16 +3557,16 @@ }, { "name": "utopia-php/database", - "version": "1.1.0", + "version": "dev-spatial-attribute-support", "source": { "type": "git", - "url": "https://github.com/utopia-php/database.git", - "reference": "670e8efe7fb91f0fe43570caa5db97a1a5223357" + "url": "https://github.com/ArnabChatterjee20k/php-utopia-database.git", + "reference": "88998edfc808821fc0c04883b922335ae090e5b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/670e8efe7fb91f0fe43570caa5db97a1a5223357", - "reference": "670e8efe7fb91f0fe43570caa5db97a1a5223357", + "url": "https://api.github.com/repos/ArnabChatterjee20k/php-utopia-database/zipball/88998edfc808821fc0c04883b922335ae090e5b5", + "reference": "88998edfc808821fc0c04883b922335ae090e5b5", "shasum": "" }, "require": { @@ -3593,7 +3593,38 @@ "Utopia\\Database\\": "src/Database" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "Tests\\E2E\\": "tests/e2e", + "Tests\\Unit\\": "tests/unit" + } + }, + "scripts": { + "build": [ + "Composer\\Config::disableProcessTimeout", + "docker compose build" + ], + "start": [ + "Composer\\Config::disableProcessTimeout", + "docker compose up -d" + ], + "test": [ + "Composer\\Config::disableProcessTimeout", + "docker compose exec tests vendor/bin/phpunit --configuration phpunit.xml" + ], + "lint": [ + "php -d memory_limit=2G ./vendor/bin/pint --test" + ], + "format": [ + "php -d memory_limit=2G ./vendor/bin/pint" + ], + "check": [ + "./vendor/bin/phpstan analyse --level 7 src tests --memory-limit 2G" + ], + "coverage": [ + "./vendor/bin/coverage-check ./tmp/clover.xml 90" + ] + }, "license": [ "MIT" ], @@ -3606,10 +3637,9 @@ "utopia" ], "support": { - "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/1.1.0" + "source": "https://github.com/ArnabChatterjee20k/php-utopia-database/tree/spatial-attribute-support" }, - "time": "2025-08-21T15:37:11+00:00" + "time": "2025-08-26T15:18:37+00:00" }, { "name": "utopia-php/detector", @@ -3861,16 +3891,16 @@ }, { "name": "utopia-php/framework", - "version": "0.33.21", + "version": "0.33.22", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "eb0e82e90b8fa493f99b8d131bdd25173422c493" + "reference": "c01a815cb976c9255e045fc3bcc3f5fcf477e0bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/eb0e82e90b8fa493f99b8d131bdd25173422c493", - "reference": "eb0e82e90b8fa493f99b8d131bdd25173422c493", + "url": "https://api.github.com/repos/utopia-php/http/zipball/c01a815cb976c9255e045fc3bcc3f5fcf477e0bc", + "reference": "c01a815cb976c9255e045fc3bcc3f5fcf477e0bc", "shasum": "" }, "require": { @@ -3902,9 +3932,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.21" + "source": "https://github.com/utopia-php/http/tree/0.33.22" }, - "time": "2025-08-19T10:52:15+00:00" + "time": "2025-08-26T10:29:50+00:00" }, { "name": "utopia-php/image", @@ -4926,16 +4956,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.1.4", + "version": "1.1.14", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "4196a50d4cd847e2d7f8dd1136fc0ee96e931043" + "reference": "662c7a53e683ed941c7d1374cfd32533bf54fbca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/4196a50d4cd847e2d7f8dd1136fc0ee96e931043", - "reference": "4196a50d4cd847e2d7f8dd1136fc0ee96e931043", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/662c7a53e683ed941c7d1374cfd32533bf54fbca", + "reference": "662c7a53e683ed941c7d1374cfd32533bf54fbca", "shasum": "" }, "require": { @@ -4971,9 +5001,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/1.1.4" + "source": "https://github.com/appwrite/sdk-generator/tree/1.1.14" }, - "time": "2025-08-21T09:46:01+00:00" + "time": "2025-08-26T13:17:07+00:00" }, { "name": "doctrine/annotations", @@ -8425,9 +8455,18 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-spatial-attribute-support", + "alias": "1.1.6", + "alias_normalized": "1.1.6.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 ede9abf658..cb1244aad3 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -6563,7 +6563,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [Query::distance('pointAttr', [[[6.0, 6.0], 1.0]])->toString()] + 'queries' => [Query::distanceEqual('pointAttr', [6.0, 6.0], 1.0)->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['total']); @@ -6574,7 +6574,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [Query::notDistance('pointAttr', [[[6.0, 6.0], 1.0]])->toString()] + 'queries' => [Query::distanceNotEqual('pointAttr', [6.0, 6.0], 1.0)->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(2, $response['body']['total']); @@ -6584,7 +6584,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [Query::distanceGreaterThan('pointAttr', [[[6.0, 6.0], 5.0]])->toString()] + 'queries' => [Query::distanceGreaterThan('pointAttr', [6.0, 6.0], 5.0)->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['total']); @@ -6594,7 +6594,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [Query::distanceLessThan('pointAttr', [[[6.0, 6.0], 0.5]])->toString()] + 'queries' => [Query::distanceLessThan('pointAttr', [6.0, 6.0], 0.5)->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['total']); diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index 8c0670e191..2e83719909 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -7719,8 +7719,8 @@ trait DatabasesBase 'queries' => [Query::equal('name', ['Test Row 1'])->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(1, $response['body']['documents']); - $this->assertEquals('row1', $response['body']['documents'][0]['$id']); + $this->assertCount(1, $response['body']['rows']); + $this->assertEquals('row1', $response['body']['rows'][0]['$id']); // Polygon column queries $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ @@ -7730,8 +7730,8 @@ trait DatabasesBase 'queries' => [Query::equal('polyAttr', [[[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]]]])->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(1, $response['body']['documents']); - $this->assertEquals('row1', $response['body']['documents'][0]['$id']); + $this->assertCount(1, $response['body']['rows']); + $this->assertEquals('row1', $response['body']['rows'][0]['$id']); // Not equal queries $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ @@ -7741,7 +7741,7 @@ trait DatabasesBase 'queries' => [Query::notEqual('pointAttr', [[6.0, 6.0]])->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(2, $response['body']['documents']); + $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([ @@ -7751,8 +7751,8 @@ trait DatabasesBase 'queries' => [Query::contains('lineAttr', [[1.0, 1.0]])->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(1, $response['body']['documents']); - $this->assertEquals('row1', $response['body']['documents'][0]['$id']); + $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([ @@ -7773,7 +7773,7 @@ trait DatabasesBase ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['total']); - $this->assertEquals('row1', $response['body']['documents'][0]['$id']); + $this->assertEquals('row1', $response['body']['rows'][0]['$id']); // notIntersects on polygon (point outside all polygons) $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ @@ -7795,7 +7795,7 @@ trait DatabasesBase ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['total']); - $this->assertEquals('row1', $response['body']['documents'][0]['$id']); + $this->assertEquals('row1', $response['body']['rows'][0]['$id']); // notOverlaps on polygon (polygon that overlaps none) $noOverlapPoly = [[[60.0, 60.0], [70.0, 60.0], [70.0, 70.0], [60.0, 70.0], [60.0, 60.0]]]; @@ -7813,18 +7813,18 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [Query::distance('pointAttr', [[[6.0, 6.0], 1.0]])->toString()] + 'queries' => [Query::distanceEqual('pointAttr', [6.0, 6.0], 1.0)->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['total']); - $this->assertEquals('row2', $response['body']['documents'][0]['$id']); + $this->assertEquals('row2', $response['body']['rows'][0]['$id']); // notDistance (outside radius) on point $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::notDistance('pointAttr', [[[6.0, 6.0], 1.0]])->toString()] + 'queries' => [Query::distanceNotEqual('pointAttr', [6.0, 6.0], 1.0)->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(2, $response['body']['total']); @@ -7834,7 +7834,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [Query::distanceGreaterThan('pointAttr', [[[6.0, 6.0], 5.0]])->toString()] + 'queries' => [Query::distanceGreaterThan('pointAttr', [6.0, 6.0], 5.0)->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['total']); @@ -7844,7 +7844,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [Query::distanceLessThan('pointAttr', [[[6.0, 6.0], 0.5]])->toString()] + 'queries' => [Query::distanceLessThan('pointAttr', [6.0, 6.0], 0.5)->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['total']); @@ -7859,7 +7859,7 @@ trait DatabasesBase ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['total']); - $this->assertEquals('row1', $response['body']['documents'][0]['$id']); + $this->assertEquals('row1', $response['body']['rows'][0]['$id']); // notCrosses on line (query line does not cross any stored lines) $nonCrossLine = [[0.0, 1.0], [0.0, 2.0]]; @@ -7882,7 +7882,7 @@ trait DatabasesBase ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(2, $response['body']['total']); - $this->assertEquals('row1', $response['body']['documents'][0]['$id']); + $this->assertEquals('row1', $response['body']['rows'][0]['$id']); // notTouches on polygon (polygon far away should not touch) $farPoly = [[[60.0, 60.0], [70.0, 60.0], [70.0, 70.0], [60.0, 70.0], [60.0, 60.0]]]; @@ -7903,8 +7903,8 @@ trait DatabasesBase 'queries' => [Query::select(['name', 'pointAttr'])->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(3, $response['body']['documents']); - foreach ($response['body']['documents'] as $doc) { + $this->assertCount(3, $response['body']['rows']); + foreach ($response['body']['rows'] as $doc) { $this->assertArrayHasKey('name', $doc); $this->assertArrayHasKey('pointAttr', $doc); $this->assertArrayNotHasKey('lineAttr', $doc); @@ -7919,10 +7919,10 @@ trait DatabasesBase 'queries' => [Query::orderAsc('name')->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(3, $response['body']['documents']); - $this->assertEquals('Test Row 1', $response['body']['documents'][0]['name']); - $this->assertEquals('Test Row 2', $response['body']['documents'][1]['name']); - $this->assertEquals('Test Row 3', $response['body']['documents'][2]['name']); + $this->assertCount(3, $response['body']['rows']); + $this->assertEquals('Test Row 1', $response['body']['rows'][0]['name']); + $this->assertEquals('Test Row 2', $response['body']['rows'][1]['name']); + $this->assertEquals('Test Row 3', $response['body']['rows'][2]['name']); // Limit results $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ @@ -7932,7 +7932,7 @@ trait DatabasesBase 'queries' => [Query::limit(2)->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(2, $response['body']['documents']); + $this->assertCount(2, $response['body']['rows']); // Offset results $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ @@ -7942,7 +7942,7 @@ trait DatabasesBase 'queries' => [Query::offset(1)->toString(), Query::limit(2)->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(2, $response['body']['documents']); + $this->assertCount(2, $response['body']['rows']); // Complex query with multiple conditions $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ @@ -7956,8 +7956,8 @@ trait DatabasesBase ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(1, $response['body']['documents']); - $this->assertEquals('Test Row 1', $response['body']['documents'][0]['name']); + $this->assertCount(1, $response['body']['rows']); + $this->assertEquals('Test Row 1', $response['body']['rows'][0]['name']); // Query with no results $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ @@ -7967,7 +7967,7 @@ trait DatabasesBase 'queries' => [Query::equal('name', ['Non-existent Row'])->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(0, $response['body']['documents']); + $this->assertCount(0, $response['body']['rows']); // Cleanup $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId, array_merge([ From 0d41d8b6c0dee90e7f8863fdd6d082837e1da99f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 26 Aug 2025 21:30:36 +0530 Subject: [PATCH 13/50] empty commit From 67903fcf085f555a664092e966d46390b9ed3047 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 26 Aug 2025 21:48:22 +0530 Subject: [PATCH 14/50] updated composer --- composer.json | 8 +------ composer.lock | 60 +++++++++------------------------------------------ 2 files changed, 11 insertions(+), 57 deletions(-) diff --git a/composer.json b/composer.json index cb8ac9c744..0c662c775f 100644 --- a/composer.json +++ b/composer.json @@ -30,12 +30,6 @@ "Appwrite\\Tests\\": "tests/extensions" } }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/ArnabChatterjee20k/php-utopia-database.git" - } - ], "require": { "php": ">=8.3.0", "ext-curl": "*", @@ -58,7 +52,7 @@ "utopia-php/cache": "0.13.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "dev-spatial-attribute-support as 1.1.6", + "utopia-php/database": "1.*", "utopia-php/detector": "0.1.*", "utopia-php/domains": "0.8.*", "utopia-php/dns": "0.3.*", diff --git a/composer.lock b/composer.lock index 23d21b2713..79dfc9372a 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": "cc71910a644cb4707dcf1b9503acc458", + "content-hash": "0da713ee5642eba1d30bc51c1a04a723", "packages": [ { "name": "adhocore/jwt", @@ -3557,16 +3557,16 @@ }, { "name": "utopia-php/database", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "653e19d26c5607b9dce917c50737824772cd3dd8" + "reference": "99beaf1dd6dc3561c8332f9893325777553644a4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/653e19d26c5607b9dce917c50737824772cd3dd8", - "reference": "653e19d26c5607b9dce917c50737824772cd3dd8", + "url": "https://api.github.com/repos/utopia-php/database/zipball/99beaf1dd6dc3561c8332f9893325777553644a4", + "reference": "99beaf1dd6dc3561c8332f9893325777553644a4", "shasum": "" }, "require": { @@ -3593,38 +3593,7 @@ "Utopia\\Database\\": "src/Database" } }, - "autoload-dev": { - "psr-4": { - "Tests\\E2E\\": "tests/e2e", - "Tests\\Unit\\": "tests/unit" - } - }, - "scripts": { - "build": [ - "Composer\\Config::disableProcessTimeout", - "docker compose build" - ], - "start": [ - "Composer\\Config::disableProcessTimeout", - "docker compose up -d" - ], - "test": [ - "Composer\\Config::disableProcessTimeout", - "docker compose exec tests vendor/bin/phpunit --configuration phpunit.xml" - ], - "lint": [ - "php -d memory_limit=2G ./vendor/bin/pint --test" - ], - "format": [ - "php -d memory_limit=2G ./vendor/bin/pint" - ], - "check": [ - "./vendor/bin/phpstan analyse --level 7 src tests --memory-limit 2G" - ], - "coverage": [ - "./vendor/bin/coverage-check ./tmp/clover.xml 90" - ] - }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -3638,9 +3607,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/1.2.0" + "source": "https://github.com/utopia-php/database/tree/1.2.1" }, - "time": "2025-08-26T12:51:42+00:00" + "time": "2025-08-26T16:05:26+00:00" }, { "name": "utopia-php/detector", @@ -8456,18 +8425,9 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [ - { - "package": "utopia-php/database", - "version": "dev-spatial-attribute-support", - "alias": "1.1.6", - "alias_normalized": "1.1.6.0" - } - ], + "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "utopia-php/database": 20 - }, + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { From a1be47e669e1b479670fc920663ea1a93c8e4a5b Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 27 Aug 2025 10:17:29 +0530 Subject: [PATCH 15/50] linting fix --- src/Appwrite/Utopia/Request/Filters/V20.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Request/Filters/V20.php b/src/Appwrite/Utopia/Request/Filters/V20.php index 939eeeabe7..30de1fb2d3 100644 --- a/src/Appwrite/Utopia/Request/Filters/V20.php +++ b/src/Appwrite/Utopia/Request/Filters/V20.php @@ -52,7 +52,7 @@ class V20 extends Filter if (empty($selections)) { $hasWildcard = true; $parsed[] = Query::select(['*']); - } else if (!$hasWildcard) { + } elseif (!$hasWildcard) { // check if any select includes a wildcard as we added one above foreach ($selections as $select) { if (\in_array('*', $select->getValues(), true)) { From 7a4929a51f369ada8c036a9c899208a5b0769d5f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 27 Aug 2025 16:30:25 +0530 Subject: [PATCH 16/50] added update and default cases for the spatial attributes endpoints --- .../Collections/Attributes/Action.php | 2 +- .../Collections/Attributes/Line/Create.php | 14 +- .../Collections/Attributes/Line/Update.php | 11 +- .../Collections/Attributes/Point/Create.php | 14 +- .../Collections/Attributes/Point/Update.php | 10 +- .../Collections/Attributes/Polygon/Create.php | 14 +- .../Collections/Attributes/Polygon/Update.php | 8 +- .../TablesDB/Tables/Columns/Line/Create.php | 10 +- .../TablesDB/Tables/Columns/Line/Update.php | 67 ++++++++ .../TablesDB/Tables/Columns/Point/Create.php | 10 +- .../TablesDB/Tables/Columns/Point/Update.php | 67 ++++++++ .../Tables/Columns/Polygon/Create.php | 10 +- .../Tables/Columns/Polygon/Update.php | 67 ++++++++ .../Databases/Services/Registry/Tables.php | 6 + .../Databases/Legacy/DatabasesBase.php | 159 ++++++++++++++++++ .../Databases/TablesDB/DatabasesBase.php | 159 ++++++++++++++++++ 16 files changed, 590 insertions(+), 38 deletions(-) create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index 948a993424..ccf886b029 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -446,7 +446,7 @@ abstract class Action extends UtopiaAction return $attribute; } - protected function updateAttribute(string $databaseId, string $collectionId, string $key, Database $dbForProject, Event $queueForEvents, string $type, int $size = null, string $filter = null, string|bool|int|float $default = null, bool $required = null, int|float|null $min = null, int|float|null $max = null, array $elements = null, array $options = [], string $newKey = null): Document + protected function updateAttribute(string $databaseId, string $collectionId, string $key, Database $dbForProject, Event $queueForEvents, string $type, int $size = null, string $filter = null, string|bool|int|float|array $default = null, bool $required = null, int|float|null $min = null, int|float|null $max = null, array $elements = null, array $options = [], string $newKey = null): Document { $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php index 56bb0e40cb..f1ab5673b1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php @@ -15,7 +15,9 @@ use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; -use Utopia\Validator\Text; +use Utopia\Validator\Boolean; +use Utopia\Validator\JSON; +use Utopia\Validator\Nullable; class Create extends Action { @@ -61,9 +63,9 @@ class Create extends Action ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', '', new Key(), 'Attribute Key.') - ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') - ->param('default', null, new Text(0, 0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true) - ->param('array', false, new \Utopia\Validator\Boolean(), 'Is attribute an array?', true) + ->param('required', null, new Boolean(), 'Is attribute required?') + ->param('default', null, new Nullable(new JSON()), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) + ->param('array', false, new Boolean(), 'Is attribute an array?', true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') @@ -73,12 +75,14 @@ class Create extends Action public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void { + $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; + $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, 'type' => Database::VAR_LINESTRING, 'size' => 0, 'required' => $required, - 'default' => $default, + 'default' => $decodedDefault, 'array' => $array, ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php index 90609977c0..2ffc6f7d3f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php @@ -14,8 +14,9 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; +use Utopia\Validator\Boolean; +use Utopia\Validator\JSON; use Utopia\Validator\Nullable; -use Utopia\Validator\Text; class Update extends Action { @@ -62,8 +63,8 @@ class Update extends Action ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).') ->param('key', '', new Key(), 'Attribute Key.') - ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new Text(0, 0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.') + ->param('required', null, new Boolean(), 'Is attribute required?') + ->param('default', null, new Nullable(new JSON()), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.') ->param('newKey', null, new Key(), 'New attribute key.', true) ->inject('response') ->inject('dbForProject') @@ -73,6 +74,8 @@ class Update extends Action public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void { + $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; + $attribute = $this->updateAttribute( databaseId: $databaseId, collectionId: $collectionId, @@ -80,7 +83,7 @@ class Update extends Action dbForProject: $dbForProject, queueForEvents: $queueForEvents, type: Database::VAR_LINESTRING, - default: $default, + default: $decodedDefault, required: $required, newKey: $newKey ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php index 3807bdc174..0a6e486f88 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php @@ -15,7 +15,9 @@ use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; -use Utopia\Validator\Text; +use Utopia\Validator\Boolean; +use Utopia\Validator\JSON; +use Utopia\Validator\Nullable; class Create extends Action { @@ -61,9 +63,9 @@ class Create extends Action ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', '', new Key(), 'Attribute Key.') - ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') - ->param('default', null, new Text(0, 0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true) - ->param('array', false, new \Utopia\Validator\Boolean(), 'Is attribute an array?', true) + ->param('required', null, new Boolean(), 'Is attribute required?') + ->param('default', null, new Nullable(new JSON()), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) + ->param('array', false, new Boolean(), 'Is attribute an array?', true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') @@ -73,12 +75,14 @@ class Create extends Action public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void { + $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; + $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, 'type' => Database::VAR_POINT, 'size' => 0, 'required' => $required, - 'default' => $default, + 'default' => $decodedDefault, 'array' => $array, ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php index f276256cf4..3113ff7014 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php @@ -14,6 +14,8 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; +use Utopia\Validator\Boolean; +use Utopia\Validator\JSON; use Utopia\Validator\Nullable; class Update extends Action @@ -61,8 +63,8 @@ class Update extends Action ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).') ->param('key', '', new Key(), 'Attribute Key.') - ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new \Utopia\Validator\Text(0, 0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.') + ->param('required', null, new Boolean(), 'Is attribute required?') + ->param('default', null, new Nullable(new JSON()), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.') ->param('newKey', null, new Key(), 'New attribute key.', true) ->inject('response') ->inject('dbForProject') @@ -72,6 +74,8 @@ class Update extends Action public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void { + $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; + $attribute = $this->updateAttribute( databaseId: $databaseId, collectionId: $collectionId, @@ -79,7 +83,7 @@ class Update extends Action dbForProject: $dbForProject, queueForEvents: $queueForEvents, type: Database::VAR_POINT, - default: $default, + default: $decodedDefault, required: $required, newKey: $newKey ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php index 56c4b4af2e..9a4d534c17 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php @@ -15,7 +15,9 @@ use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; -use Utopia\Validator\Text; +use Utopia\Validator\Boolean; +use Utopia\Validator\JSON; +use Utopia\Validator\Nullable; class Create extends Action { @@ -61,9 +63,9 @@ class Create extends Action ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', '', new Key(), 'Attribute Key.') - ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') - ->param('default', null, new Text(0, 0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true) - ->param('array', false, new \Utopia\Validator\Boolean(), 'Is attribute an array?', true) + ->param('required', null, new Boolean(), 'Is attribute required?') + ->param('default', null, new Nullable(new JSON()), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) + ->param('array', false, new Boolean(), 'Is attribute an array?', true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') @@ -73,12 +75,14 @@ class Create extends Action public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void { + $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; + $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, 'type' => Database::VAR_POLYGON, 'size' => 0, 'required' => $required, - 'default' => $default, + 'default' => $decodedDefault, 'array' => $array, ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php index 90d0960f41..8f41630ba4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php @@ -14,8 +14,8 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; +use Utopia\Validator\JSON; use Utopia\Validator\Nullable; -use Utopia\Validator\Text; class Update extends Action { @@ -63,7 +63,7 @@ class Update extends Action ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new Text(0, 0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.') + ->param('default', null, new Nullable(new JSON()), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.') ->param('newKey', null, new Key(), 'New attribute key.', true) ->inject('response') ->inject('dbForProject') @@ -73,6 +73,8 @@ class Update extends Action public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void { + $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; + $attribute = $this->updateAttribute( databaseId: $databaseId, collectionId: $collectionId, @@ -80,7 +82,7 @@ class Update extends Action dbForProject: $dbForProject, queueForEvents: $queueForEvents, type: Database::VAR_POLYGON, - default: $default, + default: $decodedDefault, required: $required, newKey: $newKey ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php index d8d1fefc11..6df33e8f96 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php @@ -10,7 +10,9 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; -use Utopia\Validator\Text; +use Utopia\Validator\Boolean; +use Utopia\Validator\JSON; +use Utopia\Validator\Nullable; class Create extends LineCreate { @@ -52,9 +54,9 @@ class Create extends LineCreate ->param('databaseId', '', new UID(), 'Database ID.') ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') - ->param('required', null, new \Utopia\Validator\Boolean(), 'Is column required?') - ->param('default', null, new Text(0, 0), 'Default value for column when not provided. Cannot be set when column is required.', true) - ->param('array', false, new \Utopia\Validator\Boolean(), 'Is column an array?', true) + ->param('required', null, new Boolean(), 'Is column required?') + ->param('default', null, new Nullable(new JSON()), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) + ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php new file mode 100644 index 0000000000..4360d85bfe --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php @@ -0,0 +1,67 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/line/:key') + ->desc('Update line column') + ->groups(['api', 'database', 'schema']) + ->label('scope', 'tables.write') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].update') + ->label('audits.event', 'column.update') + ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') + ->label('sdk', new Method( + namespace: $this->getSdkNamespace(), + group: $this->getSdkGroup(), + name: self::getName(), + description: '/docs/references/tablesdb/update-line-column.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: $this->getResponseModel(), + ) + ], + contentType: ContentType::JSON + )) + ->param('databaseId', '', new UID(), 'Database ID.') + ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') + ->param('key', '', new Key(), 'Column Key.') + ->param('required', null, new Boolean(), 'Is column required?') + ->param('default', null, new Nullable(new JSON()), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.') + ->param('newKey', null, new Key(), 'New Column Key.', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForEvents') + ->callback($this->action(...)); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php index c269af6a68..d763ec681f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php @@ -10,7 +10,9 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; -use Utopia\Validator\Text; +use Utopia\Validator\Boolean; +use Utopia\Validator\JSON; +use Utopia\Validator\Nullable; class Create extends PointCreate { @@ -52,9 +54,9 @@ class Create extends PointCreate ->param('databaseId', '', new UID(), 'Database ID.') ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') - ->param('required', null, new \Utopia\Validator\Boolean(), 'Is column required?') - ->param('default', null, new Text(0, 0), 'Default value for column when not provided. Cannot be set when column is required.', true) - ->param('array', false, new \Utopia\Validator\Boolean(), 'Is column an array?', true) + ->param('required', null, new Boolean(), 'Is column required?') + ->param('default', null, new Nullable(new JSON()), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) + ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php new file mode 100644 index 0000000000..8cf89eb0ef --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php @@ -0,0 +1,67 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/point/:key') + ->desc('Update point column') + ->groups(['api', 'database', 'schema']) + ->label('scope', 'tables.write') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].update') + ->label('audits.event', 'column.update') + ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') + ->label('sdk', new Method( + namespace: $this->getSdkNamespace(), + group: $this->getSdkGroup(), + name: self::getName(), + description: '/docs/references/tablesdb/update-point-column.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: $this->getResponseModel(), + ) + ], + contentType: ContentType::JSON + )) + ->param('databaseId', '', new UID(), 'Database ID.') + ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') + ->param('key', '', new Key(), 'Column Key.') + ->param('required', null, new Boolean(), 'Is column required?') + ->param('default', null, new Nullable(new JSON()), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.') + ->param('newKey', null, new Key(), 'New Column Key.', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForEvents') + ->callback($this->action(...)); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php index 302a5b21df..f764fcaee4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php @@ -10,7 +10,9 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; -use Utopia\Validator\Text; +use Utopia\Validator\Boolean; +use Utopia\Validator\JSON; +use Utopia\Validator\Nullable; class Create extends PolygonCreate { @@ -52,9 +54,9 @@ class Create extends PolygonCreate ->param('databaseId', '', new UID(), 'Database ID.') ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') - ->param('required', null, new \Utopia\Validator\Boolean(), 'Is column required?') - ->param('default', null, new Text(0, 0), 'Default value for column when not provided. Cannot be set when column is required.', true) - ->param('array', false, new \Utopia\Validator\Boolean(), 'Is column an array?', true) + ->param('required', null, new Boolean(), 'Is column required?') + ->param('default', null, new Nullable(new JSON()), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) + ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php new file mode 100644 index 0000000000..0b731362d2 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php @@ -0,0 +1,67 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/polygon/:key') + ->desc('Update polygon column') + ->groups(['api', 'database', 'schema']) + ->label('scope', 'tables.write') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].update') + ->label('audits.event', 'column.update') + ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') + ->label('sdk', new Method( + namespace: $this->getSdkNamespace(), + group: $this->getSdkGroup(), + name: self::getName(), + description: '/docs/references/tablesdb/update-polygon-column.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: $this->getResponseModel(), + ) + ], + contentType: ContentType::JSON + )) + ->param('databaseId', '', new UID(), 'Database ID.') + ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') + ->param('key', '', new Key(), 'Column Key.') + ->param('required', null, new Boolean(), 'Is column required?') + ->param('default', null, new Nullable(new JSON()), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.') + ->param('newKey', null, new Key(), 'New Column Key.', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForEvents') + ->callback($this->action(...)); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Tables.php b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Tables.php index 0162da1527..d570745148 100644 --- a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Tables.php +++ b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Tables.php @@ -22,8 +22,11 @@ use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Integer\Upd use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\IP\Create as CreateIP; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\IP\Update as UpdateIP; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Line\Create as CreateLine; +use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Line\Update as UpdateLine; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Point\Create as CreatePoint; +use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Point\Update as UpdatePoint; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Polygon\Create as CreatePolygon; +use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Polygon\Update as UpdatePolygon; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Relationship\Create as CreateRelationship; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Relationship\Update as UpdateRelationship; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\String\Create as CreateString; @@ -139,12 +142,15 @@ class Tables extends Base // Column: Line $service->addAction(CreateLine::getName(), new CreateLine()); + $service->addAction(UpdateLine::getName(), new UpdateLine()); // Column: Point $service->addAction(CreatePoint::getName(), new CreatePoint()); + $service->addAction(UpdatePoint::getName(), new UpdatePoint()); // Column: Polygon $service->addAction(CreatePolygon::getName(), new CreatePolygon()); + $service->addAction(UpdatePolygon::getName(), new UpdatePolygon()); // Column: Relationship $service->addAction(CreateRelationship::getName(), new CreateRelationship()); diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php index def54c4b9d..c740ebb194 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -6359,6 +6359,165 @@ trait DatabasesBase ])); } + public function testUpdateSpatialAttributes(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Update Spatial Attributes Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create collection with spatial attributes + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Update Spatial Attributes Collection', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $collectionId = $collection['body']['$id']; + + // Create string attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + + // Create point attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'location', + 'required' => true, + ]); + + // Create line attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/line', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'route', + 'required' => false, + ]); + + // Create polygon attribute + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'area', + 'required' => true, + ]); + + sleep(2); + + // Test 1: Update point attribute - change required status + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point/location', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'required' => false, + 'default' => null, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(false, $response['body']['required']); + + // Test 2: Update line attribute - change required status and add default value + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/line/route', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'required' => true, + 'default' => json_encode([[0, 0], [1, 1]]), + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(true, $response['body']['required']); + $this->assertEquals('[[0, 0], [1, 1]]', $response['body']['default']); + + // Test 3: Update polygon attribute - change key name + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/polygon/area', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'newKey' => 'coverage', + 'default' => null, + 'required' => false + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('coverage', $response['body']['key']); + + // Test 4: Update point attribute - add default value + $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point/location', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'default' => json_encode([0, 0]), + 'required' => true + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('[0, 0]', $response['body']['default']); + + // Test 5: Verify attribute updates by creating a document + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'name' => 'Test Location', + 'coverage' => [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]] + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([0, 0], $response['body']['location']); // Should use default value + $this->assertEquals([[0, 0], [1, 1]], $response['body']['route']); // Should use default value + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } + public function testSpatialQuery(): void { $database = $this->client->call(Client::METHOD_POST, '/databases', [ diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index 3e7eba94bd..f1f2e13579 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -8131,4 +8131,163 @@ trait DatabasesBase 'x-appwrite-key' => $this->getProject()['apiKey'] ])); } + + public function testUpdateSpatialColumns(): void + { + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Update Spatial Columns Test Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create table with spatial columns + $table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'tableId' => ID::unique(), + 'name' => 'Update Spatial Columns Table', + 'rowSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), + ], + ]); + + $tableId = $table['body']['$id']; + + // Create string column + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + + // Create point column + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'location', + 'required' => true, + ]); + + // Create line column + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/line', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'route', + 'required' => false, + ]); + + // Create polygon column + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/polygon', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'area', + 'required' => true, + ]); + + sleep(2); + + // Test 1: Update point column - change required status + $response = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/point/location', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'required' => false, + 'default' => null, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(false, $response['body']['required']); + + // Test 2: Update line column - change required status and add default value + $response = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/line/route', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'required' => false, + 'default' => json_encode([[0, 0], [1, 1]]), + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(false, $response['body']['required']); + $this->assertEquals([[0, 0], [1, 1]], $response['body']['default']); + + // Test 3: Update polygon column - change key name + $response = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/polygon/area', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'newKey' => 'coverage', + 'default' => null, + 'required' => false + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('coverage', $response['body']['key']); + + // Test 4: Update point column - add default value + $response = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/point/location', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'default' => json_encode([0, 0]), + 'required' => false + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals([0, 0], $response['body']['default']); + + // Test 5: Verify column updates by creating a row + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Test Location', + 'coverage' => [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]] + ] + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals([0, 0], $response['body']['location']); // Should use default value + $this->assertEquals([[0, 0], [1, 1]], $response['body']['route']); // Should use default value + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } } From 0e343125b75065fcd623f1d9a60bfce125e09740 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 27 Aug 2025 16:35:55 +0530 Subject: [PATCH 17/50] updated graphql queries --- tests/e2e/Services/GraphQL/Base.php | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/e2e/Services/GraphQL/Base.php b/tests/e2e/Services/GraphQL/Base.php index 28e632f001..9f5a93dd00 100644 --- a/tests/e2e/Services/GraphQL/Base.php +++ b/tests/e2e/Services/GraphQL/Base.php @@ -942,6 +942,35 @@ trait Base array } }'; + case self::CREATE_POINT_COLUMN: + return 'mutation createPointColumn($databaseId: String!, $tableId: String!, $key: String!, $required: Boolean!, $array: Boolean){ + tablesDBCreatePointColumn(databaseId: $databaseId, tableId: $tableId, key: $key, required: $required, array: $array) { + key + required + array + status + } + }'; + + case self::CREATE_LINE_COLUMN: + return 'mutation createLineColumn($databaseId: String!, $tableId: String!, $key: String!, $required: Boolean!, $array: Boolean){ + tablesDBCreateLineColumn(databaseId: $databaseId, tableId: $tableId, key: $key, required: $required, array: $array) { + key + required + array + status + } + }'; + + case self::CREATE_POLYGON_COLUMN: + return 'mutation createPolygonColumn($databaseId: String!, $tableId: String!, $key: String!, $required: Boolean!, $array: Boolean){ + tablesDBCreatePolygonColumn(databaseId: $databaseId, tableId: $tableId, key: $key, required: $required, array: $array) { + key + required + array + status + } + }'; case self::CREATE_RELATIONSHIP_COLUMN: return 'mutation createRelationshipColumn($databaseId: String!, $tableId: String!, $relatedTableId: String!, $type: String!, $twoWay: Boolean, $key: String, $twoWayKey: String, $onDelete: String){ tablesDBCreateRelationshipColumn(databaseId: $databaseId, tableId: $tableId, relatedTableId: $relatedTableId, type: $type, twoWay: $twoWay, key: $key, twoWayKey: $twoWayKey, onDelete: $onDelete) { @@ -1021,6 +1050,27 @@ trait Base default } }'; + case self::UPDATE_POINT_COLUMN: + return 'mutation updatePointColumn($databaseId: String!, $tableId: String!, $key: String!, $required: Boolean!){ + tablesDBUpdatePointColumn(databaseId: $databaseId, tableId: $tableId, key: $key, required: $required) { + required + } + }'; + + case self::UPDATE_LINE_COLUMN: + return 'mutation updateLineColumn($databaseId: String!, $tableId: String!, $key: String!, $required: Boolean!){ + tablesDBUpdateLineColumn(databaseId: $databaseId, tableId: $tableId, key: $key, required: $required) { + required + } + }'; + + case self::UPDATE_POLYGON_COLUMN: + return 'mutation updatePolygonColumn($databaseId: String!, $tableId: String!, $key: String!, $required: Boolean!){ + tablesDBUpdatePolygonColumn(databaseId: $databaseId, tableId: $tableId, key: $key, required: $required) { + required + } + }'; + case self::UPDATE_RELATIONSHIP_COLUMN: return 'mutation updateRelationshipColumn($databaseId: String!, $tableId: String!, $key: String!, $onDelete: String){ tablesDBUpdateRelationshipColumn(databaseId: $databaseId, tableId: $tableId, key: $key, onDelete: $onDelete) { From 2ec0da3c22f0e851e33a3cc69db1dc7c3dca9a6c Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 27 Aug 2025 16:58:24 +0530 Subject: [PATCH 18/50] updated composer lock --- composer.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.lock b/composer.lock index 79dfc9372a..5ddac255ac 100644 --- a/composer.lock +++ b/composer.lock @@ -3557,16 +3557,16 @@ }, { "name": "utopia-php/database", - "version": "1.2.1", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "99beaf1dd6dc3561c8332f9893325777553644a4" + "reference": "d59a207c079cc9e821ee4cab045a411bdad79e8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/99beaf1dd6dc3561c8332f9893325777553644a4", - "reference": "99beaf1dd6dc3561c8332f9893325777553644a4", + "url": "https://api.github.com/repos/utopia-php/database/zipball/d59a207c079cc9e821ee4cab045a411bdad79e8c", + "reference": "d59a207c079cc9e821ee4cab045a411bdad79e8c", "shasum": "" }, "require": { @@ -3607,9 +3607,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/1.2.1" + "source": "https://github.com/utopia-php/database/tree/1.2.2" }, - "time": "2025-08-26T16:05:26+00:00" + "time": "2025-08-27T11:27:06+00:00" }, { "name": "utopia-php/detector", @@ -4926,16 +4926,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.1.14", + "version": "1.1.15", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "662c7a53e683ed941c7d1374cfd32533bf54fbca" + "reference": "8e8e39634ba7558704522959d88f3542563a5444" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/662c7a53e683ed941c7d1374cfd32533bf54fbca", - "reference": "662c7a53e683ed941c7d1374cfd32533bf54fbca", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/8e8e39634ba7558704522959d88f3542563a5444", + "reference": "8e8e39634ba7558704522959d88f3542563a5444", "shasum": "" }, "require": { @@ -4971,9 +4971,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/1.1.14" + "source": "https://github.com/appwrite/sdk-generator/tree/1.1.15" }, - "time": "2025-08-26T13:17:07+00:00" + "time": "2025-08-27T04:59:35+00:00" }, { "name": "doctrine/annotations", From 8338a7318fbe2bb1c9dcbe979606183526000cae Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 27 Aug 2025 17:02:52 +0530 Subject: [PATCH 19/50] updated composer and merge conflicts --- composer.lock | 6 ------ 1 file changed, 6 deletions(-) diff --git a/composer.lock b/composer.lock index 74b43a29ae..5ddac255ac 100644 --- a/composer.lock +++ b/composer.lock @@ -4927,19 +4927,15 @@ { "name": "appwrite/sdk-generator", "version": "1.1.15", - "version": "1.1.15", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", "reference": "8e8e39634ba7558704522959d88f3542563a5444" - "reference": "8e8e39634ba7558704522959d88f3542563a5444" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/8e8e39634ba7558704522959d88f3542563a5444", "reference": "8e8e39634ba7558704522959d88f3542563a5444", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/8e8e39634ba7558704522959d88f3542563a5444", - "reference": "8e8e39634ba7558704522959d88f3542563a5444", "shasum": "" }, "require": { @@ -4976,10 +4972,8 @@ "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", "source": "https://github.com/appwrite/sdk-generator/tree/1.1.15" - "source": "https://github.com/appwrite/sdk-generator/tree/1.1.15" }, "time": "2025-08-27T04:59:35+00:00" - "time": "2025-08-27T04:59:35+00:00" }, { "name": "doctrine/annotations", From 7360dd68e015b78797c11ef3d7bbc2040d7aa01a Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 27 Aug 2025 17:41:52 +0530 Subject: [PATCH 20/50] updated tests --- tests/e2e/Services/Databases/Legacy/DatabasesBase.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php index c740ebb194..0485331613 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -6453,13 +6453,13 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'required' => true, + 'required' => false, 'default' => json_encode([[0, 0], [1, 1]]), ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(true, $response['body']['required']); - $this->assertEquals('[[0, 0], [1, 1]]', $response['body']['default']); + $this->assertEquals(false, $response['body']['required']); + $this->assertEquals([[0, 0], [1, 1]], $response['body']['default']); // Test 3: Update polygon attribute - change key name $response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/polygon/area', array_merge([ @@ -6482,11 +6482,11 @@ trait DatabasesBase 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ 'default' => json_encode([0, 0]), - 'required' => true + 'required' => false ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('[0, 0]', $response['body']['default']); + $this->assertEquals([0, 0], $response['body']['default']); // Test 5: Verify attribute updates by creating a document $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ From 51b98b6976226ddeaf6ee46739c352c7c0e596e8 Mon Sep 17 00:00:00 2001 From: Veeresh <75656445+Veera-mulge@users.noreply.github.com> Date: Thu, 28 Aug 2025 21:13:29 +0530 Subject: [PATCH 21/50] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c210784737..375b1ad48c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -> We just announced a brand new TablesDB UI for Appwrite Databases - [Learn more](https://appwrite.io/blog/post/announcing-appwrite-databases-new-ui) +> We just announced Opt-in relationship loading for Appwrite Databases - [Learn more](https://appwrite.io/blog/post/announcing-opt-in-relationship-loading) > Appwrite Cloud is now Generally Available - [Learn more](https://appwrite.io/cloud-ga) From 043ca48f91e594017e55ec1548dacf0b4d2e462d Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 1 Sep 2025 11:27:57 +0530 Subject: [PATCH 22/50] updated response model and docs --- docs/references/databases/update-line-attribute.md | 1 + docs/references/databases/update-point-attribute.md | 1 + docs/references/databases/update-polygon-attribute.md | 1 + docs/references/tablesdb/create-line-column.md | 1 + docs/references/tablesdb/create-point-column.md | 1 + docs/references/tablesdb/create-polygon-column.md | 1 + docs/references/tablesdb/update-line-column.md | 1 + docs/references/tablesdb/update-point-column.md | 1 + docs/references/tablesdb/update-polygon-column.md | 1 + src/Appwrite/Utopia/Response/Model/AttributeLine.php | 2 +- src/Appwrite/Utopia/Response/Model/AttributePoint.php | 2 +- src/Appwrite/Utopia/Response/Model/AttributePolygon.php | 2 +- src/Appwrite/Utopia/Response/Model/ColumnLine.php | 2 +- src/Appwrite/Utopia/Response/Model/ColumnPoint.php | 2 +- src/Appwrite/Utopia/Response/Model/ColumnPolygon.php | 2 +- 15 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 docs/references/databases/update-line-attribute.md create mode 100644 docs/references/databases/update-point-attribute.md create mode 100644 docs/references/databases/update-polygon-attribute.md create mode 100644 docs/references/tablesdb/create-line-column.md create mode 100644 docs/references/tablesdb/create-point-column.md create mode 100644 docs/references/tablesdb/create-polygon-column.md create mode 100644 docs/references/tablesdb/update-line-column.md create mode 100644 docs/references/tablesdb/update-point-column.md create mode 100644 docs/references/tablesdb/update-polygon-column.md diff --git a/docs/references/databases/update-line-attribute.md b/docs/references/databases/update-line-attribute.md new file mode 100644 index 0000000000..b55d31c5f6 --- /dev/null +++ b/docs/references/databases/update-line-attribute.md @@ -0,0 +1 @@ +Update a line attribute. Changing the `default` value will not update already existing documents. \ No newline at end of file diff --git a/docs/references/databases/update-point-attribute.md b/docs/references/databases/update-point-attribute.md new file mode 100644 index 0000000000..f40d18c6e5 --- /dev/null +++ b/docs/references/databases/update-point-attribute.md @@ -0,0 +1 @@ +Update a point attribute. Changing the `default` value will not update already existing documents. \ No newline at end of file diff --git a/docs/references/databases/update-polygon-attribute.md b/docs/references/databases/update-polygon-attribute.md new file mode 100644 index 0000000000..0d9718e41e --- /dev/null +++ b/docs/references/databases/update-polygon-attribute.md @@ -0,0 +1 @@ +Update a polygon attribute. Changing the `default` value will not update already existing documents. \ No newline at end of file diff --git a/docs/references/tablesdb/create-line-column.md b/docs/references/tablesdb/create-line-column.md new file mode 100644 index 0000000000..96f1509936 --- /dev/null +++ b/docs/references/tablesdb/create-line-column.md @@ -0,0 +1 @@ +Create a geometric line attribute. \ No newline at end of file diff --git a/docs/references/tablesdb/create-point-column.md b/docs/references/tablesdb/create-point-column.md new file mode 100644 index 0000000000..dd92ffc98e --- /dev/null +++ b/docs/references/tablesdb/create-point-column.md @@ -0,0 +1 @@ +Create a geometric point attribute. \ No newline at end of file diff --git a/docs/references/tablesdb/create-polygon-column.md b/docs/references/tablesdb/create-polygon-column.md new file mode 100644 index 0000000000..7cb3985ff7 --- /dev/null +++ b/docs/references/tablesdb/create-polygon-column.md @@ -0,0 +1 @@ +Create a geometric polygon attribute. \ No newline at end of file diff --git a/docs/references/tablesdb/update-line-column.md b/docs/references/tablesdb/update-line-column.md new file mode 100644 index 0000000000..1cd3b53d07 --- /dev/null +++ b/docs/references/tablesdb/update-line-column.md @@ -0,0 +1 @@ +Update a line column. Changing the `default` value will not update already existing documents. \ No newline at end of file diff --git a/docs/references/tablesdb/update-point-column.md b/docs/references/tablesdb/update-point-column.md new file mode 100644 index 0000000000..251e6de260 --- /dev/null +++ b/docs/references/tablesdb/update-point-column.md @@ -0,0 +1 @@ +Update a point column. Changing the `default` value will not update already existing documents. \ No newline at end of file diff --git a/docs/references/tablesdb/update-polygon-column.md b/docs/references/tablesdb/update-polygon-column.md new file mode 100644 index 0000000000..fc46a223cf --- /dev/null +++ b/docs/references/tablesdb/update-polygon-column.md @@ -0,0 +1 @@ +Update a polygon column. Changing the `default` value will not update already existing documents. \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/AttributeLine.php b/src/Appwrite/Utopia/Response/Model/AttributeLine.php index dce5b61978..ceebfc067d 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeLine.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeLine.php @@ -18,7 +18,7 @@ class AttributeLine extends Attribute 'example' => 'route', ]) ->addRule('type', [ - 'type' => self::TYPE_JSON, + 'type' => self::TYPE_STRING, 'description' => 'Attribute type.', 'default' => '', 'example' => 'linestring', diff --git a/src/Appwrite/Utopia/Response/Model/AttributePoint.php b/src/Appwrite/Utopia/Response/Model/AttributePoint.php index a79a1e7006..f93e5a8954 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributePoint.php +++ b/src/Appwrite/Utopia/Response/Model/AttributePoint.php @@ -18,7 +18,7 @@ class AttributePoint extends Attribute 'example' => 'location', ]) ->addRule('type', [ - 'type' => self::TYPE_JSON, + 'type' => self::TYPE_STRING, 'description' => 'Attribute type.', 'default' => '', 'example' => 'point', diff --git a/src/Appwrite/Utopia/Response/Model/AttributePolygon.php b/src/Appwrite/Utopia/Response/Model/AttributePolygon.php index e4ed3e93f9..46e95e954e 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributePolygon.php +++ b/src/Appwrite/Utopia/Response/Model/AttributePolygon.php @@ -18,7 +18,7 @@ class AttributePolygon extends Attribute 'example' => 'boundary', ]) ->addRule('type', [ - 'type' => self::TYPE_JSON, + 'type' => self::TYPE_STRING, 'description' => 'Attribute type.', 'default' => '', 'example' => 'polygon', diff --git a/src/Appwrite/Utopia/Response/Model/ColumnLine.php b/src/Appwrite/Utopia/Response/Model/ColumnLine.php index 2737924545..1e2c4d9bde 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnLine.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnLine.php @@ -18,7 +18,7 @@ class ColumnLine extends Column 'example' => 'route', ]) ->addRule('type', [ - 'type' => self::TYPE_STRING, + 'type' => self::TYPE_JSON, 'description' => 'Column type.', 'default' => '', 'example' => 'linestring', diff --git a/src/Appwrite/Utopia/Response/Model/ColumnPoint.php b/src/Appwrite/Utopia/Response/Model/ColumnPoint.php index d1803e3cae..29d39e5678 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnPoint.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnPoint.php @@ -24,7 +24,7 @@ class ColumnPoint extends Column 'example' => 'point', ]) ->addRule('default', [ - 'type' => self::TYPE_STRING, + 'type' => self::TYPE_JSON, 'description' => 'Default value for column when not provided. Cannot be set when column is required.', 'default' => null, 'required' => false, diff --git a/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php b/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php index 487f98b695..e68baa65ad 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php @@ -24,7 +24,7 @@ class ColumnPolygon extends Column 'example' => 'polygon', ]) ->addRule('default', [ - 'type' => self::TYPE_STRING, + 'type' => self::TYPE_JSON, 'description' => 'Default value for column when not provided. Cannot be set when column is required.', 'default' => null, 'required' => false, From cfe9b34cd57c1bbc0f5f71774b1409373a7125a9 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 2 Sep 2025 17:33:30 +0530 Subject: [PATCH 23/50] updated pr followups --- app/config/errors.php | 11 +++++ app/init/database/filters.php | 5 --- app/init/database/formats.php | 12 ------ src/Appwrite/Extend/Exception.php | 4 ++ .../Collections/Attributes/Action.php | 12 ++++++ .../Collections/Attributes/Line/Create.php | 11 ++--- .../Collections/Attributes/Line/Update.php | 4 +- .../Collections/Attributes/Point/Create.php | 9 ++-- .../Collections/Attributes/Point/Update.php | 4 +- .../Collections/Attributes/Polygon/Create.php | 9 ++-- .../Collections/Attributes/Polygon/Update.php | 4 +- .../Databases/Collections/Indexes/Create.php | 6 --- .../TablesDB/Tables/Columns/Line/Create.php | 2 +- .../TablesDB/Tables/Columns/Line/Update.php | 2 +- .../TablesDB/Tables/Columns/Point/Create.php | 2 +- .../TablesDB/Tables/Columns/Point/Update.php | 2 +- .../Tables/Columns/Polygon/Create.php | 2 +- .../Tables/Columns/Polygon/Update.php | 2 +- .../Utopia/Database/Validator/Spatial.php | 43 +++++++++++++++++++ src/Appwrite/Utopia/Response/Model.php | 1 + .../Utopia/Response/Model/AttributeLine.php | 14 +----- .../Utopia/Response/Model/AttributePoint.php | 14 +----- .../Response/Model/AttributePolygon.php | 16 +------ .../Utopia/Response/Model/ColumnLine.php | 14 +----- .../Utopia/Response/Model/ColumnPoint.php | 14 +----- .../Utopia/Response/Model/ColumnPolygon.php | 16 +------ .../Databases/Legacy/DatabasesBase.php | 2 - 27 files changed, 101 insertions(+), 136 deletions(-) create mode 100644 src/Appwrite/Utopia/Database/Validator/Spatial.php diff --git a/app/config/errors.php b/app/config/errors.php index 23df60f4ba..eba6e4bbac 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -837,6 +837,12 @@ return [ 'code' => 400, ], + Exception::ATTRIBUTE_TYPE_NOT_SUPPORTED => [ + 'name' => Exception::ATTRIBUTE_TYPE_NOT_SUPPORTED, + 'description' => "Attribute type not supported by the adapter.", + 'code' => 400, + ], + /** Exists for both Attributes & Columns */ Exception::RELATIONSHIP_VALUE_INVALID => [ 'name' => Exception::RELATIONSHIP_VALUE_INVALID, @@ -895,6 +901,11 @@ return [ 'description' => "Existing data is too large for new size, truncate your existing data then try again.", 'code' => 400, ], + Exception::COLUMN_TYPE_NOT_SUPPORTED => [ + 'name' => Exception::COLUMN_TYPE_NOT_SUPPORTED, + 'description' => "Column type not supported by the adapter.", + 'code' => 400, + ], /** Indexes */ Exception::INDEX_NOT_FOUND => [ diff --git a/app/init/database/filters.php b/app/init/database/filters.php index 346387125c..33f5d8077a 100644 --- a/app/init/database/filters.php +++ b/app/init/database/filters.php @@ -92,11 +92,6 @@ Database::addFilter( $filters = $attribute->getAttribute('filters', []); $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); break; - - case Database::VAR_POINT: - case Database::VAR_LINESTRING: - case Database::VAR_POLYGON: - break; } } diff --git a/app/init/database/formats.php b/app/init/database/formats.php index f8545e3b54..6c73877576 100644 --- a/app/init/database/formats.php +++ b/app/init/database/formats.php @@ -41,15 +41,3 @@ Structure::addFormat(APP_DATABASE_ATTRIBUTE_FLOAT_RANGE, function ($attribute) { $max = $attribute['formatOptions']['max'] ?? INF; return new Range($min, $max, Range::TYPE_FLOAT); }, Database::VAR_FLOAT); - -Structure::addFormat(APP_DATABASE_ATTRIBUTE_POINT, function () { - return new \Utopia\Validator\Text(0, 0); -}, Database::VAR_POINT); - -Structure::addFormat(APP_DATABASE_ATTRIBUTE_LINE, function () { - return new \Utopia\Validator\Text(0, 0); -}, Database::VAR_LINESTRING); - -Structure::addFormat(APP_DATABASE_ATTRIBUTE_POLYGON, function () { - return new \Utopia\Validator\Text(0, 0); -}, Database::VAR_POLYGON); diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 8eded2dbe0..ae9b09e85c 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -234,6 +234,8 @@ class Exception extends \Exception public const ATTRIBUTE_TYPE_INVALID = 'attribute_type_invalid'; public const ATTRIBUTE_INVALID_RESIZE = 'attribute_invalid_resize'; + public const ATTRIBUTE_TYPE_NOT_SUPPORTED = 'ATTRIBUTE_TYPE_NOT_SUPPORTED'; + /** Columns */ public const COLUMN_NOT_FOUND = 'column_not_found'; public const COLUMN_UNKNOWN = 'column_unknown'; @@ -246,6 +248,8 @@ class Exception extends \Exception public const COLUMN_TYPE_INVALID = 'column_type_invalid'; public const COLUMN_INVALID_RESIZE = 'column_invalid_resize'; + public const COLUMN_TYPE_NOT_SUPPORTED = 'COLUMN_TYPE_NOT_SUPPORTED'; + /** Relationship */ public const RELATIONSHIP_VALUE_INVALID = 'relationship_value_invalid'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index ccf886b029..f3903d91a7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -209,6 +209,14 @@ abstract class Action extends UtopiaAction : Exception::COLUMN_NOT_AVAILABLE; } + /** + * Get the exception for spatial type attribute not supported by the database adapter + */ + protected function getSpatialTypeNotSupportedException(): string + { + return $this->isCollectionsAPI() ? Exception::ATTRIBUTE_TYPE_NOT_SUPPORTED : Exception::COLUMN_TYPE_NOT_SUPPORTED; + } + /** * Get the correct collections context for Events queue. */ @@ -298,6 +306,10 @@ abstract class Action extends UtopiaAction $default = $attribute->getAttribute('default'); $options = $attribute->getAttribute('options', []); + if (in_array($type, Database::SPATIAL_TYPES) && !$dbForProject->getAdapter()->getSupportForSpatialAttributes()) { + throw new Exception($this->getSpatialTypeNotSupportedException()); + } + $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($db->isEmpty()) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php index f1ab5673b1..8ca08b01ae 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php @@ -9,6 +9,7 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Spatial; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Document; @@ -16,7 +17,6 @@ use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; -use Utopia\Validator\JSON; use Utopia\Validator\Nullable; class Create extends Action @@ -64,8 +64,7 @@ class Create extends Action ->param('collectionId', '', new UID(), 'Collection ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new JSON()), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) - ->param('array', false, new Boolean(), 'Is attribute an array?', true) + ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') @@ -73,17 +72,15 @@ class Create extends Action ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void { $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, 'type' => Database::VAR_LINESTRING, - 'size' => 0, 'required' => $required, - 'default' => $decodedDefault, - 'array' => $array, + 'default' => $decodedDefault ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); $response diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php index 2ffc6f7d3f..f8d7738434 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php @@ -9,13 +9,13 @@ use Appwrite\SDK\ContentType; use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Spatial; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; -use Utopia\Validator\JSON; use Utopia\Validator\Nullable; class Update extends Action @@ -64,7 +64,7 @@ class Update extends Action ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new JSON()), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.') + ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) ->param('newKey', null, new Key(), 'New attribute key.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php index 0a6e486f88..08dbda651a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php @@ -9,6 +9,7 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Spatial; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Document; @@ -16,7 +17,6 @@ use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; -use Utopia\Validator\JSON; use Utopia\Validator\Nullable; class Create extends Action @@ -64,8 +64,7 @@ class Create extends Action ->param('collectionId', '', new UID(), 'Collection ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new JSON()), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) - ->param('array', false, new Boolean(), 'Is attribute an array?', true) + ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') @@ -73,17 +72,15 @@ class Create extends Action ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void { $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, 'type' => Database::VAR_POINT, - 'size' => 0, 'required' => $required, 'default' => $decodedDefault, - 'array' => $array, ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); $response diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php index 3113ff7014..c1fb4e82be 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php @@ -9,13 +9,13 @@ use Appwrite\SDK\ContentType; use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Spatial; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; -use Utopia\Validator\JSON; use Utopia\Validator\Nullable; class Update extends Action @@ -64,7 +64,7 @@ class Update extends Action ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new JSON()), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.') + ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.') ->param('newKey', null, new Key(), 'New attribute key.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php index 9a4d534c17..a2d9f68b40 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php @@ -13,10 +13,10 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; +use Utopia\Database\Validator\Spatial; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; -use Utopia\Validator\JSON; use Utopia\Validator\Nullable; class Create extends Action @@ -64,8 +64,7 @@ class Create extends Action ->param('collectionId', '', new UID(), 'Collection ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new JSON()), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) - ->param('array', false, new Boolean(), 'Is attribute an array?', true) + ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') @@ -73,17 +72,15 @@ class Create extends Action ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void { $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, 'type' => Database::VAR_POLYGON, - 'size' => 0, 'required' => $required, 'default' => $decodedDefault, - 'array' => $array, ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); $response diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php index 8f41630ba4..9faee180f0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php @@ -9,12 +9,12 @@ use Appwrite\SDK\ContentType; use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Spatial; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; -use Utopia\Validator\JSON; use Utopia\Validator\Nullable; class Update extends Action @@ -63,7 +63,7 @@ class Update extends Action ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new JSON()), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.') + ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) ->param('newKey', null, new Key(), 'New attribute key.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php index 93f095e1dd..c5a429a79b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php @@ -199,12 +199,6 @@ class Create extends Action $supportForSpatialIndexNull = $dbForProject->getAdapter()->getSupportForSpatialIndexNull(); $supportForSpatialIndexOrder = $dbForProject->getAdapter()->getSupportForSpatialIndexOrder(); - if (!$this->isCollectionsAPI()) { - // Relax spatial constraints for TablesDB API - $supportForSpatialIndexNull = true; - $supportForSpatialIndexOrder = true; - } - $validator = new IndexValidator( $collection->getAttribute('attributes'), $maxIndexLength, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php index 6df33e8f96..a6fc5d1e9a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php @@ -34,7 +34,7 @@ class Create extends LineCreate ->desc('Create line column') ->groups(['api', 'database', 'schema']) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') - ->label('scope', 'tables.write') + ->label('scope', ['tables.write', 'collections.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('audits.event', 'column.create') ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php index 4360d85bfe..b7e2e43db8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php @@ -34,7 +34,7 @@ class Update extends LineUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/line/:key') ->desc('Update line column') ->groups(['api', 'database', 'schema']) - ->label('scope', 'tables.write') + ->label('scope', ['tables.write', 'collections.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].update') ->label('audits.event', 'column.update') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php index d763ec681f..cfded0e430 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php @@ -34,7 +34,7 @@ class Create extends PointCreate ->desc('Create point column') ->groups(['api', 'database', 'schema']) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') - ->label('scope', 'tables.write') + ->label('scope', ['tables.write', 'collections.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('audits.event', 'column.create') ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php index 8cf89eb0ef..4d04ac882e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php @@ -34,7 +34,7 @@ class Update extends PointUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/point/:key') ->desc('Update point column') ->groups(['api', 'database', 'schema']) - ->label('scope', 'tables.write') + ->label('scope', ['tables.write', 'collections.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].update') ->label('audits.event', 'column.update') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php index f764fcaee4..fdc11791e8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php @@ -34,7 +34,7 @@ class Create extends PolygonCreate ->desc('Create polygon column') ->groups(['api', 'database', 'schema']) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') - ->label('scope', 'tables.write') + ->label('scope', ['tables.write', 'collections.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('audits.event', 'column.create') ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php index 0b731362d2..65f26b7a0a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php @@ -34,7 +34,7 @@ class Update extends PolygonUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/polygon/:key') ->desc('Update polygon column') ->groups(['api', 'database', 'schema']) - ->label('scope', 'tables.write') + ->label('scope', ['tables.write', 'collections.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].update') ->label('audits.event', 'column.update') diff --git a/src/Appwrite/Utopia/Database/Validator/Spatial.php b/src/Appwrite/Utopia/Database/Validator/Spatial.php new file mode 100644 index 0000000000..3c28b66ce7 --- /dev/null +++ b/src/Appwrite/Utopia/Database/Validator/Spatial.php @@ -0,0 +1,43 @@ +spatialAttributeType = $spatialAttributeType; + } + /** + * Is valid. + * + * Returns true if valid or false if not. + * + * @param $value + * + * @return bool + */ + public function isValid($value): bool + { + + if (!parent::isValid($value)) { + return false; + } + $value = \json_decode($value, true); + $validator = new SpatialVaildator($this->spatialAttributeType); + return $validator->isValid($value); + } +} diff --git a/src/Appwrite/Utopia/Response/Model.php b/src/Appwrite/Utopia/Response/Model.php index 962da4834c..71443098ce 100644 --- a/src/Appwrite/Utopia/Response/Model.php +++ b/src/Appwrite/Utopia/Response/Model.php @@ -15,6 +15,7 @@ abstract class Model public const TYPE_DATETIME_EXAMPLE = '2020-10-15T06:38:00.000+00:00'; public const TYPE_RELATIONSHIP = 'relationship'; public const TYPE_PAYLOAD = 'payload'; + public const TYPE_SPATIAL = 'spatial'; /** * @var bool diff --git a/src/Appwrite/Utopia/Response/Model/AttributeLine.php b/src/Appwrite/Utopia/Response/Model/AttributeLine.php index ceebfc067d..6e0586e8b4 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeLine.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeLine.php @@ -11,20 +11,8 @@ class AttributeLine extends Attribute parent::__construct(); $this - ->addRule('key', [ - 'type' => self::TYPE_STRING, - 'description' => 'Attribute Key.', - 'default' => '', - 'example' => 'route', - ]) - ->addRule('type', [ - 'type' => self::TYPE_STRING, - 'description' => 'Attribute type.', - 'default' => '', - 'example' => 'linestring', - ]) ->addRule('default', [ - 'type' => self::TYPE_JSON, + 'type' => self::TYPE_SPATIAL, 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', 'default' => null, 'required' => false, diff --git a/src/Appwrite/Utopia/Response/Model/AttributePoint.php b/src/Appwrite/Utopia/Response/Model/AttributePoint.php index f93e5a8954..4a13054d96 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributePoint.php +++ b/src/Appwrite/Utopia/Response/Model/AttributePoint.php @@ -11,20 +11,8 @@ class AttributePoint extends Attribute parent::__construct(); $this - ->addRule('key', [ - 'type' => self::TYPE_STRING, - 'description' => 'Attribute Key.', - 'default' => '', - 'example' => 'location', - ]) - ->addRule('type', [ - 'type' => self::TYPE_STRING, - 'description' => 'Attribute type.', - 'default' => '', - 'example' => 'point', - ]) ->addRule('default', [ - 'type' => self::TYPE_JSON, + 'type' => self::TYPE_SPATIAL, 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', 'default' => null, 'required' => false, diff --git a/src/Appwrite/Utopia/Response/Model/AttributePolygon.php b/src/Appwrite/Utopia/Response/Model/AttributePolygon.php index 46e95e954e..c28d8f66ed 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributePolygon.php +++ b/src/Appwrite/Utopia/Response/Model/AttributePolygon.php @@ -11,24 +11,12 @@ class AttributePolygon extends Attribute parent::__construct(); $this - ->addRule('key', [ - 'type' => self::TYPE_STRING, - 'description' => 'Attribute Key.', - 'default' => '', - 'example' => 'boundary', - ]) - ->addRule('type', [ - 'type' => self::TYPE_STRING, - 'description' => 'Attribute type.', - 'default' => '', - 'example' => 'polygon', - ]) ->addRule('default', [ - 'type' => self::TYPE_JSON, + 'type' => self::TYPE_SPATIAL, 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', 'default' => null, 'required' => false, - 'example' => '[[[0, 0], [0, 10], [10, 10], [0, 0]]]' + 'example' => '[[[0, 0], [0, 10]], [[10, 10], [0, 0]]]' ]) ; } diff --git a/src/Appwrite/Utopia/Response/Model/ColumnLine.php b/src/Appwrite/Utopia/Response/Model/ColumnLine.php index 1e2c4d9bde..08bd66ce9c 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnLine.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnLine.php @@ -11,20 +11,8 @@ class ColumnLine extends Column parent::__construct(); $this - ->addRule('key', [ - 'type' => self::TYPE_STRING, - 'description' => 'Column Key.', - 'default' => '', - 'example' => 'route', - ]) - ->addRule('type', [ - 'type' => self::TYPE_JSON, - 'description' => 'Column type.', - 'default' => '', - 'example' => 'linestring', - ]) ->addRule('default', [ - 'type' => self::TYPE_STRING, + 'type' => self::TYPE_SPATIAL, 'description' => 'Default value for column when not provided. Cannot be set when column is required.', 'default' => null, 'required' => false, diff --git a/src/Appwrite/Utopia/Response/Model/ColumnPoint.php b/src/Appwrite/Utopia/Response/Model/ColumnPoint.php index 29d39e5678..ffc6ed6789 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnPoint.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnPoint.php @@ -11,20 +11,8 @@ class ColumnPoint extends Column parent::__construct(); $this - ->addRule('key', [ - 'type' => self::TYPE_STRING, - 'description' => 'Column Key.', - 'default' => '', - 'example' => 'location', - ]) - ->addRule('type', [ - 'type' => self::TYPE_STRING, - 'description' => 'Column type.', - 'default' => '', - 'example' => 'point', - ]) ->addRule('default', [ - 'type' => self::TYPE_JSON, + 'type' => self::TYPE_SPATIAL, 'description' => 'Default value for column when not provided. Cannot be set when column is required.', 'default' => null, 'required' => false, diff --git a/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php b/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php index e68baa65ad..9b3a6f1030 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php @@ -11,24 +11,12 @@ class ColumnPolygon extends Column parent::__construct(); $this - ->addRule('key', [ - 'type' => self::TYPE_STRING, - 'description' => 'Column Key.', - 'default' => '', - 'example' => 'boundary', - ]) - ->addRule('type', [ - 'type' => self::TYPE_STRING, - 'description' => 'Column type.', - 'default' => '', - 'example' => 'polygon', - ]) ->addRule('default', [ - 'type' => self::TYPE_JSON, + 'type' => self::TYPE_SPATIAL, 'description' => 'Default value for column when not provided. Cannot be set when column is required.', 'default' => null, 'required' => false, - 'example' => '[[[0, 0], [0, 10], [10, 10], [0, 0]]]' + 'example' => '[[[0, 0], [0, 10]], [[10, 10], [0, 0]]]' ]) ; } diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php index 0485331613..90fdc4cd62 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -6658,8 +6658,6 @@ trait DatabasesBase $this->assertCount(1, $response['body']['documents']); $this->assertEquals('doc1', $response['body']['documents'][0]['$id']); - - // Test 3: Polygon attribute queries $response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ 'content-type' => 'application/json', From 11120586897d1381ce951bc5c17a0f6d450a9d66 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 2 Sep 2025 18:07:34 +0530 Subject: [PATCH 24/50] pr followups --- .../Collections/Attributes/Line/Create.php | 2 +- .../Collections/Attributes/Line/Update.php | 2 +- .../Collections/Attributes/Point/Update.php | 2 +- .../TablesDB/Tables/Columns/Line/Create.php | 6 ++--- .../TablesDB/Tables/Columns/Line/Update.php | 5 ++-- .../TablesDB/Tables/Columns/Point/Create.php | 6 ++--- .../TablesDB/Tables/Columns/Point/Update.php | 5 ++-- .../Tables/Columns/Polygon/Create.php | 5 ++-- .../Tables/Columns/Polygon/Update.php | 5 ++-- .../Databases/Legacy/DatabasesBase.php | 23 +++++++++++++++++++ 10 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php index 8ca08b01ae..ce2452bba1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php @@ -64,7 +64,7 @@ class Create extends Action ->param('collectionId', '', new UID(), 'Collection ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) + ->param('default', null, new Nullable(new Spatial(Database::VAR_LINESTRING)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php index f8d7738434..c9bdb7d02b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php @@ -64,7 +64,7 @@ class Update extends Action ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) + ->param('default', null, new Nullable(new Spatial(Database::VAR_LINESTRING)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) ->param('newKey', null, new Key(), 'New attribute key.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php index c1fb4e82be..289606b983 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php @@ -64,7 +64,7 @@ class Update extends Action ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.') + ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.',true) ->param('newKey', null, new Key(), 'New attribute key.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php index a6fc5d1e9a..4777b99398 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php @@ -6,12 +6,13 @@ use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Li use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Spatial; use Appwrite\Utopia\Response as UtopiaResponse; +use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; -use Utopia\Validator\JSON; use Utopia\Validator\Nullable; class Create extends LineCreate @@ -55,8 +56,7 @@ class Create extends LineCreate ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') - ->param('default', null, new Nullable(new JSON()), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) - ->param('array', false, new Boolean(), 'Is column an array?', true) + ->param('default', null, new Nullable(new Spatial(Database::VAR_LINESTRING)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php index b7e2e43db8..65910b62f7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php @@ -7,12 +7,13 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Spatial; use Appwrite\Utopia\Response as UtopiaResponse; +use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; -use Utopia\Validator\JSON; use Utopia\Validator\Nullable; class Update extends LineUpdate @@ -57,7 +58,7 @@ class Update extends LineUpdate ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') - ->param('default', null, new Nullable(new JSON()), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.') + ->param('default', null, new Nullable(new Spatial(Database::VAR_LINESTRING)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) ->param('newKey', null, new Key(), 'New Column Key.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php index cfded0e430..6b2da4f266 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php @@ -6,12 +6,13 @@ use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Po use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Spatial; use Appwrite\Utopia\Response as UtopiaResponse; +use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; -use Utopia\Validator\JSON; use Utopia\Validator\Nullable; class Create extends PointCreate @@ -55,8 +56,7 @@ class Create extends PointCreate ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') - ->param('default', null, new Nullable(new JSON()), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) - ->param('array', false, new Boolean(), 'Is column an array?', true) + ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.',true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php index 4d04ac882e..5310d79829 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php @@ -8,11 +8,12 @@ use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; +use Utopia\Database\Database; use Utopia\Database\Validator\Key; +use Utopia\Database\Validator\Spatial; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; -use Utopia\Validator\JSON; use Utopia\Validator\Nullable; class Update extends PointUpdate @@ -57,7 +58,7 @@ class Update extends PointUpdate ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') - ->param('default', null, new Nullable(new JSON()), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.') + ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.',true) ->param('newKey', null, new Key(), 'New Column Key.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php index fdc11791e8..54f04b19f0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php @@ -6,12 +6,13 @@ use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Po use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Spatial; use Appwrite\Utopia\Response as UtopiaResponse; +use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; -use Utopia\Validator\JSON; use Utopia\Validator\Nullable; class Create extends PolygonCreate @@ -55,7 +56,7 @@ class Create extends PolygonCreate ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') - ->param('default', null, new Nullable(new JSON()), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) + ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php index 65f26b7a0a..7e06aafdca 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php @@ -7,12 +7,13 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Spatial; use Appwrite\Utopia\Response as UtopiaResponse; +use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; -use Utopia\Validator\JSON; use Utopia\Validator\Nullable; class Update extends PolygonUpdate @@ -57,7 +58,7 @@ class Update extends PolygonUpdate ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') - ->param('default', null, new Nullable(new JSON()), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.') + ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) ->param('newKey', null, new Key(), 'New Column Key.', true) ->inject('response') ->inject('dbForProject') diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php index 90fdc4cd62..0c7daa32b5 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -7529,6 +7529,29 @@ trait DatabasesBase ]); $this->assertEquals(400, $badIndex['headers']['status-code']); + // updating the attribute to required to create index + $updated = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point/'.'pOptional', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'required' => true, + 'default' => null + ]); + $this->assertEquals(200, $updated['headers']['status-code']); + + sleep(2); + $retriedIndex = $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_optional_point', + 'type' => Database::INDEX_SPATIAL, + 'attributes' => ['pOptional'], + ]); + $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', From 8f7085ccfccd8388d90fd9c70d62d433ed37130a Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 2 Sep 2025 23:00:31 +0530 Subject: [PATCH 25/50] pr followups --- composer.lock | 169 +++++++++++++----- .../Collections/Attributes/Point/Update.php | 2 +- .../TablesDB/Tables/Columns/Point/Create.php | 2 +- .../TablesDB/Tables/Columns/Point/Update.php | 2 +- .../Tables/Columns/Polygon/Create.php | 1 - .../Databases/Legacy/DatabasesBase.php | 155 ++++++++++++++++ .../Legacy/DatabasesCustomServerTest.php | 19 +- .../Databases/TablesDB/DatabasesBase.php | 122 ++++++++++++- .../TablesDB/DatabasesCustomServerTest.php | 5 +- 9 files changed, 414 insertions(+), 63 deletions(-) diff --git a/composer.lock b/composer.lock index 5ddac255ac..c22b7f4b05 100644 --- a/composer.lock +++ b/composer.lock @@ -2599,16 +2599,16 @@ }, { "name": "symfony/http-client", - "version": "v7.3.2", + "version": "v7.3.3", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "1c064a0c67749923483216b081066642751cc2c7" + "reference": "333b9bd7639cbdaecd25a3a48a9d2dcfaa86e019" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/1c064a0c67749923483216b081066642751cc2c7", - "reference": "1c064a0c67749923483216b081066642751cc2c7", + "url": "https://api.github.com/repos/symfony/http-client/zipball/333b9bd7639cbdaecd25a3a48a9d2dcfaa86e019", + "reference": "333b9bd7639cbdaecd25a3a48a9d2dcfaa86e019", "shasum": "" }, "require": { @@ -2616,6 +2616,7 @@ "psr/log": "^1|^2|^3", "symfony/deprecation-contracts": "^2.5|^3", "symfony/http-client-contracts": "~3.4.4|^3.5.2", + "symfony/polyfill-php83": "^1.29", "symfony/service-contracts": "^2.5|^3" }, "conflict": { @@ -2674,7 +2675,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.3.2" + "source": "https://github.com/symfony/http-client/tree/v7.3.3" }, "funding": [ { @@ -2694,7 +2695,7 @@ "type": "tidelift" } ], - "time": "2025-07-15T11:36:08+00:00" + "time": "2025-08-27T07:45:05+00:00" }, { "name": "symfony/http-client-contracts", @@ -2939,6 +2940,86 @@ ], "time": "2024-09-09T11:45:10+00:00" }, + { + "name": "symfony/polyfill-php83", + "version": "v1.33.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php83.git", + "reference": "17f6f9a6b1735c0f163024d959f700cfbc5155e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php83/zipball/17f6f9a6b1735c0f163024d959f700cfbc5155e5", + "reference": "17f6f9a6b1735c0f163024d959f700cfbc5155e5", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "type": "library", + "extra": { + "thanks": { + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php83\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.3+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php83/tree/v1.33.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2025-07-08T02:45:35+00:00" + }, { "name": "symfony/service-contracts", "version": "v3.6.0", @@ -3557,16 +3638,16 @@ }, { "name": "utopia-php/database", - "version": "1.2.2", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "d59a207c079cc9e821ee4cab045a411bdad79e8c" + "reference": "06ffa2b1c977f5451200a1ee82a500be1390a789" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/d59a207c079cc9e821ee4cab045a411bdad79e8c", - "reference": "d59a207c079cc9e821ee4cab045a411bdad79e8c", + "url": "https://api.github.com/repos/utopia-php/database/zipball/06ffa2b1c977f5451200a1ee82a500be1390a789", + "reference": "06ffa2b1c977f5451200a1ee82a500be1390a789", "shasum": "" }, "require": { @@ -3607,9 +3688,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/1.2.2" + "source": "https://github.com/utopia-php/database/tree/1.3.0" }, - "time": "2025-08-27T11:27:06+00:00" + "time": "2025-09-02T16:20:02+00:00" }, { "name": "utopia-php/detector", @@ -4109,16 +4190,16 @@ }, { "name": "utopia-php/migration", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "0e4499d9dd2c90c2be188cc5fb7a32d9a892b569" + "reference": "38171023efd3abe650d2abc5ac65f5df52311da6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/0e4499d9dd2c90c2be188cc5fb7a32d9a892b569", - "reference": "0e4499d9dd2c90c2be188cc5fb7a32d9a892b569", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/38171023efd3abe650d2abc5ac65f5df52311da6", + "reference": "38171023efd3abe650d2abc5ac65f5df52311da6", "shasum": "" }, "require": { @@ -4159,9 +4240,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.0.0" + "source": "https://github.com/utopia-php/migration/tree/1.0.1" }, - "time": "2025-08-13T09:15:53+00:00" + "time": "2025-08-28T13:41:25+00:00" }, { "name": "utopia-php/orchestration", @@ -7410,16 +7491,16 @@ }, { "name": "symfony/console", - "version": "v7.3.2", + "version": "v7.3.3", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "5f360ebc65c55265a74d23d7fe27f957870158a1" + "reference": "cb0102a1c5ac3807cf3fdf8bea96007df7fdbea7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/5f360ebc65c55265a74d23d7fe27f957870158a1", - "reference": "5f360ebc65c55265a74d23d7fe27f957870158a1", + "url": "https://api.github.com/repos/symfony/console/zipball/cb0102a1c5ac3807cf3fdf8bea96007df7fdbea7", + "reference": "cb0102a1c5ac3807cf3fdf8bea96007df7fdbea7", "shasum": "" }, "require": { @@ -7484,7 +7565,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.3.2" + "source": "https://github.com/symfony/console/tree/v7.3.3" }, "funding": [ { @@ -7504,7 +7585,7 @@ "type": "tidelift" } ], - "time": "2025-07-30T17:13:41+00:00" + "time": "2025-08-25T06:35:40+00:00" }, { "name": "symfony/filesystem", @@ -7646,16 +7727,16 @@ }, { "name": "symfony/options-resolver", - "version": "v7.3.2", + "version": "v7.3.3", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "119bcf13e67dbd188e5dbc74228b1686f66acd37" + "reference": "0ff2f5c3df08a395232bbc3c2eb7e84912df911d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/119bcf13e67dbd188e5dbc74228b1686f66acd37", - "reference": "119bcf13e67dbd188e5dbc74228b1686f66acd37", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/0ff2f5c3df08a395232bbc3c2eb7e84912df911d", + "reference": "0ff2f5c3df08a395232bbc3c2eb7e84912df911d", "shasum": "" }, "require": { @@ -7693,7 +7774,7 @@ "options" ], "support": { - "source": "https://github.com/symfony/options-resolver/tree/v7.3.2" + "source": "https://github.com/symfony/options-resolver/tree/v7.3.3" }, "funding": [ { @@ -7713,7 +7794,7 @@ "type": "tidelift" } ], - "time": "2025-07-15T11:36:08+00:00" + "time": "2025-08-05T10:16:07+00:00" }, { "name": "symfony/polyfill-ctype", @@ -8047,16 +8128,16 @@ }, { "name": "symfony/process", - "version": "v7.3.0", + "version": "v7.3.3", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "40c295f2deb408d5e9d2d32b8ba1dd61e36f05af" + "reference": "32241012d521e2e8a9d713adb0812bb773b907f1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/40c295f2deb408d5e9d2d32b8ba1dd61e36f05af", - "reference": "40c295f2deb408d5e9d2d32b8ba1dd61e36f05af", + "url": "https://api.github.com/repos/symfony/process/zipball/32241012d521e2e8a9d713adb0812bb773b907f1", + "reference": "32241012d521e2e8a9d713adb0812bb773b907f1", "shasum": "" }, "require": { @@ -8088,7 +8169,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.3.0" + "source": "https://github.com/symfony/process/tree/v7.3.3" }, "funding": [ { @@ -8099,25 +8180,29 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2025-04-17T09:11:12+00:00" + "time": "2025-08-18T09:42:54+00:00" }, { "name": "symfony/string", - "version": "v7.3.2", + "version": "v7.3.3", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "42f505aff654e62ac7ac2ce21033818297ca89ca" + "reference": "17a426cce5fd1f0901fefa9b2a490d0038fd3c9c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/42f505aff654e62ac7ac2ce21033818297ca89ca", - "reference": "42f505aff654e62ac7ac2ce21033818297ca89ca", + "url": "https://api.github.com/repos/symfony/string/zipball/17a426cce5fd1f0901fefa9b2a490d0038fd3c9c", + "reference": "17a426cce5fd1f0901fefa9b2a490d0038fd3c9c", "shasum": "" }, "require": { @@ -8175,7 +8260,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.3.2" + "source": "https://github.com/symfony/string/tree/v7.3.3" }, "funding": [ { @@ -8195,7 +8280,7 @@ "type": "tidelift" } ], - "time": "2025-07-10T08:47:49+00:00" + "time": "2025-08-25T06:35:40+00:00" }, { "name": "textalk/websocket", diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php index 289606b983..02b8bff2e5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php @@ -64,7 +64,7 @@ class Update extends Action ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.',true) + ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) ->param('newKey', null, new Key(), 'New attribute key.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php index 6b2da4f266..d0cc9a34d3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php @@ -56,7 +56,7 @@ class Create extends PointCreate ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') - ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.',true) + ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php index 5310d79829..dedc90f312 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php @@ -58,7 +58,7 @@ class Update extends PointUpdate ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') - ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.',true) + ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) ->param('newKey', null, new Key(), 'New Column Key.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php index 54f04b19f0..d261c4ec14 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php @@ -57,7 +57,6 @@ class Create extends PolygonCreate ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) - ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') ->inject('queueForDatabase') diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php index 0c7daa32b5..ea67fb1bbc 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -7572,4 +7572,159 @@ trait DatabasesBase 'x-appwrite-key' => $this->getProject()['apiKey'] ])); } + + public function testSpatialDistanceInMeter(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Distance Meters Database' + ]); + + $databaseId = $database['body']['$id']; + + // Create collection with spatial attribute + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Spatial Distance Meters Collection', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + ]); + + $collectionId = $collection['body']['$id']; + + // Create point attribute + $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/point', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'loc', + 'required' => true, + ]); + + $this->assertEquals(202, $response['headers']['status-code']); + sleep(2); + + // Create spatial index + $indexResponse = $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_loc', + 'type' => Database::INDEX_SPATIAL, + 'attributes' => ['loc'], + ]); + + sleep(2); + $this->assertEquals(202, $indexResponse['headers']['status-code']); + + + // Two points roughly ~1000 meters apart by latitude delta (~0.009 deg ≈ 1km) + $p0 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => 'p0', + 'data' => [ + 'loc' => [0.0000, 0.0000] + ] + ]); + + $p1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => 'p1', + 'data' => [ + 'loc' => [0.0090, 0.0000] + ] + ]); + + $this->assertEquals(201, $p0['headers']['status-code']); + $this->assertEquals(201, $p1['headers']['status-code']); + + // distanceLessThan with meters=true: within 1500m should include both + $within1_5km = $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::distanceLessThan('loc', [0.0000, 0.0000], 1500, true)->toString()] + ]); + + $this->assertEquals(200, $within1_5km['headers']['status-code']); + $this->assertCount(2, $within1_5km['body']['documents']); + + // Within 500m should include only p0 (exact point) + $within500m = $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::distanceLessThan('loc', [0.0000, 0.0000], 500, true)->toString()] + ]); + + $this->assertEquals(200, $within500m['headers']['status-code']); + $this->assertCount(1, $within500m['body']['documents']); + $this->assertEquals('p0', $within500m['body']['documents'][0]['$id']); + + // distanceGreaterThan 500m should include only p1 + $greater500m = $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::distanceGreaterThan('loc', [0.0000, 0.0000], 500, true)->toString()] + ]); + + $this->assertEquals(200, $greater500m['headers']['status-code']); + $this->assertCount(1, $greater500m['body']['documents']); + $this->assertEquals('p1', $greater500m['body']['documents'][0]['$id']); + + // distanceEqual with 0m should return exact match p0 + $equalZero = $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::distanceEqual('loc', [0.0000, 0.0000], 0, true)->toString()] + ]); + + $this->assertEquals(200, $equalZero['headers']['status-code']); + $this->assertEquals('p0', $equalZero['body']['documents'][0]['$id']); + + // distanceNotEqual with 0m should return p1 + $notEqualZero = $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::distanceNotEqual('loc', [0.0000, 0.0000], 0, true)->toString()] + ]); + + $this->assertEquals(200, $notEqualZero['headers']['status-code']); + $this->assertEquals('p1', $notEqualZero['body']['documents'][0]['$id']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + } } diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php index 23bca658e6..2c603233a3 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php @@ -6406,20 +6406,14 @@ class DatabasesCustomServerTest extends Scope [ '$id' => ID::unique(), 'name' => 'Invalid Point', - 'location' => [1000.0, 2000.0], // Invalid coordinates - 'area' => [ - [10.0, 20.0], - [11.0, 20.0], - [11.0, 21.0], - [10.0, 21.0], - [10.0, 20.0] - ] + 'location' => [1000.0, 2000.0], + 'area' => [10.0 , 10.0] ] ], ]); - // Coordinates are not validated strictly; creation should succeed - $this->assertEquals(201, $response['headers']['status-code']); + // invalid polygon + $this->assertEquals(400, $response['headers']['status-code']); $response = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$collectionId}/documents", array_merge([ 'content-type' => 'application/json', @@ -6438,7 +6432,7 @@ class DatabasesCustomServerTest extends Scope ], ]); - $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals(400, $response['headers']['status-code']); $response = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$collectionId}/documents", array_merge([ 'content-type' => 'application/json', @@ -6720,8 +6714,7 @@ class DatabasesCustomServerTest extends Scope ], ]); - // Single point linestrings are accepted as arrays; creation should succeed - $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals(400, $response['headers']['status-code']); // Cleanup $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index 6d7050ec60..c521928327 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -8106,7 +8106,31 @@ trait DatabasesBase 'type' => Database::INDEX_SPATIAL, 'columns' => ['pOptional'], ]); - $this->assertEquals(202, $badIndex['headers']['status-code']); + $this->assertEquals(400, $badIndex['headers']['status-code']); + + // making it required to create index on it + $updated = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/point/'.'pOptional', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'required' => true, + 'default' => null + ]); + $this->assertEquals(200, $updated['headers']['status-code']); + + sleep(2); + + $retriedIndex = $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_optional_point', + 'type' => Database::INDEX_SPATIAL, + 'columns' => ['pOptional'], + ]); + $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([ @@ -8292,4 +8316,100 @@ trait DatabasesBase 'x-appwrite-key' => $this->getProject()['apiKey'] ])); } + public function testSpatialDistanceInMeter(): void + { + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]; + + // Create database + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', $headers, [ + 'databaseId' => ID::unique(), + 'name' => 'Spatial Distance Meters Database' + ]); + $databaseId = $database['body']['$id']; + + // Create table + $table = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables", $headers, [ + 'tableId' => ID::unique(), + 'name' => 'Spatial Distance Meters Table', + 'rowSecurity' => true, + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + ]); + $tableId = $table['body']['$id']; + + // Create point column + $resp = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/columns/point", $headers, [ + 'key' => 'loc', + 'required' => true, + ]); + $this->assertEquals(202, $resp['headers']['status-code']); + + sleep(2); + + // Create spatial index + $indexResp = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/indexes", $headers, [ + 'key' => 'idx_loc', + 'type' => Database::INDEX_SPATIAL, + 'columns' => ['loc'], + ]); + $this->assertEquals(202, $indexResp['headers']['status-code']); + + + // Insert two points ~1km apart + $points = [ + 'p0' => [0.0000, 0.0000], + 'p1' => [0.0090, 0.0000] + ]; + + foreach ($points as $id => $loc) { + $rowResp = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", $headers, [ + 'rowId' => $id, + 'data' => ['loc' => $loc] + ]); + $this->assertEquals(201, $rowResp['headers']['status-code']); + } + + // Queries + $queries = [ + 'within1_5km' => Query::distanceLessThan('loc', [0.0, 0.0], 1500, true), + 'within500m' => Query::distanceLessThan('loc', [0.0, 0.0], 500, true), + 'greater500m' => Query::distanceGreaterThan('loc', [0.0, 0.0], 500, true), + 'equal0m' => Query::distanceEqual('loc', [0.0, 0.0], 0, true), + 'notEqual0m' => Query::distanceNotEqual('loc', [0.0, 0.0], 0, true), + ]; + + // Assertions + $results = [ + 'within1_5km' => 2, + 'within500m' => 1, + 'greater500m' => 1, + 'equal0m' => 'p0', + 'notEqual0m' => 'p1' + ]; + + foreach ($queries as $key => $query) { + $resp = $this->client->call(Client::METHOD_GET, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", $headers, [ + 'queries' => [$query->toString()] + ]); + $this->assertEquals(200, $resp['headers']['status-code']); + if (is_int($results[$key])) { + $this->assertCount($results[$key], $resp['body']['rows']); + } else { + $this->assertEquals($results[$key], $resp['body']['rows'][0]['$id']); + } + } + + // Cleanup + $this->client->call(Client::METHOD_DELETE, "/tablesdb/{$databaseId}/tables/{$tableId}", $headers); + $this->client->call(Client::METHOD_DELETE, "/tablesdb/{$databaseId}", $headers); + } + } diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php index 74f8a0432d..0f68d9ea7b 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php @@ -6399,7 +6399,7 @@ class DatabasesCustomServerTest extends Scope ], ]); - $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals(400, $response['headers']['status-code']); // Test 4c: Missing required location (should fail) $response = $this->client->call(Client::METHOD_POST, "/tablesdb/{$databaseId}/tables/{$tableId}/rows", array_merge([ @@ -6682,8 +6682,7 @@ class DatabasesCustomServerTest extends Scope ], ]); - // Single point linestrings are accepted as arrays; creation should succeed - $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals(400, $response['headers']['status-code']); // Cleanup $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId, array_merge([ From 72f5ac26fc2b63e78c6ed39ad82eb845dc604f30 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 2 Sep 2025 23:04:42 +0530 Subject: [PATCH 26/50] updated composer --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index f6490134d8..c22b7f4b05 100644 --- a/composer.lock +++ b/composer.lock @@ -3638,16 +3638,16 @@ }, { "name": "utopia-php/database", - "version": "1.2.3", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "8a536fead840d9da6ee819fe6b80e0f047997f69" + "reference": "06ffa2b1c977f5451200a1ee82a500be1390a789" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/8a536fead840d9da6ee819fe6b80e0f047997f69", - "reference": "8a536fead840d9da6ee819fe6b80e0f047997f69", + "url": "https://api.github.com/repos/utopia-php/database/zipball/06ffa2b1c977f5451200a1ee82a500be1390a789", + "reference": "06ffa2b1c977f5451200a1ee82a500be1390a789", "shasum": "" }, "require": { @@ -3688,9 +3688,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/1.2.3" + "source": "https://github.com/utopia-php/database/tree/1.3.0" }, - "time": "2025-08-27T11:47:04+00:00" + "time": "2025-09-02T16:20:02+00:00" }, { "name": "utopia-php/detector", From 044e68499b9f7ae38bff61b0045482aa23fb38e9 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 2 Sep 2025 23:08:01 +0530 Subject: [PATCH 27/50] update composer --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 03202639f0..c22b7f4b05 100644 --- a/composer.lock +++ b/composer.lock @@ -4190,16 +4190,16 @@ }, { "name": "utopia-php/migration", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "0e4499d9dd2c90c2be188cc5fb7a32d9a892b569" + "reference": "38171023efd3abe650d2abc5ac65f5df52311da6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/0e4499d9dd2c90c2be188cc5fb7a32d9a892b569", - "reference": "0e4499d9dd2c90c2be188cc5fb7a32d9a892b569", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/38171023efd3abe650d2abc5ac65f5df52311da6", + "reference": "38171023efd3abe650d2abc5ac65f5df52311da6", "shasum": "" }, "require": { @@ -4240,9 +4240,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.0.0" + "source": "https://github.com/utopia-php/migration/tree/1.0.1" }, - "time": "2025-08-13T09:15:53+00:00" + "time": "2025-08-28T13:41:25+00:00" }, { "name": "utopia-php/orchestration", From 0d77a33cf1be2fe97cc4ab23a6de6dab18e25edf Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 00:40:04 +0530 Subject: [PATCH 28/50] updated update endpoint to spatial appwrite validator --- .../Databases/Http/TablesDB/Tables/Columns/Point/Update.php | 2 +- tests/e2e/Services/Databases/TablesDB/DatabasesBase.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php index dedc90f312..230750b23d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php @@ -7,10 +7,10 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Spatial; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; -use Utopia\Database\Validator\Spatial; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index 0246188a7a..ada7a73301 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -8284,7 +8284,6 @@ trait DatabasesBase 'default' => json_encode([0, 0]), 'required' => false ]); - $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals([0, 0], $response['body']['default']); From 0f6b4e07d518fd8785a5553e8f6a8da9810b1fe8 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 00:41:12 +0530 Subject: [PATCH 29/50] updated validator for the create polygon --- .../Http/Databases/Collections/Attributes/Polygon/Create.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php index a2d9f68b40..4f66f8bb79 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php @@ -13,7 +13,7 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; -use Utopia\Database\Validator\Spatial; +use Appwrite\Utopia\Database\Validator\Spatial; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; From 2755fd1fe6a4df52345bb93630845c9fa0e77d69 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 00:47:05 +0530 Subject: [PATCH 30/50] updated graphql mappers --- src/Appwrite/GraphQL/Types/Mapper.php | 1 + .../Http/Databases/Collections/Attributes/Polygon/Create.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/GraphQL/Types/Mapper.php b/src/Appwrite/GraphQL/Types/Mapper.php index e0916da558..244a0c0ccb 100644 --- a/src/Appwrite/GraphQL/Types/Mapper.php +++ b/src/Appwrite/GraphQL/Types/Mapper.php @@ -58,6 +58,7 @@ class Mapper 'json' => Types::json(), 'none' => Types::json(), 'any' => Types::json(), + 'spatial' => Types::json(), ]; foreach ($defaults as $type => $default) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php index 4f66f8bb79..5ef77fd32f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php @@ -9,11 +9,11 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Spatial; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; -use Appwrite\Utopia\Database\Validator\Spatial; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; From a8bbac4800a2e2d2d81f90594d909ee0a462b7f8 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k <83803257+ArnabChatterjee20k@users.noreply.github.com> Date: Wed, 3 Sep 2025 17:50:23 +0530 Subject: [PATCH 31/50] Update src/Appwrite/Utopia/Database/Validator/Spatial.php Co-authored-by: Jake Barnby --- src/Appwrite/Utopia/Database/Validator/Spatial.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Appwrite/Utopia/Database/Validator/Spatial.php b/src/Appwrite/Utopia/Database/Validator/Spatial.php index 3c28b66ce7..ed896ce875 100644 --- a/src/Appwrite/Utopia/Database/Validator/Spatial.php +++ b/src/Appwrite/Utopia/Database/Validator/Spatial.php @@ -32,7 +32,6 @@ class Spatial extends JSON */ public function isValid($value): bool { - if (!parent::isValid($value)) { return false; } From 28b0d95d05b930d2b0d0f4c54145ef3f30786ed0 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k <83803257+ArnabChatterjee20k@users.noreply.github.com> Date: Wed, 3 Sep 2025 17:50:38 +0530 Subject: [PATCH 32/50] Update app/config/errors.php Co-authored-by: Jake Barnby --- app/config/errors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/errors.php b/app/config/errors.php index a54eedf3c9..e179a1a838 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -844,7 +844,7 @@ return [ Exception::ATTRIBUTE_TYPE_NOT_SUPPORTED => [ 'name' => Exception::ATTRIBUTE_TYPE_NOT_SUPPORTED, - 'description' => "Attribute type not supported by the adapter.", + 'description' => 'Attribute type is not supported.', 'code' => 400, ], From 8734125a738afc478792e63890e7f2da3aec18b4 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k <83803257+ArnabChatterjee20k@users.noreply.github.com> Date: Wed, 3 Sep 2025 17:50:50 +0530 Subject: [PATCH 33/50] Update app/config/errors.php Co-authored-by: Jake Barnby --- app/config/errors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/errors.php b/app/config/errors.php index e179a1a838..156af5db8f 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -908,7 +908,7 @@ return [ ], Exception::COLUMN_TYPE_NOT_SUPPORTED => [ 'name' => Exception::COLUMN_TYPE_NOT_SUPPORTED, - 'description' => "Column type not supported by the adapter.", + 'description' => 'Column type is not supported.', 'code' => 400, ], From 4895865a01d65b4726175bc0290007547e515824 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 17:58:25 +0530 Subject: [PATCH 34/50] removed redundant comments from ai + removed spatial type conditions --- .../Databases/Http/Databases/Collections/Indexes/Create.php | 2 -- src/Appwrite/Utopia/Response/Model/AttributeLine.php | 4 ---- src/Appwrite/Utopia/Response/Model/AttributePoint.php | 4 ---- src/Appwrite/Utopia/Response/Model/AttributePolygon.php | 4 ---- src/Appwrite/Utopia/Response/Model/ColumnLine.php | 4 ---- src/Appwrite/Utopia/Response/Model/ColumnPoint.php | 4 ---- src/Appwrite/Utopia/Response/Model/ColumnPolygon.php | 4 ---- 7 files changed, 26 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php index c5a429a79b..733259f091 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php @@ -190,8 +190,6 @@ class Create extends Action 'orders' => $orders, ]); - // Determine adapter capabilities. For TablesDB, be permissive to accept requests - // and let the background worker enforce engine-specific constraints. $maxIndexLength = $dbForProject->getAdapter()->getMaxIndexLength(); $internalIndexesKeys = $dbForProject->getAdapter()->getInternalIndexesKeys(); $supportForIndexArray = $dbForProject->getAdapter()->getSupportForIndexArray(); diff --git a/src/Appwrite/Utopia/Response/Model/AttributeLine.php b/src/Appwrite/Utopia/Response/Model/AttributeLine.php index 6e0586e8b4..a4d9c75672 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeLine.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeLine.php @@ -21,10 +21,6 @@ class AttributeLine extends Attribute ; } - public array $conditions = [ - 'type' => 'linestring' - ]; - /** * Get Name * diff --git a/src/Appwrite/Utopia/Response/Model/AttributePoint.php b/src/Appwrite/Utopia/Response/Model/AttributePoint.php index 4a13054d96..47b83cc58b 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributePoint.php +++ b/src/Appwrite/Utopia/Response/Model/AttributePoint.php @@ -21,10 +21,6 @@ class AttributePoint extends Attribute ; } - public array $conditions = [ - 'type' => 'point' - ]; - /** * Get Name * diff --git a/src/Appwrite/Utopia/Response/Model/AttributePolygon.php b/src/Appwrite/Utopia/Response/Model/AttributePolygon.php index c28d8f66ed..8ef7f4ab73 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributePolygon.php +++ b/src/Appwrite/Utopia/Response/Model/AttributePolygon.php @@ -21,10 +21,6 @@ class AttributePolygon extends Attribute ; } - public array $conditions = [ - 'type' => 'polygon' - ]; - /** * Get Name * diff --git a/src/Appwrite/Utopia/Response/Model/ColumnLine.php b/src/Appwrite/Utopia/Response/Model/ColumnLine.php index 08bd66ce9c..01a6c6fe02 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnLine.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnLine.php @@ -21,10 +21,6 @@ class ColumnLine extends Column ; } - public array $conditions = [ - 'type' => 'linestring' - ]; - /** * Get Name * diff --git a/src/Appwrite/Utopia/Response/Model/ColumnPoint.php b/src/Appwrite/Utopia/Response/Model/ColumnPoint.php index ffc6ed6789..6ec5229011 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnPoint.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnPoint.php @@ -21,10 +21,6 @@ class ColumnPoint extends Column ; } - public array $conditions = [ - 'type' => 'point' - ]; - /** * Get Name * diff --git a/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php b/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php index 9b3a6f1030..6a9a14d548 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnPolygon.php @@ -21,10 +21,6 @@ class ColumnPolygon extends Column ; } - public array $conditions = [ - 'type' => 'polygon' - ]; - /** * Get Name * From 12d2c804312391db32b9e1faea6cb99cd62ec17a Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 18:03:46 +0530 Subject: [PATCH 35/50] replaced table with collection --- .../Http/Databases/Collections/Attributes/Line/Create.php | 2 +- .../Http/Databases/Collections/Attributes/Point/Create.php | 2 +- .../Http/Databases/Collections/Attributes/Polygon/Create.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php index ce2452bba1..9062bf87a2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php @@ -61,7 +61,7 @@ class Create extends Action ), )) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('collectionId', '', new UID(), 'Collection ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') + ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') ->param('default', null, new Nullable(new Spatial(Database::VAR_LINESTRING)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php index 08dbda651a..6af656ce05 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php @@ -61,7 +61,7 @@ class Create extends Action ), )) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('collectionId', '', new UID(), 'Collection ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') + ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php index 5ef77fd32f..b661dbdb87 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php @@ -61,7 +61,7 @@ class Create extends Action ), )) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('collectionId', '', new UID(), 'Collection ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') + ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) From e904fa6f9d3cb79d3a020b0ca1a679419b9a0703 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 18:05:28 +0530 Subject: [PATCH 36/50] overwrite decodedDefault with the default --- .../Http/Databases/Collections/Attributes/Line/Create.php | 2 +- .../Http/Databases/Collections/Attributes/Line/Update.php | 4 ++-- .../Http/Databases/Collections/Attributes/Point/Create.php | 4 ++-- .../Http/Databases/Collections/Attributes/Point/Update.php | 4 ++-- .../Http/Databases/Collections/Attributes/Polygon/Create.php | 4 ++-- .../Http/Databases/Collections/Attributes/Polygon/Update.php | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php index 9062bf87a2..1d26e1676c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php @@ -74,7 +74,7 @@ class Create extends Action public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void { - $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; + $default = \is_string($default) ? \json_decode($default, true) : $default; $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php index c9bdb7d02b..b1aa827091 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Update.php @@ -74,7 +74,7 @@ class Update extends Action public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void { - $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; + $default = \is_string($default) ? \json_decode($default, true) : $default; $attribute = $this->updateAttribute( databaseId: $databaseId, @@ -83,7 +83,7 @@ class Update extends Action dbForProject: $dbForProject, queueForEvents: $queueForEvents, type: Database::VAR_LINESTRING, - default: $decodedDefault, + default: $default, required: $required, newKey: $newKey ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php index 6af656ce05..4cc520f34e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php @@ -74,13 +74,13 @@ class Create extends Action public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void { - $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; + $default = \is_string($default) ? \json_decode($default, true) : $default; $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, 'type' => Database::VAR_POINT, 'required' => $required, - 'default' => $decodedDefault, + 'default' => $default, ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); $response diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php index 02b8bff2e5..222da133b2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Update.php @@ -74,7 +74,7 @@ class Update extends Action public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void { - $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; + $default = \is_string($default) ? \json_decode($default, true) : $default; $attribute = $this->updateAttribute( databaseId: $databaseId, @@ -83,7 +83,7 @@ class Update extends Action dbForProject: $dbForProject, queueForEvents: $queueForEvents, type: Database::VAR_POINT, - default: $decodedDefault, + default: $default, required: $required, newKey: $newKey ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php index b661dbdb87..99ef5fda88 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php @@ -74,13 +74,13 @@ class Create extends Action public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void { - $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; + $default = \is_string($default) ? \json_decode($default, true) : $default; $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, 'type' => Database::VAR_POLYGON, 'required' => $required, - 'default' => $decodedDefault, + 'default' => $default, ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); $response diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php index 9faee180f0..c5604f4e86 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php @@ -73,7 +73,7 @@ class Update extends Action public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void { - $decodedDefault = \is_string($default) ? \json_decode($default, true) : $default; + $default = \is_string($default) ? \json_decode($default, true) : $default; $attribute = $this->updateAttribute( databaseId: $databaseId, @@ -82,7 +82,7 @@ class Update extends Action dbForProject: $dbForProject, queueForEvents: $queueForEvents, type: Database::VAR_POLYGON, - default: $decodedDefault, + default: $default, required: $required, newKey: $newKey ); From a9138d7e8dfe76d308af1e8b87fefa6cec19bdb6 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 18:06:25 +0530 Subject: [PATCH 37/50] overwrite decodedDefault with default --- .../Http/Databases/Collections/Attributes/Line/Create.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php index 1d26e1676c..cfc46a97df 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php @@ -80,7 +80,7 @@ class Create extends Action 'key' => $key, 'type' => Database::VAR_LINESTRING, 'required' => $required, - 'default' => $decodedDefault + 'default' => $default ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); $response From 2004ed55a5ec9dc49dff8d57b1648ca93019cf3a Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 18:11:49 +0530 Subject: [PATCH 38/50] reset readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f2afe3a86..9cd5808e33 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -> We just announced Opt-in relationship loading for Appwrite Databases - [Learn more](https://appwrite.io/blog/post/announcing-opt-in-relationship-loading) +> We just announced Timestamp Overrides for Appwrite Databases - [Learn more](https://appwrite.io/blog/post/announcing-timestamp-overrides) > Appwrite Cloud is now Generally Available - [Learn more](https://appwrite.io/cloud-ga) From 39fc7e996b27b200565751c6343951b1b1194787 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 18:18:22 +0530 Subject: [PATCH 39/50] changed database service to tablesdb service for all tablesdb --- .../Databases/Http/TablesDB/Tables/Columns/Line/Create.php | 2 +- .../Databases/Http/TablesDB/Tables/Columns/Line/Update.php | 2 +- .../Databases/Http/TablesDB/Tables/Columns/Point/Create.php | 2 +- .../Databases/Http/TablesDB/Tables/Columns/Point/Update.php | 2 +- .../Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php | 2 +- .../Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php index 4777b99398..32cafae529 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php @@ -53,7 +53,7 @@ class Create extends LineCreate ] )) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') + ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') ->param('default', null, new Nullable(new Spatial(Database::VAR_LINESTRING)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php index 65910b62f7..9aea87ec42 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Update.php @@ -55,7 +55,7 @@ class Update extends LineUpdate contentType: ContentType::JSON )) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') + ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') ->param('default', null, new Nullable(new Spatial(Database::VAR_LINESTRING)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php index d0cc9a34d3..3615531b89 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php @@ -53,7 +53,7 @@ class Create extends PointCreate ] )) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') + ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php index 230750b23d..d2b741d4c7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Update.php @@ -55,7 +55,7 @@ class Update extends PointUpdate contentType: ContentType::JSON )) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') + ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php index d261c4ec14..dc16258596 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php @@ -53,7 +53,7 @@ class Create extends PolygonCreate ] )) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') + ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php index 7e06aafdca..aba20fca63 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Update.php @@ -55,7 +55,7 @@ class Update extends PolygonUpdate contentType: ContentType::JSON )) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') + ->param('tableId', '', new UID(), 'Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).') ->param('key', '', new Key(), 'Column Key.') ->param('required', null, new Boolean(), 'Is column required?') ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for column when not provided, as JSON string. Cannot be set when column is required.', true) From dd15023a2b276260a966bf738397f479da96a771 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 18:35:42 +0530 Subject: [PATCH 40/50] used import --- .../Http/Databases/Collections/Attributes/Polygon/Update.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php index c5604f4e86..0b056a26fb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Update.php @@ -15,6 +15,7 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Swoole\Response as SwooleResponse; +use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; class Update extends Action @@ -62,7 +63,7 @@ class Update extends Action ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).') ->param('key', '', new Key(), 'Attribute Key.') - ->param('required', null, new \Utopia\Validator\Boolean(), 'Is attribute required?') + ->param('required', null, new Boolean(), 'Is attribute required?') ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.', true) ->param('newKey', null, new Key(), 'New attribute key.', true) ->inject('response') From 5a6955debd2bf19fad879c5656cecda19ae25356 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 18:38:06 +0530 Subject: [PATCH 41/50] typo fix --- src/Appwrite/Utopia/Database/Validator/Spatial.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Utopia/Database/Validator/Spatial.php b/src/Appwrite/Utopia/Database/Validator/Spatial.php index ed896ce875..65ba9b83b8 100644 --- a/src/Appwrite/Utopia/Database/Validator/Spatial.php +++ b/src/Appwrite/Utopia/Database/Validator/Spatial.php @@ -2,7 +2,7 @@ namespace Appwrite\Utopia\Database\Validator; -use Utopia\Database\Validator\Spatial as SpatialVaildator; +use Utopia\Database\Validator\Spatial as SpatialValidator; use Utopia\Validator\JSON; class Spatial extends JSON @@ -36,7 +36,7 @@ class Spatial extends JSON return false; } $value = \json_decode($value, true); - $validator = new SpatialVaildator($this->spatialAttributeType); + $validator = new SpatialValidator($this->spatialAttributeType); return $validator->isValid($value); } } From a2e9ee73dc6b52629ebaeb6f63d642d505cdd92c Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 19:36:24 +0530 Subject: [PATCH 42/50] bulk upsert support --- .../Collections/Documents/Bulk/Upsert.php | 18 ++++++- .../Http/TablesDB/Tables/Rows/Bulk/Upsert.php | 4 ++ .../Realtime/RealtimeCustomClientTest.php | 50 +++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php index 3c6e5ddc57..bc26d4b4ad 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php @@ -2,6 +2,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Bulk; +use Appwrite\Event\Event; use Appwrite\Event\StatsUsage; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Action; @@ -74,11 +75,15 @@ class Upsert extends Action ->inject('response') ->inject('dbForProject') ->inject('queueForStatsUsage') + ->inject('queueForEvents') + ->inject('queueForRealtime') + ->inject('queueForFunctions') + ->inject('queueForWebhooks') ->inject('plan') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, array $documents, UtopiaResponse $response, Database $dbForProject, StatsUsage $queueForStatsUsage, array $plan): void + public function action(string $databaseId, string $collectionId, array $documents, UtopiaResponse $response, Database $dbForProject, StatsUsage $queueForStatsUsage, Event $queueForEvents, Event $queueForRealtime, Event $queueForFunctions, Event $queueForWebhooks, array $plan): void { $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { @@ -141,5 +146,16 @@ class Upsert extends Action 'total' => $modified, $this->getSdkGroup() => $upserted ]), $this->getResponseModel()); + + $this->triggerBulk( + 'databases.[databaseId].collections.[collectionId].documents.[documentId].upsert', + $database, + $collection, + $documents, + $queueForEvents, + $queueForRealtime, + $queueForFunctions, + $queueForWebhooks + ); } } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Bulk/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Bulk/Upsert.php index c4a7c6e677..26c5c8030c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Bulk/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Bulk/Upsert.php @@ -61,6 +61,10 @@ class Upsert extends DocumentsUpsert ->inject('response') ->inject('dbForProject') ->inject('queueForStatsUsage') + ->inject('queueForEvents') + ->inject('queueForRealtime') + ->inject('queueForFunctions') + ->inject('queueForWebhooks') ->inject('plan') ->callback($this->action(...)); } diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php index 60f58bd8ee..3121f9b45f 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php @@ -1188,6 +1188,56 @@ class RealtimeCustomClientTest extends Scope $this->assertArrayHasKey('$permissions', $response['data']['payload']); $this->assertIsArray($response['data']['payload']['$permissions']); + // bulk upsert + $this->client->call(Client::METHOD_PUT, "/databases/{$databaseId}/collections/{$actorsId}/documents", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'documents' => [ + [ + '$id' => ID::unique(), + 'name' => 'Robert Downey Jr.', + '$permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + ] + ], + ]); + + $response = json_decode($client->receive(), true); + $response = json_decode($client->receive(), true); + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('event', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertArrayHasKey('timestamp', $response['data']); + $this->assertCount(6, $response['data']['channels']); + + $this->assertContains("databases.{$databaseId}.collections.{$actorsId}.documents.{$response['data']['payload']['$id']}.upsert", $response['data']['events']); + $this->assertContains("databases.*.collections.*.documents.*.upsert", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.*.documents.*.upsert", $response['data']['events']); + $this->assertContains("databases.*.collections.{$actorsId}.documents.*.upsert", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.{$actorsId}.documents.*", $response['data']['events']); + $this->assertContains("databases.*.collections.*.documents.*", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.*.documents.*", $response['data']['events']); + $this->assertContains("databases.*.collections.{$actorsId}.documents.*", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.{$actorsId}", $response['data']['events']); + $this->assertContains("databases.*.collections.*", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.*", $response['data']['events']); + $this->assertContains("databases.*.collections.{$actorsId}", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.*.documents.*.upsert", $response['data']['events']); + $this->assertContains("databases.*", $response['data']['events']); + + $this->assertNotEmpty($response['data']['payload']); + $this->assertIsArray($response['data']['payload']); + $this->assertArrayHasKey('$id', $response['data']['payload']); + $this->assertArrayHasKey('name', $response['data']['payload']); + $this->assertArrayHasKey('$permissions', $response['data']['payload']); + $this->assertIsArray($response['data']['payload']['$permissions']); + $client->close(); } From b7a0f5399470a121dd533390fcae5b33b8f067a5 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 19:43:33 +0530 Subject: [PATCH 43/50] updated tests --- tests/e2e/Services/Realtime/RealtimeCustomClientTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php index 3121f9b45f..e83680db1e 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php @@ -1207,7 +1207,6 @@ class RealtimeCustomClientTest extends Scope ], ]); - $response = json_decode($client->receive(), true); $response = json_decode($client->receive(), true); $this->assertArrayHasKey('type', $response); $this->assertArrayHasKey('data', $response); From fdeb8c48c5c350d86cd09e04ea663df52bd4ff27 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 3 Sep 2025 19:53:20 +0530 Subject: [PATCH 44/50] added permission upsert test --- .../Realtime/RealtimeCustomClientTest.php | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php index e83680db1e..3e57c5e9bc 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php @@ -1693,6 +1693,107 @@ class RealtimeCustomClientTest extends Scope $this->assertIsArray($response2['data']['payload']['$permissions']); } + // bulk upsert + $this->client->call(Client::METHOD_PUT, "/databases/{$databaseId}/collections/{$actorsId}/documents", array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'documents' => [ + [ + '$id' => ID::unique(), + 'name' => 'Robert Downey Jr.', + '$permissions' => [ + Permission::read(Role::user($user1Id)), + ], + ], + [ + '$id' => ID::unique(), + 'name' => 'Thor', + '$permissions' => [ + Permission::read(Role::user($user2Id)), + ], + ] + ], + ]); + + $response = json_decode($client1->receive(), true); + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('event', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertArrayHasKey('timestamp', $response['data']); + $this->assertCount(6, $response['data']['channels']); + + $this->assertContains("databases.{$databaseId}.collections.{$actorsId}.documents.{$response['data']['payload']['$id']}.upsert", $response['data']['events']); + $this->assertContains("databases.*.collections.*.documents.*.upsert", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.*.documents.*.upsert", $response['data']['events']); + $this->assertContains("databases.*.collections.{$actorsId}.documents.*.upsert", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.{$actorsId}.documents.*", $response['data']['events']); + $this->assertContains("databases.*.collections.*.documents.*", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.*.documents.*", $response['data']['events']); + $this->assertContains("databases.*.collections.{$actorsId}.documents.*", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.{$actorsId}", $response['data']['events']); + $this->assertContains("databases.*.collections.*", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.*", $response['data']['events']); + $this->assertContains("databases.*.collections.{$actorsId}", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.*.documents.*.upsert", $response['data']['events']); + $this->assertContains("databases.*", $response['data']['events']); + + $this->assertNotEmpty($response['data']['payload']); + $this->assertIsArray($response['data']['payload']); + $this->assertArrayHasKey('$id', $response['data']['payload']); + $this->assertArrayHasKey('name', $response['data']['payload']); + $this->assertArrayHasKey('$permissions', $response['data']['payload']); + $this->assertIsArray($response['data']['payload']['$permissions']); + + // client1 shouldnot receive more than 1 event + try { + json_decode(json_decode($client1->receive(), true)); + $this->fail('Expected TimeoutException was not thrown.'); + } catch (Exception $e) { + $this->assertInstanceOf(TimeoutException::class, $e); + } + + $response = json_decode($client2->receive(), true); + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('event', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertArrayHasKey('timestamp', $response['data']); + $this->assertCount(6, $response['data']['channels']); + + $this->assertContains("databases.{$databaseId}.collections.{$actorsId}.documents.{$response['data']['payload']['$id']}.upsert", $response['data']['events']); + $this->assertContains("databases.*.collections.*.documents.*.upsert", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.*.documents.*.upsert", $response['data']['events']); + $this->assertContains("databases.*.collections.{$actorsId}.documents.*.upsert", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.{$actorsId}.documents.*", $response['data']['events']); + $this->assertContains("databases.*.collections.*.documents.*", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.*.documents.*", $response['data']['events']); + $this->assertContains("databases.*.collections.{$actorsId}.documents.*", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.{$actorsId}", $response['data']['events']); + $this->assertContains("databases.*.collections.*", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.*", $response['data']['events']); + $this->assertContains("databases.*.collections.{$actorsId}", $response['data']['events']); + $this->assertContains("databases.{$databaseId}.collections.*.documents.*.upsert", $response['data']['events']); + $this->assertContains("databases.*", $response['data']['events']); + + $this->assertNotEmpty($response['data']['payload']); + $this->assertIsArray($response['data']['payload']); + $this->assertArrayHasKey('$id', $response['data']['payload']); + $this->assertArrayHasKey('name', $response['data']['payload']); + $this->assertArrayHasKey('$permissions', $response['data']['payload']); + $this->assertIsArray($response['data']['payload']['$permissions']); + + // client2 shouldnot receive more than 1 event + try { + json_decode(json_decode($client2->receive(), true)); + $this->fail('Expected TimeoutException was not thrown.'); + } catch (Exception $e) { + $this->assertInstanceOf(TimeoutException::class, $e); + } + + $client1->close(); $client2->close(); } From 52f8cb75cac4133d019bfd4573cfe9c27ffa6c2c Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k <83803257+ArnabChatterjee20k@users.noreply.github.com> Date: Wed, 3 Sep 2025 20:27:23 +0530 Subject: [PATCH 45/50] Update Upsert.php --- .../Http/Databases/Collections/Documents/Bulk/Upsert.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php index bc26d4b4ad..395e3d757b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php @@ -151,7 +151,7 @@ class Upsert extends Action 'databases.[databaseId].collections.[collectionId].documents.[documentId].upsert', $database, $collection, - $documents, + $upserted, $queueForEvents, $queueForRealtime, $queueForFunctions, From b75952071e18e21f4379c35d87a3fae7ae5cc2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 3 Sep 2025 17:32:15 +0200 Subject: [PATCH 46/50] Support array headers for set-cookie --- app/controllers/general.php | 62 +++++++++++++++++++------------- docker-compose.yml | 2 +- src/Appwrite/Utopia/Response.php | 16 +++++++-- src/Executor/Executor.php | 12 +++++-- 4 files changed, 61 insertions(+), 31 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 40ce66b574..46913d2d96 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -562,15 +562,18 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw cpus: $spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT, memory: $spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT, logging: $resource->getAttribute('logging', true), - requestTimeout: 30 + requestTimeout: 30, + responseFormat: Executor::RESPONSE_FORMAT_ARRAY_HEADERS ); + $headerOverrides = []; + // Branded 404 override $isResponseBranded = false; if ($executionResponse['statusCode'] === 404 && $deployment->getAttribute('adapter', '') === 'static') { $layout = new View(__DIR__ . '/../views/general/404.phtml'); $executionResponse['body'] = $layout->render(); - $executionResponse['headers']['content-length'] = \strlen($executionResponse['body']); + $headerOverrides['content-length'] = \strlen($executionResponse['body']); $isResponseBranded = true; } @@ -580,15 +583,16 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $transformation = new Transformation(); $transformation->addAdapter(new Preview()); $transformation->setInput($executionResponse['body']); - $transformation->setTraits($executionResponse['headers']); + + $simpleHeaders = []; + foreach ($executionResponse['headers'] as $key => $value) { + $simpleHeaders[$key] = \is_array($value) ? \implode(', ', $value) : $value; + } + + $transformation->setTraits($simpleHeaders); if ($isPreview && $transformation->transform()) { $executionResponse['body'] = $transformation->getOutput(); - - foreach ($executionResponse['headers'] as $key => $value) { - if (\strtolower($key) === 'content-length') { - $executionResponse['headers'][$key] = \strlen($executionResponse['body']); - } - } + $headerOverrides['content-length'] = \strlen($executionResponse['body']); } } } @@ -602,25 +606,33 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw ->setParam('code', $executionResponse['statusCode']); $executionResponse['body'] = $layout->render(); - foreach ($executionResponse['headers'] as $key => $value) { - if (\strtolower($key) === 'content-length') { - $executionResponse['headers'][$key] = \strlen($executionResponse['body']); - } elseif (\strtolower($key) === 'content-type') { - $executionResponse['headers'][$key] = 'text/html'; - } - } + + $headerOverrides['content-length'] = \strlen($executionResponse['body']); + $headerOverrides['content-type'] = 'text/html'; } if ($deployment->getAttribute('resourceType') === 'functions') { - $executionResponse['headers']['x-appwrite-execution-id'] = $execution->getId(); + $headerOverrides['x-appwrite-execution-id'] = $execution->getId(); } elseif ($deployment->getAttribute('resourceType') === 'sites') { - $executionResponse['headers']['x-appwrite-log-id'] = $execution->getId(); + $headerOverrides['x-appwrite-log-id'] = $execution->getId(); + } + + foreach ($headerOverrides as $key => $value) { + if (\array_key_exists($key, $executionResponse['headers'])) { + if (\is_array($executionResponse['headers'][$key])) { + $executionResponse['headers'][$key][] = $value; + } else { + $executionResponse['headers'][$key] = [$executionResponse['headers'][$key], $value]; + } + } else { + $executionResponse['headers'][$key] = $value; + } } $headersFiltered = []; foreach ($executionResponse['headers'] as $key => $value) { if (\in_array(\strtolower($key), FUNCTION_ALLOWLIST_HEADERS_RESPONSE)) { - $headersFiltered[] = ['name' => $key, 'value' => $value]; + $headersFiltered[] = ['name' => $key, 'value' => \is_array($value) ? \implode(', ', $value) : $value]; } } @@ -687,7 +699,7 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $headers = []; foreach (($executionResponse['headers'] ?? []) as $key => $value) { - $headers[] = ['name' => $key, 'value' => $value]; + $headers[] = ['name' => $key, 'value' => \is_array($value) ? \implode(', ', $value) : $value]; } $execution->setAttribute('responseBody', $executionResponse['body'] ?? ''); @@ -696,16 +708,16 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $body = $execution['responseBody'] ?? ''; $contentType = 'text/plain'; - foreach ($execution['responseHeaders'] as $header) { - if (\strtolower($header['name']) === 'content-type') { - $contentType = $header['value']; + foreach ($executionResponse['headers'] as $name => $values) { + if (\strtolower($name) === 'content-type') { + $contentType = $values[0] ?? 'text/plain'; } - if (\strtolower($header['name']) === 'transfer-encoding') { + if (\strtolower($name) === 'transfer-encoding') { continue; } - $response->addHeader(\strtolower($header['name']), $header['value']); + $response->setHeader($name, $values); } $response diff --git a/docker-compose.yml b/docker-compose.yml index 87385aa086..4ab62832d6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -966,7 +966,7 @@ services: hostname: exc1 <<: *x-logging stop_signal: SIGINT - image: openruntimes/executor:0.8.1 + image: tmpexecutor restart: unless-stopped networks: - appwrite diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 35c43ef07c..4a59ce77ad 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -411,6 +411,8 @@ class Response extends SwooleResponse */ protected static bool $showSensitive = false; + protected SwooleHTTPResponse $swoole; + /** * Response constructor. * @@ -418,6 +420,8 @@ class Response extends SwooleResponse */ public function __construct(SwooleHTTPResponse $response) { + $this->swoole = $response; + $this // General ->setModel(new None()) @@ -955,12 +959,18 @@ class Response extends SwooleResponse * Set Header * * @param string $key - * @param string $value + * @param string|array $value * @return void */ - public function setHeader(string $key, string $value): void + public function setHeader(string $key, mixed $value): void { - $this->sendHeader($key, $value); + if (is_array($value)) { + // Temporary solution to support proxying Set-cookie (2 cookies, 1 name) + // Ideally this would live in http library, supporting array of values in all adapters + $this->swoole->header($key, $value); + } else { + $this->sendHeader($key, $value); + } } /** diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index df4c5fd8f5..30c6132b76 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -9,6 +9,12 @@ use Utopia\System\System; class Executor { + // 0.8.6 is last version with object-based headers + public const RESPONSE_FORMAT_OBJECT_HEADERS = '0.10.0'; + + // 0.9.0 is first version with array-based headers + public const RESPONSE_FORMAT_ARRAY_HEADERS = '0.11.0'; + public const METHOD_GET = 'GET'; public const METHOD_POST = 'POST'; public const METHOD_PUT = 'PUT'; @@ -170,6 +176,7 @@ class Executor * @param string $entrypoint * @param string $runtimeEntrypoint * @param bool $logging + * @param string $responseFormat * * @return array */ @@ -190,7 +197,8 @@ class Executor int $memory, bool $logging, string $runtimeEntrypoint = '', - ?int $requestTimeout = null + ?int $requestTimeout = null, + string $responseFormat = self::RESPONSE_FORMAT_OBJECT_HEADERS ) { if (empty($headers['host'])) { $headers['host'] = System::getEnv('_APP_DOMAIN', ''); @@ -232,7 +240,7 @@ class Executor $requestTimeout = $timeout + 15; } - $response = $this->call($this->endpoint, self::METHOD_POST, $route, [ 'x-opr-runtime-id' => $runtimeId, 'content-type' => 'multipart/form-data', 'accept' => 'multipart/form-data' ], $params, true, $requestTimeout); + $response = $this->call($this->endpoint, self::METHOD_POST, $route, [ 'x-opr-runtime-id' => $runtimeId, 'content-type' => 'multipart/form-data', 'accept' => 'multipart/form-data', 'x-executor-response-format' => $responseFormat ], $params, true, $requestTimeout); $status = $response['headers']['status-code']; if ($status >= 400) { From 128a35bd4d7676f8571c7e21ad2d6dc09ab09ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 3 Sep 2025 17:36:35 +0200 Subject: [PATCH 47/50] Use executor 0.11.0 --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4ab62832d6..da6362b4c4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -966,7 +966,7 @@ services: hostname: exc1 <<: *x-logging stop_signal: SIGINT - image: tmpexecutor + image: openruntimes/executor:0.11.0 restart: unless-stopped networks: - appwrite From 10cfc159042cd57002c1b501a5055e0150616cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 3 Sep 2025 17:49:10 +0200 Subject: [PATCH 48/50] Add set-cookie tests --- tests/e2e/Services/Sites/SitesCustomServerTest.php | 6 ++++-- tests/resources/sites/astro/src/pages/cookies.js | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index d28e2fe8b4..c8301b9428 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2775,11 +2775,13 @@ class SitesCustomServerTest extends Scope $proxyClient->setEndpoint('http://' . $domain); $response = $proxyClient->call(Client::METHOD_GET, '/cookies', [ - 'cookie' => 'custom-session-id=abcd123' + 'cookie' => 'custom-session-id=abcd123; custom-user-id=efgh456' ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals("abcd123", $response['body']); + $this->assertEquals("abcd123;efgh456", $response['body']); + $this->assertEquals("value-one", $response['cookies']['my-cookie-one']); + $this->assertEquals("value-two", $response['cookies']['my-cookie-two']); $this->cleanupSite($siteId); } diff --git a/tests/resources/sites/astro/src/pages/cookies.js b/tests/resources/sites/astro/src/pages/cookies.js index 5f5efac833..65911c8aeb 100644 --- a/tests/resources/sites/astro/src/pages/cookies.js +++ b/tests/resources/sites/astro/src/pages/cookies.js @@ -1,4 +1,9 @@ export async function GET(context) { const sessionId = context.cookies.get("custom-session-id")?.value ?? 'Custom session ID missing'; - return new Response(sessionId); + const userId = context.cookies.get("custom-user-id")?.value ?? 'Custom user ID missing'; + + context.cookies.set('my-cookie-one', 'value-one'); + context.cookies.set('my-cookie-two', 'value-two'); + + return new Response(sessionId + ";" + userId); } From f6308b34774355e334444eda8a4031395d9c664e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 3 Sep 2025 17:57:12 +0200 Subject: [PATCH 49/50] AI code quality fixes --- app/controllers/general.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/general.php b/app/controllers/general.php index 46913d2d96..b4ad7917cd 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -711,6 +711,7 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw foreach ($executionResponse['headers'] as $name => $values) { if (\strtolower($name) === 'content-type') { $contentType = $values[0] ?? 'text/plain'; + continue; } if (\strtolower($name) === 'transfer-encoding') { From 5c5c4e432f869bbb738baeeeef54aa75f35eb0ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 3 Sep 2025 18:04:58 +0200 Subject: [PATCH 50/50] Fix content type header --- app/controllers/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index b4ad7917cd..50d56ff9fd 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -710,7 +710,7 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $contentType = 'text/plain'; foreach ($executionResponse['headers'] as $name => $values) { if (\strtolower($name) === 'content-type') { - $contentType = $values[0] ?? 'text/plain'; + $contentType = \is_array($values) ? $values[0] : $values; continue; }