From 065a0fddae12966f0d513219362652009a3f6129 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 12 Mar 2026 13:41:00 +0000 Subject: [PATCH 001/211] Add backup policy migration support --- src/Appwrite/Platform/Workers/Migrations.php | 60 +++++++++++--------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index e2185a6676..359d533c21 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -309,6 +309,39 @@ class Migrations extends Action ); } + /** + * @return array + */ + protected function getAPIKeyScopes(): array + { + return [ + 'users.read', + 'users.write', + 'teams.read', + 'teams.write', + 'buckets.read', + 'buckets.write', + 'files.read', + 'files.write', + 'functions.read', + 'functions.write', + 'sites.read', + 'sites.write', + 'tokens.read', + 'tokens.write', + 'providers.read', + 'providers.write', + 'topics.read', + 'topics.write', + 'subscribers.read', + 'subscribers.write', + 'messages.read', + 'messages.write', + 'targets.read', + 'targets.write', + ]; + } + /** * @throws Exception */ @@ -329,32 +362,7 @@ class Migrations extends Action METRIC_NETWORK_INBOUND, METRIC_NETWORK_OUTBOUND, ], - 'scopes' => [ - 'users.read', - 'users.write', - 'teams.read', - 'teams.write', - 'buckets.read', - 'buckets.write', - 'files.read', - 'files.write', - 'functions.read', - 'functions.write', - 'sites.read', - 'sites.write', - 'tokens.read', - 'tokens.write', - 'providers.read', - 'providers.write', - 'topics.read', - 'topics.write', - 'subscribers.read', - 'subscribers.write', - 'messages.read', - 'messages.write', - 'targets.read', - 'targets.write', - ] + 'scopes' => $this->getAPIKeyScopes() ]); return API_KEY_DYNAMIC . '_' . $apiKey; From 6128a049f2b17dcb231d03ae3832dce9d04d6595 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 24 Mar 2026 13:33:05 +0000 Subject: [PATCH 002/211] Point migration dep to feature branch --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 65838a1615..5e743b82f0 100644 --- a/composer.json +++ b/composer.json @@ -73,7 +73,7 @@ "utopia-php/locale": "0.8.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.20.*", - "utopia-php/migration": "1.8.*", + "utopia-php/migration": "dev-backup-migration-multitype as 1.8.0", "utopia-php/platform": "0.7.*", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", From bd03ec7a500cb2f042b85a6a366951ec6a10bec4 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 24 Mar 2026 13:36:42 +0000 Subject: [PATCH 003/211] Update composer.lock for migration feature branch --- composer.lock | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/composer.lock b/composer.lock index 7a30e2f265..fab609ba6a 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": "f9225f2b580de0ccb796b2fb8c881384", + "content-hash": "baa3a90aacf18e57e2025e79eb6cbf64", "packages": [ { "name": "adhocore/jwt", @@ -4518,16 +4518,16 @@ }, { "name": "utopia-php/migration", - "version": "1.8.3", + "version": "dev-backup-migration-multitype", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "8633523b3343d492427331b6eec53f020f6ab7a7" + "reference": "0075ba97a64dca8885a7d767aab036269bf826f0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/8633523b3343d492427331b6eec53f020f6ab7a7", - "reference": "8633523b3343d492427331b6eec53f020f6ab7a7", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/0075ba97a64dca8885a7d767aab036269bf826f0", + "reference": "0075ba97a64dca8885a7d767aab036269bf826f0", "shasum": "" }, "require": { @@ -4567,9 +4567,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.8.3" + "source": "https://github.com/utopia-php/migration/tree/backup-migration-multitype" }, - "time": "2026-03-19T09:18:47+00:00" + "time": "2026-03-24T11:53:33+00:00" }, { "name": "utopia-php/mongo", @@ -8433,9 +8433,18 @@ "time": "2024-11-07T12:36:22+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/migration", + "version": "dev-backup-migration-multitype", + "alias": "1.8.0", + "alias_normalized": "1.8.0.0" + } + ], "minimum-stability": "dev", - "stability-flags": {}, + "stability-flags": { + "utopia-php/migration": 20 + }, "prefer-stable": true, "prefer-lowest": false, "platform": { From 2838642bae059f050f1a63aec5c4e44c1971b3c2 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 24 Mar 2026 17:09:27 +0000 Subject: [PATCH 004/211] Add policies.read/write scopes to test API key --- tests/e2e/Scopes/ProjectCustom.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index b7037267c5..d32ab25c03 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -163,6 +163,8 @@ trait ProjectCustom 'tokens.write', 'webhooks.read', 'webhooks.write', + 'policies.read', + 'policies.write', 'project.read', 'project.write' ], From d993214810e6e6e4cc54516ff7efe4635b7c372a Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 24 Mar 2026 17:22:31 +0000 Subject: [PATCH 005/211] Revert "Add policies.read/write scopes to test API key" This reverts commit 2838642bae059f050f1a63aec5c4e44c1971b3c2. --- tests/e2e/Scopes/ProjectCustom.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index d32ab25c03..b7037267c5 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -163,8 +163,6 @@ trait ProjectCustom 'tokens.write', 'webhooks.read', 'webhooks.write', - 'policies.read', - 'policies.write', 'project.read', 'project.write' ], From 03c73ac0aab0b66116065540341e904854dd7880 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 15:50:59 +0530 Subject: [PATCH 006/211] added big int attributes --- composer.json | 4 +- composer.lock | 48 ++++--- .../databases/create-bigint-attribute.md | 1 + .../databases/update-bigint-attribute.md | 1 + .../Collections/Attributes/BigInt/Create.php | 120 ++++++++++++++++++ .../Collections/Attributes/BigInt/Update.php | 106 ++++++++++++++++ .../Databases/Services/Registry/Legacy.php | 6 + 7 files changed, 268 insertions(+), 18 deletions(-) create mode 100644 docs/references/databases/create-bigint-attribute.md create mode 100644 docs/references/databases/update-bigint-attribute.md create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php diff --git a/composer.json b/composer.json index 65838a1615..ba7d89d6ed 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "utopia-php/compression": "0.1.*", "utopia-php/config": "1.*", "utopia-php/console": "0.1.*", - "utopia-php/database": "5.*", + "utopia-php/database": "dev-big-init as 5.7", "utopia-php/agents": "1.*", "utopia-php/detector": "0.2.*", "utopia-php/domains": "1.*", @@ -73,7 +73,7 @@ "utopia-php/locale": "0.8.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.20.*", - "utopia-php/migration": "1.8.*", + "utopia-php/migration": "dev-big-int as 1.8.6", "utopia-php/platform": "0.7.*", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", diff --git a/composer.lock b/composer.lock index 1441bf06d1..036415e843 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": "f9225f2b580de0ccb796b2fb8c881384", + "content-hash": "4bdbec3c3569eac8ed04d24a71ddaa34", "packages": [ { "name": "adhocore/jwt", @@ -3850,16 +3850,16 @@ }, { "name": "utopia-php/database", - "version": "5.3.17", + "version": "dev-big-init", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "cff2b6ed63d3291b74110d086e16ff089fe05993" + "reference": "ef5c77972a95129eb929cce6c8f7c674db930ec9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/cff2b6ed63d3291b74110d086e16ff089fe05993", - "reference": "cff2b6ed63d3291b74110d086e16ff089fe05993", + "url": "https://api.github.com/repos/utopia-php/database/zipball/ef5c77972a95129eb929cce6c8f7c674db930ec9", + "reference": "ef5c77972a95129eb929cce6c8f7c674db930ec9", "shasum": "" }, "require": { @@ -3903,9 +3903,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/5.3.17" + "source": "https://github.com/utopia-php/database/tree/big-init" }, - "time": "2026-03-20T01:18:52+00:00" + "time": "2026-03-30T06:31:05+00:00" }, { "name": "utopia-php/detector", @@ -4518,16 +4518,16 @@ }, { "name": "utopia-php/migration", - "version": "1.8.3", + "version": "dev-big-int", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "8633523b3343d492427331b6eec53f020f6ab7a7" + "reference": "9e8708883677661ac568ba41f7a0b79cd6f04253" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/8633523b3343d492427331b6eec53f020f6ab7a7", - "reference": "8633523b3343d492427331b6eec53f020f6ab7a7", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/9e8708883677661ac568ba41f7a0b79cd6f04253", + "reference": "9e8708883677661ac568ba41f7a0b79cd6f04253", "shasum": "" }, "require": { @@ -4536,7 +4536,7 @@ "ext-openssl": "*", "halaxa/json-machine": "^1.2", "php": ">=8.1", - "utopia-php/database": "5.*", + "utopia-php/database": "dev-big-init as 5.4", "utopia-php/dsn": "0.2.*", "utopia-php/storage": "1.0.*" }, @@ -4567,9 +4567,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.8.3" + "source": "https://github.com/utopia-php/migration/tree/big-int" }, - "time": "2026-03-19T09:18:47+00:00" + "time": "2026-03-30T10:03:42+00:00" }, { "name": "utopia-php/mongo", @@ -8433,9 +8433,25 @@ "time": "2024-11-07T12:36:22+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-big-init", + "alias": "5.7", + "alias_normalized": "5.7.0.0" + }, + { + "package": "utopia-php/migration", + "version": "dev-big-int", + "alias": "1.8.6", + "alias_normalized": "1.8.6.0" + } + ], "minimum-stability": "dev", - "stability-flags": {}, + "stability-flags": { + "utopia-php/database": 20, + "utopia-php/migration": 20 + }, "prefer-stable": true, "prefer-lowest": false, "platform": { diff --git a/docs/references/databases/create-bigint-attribute.md b/docs/references/databases/create-bigint-attribute.md new file mode 100644 index 0000000000..6fb607304b --- /dev/null +++ b/docs/references/databases/create-bigint-attribute.md @@ -0,0 +1 @@ +Create a bigint attribute. Optionally, minimum and maximum values can be provided. diff --git a/docs/references/databases/update-bigint-attribute.md b/docs/references/databases/update-bigint-attribute.md new file mode 100644 index 0000000000..4a301c2216 --- /dev/null +++ b/docs/references/databases/update-bigint-attribute.md @@ -0,0 +1 @@ +Update a bigint attribute. Changing the `default` value will not update already existing documents. diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php new file mode 100644 index 0000000000..ecae3c3db3 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php @@ -0,0 +1,120 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_POST) + ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/bigint') + ->desc('Create bigint attribute') + ->groups(['api', 'database', 'schema']) + ->label('scope', 'collections.write') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('event', 'databases.[databaseId].collections.[collectionId].attributes.[attributeId].create') + ->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-bigint-attribute.md', + auth: [AuthType::ADMIN, AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_ACCEPTED, + model: $this->getResponseModel(), + ) + ], + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createIntegerColumn', + ), + )) + ->param('databaseId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Database ID.', false, ['dbForProject']) + ->param('collectionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Collection ID.', false, ['dbForProject']) + ->param('key', '', fn (Database $dbForProject) => new Key(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Attribute Key.', false, ['dbForProject']) + ->param('required', null, new Boolean(), 'Is attribute required?') + ->param('min', null, new Nullable(new Integer(false, 64)), 'Minimum value', true) + ->param('max', null, new Nullable(new Integer(false, 64)), 'Maximum value', true) + ->param('default', null, new Nullable(new Integer(false, 64)), 'Default value. Cannot be set when attribute is required.', true) + ->param('array', false, new Boolean(), 'Is attribute an array?', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForDatabase') + ->inject('queueForEvents') + ->inject('authorization') + ->callback($this->action(...)); + } + + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?int $min, ?int $max, ?int $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + { + $min ??= \PHP_INT_MIN; + $max ??= \PHP_INT_MAX; + + if ($min > $max) { + throw new Exception($this->getInvalidValueException(), 'Minimum value must be lesser than maximum value'); + } + + $validator = new Range($min, $max, Database::VAR_INTEGER); + if (!\is_null($default) && !$validator->isValid($default)) { + throw new Exception($this->getInvalidValueException(), $validator->getDescription()); + } + + // `bigint` is always stored as a 64-bit integer. + $size = 8; + + $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ + 'key' => $key, + 'type' => Database::VAR_INTEGER, + 'size' => $size, + 'required' => $required, + 'default' => $default, + 'array' => $array, + 'format' => APP_DATABASE_ATTRIBUTE_INT_RANGE, + 'formatOptions' => ['min' => $min, 'max' => $max], + ]), $response, $dbForProject, $queueForDatabase, $queueForEvents, $authorization); + + $formatOptions = $attribute->getAttribute('formatOptions', []); + if (!empty($formatOptions)) { + $attribute->setAttribute('min', \intval($formatOptions['min'])); + $attribute->setAttribute('max', \intval($formatOptions['max'])); + } + + $response + ->setStatusCode(SwooleResponse::STATUS_CODE_ACCEPTED) + ->dynamic($attribute, $this->getResponseModel()); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php new file mode 100644 index 0000000000..2010b51208 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php @@ -0,0 +1,106 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/bigint/:key') + ->desc('Update bigint 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-bigint-attribute.md', + auth: [AuthType::ADMIN, 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.updateIntegerColumn', + ), + )) + ->param('databaseId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Database ID.', false, ['dbForProject']) + ->param('collectionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Collection ID.', false, ['dbForProject']) + ->param('key', '', fn (Database $dbForProject) => new Key(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Attribute Key.', false, ['dbForProject']) + ->param('required', null, new Boolean(), 'Is attribute required?') + ->param('min', null, new Nullable(new Integer(false, 64)), 'Minimum value', true) + ->param('max', null, new Nullable(new Integer(false, 64)), 'Maximum value', true) + ->param('default', null, new Nullable(new Integer(false, 64)), 'Default value. Cannot be set when attribute is required.') + ->param('newKey', null, fn (Database $dbForProject) => new Nullable(new Key(false, $dbForProject->getAdapter()->getMaxUIDLength())), 'New Attribute Key.', true, ['dbForProject']) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForEvents') + ->inject('authorization') + ->callback($this->action(...)); + } + + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?int $min, ?int $max, ?int $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents, Authorization $authorization): void + { + $attribute = $this->updateAttribute( + databaseId: $databaseId, + collectionId: $collectionId, + key: $key, + dbForProject: $dbForProject, + queueForEvents: $queueForEvents, + authorization: $authorization, + type: Database::VAR_INTEGER, + default: $default, + required: $required, + min: $min, + max: $max, + newKey: $newKey + ); + + $formatOptions = $attribute->getAttribute('formatOptions', []); + if (!empty($formatOptions)) { + $attribute->setAttribute('min', \intval($formatOptions['min'])); + $attribute->setAttribute('max', \intval($formatOptions['max'])); + } + + $response + ->setStatusCode(SwooleResponse::STATUS_CODE_OK) + ->dynamic($attribute, $this->getResponseModel()); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Legacy.php b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Legacy.php index a8d2205236..a2fba9efb3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Legacy.php +++ b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Legacy.php @@ -2,6 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Services\Registry; +use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\BigInt\Create as CreateBigIntAttribute; +use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\BigInt\Update as UpdateBigIntAttribute; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Boolean\Create as CreateBooleanAttribute; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Boolean\Update as UpdateBooleanAttribute; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Datetime\Create as CreateDatetimeAttribute; @@ -171,6 +173,10 @@ class Legacy extends Base $service->addAction(CreateIntegerAttribute::getName(), new CreateIntegerAttribute()); $service->addAction(UpdateIntegerAttribute::getName(), new UpdateIntegerAttribute()); + // Attribute: BigInt + $service->addAction(CreateBigIntAttribute::getName(), new CreateBigIntAttribute()); + $service->addAction(UpdateBigIntAttribute::getName(), new UpdateBigIntAttribute()); + // Attribute: IP $service->addAction(CreateIPAttribute::getName(), new CreateIPAttribute()); $service->addAction(UpdateIPAttribute::getName(), new UpdateIPAttribute()); From ffa3f741ed41525b5080cd57c3ca4bbb353df73d Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 15:53:06 +0530 Subject: [PATCH 007/211] added bigint columns --- .../tablesdb/create-bigint-column.md | 1 + .../tablesdb/update-bigint-column.md | 1 + .../TablesDB/Tables/Columns/BigInt/Create.php | 70 ++++++++++++++++++ .../TablesDB/Tables/Columns/BigInt/Update.php | 71 +++++++++++++++++++ .../Databases/Services/Registry/TablesDB.php | 6 ++ 5 files changed, 149 insertions(+) create mode 100644 docs/references/tablesdb/create-bigint-column.md create mode 100644 docs/references/tablesdb/update-bigint-column.md create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php diff --git a/docs/references/tablesdb/create-bigint-column.md b/docs/references/tablesdb/create-bigint-column.md new file mode 100644 index 0000000000..7bbbb5aac6 --- /dev/null +++ b/docs/references/tablesdb/create-bigint-column.md @@ -0,0 +1 @@ +Create a bigint column. Optionally, minimum and maximum values can be provided. diff --git a/docs/references/tablesdb/update-bigint-column.md b/docs/references/tablesdb/update-bigint-column.md new file mode 100644 index 0000000000..0dde070f6f --- /dev/null +++ b/docs/references/tablesdb/update-bigint-column.md @@ -0,0 +1 @@ +Update a bigint column. Changing the `default` value will not update already existing rows. diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php new file mode 100644 index 0000000000..514e13aa32 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php @@ -0,0 +1,70 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_POST) + ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/bigint') + ->desc('Create bigint column') + ->groups(['api', 'database', 'schema']) + ->label('scope', ['tables.write', 'collections.write']) + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') + ->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-bigint-column.md', + auth: [AuthType::ADMIN, AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_ACCEPTED, + model: $this->getResponseModel(), + ) + ] + )) + ->param('databaseId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Database ID.', false, ['dbForProject']) + ->param('tableId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Table ID.', false, ['dbForProject']) + ->param('key', '', fn (Database $dbForProject) => new Key(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Column Key.', false, ['dbForProject']) + ->param('required', null, new Boolean(), 'Is column required?') + ->param('min', null, new Nullable(new Integer(false, 64)), 'Minimum value', true) + ->param('max', null, new Nullable(new Integer(false, 64)), 'Maximum value', true) + ->param('default', null, new Nullable(new Integer(false, 64)), 'Default value. Cannot be set when column is required.', true) + ->param('array', false, new Boolean(), 'Is column an array?', true) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForDatabase') + ->inject('queueForEvents') + ->inject('authorization') + ->callback($this->action(...)); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php new file mode 100644 index 0000000000..6f4343cbc9 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php @@ -0,0 +1,71 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/bigint/:key') + ->desc('Update bigint column') + ->groups(['api', 'database', 'schema']) + ->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') + ->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-bigint-column.md', + auth: [AuthType::ADMIN, AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: $this->getResponseModel(), + ) + ], + contentType: ContentType::JSON + )) + ->param('databaseId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Database ID.', false, ['dbForProject']) + ->param('tableId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Table ID.', false, ['dbForProject']) + ->param('key', '', fn (Database $dbForProject) => new Key(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Column Key.', false, ['dbForProject']) + ->param('required', null, new Boolean(), 'Is column required?') + ->param('min', null, new Nullable(new Integer(false, 64)), 'Minimum value', true) + ->param('max', null, new Nullable(new Integer(false, 64)), 'Maximum value', true) + ->param('default', null, new Nullable(new Integer(false, 64)), 'Default value. Cannot be set when column is required.') + ->param('newKey', null, fn (Database $dbForProject) => new Nullable(new Key(false, $dbForProject->getAdapter()->getMaxUIDLength())), 'New Column Key.', true, ['dbForProject']) + ->inject('response') + ->inject('dbForProject') + ->inject('queueForEvents') + ->inject('authorization') + ->callback($this->action(...)); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Services/Registry/TablesDB.php b/src/Appwrite/Platform/Modules/Databases/Services/Registry/TablesDB.php index 965e0929fb..765fbd4421 100644 --- a/src/Appwrite/Platform/Modules/Databases/Services/Registry/TablesDB.php +++ b/src/Appwrite/Platform/Modules/Databases/Services/Registry/TablesDB.php @@ -5,6 +5,8 @@ namespace Appwrite\Platform\Modules\Databases\Services\Registry; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Create as CreateTablesDatabase; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Delete as DeleteTablesDatabase; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Get as GetTablesDatabase; +use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\BigInt\Create as CreateBigInt; +use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\BigInt\Update as UpdateBigInt; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Boolean\Create as CreateBoolean; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Boolean\Update as UpdateBoolean; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Datetime\Create as CreateDatetime; @@ -151,6 +153,10 @@ class TablesDB extends Base $service->addAction(CreateInteger::getName(), new CreateInteger()); $service->addAction(UpdateInteger::getName(), new UpdateInteger()); + // Column: BigInt + $service->addAction(CreateBigInt::getName(), new CreateBigInt()); + $service->addAction(UpdateBigInt::getName(), new UpdateBigInt()); + // Column: IP $service->addAction(CreateIP::getName(), new CreateIP()); $service->addAction(UpdateIP::getName(), new UpdateIP()); From 01db1efbc48bd3a30410c0ee1230db6939feeae7 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 16:08:21 +0530 Subject: [PATCH 008/211] added tests --- .../TablesDB/DatabasesNumericTypesTest.php | 400 ++++++++++++++++++ 1 file changed, 400 insertions(+) create mode 100644 tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php diff --git a/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php b/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php new file mode 100644 index 0000000000..d341681a65 --- /dev/null +++ b/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php @@ -0,0 +1,400 @@ +getProject()['$id'] ?? 'default'; + if (!empty(static::$setupCache[$cacheKey])) { + return static::$setupCache[$cacheKey]; + } + + $projectId = $this->getProject()['$id']; + $apiKey = $this->getProject()['apiKey']; + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]; + + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', $headers, [ + 'databaseId' => ID::unique(), + 'name' => 'Numeric Types Test Database', + ]); + + $this->assertEquals(201, $database['headers']['status-code']); + $databaseId = $database['body']['$id']; + + $table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', $headers, [ + 'tableId' => ID::unique(), + 'name' => 'Numeric Types Table', + 'rowSecurity' => true, + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + ], + ]); + + $this->assertEquals(201, $table['headers']['status-code']); + $tableId = $table['body']['$id']; + + // Create integer column + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer', $headers, [ + 'key' => 'integer_field', + 'required' => false, + 'min' => -10, + 'max' => 10, + 'default' => 0, + ]); + + // Create bigint column + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/bigint', $headers, [ + 'key' => 'bigint_field', + 'required' => false, + 'min' => -900719925, + 'max' => 900719925, + 'default' => 123, + ]); + + // Cache before waiting so that if waitForAllAttributes times out, + // subsequent calls don't try to re-create the same columns (causing 409) + static::$setupCache[$cacheKey] = [ + 'databaseId' => $databaseId, + 'tableId' => $tableId, + ]; + + // Wait for all columns to be available + $this->waitForAllAttributes($databaseId, $tableId); + + return static::$setupCache[$cacheKey]; + } + + /** + * Setup database/table without caching so mutations (update/delete) don't + * affect other tests that might be executed in a different order. + */ + protected function setupFreshDatabaseAndTable(): array + { + $projectId = $this->getProject()['$id']; + $apiKey = $this->getProject()['apiKey']; + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]; + + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', $headers, [ + 'databaseId' => ID::unique(), + 'name' => 'Numeric Types Test Database', + ]); + + $this->assertEquals(201, $database['headers']['status-code']); + $databaseId = $database['body']['$id']; + + $table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', $headers, [ + 'tableId' => ID::unique(), + 'name' => 'Numeric Types Table', + 'rowSecurity' => true, + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + ], + ]); + + $this->assertEquals(201, $table['headers']['status-code']); + $tableId = $table['body']['$id']; + + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer', $headers, [ + 'key' => 'integer_field', + 'required' => false, + 'min' => -10, + 'max' => 10, + 'default' => 0, + ]); + + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/bigint', $headers, [ + 'key' => 'bigint_field', + 'required' => false, + 'min' => -900719925, + 'max' => 900719925, + 'default' => 123, + ]); + + $this->waitForAllAttributes($databaseId, $tableId); + + return [ + 'databaseId' => $databaseId, + 'tableId' => $tableId, + ]; + } + + public function testCreateDatabase(): 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' => 'Numeric Types Test Database', + ]); + + $this->assertEquals(201, $database['headers']['status-code']); + } + + public function testCreateTable(): void + { + $data = $this->setupDatabaseAndTable(); + + $table = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $data['databaseId'] . '/tables/' . $data['tableId'], [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(200, $table['headers']['status-code']); + $this->assertEquals($data['tableId'], $table['body']['$id']); + } + + public function testGetIntegerAndBigIntColumns(): void + { + $data = $this->setupDatabaseAndTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + + $integerColumn = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer_field', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(200, $integerColumn['headers']['status-code']); + $this->assertEquals('integer_field', $integerColumn['body']['key']); + $this->assertEquals('integer', $integerColumn['body']['type']); + $this->assertEquals(false, $integerColumn['body']['required']); + $this->assertEquals(false, $integerColumn['body']['array']); + $this->assertEquals(-10, $integerColumn['body']['min']); + $this->assertEquals(10, $integerColumn['body']['max']); + $this->assertEquals(0, $integerColumn['body']['default']); + + $bigintColumn = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/bigint_field', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(200, $bigintColumn['headers']['status-code']); + $this->assertEquals('bigint_field', $bigintColumn['body']['key']); + + // Some implementations may still represent bigint columns as integer internally. + $this->assertTrue(\in_array($bigintColumn['body']['type'], ['bigint', 'integer'], true)); + $this->assertEquals(false, $bigintColumn['body']['required']); + $this->assertEquals(false, $bigintColumn['body']['array']); + $this->assertEquals(-900719925, $bigintColumn['body']['min']); + $this->assertEquals(900719925, $bigintColumn['body']['max']); + $this->assertEquals(123, $bigintColumn['body']['default']); + } + + public function testListColumnsWithNumericTypes(): void + { + $data = $this->setupDatabaseAndTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + + $columns = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(200, $columns['headers']['status-code']); + $this->assertIsArray($columns['body']['columns']); + $this->assertGreaterThan(0, $columns['body']['total']); + + $columnKeys = array_map(fn ($col) => $col['key'], $columns['body']['columns']); + $this->assertContains('integer_field', $columnKeys); + $this->assertContains('bigint_field', $columnKeys); + + $columnTypeByKey = []; + foreach ($columns['body']['columns'] as $col) { + $columnTypeByKey[$col['key']] = $col['type']; + } + + $this->assertEquals('integer', $columnTypeByKey['integer_field']); + $this->assertTrue(\in_array($columnTypeByKey['bigint_field'], ['bigint', 'integer'], true)); + } + + public function testCreateRowWithIntegerAndBigIntTypes(): void + { + $data = $this->setupDatabaseAndTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + + $row = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + 'rowId' => ID::unique(), + 'data' => [ + 'integer_field' => 5, + 'bigint_field' => 456, + ], + 'permissions' => [ + Permission::read(Role::any()), + ], + ]); + + $this->assertEquals(201, $row['headers']['status-code']); + $this->assertEquals(5, $row['body']['integer_field']); + $this->assertEquals(456, $row['body']['bigint_field']); + } + + public function testUpdateIntegerAndBigIntColumns(): void + { + $data = $this->setupFreshDatabaseAndTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + + // Update integer column + $updateInteger = $this->client->call( + Client::METHOD_PATCH, + '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer_field', + [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], + [ + 'required' => false, + 'min' => -20, + 'max' => 20, + 'default' => 3, + ] + ); + + $this->assertEquals(200, $updateInteger['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $tableId) { + $column = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer_field', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(200, $column['headers']['status-code']); + $this->assertEquals(-20, $column['body']['min']); + $this->assertEquals(20, $column['body']['max']); + $this->assertEquals(3, $column['body']['default']); + }, 30000, 250); + + // Update bigint column + $updateBigint = $this->client->call( + Client::METHOD_PATCH, + '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/bigint_field', + [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], + [ + 'required' => false, + 'min' => -999, + 'max' => 999, + 'default' => 10, + ] + ); + + $this->assertEquals(200, $updateBigint['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $tableId) { + $column = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/bigint_field', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(200, $column['headers']['status-code']); + $this->assertEquals(-999, $column['body']['min']); + $this->assertEquals(999, $column['body']['max']); + $this->assertEquals(10, $column['body']['default']); + }, 30000, 250); + } + + public function testDeleteIntegerAndBigIntColumns(): void + { + $data = $this->setupFreshDatabaseAndTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + + // Delete integer column + $deleteInteger = $this->client->call( + Client::METHOD_DELETE, + '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer_field', + [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ] + ); + + $this->assertEquals(204, $deleteInteger['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $tableId) { + $column = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer_field', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(404, $column['headers']['status-code']); + }, 30000, 250); + + // Delete bigint column + $deleteBigint = $this->client->call( + Client::METHOD_DELETE, + '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/bigint_field', + [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ] + ); + + $this->assertEquals(204, $deleteBigint['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $tableId) { + $column = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/bigint_field', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(404, $column['headers']['status-code']); + }, 30000, 250); + } +} From a9ed74c6a83d52e30c719a733e0bbe48f20f05ec Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 16:11:42 +0530 Subject: [PATCH 009/211] added tests to migration --- tests/e2e/Services/Migrations/MigrationsBase.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 1e8b1f5ad3..0dc62a3be9 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1572,6 +1572,19 @@ trait MigrationsBase $this->assertEquals(202, $varchar['headers']['status-code']); + $bigint = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/bigint', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'key' => 'bigint', + 'min' => 0, + 'max' => 100000, + 'required' => false, + ]); + + $this->assertEquals(202, $bigint['headers']['status-code']); + $mediumtext = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/mediumtext', [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -1622,6 +1635,7 @@ trait MigrationsBase 'mediumtext' => 'mediumText', 'longtext' => 'longText', 'varchar' => 'varchar', + 'bigint' => $i * 1000, ] ]); @@ -1710,6 +1724,8 @@ trait MigrationsBase $this->assertStringContainsString('mediumText', $csvData, 'CSV should contain the medium column header'); $this->assertStringContainsString('longText', $csvData, 'CSV should contain the long text column header'); $this->assertStringContainsString('varchar', $csvData, 'CSV should contain the varchar column header'); + $this->assertStringContainsString('bigint', $csvData, 'CSV should contain the bigint column header'); + $this->assertStringContainsString('1000', $csvData, 'CSV should contain bigint test data'); // Cleanup $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, [ From 77d195f0c3edfc222e1eb3a33113e98ec28023c3 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 16:17:44 +0530 Subject: [PATCH 010/211] updated response models --- app/init/models.php | 4 +++ .../Collections/Attributes/BigInt/Create.php | 2 +- .../Collections/Attributes/BigInt/Update.php | 2 +- .../TablesDB/Tables/Columns/BigInt/Create.php | 2 +- .../TablesDB/Tables/Columns/BigInt/Update.php | 2 +- src/Appwrite/Utopia/Response.php | 2 ++ .../Utopia/Response/Model/AttributeBigInt.php | 31 +++++++++++++++++++ .../Utopia/Response/Model/AttributeList.php | 1 + .../Utopia/Response/Model/Collection.php | 1 + .../Utopia/Response/Model/ColumnBigInt.php | 31 +++++++++++++++++++ .../Utopia/Response/Model/ColumnList.php | 1 + src/Appwrite/Utopia/Response/Model/Table.php | 1 + 12 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 src/Appwrite/Utopia/Response/Model/AttributeBigInt.php create mode 100644 src/Appwrite/Utopia/Response/Model/ColumnBigInt.php diff --git a/app/init/models.php b/app/init/models.php index bf6d67dd95..794401375b 100644 --- a/app/init/models.php +++ b/app/init/models.php @@ -11,6 +11,7 @@ use Appwrite\Utopia\Response\Model\AlgoScryptModified; use Appwrite\Utopia\Response\Model\AlgoSha; use Appwrite\Utopia\Response\Model\Any; use Appwrite\Utopia\Response\Model\Attribute; +use Appwrite\Utopia\Response\Model\AttributeBigInt; use Appwrite\Utopia\Response\Model\AttributeBoolean; use Appwrite\Utopia\Response\Model\AttributeDatetime; use Appwrite\Utopia\Response\Model\AttributeEmail; @@ -37,6 +38,7 @@ use Appwrite\Utopia\Response\Model\Branch; use Appwrite\Utopia\Response\Model\Bucket; use Appwrite\Utopia\Response\Model\Collection; use Appwrite\Utopia\Response\Model\Column; +use Appwrite\Utopia\Response\Model\ColumnBigInt; use Appwrite\Utopia\Response\Model\ColumnBoolean; use Appwrite\Utopia\Response\Model\ColumnDatetime; use Appwrite\Utopia\Response\Model\ColumnEmail; @@ -232,6 +234,7 @@ Response::setModel(new Attribute()); Response::setModel(new AttributeList()); Response::setModel(new AttributeString()); Response::setModel(new AttributeInteger()); +Response::setModel(new AttributeBigInt()); Response::setModel(new AttributeFloat()); Response::setModel(new AttributeBoolean()); Response::setModel(new AttributeEmail()); @@ -265,6 +268,7 @@ Response::setModel(new Column()); Response::setModel(new ColumnList()); Response::setModel(new ColumnString()); Response::setModel(new ColumnInteger()); +Response::setModel(new ColumnBigInt()); Response::setModel(new ColumnFloat()); Response::setModel(new ColumnBoolean()); Response::setModel(new ColumnEmail()); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php index ecae3c3db3..f99ee38d91 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php @@ -31,7 +31,7 @@ class Create extends Action protected function getResponseModel(): string|array { - return UtopiaResponse::MODEL_ATTRIBUTE_INTEGER; + return UtopiaResponse::MODEL_ATTRIBUTE_BIGINT; } public function __construct() diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php index 2010b51208..8e4a060ace 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php @@ -28,7 +28,7 @@ class Update extends Action protected function getResponseModel(): string|array { - return UtopiaResponse::MODEL_ATTRIBUTE_INTEGER; + return UtopiaResponse::MODEL_ATTRIBUTE_BIGINT; } public function __construct() diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php index 514e13aa32..1b7b33291b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php @@ -24,7 +24,7 @@ class Create extends BigIntCreate protected function getResponseModel(): string|array { - return UtopiaResponse::MODEL_COLUMN_INTEGER; + return UtopiaResponse::MODEL_COLUMN_BIGINT; } public function __construct() diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php index 6f4343cbc9..387dd08238 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php @@ -25,7 +25,7 @@ class Update extends BigIntUpdate protected function getResponseModel(): string|array { - return UtopiaResponse::MODEL_COLUMN_INTEGER; + return UtopiaResponse::MODEL_COLUMN_BIGINT; } public function __construct() diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 99170a58c9..2f36270624 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -72,6 +72,7 @@ class Response extends SwooleResponse public const MODEL_ATTRIBUTE_LIST = 'attributeList'; public const MODEL_ATTRIBUTE_STRING = 'attributeString'; public const MODEL_ATTRIBUTE_INTEGER = 'attributeInteger'; + public const MODEL_ATTRIBUTE_BIGINT = 'attributeBigint'; public const MODEL_ATTRIBUTE_FLOAT = 'attributeFloat'; public const MODEL_ATTRIBUTE_BOOLEAN = 'attributeBoolean'; public const MODEL_ATTRIBUTE_EMAIL = 'attributeEmail'; @@ -95,6 +96,7 @@ class Response extends SwooleResponse public const MODEL_COLUMN_LIST = 'columnList'; public const MODEL_COLUMN_STRING = 'columnString'; public const MODEL_COLUMN_INTEGER = 'columnInteger'; + public const MODEL_COLUMN_BIGINT = 'columnBigint'; public const MODEL_COLUMN_FLOAT = 'columnFloat'; public const MODEL_COLUMN_BOOLEAN = 'columnBoolean'; public const MODEL_COLUMN_EMAIL = 'columnEmail'; diff --git a/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php b/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php new file mode 100644 index 0000000000..9e0d918fe0 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php @@ -0,0 +1,31 @@ + self::TYPE_INTEGER, + 'size' => 8, + ]; + + public function __construct() + { + parent::__construct(); + + // Update example for the `type` field + $this->rules['type']['example'] = 'bigint'; + } + + public function getName(): string + { + return 'AttributeBigInt'; + } + + public function getType(): string + { + return Response::MODEL_ATTRIBUTE_BIGINT; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/AttributeList.php b/src/Appwrite/Utopia/Response/Model/AttributeList.php index 50189a80c3..70459c3df1 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeList.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeList.php @@ -20,6 +20,7 @@ class AttributeList extends Model 'type' => [ Response::MODEL_ATTRIBUTE_BOOLEAN, Response::MODEL_ATTRIBUTE_INTEGER, + Response::MODEL_ATTRIBUTE_BIGINT, Response::MODEL_ATTRIBUTE_FLOAT, Response::MODEL_ATTRIBUTE_EMAIL, Response::MODEL_ATTRIBUTE_ENUM, diff --git a/src/Appwrite/Utopia/Response/Model/Collection.php b/src/Appwrite/Utopia/Response/Model/Collection.php index 4ab7de8e4d..7fe335cf09 100644 --- a/src/Appwrite/Utopia/Response/Model/Collection.php +++ b/src/Appwrite/Utopia/Response/Model/Collection.php @@ -63,6 +63,7 @@ class Collection extends Model 'type' => [ Response::MODEL_ATTRIBUTE_BOOLEAN, Response::MODEL_ATTRIBUTE_INTEGER, + Response::MODEL_ATTRIBUTE_BIGINT, Response::MODEL_ATTRIBUTE_FLOAT, Response::MODEL_ATTRIBUTE_EMAIL, Response::MODEL_ATTRIBUTE_ENUM, diff --git a/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php b/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php new file mode 100644 index 0000000000..9d7649f144 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php @@ -0,0 +1,31 @@ + self::TYPE_INTEGER, + 'size' => 8, + ]; + + public function __construct() + { + parent::__construct(); + + // Update example for the `type` field + $this->rules['type']['example'] = 'bigint'; + } + + public function getName(): string + { + return 'ColumnBigInt'; + } + + public function getType(): string + { + return Response::MODEL_COLUMN_BIGINT; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/ColumnList.php b/src/Appwrite/Utopia/Response/Model/ColumnList.php index e99223cd17..64cdbdcf07 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnList.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnList.php @@ -20,6 +20,7 @@ class ColumnList extends Model 'type' => [ Response::MODEL_COLUMN_BOOLEAN, Response::MODEL_COLUMN_INTEGER, + Response::MODEL_COLUMN_BIGINT, Response::MODEL_COLUMN_FLOAT, Response::MODEL_COLUMN_EMAIL, Response::MODEL_COLUMN_ENUM, diff --git a/src/Appwrite/Utopia/Response/Model/Table.php b/src/Appwrite/Utopia/Response/Model/Table.php index 20cd3ccca2..b08bc2e97c 100644 --- a/src/Appwrite/Utopia/Response/Model/Table.php +++ b/src/Appwrite/Utopia/Response/Model/Table.php @@ -64,6 +64,7 @@ class Table extends Model 'type' => [ Response::MODEL_COLUMN_BOOLEAN, Response::MODEL_COLUMN_INTEGER, + Response::MODEL_COLUMN_BIGINT, Response::MODEL_COLUMN_FLOAT, Response::MODEL_COLUMN_EMAIL, Response::MODEL_COLUMN_ENUM, From 89eb5c2254d44dab8106e09a2f2c9197e28f9362 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 17:14:38 +0530 Subject: [PATCH 011/211] Refactor response model attribute and column types to prioritize BigInt over Integer for more accurate type matching in AttributeList, Collection, ColumnList, and Table classes. --- src/Appwrite/Utopia/Response/Model/AttributeList.php | 4 +++- src/Appwrite/Utopia/Response/Model/Collection.php | 4 +++- src/Appwrite/Utopia/Response/Model/ColumnList.php | 4 +++- src/Appwrite/Utopia/Response/Model/Table.php | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Model/AttributeList.php b/src/Appwrite/Utopia/Response/Model/AttributeList.php index 70459c3df1..87d1dc8b9f 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeList.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeList.php @@ -19,8 +19,10 @@ class AttributeList extends Model ->addRule('attributes', [ 'type' => [ Response::MODEL_ATTRIBUTE_BOOLEAN, - Response::MODEL_ATTRIBUTE_INTEGER, + // BigInt must come before Integer: response model dispatch is "first match wins", + // and Integer matches all int types (including bigint), while BigInt is more specific (size=8). Response::MODEL_ATTRIBUTE_BIGINT, + Response::MODEL_ATTRIBUTE_INTEGER, Response::MODEL_ATTRIBUTE_FLOAT, Response::MODEL_ATTRIBUTE_EMAIL, Response::MODEL_ATTRIBUTE_ENUM, diff --git a/src/Appwrite/Utopia/Response/Model/Collection.php b/src/Appwrite/Utopia/Response/Model/Collection.php index 7fe335cf09..bc4de22858 100644 --- a/src/Appwrite/Utopia/Response/Model/Collection.php +++ b/src/Appwrite/Utopia/Response/Model/Collection.php @@ -62,8 +62,10 @@ class Collection extends Model ->addRule('attributes', [ 'type' => [ Response::MODEL_ATTRIBUTE_BOOLEAN, - Response::MODEL_ATTRIBUTE_INTEGER, + // BigInt must come before Integer: response model dispatch is "first match wins", + // and Integer matches all int types (including bigint), while BigInt is more specific (size=8). Response::MODEL_ATTRIBUTE_BIGINT, + Response::MODEL_ATTRIBUTE_INTEGER, Response::MODEL_ATTRIBUTE_FLOAT, Response::MODEL_ATTRIBUTE_EMAIL, Response::MODEL_ATTRIBUTE_ENUM, diff --git a/src/Appwrite/Utopia/Response/Model/ColumnList.php b/src/Appwrite/Utopia/Response/Model/ColumnList.php index 64cdbdcf07..0586015e4d 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnList.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnList.php @@ -19,8 +19,10 @@ class ColumnList extends Model ->addRule('columns', [ 'type' => [ Response::MODEL_COLUMN_BOOLEAN, - Response::MODEL_COLUMN_INTEGER, + // BigInt must come before Integer: response model dispatch is "first match wins", + // and Integer matches all int types (including bigint), while BigInt is more specific (size=8). Response::MODEL_COLUMN_BIGINT, + Response::MODEL_COLUMN_INTEGER, Response::MODEL_COLUMN_FLOAT, Response::MODEL_COLUMN_EMAIL, Response::MODEL_COLUMN_ENUM, diff --git a/src/Appwrite/Utopia/Response/Model/Table.php b/src/Appwrite/Utopia/Response/Model/Table.php index b08bc2e97c..f9f2804fe5 100644 --- a/src/Appwrite/Utopia/Response/Model/Table.php +++ b/src/Appwrite/Utopia/Response/Model/Table.php @@ -63,8 +63,10 @@ class Table extends Model ->addRule('columns', [ 'type' => [ Response::MODEL_COLUMN_BOOLEAN, - Response::MODEL_COLUMN_INTEGER, + // BigInt must come before Integer: response model dispatch is "first match wins", + // and Integer matches all int types (including bigint), while BigInt is more specific (size=8). Response::MODEL_COLUMN_BIGINT, + Response::MODEL_COLUMN_INTEGER, Response::MODEL_COLUMN_FLOAT, Response::MODEL_COLUMN_EMAIL, Response::MODEL_COLUMN_ENUM, From 5741041f33a543081e0654e6cd6a3682da18e842 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 17:32:49 +0530 Subject: [PATCH 012/211] updated tests --- tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php b/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php index d341681a65..66f08e6000 100644 --- a/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php +++ b/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php @@ -283,7 +283,7 @@ class DatabasesNumericTypesTest extends Scope // Update integer column $updateInteger = $this->client->call( Client::METHOD_PATCH, - '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer_field', + '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer/integer_field', [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -315,7 +315,7 @@ class DatabasesNumericTypesTest extends Scope // Update bigint column $updateBigint = $this->client->call( Client::METHOD_PATCH, - '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/bigint_field', + '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/bigint/bigint_field', [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], From 19487cf56b353cc797a088e9368818bf25a64ad0 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k <83803257+ArnabChatterjee20k@users.noreply.github.com> Date: Mon, 30 Mar 2026 17:34:36 +0530 Subject: [PATCH 013/211] Update src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- .../Http/Databases/Collections/Attributes/BigInt/Create.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php index f99ee38d91..6991b8ac16 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php @@ -58,9 +58,10 @@ class Create extends Action model: $this->getResponseModel(), ) ], + deprecated: new Deprecated( deprecated: new Deprecated( since: '1.8.0', - replaceWith: 'tablesDB.createIntegerColumn', + replaceWith: 'tablesDB.createBigIntColumn', ), )) ->param('databaseId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Database ID.', false, ['dbForProject']) From e5d818ba44294c14124d5961032c586e31423b1f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 17:38:24 +0530 Subject: [PATCH 014/211] updated --- .../Databases/Collections/Attributes/BigInt/Create.php | 2 +- .../Databases/Collections/Attributes/BigInt/Update.php | 2 +- tests/e2e/Services/Migrations/MigrationsBase.php | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php index f99ee38d91..1add0a6015 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php @@ -60,7 +60,7 @@ class Create extends Action ], deprecated: new Deprecated( since: '1.8.0', - replaceWith: 'tablesDB.createIntegerColumn', + replaceWith: 'tablesDB.createBigIntColumn', ), )) ->param('databaseId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Database ID.', false, ['dbForProject']) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php index 8e4a060ace..4c795527cb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php @@ -58,7 +58,7 @@ class Update extends Action contentType: ContentType::JSON, deprecated: new Deprecated( since: '1.8.0', - replaceWith: 'tablesDB.updateIntegerColumn', + replaceWith: 'tablesDB.updateBigIntColumn', ), )) ->param('databaseId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Database ID.', false, ['dbForProject']) diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 0dc62a3be9..fef0a6d577 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1578,8 +1578,8 @@ trait MigrationsBase 'x-appwrite-key' => $this->getProject()['apiKey'] ], [ 'key' => 'bigint', - 'min' => 0, - 'max' => 100000, + 'min' => 2147483648, + 'max' => 9223372036854775807, 'required' => false, ]); @@ -1635,7 +1635,7 @@ trait MigrationsBase 'mediumtext' => 'mediumText', 'longtext' => 'longText', 'varchar' => 'varchar', - 'bigint' => $i * 1000, + 'bigint' => 2147483648 + $i, ] ]); @@ -1725,7 +1725,7 @@ trait MigrationsBase $this->assertStringContainsString('longText', $csvData, 'CSV should contain the long text column header'); $this->assertStringContainsString('varchar', $csvData, 'CSV should contain the varchar column header'); $this->assertStringContainsString('bigint', $csvData, 'CSV should contain the bigint column header'); - $this->assertStringContainsString('1000', $csvData, 'CSV should contain bigint test data'); + $this->assertStringContainsString('2147483649', $csvData, 'CSV should contain bigint test data'); // Cleanup $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, [ From 819863559ef83697c14fa545de4e8535cb16358d Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 17:45:25 +0530 Subject: [PATCH 015/211] Enhance BigInt support across database attributes and validation, updating types and tests for consistency. --- .../Http/Databases/Collections/Attributes/Action.php | 8 +++++++- .../Databases/Collections/Attributes/BigInt/Create.php | 5 ++--- .../Databases/Collections/Attributes/BigInt/Update.php | 2 +- src/Appwrite/Utopia/Response/Model/AttributeBigInt.php | 2 +- src/Appwrite/Utopia/Response/Model/ColumnBigInt.php | 2 +- tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php | 5 ++--- 6 files changed, 14 insertions(+), 10 deletions(-) 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 0d562a2894..e4c02b40ce 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 @@ -237,6 +237,10 @@ abstract class Action extends UtopiaAction ? UtopiaResponse::MODEL_ATTRIBUTE_BOOLEAN : UtopiaResponse::MODEL_COLUMN_BOOLEAN, + Database::VAR_BIGINT => $isCollections + ? UtopiaResponse::MODEL_ATTRIBUTE_BIGINT + : UtopiaResponse::MODEL_COLUMN_BIGINT, + Database::VAR_INTEGER => $isCollections ? UtopiaResponse::MODEL_ATTRIBUTE_INTEGER : UtopiaResponse::MODEL_COLUMN_INTEGER, @@ -549,7 +553,9 @@ abstract class Action extends UtopiaAction } if ($attribute->getAttribute('format') === APP_DATABASE_ATTRIBUTE_INT_RANGE) { - $validator = new Range($min, $max, Database::VAR_INTEGER); + // Use bigint validator when updating a bigint attribute/column. + $rangeType = $type === Database::VAR_BIGINT ? Database::VAR_BIGINT : Database::VAR_INTEGER; + $validator = new Range($min, $max, $rangeType); } else { $validator = new Range($min, $max, Database::VAR_FLOAT); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php index 6991b8ac16..a7df055094 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php @@ -58,7 +58,6 @@ class Create extends Action model: $this->getResponseModel(), ) ], - deprecated: new Deprecated( deprecated: new Deprecated( since: '1.8.0', replaceWith: 'tablesDB.createBigIntColumn', @@ -89,7 +88,7 @@ class Create extends Action throw new Exception($this->getInvalidValueException(), 'Minimum value must be lesser than maximum value'); } - $validator = new Range($min, $max, Database::VAR_INTEGER); + $validator = new Range($min, $max, Database::VAR_BIGINT); if (!\is_null($default) && !$validator->isValid($default)) { throw new Exception($this->getInvalidValueException(), $validator->getDescription()); } @@ -99,7 +98,7 @@ class Create extends Action $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, - 'type' => Database::VAR_INTEGER, + 'type' => Database::VAR_BIGINT, 'size' => $size, 'required' => $required, 'default' => $default, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php index 4c795527cb..5d8e8bf3a5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Update.php @@ -85,7 +85,7 @@ class Update extends Action dbForProject: $dbForProject, queueForEvents: $queueForEvents, authorization: $authorization, - type: Database::VAR_INTEGER, + type: Database::VAR_BIGINT, default: $default, required: $required, min: $min, diff --git a/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php b/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php index 9e0d918fe0..2ab02991cb 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php @@ -7,7 +7,7 @@ use Appwrite\Utopia\Response; class AttributeBigInt extends AttributeInteger { public array $conditions = [ - 'type' => self::TYPE_INTEGER, + 'type' => 'bigint', 'size' => 8, ]; diff --git a/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php b/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php index 9d7649f144..0d8b71ee98 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php @@ -7,7 +7,7 @@ use Appwrite\Utopia\Response; class ColumnBigInt extends ColumnInteger { public array $conditions = [ - 'type' => self::TYPE_INTEGER, + 'type' => 'bigint', 'size' => 8, ]; diff --git a/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php b/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php index 66f08e6000..614a8f1f34 100644 --- a/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php +++ b/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php @@ -210,8 +210,7 @@ class DatabasesNumericTypesTest extends Scope $this->assertEquals(200, $bigintColumn['headers']['status-code']); $this->assertEquals('bigint_field', $bigintColumn['body']['key']); - // Some implementations may still represent bigint columns as integer internally. - $this->assertTrue(\in_array($bigintColumn['body']['type'], ['bigint', 'integer'], true)); + $this->assertEquals('bigint', $bigintColumn['body']['type']); $this->assertEquals(false, $bigintColumn['body']['required']); $this->assertEquals(false, $bigintColumn['body']['array']); $this->assertEquals(-900719925, $bigintColumn['body']['min']); @@ -245,7 +244,7 @@ class DatabasesNumericTypesTest extends Scope } $this->assertEquals('integer', $columnTypeByKey['integer_field']); - $this->assertTrue(\in_array($columnTypeByKey['bigint_field'], ['bigint', 'integer'], true)); + $this->assertEquals('bigint', $columnTypeByKey['bigint_field']); } public function testCreateRowWithIntegerAndBigIntTypes(): void From 737bfc599a7b7c467e9798b768ac4b1f4b4f1b98 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 18:00:43 +0530 Subject: [PATCH 016/211] fixed analyze --- tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php b/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php index 614a8f1f34..2da7769672 100644 --- a/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php +++ b/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php @@ -29,8 +29,8 @@ class DatabasesNumericTypesTest extends Scope protected function setupDatabaseAndTable(): array { $cacheKey = $this->getProject()['$id'] ?? 'default'; - if (!empty(static::$setupCache[$cacheKey])) { - return static::$setupCache[$cacheKey]; + if (!empty(self::$setupCache[$cacheKey])) { + return self::$setupCache[$cacheKey]; } $projectId = $this->getProject()['$id']; @@ -82,7 +82,7 @@ class DatabasesNumericTypesTest extends Scope // Cache before waiting so that if waitForAllAttributes times out, // subsequent calls don't try to re-create the same columns (causing 409) - static::$setupCache[$cacheKey] = [ + self::$setupCache[$cacheKey] = [ 'databaseId' => $databaseId, 'tableId' => $tableId, ]; @@ -90,7 +90,7 @@ class DatabasesNumericTypesTest extends Scope // Wait for all columns to be available $this->waitForAllAttributes($databaseId, $tableId); - return static::$setupCache[$cacheKey]; + return self::$setupCache[$cacheKey]; } /** From a5b2021d1e3eef44f32930239b81536a9d2f5189 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 18:17:14 +0530 Subject: [PATCH 017/211] empty From dfbf22cf3cf17f46e3f53d5f36dddfd19f3b5ec6 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 18:36:19 +0530 Subject: [PATCH 018/211] updated format --- app/init/database/formats.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/init/database/formats.php b/app/init/database/formats.php index 29a4f0c7d4..a4d80bea3e 100644 --- a/app/init/database/formats.php +++ b/app/init/database/formats.php @@ -36,6 +36,13 @@ Structure::addFormat(APP_DATABASE_ATTRIBUTE_INT_RANGE, function ($attribute) { return new Range($min, $max, Range::TYPE_INTEGER); }, Database::VAR_INTEGER); +// BigInt uses the same intRange format, but is stored as a 64-bit integer type. +Structure::addFormat(APP_DATABASE_ATTRIBUTE_INT_RANGE, function ($attribute) { + $min = $attribute['formatOptions']['min'] ?? -INF; + $max = $attribute['formatOptions']['max'] ?? INF; + return new Range($min, $max, Range::TYPE_INTEGER); +}, Database::VAR_BIGINT); + Structure::addFormat(APP_DATABASE_ATTRIBUTE_FLOAT_RANGE, function ($attribute) { $min = $attribute['formatOptions']['min'] ?? -INF; $max = $attribute['formatOptions']['max'] ?? INF; From 2fb54e084628468517826203d4b58a7e0593fe75 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 18:59:24 +0530 Subject: [PATCH 019/211] Add BigInt support with dedicated bigintRange format and update related logic --- app/init/constants.php | 1 + app/init/database/formats.php | 4 ++-- .../Databases/Collections/Attributes/Action.php | 14 +++++++++----- .../Collections/Attributes/BigInt/Create.php | 2 +- .../Http/Databases/Collections/Create.php | 14 +++++++++----- tests/e2e/Services/Migrations/MigrationsBase.php | 1 - 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/init/constants.php b/app/init/constants.php index ab88be5854..2aa9a938ab 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -54,6 +54,7 @@ const APP_DATABASE_ATTRIBUTE_IP = 'ip'; const APP_DATABASE_ATTRIBUTE_DATETIME = 'datetime'; const APP_DATABASE_ATTRIBUTE_URL = 'url'; const APP_DATABASE_ATTRIBUTE_INT_RANGE = 'intRange'; +const APP_DATABASE_ATTRIBUTE_BIGINT_RANGE = 'bigintRange'; const APP_DATABASE_ATTRIBUTE_FLOAT_RANGE = 'floatRange'; const APP_DATABASE_ATTRIBUTE_POINT = 'point'; const APP_DATABASE_ATTRIBUTE_LINE = 'line'; diff --git a/app/init/database/formats.php b/app/init/database/formats.php index a4d80bea3e..9ecf07716a 100644 --- a/app/init/database/formats.php +++ b/app/init/database/formats.php @@ -36,8 +36,8 @@ Structure::addFormat(APP_DATABASE_ATTRIBUTE_INT_RANGE, function ($attribute) { return new Range($min, $max, Range::TYPE_INTEGER); }, Database::VAR_INTEGER); -// BigInt uses the same intRange format, but is stored as a 64-bit integer type. -Structure::addFormat(APP_DATABASE_ATTRIBUTE_INT_RANGE, function ($attribute) { +// BigInt uses a dedicated bigintRange format name to avoid clobbering `intRange`. +Structure::addFormat(APP_DATABASE_ATTRIBUTE_BIGINT_RANGE, function ($attribute) { $min = $attribute['formatOptions']['min'] ?? -INF; $max = $attribute['formatOptions']['max'] ?? INF; return new Range($min, $max, Range::TYPE_INTEGER); 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 e4c02b40ce..0825f6a48e 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 @@ -544,6 +544,7 @@ abstract class Action extends UtopiaAction switch ($attribute->getAttribute('format')) { case APP_DATABASE_ATTRIBUTE_INT_RANGE: + case APP_DATABASE_ATTRIBUTE_BIGINT_RANGE: case APP_DATABASE_ATTRIBUTE_FLOAT_RANGE: $min ??= $attribute->getAttribute('formatOptions')['min']; $max ??= $attribute->getAttribute('formatOptions')['max']; @@ -552,16 +553,19 @@ abstract class Action extends UtopiaAction throw new Exception($this->getInvalidValueException(), 'Minimum value must be lesser than maximum value'); } - if ($attribute->getAttribute('format') === APP_DATABASE_ATTRIBUTE_INT_RANGE) { - // Use bigint validator when updating a bigint attribute/column. - $rangeType = $type === Database::VAR_BIGINT ? Database::VAR_BIGINT : Database::VAR_INTEGER; - $validator = new Range($min, $max, $rangeType); - } else { + if ($attribute->getAttribute('format') === APP_DATABASE_ATTRIBUTE_FLOAT_RANGE) { $validator = new Range($min, $max, Database::VAR_FLOAT); if (!is_null($default)) { $default = \floatval($default); } + } else { + // intRange and bigintRange share the same integer range semantics + // but validate against different primitive types. + $rangeType = $attribute->getAttribute('format') === APP_DATABASE_ATTRIBUTE_BIGINT_RANGE + ? Database::VAR_BIGINT + : Database::VAR_INTEGER; + $validator = new Range($min, $max, $rangeType); } if (!is_null($default) && !$validator->isValid($default)) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php index a7df055094..74e63e2f2d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php @@ -103,7 +103,7 @@ class Create extends Action 'required' => $required, 'default' => $default, 'array' => $array, - 'format' => APP_DATABASE_ATTRIBUTE_INT_RANGE, + 'format' => APP_DATABASE_ATTRIBUTE_BIGINT_RANGE, 'formatOptions' => ['min' => $min, 'max' => $max], ]), $response, $dbForProject, $queueForDatabase, $queueForEvents, $authorization); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index fd309a413c..788222d4be 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -290,13 +290,17 @@ class Create extends Action } if (isset($attribute['min']) || isset($attribute['max'])) { - $format = $type === Database::VAR_INTEGER - ? APP_DATABASE_ATTRIBUTE_INT_RANGE - : APP_DATABASE_ATTRIBUTE_FLOAT_RANGE; + if ($type === Database::VAR_INTEGER) { + $format = APP_DATABASE_ATTRIBUTE_INT_RANGE; + } elseif ($type === Database::VAR_BIGINT) { + $format = APP_DATABASE_ATTRIBUTE_BIGINT_RANGE; + } else { + $format = APP_DATABASE_ATTRIBUTE_FLOAT_RANGE; + } $formatOptions = [ - 'min' => $attribute['min'] ?? ($type === Database::VAR_INTEGER ? \PHP_INT_MIN : -\PHP_FLOAT_MAX), - 'max' => $attribute['max'] ?? ($type === Database::VAR_INTEGER ? \PHP_INT_MAX : \PHP_FLOAT_MAX), + 'min' => $attribute['min'] ?? ($type === Database::VAR_INTEGER || $type === Database::VAR_BIGINT ? \PHP_INT_MIN : -\PHP_FLOAT_MAX), + 'max' => $attribute['max'] ?? ($type === Database::VAR_INTEGER || $type === Database::VAR_BIGINT ? \PHP_INT_MAX : \PHP_FLOAT_MAX), ]; } diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index fef0a6d577..41710252e4 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1256,7 +1256,6 @@ trait MigrationsBase 'max' => 65, 'required' => true, ]); - $this->assertEquals(202, $response['headers']['status-code']); $this->assertEquals($response['body']['key'], 'age'); $this->assertEquals($response['body']['type'], 'integer'); From 5fa4551400f930d1a42d25e45da559c2acceb653 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 20:10:13 +0530 Subject: [PATCH 020/211] Refactor bigint handling in validation and action classes to unify range validation logic --- composer.lock | 8 ++--- .../Collections/Attributes/Action.php | 10 +----- .../Collections/Attributes/BigInt/Create.php | 2 +- .../Utopia/Database/Validator/Attributes.php | 34 ++++++++++++++----- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/composer.lock b/composer.lock index 036415e843..cdc650af86 100644 --- a/composer.lock +++ b/composer.lock @@ -3854,12 +3854,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "ef5c77972a95129eb929cce6c8f7c674db930ec9" + "reference": "b87cf3a9727f24cf080d8d2c21f376b88b308668" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/ef5c77972a95129eb929cce6c8f7c674db930ec9", - "reference": "ef5c77972a95129eb929cce6c8f7c674db930ec9", + "url": "https://api.github.com/repos/utopia-php/database/zipball/b87cf3a9727f24cf080d8d2c21f376b88b308668", + "reference": "b87cf3a9727f24cf080d8d2c21f376b88b308668", "shasum": "" }, "require": { @@ -3905,7 +3905,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/big-init" }, - "time": "2026-03-30T06:31:05+00:00" + "time": "2026-03-30T14:36:08+00:00" }, { "name": "utopia-php/detector", 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 0825f6a48e..d726d613be 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 @@ -237,10 +237,6 @@ abstract class Action extends UtopiaAction ? UtopiaResponse::MODEL_ATTRIBUTE_BOOLEAN : UtopiaResponse::MODEL_COLUMN_BOOLEAN, - Database::VAR_BIGINT => $isCollections - ? UtopiaResponse::MODEL_ATTRIBUTE_BIGINT - : UtopiaResponse::MODEL_COLUMN_BIGINT, - Database::VAR_INTEGER => $isCollections ? UtopiaResponse::MODEL_ATTRIBUTE_INTEGER : UtopiaResponse::MODEL_COLUMN_INTEGER, @@ -561,11 +557,7 @@ abstract class Action extends UtopiaAction } } else { // intRange and bigintRange share the same integer range semantics - // but validate against different primitive types. - $rangeType = $attribute->getAttribute('format') === APP_DATABASE_ATTRIBUTE_BIGINT_RANGE - ? Database::VAR_BIGINT - : Database::VAR_INTEGER; - $validator = new Range($min, $max, $rangeType); + $validator = new Range($min, $max, Range::TYPE_INTEGER); } if (!is_null($default) && !$validator->isValid($default)) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php index 74e63e2f2d..c0544fb122 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php @@ -88,7 +88,7 @@ class Create extends Action throw new Exception($this->getInvalidValueException(), 'Minimum value must be lesser than maximum value'); } - $validator = new Range($min, $max, Database::VAR_BIGINT); + $validator = new Range($min, $max, Range::TYPE_INTEGER); if (!\is_null($default) && !$validator->isValid($default)) { throw new Exception($this->getInvalidValueException(), $validator->getDescription()); } diff --git a/src/Appwrite/Utopia/Database/Validator/Attributes.php b/src/Appwrite/Utopia/Database/Validator/Attributes.php index f8bdd01103..34562a2536 100644 --- a/src/Appwrite/Utopia/Database/Validator/Attributes.php +++ b/src/Appwrite/Utopia/Database/Validator/Attributes.php @@ -23,6 +23,7 @@ class Attributes extends Validator protected array $supportedTypes = [ Database::VAR_STRING, Database::VAR_INTEGER, + Database::VAR_BIGINT, Database::VAR_FLOAT, Database::VAR_BOOLEAN, Database::VAR_DATETIME, @@ -181,9 +182,9 @@ class Attributes extends Validator return false; } - // Validate signed only for integer/float types - if (isset($attribute['signed']) && !in_array($attribute['type'], [Database::VAR_INTEGER, Database::VAR_FLOAT])) { - $this->message = "Attribute '" . $attribute['key'] . "': 'signed' can only be used with integer or float types"; + // Validate signed only for integer/bigint/float types + if (isset($attribute['signed']) && !in_array($attribute['type'], [Database::VAR_INTEGER, Database::VAR_BIGINT, Database::VAR_FLOAT])) { + $this->message = "Attribute '" . $attribute['key'] . "': 'signed' can only be used with integer, bigint or float types"; return false; } @@ -199,10 +200,10 @@ class Attributes extends Validator return false; } - // Validate min/max range for integer/float + // Validate min/max range for integer/bigint/float if (isset($attribute['min']) || isset($attribute['max'])) { - if (!in_array($attribute['type'], [Database::VAR_INTEGER, Database::VAR_FLOAT])) { - $this->message = "Attribute '" . $attribute['key'] . "': min/max can only be used with integer or float types"; + if (!in_array($attribute['type'], [Database::VAR_INTEGER, Database::VAR_BIGINT, Database::VAR_FLOAT])) { + $this->message = "Attribute '" . $attribute['key'] . "': min/max can only be used with integer, bigint or float types"; return false; } @@ -264,7 +265,7 @@ class Attributes extends Validator if (isset($attribute['min']) || isset($attribute['max'])) { $min = $attribute['min'] ?? \PHP_INT_MIN; $max = $attribute['max'] ?? \PHP_INT_MAX; - $rangeValidator = new Range($min, $max, Database::VAR_INTEGER); + $rangeValidator = new Range($min, $max, Range::TYPE_INTEGER); if (!$rangeValidator->isValid($attribute['default'])) { $this->message = "Default value for integer attribute '" . $attribute['key'] . "' must be between $min and $max"; return false; @@ -272,6 +273,23 @@ class Attributes extends Validator } break; + case Database::VAR_BIGINT: + if (!is_int($attribute['default'])) { + $this->message = "Default value for bigint attribute '" . $attribute['key'] . "' must be an integer"; + return false; + } + // Validate within range if min/max specified + if (isset($attribute['min']) || isset($attribute['max'])) { + $min = $attribute['min'] ?? \PHP_INT_MIN; + $max = $attribute['max'] ?? \PHP_INT_MAX; + $rangeValidator = new Range($min, $max, Range::TYPE_INTEGER); + if (!$rangeValidator->isValid($attribute['default'])) { + $this->message = "Default value for bigint attribute '" . $attribute['key'] . "' must be between $min and $max"; + return false; + } + } + break; + case Database::VAR_FLOAT: if (!is_float($attribute['default']) && !is_int($attribute['default'])) { $this->message = "Default value for float attribute '" . $attribute['key'] . "' must be a number"; @@ -281,7 +299,7 @@ class Attributes extends Validator if (isset($attribute['min']) || isset($attribute['max'])) { $min = $attribute['min'] ?? -\PHP_FLOAT_MAX; $max = $attribute['max'] ?? \PHP_FLOAT_MAX; - $rangeValidator = new Range($min, $max, Database::VAR_FLOAT); + $rangeValidator = new Range($min, $max, Range::TYPE_FLOAT); if (!$rangeValidator->isValid((float)$attribute['default'])) { $this->message = "Default value for float attribute '" . $attribute['key'] . "' must be between $min and $max"; return false; From c4b3956beff6a28c49c90a37a7b5ab3da53ed9ab Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 20:26:23 +0530 Subject: [PATCH 021/211] emtpy From ad7f83db11b14203583a77867153e2634c3f5b83 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 30 Mar 2026 20:32:03 +0530 Subject: [PATCH 022/211] updated actions --- .../Http/Databases/Collections/Attributes/Action.php | 4 ++++ 1 file changed, 4 insertions(+) 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 d726d613be..3b28bdeffb 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 @@ -241,6 +241,10 @@ abstract class Action extends UtopiaAction ? UtopiaResponse::MODEL_ATTRIBUTE_INTEGER : UtopiaResponse::MODEL_COLUMN_INTEGER, + Database::VAR_BIGINT => $isCollections + ? UtopiaResponse::MODEL_ATTRIBUTE_BIGINT + : UtopiaResponse::MODEL_COLUMN_BIGINT, + Database::VAR_FLOAT => $isCollections ? UtopiaResponse::MODEL_ATTRIBUTE_FLOAT : UtopiaResponse::MODEL_COLUMN_FLOAT, From 71b28eae5a7f0bcb44d9ee1e9d80353eb8ab909f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 1 Apr 2026 15:55:26 +0530 Subject: [PATCH 023/211] updated db --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 59173e9794..869bee8d7d 100644 --- a/composer.lock +++ b/composer.lock @@ -3854,12 +3854,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "b87cf3a9727f24cf080d8d2c21f376b88b308668" + "reference": "ad89dab91d0e85f4496d366ad80b687cbdefd714" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/b87cf3a9727f24cf080d8d2c21f376b88b308668", - "reference": "b87cf3a9727f24cf080d8d2c21f376b88b308668", + "url": "https://api.github.com/repos/utopia-php/database/zipball/ad89dab91d0e85f4496d366ad80b687cbdefd714", + "reference": "ad89dab91d0e85f4496d366ad80b687cbdefd714", "shasum": "" }, "require": { @@ -3905,7 +3905,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/big-init" }, - "time": "2026-03-30T14:36:08+00:00" + "time": "2026-04-01T05:25:04+00:00" }, { "name": "utopia-php/detector", From 45dc259df3d341be3001b0ec8d264742c65f819b Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 9 Apr 2026 11:14:28 +0530 Subject: [PATCH 024/211] updated validator --- composer.lock | 8 ++++---- .../Http/TablesDB/Tables/Columns/BigInt/Create.php | 3 ++- .../Http/TablesDB/Tables/Columns/BigInt/Update.php | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 869bee8d7d..a1fa0b153a 100644 --- a/composer.lock +++ b/composer.lock @@ -3854,12 +3854,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "ad89dab91d0e85f4496d366ad80b687cbdefd714" + "reference": "17615116013c18b8f4d00246d52268ffbc15b11c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/ad89dab91d0e85f4496d366ad80b687cbdefd714", - "reference": "ad89dab91d0e85f4496d366ad80b687cbdefd714", + "url": "https://api.github.com/repos/utopia-php/database/zipball/17615116013c18b8f4d00246d52268ffbc15b11c", + "reference": "17615116013c18b8f4d00246d52268ffbc15b11c", "shasum": "" }, "require": { @@ -3905,7 +3905,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/big-init" }, - "time": "2026-04-01T05:25:04+00:00" + "time": "2026-04-09T05:22:46+00:00" }, { "name": "utopia-php/detector", diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php index 1b7b33291b..2b5dd078b4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php @@ -8,6 +8,7 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; +use Utopia\Database\Validator\BigInt; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; @@ -58,7 +59,7 @@ class Create extends BigIntCreate ->param('required', null, new Boolean(), 'Is column required?') ->param('min', null, new Nullable(new Integer(false, 64)), 'Minimum value', true) ->param('max', null, new Nullable(new Integer(false, 64)), 'Maximum value', true) - ->param('default', null, new Nullable(new Integer(false, 64)), 'Default value. Cannot be set when column is required.', true) + ->param('default', null, new Nullable(new BigInt(false, true)), 'Default value. 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/BigInt/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php index 387dd08238..bcec75f713 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php @@ -9,6 +9,7 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; +use Utopia\Database\Validator\BigInt; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; @@ -60,7 +61,7 @@ class Update extends BigIntUpdate ->param('required', null, new Boolean(), 'Is column required?') ->param('min', null, new Nullable(new Integer(false, 64)), 'Minimum value', true) ->param('max', null, new Nullable(new Integer(false, 64)), 'Maximum value', true) - ->param('default', null, new Nullable(new Integer(false, 64)), 'Default value. Cannot be set when column is required.') + ->param('default', null, new Nullable(new BigInt(false, true)), 'Default value. Cannot be set when column is required.') ->param('newKey', null, fn (Database $dbForProject) => new Nullable(new Key(false, $dbForProject->getAdapter()->getMaxUIDLength())), 'New Column Key.', true, ['dbForProject']) ->inject('response') ->inject('dbForProject') From 0c734f8f1205ae6344382e791b1b303d5781e29f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 9 Apr 2026 12:02:13 +0530 Subject: [PATCH 025/211] updated --- composer.lock | 36 +++++++++---------- .../SDK/Specification/Format/OpenAPI3.php | 9 +++++ .../SDK/Specification/Format/Swagger2.php | 9 +++++ 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/composer.lock b/composer.lock index 45ced3bce8..141ef45c01 100644 --- a/composer.lock +++ b/composer.lock @@ -3403,16 +3403,16 @@ }, { "name": "utopia-php/agents", - "version": "1.2.1", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/utopia-php/agents.git", - "reference": "052227953678a30ecc4b5467401fcb0b2386471e" + "reference": "06064fd9fb19b77ae45a12ec7bcbc17670912c30" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/agents/zipball/052227953678a30ecc4b5467401fcb0b2386471e", - "reference": "052227953678a30ecc4b5467401fcb0b2386471e", + "url": "https://api.github.com/repos/utopia-php/agents/zipball/06064fd9fb19b77ae45a12ec7bcbc17670912c30", + "reference": "06064fd9fb19b77ae45a12ec7bcbc17670912c30", "shasum": "" }, "require": { @@ -3450,9 +3450,9 @@ ], "support": { "issues": "https://github.com/utopia-php/agents/issues", - "source": "https://github.com/utopia-php/agents/tree/1.2.1" + "source": "https://github.com/utopia-php/agents/tree/1.3.0" }, - "time": "2026-02-24T06:03:55+00:00" + "time": "2026-03-26T03:51:11+00:00" }, { "name": "utopia-php/analytics", @@ -5225,16 +5225,16 @@ }, { "name": "utopia-php/vcs", - "version": "3.1.0", + "version": "3.2.0", "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "03b76ad5fd01bc50f809915bca6ff0745ea913af" + "reference": "44a84ab52b42fc12f812b4d7331286b519d39db3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/vcs/zipball/03b76ad5fd01bc50f809915bca6ff0745ea913af", - "reference": "03b76ad5fd01bc50f809915bca6ff0745ea913af", + "url": "https://api.github.com/repos/utopia-php/vcs/zipball/44a84ab52b42fc12f812b4d7331286b519d39db3", + "reference": "44a84ab52b42fc12f812b4d7331286b519d39db3", "shasum": "" }, "require": { @@ -5268,9 +5268,9 @@ ], "support": { "issues": "https://github.com/utopia-php/vcs/issues", - "source": "https://github.com/utopia-php/vcs/tree/3.1.0" + "source": "https://github.com/utopia-php/vcs/tree/3.2.0" }, - "time": "2026-03-24T08:49:14+00:00" + "time": "2026-04-08T16:00:31+00:00" }, { "name": "utopia-php/websocket", @@ -5448,16 +5448,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.17.7", + "version": "1.17.8", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "291471d04c3f0e7b9fcc46668a6255a4c0f2947e" + "reference": "b7109e13cec89ed56ad80111973b12646e4eb5f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/291471d04c3f0e7b9fcc46668a6255a4c0f2947e", - "reference": "291471d04c3f0e7b9fcc46668a6255a4c0f2947e", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/b7109e13cec89ed56ad80111973b12646e4eb5f7", + "reference": "b7109e13cec89ed56ad80111973b12646e4eb5f7", "shasum": "" }, "require": { @@ -5493,9 +5493,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.17.7" + "source": "https://github.com/appwrite/sdk-generator/tree/1.17.8" }, - "time": "2026-04-08T08:51:05+00:00" + "time": "2026-04-09T05:08:21+00:00" }, { "name": "brianium/paratest", diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index 94e0f831b7..0f3b2568a2 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -431,6 +431,15 @@ class OpenAPI3 extends Format $node['schema']['type'] = $validator->getType(); $node['schema']['x-example'] = ($param['example'] ?? '') ?: '<' . \strtoupper(Template::fromCamelCaseToSnake($node['name'])) . '>'; break; + case \Utopia\Database\Validator\BigInt::class: + // BigInt validator reports Database::VAR_BIGINT, but OpenAPI expects scalar types. + // We expose it as int64 to keep schema consistent with Column/Attribute models. + $node['schema']['type'] = 'integer'; + $node['schema']['format'] = 'int64'; + if (!empty($param['example'])) { + $node['schema']['x-example'] = $param['example']; + } + break; case \Utopia\Validator\Boolean::class: $node['schema']['type'] = $validator->getType(); $node['schema']['x-example'] = ($param['example'] ?? '') ?: false; diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 14a18eea2e..f47ca03152 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -435,6 +435,15 @@ class Swagger2 extends Format $node['type'] = $validator->getType(); $node['x-example'] = ($param['example'] ?? '') ?: '<' . \strtoupper(Template::fromCamelCaseToSnake($node['name'])) . '>'; break; + case \Utopia\Database\Validator\BigInt::class: + // BigInt validator reports Database::VAR_BIGINT, but Swagger expects scalar types. + // We expose it as int64 to keep schema consistent with Column/Attribute models. + $node['type'] = 'integer'; + $node['format'] = 'int64'; + if (!empty($param['example'])) { + $node['x-example'] = $param['example']; + } + break; case \Utopia\Validator\Boolean::class: $node['type'] = $validator->getType(); $node['x-example'] = ($param['example'] ?? '') ?: false; From 0ea83790651e33784aa083ffb5134bb2c782e54c Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 9 Apr 2026 14:11:21 +0530 Subject: [PATCH 026/211] added the changes --- .../Http/TablesDB/Tables/Columns/BigInt/Create.php | 3 +-- .../Http/TablesDB/Tables/Columns/BigInt/Update.php | 3 +-- src/Appwrite/SDK/Specification/Format/Swagger2.php | 9 --------- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php index 2b5dd078b4..1b7b33291b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php @@ -8,7 +8,6 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; -use Utopia\Database\Validator\BigInt; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; @@ -59,7 +58,7 @@ class Create extends BigIntCreate ->param('required', null, new Boolean(), 'Is column required?') ->param('min', null, new Nullable(new Integer(false, 64)), 'Minimum value', true) ->param('max', null, new Nullable(new Integer(false, 64)), 'Maximum value', true) - ->param('default', null, new Nullable(new BigInt(false, true)), 'Default value. Cannot be set when column is required.', true) + ->param('default', null, new Nullable(new Integer(false, 64)), 'Default value. 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/BigInt/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php index bcec75f713..387dd08238 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php @@ -9,7 +9,6 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; -use Utopia\Database\Validator\BigInt; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; @@ -61,7 +60,7 @@ class Update extends BigIntUpdate ->param('required', null, new Boolean(), 'Is column required?') ->param('min', null, new Nullable(new Integer(false, 64)), 'Minimum value', true) ->param('max', null, new Nullable(new Integer(false, 64)), 'Maximum value', true) - ->param('default', null, new Nullable(new BigInt(false, true)), 'Default value. Cannot be set when column is required.') + ->param('default', null, new Nullable(new Integer(false, 64)), 'Default value. Cannot be set when column is required.') ->param('newKey', null, fn (Database $dbForProject) => new Nullable(new Key(false, $dbForProject->getAdapter()->getMaxUIDLength())), 'New Column Key.', true, ['dbForProject']) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index f47ca03152..14a18eea2e 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -435,15 +435,6 @@ class Swagger2 extends Format $node['type'] = $validator->getType(); $node['x-example'] = ($param['example'] ?? '') ?: '<' . \strtoupper(Template::fromCamelCaseToSnake($node['name'])) . '>'; break; - case \Utopia\Database\Validator\BigInt::class: - // BigInt validator reports Database::VAR_BIGINT, but Swagger expects scalar types. - // We expose it as int64 to keep schema consistent with Column/Attribute models. - $node['type'] = 'integer'; - $node['format'] = 'int64'; - if (!empty($param['example'])) { - $node['x-example'] = $param['example']; - } - break; case \Utopia\Validator\Boolean::class: $node['type'] = $validator->getType(); $node['x-example'] = ($param['example'] ?? '') ?: false; From 4f599fc75cb5e8cd75b48b0c9a93ad772fff18e4 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 9 Apr 2026 17:07:47 +0530 Subject: [PATCH 027/211] updated --- composer.lock | 8 +-- .../Collections/Attributes/BigInt/Create.php | 5 +- .../Http/Databases/Collections/Create.php | 11 +++- .../Utopia/Response/Model/AttributeBigInt.php | 51 ++++++++++++++++--- .../Utopia/Response/Model/ColumnBigInt.php | 51 ++++++++++++++++--- 5 files changed, 101 insertions(+), 25 deletions(-) diff --git a/composer.lock b/composer.lock index 141ef45c01..bec82a1a4c 100644 --- a/composer.lock +++ b/composer.lock @@ -3854,12 +3854,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "17615116013c18b8f4d00246d52268ffbc15b11c" + "reference": "0e43fd44f2190da36cac816a17650d697e034507" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/17615116013c18b8f4d00246d52268ffbc15b11c", - "reference": "17615116013c18b8f4d00246d52268ffbc15b11c", + "url": "https://api.github.com/repos/utopia-php/database/zipball/0e43fd44f2190da36cac816a17650d697e034507", + "reference": "0e43fd44f2190da36cac816a17650d697e034507", "shasum": "" }, "require": { @@ -3905,7 +3905,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/big-init" }, - "time": "2026-04-09T05:22:46+00:00" + "time": "2026-04-09T11:05:50+00:00" }, { "name": "utopia-php/detector", diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php index c0544fb122..4ea85b71e6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php @@ -93,13 +93,10 @@ class Create extends Action throw new Exception($this->getInvalidValueException(), $validator->getDescription()); } - // `bigint` is always stored as a 64-bit integer. - $size = 8; - $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, 'type' => Database::VAR_BIGINT, - 'size' => $size, + 'size' => 8, 'required' => $required, 'default' => $default, 'array' => $array, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index 788222d4be..24cec35eac 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -276,7 +276,16 @@ class Create extends Action ): array { $key = $attribute['key']; $type = $attribute['type']; - $size = $attribute['size'] ?? 0; + switch ($type) { + case Database::VAR_INTEGER: + $size = 4; + break; + case Database::VAR_BIGINT: + $size = 8; + break; + default: + $size = $attribute['size'] ?? 0; + } $required = $attribute['required'] ?? false; $signed = $attribute['signed'] ?? true; $array = $attribute['array'] ?? false; diff --git a/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php b/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php index 2ab02991cb..722bcedf5a 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php @@ -4,21 +4,56 @@ namespace Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response; -class AttributeBigInt extends AttributeInteger +class AttributeBigInt extends Attribute { - public array $conditions = [ - 'type' => 'bigint', - 'size' => 8, - ]; - public function __construct() { parent::__construct(); - // Update example for the `type` field - $this->rules['type']['example'] = 'bigint'; + $this + ->addRule('key', [ + 'type' => self::TYPE_STRING, + 'description' => 'Attribute Key.', + 'default' => '', + 'example' => 'count', + ]) + ->addRule('type', [ + 'type' => self::TYPE_STRING, + 'description' => 'Attribute type.', + 'default' => '', + 'example' => 'bigint', + ]) + ->addRule('min', [ + 'type' => self::TYPE_INTEGER, + 'format' => 'int64', + 'description' => 'Minimum value to enforce for new documents.', + 'default' => null, + 'required' => false, + 'example' => 1, + ]) + ->addRule('max', [ + 'type' => self::TYPE_INTEGER, + 'format' => 'int64', + 'description' => 'Maximum value to enforce for new documents.', + 'default' => null, + 'required' => false, + 'example' => 10, + ]) + ->addRule('default', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', + 'default' => null, + 'required' => false, + 'example' => 10, + ]) + ; } + public array $conditions = [ + 'type' => 'bigint', + 'size' => 8, + ]; + public function getName(): string { return 'AttributeBigInt'; diff --git a/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php b/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php index 0d8b71ee98..c4d7f96586 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php @@ -4,21 +4,56 @@ namespace Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response; -class ColumnBigInt extends ColumnInteger +class ColumnBigInt extends Column { - public array $conditions = [ - 'type' => 'bigint', - 'size' => 8, - ]; - public function __construct() { parent::__construct(); - // Update example for the `type` field - $this->rules['type']['example'] = 'bigint'; + $this + ->addRule('key', [ + 'type' => self::TYPE_STRING, + 'description' => 'Column Key.', + 'default' => '', + 'example' => 'count', + ]) + ->addRule('type', [ + 'type' => self::TYPE_STRING, + 'description' => 'Column type.', + 'default' => '', + 'example' => 'bigint', + ]) + ->addRule('min', [ + 'type' => self::TYPE_INTEGER, + 'format' => 'int64', + 'description' => 'Minimum value to enforce for new documents.', + 'default' => null, + 'required' => false, + 'example' => 1, + ]) + ->addRule('max', [ + 'type' => self::TYPE_INTEGER, + 'format' => 'int64', + 'description' => 'Maximum value to enforce for new documents.', + 'default' => null, + 'required' => false, + 'example' => 10, + ]) + ->addRule('default', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Default value for column when not provided. Cannot be set when column is required.', + 'default' => null, + 'required' => false, + 'example' => 10, + ]) + ; } + public array $conditions = [ + 'type' => 'bigint', + 'size' => 8, + ]; + public function getName(): string { return 'ColumnBigInt'; From b3c6e0e67f19f9c5932bf3e90340e9d35c6a9902 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 9 Apr 2026 17:10:47 +0530 Subject: [PATCH 028/211] removed size from the conditions --- src/Appwrite/Utopia/Response/Model/AttributeBigInt.php | 3 +-- src/Appwrite/Utopia/Response/Model/ColumnBigInt.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php b/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php index 722bcedf5a..217589c578 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php @@ -50,8 +50,7 @@ class AttributeBigInt extends Attribute } public array $conditions = [ - 'type' => 'bigint', - 'size' => 8, + 'type' => 'bigint' ]; public function getName(): string diff --git a/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php b/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php index c4d7f96586..e001b6aedf 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php @@ -50,8 +50,7 @@ class ColumnBigInt extends Column } public array $conditions = [ - 'type' => 'bigint', - 'size' => 8, + 'type' => 'bigint' ]; public function getName(): string From d44820e00c956b5c671c61320951622861acd299 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Wed, 15 Apr 2026 14:15:08 +0100 Subject: [PATCH 029/211] Add overwrite and skip options to migration imports Exposes two new optional boolean params on the three migration creation endpoints so CSV / JSON / appwrite-to-appwrite imports can choose how to handle rows whose IDs already exist at the destination. Endpoints updated (app/controllers/api/migrations.php): - POST /v1/migrations/appwrite - POST /v1/migrations/csv/imports - POST /v1/migrations/json/imports Parameter semantics: - overwrite=true -> destination uses upsertDocuments instead of createDocuments; existing rows are replaced with imported values - skip=true -> destination wraps createDocuments in skipDuplicates; existing rows are preserved unchanged, duplicate-id rows silently no-op - both false -> default; fails fast on DuplicateException (original behavior, unchanged) - both true -> overwrite wins (upsert subsumes skip) Both params are stored in the migration Document's options array (matches the existing pattern for destination behavior config like path, size, delimiter, bucketId, etc.) and read back in the worker's processDestination() to instantiate DestinationAppwrite with the new constructor params. Feature-branch note: depends on utopia-php/migration#feat/skip-duplicates (DestinationAppwrite constructor params) which in turn depends on utopia-php/database#852 (skipDuplicates scope guard). composer.json is temporarily pinned to dev-feat/skip-duplicates and dev-csv-import-upsert-v2 respectively; both must be reset to proper release versions once the upstream PRs merge. --- app/controllers/api/migrations.php | 20 +++++- composer.json | 4 +- composer.lock | 72 ++++++++++++-------- src/Appwrite/Platform/Workers/Migrations.php | 2 + 4 files changed, 67 insertions(+), 31 deletions(-) diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index 4c541d2817..f19598c198 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -87,13 +87,15 @@ Http::post('/v1/migrations/appwrite') ->param('endpoint', '', new URL(), 'Source Appwrite endpoint') ->param('projectId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Source Project ID', false, ['dbForProject']) ->param('apiKey', '', new Text(512), 'Source API Key') + ->param('overwrite', false, new Boolean(), 'When true, replace existing rows by calling upsertDocuments instead of createDocuments. Rows with matching IDs will be updated with the imported values.', true) + ->param('skip', false, new Boolean(), 'When true, silently ignore rows whose IDs already exist in the destination. Existing rows are preserved unchanged.', true) ->inject('response') ->inject('dbForProject') ->inject('project') ->inject('platform') ->inject('queueForEvents') ->inject('publisherForMigrations') - ->action(function (array $resources, string $endpoint, string $projectId, string $apiKey, Response $response, Database $dbForProject, Document $project, array $platform, Event $queueForEvents, MigrationPublisher $publisherForMigrations) { + ->action(function (array $resources, string $endpoint, string $projectId, string $apiKey, bool $overwrite, bool $skip, Response $response, Database $dbForProject, Document $project, array $platform, Event $queueForEvents, MigrationPublisher $publisherForMigrations) { $migration = $dbForProject->createDocument('migrations', new Document([ '$id' => ID::unique(), 'status' => 'pending', @@ -109,6 +111,10 @@ Http::post('/v1/migrations/appwrite') 'statusCounters' => '{}', 'resourceData' => '{}', 'errors' => [], + 'options' => [ + 'overwrite' => $overwrite, + 'skip' => $skip, + ], ])); $queueForEvents->setParam('migrationId', $migration->getId()); @@ -352,6 +358,8 @@ Http::post('/v1/migrations/csv/imports') ->param('fileId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'File ID.', false, ['dbForProject']) ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.') ->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true) + ->param('overwrite', false, new Boolean(), 'When true, replace existing rows by calling upsertDocuments instead of createDocuments. Rows with matching IDs will be updated with the imported values.', true) + ->param('skip', false, new Boolean(), 'When true, silently ignore rows whose IDs already exist in the destination. Existing rows are preserved unchanged.', true) ->inject('response') ->inject('dbForProject') ->inject('dbForPlatform') @@ -367,6 +375,8 @@ Http::post('/v1/migrations/csv/imports') string $fileId, string $resourceId, bool $internalFile, + bool $overwrite, + bool $skip, Response $response, Database $dbForProject, Database $dbForPlatform, @@ -467,6 +477,8 @@ Http::post('/v1/migrations/csv/imports') 'options' => [ 'path' => $newPath, 'size' => $fileSize, + 'overwrite' => $overwrite, + 'skip' => $skip, ], ])); @@ -656,6 +668,8 @@ Http::post('/v1/migrations/json/imports') ->param('fileId', '', new UID(), 'File ID.') ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.') ->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true) + ->param('overwrite', false, new Boolean(), 'When true, replace existing rows by calling upsertDocuments instead of createDocuments. Rows with matching IDs will be updated with the imported values.', true) + ->param('skip', false, new Boolean(), 'When true, silently ignore rows whose IDs already exist in the destination. Existing rows are preserved unchanged.', true) ->inject('response') ->inject('dbForProject') ->inject('dbForPlatform') @@ -671,6 +685,8 @@ Http::post('/v1/migrations/json/imports') string $fileId, string $resourceId, bool $internalFile, + bool $overwrite, + bool $skip, Response $response, Database $dbForProject, Database $dbForPlatform, @@ -770,6 +786,8 @@ Http::post('/v1/migrations/json/imports') 'options' => [ 'path' => $newPath, 'size' => $fileSize, + 'overwrite' => $overwrite, + 'skip' => $skip, ], ])); diff --git a/composer.json b/composer.json index 3aa6d157cf..2dbe5616e5 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "utopia-php/compression": "0.1.*", "utopia-php/config": "1.*", "utopia-php/console": "0.1.*", - "utopia-php/database": "5.*", + "utopia-php/database": "dev-csv-import-upsert-v2 as 5.99.0", "utopia-php/detector": "0.2.*", "utopia-php/domains": "1.*", "utopia-php/emails": "0.6.*", @@ -73,7 +73,7 @@ "utopia-php/locale": "0.8.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.22.*", - "utopia-php/migration": "1.9.*", + "utopia-php/migration": "dev-feat/skip-duplicates as 1.9.99", "utopia-php/platform": "0.12.*", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", diff --git a/composer.lock b/composer.lock index bc3d9d30bf..e93af8906a 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": "f6a87c1012b316e614258f8f57a28e48", + "content-hash": "0cabf47b85d8fac9a1f78df82b0add1f", "packages": [ { "name": "adhocore/jwt", @@ -2887,7 +2887,7 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.34.0", + "version": "v1.35.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", @@ -2948,7 +2948,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.34.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.35.0" }, "funding": [ { @@ -2972,7 +2972,7 @@ }, { "name": "symfony/polyfill-php82", - "version": "v1.34.0", + "version": "v1.35.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php82.git", @@ -3028,7 +3028,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php82/tree/v1.34.0" + "source": "https://github.com/symfony/polyfill-php82/tree/v1.35.0" }, "funding": [ { @@ -3052,7 +3052,7 @@ }, { "name": "symfony/polyfill-php83", - "version": "v1.34.0", + "version": "v1.35.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php83.git", @@ -3108,7 +3108,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php83/tree/v1.34.0" + "source": "https://github.com/symfony/polyfill-php83/tree/v1.35.0" }, "funding": [ { @@ -3132,7 +3132,7 @@ }, { "name": "symfony/polyfill-php85", - "version": "v1.34.0", + "version": "v1.35.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php85.git", @@ -3188,7 +3188,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php85/tree/v1.34.0" + "source": "https://github.com/symfony/polyfill-php85/tree/v1.35.0" }, "funding": [ { @@ -3850,16 +3850,16 @@ }, { "name": "utopia-php/database", - "version": "5.3.21", + "version": "dev-csv-import-upsert-v2", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "ee2d7d4c87b3a3fae954089ad7494ceb454f619d" + "reference": "52b189bded7ef409bb978483a7231d779051b510" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/ee2d7d4c87b3a3fae954089ad7494ceb454f619d", - "reference": "ee2d7d4c87b3a3fae954089ad7494ceb454f619d", + "url": "https://api.github.com/repos/utopia-php/database/zipball/52b189bded7ef409bb978483a7231d779051b510", + "reference": "52b189bded7ef409bb978483a7231d779051b510", "shasum": "" }, "require": { @@ -3903,9 +3903,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/5.3.21" + "source": "https://github.com/utopia-php/database/tree/csv-import-upsert-v2" }, - "time": "2026-04-10T12:38:57+00:00" + "time": "2026-04-15T10:53:53+00:00" }, { "name": "utopia-php/detector", @@ -4526,16 +4526,16 @@ }, { "name": "utopia-php/migration", - "version": "1.9.1", + "version": "dev-feat/skip-duplicates", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "7a86aeadf182b63a9f4ceba7e137588b31c5d2e2" + "reference": "2012cda162ad0ab79678c924d7534de6f3ec85ad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/7a86aeadf182b63a9f4ceba7e137588b31c5d2e2", - "reference": "7a86aeadf182b63a9f4ceba7e137588b31c5d2e2", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/2012cda162ad0ab79678c924d7534de6f3ec85ad", + "reference": "2012cda162ad0ab79678c924d7534de6f3ec85ad", "shasum": "" }, "require": { @@ -4544,7 +4544,7 @@ "ext-openssl": "*", "halaxa/json-machine": "^1.2", "php": ">=8.1", - "utopia-php/database": "5.*", + "utopia-php/database": "dev-csv-import-upsert-v2 as 5.99.0", "utopia-php/dsn": "0.2.*", "utopia-php/storage": "1.0.*" }, @@ -4575,9 +4575,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.9.1" + "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-03-25T07:05:27+00:00" + "time": "2026-04-15T12:36:51+00:00" }, { "name": "utopia-php/mongo", @@ -7778,7 +7778,7 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.34.0", + "version": "v1.35.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", @@ -7837,7 +7837,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.34.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.35.0" }, "funding": [ { @@ -8028,7 +8028,7 @@ }, { "name": "symfony/polyfill-php81", - "version": "v1.34.0", + "version": "v1.35.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php81.git", @@ -8084,7 +8084,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php81/tree/v1.34.0" + "source": "https://github.com/symfony/polyfill-php81/tree/v1.35.0" }, "funding": [ { @@ -8440,9 +8440,25 @@ "time": "2024-11-07T12:36:22+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-csv-import-upsert-v2", + "alias": "5.99.0", + "alias_normalized": "5.99.0.0" + }, + { + "package": "utopia-php/migration", + "version": "dev-feat/skip-duplicates", + "alias": "1.9.99", + "alias_normalized": "1.9.99.0" + } + ], "minimum-stability": "dev", - "stability-flags": {}, + "stability-flags": { + "utopia-php/database": 20, + "utopia-php/migration": 20 + }, "prefer-stable": true, "prefer-lowest": false, "platform": { diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 118ff7acf9..710b24c19d 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -276,6 +276,8 @@ class Migrations extends Action $this->dbForProject, $this->getDatabasesDB, Config::getParam('collections', [])['databases']['collections'], + $options['overwrite'] ?? false, + $options['skip'] ?? false, ), DestinationCSV::getName() => new DestinationCSV( $this->deviceForFiles, From c5fe71684af7582eb439701540ce50212efc1199 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Wed, 15 Apr 2026 14:23:02 +0100 Subject: [PATCH 030/211] Add E2E tests for CSV import overwrite/skip flags Three new test methods in MigrationsBase, following the existing testCreateCSVImport setup pattern: - testCreateCSVImportSkipDuplicates Seeds documents.csv, mutates one row, re-imports with skip=true. Asserts the mutated row keeps its mutated value (not overwritten by the CSV's original value) and the row count stays at 100. - testCreateCSVImportOverwrite Seeds documents.csv, mutates one row, re-imports with overwrite=true. Asserts the mutated row is restored to the CSV's original value (proving upsertDocuments actually replaced the row) and the row count stays at 100. - testCreateCSVImportDefaultFailsOnDuplicate Regression guard: re-imports documents.csv with no flags. Asserts the migration goes to status=failed with errors populated, proving the default duplicate-throws behavior is preserved. All three share a prepareCsvImportFixture() helper that sets up database + table (name, age columns) + bucket + documents.csv upload. Returns the known first-row id + original name/age so tests can mutate and assert on a predictable row. Reuses the existing documents.csv fixture (100 rows with \$id as the first column). No new fixture files needed. --- .../Services/Migrations/MigrationsBase.php | 244 ++++++++++++++++++ 1 file changed, 244 insertions(+) diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 9e9ce2fbcd..37036cadc2 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1482,6 +1482,250 @@ trait MigrationsBase }, 10_000, 500); } + /** + * Set up a database + table + bucket + uploaded CSV for the skip/overwrite tests. + * Returns [$databaseId, $tableId, $bucketId, $fileId, $firstRowId, $firstRowName, $firstRowAge]. + * + * @return array{string,string,string,string,string,string,int} + */ + private function prepareCsvImportFixture(string $testLabel): array + { + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]; + + // database + $response = $this->client->call(Client::METHOD_POST, '/databases', $headers, [ + 'databaseId' => ID::unique(), + 'name' => 'Test DB ' . $testLabel, + ]); + $this->assertEquals(201, $response['headers']['status-code']); + $databaseId = $response['body']['$id']; + + // table + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', $headers, [ + 'name' => 'Test table ' . $testLabel, + 'tableId' => ID::unique(), + ]); + $this->assertEquals(201, $response['headers']['status-code']); + $tableId = $response['body']['$id']; + + // columns: name, age (match documents.csv fixture) + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string', $headers, [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + $this->assertEquals(202, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer', $headers, [ + 'key' => 'age', + 'min' => 18, + 'max' => 65, + 'required' => true, + ]); + $this->assertEquals(202, $response['headers']['status-code']); + + // bucket + $response = $this->client->call(Client::METHOD_POST, '/storage/buckets', $headers, [ + 'bucketId' => ID::unique(), + 'name' => 'Bucket ' . $testLabel, + 'maximumFileSize' => 2000000, + 'allowedFileExtensions' => ['csv'], + ]); + $this->assertEquals(201, $response['headers']['status-code']); + $bucketId = $response['body']['$id']; + + // upload documents.csv (100 rows with $id, name, age columns) + $response = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'fileId' => ID::unique(), + 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/csv/documents.csv'), 'text/csv', 'documents.csv'), + ]); + $this->assertEquals(201, $response['headers']['status-code']); + $fileId = $response['body']['$id']; + + // first row in documents.csv: hxfcwpcas5xokpwe,Diamond Mendez,56 + return [$databaseId, $tableId, $bucketId, $fileId, 'hxfcwpcas5xokpwe', 'Diamond Mendez', 56]; + } + + /** + * skip=true on re-import: duplicates are silently no-op'd, existing rows preserved unchanged. + */ + public function testCreateCSVImportSkipDuplicates(): void + { + [$databaseId, $tableId, $bucketId, $fileId, $rowId, $originalName, $originalAge] = $this->prepareCsvImportFixture('skip'); + + // First import: 100 rows created + $first = $this->performCsvMigration([ + 'fileId' => $fileId, + 'bucketId' => $bucketId, + 'resourceId' => $databaseId . ':' . $tableId, + ]); + $this->assertEventually(function () use ($first) { + $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $first['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals('completed', $migration['body']['status']); + $this->assertEquals(100, $migration['body']['statusCounters'][Resource::TYPE_ROW]['success']); + }, 10_000, 500); + + // Mutate one row so we can prove skip does NOT overwrite it + $mutate = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + 'data' => ['age' => 22], + ]); + $this->assertEquals(200, $mutate['headers']['status-code']); + $this->assertEquals(22, $mutate['body']['age']); + + // Second import with skip=true: no errors, mutated row preserved + $second = $this->performCsvMigration([ + 'fileId' => $fileId, + 'bucketId' => $bucketId, + 'resourceId' => $databaseId . ':' . $tableId, + 'skip' => true, + ]); + $this->assertEventually(function () use ($second) { + $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $second['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals('completed', $migration['body']['status']); + }, 10_000, 500); + + // Mutated row kept its mutated value (not overwritten by CSV's original age) + $row = $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, $row['headers']['status-code']); + $this->assertEquals($originalName, $row['body']['name']); + $this->assertEquals(22, $row['body']['age'], 'skip=true must not overwrite mutated row'); + + // Row count still 100 (no duplicates created) + $rows = $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(150)->toString()], + ]); + $this->assertEquals(100, $rows['body']['total']); + } + + /** + * overwrite=true on re-import: existing rows are replaced with imported values. + */ + public function testCreateCSVImportOverwrite(): void + { + [$databaseId, $tableId, $bucketId, $fileId, $rowId, $originalName, $originalAge] = $this->prepareCsvImportFixture('overwrite'); + + // First import: 100 rows created + $first = $this->performCsvMigration([ + 'fileId' => $fileId, + 'bucketId' => $bucketId, + 'resourceId' => $databaseId . ':' . $tableId, + ]); + $this->assertEventually(function () use ($first) { + $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $first['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals('completed', $migration['body']['status']); + $this->assertEquals(100, $migration['body']['statusCounters'][Resource::TYPE_ROW]['success']); + }, 10_000, 500); + + // Mutate one row so we can prove overwrite restores it to the CSV's original value + $mutate = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + 'data' => ['age' => 22], + ]); + $this->assertEquals(200, $mutate['headers']['status-code']); + $this->assertEquals(22, $mutate['body']['age']); + + // Second import with overwrite=true: mutated row restored to CSV value + $second = $this->performCsvMigration([ + 'fileId' => $fileId, + 'bucketId' => $bucketId, + 'resourceId' => $databaseId . ':' . $tableId, + 'overwrite' => true, + ]); + $this->assertEventually(function () use ($second) { + $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $second['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals('completed', $migration['body']['status']); + }, 10_000, 500); + + // Mutated row is back to CSV's original age (proving overwrite actually replaced the row) + $row = $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, $row['headers']['status-code']); + $this->assertEquals($originalName, $row['body']['name']); + $this->assertEquals($originalAge, $row['body']['age'], 'overwrite=true must restore row to imported value'); + + // Row count still 100 (no duplicates created) + $rows = $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(150)->toString()], + ]); + $this->assertEquals(100, $rows['body']['total']); + } + + /** + * Default behavior (neither flag): re-import of duplicate ids fails with DuplicateException. + * Regression guard so the skip/overwrite additions don't silently change the default. + */ + public function testCreateCSVImportDefaultFailsOnDuplicate(): void + { + [$databaseId, $tableId, $bucketId, $fileId] = $this->prepareCsvImportFixture('default'); + + // First import: succeeds + $first = $this->performCsvMigration([ + 'fileId' => $fileId, + 'bucketId' => $bucketId, + 'resourceId' => $databaseId . ':' . $tableId, + ]); + $this->assertEventually(function () use ($first) { + $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $first['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals('completed', $migration['body']['status']); + }, 10_000, 500); + + // Second import with no flags: should fail on duplicate ids + $second = $this->performCsvMigration([ + 'fileId' => $fileId, + 'bucketId' => $bucketId, + 'resourceId' => $databaseId . ':' . $tableId, + ]); + $this->assertEventually(function () use ($second) { + $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $second['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals('finished', $migration['body']['stage']); + $this->assertEquals('failed', $migration['body']['status']); + $this->assertNotEmpty($migration['body']['errors']); + }, 60_000, 500); + } + private function performCsvMigration(array $body): array { return $this->client->call(Client::METHOD_POST, '/migrations/csv', [ From d84f71e728fe9af0b412cf325daafd05d9ed5431 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 16 Apr 2026 14:10:20 +0530 Subject: [PATCH 031/211] updated --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 270491a291..d456c314a3 100644 --- a/composer.lock +++ b/composer.lock @@ -3854,12 +3854,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "7315ba260141830ec1f51963955e12695988c281" + "reference": "6ff2d7b081f99280ffb85dd6efa710c9aeb3e620" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/7315ba260141830ec1f51963955e12695988c281", - "reference": "7315ba260141830ec1f51963955e12695988c281", + "url": "https://api.github.com/repos/utopia-php/database/zipball/6ff2d7b081f99280ffb85dd6efa710c9aeb3e620", + "reference": "6ff2d7b081f99280ffb85dd6efa710c9aeb3e620", "shasum": "" }, "require": { @@ -3905,7 +3905,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/big-init" }, - "time": "2026-04-16T08:36:02+00:00" + "time": "2026-04-16T08:39:46+00:00" }, { "name": "utopia-php/detector", From e7072574adb5a6035bc207f232bd2141de453ca6 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 16 Apr 2026 14:13:01 +0530 Subject: [PATCH 032/211] updated tests --- .../Http/Databases/Collections/Create.php | 3 --- .../TablesDB/DatabasesNumericTypesTest.php | 18 +++++++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index 24cec35eac..32c311b10a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -277,9 +277,6 @@ class Create extends Action $key = $attribute['key']; $type = $attribute['type']; switch ($type) { - case Database::VAR_INTEGER: - $size = 4; - break; case Database::VAR_BIGINT: $size = 8; break; diff --git a/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php b/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php index 2da7769672..0e46d9466c 100644 --- a/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php +++ b/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php @@ -75,9 +75,9 @@ class DatabasesNumericTypesTest extends Scope $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/bigint', $headers, [ 'key' => 'bigint_field', 'required' => false, - 'min' => -900719925, - 'max' => 900719925, - 'default' => 123, + 'min' => -9007199254740991, + 'max' => 9007199254740991, + 'default' => 9007199254740000, ]); // Cache before waiting so that if waitForAllAttributes times out, @@ -139,9 +139,9 @@ class DatabasesNumericTypesTest extends Scope $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/bigint', $headers, [ 'key' => 'bigint_field', 'required' => false, - 'min' => -900719925, - 'max' => 900719925, - 'default' => 123, + 'min' => -9007199254740991, + 'max' => 9007199254740991, + 'default' => 9007199254740000, ]); $this->waitForAllAttributes($databaseId, $tableId); @@ -213,9 +213,9 @@ class DatabasesNumericTypesTest extends Scope $this->assertEquals('bigint', $bigintColumn['body']['type']); $this->assertEquals(false, $bigintColumn['body']['required']); $this->assertEquals(false, $bigintColumn['body']['array']); - $this->assertEquals(-900719925, $bigintColumn['body']['min']); - $this->assertEquals(900719925, $bigintColumn['body']['max']); - $this->assertEquals(123, $bigintColumn['body']['default']); + $this->assertEquals(-9007199254740991, $bigintColumn['body']['min']); + $this->assertEquals(9007199254740991, $bigintColumn['body']['max']); + $this->assertEquals(9007199254740000, $bigintColumn['body']['default']); } public function testListColumnsWithNumericTypes(): void From 8fa28257bedc2915ec885e92bce4c2797821a0b1 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 20 Apr 2026 10:28:05 +0100 Subject: [PATCH 033/211] Migrations: replace overwrite/skip with onDuplicate enum string, bump database to 5.3.22 --- app/controllers/api/migrations.php | 27 ++++----- composer.json | 2 +- composer.lock | 55 ++++++++----------- src/Appwrite/Platform/Workers/Migrations.php | 3 +- .../Services/Migrations/MigrationsBase.php | 20 +++---- 5 files changed, 46 insertions(+), 61 deletions(-) diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index f19598c198..5868695bd3 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -26,6 +26,7 @@ use Utopia\Database\Validator\Queries\Documents; use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; use Utopia\Http\Http; +use Utopia\Migration\Destinations\Appwrite as DestinationAppwrite; use Utopia\Migration\Resource; use Utopia\Migration\Sources\Appwrite; use Utopia\Migration\Sources\CSV; @@ -87,15 +88,14 @@ Http::post('/v1/migrations/appwrite') ->param('endpoint', '', new URL(), 'Source Appwrite endpoint') ->param('projectId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Source Project ID', false, ['dbForProject']) ->param('apiKey', '', new Text(512), 'Source API Key') - ->param('overwrite', false, new Boolean(), 'When true, replace existing rows by calling upsertDocuments instead of createDocuments. Rows with matching IDs will be updated with the imported values.', true) - ->param('skip', false, new Boolean(), 'When true, silently ignore rows whose IDs already exist in the destination. Existing rows are preserved unchanged.', true) + ->param('onDuplicate', DestinationAppwrite::ON_DUPLICATE_FAIL, new WhiteList(DestinationAppwrite::ON_DUPLICATES), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "upsert": replace existing row.', true) ->inject('response') ->inject('dbForProject') ->inject('project') ->inject('platform') ->inject('queueForEvents') ->inject('publisherForMigrations') - ->action(function (array $resources, string $endpoint, string $projectId, string $apiKey, bool $overwrite, bool $skip, Response $response, Database $dbForProject, Document $project, array $platform, Event $queueForEvents, MigrationPublisher $publisherForMigrations) { + ->action(function (array $resources, string $endpoint, string $projectId, string $apiKey, string $onDuplicate, Response $response, Database $dbForProject, Document $project, array $platform, Event $queueForEvents, MigrationPublisher $publisherForMigrations) { $migration = $dbForProject->createDocument('migrations', new Document([ '$id' => ID::unique(), 'status' => 'pending', @@ -112,8 +112,7 @@ Http::post('/v1/migrations/appwrite') 'resourceData' => '{}', 'errors' => [], 'options' => [ - 'overwrite' => $overwrite, - 'skip' => $skip, + 'onDuplicate' => $onDuplicate, ], ])); @@ -358,8 +357,7 @@ Http::post('/v1/migrations/csv/imports') ->param('fileId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'File ID.', false, ['dbForProject']) ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.') ->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true) - ->param('overwrite', false, new Boolean(), 'When true, replace existing rows by calling upsertDocuments instead of createDocuments. Rows with matching IDs will be updated with the imported values.', true) - ->param('skip', false, new Boolean(), 'When true, silently ignore rows whose IDs already exist in the destination. Existing rows are preserved unchanged.', true) + ->param('onDuplicate', DestinationAppwrite::ON_DUPLICATE_FAIL, new WhiteList(DestinationAppwrite::ON_DUPLICATES), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "upsert": replace existing row.', true) ->inject('response') ->inject('dbForProject') ->inject('dbForPlatform') @@ -375,8 +373,7 @@ Http::post('/v1/migrations/csv/imports') string $fileId, string $resourceId, bool $internalFile, - bool $overwrite, - bool $skip, + string $onDuplicate, Response $response, Database $dbForProject, Database $dbForPlatform, @@ -477,8 +474,7 @@ Http::post('/v1/migrations/csv/imports') 'options' => [ 'path' => $newPath, 'size' => $fileSize, - 'overwrite' => $overwrite, - 'skip' => $skip, + 'onDuplicate' => $onDuplicate, ], ])); @@ -668,8 +664,7 @@ Http::post('/v1/migrations/json/imports') ->param('fileId', '', new UID(), 'File ID.') ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.') ->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true) - ->param('overwrite', false, new Boolean(), 'When true, replace existing rows by calling upsertDocuments instead of createDocuments. Rows with matching IDs will be updated with the imported values.', true) - ->param('skip', false, new Boolean(), 'When true, silently ignore rows whose IDs already exist in the destination. Existing rows are preserved unchanged.', true) + ->param('onDuplicate', DestinationAppwrite::ON_DUPLICATE_FAIL, new WhiteList(DestinationAppwrite::ON_DUPLICATES), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "upsert": replace existing row.', true) ->inject('response') ->inject('dbForProject') ->inject('dbForPlatform') @@ -685,8 +680,7 @@ Http::post('/v1/migrations/json/imports') string $fileId, string $resourceId, bool $internalFile, - bool $overwrite, - bool $skip, + string $onDuplicate, Response $response, Database $dbForProject, Database $dbForPlatform, @@ -786,8 +780,7 @@ Http::post('/v1/migrations/json/imports') 'options' => [ 'path' => $newPath, 'size' => $fileSize, - 'overwrite' => $overwrite, - 'skip' => $skip, + 'onDuplicate' => $onDuplicate, ], ])); diff --git a/composer.json b/composer.json index 2dbe5616e5..d8bb03d120 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "utopia-php/compression": "0.1.*", "utopia-php/config": "1.*", "utopia-php/console": "0.1.*", - "utopia-php/database": "dev-csv-import-upsert-v2 as 5.99.0", + "utopia-php/database": "5.3.22", "utopia-php/detector": "0.2.*", "utopia-php/domains": "1.*", "utopia-php/emails": "0.6.*", diff --git a/composer.lock b/composer.lock index e93af8906a..de21fbef5e 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": "0cabf47b85d8fac9a1f78df82b0add1f", + "content-hash": "cce51bafc6cbb73585a51e7495b2e6cc", "packages": [ { "name": "adhocore/jwt", @@ -2887,7 +2887,7 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.35.0", + "version": "v1.36.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", @@ -2948,7 +2948,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.35.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.36.0" }, "funding": [ { @@ -2972,7 +2972,7 @@ }, { "name": "symfony/polyfill-php82", - "version": "v1.35.0", + "version": "v1.36.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php82.git", @@ -3028,7 +3028,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php82/tree/v1.35.0" + "source": "https://github.com/symfony/polyfill-php82/tree/v1.36.0" }, "funding": [ { @@ -3052,7 +3052,7 @@ }, { "name": "symfony/polyfill-php83", - "version": "v1.35.0", + "version": "v1.36.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php83.git", @@ -3108,7 +3108,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php83/tree/v1.35.0" + "source": "https://github.com/symfony/polyfill-php83/tree/v1.36.0" }, "funding": [ { @@ -3132,7 +3132,7 @@ }, { "name": "symfony/polyfill-php85", - "version": "v1.35.0", + "version": "v1.36.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php85.git", @@ -3188,7 +3188,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php85/tree/v1.35.0" + "source": "https://github.com/symfony/polyfill-php85/tree/v1.36.0" }, "funding": [ { @@ -3850,16 +3850,16 @@ }, { "name": "utopia-php/database", - "version": "dev-csv-import-upsert-v2", + "version": "5.3.22", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "52b189bded7ef409bb978483a7231d779051b510" + "reference": "d765945da6b3141852014b2f96ecf1fe7e3d6ba7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/52b189bded7ef409bb978483a7231d779051b510", - "reference": "52b189bded7ef409bb978483a7231d779051b510", + "url": "https://api.github.com/repos/utopia-php/database/zipball/d765945da6b3141852014b2f96ecf1fe7e3d6ba7", + "reference": "d765945da6b3141852014b2f96ecf1fe7e3d6ba7", "shasum": "" }, "require": { @@ -3903,9 +3903,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/csv-import-upsert-v2" + "source": "https://github.com/utopia-php/database/tree/5.3.22" }, - "time": "2026-04-15T10:53:53+00:00" + "time": "2026-04-20T07:12:46+00:00" }, { "name": "utopia-php/detector", @@ -4530,12 +4530,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "2012cda162ad0ab79678c924d7534de6f3ec85ad" + "reference": "6025318d61c15355015c0e34427480e84ad690ad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/2012cda162ad0ab79678c924d7534de6f3ec85ad", - "reference": "2012cda162ad0ab79678c924d7534de6f3ec85ad", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/6025318d61c15355015c0e34427480e84ad690ad", + "reference": "6025318d61c15355015c0e34427480e84ad690ad", "shasum": "" }, "require": { @@ -4544,7 +4544,7 @@ "ext-openssl": "*", "halaxa/json-machine": "^1.2", "php": ">=8.1", - "utopia-php/database": "dev-csv-import-upsert-v2 as 5.99.0", + "utopia-php/database": "5.3.22", "utopia-php/dsn": "0.2.*", "utopia-php/storage": "1.0.*" }, @@ -4577,7 +4577,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-15T12:36:51+00:00" + "time": "2026-04-20T09:07:20+00:00" }, { "name": "utopia-php/mongo", @@ -7778,7 +7778,7 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.35.0", + "version": "v1.36.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", @@ -7837,7 +7837,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.35.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.36.0" }, "funding": [ { @@ -8028,7 +8028,7 @@ }, { "name": "symfony/polyfill-php81", - "version": "v1.35.0", + "version": "v1.36.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php81.git", @@ -8084,7 +8084,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php81/tree/v1.35.0" + "source": "https://github.com/symfony/polyfill-php81/tree/v1.36.0" }, "funding": [ { @@ -8441,12 +8441,6 @@ } ], "aliases": [ - { - "package": "utopia-php/database", - "version": "dev-csv-import-upsert-v2", - "alias": "5.99.0", - "alias_normalized": "5.99.0.0" - }, { "package": "utopia-php/migration", "version": "dev-feat/skip-duplicates", @@ -8456,7 +8450,6 @@ ], "minimum-stability": "dev", "stability-flags": { - "utopia-php/database": 20, "utopia-php/migration": 20 }, "prefer-stable": true, diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 710b24c19d..6a440e54c0 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -276,8 +276,7 @@ class Migrations extends Action $this->dbForProject, $this->getDatabasesDB, Config::getParam('collections', [])['databases']['collections'], - $options['overwrite'] ?? false, - $options['skip'] ?? false, + $options['onDuplicate'] ?? DestinationAppwrite::ON_DUPLICATE_FAIL, ), DestinationCSV::getName() => new DestinationCSV( $this->deviceForFiles, diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 37036cadc2..35f196ec49 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1554,7 +1554,7 @@ trait MigrationsBase } /** - * skip=true on re-import: duplicates are silently no-op'd, existing rows preserved unchanged. + * onDuplicate=skip on re-import: duplicates are silently no-op'd, existing rows preserved unchanged. */ public function testCreateCSVImportSkipDuplicates(): void { @@ -1586,12 +1586,12 @@ trait MigrationsBase $this->assertEquals(200, $mutate['headers']['status-code']); $this->assertEquals(22, $mutate['body']['age']); - // Second import with skip=true: no errors, mutated row preserved + // Second import with onDuplicate=skip: no errors, mutated row preserved $second = $this->performCsvMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, 'resourceId' => $databaseId . ':' . $tableId, - 'skip' => true, + 'onDuplicate' => 'skip', ]); $this->assertEventually(function () use ($second) { $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $second['body']['$id'], array_merge([ @@ -1608,7 +1608,7 @@ trait MigrationsBase ], $this->getHeaders())); $this->assertEquals(200, $row['headers']['status-code']); $this->assertEquals($originalName, $row['body']['name']); - $this->assertEquals(22, $row['body']['age'], 'skip=true must not overwrite mutated row'); + $this->assertEquals(22, $row['body']['age'], 'onDuplicate=skip must not overwrite mutated row'); // Row count still 100 (no duplicates created) $rows = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ @@ -1621,7 +1621,7 @@ trait MigrationsBase } /** - * overwrite=true on re-import: existing rows are replaced with imported values. + * onDuplicate=upsert on re-import: existing rows are replaced with imported values. */ public function testCreateCSVImportOverwrite(): void { @@ -1642,7 +1642,7 @@ trait MigrationsBase $this->assertEquals(100, $migration['body']['statusCounters'][Resource::TYPE_ROW]['success']); }, 10_000, 500); - // Mutate one row so we can prove overwrite restores it to the CSV's original value + // Mutate one row so we can prove upsert restores it to the CSV's original value $mutate = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -1653,12 +1653,12 @@ trait MigrationsBase $this->assertEquals(200, $mutate['headers']['status-code']); $this->assertEquals(22, $mutate['body']['age']); - // Second import with overwrite=true: mutated row restored to CSV value + // Second import with onDuplicate=upsert: mutated row restored to CSV value $second = $this->performCsvMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, 'resourceId' => $databaseId . ':' . $tableId, - 'overwrite' => true, + 'onDuplicate' => 'upsert', ]); $this->assertEventually(function () use ($second) { $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $second['body']['$id'], array_merge([ @@ -1668,14 +1668,14 @@ trait MigrationsBase $this->assertEquals('completed', $migration['body']['status']); }, 10_000, 500); - // Mutated row is back to CSV's original age (proving overwrite actually replaced the row) + // Mutated row is back to CSV's original age (proving upsert actually replaced the row) $row = $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, $row['headers']['status-code']); $this->assertEquals($originalName, $row['body']['name']); - $this->assertEquals($originalAge, $row['body']['age'], 'overwrite=true must restore row to imported value'); + $this->assertEquals($originalAge, $row['body']['age'], 'onDuplicate=upsert must restore row to imported value'); // Row count still 100 (no duplicates created) $rows = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ From 18f9dfb64e22c681320b5711038f7e8d007870be Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 20 Apr 2026 13:16:45 +0100 Subject: [PATCH 034/211] Bump utopia-php/migration to 1.9.2, use OnDuplicate enum --- app/controllers/api/migrations.php | 8 +++--- composer.json | 2 +- composer.lock | 29 +++++++------------- src/Appwrite/Platform/Workers/Migrations.php | 3 +- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index 5868695bd3..ef71f8f6ef 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -26,7 +26,7 @@ use Utopia\Database\Validator\Queries\Documents; use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; use Utopia\Http\Http; -use Utopia\Migration\Destinations\Appwrite as DestinationAppwrite; +use Utopia\Migration\Destinations\OnDuplicate; use Utopia\Migration\Resource; use Utopia\Migration\Sources\Appwrite; use Utopia\Migration\Sources\CSV; @@ -88,7 +88,7 @@ Http::post('/v1/migrations/appwrite') ->param('endpoint', '', new URL(), 'Source Appwrite endpoint') ->param('projectId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Source Project ID', false, ['dbForProject']) ->param('apiKey', '', new Text(512), 'Source API Key') - ->param('onDuplicate', DestinationAppwrite::ON_DUPLICATE_FAIL, new WhiteList(DestinationAppwrite::ON_DUPLICATES), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "upsert": replace existing row.', true) + ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "upsert": replace existing row.', true) ->inject('response') ->inject('dbForProject') ->inject('project') @@ -357,7 +357,7 @@ Http::post('/v1/migrations/csv/imports') ->param('fileId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'File ID.', false, ['dbForProject']) ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.') ->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true) - ->param('onDuplicate', DestinationAppwrite::ON_DUPLICATE_FAIL, new WhiteList(DestinationAppwrite::ON_DUPLICATES), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "upsert": replace existing row.', true) + ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "upsert": replace existing row.', true) ->inject('response') ->inject('dbForProject') ->inject('dbForPlatform') @@ -664,7 +664,7 @@ Http::post('/v1/migrations/json/imports') ->param('fileId', '', new UID(), 'File ID.') ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.') ->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true) - ->param('onDuplicate', DestinationAppwrite::ON_DUPLICATE_FAIL, new WhiteList(DestinationAppwrite::ON_DUPLICATES), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "upsert": replace existing row.', true) + ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "upsert": replace existing row.', true) ->inject('response') ->inject('dbForProject') ->inject('dbForPlatform') diff --git a/composer.json b/composer.json index d8bb03d120..2f8ea37011 100644 --- a/composer.json +++ b/composer.json @@ -73,7 +73,7 @@ "utopia-php/locale": "0.8.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.22.*", - "utopia-php/migration": "dev-feat/skip-duplicates as 1.9.99", + "utopia-php/migration": "1.9.2", "utopia-php/platform": "0.12.*", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", diff --git a/composer.lock b/composer.lock index de21fbef5e..7e09c5cf00 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": "cce51bafc6cbb73585a51e7495b2e6cc", + "content-hash": "8fe5034e4c20ba22c778a666ef451dd9", "packages": [ { "name": "adhocore/jwt", @@ -4526,16 +4526,16 @@ }, { "name": "utopia-php/migration", - "version": "dev-feat/skip-duplicates", + "version": "1.9.2", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "6025318d61c15355015c0e34427480e84ad690ad" + "reference": "97266905f35260137ba0b0e0c4f849f1ee422e43" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/6025318d61c15355015c0e34427480e84ad690ad", - "reference": "6025318d61c15355015c0e34427480e84ad690ad", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/97266905f35260137ba0b0e0c4f849f1ee422e43", + "reference": "97266905f35260137ba0b0e0c4f849f1ee422e43", "shasum": "" }, "require": { @@ -4544,7 +4544,7 @@ "ext-openssl": "*", "halaxa/json-machine": "^1.2", "php": ">=8.1", - "utopia-php/database": "5.3.22", + "utopia-php/database": "5.*", "utopia-php/dsn": "0.2.*", "utopia-php/storage": "1.0.*" }, @@ -4575,9 +4575,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" + "source": "https://github.com/utopia-php/migration/tree/1.9.2" }, - "time": "2026-04-20T09:07:20+00:00" + "time": "2026-04-20T11:55:43+00:00" }, { "name": "utopia-php/mongo", @@ -8440,18 +8440,9 @@ "time": "2024-11-07T12:36:22+00:00" } ], - "aliases": [ - { - "package": "utopia-php/migration", - "version": "dev-feat/skip-duplicates", - "alias": "1.9.99", - "alias_normalized": "1.9.99.0" - } - ], + "aliases": [], "minimum-stability": "dev", - "stability-flags": { - "utopia-php/migration": 20 - }, + "stability-flags": {}, "prefer-stable": true, "prefer-lowest": false, "platform": { diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 6a440e54c0..d88ab23535 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -30,6 +30,7 @@ use Utopia\Migration\Destination; use Utopia\Migration\Destinations\Appwrite as DestinationAppwrite; use Utopia\Migration\Destinations\CSV as DestinationCSV; use Utopia\Migration\Destinations\JSON as DestinationJSON; +use Utopia\Migration\Destinations\OnDuplicate; use Utopia\Migration\Exception as MigrationException; use Utopia\Migration\Resource; use Utopia\Migration\Resources\Database\Database as ResourceDatabase; @@ -276,7 +277,7 @@ class Migrations extends Action $this->dbForProject, $this->getDatabasesDB, Config::getParam('collections', [])['databases']['collections'], - $options['onDuplicate'] ?? DestinationAppwrite::ON_DUPLICATE_FAIL, + OnDuplicate::tryFrom($options['onDuplicate'] ?? '') ?? OnDuplicate::Fail, ), DestinationCSV::getName() => new DestinationCSV( $this->deviceForFiles, From f3c2502a8cec9dd2dfdcf8715303d8c321ea9bfa Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 20 Apr 2026 13:56:25 +0100 Subject: [PATCH 035/211] composer: widen database/migration pins to minor-version wildcards --- composer.json | 4 ++-- composer.lock | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 2f8ea37011..d7681742a5 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "utopia-php/compression": "0.1.*", "utopia-php/config": "1.*", "utopia-php/console": "0.1.*", - "utopia-php/database": "5.3.22", + "utopia-php/database": "5.3.*", "utopia-php/detector": "0.2.*", "utopia-php/domains": "1.*", "utopia-php/emails": "0.6.*", @@ -73,7 +73,7 @@ "utopia-php/locale": "0.8.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.22.*", - "utopia-php/migration": "1.9.2", + "utopia-php/migration": "1.9.*", "utopia-php/platform": "0.12.*", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", diff --git a/composer.lock b/composer.lock index 7e09c5cf00..423b5bef9c 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": "8fe5034e4c20ba22c778a666ef451dd9", + "content-hash": "86a1fe0eb48da6028c13db50640cc4f6", "packages": [ { "name": "adhocore/jwt", From e878b0b403e73fe7feee9543fb95b16157e0da6f Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 20 Apr 2026 14:43:45 +0100 Subject: [PATCH 036/211] tests: cover onDuplicate on JSON import endpoint + column readiness wait --- .../Services/Migrations/MigrationsBase.php | 250 ++++++++++++++++++ 1 file changed, 250 insertions(+) diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 35f196ec49..3adff48036 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1528,6 +1528,16 @@ trait MigrationsBase ]); $this->assertEquals(202, $response['headers']['status-code']); + // Columns are created async (202). Wait for both to be `available` + // before proceeding so the migration worker doesn't race the schema. + foreach (['name', 'age'] as $column) { + $this->assertEventually(function () use ($databaseId, $tableId, $column, $headers) { + $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/' . $column, $headers); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('available', $response['body']['status']); + }, 5000, 500); + } + // bucket $response = $this->client->call(Client::METHOD_POST, '/storage/buckets', $headers, [ 'bucketId' => ID::unique(), @@ -1735,6 +1745,246 @@ trait MigrationsBase ], $body); } + /** + * Set up a database + table + bucket + uploaded JSON for the skip/overwrite tests. + * Mirrors prepareCsvImportFixture but uploads documents.json instead. + * + * @return array{string,string,string,string,string,string,int} + */ + private function prepareJsonImportFixture(string $testLabel): array + { + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]; + + // database + $response = $this->client->call(Client::METHOD_POST, '/databases', $headers, [ + 'databaseId' => ID::unique(), + 'name' => 'Test JSON DB ' . $testLabel, + ]); + $this->assertEquals(201, $response['headers']['status-code']); + $databaseId = $response['body']['$id']; + + // table + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', $headers, [ + 'name' => 'Test JSON table ' . $testLabel, + 'tableId' => ID::unique(), + ]); + $this->assertEquals(201, $response['headers']['status-code']); + $tableId = $response['body']['$id']; + + // columns: name, age (match documents.json fixture) + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string', $headers, [ + 'key' => 'name', + 'size' => 256, + 'required' => true, + ]); + $this->assertEquals(202, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer', $headers, [ + 'key' => 'age', + 'min' => 18, + 'max' => 65, + 'required' => true, + ]); + $this->assertEquals(202, $response['headers']['status-code']); + + foreach (['name', 'age'] as $column) { + $this->assertEventually(function () use ($databaseId, $tableId, $column, $headers) { + $response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/' . $column, $headers); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('available', $response['body']['status']); + }, 5000, 500); + } + + // bucket + $response = $this->client->call(Client::METHOD_POST, '/storage/buckets', $headers, [ + 'bucketId' => ID::unique(), + 'name' => 'JSON Bucket ' . $testLabel, + 'maximumFileSize' => 2000000, + 'allowedFileExtensions' => ['json'], + ]); + $this->assertEquals(201, $response['headers']['status-code']); + $bucketId = $response['body']['$id']; + + // upload documents.json (same row shape as documents.csv) + $response = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'fileId' => ID::unique(), + 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/json/documents.json'), 'application/json', 'documents.json'), + ]); + $this->assertEquals(201, $response['headers']['status-code']); + $fileId = $response['body']['$id']; + + // first row in documents.json: hxfcwpcas5xokpwe, Diamond Mendez, 56 + return [$databaseId, $tableId, $bucketId, $fileId, 'hxfcwpcas5xokpwe', 'Diamond Mendez', 56]; + } + + /** + * onDuplicate=skip on JSON re-import: duplicates silently no-op, existing rows preserved unchanged. + */ + public function testCreateJSONImportSkipDuplicates(): void + { + [$databaseId, $tableId, $bucketId, $fileId, $rowId, $originalName, $originalAge] = $this->prepareJsonImportFixture('skip'); + + $first = $this->performJsonMigration([ + 'fileId' => $fileId, + 'bucketId' => $bucketId, + 'resourceId' => $databaseId . ':' . $tableId, + ]); + $this->assertEventually(function () use ($first) { + $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $first['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals('completed', $migration['body']['status']); + $this->assertEquals(100, $migration['body']['statusCounters'][Resource::TYPE_ROW]['success']); + }, 10_000, 500); + + // Mutate one row so we can prove skip does NOT overwrite it + $mutate = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + 'data' => ['age' => 22], + ]); + $this->assertEquals(200, $mutate['headers']['status-code']); + $this->assertEquals(22, $mutate['body']['age']); + + $second = $this->performJsonMigration([ + 'fileId' => $fileId, + 'bucketId' => $bucketId, + 'resourceId' => $databaseId . ':' . $tableId, + 'onDuplicate' => 'skip', + ]); + $this->assertEventually(function () use ($second) { + $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $second['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals('completed', $migration['body']['status']); + }, 10_000, 500); + + $row = $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, $row['headers']['status-code']); + $this->assertEquals($originalName, $row['body']['name']); + $this->assertEquals(22, $row['body']['age'], 'onDuplicate=skip must not overwrite mutated row'); + + $rows = $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(150)->toString()], + ]); + $this->assertEquals(100, $rows['body']['total']); + } + + /** + * onDuplicate=upsert on JSON re-import: existing rows replaced with imported values. + */ + public function testCreateJSONImportOverwrite(): void + { + [$databaseId, $tableId, $bucketId, $fileId, $rowId, $originalName, $originalAge] = $this->prepareJsonImportFixture('overwrite'); + + $first = $this->performJsonMigration([ + 'fileId' => $fileId, + 'bucketId' => $bucketId, + 'resourceId' => $databaseId . ':' . $tableId, + ]); + $this->assertEventually(function () use ($first) { + $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $first['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals('completed', $migration['body']['status']); + $this->assertEquals(100, $migration['body']['statusCounters'][Resource::TYPE_ROW]['success']); + }, 10_000, 500); + + $mutate = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + 'data' => ['age' => 22], + ]); + $this->assertEquals(200, $mutate['headers']['status-code']); + $this->assertEquals(22, $mutate['body']['age']); + + $second = $this->performJsonMigration([ + 'fileId' => $fileId, + 'bucketId' => $bucketId, + 'resourceId' => $databaseId . ':' . $tableId, + 'onDuplicate' => 'upsert', + ]); + $this->assertEventually(function () use ($second) { + $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $second['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals('completed', $migration['body']['status']); + }, 10_000, 500); + + $row = $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, $row['headers']['status-code']); + $this->assertEquals($originalName, $row['body']['name']); + $this->assertEquals($originalAge, $row['body']['age'], 'onDuplicate=upsert must restore row to imported value'); + + $rows = $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(150)->toString()], + ]); + $this->assertEquals(100, $rows['body']['total']); + } + + /** + * Default (no onDuplicate) on JSON re-import: regression guard, must fail on duplicate ids. + */ + public function testCreateJSONImportDefaultFailsOnDuplicate(): void + { + [$databaseId, $tableId, $bucketId, $fileId] = $this->prepareJsonImportFixture('default'); + + $first = $this->performJsonMigration([ + 'fileId' => $fileId, + 'bucketId' => $bucketId, + 'resourceId' => $databaseId . ':' . $tableId, + ]); + $this->assertEventually(function () use ($first) { + $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $first['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals('completed', $migration['body']['status']); + }, 10_000, 500); + + $second = $this->performJsonMigration([ + 'fileId' => $fileId, + 'bucketId' => $bucketId, + 'resourceId' => $databaseId . ':' . $tableId, + ]); + $this->assertEventually(function () use ($second) { + $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $second['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals('finished', $migration['body']['stage']); + $this->assertEquals('failed', $migration['body']['status']); + $this->assertNotEmpty($migration['body']['errors']); + }, 60_000, 500); + } + /** * Test CSV export with email notification */ From fc6bd7232e9105d59bdb584c156b397f9f675740 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 20 Apr 2026 14:50:57 +0100 Subject: [PATCH 037/211] tests: add Appwrite->Appwrite row migration onDuplicate test --- .../Services/Migrations/MigrationsBase.php | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 3adff48036..9b44bc4fd3 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -761,6 +761,96 @@ trait MigrationsBase self::$cachedTableData = []; } + /** + * Appwrite → Appwrite row migration honoring onDuplicate=skip and onDuplicate=upsert. + * Exercises the row-buffer dispatch path via cross-project migration rather than CSV/JSON upload. + */ + public function testAppwriteMigrationRowsOnDuplicate(): void + { + $sourceHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]; + + // Source setup: database + table + column + row + $data = $this->setupMigrationTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + + $row = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', $sourceHeaders, [ + 'rowId' => ID::unique(), + 'data' => ['name' => 'Original'], + ]); + $this->assertEquals(201, $row['headers']['status-code']); + $rowId = $row['body']['$id']; + + $resources = [ + Resource::TYPE_DATABASE, + Resource::TYPE_TABLE, + Resource::TYPE_COLUMN, + Resource::TYPE_ROW, + ]; + + // First migration: destination is empty, all resources copied + $first = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + ]); + $this->assertEquals('completed', $first['status']); + + // Mutate destination row so we can prove skip preserves it + $mutate = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders, [ + 'data' => ['name' => 'Mutated'], + ]); + $this->assertEquals(200, $mutate['headers']['status-code']); + $this->assertEquals('Mutated', $mutate['body']['name']); + + // Second migration with onDuplicate=skip: destination row must keep 'Mutated' + $second = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'skip', + ]); + $this->assertEquals('completed', $second['status']); + + $rowAfterSkip = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); + $this->assertEquals(200, $rowAfterSkip['headers']['status-code']); + $this->assertEquals('Mutated', $rowAfterSkip['body']['name'], 'onDuplicate=skip must not overwrite destination row'); + + // Third migration with onDuplicate=upsert: destination row must be restored to 'Original' + $third = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'upsert', + ]); + $this->assertEquals('completed', $third['status']); + + $rowAfterUpsert = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); + $this->assertEquals(200, $rowAfterUpsert['headers']['status-code']); + $this->assertEquals('Original', $rowAfterUpsert['body']['name'], 'onDuplicate=upsert must restore source value'); + + // Cleanup on destination + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); + + // Cleanup on source + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); + + self::$cachedDatabaseData = []; + self::$cachedTableData = []; + } + /** * Storage */ From d0603c4d289d356b2eac8f6dea37bac140be28bb Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 20 Apr 2026 16:38:59 +0100 Subject: [PATCH 038/211] tests: add Appwrite->Appwrite row onDuplicate test with tolerant poller --- .../Services/Migrations/MigrationsBase.php | 60 ++++++++++++++----- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 9b44bc4fd3..6ba7a0604e 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -762,8 +762,12 @@ trait MigrationsBase } /** - * Appwrite → Appwrite row migration honoring onDuplicate=skip and onDuplicate=upsert. - * Exercises the row-buffer dispatch path via cross-project migration rather than CSV/JSON upload. + * Appwrite → Appwrite row re-migration honoring onDuplicate=skip and onDuplicate=upsert. + * + * onDuplicate only gates the row-write path in DestinationAppwrite. Re-running the + * migration with the full resource tree (database/table/column/row) always errors + * on schema creation because destination already has those. This test accepts those + * schema-level errors as expected noise and asserts row-level correctness directly. */ public function testAppwriteMigrationRowsOnDuplicate(): void { @@ -778,7 +782,6 @@ trait MigrationsBase 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], ]; - // Source setup: database + table + column + row $data = $this->setupMigrationTable(); $databaseId = $data['databaseId']; $tableId = $data['tableId']; @@ -797,7 +800,7 @@ trait MigrationsBase Resource::TYPE_ROW, ]; - // First migration: destination is empty, all resources copied + // First migration: destination is empty, strict completion expected. $first = $this->performMigrationSync([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, @@ -806,51 +809,80 @@ trait MigrationsBase ]); $this->assertEquals('completed', $first['status']); - // Mutate destination row so we can prove skip preserves it + // Mutate destination row to prove onDuplicate=skip preserves it. $mutate = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders, [ 'data' => ['name' => 'Mutated'], ]); $this->assertEquals(200, $mutate['headers']['status-code']); $this->assertEquals('Mutated', $mutate['body']['name']); - // Second migration with onDuplicate=skip: destination row must keep 'Mutated' - $second = $this->performMigrationSync([ + // Re-migration with onDuplicate=skip. Overall status is expected to be 'failed' + // because schema re-create errors (database/table/column already exist) — those + // are orthogonal to onDuplicate which only affects row writes. Assert row-level + // success counter instead. + $this->runMigrationAssertingRowSuccess([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], 'onDuplicate' => 'skip', ]); - $this->assertEquals('completed', $second['status']); $rowAfterSkip = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); $this->assertEquals(200, $rowAfterSkip['headers']['status-code']); $this->assertEquals('Mutated', $rowAfterSkip['body']['name'], 'onDuplicate=skip must not overwrite destination row'); - // Third migration with onDuplicate=upsert: destination row must be restored to 'Original' - $third = $this->performMigrationSync([ + // Re-migration with onDuplicate=upsert. Same status-tolerant approach; assert + // destination row was restored to source value. + $this->runMigrationAssertingRowSuccess([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], 'onDuplicate' => 'upsert', ]); - $this->assertEquals('completed', $third['status']); $rowAfterUpsert = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); $this->assertEquals(200, $rowAfterUpsert['headers']['status-code']); $this->assertEquals('Original', $rowAfterUpsert['body']['name'], 'onDuplicate=upsert must restore source value'); - // Cleanup on destination $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); - - // Cleanup on source $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); self::$cachedDatabaseData = []; self::$cachedTableData = []; } + /** + * Helper for Appwrite→Appwrite re-migrations where onDuplicate applies only to rows. + * Accepts migration stages of 'finished' regardless of overall status, then asserts + * the row-level counter has zero errors (and at least one success). + * + * @param array $body + */ + private function runMigrationAssertingRowSuccess(array $body): void + { + $migration = $this->client->call(Client::METHOD_POST, '/migrations/appwrite', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ], $body); + $this->assertEquals(202, $migration['headers']['status-code']); + + $this->assertEventually(function () use ($migration) { + $response = $this->client->call(Client::METHOD_GET, '/migrations/' . $migration['body']['$id'], [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('finished', $response['body']['stage']); + $this->assertArrayHasKey(Resource::TYPE_ROW, $response['body']['statusCounters']); + $this->assertEquals(0, $response['body']['statusCounters'][Resource::TYPE_ROW]['error']); + $this->assertGreaterThanOrEqual(1, $response['body']['statusCounters'][Resource::TYPE_ROW]['success']); + }, 60_000, 500); + } + /** * Storage */ From 19f02a5129507e279d801f2c960ec91f5a554963 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 20 Apr 2026 16:44:36 +0100 Subject: [PATCH 039/211] composer: sync lock content-hash after merge from 1.9.x --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index 19d7af6719..b56e9b1444 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": "86a1fe0eb48da6028c13db50640cc4f6", + "content-hash": "756f545d9723dbad7f23fd10fddc64bc", "packages": [ { "name": "adhocore/jwt", From 715bd40b4a0c649ab83a0560dce90dcd5d772772 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Wed, 22 Apr 2026 16:38:32 +0100 Subject: [PATCH 040/211] =?UTF-8?q?Tighten=20A=E2=86=92A=20re-migration=20?= =?UTF-8?q?tests=20against=20utopia-php/migration=20schema=20tolerance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit utopia-php/migration's DestinationAppwrite now handles schema tolerance on re-migration (PR #171 on feat/skip-duplicates): it pre-checks destination `_metadata` for each database / table / column / index and tolerates in Skip/Upsert mode. Re-runs no longer produce schema-level errors, so the E2E tests can drop the status-tolerant workaround and assert strict 'completed' outcomes. Changes: - composer.json: pin utopia-php/migration to dev-feat/skip-duplicates (aliased to 1.9.99 for stability resolution). Will be replaced with a fixed 1.10.0 tag once the migration PR lands. - testAppwriteMigrationRowsOnDuplicate: replace the tolerant runMigrationAssertingRowSuccess helper with performMigrationSync on the Skip and Upsert re-runs. Asserts 'completed' status on every run, destination row content matches the expected value per mode (Mutated preserved on Skip, Original restored on Upsert). Helper method removed. - testAppwriteMigrationReRunIsIdempotent (new): seeds two rows on source, runs the migration three times back-to-back (fresh, Skip re-run, Upsert re-run) against unchanged source data, asserts strict 'completed' on every run and row content is stable across all three. Exercises the schema-tolerance path end-to-end: every database/table/column on destination already exists with a matching spec, so DestinationAppwrite's pre-check returns Tolerate for every resource. --- composer.json | 2 +- composer.lock | 27 ++-- .../Services/Migrations/MigrationsBase.php | 120 +++++++++++++----- 3 files changed, 107 insertions(+), 42 deletions(-) diff --git a/composer.json b/composer.json index bcbd59a636..8daede4537 100644 --- a/composer.json +++ b/composer.json @@ -73,7 +73,7 @@ "utopia-php/locale": "0.8.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.22.*", - "utopia-php/migration": "1.9.*", + "utopia-php/migration": "dev-feat/skip-duplicates as 1.9.99", "utopia-php/platform": "0.13.*", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", diff --git a/composer.lock b/composer.lock index b56e9b1444..9148102adf 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": "756f545d9723dbad7f23fd10fddc64bc", + "content-hash": "b6c60200cc06ec4d8ef8e342f09c7c30", "packages": [ { "name": "adhocore/jwt", @@ -4528,16 +4528,16 @@ }, { "name": "utopia-php/migration", - "version": "1.9.2", + "version": "dev-feat/skip-duplicates", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "97266905f35260137ba0b0e0c4f849f1ee422e43" + "reference": "001682168f7d87932c56635a0d0a45b927febc33" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/97266905f35260137ba0b0e0c4f849f1ee422e43", - "reference": "97266905f35260137ba0b0e0c4f849f1ee422e43", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/001682168f7d87932c56635a0d0a45b927febc33", + "reference": "001682168f7d87932c56635a0d0a45b927febc33", "shasum": "" }, "require": { @@ -4577,9 +4577,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.9.2" + "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-20T11:55:43+00:00" + "time": "2026-04-22T13:15:22+00:00" }, { "name": "utopia-php/mongo", @@ -8441,9 +8441,18 @@ "time": "2024-11-07T12:36:22+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/migration", + "version": "dev-feat/skip-duplicates", + "alias": "1.9.99", + "alias_normalized": "1.9.99.0" + } + ], "minimum-stability": "dev", - "stability-flags": {}, + "stability-flags": { + "utopia-php/migration": 20 + }, "prefer-stable": true, "prefer-lowest": false, "platform": { diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 6ba7a0604e..a2199dd63d 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -764,10 +764,11 @@ trait MigrationsBase /** * Appwrite → Appwrite row re-migration honoring onDuplicate=skip and onDuplicate=upsert. * - * onDuplicate only gates the row-write path in DestinationAppwrite. Re-running the - * migration with the full resource tree (database/table/column/row) always errors - * on schema creation because destination already has those. This test accepts those - * schema-level errors as expected noise and asserts row-level correctness directly. + * With utopia-php/migration's DestinationAppwrite handling schema tolerance + * (pre-check the destination `_metadata` for each database / table / column + * / index, tolerate existing in Skip/Upsert), re-migration completes + * cleanly — no more schema-level errors to tolerate. The test asserts + * strict 'completed' status via performMigrationSync on every run. */ public function testAppwriteMigrationRowsOnDuplicate(): void { @@ -816,31 +817,31 @@ trait MigrationsBase $this->assertEquals(200, $mutate['headers']['status-code']); $this->assertEquals('Mutated', $mutate['body']['name']); - // Re-migration with onDuplicate=skip. Overall status is expected to be 'failed' - // because schema re-create errors (database/table/column already exist) — those - // are orthogonal to onDuplicate which only affects row writes. Assert row-level - // success counter instead. - $this->runMigrationAssertingRowSuccess([ + // Re-migration with onDuplicate=skip — completion is strict because + // DestinationAppwrite tolerates existing schema resources. + $skipResult = $this->performMigrationSync([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], 'onDuplicate' => 'skip', ]); + $this->assertEquals('completed', $skipResult['status']); $rowAfterSkip = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); $this->assertEquals(200, $rowAfterSkip['headers']['status-code']); $this->assertEquals('Mutated', $rowAfterSkip['body']['name'], 'onDuplicate=skip must not overwrite destination row'); - // Re-migration with onDuplicate=upsert. Same status-tolerant approach; assert - // destination row was restored to source value. - $this->runMigrationAssertingRowSuccess([ + // Re-migration with onDuplicate=upsert — strict completion; destination + // row restored to source value. + $upsertResult = $this->performMigrationSync([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], 'onDuplicate' => 'upsert', ]); + $this->assertEquals('completed', $upsertResult['status']); $rowAfterUpsert = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); $this->assertEquals(200, $rowAfterUpsert['headers']['status-code']); @@ -854,33 +855,88 @@ trait MigrationsBase } /** - * Helper for Appwrite→Appwrite re-migrations where onDuplicate applies only to rows. - * Accepts migration stages of 'finished' regardless of overall status, then asserts - * the row-level counter has zero errors (and at least one success). - * - * @param array $body + * Re-migrating unchanged source (Skip / Upsert) completes cleanly without + * touching destination rows. Proves the schema-tolerance path: every + * database / table / attribute on destination already exists with a + * matching spec, so DestinationAppwrite's pre-check returns Tolerate for + * every resource and no-ops row writes go through the DB-native conflict + * primitives (INSERT IGNORE / ON DUPLICATE KEY UPDATE). */ - private function runMigrationAssertingRowSuccess(array $body): void + public function testAppwriteMigrationReRunIsIdempotent(): void { - $migration = $this->client->call(Client::METHOD_POST, '/migrations/appwrite', [ + $sourceHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destHeaders = [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getDestinationProject()['$id'], 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], - ], $body); - $this->assertEquals(202, $migration['headers']['status-code']); + ]; - $this->assertEventually(function () use ($migration) { - $response = $this->client->call(Client::METHOD_GET, '/migrations/' . $migration['body']['$id'], [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getDestinationProject()['$id'], - 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + $data = $this->setupMigrationTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + + // Seed two rows on source so the row-level tolerance is exercised too. + foreach (['row-a', 'row-b'] as $rowId) { + $row = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', $sourceHeaders, [ + 'rowId' => $rowId, + 'data' => ['name' => 'Seeded ' . $rowId], ]); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('finished', $response['body']['stage']); - $this->assertArrayHasKey(Resource::TYPE_ROW, $response['body']['statusCounters']); - $this->assertEquals(0, $response['body']['statusCounters'][Resource::TYPE_ROW]['error']); - $this->assertGreaterThanOrEqual(1, $response['body']['statusCounters'][Resource::TYPE_ROW]['success']); - }, 60_000, 500); + $this->assertEquals(201, $row['headers']['status-code']); + } + + $resources = [ + Resource::TYPE_DATABASE, + Resource::TYPE_TABLE, + Resource::TYPE_COLUMN, + Resource::TYPE_ROW, + ]; + + // First migration: fresh destination. + $first = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + ]); + $this->assertEquals('completed', $first['status']); + + // Re-run under Skip: nothing on source has changed. Destination + // schema + rows are already correct — expect clean completion. + $reRunSkip = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'skip', + ]); + $this->assertEquals('completed', $reRunSkip['status']); + + // Re-run under Upsert: same unchanged source. Schema tolerance path + // fires for each resource; rows go through DB-native upsert. + $reRunUpsert = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'upsert', + ]); + $this->assertEquals('completed', $reRunUpsert['status']); + + foreach (['row-a', 'row-b'] as $rowId) { + $check = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); + $this->assertEquals(200, $check['headers']['status-code']); + $this->assertEquals('Seeded ' . $rowId, $check['body']['name']); + } + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); + + self::$cachedDatabaseData = []; + self::$cachedTableData = []; } /** From 2ad95e511382c6ba23762adfc4861c6cb93c1b3f Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Wed, 22 Apr 2026 16:46:33 +0100 Subject: [PATCH 041/211] ci: restrict to Migrations service for fast feedback loop (TEMP) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Branch is iterating on utopia-php/migration's re-migration tolerance. Other test matrices (unit, general, abuse, screenshots, benchmark, and every other e2e service) add ~30+ minutes to CI without exercising code this PR touches. Restrict the matrix to the Migrations service and skip the unrelated test jobs until the migration work is ready to merge. All jobs marked with 'TEMP:' comments + 'if: false' — revert to the full matrix before merging to main. Static analysis (lint, phpstan, composer audit, specs, locale, security) still runs on every PR push. --- .github/workflows/ci.yml | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b02d021f1a..ce44c19931 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -285,6 +285,8 @@ jobs: unit: name: Tests / Unit + # TEMP: Migrations-only CI run. Re-enable before merging to main. + if: false runs-on: ubuntu-latest needs: build permissions: @@ -332,6 +334,8 @@ jobs: e2e_general: name: Tests / E2E / General + # TEMP: Migrations-only CI run. Re-enable before merging to main. + if: false runs-on: ubuntu-latest needs: build permissions: @@ -400,32 +404,10 @@ jobs: matrix: database: ${{ fromJSON(needs.matrix.outputs.databases) }} mode: ${{ fromJSON(needs.matrix.outputs.modes) }} - service: [ - Account, - Avatars, - Console, - Databases, - TablesDB, - Functions, - FunctionsSchedule, - GraphQL, - Health, - Locale, - Projects, - Realtime, - Sites, - Proxy, - Storage, - Tokens, - Teams, - Users, - ProjectWebhooks, - Webhooks, - VCS, - Messaging, - Migrations, - Project - ] + # TEMP: branch is testing utopia-php/migration re-migration tolerance. + # Restricted to Migrations to get fast CI feedback on the feature work; + # revert to the full matrix before merging to main. + service: [Migrations] include: - service: Databases runner: blacksmith-4vcpu-ubuntu-2404 @@ -524,6 +506,8 @@ jobs: e2e_abuse: name: Tests / E2E / Abuse (${{ matrix.mode }}) + # TEMP: Migrations-only CI run. Re-enable before merging to main. + if: false runs-on: ubuntu-latest needs: [build, matrix] permissions: @@ -583,6 +567,8 @@ jobs: e2e_screenshots: name: Tests / E2E / Screenshots (${{ matrix.mode }}) + # TEMP: Migrations-only CI run. Re-enable before merging to main. + if: false runs-on: ubuntu-latest needs: [build, matrix] permissions: @@ -649,6 +635,8 @@ jobs: benchmark: name: Benchmark + # TEMP: Migrations-only CI run. Re-enable before merging to main. + if: false runs-on: ubuntu-latest needs: build permissions: From c1506643e9196d4395e3ab8c95e83128e3c39376 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 23 Apr 2026 00:12:09 +0100 Subject: [PATCH 042/211] composer: bump utopia-php/migration to cfba224 Picks up the PR #171 refactor + unit tests: - resolveSchemaAction decision point consolidation - deleteAttributeCompletely primitive (two-way cleanup in one place) - Hardened sourceIsNewer against MySQL zero-date sentinel - 14 unit tests locking the decision matrix --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 9148102adf..e590802949 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "001682168f7d87932c56635a0d0a45b927febc33" + "reference": "cfba224f73f00d236a748553d87381a4cf77d0f6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/001682168f7d87932c56635a0d0a45b927febc33", - "reference": "001682168f7d87932c56635a0d0a45b927febc33", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/cfba224f73f00d236a748553d87381a4cf77d0f6", + "reference": "cfba224f73f00d236a748553d87381a4cf77d0f6", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-22T13:15:22+00:00" + "time": "2026-04-22T23:09:03+00:00" }, { "name": "utopia-php/mongo", From 44b7b26adfdb86f2c23c71397b02b277e78daa12 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 23 Apr 2026 06:06:30 +0100 Subject: [PATCH 043/211] composer: bump utopia-php/migration to e08d531 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Picks up the UpdateInPlace branch — database/table metadata drift is now reconciled on Upsert-newer (renames, enable toggles, table permissions / documentSecurity) via updateDocument, without touching child rows. --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index e590802949..079cb8e145 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "cfba224f73f00d236a748553d87381a4cf77d0f6" + "reference": "e08d531d7cab9c6aeed4fa28cfe326449b0dd3b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/cfba224f73f00d236a748553d87381a4cf77d0f6", - "reference": "cfba224f73f00d236a748553d87381a4cf77d0f6", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/e08d531d7cab9c6aeed4fa28cfe326449b0dd3b0", + "reference": "e08d531d7cab9c6aeed4fa28cfe326449b0dd3b0", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-22T23:09:03+00:00" + "time": "2026-04-23T05:05:36+00:00" }, { "name": "utopia-php/mongo", From 0134832fb6f4d0cfe3dec7d6c701e57e2a81f195 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 23 Apr 2026 06:22:26 +0100 Subject: [PATCH 044/211] tests: cover Upsert UpdateInPlace for database/table + Skip preserves dest drift MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two new E2E tests exercising the schema-tolerance UpdateInPlace path added in utopia-php/migration's DestinationAppwrite. testAppwriteMigrationUpsertUpdatesContainerMetadata (positive): - Fresh migration copies source database + table + column + row to dest. - Mutates source database name (PUT /databases/:id) and table name/permissions/rowSecurity/enabled (PUT /tablesdb/:db/tables/:id). - One-second sleep before mutation ensures source's $updatedAt is strictly greater than dest's at second granularity (strtotime comparison). - Upsert re-migration asserts: - 'completed' status. - dest database name matches source's new name. - dest table name / enabled / rowSecurity match source's new values. - child row's 'name' attribute is untouched — UpdateInPlace only rewrites container metadata, not rows. testAppwriteMigrationSkipPreservesContainerDrift (negative): - Fresh migration, then mutate BOTH dest (simulating ops tightening permissions post-migration) and source (divergence). - Skip re-migration asserts dest kept its tightened values — Skip's strict "don't touch" contract protects dev→prod cutover workflows from accidentally wiping ops-side drift on schema re-sync. Both tests use performMigrationSync for strict 'completed' assertions. Runtime ~18s combined. Existing testAppwriteMigrationRowsOnDuplicate and testAppwriteMigrationReRunIsIdempotent regression-tested locally. --- .../Services/Migrations/MigrationsBase.php | 178 ++++++++++++++++++ 1 file changed, 178 insertions(+) diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index a2199dd63d..3a997a8354 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -939,6 +939,184 @@ trait MigrationsBase self::$cachedTableData = []; } + /** + * Upsert re-migration reconciles container metadata drift: when source's + * database or table was modified between runs (rename, enabled flag, + * permissions tightening), the Upsert pre-check returns UpdateInPlace + * and migration's updateDocument propagates source values to dest. + * Children (rows) are preserved. + */ + public function testAppwriteMigrationUpsertUpdatesContainerMetadata(): void + { + $sourceHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]; + + $data = $this->setupMigrationTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + $rowId = 'persist-me'; + + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', $sourceHeaders, [ + 'rowId' => $rowId, + 'data' => ['name' => 'SeedRow'], + ]); + + $resources = [ + Resource::TYPE_DATABASE, + Resource::TYPE_TABLE, + Resource::TYPE_COLUMN, + Resource::TYPE_ROW, + ]; + + // First migration — dest empty, strict completion. + $first = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + ]); + $this->assertEquals('completed', $first['status']); + + // `_updatedAt` is stored at second granularity (strtotime) — ensure + // the source edits below produce a strictly-newer timestamp than + // dest's first-migration timestamp. + sleep(1); + + // Mutate source: rename database + toggle table enabled. + $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId, $sourceHeaders, [ + 'name' => 'Renamed Source DB', + ]); + $this->client->call(Client::METHOD_PUT, '/tablesdb/' . $databaseId . '/tables/' . $tableId, $sourceHeaders, [ + 'name' => 'Renamed Source Table', + 'permissions' => [Permission::read(Role::any())], + 'rowSecurity' => true, + 'enabled' => false, + ]); + + // Upsert re-migration: UpdateInPlace path fires for database + table. + $upsertResult = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'upsert', + ]); + $this->assertEquals('completed', $upsertResult['status']); + + // Assert dest database metadata reflects source's new values. + $destDb = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId, $destHeaders); + $this->assertEquals(200, $destDb['headers']['status-code']); + $this->assertEquals('Renamed Source DB', $destDb['body']['name']); + + // Assert dest table metadata reflects source's new values. + $destTable = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId, $destHeaders); + $this->assertEquals(200, $destTable['headers']['status-code']); + $this->assertEquals('Renamed Source Table', $destTable['body']['name']); + $this->assertFalse($destTable['body']['enabled'], 'Upsert must propagate source enabled=false'); + $this->assertTrue($destTable['body']['documentSecurity'] ?? $destTable['body']['rowSecurity'], 'Upsert must propagate source rowSecurity=true'); + + // Child row untouched — UpdateInPlace only rewrites container metadata. + $row = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); + $this->assertEquals(200, $row['headers']['status-code']); + $this->assertEquals('SeedRow', $row['body']['name'], 'Upsert must not touch child rows when updating container metadata'); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); + + self::$cachedDatabaseData = []; + self::$cachedTableData = []; + } + + /** + * Skip mode is strict "don't touch" — destination container metadata + * drift (permissions tightened post-migration, rename on dest) is + * preserved on every re-run, even when source has diverged. Guards + * against a common production workflow: dev→prod migrate, ops tightens + * prod permissions, later schema-only re-sync must not wipe out the + * tightening. + */ + public function testAppwriteMigrationSkipPreservesContainerDrift(): void + { + $sourceHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]; + + $data = $this->setupMigrationTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + + $resources = [ + Resource::TYPE_DATABASE, + Resource::TYPE_TABLE, + Resource::TYPE_COLUMN, + ]; + + // First migration: dest gets whatever source had. + $first = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + ]); + $this->assertEquals('completed', $first['status']); + + sleep(1); + + // Mutate dest: ops tightens permissions and renames the table for + // its production-specific branding. + $this->client->call(Client::METHOD_PUT, '/tablesdb/' . $databaseId . '/tables/' . $tableId, $destHeaders, [ + 'name' => 'Dest-Managed Table', + 'permissions' => [Permission::read(Role::users())], + 'rowSecurity' => false, + 'enabled' => true, + ]); + + // Also mutate source so the second run has a real divergence. + $this->client->call(Client::METHOD_PUT, '/tablesdb/' . $databaseId . '/tables/' . $tableId, $sourceHeaders, [ + 'name' => 'Source Renamed', + 'permissions' => [Permission::read(Role::any())], + 'rowSecurity' => true, + 'enabled' => false, + ]); + + // Skip re-migration: must tolerate existing destination — no update. + $skipResult = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'skip', + ]); + $this->assertEquals('completed', $skipResult['status']); + + // Dest kept its tightened values. + $destTable = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId, $destHeaders); + $this->assertEquals(200, $destTable['headers']['status-code']); + $this->assertEquals('Dest-Managed Table', $destTable['body']['name'], 'Skip must not propagate source name over dest drift'); + $this->assertTrue($destTable['body']['enabled'], 'Skip must preserve dest enabled flag'); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); + + self::$cachedDatabaseData = []; + self::$cachedTableData = []; + } + /** * Storage */ From 18694e0a28192bfc076779a292499de407ae6885 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 23 Apr 2026 07:10:23 +0100 Subject: [PATCH 045/211] TEMP: run Migrations across all adapters/modes on this branch --- .github/workflows/ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce44c19931..cbc667c767 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -212,8 +212,11 @@ jobs: const allDatabases = ['MariaDB', 'PostgreSQL', 'MongoDB']; const allModes = ['dedicated', 'shared']; - const defaultDatabases = ['MongoDB']; - const defaultModes = ['dedicated']; + // TEMP: branch is testing utopia-php/migration re-migration tolerance + // across every adapter/mode. Revert to ['MongoDB']/['dedicated'] + // before merging to main. + const defaultDatabases = allDatabases; + const defaultModes = allModes; const pr = context.payload.pull_request; if (!pr) { From 84b6dfa9d5050b072e33ffbe2700f28d8ff4000f Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 23 Apr 2026 16:39:30 +0100 Subject: [PATCH 046/211] composer: bump utopia-php/migration to bb21912 (SKIPPED status on tolerate) --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 079cb8e145..4a005bb20f 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "e08d531d7cab9c6aeed4fa28cfe326449b0dd3b0" + "reference": "bb21912e8cb501e5144b6bc6e1d0c9a6918a88d1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/e08d531d7cab9c6aeed4fa28cfe326449b0dd3b0", - "reference": "e08d531d7cab9c6aeed4fa28cfe326449b0dd3b0", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/bb21912e8cb501e5144b6bc6e1d0c9a6918a88d1", + "reference": "bb21912e8cb501e5144b6bc6e1d0c9a6918a88d1", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-23T05:05:36+00:00" + "time": "2026-04-23T15:35:27+00:00" }, { "name": "utopia-php/mongo", From e728265d21525110fa4104a3e6ba9d40472ac077 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Fri, 24 Apr 2026 05:57:32 +0100 Subject: [PATCH 047/211] composer: bump utopia-php/migration to 36fdf26 (Upsert orphan cleanup + nullable timestamps) --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 4a005bb20f..8beec7f2fe 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "bb21912e8cb501e5144b6bc6e1d0c9a6918a88d1" + "reference": "36fdf269fe1c6fac2a1d80f5b913493c18989727" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/bb21912e8cb501e5144b6bc6e1d0c9a6918a88d1", - "reference": "bb21912e8cb501e5144b6bc6e1d0c9a6918a88d1", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/36fdf269fe1c6fac2a1d80f5b913493c18989727", + "reference": "36fdf269fe1c6fac2a1d80f5b913493c18989727", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-23T15:35:27+00:00" + "time": "2026-04-24T04:55:29+00:00" }, { "name": "utopia-php/mongo", From 8292f7493d85f4e3b45693e4eaea26eca33b5f6a Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Fri, 24 Apr 2026 07:25:37 +0100 Subject: [PATCH 048/211] composer: bump utopia-php/migration to c2b8715 (rename orphan tracker to 'table' vocabulary) --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 8beec7f2fe..31c3610ad0 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "36fdf269fe1c6fac2a1d80f5b913493c18989727" + "reference": "c2b871519bbdaf7b3a2d947baa4e88a4b407c85d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/36fdf269fe1c6fac2a1d80f5b913493c18989727", - "reference": "36fdf269fe1c6fac2a1d80f5b913493c18989727", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/c2b871519bbdaf7b3a2d947baa4e88a4b407c85d", + "reference": "c2b871519bbdaf7b3a2d947baa4e88a4b407c85d", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-24T04:55:29+00:00" + "time": "2026-04-24T06:24:44+00:00" }, { "name": "utopia-php/mongo", From 478a2a6e86eb12cae084dbac30b1397d8afadb79 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Fri, 24 Apr 2026 07:30:29 +0100 Subject: [PATCH 049/211] tests: Upsert drops orphan columns / Skip preserves them testAppwriteMigrationUpsertDropsOrphanColumn: adds a column directly on destination (simulating post-rename orphan or dest-only drift), runs Upsert, asserts the orphan is dropped and source-declared column survives. Covers the per-table orphan cleanup fired inside createRecord before rows land. testAppwriteMigrationSkipKeepsOrphanColumn: same setup, Skip mode. Asserts the orphan survives, proving the cleanup is correctly gated to Upsert only. --- .../Services/Migrations/MigrationsBase.php | 174 ++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 7a8f918b96..229c01057e 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1117,6 +1117,180 @@ trait MigrationsBase self::$cachedTableData = []; } + /** + * Upsert re-migration reconciles column-level drift: a column that + * exists only on destination (e.g. from a subsequent dest-side edit, or + * left over after a source-side rename) must be dropped so destination's + * schema matches what source declares. Source-declared columns are + * preserved. Rows land after the orphan drop so row upsert doesn't + * fail on orphan required columns. + */ + public function testAppwriteMigrationUpsertDropsOrphanColumn(): void + { + $sourceHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]; + + $data = $this->setupMigrationTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + + $resources = [ + Resource::TYPE_DATABASE, + Resource::TYPE_TABLE, + Resource::TYPE_COLUMN, + Resource::TYPE_ROW, + ]; + + // First migration: dest mirrors source (one column 'name'). + $first = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + ]); + $this->assertEquals('completed', $first['status']); + + // Add an orphan column directly on destination (not on source). + // Simulates the post-rename state: source dropped a column, dest + // still has it — or a dest-only column added by a separate app. + $orphanResp = $this->client->call( + Client::METHOD_POST, + '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string', + $destHeaders, + [ + 'key' => 'orphan_col', + 'size' => 50, + 'required' => false, + ] + ); + $this->assertEquals(202, $orphanResp['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $tableId, $destHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/orphan_col', $destHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + }, 5000, 500); + + // Seed a row on source so per-table orphan cleanup fires inside + // createRecord (before rows land), not just at end of run. + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', $sourceHeaders, [ + 'rowId' => ID::unique(), + 'data' => ['name' => 'seed'], + ]); + + // Upsert re-migration: orphan_col must be dropped from dest. + $upsertResult = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'upsert', + ]); + $this->assertEquals('completed', $upsertResult['status']); + + // Orphan column dropped. + $orphanCheck = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/orphan_col', $destHeaders); + $this->assertEquals(404, $orphanCheck['headers']['status-code'], 'Upsert must drop destination column source no longer declares'); + + // Source's column preserved. + $nameCheck = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $destHeaders); + $this->assertEquals(200, $nameCheck['headers']['status-code'], 'Upsert must preserve columns source declared'); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); + + self::$cachedDatabaseData = []; + self::$cachedTableData = []; + } + + /** + * Skip mode never touches destination, including orphan columns. + * Pairs with testAppwriteMigrationUpsertDropsOrphanColumn to prove the + * cleanup is gated correctly: only Upsert reconciles, Skip tolerates. + */ + public function testAppwriteMigrationSkipKeepsOrphanColumn(): void + { + $sourceHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]; + + $data = $this->setupMigrationTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + + $resources = [ + Resource::TYPE_DATABASE, + Resource::TYPE_TABLE, + Resource::TYPE_COLUMN, + Resource::TYPE_ROW, + ]; + + $first = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + ]); + $this->assertEquals('completed', $first['status']); + + $orphanResp = $this->client->call( + Client::METHOD_POST, + '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string', + $destHeaders, + [ + 'key' => 'dest_only_col', + 'size' => 50, + 'required' => false, + ] + ); + $this->assertEquals(202, $orphanResp['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $tableId, $destHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/dest_only_col', $destHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + }, 5000, 500); + + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', $sourceHeaders, [ + 'rowId' => ID::unique(), + 'data' => ['name' => 'seed'], + ]); + + // Skip re-migration: orphan column must NOT be dropped. + $skipResult = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'skip', + ]); + $this->assertEquals('completed', $skipResult['status']); + + $orphanCheck = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/dest_only_col', $destHeaders); + $this->assertEquals(200, $orphanCheck['headers']['status-code'], 'Skip must preserve destination columns, including orphans'); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); + + self::$cachedDatabaseData = []; + self::$cachedTableData = []; + } + /** * Storage */ From dc9f48c9485f0dedc0478307d23a69964b839874 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Fri, 24 Apr 2026 15:09:42 +0100 Subject: [PATCH 050/211] composer: bump utopia-php/migration to 6e6f825 (relationships UpdateInPlace) --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 31c3610ad0..6ebcae42c5 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "c2b871519bbdaf7b3a2d947baa4e88a4b407c85d" + "reference": "6e6f8255fa52c8053fa2b9ad877c7797d93e32c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/c2b871519bbdaf7b3a2d947baa4e88a4b407c85d", - "reference": "c2b871519bbdaf7b3a2d947baa4e88a4b407c85d", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/6e6f8255fa52c8053fa2b9ad877c7797d93e32c5", + "reference": "6e6f8255fa52c8053fa2b9ad877c7797d93e32c5", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-24T06:24:44+00:00" + "time": "2026-04-24T10:33:58+00:00" }, { "name": "utopia-php/mongo", From 5f8a32798dd6cf0c0e756c0861eb48b1ac100a16 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 27 Apr 2026 12:32:37 +0100 Subject: [PATCH 051/211] tests: SDK-aligned UpdateInPlace coverage + bump migration to a36d95f MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three new e2e tests in MigrationsBase covering the schema reconciliation paths added in utopia-php/migration: - testAppwriteMigrationUpsertUpdatesAttributeInPlace: PATCH source required/default (SDK-reachable), assert dest reflects change and the pre-existing row's column data is preserved (drop+recreate would have wiped it). - testAppwriteMigrationSkipPreservesAttributeDrift: leaf-level analog of the existing container-drift Skip test — guards Skip from ever consulting timestamps. - testAppwriteMigrationUpsertUpdatesRelationshipOnDeleteInPlace: PATCH source onDelete cascade->restrict (SDK-reachable), assert dest reflects change and structural fields (relationType, twoWay) untouched. composer.lock: utopia-php/migration 6e6f825 -> a36d95f (mechanical helpers replacement, parseTimestamp dedup, match dispatch, comment trim). --- composer.lock | 8 +- .../Services/Migrations/MigrationsBase.php | 316 ++++++++++++++++++ 2 files changed, 320 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 6ebcae42c5..084d4a5bfe 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "6e6f8255fa52c8053fa2b9ad877c7797d93e32c5" + "reference": "a36d95f86d24b4f024a419191e69c3c034a593eb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/6e6f8255fa52c8053fa2b9ad877c7797d93e32c5", - "reference": "6e6f8255fa52c8053fa2b9ad877c7797d93e32c5", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/a36d95f86d24b4f024a419191e69c3c034a593eb", + "reference": "a36d95f86d24b4f024a419191e69c3c034a593eb", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-24T10:33:58+00:00" + "time": "2026-04-27T11:29:25+00:00" }, { "name": "utopia-php/mongo", diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 229c01057e..264f6a0ee1 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1291,6 +1291,322 @@ trait MigrationsBase self::$cachedTableData = []; } + /** + * Upsert reconciles attribute-level metadata edits using the Appwrite SDK's + * per-type updateXAttribute endpoint instead of drop+recreate. Source-side + * PATCH of fields the SDK can express (`required`, `default`, `size` for + * strings) — same `$createdAt` on both sides, source `$updatedAt` newer — + * routes through `updateAttributeInPlace` on DestinationAppwrite. Existing + * row data must survive (drop+recreate would have wiped the column). + */ + public function testAppwriteMigrationUpsertUpdatesAttributeInPlace(): void + { + $sourceHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]; + + $data = $this->setupMigrationTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + $rowId = 'persist-on-inplace'; + + // Seed a row that proves drop+recreate didn't happen — recreate would + // have wiped this column's data on the destination. + $row = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', $sourceHeaders, [ + 'rowId' => $rowId, + 'data' => ['name' => 'SeedRow'], + ]); + $this->assertEquals(201, $row['headers']['status-code']); + + $resources = [ + Resource::TYPE_DATABASE, + Resource::TYPE_TABLE, + Resource::TYPE_COLUMN, + Resource::TYPE_ROW, + ]; + + // First migration — dest gets the column as required:true. + $first = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + ]); + $this->assertEquals('completed', $first['status']); + + $beforeUpdate = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $destHeaders); + $this->assertEquals(200, $beforeUpdate['headers']['status-code']); + $this->assertTrue($beforeUpdate['body']['required']); + + // _updatedAt has second granularity; ensure source's PATCH produces a + // strictly-newer timestamp than the dest's first-migration value. + sleep(1); + + // SDK-reachable change set: required true→false, default null→'unknown'. + // Both fields are supported by PATCH /columns/string/:key — must route + // through updateAttributeInPlace, not DropAndRecreate. + $patch = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string/name', $sourceHeaders, [ + 'required' => false, + 'default' => 'unknown', + ]); + $this->assertEquals(200, $patch['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $tableId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $sourceHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + $this->assertFalse($r['body']['required']); + $this->assertEquals('unknown', $r['body']['default']); + }, 5000, 500); + + $upsertResult = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'upsert', + ]); + $this->assertEquals('completed', $upsertResult['status']); + + $this->assertEventually(function () use ($databaseId, $tableId, $destHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $destHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + $this->assertFalse($r['body']['required'], 'updateAttributeInPlace must propagate source required=false'); + $this->assertEquals('unknown', $r['body']['default'], 'updateAttributeInPlace must propagate source default'); + }, 10000, 500); + + // Pre-existing row preserved — proof that the path was UpdateInPlace + // and not DropAndRecreate (which would have nulled this column). + $rowAfter = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); + $this->assertEquals(200, $rowAfter['headers']['status-code']); + $this->assertEquals('SeedRow', $rowAfter['body']['name'], 'updateAttributeInPlace must not touch row data'); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); + + self::$cachedDatabaseData = []; + self::$cachedTableData = []; + } + + /** + * Skip mode is "don't touch" at the attribute level too: destination + * column drift (ops loosened a column post-migration) must survive a + * Skip re-run, even when source's `$updatedAt` is strictly newer. + * Pairs with testAppwriteMigrationSkipPreservesContainerDrift but + * exercises the leaf path (`canDrop = true`) instead of the container + * path. Regression guard against Skip ever consulting timestamps. + */ + public function testAppwriteMigrationSkipPreservesAttributeDrift(): void + { + $sourceHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]; + + $data = $this->setupMigrationTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + + $resources = [ + Resource::TYPE_DATABASE, + Resource::TYPE_TABLE, + Resource::TYPE_COLUMN, + ]; + + $first = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + ]); + $this->assertEquals('completed', $first['status']); + + sleep(1); + + // Dest divergence: ops loosens the column for a production-only need. + $destPatch = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string/name', $destHeaders, [ + 'required' => false, + 'default' => 'dest-default', + ]); + $this->assertEquals(200, $destPatch['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $tableId, $destHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $destHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + $this->assertFalse($r['body']['required']); + }, 5000, 500); + + sleep(1); + + // Source advances strictly later (and to a different value). Under + // Upsert this would propagate to dest; under Skip it must not. + $sourcePatch = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string/name', $sourceHeaders, [ + 'required' => true, + 'default' => null, + ]); + $this->assertEquals(200, $sourcePatch['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $tableId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $sourceHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + $this->assertTrue($r['body']['required']); + }, 5000, 500); + + $skipResult = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'skip', + ]); + $this->assertEquals('completed', $skipResult['status']); + + $destAttr = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $destHeaders); + $this->assertEquals(200, $destAttr['headers']['status-code']); + $this->assertFalse($destAttr['body']['required'], 'Skip must not propagate source required over dest drift'); + $this->assertEquals('dest-default', $destAttr['body']['default'], 'Skip must preserve dest default'); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); + + self::$cachedDatabaseData = []; + self::$cachedTableData = []; + } + + /** + * Upsert reconciles relationship `onDelete` drift through the SDK's + * `updateRelationshipAttribute` endpoint — the only relationship fields + * the SDK exposes for in-place edit are `onDelete` and `newKey`. Any + * structural change (`relationType`, `twoWay`, `twoWayKey`, + * `relatedCollection`) is a non-SDK field and must drop+recreate via + * `deleteRelationship`. This test exercises the in-place path: change + * `onDelete` cascade→restrict on source, re-migrate Upsert, assert dest + * reflects the new value without dropping the column. + */ + public function testAppwriteMigrationUpsertUpdatesRelationshipOnDeleteInPlace(): void + { + $sourceHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]; + + $databaseId = ID::unique(); + $createDb = $this->client->call(Client::METHOD_POST, '/databases', $sourceHeaders, [ + 'databaseId' => $databaseId, + 'name' => 'Rel In-Place DB', + ]); + $this->assertEquals(201, $createDb['headers']['status-code']); + + foreach (['parents', 'children'] as $tbl) { + $createTable = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', $sourceHeaders, [ + 'tableId' => $tbl, + 'name' => $tbl, + ]); + $this->assertEquals(201, $createTable['headers']['status-code']); + } + + // One-way relationship parents → children. One-way is sufficient to + // exercise updateRelationshipInPlace; two-way pair-key dedup is + // covered by the existing two-way coverage in MigrationDocumentsDB. + $createRel = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/parents/columns/relationship', $sourceHeaders, [ + 'relatedTableId' => 'children', + 'type' => Database::RELATION_ONE_TO_MANY, + 'twoWay' => false, + 'key' => 'kids', + 'onDelete' => Database::RELATION_MUTATE_CASCADE, + ]); + $this->assertEquals(202, $createRel['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $sourceHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + $this->assertEquals(Database::RELATION_MUTATE_CASCADE, $r['body']['onDelete']); + }, 10000, 500); + + $resources = [ + Resource::TYPE_DATABASE, + Resource::TYPE_TABLE, + Resource::TYPE_COLUMN, + ]; + + $first = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + ]); + $this->assertEquals('completed', $first['status']); + + $this->assertEventually(function () use ($databaseId, $destHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $destHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + $this->assertEquals(Database::RELATION_MUTATE_CASCADE, $r['body']['onDelete']); + }, 10000, 500); + + sleep(1); + + // SDK-reachable: PATCH /columns/:key/relationship accepts onDelete. + $patch = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids/relationship', $sourceHeaders, [ + 'onDelete' => Database::RELATION_MUTATE_RESTRICT, + ]); + $this->assertEquals(200, $patch['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $sourceHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + $this->assertEquals(Database::RELATION_MUTATE_RESTRICT, $r['body']['onDelete']); + }, 5000, 500); + + $upsertResult = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'upsert', + ]); + $this->assertEquals('completed', $upsertResult['status']); + + $this->assertEventually(function () use ($databaseId, $destHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $destHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + $this->assertEquals(Database::RELATION_MUTATE_RESTRICT, $r['body']['onDelete'], 'updateRelationshipInPlace must propagate source onDelete'); + $this->assertEquals(Database::RELATION_ONE_TO_MANY, $r['body']['relationType'], 'In-place update must not change relationType'); + $this->assertFalse($r['body']['twoWay'], 'In-place update must not change twoWay'); + }, 10000, 500); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); + + self::$cachedDatabaseData = []; + self::$cachedTableData = []; + } + /** * Storage */ From dfde1be03544301365f18450495c362ed4976928 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 27 Apr 2026 14:03:02 +0100 Subject: [PATCH 052/211] tests: cover two-way relationship onDelete in-place update + bump migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous version of this test created a one-way relationship, which falls through to DropAndRecreate (one-way + onDelete change is gated off in updateRelationshipInPlace because utopia's updateRelationship partner-cascade throws on one-way). It never exercised the in-place path it was named for. Converted to two-way (parents.kids ↔ children.parent), and asserted both parent- and partner-side onDelete on dest. Partner-side assertion is the regression guard for the partner-meta refresh that was missing from updateRelationshipInPlace. composer.lock: utopia-php/migration a36d95f -> c76de9a (partner-side onDelete sync fix). --- composer.lock | 8 +-- .../Services/Migrations/MigrationsBase.php | 58 ++++++++++++------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/composer.lock b/composer.lock index 084d4a5bfe..9f951576fb 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "a36d95f86d24b4f024a419191e69c3c034a593eb" + "reference": "c76de9acffa7fddac7cb1e969ebde63c053abcd3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/a36d95f86d24b4f024a419191e69c3c034a593eb", - "reference": "a36d95f86d24b4f024a419191e69c3c034a593eb", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/c76de9acffa7fddac7cb1e969ebde63c053abcd3", + "reference": "c76de9acffa7fddac7cb1e969ebde63c053abcd3", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-27T11:29:25+00:00" + "time": "2026-04-27T12:57:33+00:00" }, { "name": "utopia-php/mongo", diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 264f6a0ee1..c52cd8fb99 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1490,14 +1490,15 @@ trait MigrationsBase } /** - * Upsert reconciles relationship `onDelete` drift through the SDK's - * `updateRelationshipAttribute` endpoint — the only relationship fields - * the SDK exposes for in-place edit are `onDelete` and `newKey`. Any - * structural change (`relationType`, `twoWay`, `twoWayKey`, - * `relatedCollection`) is a non-SDK field and must drop+recreate via - * `deleteRelationship`. This test exercises the in-place path: change - * `onDelete` cascade→restrict on source, re-migrate Upsert, assert dest - * reflects the new value without dropping the column. + * Upsert reconciles two-way relationship `onDelete` drift via the SDK's + * updateRelationshipAttribute (only `onDelete`/`newKey` are SDK-reachable). + * Two-way is required to exercise updateRelationshipInPlace — one-way + + * onDelete change falls through to DropAndRecreate (utopia's + * updateRelationship partner-cascade throws on one-way). + * + * Asserts both sides of the relationship reflect the new onDelete on dest: + * utopia's updateRelationship syncs the physical constraint on both sides, + * but the Appwrite-level partner meta doc has to be refreshed explicitly. */ public function testAppwriteMigrationUpsertUpdatesRelationshipOnDeleteInPlace(): void { @@ -1527,14 +1528,13 @@ trait MigrationsBase $this->assertEquals(201, $createTable['headers']['status-code']); } - // One-way relationship parents → children. One-way is sufficient to - // exercise updateRelationshipInPlace; two-way pair-key dedup is - // covered by the existing two-way coverage in MigrationDocumentsDB. + // Two-way: parents.kids ↔ children.parent. Required to hit the in-place path. $createRel = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/parents/columns/relationship', $sourceHeaders, [ 'relatedTableId' => 'children', 'type' => Database::RELATION_ONE_TO_MANY, - 'twoWay' => false, + 'twoWay' => true, 'key' => 'kids', + 'twoWayKey' => 'parent', 'onDelete' => Database::RELATION_MUTATE_CASCADE, ]); $this->assertEquals(202, $createRel['headers']['status-code']); @@ -1560,11 +1560,17 @@ trait MigrationsBase ]); $this->assertEquals('completed', $first['status']); + // Both sides land on dest with onDelete=cascade. $this->assertEventually(function () use ($databaseId, $destHeaders) { - $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $destHeaders); - $this->assertEquals(200, $r['headers']['status-code']); - $this->assertEquals('available', $r['body']['status']); - $this->assertEquals(Database::RELATION_MUTATE_CASCADE, $r['body']['onDelete']); + $parent = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $destHeaders); + $this->assertEquals(200, $parent['headers']['status-code']); + $this->assertEquals('available', $parent['body']['status']); + $this->assertEquals(Database::RELATION_MUTATE_CASCADE, $parent['body']['onDelete']); + + $child = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/children/columns/parent', $destHeaders); + $this->assertEquals(200, $child['headers']['status-code']); + $this->assertEquals('available', $child['body']['status']); + $this->assertEquals(Database::RELATION_MUTATE_CASCADE, $child['body']['onDelete']); }, 10000, 500); sleep(1); @@ -1591,13 +1597,21 @@ trait MigrationsBase ]); $this->assertEquals('completed', $upsertResult['status']); + // Both sides on dest must reflect onDelete=restrict. Asserting the + // partner side is the regression guard for the previously-missed + // partner meta refresh in updateRelationshipInPlace. $this->assertEventually(function () use ($databaseId, $destHeaders) { - $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $destHeaders); - $this->assertEquals(200, $r['headers']['status-code']); - $this->assertEquals('available', $r['body']['status']); - $this->assertEquals(Database::RELATION_MUTATE_RESTRICT, $r['body']['onDelete'], 'updateRelationshipInPlace must propagate source onDelete'); - $this->assertEquals(Database::RELATION_ONE_TO_MANY, $r['body']['relationType'], 'In-place update must not change relationType'); - $this->assertFalse($r['body']['twoWay'], 'In-place update must not change twoWay'); + $parent = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $destHeaders); + $this->assertEquals(200, $parent['headers']['status-code']); + $this->assertEquals('available', $parent['body']['status']); + $this->assertEquals(Database::RELATION_MUTATE_RESTRICT, $parent['body']['onDelete'], 'parent-side onDelete must reflect source'); + $this->assertEquals(Database::RELATION_ONE_TO_MANY, $parent['body']['relationType'], 'In-place update must not change relationType'); + $this->assertTrue($parent['body']['twoWay'], 'In-place update must not change twoWay'); + + $child = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/children/columns/parent', $destHeaders); + $this->assertEquals(200, $child['headers']['status-code']); + $this->assertEquals('available', $child['body']['status']); + $this->assertEquals(Database::RELATION_MUTATE_RESTRICT, $child['body']['onDelete'], 'partner-side onDelete must reflect source after in-place update'); }, 10000, 500); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); From 49d2db65e6f7279520c2d896ccbda9e42ad1f935 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 27 Apr 2026 17:15:00 +0400 Subject: [PATCH 053/211] feat: support out-of-order chunked uploads - Add APP_LIMIT_UPLOAD_CHUNK_SIZE constant (5MB) matching official SDKs - Replace dynamic chunk calculation with fixed 5MB chunk math in all upload endpoints - Remove -1 last-chunk sentinel that broke when last chunk arrived first - Fix duplicate-retry guards: return existing resource instead of erroring for chunked uploads - Add out-of-order e2e tests for Storage, Functions, and Sites - Upgrade utopia-php/storage to 2.0.0 for device-level out-of-order assembly support --- app/init/constants.php | 1 + composer.json | 2 +- composer.lock | 181 +++++++++--------- .../Functions/Http/Deployments/Create.php | 26 +-- .../Modules/Sites/Http/Deployments/Create.php | 26 +-- .../Storage/Http/Buckets/Files/Create.php | 30 +-- .../Functions/FunctionsCustomServerTest.php | 112 +++++++++++ .../Services/Sites/SitesCustomServerTest.php | 130 +++++++++++++ tests/e2e/Services/Storage/StorageBase.php | 147 ++++++++++++++ 9 files changed, 510 insertions(+), 145 deletions(-) diff --git a/app/init/constants.php b/app/init/constants.php index 8eacf2fe12..0f12036b69 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -244,6 +244,7 @@ const APP_AUTH_TYPE_KEY = 'Key'; const APP_AUTH_TYPE_ADMIN = 'Admin'; // Response related const MAX_OUTPUT_CHUNK_SIZE = 10 * 1024 * 1024; // 10MB +const APP_LIMIT_UPLOAD_CHUNK_SIZE = 5 * 1024 * 1024; // 5MB const APP_FUNCTION_LOG_LENGTH_LIMIT = 1000000; const APP_FUNCTION_ERROR_LENGTH_LIMIT = 1000000; // Function headers diff --git a/composer.json b/composer.json index 6312243e32..7a61f2c1e6 100644 --- a/composer.json +++ b/composer.json @@ -81,7 +81,7 @@ "utopia-php/queue": "0.17.*", "utopia-php/servers": "0.3.*", "utopia-php/registry": "0.5.*", - "utopia-php/storage": "1.0.*", + "utopia-php/storage": "2.*", "utopia-php/system": "0.10.*", "utopia-php/telemetry": "0.2.*", "utopia-php/vcs": "3.*", diff --git a/composer.lock b/composer.lock index 02590020e0..ca4a58b2cb 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": "c5ae97637fd0ec0a950044d1c33677ea", + "content-hash": "ba332fbec7c2e7d462ee5bb3fad9775c", "packages": [ { "name": "adhocore/jwt", @@ -1996,16 +1996,16 @@ }, { "name": "phpseclib/phpseclib", - "version": "3.0.51", + "version": "3.0.52", "source": { "type": "git", "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "d59c94077f9c9915abb51ddb52ce85188ece1748" + "reference": "2adaefc83df2ec548558307690f376dd7d4f4fce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/d59c94077f9c9915abb51ddb52ce85188ece1748", - "reference": "d59c94077f9c9915abb51ddb52ce85188ece1748", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/2adaefc83df2ec548558307690f376dd7d4f4fce", + "reference": "2adaefc83df2ec548558307690f376dd7d4f4fce", "shasum": "" }, "require": { @@ -2086,7 +2086,7 @@ ], "support": { "issues": "https://github.com/phpseclib/phpseclib/issues", - "source": "https://github.com/phpseclib/phpseclib/tree/3.0.51" + "source": "https://github.com/phpseclib/phpseclib/tree/3.0.52" }, "funding": [ { @@ -2102,7 +2102,7 @@ "type": "tidelift" } ], - "time": "2026-04-10T01:33:53+00:00" + "time": "2026-04-27T07:02:15+00:00" }, { "name": "psr/clock", @@ -2887,7 +2887,7 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.36.0", + "version": "v1.37.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", @@ -2948,7 +2948,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.36.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.37.0" }, "funding": [ { @@ -2972,7 +2972,7 @@ }, { "name": "symfony/polyfill-php82", - "version": "v1.36.0", + "version": "v1.37.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php82.git", @@ -3028,7 +3028,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php82/tree/v1.36.0" + "source": "https://github.com/symfony/polyfill-php82/tree/v1.37.0" }, "funding": [ { @@ -3052,7 +3052,7 @@ }, { "name": "symfony/polyfill-php83", - "version": "v1.36.0", + "version": "v1.37.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php83.git", @@ -3108,7 +3108,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php83/tree/v1.36.0" + "source": "https://github.com/symfony/polyfill-php83/tree/v1.37.0" }, "funding": [ { @@ -3132,16 +3132,16 @@ }, { "name": "symfony/polyfill-php85", - "version": "v1.36.0", + "version": "v1.37.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php85.git", - "reference": "2c408a6bb0313e6001a83628dc5506100474254e" + "reference": "fcfa4973a9917cef23f2e38774da74a2b7d115ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php85/zipball/2c408a6bb0313e6001a83628dc5506100474254e", - "reference": "2c408a6bb0313e6001a83628dc5506100474254e", + "url": "https://api.github.com/repos/symfony/polyfill-php85/zipball/fcfa4973a9917cef23f2e38774da74a2b7d115ee", + "reference": "fcfa4973a9917cef23f2e38774da74a2b7d115ee", "shasum": "" }, "require": { @@ -3188,7 +3188,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php85/tree/v1.36.0" + "source": "https://github.com/symfony/polyfill-php85/tree/v1.37.0" }, "funding": [ { @@ -3208,7 +3208,7 @@ "type": "tidelift" } ], - "time": "2026-04-10T16:50:15+00:00" + "time": "2026-04-26T13:10:57+00:00" }, { "name": "symfony/service-contracts", @@ -3658,16 +3658,16 @@ }, { "name": "utopia-php/cli", - "version": "0.23.1", + "version": "0.23.2", "source": { "type": "git", "url": "https://github.com/utopia-php/cli.git", - "reference": "8d1955b8bc4dc631f45d7c7df689ed7b63f70621" + "reference": "145b91fef827853bcceaa3ab8ca2b1d6faaca2ab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cli/zipball/8d1955b8bc4dc631f45d7c7df689ed7b63f70621", - "reference": "8d1955b8bc4dc631f45d7c7df689ed7b63f70621", + "url": "https://api.github.com/repos/utopia-php/cli/zipball/145b91fef827853bcceaa3ab8ca2b1d6faaca2ab", + "reference": "145b91fef827853bcceaa3ab8ca2b1d6faaca2ab", "shasum": "" }, "require": { @@ -3703,9 +3703,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cli/issues", - "source": "https://github.com/utopia-php/cli/tree/0.23.1" + "source": "https://github.com/utopia-php/cli/tree/0.23.2" }, - "time": "2026-04-05T15:27:35+00:00" + "time": "2026-04-27T09:19:04+00:00" }, { "name": "utopia-php/compression", @@ -4271,21 +4271,20 @@ }, { "name": "utopia-php/http", - "version": "0.34.21", + "version": "0.34.24", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "49a6bd3ea0d2966aa19cf707255d442675288a24" + "reference": "d1eced0627c5a9fceddf53992ed97d664b810d33" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/49a6bd3ea0d2966aa19cf707255d442675288a24", - "reference": "49a6bd3ea0d2966aa19cf707255d442675288a24", + "url": "https://api.github.com/repos/utopia-php/http/zipball/d1eced0627c5a9fceddf53992ed97d664b810d33", + "reference": "d1eced0627c5a9fceddf53992ed97d664b810d33", "shasum": "" }, "require": { - "ext-swoole": "*", - "php": ">=8.2", + "php": ">=8.3", "utopia-php/compression": "0.1.*", "utopia-php/di": "0.3.*", "utopia-php/servers": "0.3.*", @@ -4295,11 +4294,14 @@ "require-dev": { "doctrine/instantiator": "^1.5", "laravel/pint": "1.*", - "phpbench/phpbench": "^1.2", - "phpstan/phpstan": "1.*", - "phpunit/phpunit": "^9.5.25", + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^12.0", + "rector/rector": "^2.4", "swoole/ide-helper": "4.8.3" }, + "suggest": { + "ext-swoole": "Required to use the Swoole server adapter (\\Utopia\\Http\\Adapter\\Swoole\\Server)." + }, "type": "library", "autoload": { "psr-4": { @@ -4319,9 +4321,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.34.21" + "source": "https://github.com/utopia-php/http/tree/0.34.24" }, - "time": "2026-04-19T19:44:04+00:00" + "time": "2026-04-24T12:16:53+00:00" }, { "name": "utopia-php/image", @@ -4528,16 +4530,16 @@ }, { "name": "utopia-php/migration", - "version": "1.9.1", + "version": "1.9.4", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "7a86aeadf182b63a9f4ceba7e137588b31c5d2e2" + "reference": "969dc9477ea962f16da9254facdbd8944cf13477" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/7a86aeadf182b63a9f4ceba7e137588b31c5d2e2", - "reference": "7a86aeadf182b63a9f4ceba7e137588b31c5d2e2", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/969dc9477ea962f16da9254facdbd8944cf13477", + "reference": "969dc9477ea962f16da9254facdbd8944cf13477", "shasum": "" }, "require": { @@ -4548,7 +4550,7 @@ "php": ">=8.1", "utopia-php/database": "5.*", "utopia-php/dsn": "0.2.*", - "utopia-php/storage": "1.0.*" + "utopia-php/storage": "2.*" }, "require-dev": { "ext-pdo": "*", @@ -4577,22 +4579,22 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.9.1" + "source": "https://github.com/utopia-php/migration/tree/1.9.4" }, - "time": "2026-03-25T07:05:27+00:00" + "time": "2026-04-27T12:42:51+00:00" }, { "name": "utopia-php/mongo", - "version": "1.0.2", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/utopia-php/mongo.git", - "reference": "677a21c53f7a1316c528b4b45b3fce886cee7223" + "reference": "73593682deee4696525a04e26524c1c1226e1530" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/mongo/zipball/677a21c53f7a1316c528b4b45b3fce886cee7223", - "reference": "677a21c53f7a1316c528b4b45b3fce886cee7223", + "url": "https://api.github.com/repos/utopia-php/mongo/zipball/73593682deee4696525a04e26524c1c1226e1530", + "reference": "73593682deee4696525a04e26524c1c1226e1530", "shasum": "" }, "require": { @@ -4638,9 +4640,9 @@ ], "support": { "issues": "https://github.com/utopia-php/mongo/issues", - "source": "https://github.com/utopia-php/mongo/tree/1.0.2" + "source": "https://github.com/utopia-php/mongo/tree/1.1.0" }, - "time": "2026-03-18T02:45:50+00:00" + "time": "2026-04-24T06:15:10+00:00" }, { "name": "utopia-php/platform", @@ -5018,16 +5020,16 @@ }, { "name": "utopia-php/storage", - "version": "1.0.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "f014be445f0baa635d0764e1673196f412511618" + "reference": "52d1f89a47165ef0d3deff63043cda182175adfb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/f014be445f0baa635d0764e1673196f412511618", - "reference": "f014be445f0baa635d0764e1673196f412511618", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/52d1f89a47165ef0d3deff63043cda182175adfb", + "reference": "52d1f89a47165ef0d3deff63043cda182175adfb", "shasum": "" }, "require": { @@ -5041,9 +5043,8 @@ "utopia-php/validators": "0.2.*" }, "require-dev": { - "laravel/pint": "1.2.*", - "phpunit/phpunit": "^9.3", - "vimeo/psalm": "4.0.1" + "laravel/pint": "^1.21", + "phpunit/phpunit": "^9.3" }, "type": "library", "autoload": { @@ -5065,9 +5066,9 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/1.0.1" + "source": "https://github.com/utopia-php/storage/tree/2.0.0" }, - "time": "2026-02-23T05:59:32+00:00" + "time": "2026-04-27T11:39:32+00:00" }, { "name": "utopia-php/system", @@ -5464,16 +5465,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.20", + "version": "1.24.0", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "525f0630520c95100fcdfb63c9dac859c1d02588" + "reference": "6d4d26659bc7a1c347c1d4d8dae3b77b5562e0cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/525f0630520c95100fcdfb63c9dac859c1d02588", - "reference": "525f0630520c95100fcdfb63c9dac859c1d02588", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/6d4d26659bc7a1c347c1d4d8dae3b77b5562e0cb", + "reference": "6d4d26659bc7a1c347c1d4d8dae3b77b5562e0cb", "shasum": "" }, "require": { @@ -5509,9 +5510,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.20" + "source": "https://github.com/appwrite/sdk-generator/tree/1.24.0" }, - "time": "2026-04-20T05:45:00+00:00" + "time": "2026-04-24T12:50:05+00:00" }, { "name": "brianium/paratest", @@ -5793,16 +5794,16 @@ }, { "name": "laravel/pint", - "version": "v1.29.0", + "version": "v1.29.1", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "bdec963f53172c5e36330f3a400604c69bf02d39" + "reference": "0770e9b7fafd50d4586881d456d6eb41c9247a80" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/bdec963f53172c5e36330f3a400604c69bf02d39", - "reference": "bdec963f53172c5e36330f3a400604c69bf02d39", + "url": "https://api.github.com/repos/laravel/pint/zipball/0770e9b7fafd50d4586881d456d6eb41c9247a80", + "reference": "0770e9b7fafd50d4586881d456d6eb41c9247a80", "shasum": "" }, "require": { @@ -5813,14 +5814,14 @@ "php": "^8.2.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.94.2", - "illuminate/view": "^12.54.1", - "larastan/larastan": "^3.9.3", - "laravel-zero/framework": "^12.0.5", + "friendsofphp/php-cs-fixer": "^3.95.1", + "illuminate/view": "^12.56.0", + "larastan/larastan": "^3.9.6", + "laravel-zero/framework": "^12.1.0", "mockery/mockery": "^1.6.12", "nunomaduro/termwind": "^2.4.0", "pestphp/pest": "^3.8.6", - "shipfastlabs/agent-detector": "^1.1.0" + "shipfastlabs/agent-detector": "^1.1.3" }, "bin": [ "builds/pint" @@ -5857,7 +5858,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2026-03-12T15:51:39+00:00" + "time": "2026-04-20T15:26:14+00:00" }, { "name": "matthiasmullie/minify", @@ -6220,11 +6221,11 @@ }, { "name": "phpstan/phpstan", - "version": "2.1.50", + "version": "2.1.51", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d452086fb4cf648c6b2d8cf3b639351f79e4f3e2", - "reference": "d452086fb4cf648c6b2d8cf3b639351f79e4f3e2", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dc3b523c45e714c70de2ac5113b958223b55dc59", + "reference": "dc3b523c45e714c70de2ac5113b958223b55dc59", "shasum": "" }, "require": { @@ -6269,7 +6270,7 @@ "type": "github" } ], - "time": "2026-04-17T13:10:32+00:00" + "time": "2026-04-21T18:22:01+00:00" }, { "name": "phpunit/php-code-coverage", @@ -7779,7 +7780,7 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.36.0", + "version": "v1.37.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", @@ -7838,7 +7839,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.36.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.37.0" }, "funding": [ { @@ -7862,16 +7863,16 @@ }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.36.0", + "version": "v1.37.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "ad1b7b9092976d6c948b8a187cec9faaea9ec1df" + "reference": "4864388bfbd3001ce88e234fab652acd91fdc57e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/ad1b7b9092976d6c948b8a187cec9faaea9ec1df", - "reference": "ad1b7b9092976d6c948b8a187cec9faaea9ec1df", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/4864388bfbd3001ce88e234fab652acd91fdc57e", + "reference": "4864388bfbd3001ce88e234fab652acd91fdc57e", "shasum": "" }, "require": { @@ -7920,7 +7921,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.36.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.37.0" }, "funding": [ { @@ -7940,11 +7941,11 @@ "type": "tidelift" } ], - "time": "2026-04-10T16:19:22+00:00" + "time": "2026-04-26T13:13:48+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.36.0", + "version": "v1.37.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", @@ -8005,7 +8006,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.36.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.37.0" }, "funding": [ { @@ -8029,7 +8030,7 @@ }, { "name": "symfony/polyfill-php81", - "version": "v1.36.0", + "version": "v1.37.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php81.git", @@ -8085,7 +8086,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php81/tree/v1.36.0" + "source": "https://github.com/symfony/polyfill-php81/tree/v1.37.0" }, "funding": [ { diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php index 11736c8ca5..decf1323c1 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php @@ -175,15 +175,8 @@ class Create extends Action throw new Exception(Exception::STORAGE_INVALID_CONTENT_RANGE); } - // TODO remove the condition that checks `$end === $fileSize` in next breaking version - if ($end === $fileSize - 1 || $end === $fileSize) { - //if it's a last chunks the chunk size might differ, so we set the $chunks and $chunk to notify it's last chunk - $chunks = $chunk = -1; - } else { - // Calculate total number of chunks based on the chunk size i.e ($rangeEnd - $rangeStart) - $chunks = (int) ceil($fileSize / ($end + 1 - $start)); - $chunk = (int) ($start / ($end + 1 - $start)) + 1; - } + $chunks = (int) ceil($fileSize / APP_LIMIT_UPLOAD_CHUNK_SIZE); + $chunk = (int) ($start / APP_LIMIT_UPLOAD_CHUNK_SIZE) + 1; } if (!$fileSizeValidator->isValid($fileSize) && $functionSizeLimit !== 0) { // Check if file size is exceeding allowed limit @@ -202,15 +195,14 @@ class Create extends Action $metadata = ['content_type' => $deviceForLocal->getFileMimeType($fileTmpName)]; if (!$deployment->isEmpty()) { $chunks = $deployment->getAttribute('sourceChunksTotal', 1); + $uploaded = $deployment->getAttribute('sourceChunksUploaded', 0); $metadata = $deployment->getAttribute('sourceMetadata', []); - if ($chunk === -1) { - $chunk = $chunks; - } - } else { - // Guard against manually setting range header for single chunk upload - if ($chunks === -1) { - $chunks = 1; - $chunk = 1; + + if ($uploaded === $chunks) { + $response + ->setStatusCode(Response::STATUS_CODE_ACCEPTED) + ->dynamic($deployment, Response::MODEL_DEPLOYMENT); + return; } } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php index 0b8ca24aaa..d6e3e68e90 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php @@ -177,15 +177,8 @@ class Create extends Action throw new Exception(Exception::STORAGE_INVALID_CONTENT_RANGE); } - // TODO remove the condition that checks `$end === $fileSize` in next breaking version - if ($end === $fileSize - 1 || $end === $fileSize) { - //if it's a last chunks the chunk size might differ, so we set the $chunks and $chunk to notify it's last chunk - $chunks = $chunk = -1; - } else { - // Calculate total number of chunks based on the chunk size i.e ($rangeEnd - $rangeStart) - $chunks = (int) ceil($fileSize / ($end + 1 - $start)); - $chunk = (int) ($start / ($end + 1 - $start)) + 1; - } + $chunks = (int) ceil($fileSize / APP_LIMIT_UPLOAD_CHUNK_SIZE); + $chunk = (int) ($start / APP_LIMIT_UPLOAD_CHUNK_SIZE) + 1; } if (!$fileSizeValidator->isValid($fileSize) && $siteSizeLimit !== 0) { // Check if file size is exceeding allowed limit @@ -204,15 +197,14 @@ class Create extends Action $metadata = ['content_type' => $deviceForLocal->getFileMimeType($fileTmpName)]; if (!$deployment->isEmpty()) { $chunks = $deployment->getAttribute('sourceChunksTotal', 1); + $uploaded = $deployment->getAttribute('sourceChunksUploaded', 0); $metadata = $deployment->getAttribute('sourceMetadata', []); - if ($chunk === -1) { - $chunk = $chunks; - } - } else { - // Guard against manually setting range header for single chunk upload - if ($chunks === -1) { - $chunks = 1; - $chunk = 1; + + if ($uploaded === $chunks) { + $response + ->setStatusCode(Response::STATUS_CODE_ACCEPTED) + ->dynamic($deployment, Response::MODEL_DEPLOYMENT); + return; } } diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php index befc02a1df..2ce5ef97f5 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php @@ -204,15 +204,8 @@ class Create extends Action throw new Exception(Exception::STORAGE_INVALID_APPWRITE_ID); } - // TODO remove the condition that checks `$end === $fileSize` in next breaking version - if ($end === $fileSize - 1 || $end === $fileSize) { - //if it's a last chunks the chunk size might differ, so we set the $chunks and $chunk to -1 notify it's last chunk - $chunks = $chunk = -1; - } else { - // Calculate total number of chunks based on the chunk size i.e ($rangeEnd - $rangeStart) - $chunks = (int) ceil($fileSize / ($end + 1 - $start)); - $chunk = (int) ($start / ($end + 1 - $start)) + 1; - } + $chunks = (int) ceil($fileSize / APP_LIMIT_UPLOAD_CHUNK_SIZE); + $chunk = (int) ($start / APP_LIMIT_UPLOAD_CHUNK_SIZE) + 1; } /** @@ -249,18 +242,15 @@ class Create extends Action $uploaded = $file->getAttribute('chunksUploaded', 0); $metadata = $file->getAttribute('metadata', []); - if ($chunk === -1) { - $chunk = $chunks; - } - if ($uploaded === $chunks) { - throw new Exception(Exception::STORAGE_FILE_ALREADY_EXISTS); - } - } else { - // Guard against manually setting range header for single chunk upload - if ($chunks === -1) { - $chunks = 1; - $chunk = 1; + if (empty($contentRange)) { + throw new Exception(Exception::STORAGE_FILE_ALREADY_EXISTS); + } + + $response + ->setStatusCode(Response::STATUS_CODE_OK) + ->dynamic($file, Response::MODEL_FILE); + return; } } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 4255774f18..87f73dd7d3 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1079,6 +1079,118 @@ class FunctionsCustomServerTest extends Scope }, 120000, 500); } + public function testCreateDeploymentOutOfOrder(): void + { + $data = $this->setupTestFunction(); + $functionId = $data['functionId']; + + // Prepare a code file that spans at least 3 chunks + $folder = 'large'; + $code = realpath(__DIR__ . '/../../../resources/functions') . "/$folder/code.tar.gz"; + Console::execute('cd ' . realpath(__DIR__ . "/../../../resources/functions") . "/$folder && tar --exclude code.tar.gz --exclude node_modules -czf code.tar.gz .", '', $this->stdout, $this->stderr); + + $totalSize = filesize($code); + $chunkSize = 5 * 1024 * 1024; // 5MB chunks + $mimeType = 'application/x-gzip'; + $chunksTotal = (int) ceil($totalSize / $chunkSize); + + // Read all chunks into memory + $handle = fopen($code, "rb"); + $this->assertNotFalse($handle, "Could not open test resource: $code"); + $chunks = []; + for ($i = 0; $i < $chunksTotal; $i++) { + $start = $i * $chunkSize; + $end = min($start + $chunkSize, $totalSize); + $length = $end - $start; + $data = fread($handle, $length); + $chunks[] = [ + 'data' => $data, + 'start' => $start, + 'end' => $end - 1, + 'index' => $i, + ]; + } + fclose($handle); + + // We need at least 3 chunks for a meaningful out-of-order test + $this->assertGreaterThanOrEqual(3, count($chunks), 'Test file must span at least 3 chunks'); + + // Upload chunks in out-of-order sequence: last chunk first, then first, then second + $uploadOrder = [count($chunks) - 1, 0, 1]; + $deploymentId = ''; + $deployment = null; + + foreach ($uploadOrder as $chunkIndex) { + $chunk = $chunks[$chunkIndex]; + $curlFile = new \CURLFile( + 'data://' . $mimeType . ';base64,' . base64_encode($chunk['data']), + $mimeType, + 'large-fx.tar.gz' + ); + + $headers = [ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + 'content-range' => 'bytes ' . $chunk['start'] . '-' . $chunk['end'] . '/' . $totalSize, + ]; + + if (!empty($deploymentId)) { + $headers['x-appwrite-id'] = $deploymentId; + } + + $deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge($headers, $this->getHeaders()), [ + 'entrypoint' => 'index.js', + 'code' => $curlFile, + 'activate' => true, + ]); + + $this->assertEquals(202, $deployment['headers']['status-code']); + $deploymentId = $deployment['body']['$id']; + } + + // Upload remaining chunks in any order to complete the file + $remainingChunks = []; + for ($i = 2; $i < count($chunks) - 1; $i++) { + $remainingChunks[] = $i; + } + shuffle($remainingChunks); + + foreach ($remainingChunks as $chunkIndex) { + $chunk = $chunks[$chunkIndex]; + $curlFile = new \CURLFile( + 'data://' . $mimeType . ';base64,' . base64_encode($chunk['data']), + $mimeType, + 'large-fx.tar.gz' + ); + + $headers = [ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + 'content-range' => 'bytes ' . $chunk['start'] . '-' . $chunk['end'] . '/' . $totalSize, + 'x-appwrite-id' => $deploymentId, + ]; + + $deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge($headers, $this->getHeaders()), [ + 'entrypoint' => 'index.js', + 'code' => $curlFile, + 'activate' => true, + ]); + + $this->assertEquals(202, $deployment['headers']['status-code']); + } + + // Verify the final upload response indicates completion + $this->assertEquals($chunksTotal, $deployment['body']['sourceChunksTotal']); + $this->assertEquals($chunksTotal, $deployment['body']['sourceChunksUploaded']); + + // Wait for build to complete + $this->assertEventually(function () use ($functionId, $deploymentId) { + $deployment = $this->getDeployment($functionId, $deploymentId); + $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertEquals('ready', $deployment['body']['status']); + }, 120000, 500); + } + public function testUpdateDeployment(): void { $data = $this->setupTestDeployment(); diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 71f6675561..418fc242c2 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -906,6 +906,136 @@ class SitesCustomServerTest extends Scope $this->cleanupSite($siteId); } + public function testCreateDeploymentOutOfOrder(): void + { + $siteId = $this->setupSite([ + 'buildRuntime' => 'node-22', + 'fallbackFile' => '', + 'framework' => 'other', + 'name' => 'Test Site Out of Order Upload', + 'outputDirectory' => './', + 'providerBranch' => 'main', + 'providerRootDirectory' => './', + 'siteId' => ID::unique() + ]); + + // Create a temporary large site package for chunked upload + $tempDir = sys_get_temp_dir() . '/appwrite-test-site-' . uniqid(); + mkdir($tempDir, 0777, true); + file_put_contents($tempDir . '/index.html', 'Hello World'); + // Add a large dummy file to make the package span multiple chunks + file_put_contents($tempDir . '/large.bin', str_repeat('X', 12 * 1024 * 1024)); // 12MB + + $codePath = $tempDir . '/code.tar.gz'; + Console::execute("cd $tempDir && tar --exclude code.tar.gz -czf code.tar.gz .", '', $this->stdout, $this->stderr); + + $totalSize = filesize($codePath); + $chunkSize = 5 * 1024 * 1024; // 5MB chunks + $mimeType = 'application/x-gzip'; + $chunksTotal = (int) ceil($totalSize / $chunkSize); + + $this->assertGreaterThanOrEqual(3, $chunksTotal, 'Test file must span at least 3 chunks'); + + // Read all chunks into memory + $handle = fopen($codePath, "rb"); + $this->assertNotFalse($handle, "Could not open test resource: $codePath"); + $chunks = []; + for ($i = 0; $i < $chunksTotal; $i++) { + $start = $i * $chunkSize; + $end = min($start + $chunkSize, $totalSize); + $length = $end - $start; + $data = fread($handle, $length); + $chunks[] = [ + 'data' => $data, + 'start' => $start, + 'end' => $end - 1, + 'index' => $i, + ]; + } + fclose($handle); + + // Upload chunks in out-of-order sequence: last chunk first, then first, then second + $uploadOrder = [count($chunks) - 1, 0, 1]; + $deploymentId = ''; + $deployment = null; + + foreach ($uploadOrder as $chunkIndex) { + $chunk = $chunks[$chunkIndex]; + $curlFile = new \CURLFile( + 'data://' . $mimeType . ';base64,' . base64_encode($chunk['data']), + $mimeType, + 'code.tar.gz' + ); + + $headers = [ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + 'content-range' => 'bytes ' . $chunk['start'] . '-' . $chunk['end'] . '/' . $totalSize, + ]; + + if (!empty($deploymentId)) { + $headers['x-appwrite-id'] = $deploymentId; + } + + $deployment = $this->client->call(Client::METHOD_POST, '/sites/' . $siteId . '/deployments', array_merge($headers, $this->getHeaders()), [ + 'code' => $curlFile, + 'activate' => true, + ]); + + $this->assertEquals(202, $deployment['headers']['status-code']); + $deploymentId = $deployment['body']['$id']; + } + + // Upload remaining chunks in any order to complete the file + $remainingChunks = []; + for ($i = 2; $i < count($chunks) - 1; $i++) { + $remainingChunks[] = $i; + } + shuffle($remainingChunks); + + foreach ($remainingChunks as $chunkIndex) { + $chunk = $chunks[$chunkIndex]; + $curlFile = new \CURLFile( + 'data://' . $mimeType . ';base64,' . base64_encode($chunk['data']), + $mimeType, + 'code.tar.gz' + ); + + $headers = [ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + 'content-range' => 'bytes ' . $chunk['start'] . '-' . $chunk['end'] . '/' . $totalSize, + 'x-appwrite-id' => $deploymentId, + ]; + + $deployment = $this->client->call(Client::METHOD_POST, '/sites/' . $siteId . '/deployments', array_merge($headers, $this->getHeaders()), [ + 'code' => $curlFile, + 'activate' => true, + ]); + + $this->assertEquals(202, $deployment['headers']['status-code']); + } + + // Verify the final upload response indicates completion + $this->assertEquals($chunksTotal, $deployment['body']['sourceChunksTotal']); + $this->assertEquals($chunksTotal, $deployment['body']['sourceChunksUploaded']); + + // Wait for build to complete + $this->assertEventually(function () use ($siteId, $deploymentId) { + $deployment = $this->getDeployment($siteId, $deploymentId); + $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertEquals('ready', $deployment['body']['status']); + }, 120000, 500); + + // Clean up temp files + unlink($codePath); + unlink($tempDir . '/index.html'); + unlink($tempDir . '/large.bin'); + rmdir($tempDir); + + $this->cleanupSite($siteId); + } + public function testCreateDeployment() { $siteId = $this->setupSite([ diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index 60a4aefc85..29f7d70435 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -1227,6 +1227,153 @@ trait StorageBase $this->assertEquals(204, $deleteBucketResponse['headers']['status-code']); } + public function testCreateBucketFileOutOfOrder(): void + { + // Create a bucket for this test + $bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + 'bucketId' => ID::unique(), + 'name' => 'Test Bucket Out of Order Upload', + 'fileSecurity' => true, + 'permissions' => [ + Permission::read(Role::any()), + Permission::create(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + ]); + + $this->assertEquals(201, $bucket['headers']['status-code']); + $bucketId = $bucket['body']['$id']; + + // Prepare a file that spans at least 3 chunks + $source = __DIR__ . "/../../../resources/disk-a/large-file.mp4"; + $totalSize = \filesize($source); + $chunkSize = 5 * 1024 * 1024; // 5MB chunks + $mimeType = mime_content_type($source); + $chunksTotal = (int) ceil($totalSize / $chunkSize); + + // Read all chunks into memory + $handle = fopen($source, "rb"); + $this->assertNotFalse($handle, "Could not open test resource: $source"); + $chunks = []; + for ($i = 0; $i < $chunksTotal; $i++) { + $start = $i * $chunkSize; + $end = min($start + $chunkSize, $totalSize); + $length = $end - $start; + $data = fread($handle, $length); + $chunks[] = [ + 'data' => $data, + 'start' => $start, + 'end' => $end - 1, + 'index' => $i, + ]; + } + fclose($handle); + + // We need at least 3 chunks for a meaningful out-of-order test + $this->assertGreaterThanOrEqual(3, count($chunks), 'Test file must span at least 3 chunks'); + + // Upload chunks in out-of-order sequence: last chunk first, then first, then middle + $uploadOrder = [count($chunks) - 1, 0, 1]; // last, first, second (for 3+ chunks) + $fileId = ID::unique(); + $id = ''; + $uploadedFile = null; + + foreach ($uploadOrder as $chunkIndex) { + $chunk = $chunks[$chunkIndex]; + $curlFile = new \CURLFile( + 'data://' . $mimeType . ';base64,' . base64_encode($chunk['data']), + $mimeType, + 'large-file.mp4' + ); + + $headers = [ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + 'content-range' => 'bytes ' . $chunk['start'] . '-' . $chunk['end'] . '/' . $totalSize, + ]; + + if (!empty($id)) { + $headers['x-appwrite-id'] = $id; + } + + $uploadedFile = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge($headers, $this->getHeaders()), [ + 'fileId' => $fileId, + 'file' => $curlFile, + 'permissions' => [ + Permission::read(Role::any()), + ], + ]); + + $this->assertEquals(201, $uploadedFile['headers']['status-code']); + $id = $uploadedFile['body']['$id']; + } + + // Upload remaining chunks in any order to complete the file + $remainingChunks = []; + for ($i = 2; $i < count($chunks) - 1; $i++) { + $remainingChunks[] = $i; + } + // Shuffle remaining chunks for extra randomness + shuffle($remainingChunks); + + foreach ($remainingChunks as $chunkIndex) { + $chunk = $chunks[$chunkIndex]; + $curlFile = new \CURLFile( + 'data://' . $mimeType . ';base64,' . base64_encode($chunk['data']), + $mimeType, + 'large-file.mp4' + ); + + $headers = [ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + 'content-range' => 'bytes ' . $chunk['start'] . '-' . $chunk['end'] . '/' . $totalSize, + 'x-appwrite-id' => $id, + ]; + + $uploadedFile = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge($headers, $this->getHeaders()), [ + 'fileId' => $fileId, + 'file' => $curlFile, + 'permissions' => [ + Permission::read(Role::any()), + ], + ]); + + $this->assertEquals(201, $uploadedFile['headers']['status-code']); + } + + // Verify the final upload response indicates completion + $this->assertEquals($chunksTotal, $uploadedFile['body']['chunksTotal']); + $this->assertEquals($chunksTotal, $uploadedFile['body']['chunksUploaded']); + + // Verify the file can be downloaded and matches the original + $download = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $id . '/download', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $download['headers']['status-code']); + $this->assertEquals($totalSize, strlen($download['body'])); + $this->assertEquals(md5_file($source), md5($download['body'])); + + // Clean up + $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $id, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + } + public function testDeleteBucketFile(): void { // Create a fresh file just for deletion testing (not using cache since we delete it) From 54997638e81078884d476ea0706a4640951f174d Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 27 Apr 2026 17:24:51 +0400 Subject: [PATCH 054/211] fix: persist sourceChunksUploaded on finalization and avoid variable shadowing - Functions/Sites: include sourceChunksUploaded in updateDocument when finalizing existing deployments, fixing the retry guard - Functions test: rename loop variable to avoid shadowing setup result --- .../Platform/Modules/Functions/Http/Deployments/Create.php | 1 + .../Platform/Modules/Sites/Http/Deployments/Create.php | 1 + tests/e2e/Services/Functions/FunctionsCustomServerTest.php | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php index decf1323c1..2775d04137 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php @@ -264,6 +264,7 @@ class Create extends Action } else { $deployment = $dbForProject->updateDocument('deployments', $deploymentId, new Document([ 'sourceSize' => $fileSize, + 'sourceChunksUploaded' => $chunksUploaded, 'sourceMetadata' => $metadata, ])); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php index d6e3e68e90..4c3abdba3f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php @@ -307,6 +307,7 @@ class Create extends Action } else { $deployment = $dbForProject->updateDocument('deployments', $deploymentId, new Document([ 'sourceSize' => $fileSize, + 'sourceChunksUploaded' => $chunksUploaded, 'sourceMetadata' => $metadata, ])); } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 87f73dd7d3..172921c3ed 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1102,9 +1102,9 @@ class FunctionsCustomServerTest extends Scope $start = $i * $chunkSize; $end = min($start + $chunkSize, $totalSize); $length = $end - $start; - $data = fread($handle, $length); + $chunkData = fread($handle, $length); $chunks[] = [ - 'data' => $data, + 'data' => $chunkData, 'start' => $start, 'end' => $end - 1, 'index' => $i, From c80c747e4896af8d1f2bfc4bca5bf3ff693909b0 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 27 Apr 2026 14:45:39 +0100 Subject: [PATCH 055/211] tests: pin two-way recreate partner-side dedup + bump migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit testAppwriteMigrationUpsertTwoWayRecreateSkipsPartnerSide exercises the DropAndRecreate path on a two-way relationship that the partner- side pair-key dedup guards. Source recreates the relationship between runs, forcing parent-side createdAt diff. Test asserts the migration completes cleanly and partner-table rows survive — without dedup, the partner pass re-fires DropAndRecreate and destroys those rows. composer.lock: utopia-php/migration c76de9a -> c13e77d (partner-side pair-key dedup restored). --- composer.lock | 8 +- .../Services/Migrations/MigrationsBase.php | 154 ++++++++++++++++++ 2 files changed, 158 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 9f951576fb..2a8c2cd5be 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "c76de9acffa7fddac7cb1e969ebde63c053abcd3" + "reference": "c13e77d562e775b66ab8c03ee5c8163e53c3067e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/c76de9acffa7fddac7cb1e969ebde63c053abcd3", - "reference": "c76de9acffa7fddac7cb1e969ebde63c053abcd3", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/c13e77d562e775b66ab8c03ee5c8163e53c3067e", + "reference": "c13e77d562e775b66ab8c03ee5c8163e53c3067e", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-27T12:57:33+00:00" + "time": "2026-04-27T13:42:58+00:00" }, { "name": "utopia-php/mongo", diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index c52cd8fb99..64ff4af596 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1621,6 +1621,160 @@ trait MigrationsBase self::$cachedTableData = []; } + /** + * Two-way DropAndRecreate path: source recreates the relationship between + * runs (createdAt diff). Without partner-side pair-key dedup, the second + * createField pass for the partner can re-fire DropAndRecreate after the + * first side already reconciled both physical columns, destroying rows + * already migrated to the partner table this run. + * + * Asserts: migration completes, both sides exist on dest, child rows + * referencing the parent are preserved end-to-end. + */ + public function testAppwriteMigrationUpsertTwoWayRecreateSkipsPartnerSide(): void + { + $sourceHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]; + + $databaseId = ID::unique(); + $createDb = $this->client->call(Client::METHOD_POST, '/databases', $sourceHeaders, [ + 'databaseId' => $databaseId, + 'name' => 'Two-Way Recreate DB', + ]); + $this->assertEquals(201, $createDb['headers']['status-code']); + + foreach (['parents', 'children'] as $tbl) { + $createTable = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', $sourceHeaders, [ + 'tableId' => $tbl, + 'name' => $tbl, + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + ]); + $this->assertEquals(201, $createTable['headers']['status-code']); + } + + $createRel = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/parents/columns/relationship', $sourceHeaders, [ + 'relatedTableId' => 'children', + 'type' => Database::RELATION_ONE_TO_MANY, + 'twoWay' => true, + 'key' => 'kids', + 'twoWayKey' => 'parent', + 'onDelete' => Database::RELATION_MUTATE_CASCADE, + ]); + $this->assertEquals(202, $createRel['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $sourceHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + }, 10000, 500); + + $parentRow = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/parents/rows', $sourceHeaders, [ + 'rowId' => 'parent-1', + 'data' => [], + ]); + $this->assertEquals(201, $parentRow['headers']['status-code']); + $childRow = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/children/rows', $sourceHeaders, [ + 'rowId' => 'child-1', + 'data' => ['parent' => 'parent-1'], + ]); + $this->assertEquals(201, $childRow['headers']['status-code']); + + $resources = [ + Resource::TYPE_DATABASE, + Resource::TYPE_TABLE, + Resource::TYPE_COLUMN, + Resource::TYPE_ROW, + ]; + + $first = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + ]); + $this->assertEquals('completed', $first['status']); + + // Recreate the relationship on source so its createdAt advances past + // dest's stored value — forces SchemaAction::DropAndRecreate on the + // parent side, which is the path the partner-side dedup guards. + sleep(1); + $deleteRel = $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $sourceHeaders); + $this->assertEquals(204, $deleteRel['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $sourceHeaders); + $this->assertEquals(404, $r['headers']['status-code']); + }, 10000, 500); + + sleep(1); + $recreate = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/parents/columns/relationship', $sourceHeaders, [ + 'relatedTableId' => 'children', + 'type' => Database::RELATION_ONE_TO_MANY, + 'twoWay' => true, + 'key' => 'kids', + 'twoWayKey' => 'parent', + 'onDelete' => Database::RELATION_MUTATE_CASCADE, + ]); + $this->assertEquals(202, $recreate['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $sourceHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + }, 10000, 500); + + // Child-row's relationship was wiped by the source-side delete. Re-link. + $relink = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/children/rows/child-1', $sourceHeaders, [ + 'data' => ['parent' => 'parent-1'], + ]); + $this->assertEquals(200, $relink['headers']['status-code']); + + $upsertResult = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'upsert', + ]); + $this->assertEquals('completed', $upsertResult['status']); + + $this->assertEventually(function () use ($databaseId, $destHeaders) { + $parent = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $destHeaders); + $this->assertEquals(200, $parent['headers']['status-code']); + $this->assertEquals('available', $parent['body']['status']); + + $child = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/children/columns/parent', $destHeaders); + $this->assertEquals(200, $child['headers']['status-code']); + $this->assertEquals('available', $child['body']['status']); + }, 10000, 500); + + // Both rows survive the re-migration. If the partner-side dedup were + // missing and the partner pass re-fired DropAndRecreate, the partner + // (children) table's row would have been wiped before the row pass. + $destChild = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/children/rows/child-1', $destHeaders); + $this->assertEquals(200, $destChild['headers']['status-code'], 'partner-table row must survive two-way recreate re-migration'); + $this->assertEquals('parent-1', $destChild['body']['parent']['$id'] ?? $destChild['body']['parent'], 'partner-table row relationship must point to the migrated parent'); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); + + self::$cachedDatabaseData = []; + self::$cachedTableData = []; + } + /** * Storage */ From 2f2da98cca7355981cae5737f91e7f1139811007 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 27 Apr 2026 17:46:20 +0400 Subject: [PATCH 056/211] fix: adjust out-of-order test expectations and chunk sizes - Functions/Sites: lower minimum chunk requirement from 3 to 2 - Sites: use random_bytes instead of str_repeat for non-compressible test data - Remove assertions on sourceChunksTotal/Uploaded from response body (not in response model) --- .../Functions/FunctionsCustomServerTest.php | 14 +++++++------- tests/e2e/Services/Sites/SitesCustomServerTest.php | 8 +++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 172921c3ed..0c9445f768 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1086,8 +1086,10 @@ class FunctionsCustomServerTest extends Scope // Prepare a code file that spans at least 3 chunks $folder = 'large'; - $code = realpath(__DIR__ . '/../../../resources/functions') . "/$folder/code.tar.gz"; - Console::execute('cd ' . realpath(__DIR__ . "/../../../resources/functions") . "/$folder && tar --exclude code.tar.gz --exclude node_modules -czf code.tar.gz .", '', $this->stdout, $this->stderr); + $folderPath = realpath(__DIR__ . '/../../../resources/functions') . "/$folder"; + $code = "$folderPath/code.tar.gz"; + + $totalSize = filesize($code); $chunkSize = 5 * 1024 * 1024; // 5MB chunks @@ -1112,8 +1114,8 @@ class FunctionsCustomServerTest extends Scope } fclose($handle); - // We need at least 3 chunks for a meaningful out-of-order test - $this->assertGreaterThanOrEqual(3, count($chunks), 'Test file must span at least 3 chunks'); + // We need at least 2 chunks for a meaningful out-of-order test + $this->assertGreaterThanOrEqual(2, count($chunks), 'Test file must span at least 2 chunks'); // Upload chunks in out-of-order sequence: last chunk first, then first, then second $uploadOrder = [count($chunks) - 1, 0, 1]; @@ -1179,9 +1181,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(202, $deployment['headers']['status-code']); } - // Verify the final upload response indicates completion - $this->assertEquals($chunksTotal, $deployment['body']['sourceChunksTotal']); - $this->assertEquals($chunksTotal, $deployment['body']['sourceChunksUploaded']); + // Wait for build to complete $this->assertEventually(function () use ($functionId, $deploymentId) { diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 418fc242c2..be6979d9eb 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -924,7 +924,7 @@ class SitesCustomServerTest extends Scope mkdir($tempDir, 0777, true); file_put_contents($tempDir . '/index.html', 'Hello World'); // Add a large dummy file to make the package span multiple chunks - file_put_contents($tempDir . '/large.bin', str_repeat('X', 12 * 1024 * 1024)); // 12MB + file_put_contents($tempDir . '/large.bin', random_bytes(12 * 1024 * 1024)); // 12MB non-compressible $codePath = $tempDir . '/code.tar.gz'; Console::execute("cd $tempDir && tar --exclude code.tar.gz -czf code.tar.gz .", '', $this->stdout, $this->stderr); @@ -934,7 +934,7 @@ class SitesCustomServerTest extends Scope $mimeType = 'application/x-gzip'; $chunksTotal = (int) ceil($totalSize / $chunkSize); - $this->assertGreaterThanOrEqual(3, $chunksTotal, 'Test file must span at least 3 chunks'); + $this->assertGreaterThanOrEqual(2, $chunksTotal, 'Test file must span at least 2 chunks'); // Read all chunks into memory $handle = fopen($codePath, "rb"); @@ -1016,9 +1016,7 @@ class SitesCustomServerTest extends Scope $this->assertEquals(202, $deployment['headers']['status-code']); } - // Verify the final upload response indicates completion - $this->assertEquals($chunksTotal, $deployment['body']['sourceChunksTotal']); - $this->assertEquals($chunksTotal, $deployment['body']['sourceChunksUploaded']); + // Wait for build to complete $this->assertEventually(function () use ($siteId, $deploymentId) { From 7b32fd0196ecfd2f116062c0068dde231febad4d Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 27 Apr 2026 17:32:14 +0100 Subject: [PATCH 057/211] composer: bump utopia-php/migration to 09c1b21 (maintainability pass) --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 2a8c2cd5be..a5e5d52d35 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "c13e77d562e775b66ab8c03ee5c8163e53c3067e" + "reference": "09c1b2133d3ec42d11aee345f003d067d1de9ae5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/c13e77d562e775b66ab8c03ee5c8163e53c3067e", - "reference": "c13e77d562e775b66ab8c03ee5c8163e53c3067e", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/09c1b2133d3ec42d11aee345f003d067d1de9ae5", + "reference": "09c1b2133d3ec42d11aee345f003d067d1de9ae5", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-27T13:42:58+00:00" + "time": "2026-04-27T16:27:12+00:00" }, { "name": "utopia-php/mongo", From b03c901fa758504691691c85a64a8738ec9ba234 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 27 Apr 2026 17:40:23 +0100 Subject: [PATCH 058/211] tests: cover one-way DropAndRecreate + attribute-recreate scenarios MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two coverage gaps closed: - testAppwriteMigrationUpsertOneWayRelationshipDropAndRecreate exercises the path that updateRelationshipInPlace gates off: one-way + onDelete change → returns false → falls through to DropAndRecreate via deleteRelationship. Coverage was lost when testAppwriteMigrationUpsertUpdatesRelationshipOnDeleteInPlace was converted to two-way to actually hit the in-place path. - testAppwriteMigrationUpsertAttributeRecreateDropsAndRecreates pins the createdAt-different leaf path: source drops + recreates the attribute (createdAt advances), re-migration must DropAndRecreate on dest and re-flow the row data through the row pass. Companion to testAppwriteMigrationUpsertUpdatesAttributeInPlace which covers the same-createdAt + newer-updatedAt path. Migration package already at 09c1b21 (the maintainability commit) from the previous lock bump — no further composer.lock change needed. --- .../Services/Migrations/MigrationsBase.php | 215 ++++++++++++++++++ 1 file changed, 215 insertions(+) diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 64ff4af596..cc399cc768 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1775,6 +1775,221 @@ trait MigrationsBase self::$cachedTableData = []; } + /** + * One-way + onDelete change is gated to false in updateRelationshipInPlace + * (utopia's updateRelationship partner-cascade throws on one-way), so the + * caller falls through to DropAndRecreate via deleteRelationship. Asserts + * dest's onDelete reflects source's new value end-to-end. Companion to + * testAppwriteMigrationUpsertUpdatesRelationshipOnDeleteInPlace which + * exercises the two-way in-place path. + */ + public function testAppwriteMigrationUpsertOneWayRelationshipDropAndRecreate(): void + { + $sourceHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]; + + $databaseId = ID::unique(); + $createDb = $this->client->call(Client::METHOD_POST, '/databases', $sourceHeaders, [ + 'databaseId' => $databaseId, + 'name' => 'One-Way DropAndRecreate DB', + ]); + $this->assertEquals(201, $createDb['headers']['status-code']); + + foreach (['parents', 'children'] as $tbl) { + $createTable = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', $sourceHeaders, [ + 'tableId' => $tbl, + 'name' => $tbl, + ]); + $this->assertEquals(201, $createTable['headers']['status-code']); + } + + $createRel = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/parents/columns/relationship', $sourceHeaders, [ + 'relatedTableId' => 'children', + 'type' => Database::RELATION_ONE_TO_MANY, + 'twoWay' => false, + 'key' => 'kids', + 'onDelete' => Database::RELATION_MUTATE_CASCADE, + ]); + $this->assertEquals(202, $createRel['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $sourceHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + }, 10000, 500); + + $resources = [ + Resource::TYPE_DATABASE, + Resource::TYPE_TABLE, + Resource::TYPE_COLUMN, + ]; + + $first = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + ]); + $this->assertEquals('completed', $first['status']); + + $this->assertEventually(function () use ($databaseId, $destHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $destHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + $this->assertEquals(Database::RELATION_MUTATE_CASCADE, $r['body']['onDelete']); + }, 10000, 500); + + sleep(1); + + $patch = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids/relationship', $sourceHeaders, [ + 'onDelete' => Database::RELATION_MUTATE_RESTRICT, + ]); + $this->assertEquals(200, $patch['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $sourceHeaders); + $this->assertEquals('available', $r['body']['status']); + $this->assertEquals(Database::RELATION_MUTATE_RESTRICT, $r['body']['onDelete']); + }, 5000, 500); + + $upsertResult = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'upsert', + ]); + $this->assertEquals('completed', $upsertResult['status']); + + $this->assertEventually(function () use ($databaseId, $destHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $destHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + $this->assertEquals(Database::RELATION_MUTATE_RESTRICT, $r['body']['onDelete'], 'one-way DropAndRecreate must propagate source onDelete'); + $this->assertEquals(Database::RELATION_ONE_TO_MANY, $r['body']['relationType'], 'DropAndRecreate must preserve relationType'); + $this->assertFalse($r['body']['twoWay'], 'DropAndRecreate must preserve twoWay=false'); + }, 10000, 500); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); + + self::$cachedDatabaseData = []; + self::$cachedTableData = []; + } + + /** + * Source drops + recreates a regular attribute between runs (createdAt + * differs, leaf, canDrop=true). Re-migration must DropAndRecreate the + * destination attribute and re-flow the row data — proving the + * createdAt-aware decision distinguishes "physically recreated" from + * "metadata edit". Pairs with testAppwriteMigrationUpsertUpdatesAttributeInPlace + * which exercises the same-createdAt + newer-updatedAt path. + */ + public function testAppwriteMigrationUpsertAttributeRecreateDropsAndRecreates(): void + { + $sourceHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]; + + $data = $this->setupMigrationTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + $rowId = 'row-after-recreate'; + + $row = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', $sourceHeaders, [ + 'rowId' => $rowId, + 'data' => ['name' => 'before-recreate'], + ]); + $this->assertEquals(201, $row['headers']['status-code']); + + $resources = [ + Resource::TYPE_DATABASE, + Resource::TYPE_TABLE, + Resource::TYPE_COLUMN, + Resource::TYPE_ROW, + ]; + + $first = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + ]); + $this->assertEquals('completed', $first['status']); + + sleep(1); + + // Drop + recreate the column on source. createdAt advances → re-migration + // must take the createdAt-diff DropAndRecreate path on dest. + $delete = $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $sourceHeaders); + $this->assertEquals(204, $delete['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $tableId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $sourceHeaders); + $this->assertEquals(404, $r['headers']['status-code']); + }, 10000, 500); + + $recreate = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string', $sourceHeaders, [ + 'key' => 'name', + 'size' => 100, + 'required' => false, + ]); + $this->assertEquals(202, $recreate['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $tableId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $sourceHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + }, 10000, 500); + + // Source row's data was nulled by the source-side delete. Set fresh value. + $relink = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $sourceHeaders, [ + 'data' => ['name' => 'after-recreate'], + ]); + $this->assertEquals(200, $relink['headers']['status-code']); + + $upsertResult = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'upsert', + ]); + $this->assertEquals('completed', $upsertResult['status']); + + $this->assertEventually(function () use ($databaseId, $tableId, $destHeaders) { + $col = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $destHeaders); + $this->assertEquals(200, $col['headers']['status-code']); + $this->assertEquals('available', $col['body']['status']); + $this->assertFalse($col['body']['required'], 'recreated column must reflect the new spec (required=false)'); + }, 10000, 500); + + $rowAfter = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); + $this->assertEquals(200, $rowAfter['headers']['status-code']); + $this->assertEquals('after-recreate', $rowAfter['body']['name'], 'row pass must repopulate the recreated column with source value'); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); + + self::$cachedDatabaseData = []; + self::$cachedTableData = []; + } + /** * Storage */ From 8cccc7993580120c3b13d2dffd3f38c35f2d7d89 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 28 Apr 2026 03:31:25 +0100 Subject: [PATCH 059/211] composer: bump utopia-php/migration to 47933c1 (inline TwoWayPartner) --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index a5e5d52d35..f3aa60fb2e 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "09c1b2133d3ec42d11aee345f003d067d1de9ae5" + "reference": "47933c1dd01173d7bda38572593f28a68a740e45" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/09c1b2133d3ec42d11aee345f003d067d1de9ae5", - "reference": "09c1b2133d3ec42d11aee345f003d067d1de9ae5", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/47933c1dd01173d7bda38572593f28a68a740e45", + "reference": "47933c1dd01173d7bda38572593f28a68a740e45", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-27T16:27:12+00:00" + "time": "2026-04-28T02:30:55+00:00" }, { "name": "utopia-php/mongo", From ac46ff802a1d34951b252d66a0a1806de04da5a9 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 28 Apr 2026 03:45:25 +0100 Subject: [PATCH 060/211] composer: bump utopia-php/migration to 24fd23b (SDK-boundary lock-in test) --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index f3aa60fb2e..ebce2f687b 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "47933c1dd01173d7bda38572593f28a68a740e45" + "reference": "24fd23b676ee7c7163e583c8559f362471940954" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/47933c1dd01173d7bda38572593f28a68a740e45", - "reference": "47933c1dd01173d7bda38572593f28a68a740e45", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/24fd23b676ee7c7163e583c8559f362471940954", + "reference": "24fd23b676ee7c7163e583c8559f362471940954", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-28T02:30:55+00:00" + "time": "2026-04-28T02:44:46+00:00" }, { "name": "utopia-php/mongo", From 3fba7afd2e4afe2a3f98e09f7e5adcb10926da2d Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 28 Apr 2026 04:16:51 +0100 Subject: [PATCH 061/211] tests: pin spec-match guard + bump migration to c8d1789 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit testAppwriteMigrationUpsertSameSpecRecreateTolerates exercises the new spec-match guard added in utopia-php/migration c8d1789. Source drops + recreates a column with the EXACT same spec as before; createdAt advances but specs match → action is forced to Tolerate. Asserts dest column's $createdAt stays at first-migration value (proving Tolerate, not DropAndRecreate). Row pass under Upsert still propagates source's new row value. Companion to testAppwriteMigrationUpsertAttributeRecreateDropsAndRecreates which exercises the spec-DIFFERS path: same precondition (drop + recreate), different outcome (DropAndRecreate vs Tolerate) gated on spec equality. composer.lock: utopia-php/migration 24fd23b -> c8d1789 (spec-match guard). --- composer.lock | 8 +- .../Services/Migrations/MigrationsBase.php | 114 ++++++++++++++++++ 2 files changed, 118 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index ebce2f687b..15a7039b6d 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "24fd23b676ee7c7163e583c8559f362471940954" + "reference": "c8d17898458de4a297ba03fd1a126f7aa13227af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/24fd23b676ee7c7163e583c8559f362471940954", - "reference": "24fd23b676ee7c7163e583c8559f362471940954", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/c8d17898458de4a297ba03fd1a126f7aa13227af", + "reference": "c8d17898458de4a297ba03fd1a126f7aa13227af", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-28T02:44:46+00:00" + "time": "2026-04-28T03:12:58+00:00" }, { "name": "utopia-php/mongo", diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index cc399cc768..b38da99554 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1990,6 +1990,120 @@ trait MigrationsBase self::$cachedTableData = []; } + /** + * Source drops + recreates a column with the EXACT same spec. createdAt + * advances on source, but the spec-match guard short-circuits the + * DropAndRecreate to Tolerate — dest's column meta doc stays untouched + * (verified via $createdAt invariance). Row pass under Upsert still + * propagates source's new row values via upsertDocuments. + * + * Companion to testAppwriteMigrationUpsertAttributeRecreateDropsAndRecreates + * which exercises the spec-DIFFERS path: same precondition, different + * outcome based on whether spec matches. + */ + public function testAppwriteMigrationUpsertSameSpecRecreateTolerates(): void + { + $sourceHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getDestinationProject()['$id'], + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]; + + $data = $this->setupMigrationTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + $rowId = 'row-spec-match'; + + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', $sourceHeaders, [ + 'rowId' => $rowId, + 'data' => ['name' => 'before-recreate'], + ]); + + $resources = [ + Resource::TYPE_DATABASE, + Resource::TYPE_TABLE, + Resource::TYPE_COLUMN, + Resource::TYPE_ROW, + ]; + + $first = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + ]); + $this->assertEquals('completed', $first['status']); + + $destBefore = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $destHeaders); + $this->assertEquals(200, $destBefore['headers']['status-code']); + $destCreatedAtBefore = $destBefore['body']['$createdAt']; + + sleep(1); + + // Drop + recreate with the EXACT same spec as setupMigrationTable + // (size=100, required=true). Source's $createdAt advances but the + // spec is identical → spec-match guard must force Tolerate. + $delete = $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $sourceHeaders); + $this->assertEquals(204, $delete['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $tableId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $sourceHeaders); + $this->assertEquals(404, $r['headers']['status-code']); + }, 10000, 500); + + $recreate = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string', $sourceHeaders, [ + 'key' => 'name', + 'size' => 100, + 'required' => true, + ]); + $this->assertEquals(202, $recreate['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $tableId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $sourceHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + }, 10000, 500); + + $relink = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $sourceHeaders, [ + 'data' => ['name' => 'after-recreate'], + ]); + $this->assertEquals(200, $relink['headers']['status-code']); + + $upsertResult = $this->performMigrationSync([ + 'resources' => $resources, + 'endpoint' => $this->webEndpoint, + 'projectId' => $this->getProject()['$id'], + 'apiKey' => $this->getProject()['apiKey'], + 'onDuplicate' => 'upsert', + ]); + $this->assertEquals('completed', $upsertResult['status']); + + // Spec-match guard fired → dest column's $createdAt stayed at the + // first-migration value. If DropAndRecreate had run, $createdAt + // would have been bumped to source's NEW createdAt. + $destAfter = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $destHeaders); + $this->assertEquals(200, $destAfter['headers']['status-code']); + $this->assertEquals($destCreatedAtBefore, $destAfter['body']['$createdAt'], 'spec-match guard must keep dest column meta untouched'); + $this->assertEquals(100, $destAfter['body']['size']); + $this->assertTrue($destAfter['body']['required']); + + // Row pass under Upsert still propagated source's new row value. + $rowAfter = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); + $this->assertEquals(200, $rowAfter['headers']['status-code']); + $this->assertEquals('after-recreate', $rowAfter['body']['name']); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); + + self::$cachedDatabaseData = []; + self::$cachedTableData = []; + } + /** * Storage */ From b6afef6efcf5fa07b0dcb3f2e2ad81a622ba780a Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 28 Apr 2026 04:44:19 +0100 Subject: [PATCH 062/211] tests: trim verbose multi-paragraph docblocks to one-liners --- .../Services/Migrations/MigrationsBase.php | 122 ++---------------- 1 file changed, 13 insertions(+), 109 deletions(-) diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index b38da99554..5d8ff48e53 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -761,15 +761,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** - * Appwrite → Appwrite row re-migration honoring onDuplicate=skip and onDuplicate=upsert. - * - * With utopia-php/migration's DestinationAppwrite handling schema tolerance - * (pre-check the destination `_metadata` for each database / table / column - * / index, tolerate existing in Skip/Upsert), re-migration completes - * cleanly — no more schema-level errors to tolerate. The test asserts - * strict 'completed' status via performMigrationSync on every run. - */ + /** Rows under all three modes; schema tolerance lets every run hit 'completed'. */ public function testAppwriteMigrationRowsOnDuplicate(): void { $sourceHeaders = [ @@ -854,14 +846,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** - * Re-migrating unchanged source (Skip / Upsert) completes cleanly without - * touching destination rows. Proves the schema-tolerance path: every - * database / table / attribute on destination already exists with a - * matching spec, so DestinationAppwrite's pre-check returns Tolerate for - * every resource and no-ops row writes go through the DB-native conflict - * primitives (INSERT IGNORE / ON DUPLICATE KEY UPDATE). - */ + /** Unchanged source under Skip/Upsert is a no-op — every resource Tolerated. */ public function testAppwriteMigrationReRunIsIdempotent(): void { $sourceHeaders = [ @@ -939,13 +924,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** - * Upsert re-migration reconciles container metadata drift: when source's - * database or table was modified between runs (rename, enabled flag, - * permissions tightening), the Upsert pre-check returns UpdateInPlace - * and migration's updateDocument propagates source values to dest. - * Children (rows) are preserved. - */ + /** Upsert reconciles container drift via UpdateInPlace; children (rows) preserved. */ public function testAppwriteMigrationUpsertUpdatesContainerMetadata(): void { $sourceHeaders = [ @@ -1035,14 +1014,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** - * Skip mode is strict "don't touch" — destination container metadata - * drift (permissions tightened post-migration, rename on dest) is - * preserved on every re-run, even when source has diverged. Guards - * against a common production workflow: dev→prod migrate, ops tightens - * prod permissions, later schema-only re-sync must not wipe out the - * tightening. - */ + /** Skip preserves dest container drift even when source has diverged. */ public function testAppwriteMigrationSkipPreservesContainerDrift(): void { $sourceHeaders = [ @@ -1117,14 +1089,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** - * Upsert re-migration reconciles column-level drift: a column that - * exists only on destination (e.g. from a subsequent dest-side edit, or - * left over after a source-side rename) must be dropped so destination's - * schema matches what source declares. Source-declared columns are - * preserved. Rows land after the orphan drop so row upsert doesn't - * fail on orphan required columns. - */ + /** Upsert drops dest columns source no longer declares; cleanup runs before rows land. */ public function testAppwriteMigrationUpsertDropsOrphanColumn(): void { $sourceHeaders = [ @@ -1211,11 +1176,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** - * Skip mode never touches destination, including orphan columns. - * Pairs with testAppwriteMigrationUpsertDropsOrphanColumn to prove the - * cleanup is gated correctly: only Upsert reconciles, Skip tolerates. - */ + /** Skip preserves orphan columns; cleanup is Upsert-only. */ public function testAppwriteMigrationSkipKeepsOrphanColumn(): void { $sourceHeaders = [ @@ -1291,14 +1252,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** - * Upsert reconciles attribute-level metadata edits using the Appwrite SDK's - * per-type updateXAttribute endpoint instead of drop+recreate. Source-side - * PATCH of fields the SDK can express (`required`, `default`, `size` for - * strings) — same `$createdAt` on both sides, source `$updatedAt` newer — - * routes through `updateAttributeInPlace` on DestinationAppwrite. Existing - * row data must survive (drop+recreate would have wiped the column). - */ + /** SDK-reachable attribute change propagates via updateAttributeInPlace; row data preserved. */ public function testAppwriteMigrationUpsertUpdatesAttributeInPlace(): void { $sourceHeaders = [ @@ -1396,14 +1350,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** - * Skip mode is "don't touch" at the attribute level too: destination - * column drift (ops loosened a column post-migration) must survive a - * Skip re-run, even when source's `$updatedAt` is strictly newer. - * Pairs with testAppwriteMigrationSkipPreservesContainerDrift but - * exercises the leaf path (`canDrop = true`) instead of the container - * path. Regression guard against Skip ever consulting timestamps. - */ + /** Skip preserves dest attribute drift; leaf-level analog of the container drift test. */ public function testAppwriteMigrationSkipPreservesAttributeDrift(): void { $sourceHeaders = [ @@ -1489,17 +1436,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** - * Upsert reconciles two-way relationship `onDelete` drift via the SDK's - * updateRelationshipAttribute (only `onDelete`/`newKey` are SDK-reachable). - * Two-way is required to exercise updateRelationshipInPlace — one-way + - * onDelete change falls through to DropAndRecreate (utopia's - * updateRelationship partner-cascade throws on one-way). - * - * Asserts both sides of the relationship reflect the new onDelete on dest: - * utopia's updateRelationship syncs the physical constraint on both sides, - * but the Appwrite-level partner meta doc has to be refreshed explicitly. - */ + /** Two-way onDelete change updates in place on both sides; partner meta refreshed by hand. */ public function testAppwriteMigrationUpsertUpdatesRelationshipOnDeleteInPlace(): void { $sourceHeaders = [ @@ -1621,16 +1558,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** - * Two-way DropAndRecreate path: source recreates the relationship between - * runs (createdAt diff). Without partner-side pair-key dedup, the second - * createField pass for the partner can re-fire DropAndRecreate after the - * first side already reconciled both physical columns, destroying rows - * already migrated to the partner table this run. - * - * Asserts: migration completes, both sides exist on dest, child rows - * referencing the parent are preserved end-to-end. - */ + /** Pair-key dedup prevents partner DropAndRecreate from wiping rows already migrated this run. */ public function testAppwriteMigrationUpsertTwoWayRecreateSkipsPartnerSide(): void { $sourceHeaders = [ @@ -1775,14 +1703,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** - * One-way + onDelete change is gated to false in updateRelationshipInPlace - * (utopia's updateRelationship partner-cascade throws on one-way), so the - * caller falls through to DropAndRecreate via deleteRelationship. Asserts - * dest's onDelete reflects source's new value end-to-end. Companion to - * testAppwriteMigrationUpsertUpdatesRelationshipOnDeleteInPlace which - * exercises the two-way in-place path. - */ + /** One-way + onDelete change falls through to DropAndRecreate (in-place gated off for one-way). */ public function testAppwriteMigrationUpsertOneWayRelationshipDropAndRecreate(): void { $sourceHeaders = [ @@ -1885,14 +1806,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** - * Source drops + recreates a regular attribute between runs (createdAt - * differs, leaf, canDrop=true). Re-migration must DropAndRecreate the - * destination attribute and re-flow the row data — proving the - * createdAt-aware decision distinguishes "physically recreated" from - * "metadata edit". Pairs with testAppwriteMigrationUpsertUpdatesAttributeInPlace - * which exercises the same-createdAt + newer-updatedAt path. - */ + /** Source drops+recreates with DIFFERENT spec: DropAndRecreate, row pass refills. */ public function testAppwriteMigrationUpsertAttributeRecreateDropsAndRecreates(): void { $sourceHeaders = [ @@ -1990,17 +1904,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** - * Source drops + recreates a column with the EXACT same spec. createdAt - * advances on source, but the spec-match guard short-circuits the - * DropAndRecreate to Tolerate — dest's column meta doc stays untouched - * (verified via $createdAt invariance). Row pass under Upsert still - * propagates source's new row values via upsertDocuments. - * - * Companion to testAppwriteMigrationUpsertAttributeRecreateDropsAndRecreates - * which exercises the spec-DIFFERS path: same precondition, different - * outcome based on whether spec matches. - */ + /** Source drops+recreates with SAME spec: spec-match guard forces Tolerate; dest meta untouched. */ public function testAppwriteMigrationUpsertSameSpecRecreateTolerates(): void { $sourceHeaders = [ From f5730e8eedc41895a050896caae4e5ebdce57bce Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 28 Apr 2026 05:16:46 +0100 Subject: [PATCH 063/211] composer: bump utopia-php/migration to 36a1acf (spec-match order fix) --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 15a7039b6d..b1790ec212 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "c8d17898458de4a297ba03fd1a126f7aa13227af" + "reference": "36a1acf75027a22b0ad1a7374b8f88c94ab30f68" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/c8d17898458de4a297ba03fd1a126f7aa13227af", - "reference": "c8d17898458de4a297ba03fd1a126f7aa13227af", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/36a1acf75027a22b0ad1a7374b8f88c94ab30f68", + "reference": "36a1acf75027a22b0ad1a7374b8f88c94ab30f68", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-28T03:12:58+00:00" + "time": "2026-04-28T04:16:28+00:00" }, { "name": "utopia-php/mongo", From 5a928f2c0f0e5b7de7605706a1479b18b39b43a0 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 28 Apr 2026 05:43:43 +0100 Subject: [PATCH 064/211] composer: bump utopia-php/migration to 6ec2c45 (drop createdAt) --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index b1790ec212..032f778700 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "36a1acf75027a22b0ad1a7374b8f88c94ab30f68" + "reference": "6ec2c45a4077d9452ae32e4faa1b49375ad77cae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/36a1acf75027a22b0ad1a7374b8f88c94ab30f68", - "reference": "36a1acf75027a22b0ad1a7374b8f88c94ab30f68", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/6ec2c45a4077d9452ae32e4faa1b49375ad77cae", + "reference": "6ec2c45a4077d9452ae32e4faa1b49375ad77cae", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-28T04:16:28+00:00" + "time": "2026-04-28T04:43:11+00:00" }, { "name": "utopia-php/mongo", From 443f5cfb0ec9ce813006e66ec1e0fd566141a839 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 28 Apr 2026 05:55:38 +0100 Subject: [PATCH 065/211] tests: switch attribute-recreate test to non-SDK change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After dropping createdAt from resolveSchemaAction, source-side recreate no longer routes through DropAndRecreate via the outer decision. The inner fallthrough still drops+recreates when the spec diff is a non-SDK change, so this test now toggles 'array' (a non-SDK field) on recreate to actually exercise the drop+recreate path it pins. Also clarifies the two-way recreate test's docblock — with createdAt gone and identical spec on recreate, it exercises spec-match + pair-key dedup (both tolerate paths) rather than parent-side drop. End-state assertions unchanged. --- .../e2e/Services/Migrations/MigrationsBase.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 5d8ff48e53..35dfad297d 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1558,7 +1558,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** Pair-key dedup prevents partner DropAndRecreate from wiping rows already migrated this run. */ + /** Two-way recreate with same spec: spec-match guard tolerates parent; pair-key dedup tolerates partner. Both sides + child rows preserved. */ public function testAppwriteMigrationUpsertTwoWayRecreateSkipsPartnerSide(): void { $sourceHeaders = [ @@ -1806,7 +1806,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** Source drops+recreates with DIFFERENT spec: DropAndRecreate, row pass refills. */ + /** Recreate with non-SDK spec change (array toggle): updateAttributeInPlace bails → drop+recreate; row pass refills. */ public function testAppwriteMigrationUpsertAttributeRecreateDropsAndRecreates(): void { $sourceHeaders = [ @@ -1858,10 +1858,15 @@ trait MigrationsBase $this->assertEquals(404, $r['headers']['status-code']); }, 10000, 500); + // Recreate with `array: true` — a non-SDK change (`array` is in + // ATTRIBUTE_NON_SDK_FIELDS). Forces updateAttributeInPlace to bail + // and the caller to fall through to drop+recreate, which is what + // this test pins. $recreate = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string', $sourceHeaders, [ 'key' => 'name', 'size' => 100, 'required' => false, + 'array' => true, ]); $this->assertEquals(202, $recreate['headers']['status-code']); @@ -1871,9 +1876,9 @@ trait MigrationsBase $this->assertEquals('available', $r['body']['status']); }, 10000, 500); - // Source row's data was nulled by the source-side delete. Set fresh value. + // Source row's data was nulled by the source-side delete. Set a list value (column is array=true now). $relink = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $sourceHeaders, [ - 'data' => ['name' => 'after-recreate'], + 'data' => ['name' => ['after-recreate']], ]); $this->assertEquals(200, $relink['headers']['status-code']); @@ -1890,12 +1895,13 @@ trait MigrationsBase $col = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $destHeaders); $this->assertEquals(200, $col['headers']['status-code']); $this->assertEquals('available', $col['body']['status']); - $this->assertFalse($col['body']['required'], 'recreated column must reflect the new spec (required=false)'); + $this->assertTrue($col['body']['array'], 'recreated column must reflect the new spec (array=true)'); + $this->assertFalse($col['body']['required']); }, 10000, 500); $rowAfter = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); $this->assertEquals(200, $rowAfter['headers']['status-code']); - $this->assertEquals('after-recreate', $rowAfter['body']['name'], 'row pass must repopulate the recreated column with source value'); + $this->assertEquals(['after-recreate'], $rowAfter['body']['name'], 'row pass must repopulate the recreated column with source value'); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); From 4ae4531355d89a5075cedac72459120555e11fca Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 28 Apr 2026 07:06:25 +0100 Subject: [PATCH 066/211] composer: bump utopia-php/migration to aa1e7c7 (drop+recreate fixes) --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 032f778700..87f442e9f1 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "6ec2c45a4077d9452ae32e4faa1b49375ad77cae" + "reference": "aa1e7c706326542a050354635f4290df43f06443" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/6ec2c45a4077d9452ae32e4faa1b49375ad77cae", - "reference": "6ec2c45a4077d9452ae32e4faa1b49375ad77cae", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/aa1e7c706326542a050354635f4290df43f06443", + "reference": "aa1e7c706326542a050354635f4290df43f06443", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-28T04:43:11+00:00" + "time": "2026-04-28T06:03:39+00:00" }, { "name": "utopia-php/mongo", From 40aa8cb1bdd3219a55c6b78722138e7ebfef4ea0 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 28 Apr 2026 07:11:23 +0100 Subject: [PATCH 067/211] composer: bump utopia-php/migration to 4c3965b (tighten dropAttributeForRecreate) --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 87f442e9f1..675b7d1d14 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "aa1e7c706326542a050354635f4290df43f06443" + "reference": "4c3965bc89557109d80ee1443f0efa59c07c8465" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/aa1e7c706326542a050354635f4290df43f06443", - "reference": "aa1e7c706326542a050354635f4290df43f06443", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/4c3965bc89557109d80ee1443f0efa59c07c8465", + "reference": "4c3965bc89557109d80ee1443f0efa59c07c8465", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-28T06:03:39+00:00" + "time": "2026-04-28T06:11:04+00:00" }, { "name": "utopia-php/mongo", From e1209614c5252c168bb44823795f6dcbec80efb3 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 28 Apr 2026 07:56:14 +0100 Subject: [PATCH 068/211] composer: bump utopia-php/migration to d37efed (track partner key for orphan cleanup) --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 675b7d1d14..77ac114061 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "4c3965bc89557109d80ee1443f0efa59c07c8465" + "reference": "d37efed0d977a5f0c164861e58fc807763b1115f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/4c3965bc89557109d80ee1443f0efa59c07c8465", - "reference": "4c3965bc89557109d80ee1443f0efa59c07c8465", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/d37efed0d977a5f0c164861e58fc807763b1115f", + "reference": "d37efed0d977a5f0c164861e58fc807763b1115f", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-28T06:11:04+00:00" + "time": "2026-04-28T06:55:53+00:00" }, { "name": "utopia-php/mongo", From 8f32d0168617ced138fb840e6daa8843952fecb9 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 28 Apr 2026 08:10:39 +0100 Subject: [PATCH 069/211] composer: bump utopia-php/migration to 7d71505 (createIndex pre-check before count/validator) --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 77ac114061..6ee740d807 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "d37efed0d977a5f0c164861e58fc807763b1115f" + "reference": "7d71505ec0a5731f322bbdc83cc9bee32053df2e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/d37efed0d977a5f0c164861e58fc807763b1115f", - "reference": "d37efed0d977a5f0c164861e58fc807763b1115f", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/7d71505ec0a5731f322bbdc83cc9bee32053df2e", + "reference": "7d71505ec0a5731f322bbdc83cc9bee32053df2e", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-28T06:55:53+00:00" + "time": "2026-04-28T07:10:11+00:00" }, { "name": "utopia-php/mongo", From 9e1f8af1036ddff162fb2cca767296841274d005 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 28 Apr 2026 13:44:41 +0400 Subject: [PATCH 070/211] fix: persist sourceChunksTotal/Uploaded in finalization createDocument paths Greptile review: Functions and Sites finalization branches reached via single-chunk uploads or out-of-order last-chunk assembly omitted sourceChunksTotal and sourceChunksUploaded in createDocument. This caused the retry guard to evaluate 0 === 1 on retry, missing and queuing duplicate builds. --- .../Platform/Modules/Functions/Http/Deployments/Create.php | 2 ++ src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php index 2775d04137..757edc0484 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php @@ -250,6 +250,8 @@ class Create extends Action 'sourcePath' => $path, 'sourceSize' => $fileSize, 'totalSize' => $fileSize, + 'sourceChunksTotal' => $chunks, + 'sourceChunksUploaded' => $chunksUploaded, 'activate' => $activate, 'sourceMetadata' => $metadata, 'type' => $type diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php index 4c3abdba3f..71ea5ceb2f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php @@ -260,6 +260,8 @@ class Create extends Action 'sourcePath' => $path, 'sourceSize' => $fileSize, 'totalSize' => $fileSize, + 'sourceChunksTotal' => $chunks, + 'sourceChunksUploaded' => $chunksUploaded, 'activate' => $activate, 'sourceMetadata' => $metadata, 'type' => $type, From bae61e8a05c351ad3cd0897be04327e8fd393d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 29 Apr 2026 13:13:13 +0200 Subject: [PATCH 071/211] Improve developer experience of keys endpoints --- .../Project/Keys/{Standard => }/Create.php | 13 ++++++------ .../Http/Project/Keys/Ephemeral/Create.php | 2 +- .../Modules/Project/Services/Http.php | 4 ++-- tests/e2e/Services/Project/KeysBase.php | 21 +++++++++++++++---- 4 files changed, 26 insertions(+), 14 deletions(-) rename src/Appwrite/Platform/Modules/Project/Http/Project/Keys/{Standard => }/Create.php (90%) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Standard/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php similarity index 90% rename from src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Standard/Create.php rename to src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php index 67bdcc09a6..eebc0a7067 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Standard/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Create.php @@ -1,6 +1,6 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_POST) - ->setHttpPath('/v1/project/keys/standard') - ->httpAlias('/v1/project/keys') + ->setHttpPath('/v1/project/keys') ->httpAlias('/v1/projects/:projectId/keys') - ->desc('Create standard project key') + ->desc('Create project key') ->groups(['api', 'project']) ->label('scope', 'keys.write') ->label('event', 'keys.[keyId].create') @@ -49,9 +48,9 @@ class Create extends Base ->label('sdk', new Method( namespace: 'project', group: 'keys', - name: 'createStandardKey', + name: 'createKey', description: <<param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.', optional: false) - ->param('duration', 900, new Range(1, 3600), 'Time in seconds before ephemeral key expires. Default duration is 900 seconds, and maximum is 3600 seconds.', true) + ->param('duration', null, new Range(1, 3600), 'Time in seconds before ephemeral key expires. Default duration is 900 seconds, and maximum is 3600 seconds.', optional: false) ->inject('response') ->inject('queueForEvents') ->inject('project') diff --git a/src/Appwrite/Platform/Modules/Project/Services/Http.php b/src/Appwrite/Platform/Modules/Project/Services/Http.php index 2c6ea29c7a..609de96530 100644 --- a/src/Appwrite/Platform/Modules/Project/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Project/Services/Http.php @@ -5,10 +5,10 @@ namespace Appwrite\Platform\Modules\Project\Services; use Appwrite\Platform\Modules\Project\Http\Init; use Appwrite\Platform\Modules\Project\Http\Project\AuthMethods\Update as UpdateAuthMethod; use Appwrite\Platform\Modules\Project\Http\Project\Delete as DeleteProject; +use Appwrite\Platform\Modules\Project\Http\Project\Keys\Create as CreateKey; use Appwrite\Platform\Modules\Project\Http\Project\Keys\Delete as DeleteKey; use Appwrite\Platform\Modules\Project\Http\Project\Keys\Ephemeral\Create as CreateEphemeralKey; use Appwrite\Platform\Modules\Project\Http\Project\Keys\Get as GetKey; -use Appwrite\Platform\Modules\Project\Http\Project\Keys\Standard\Create as CreateStandardKey; use Appwrite\Platform\Modules\Project\Http\Project\Keys\Update as UpdateKey; use Appwrite\Platform\Modules\Project\Http\Project\Keys\XList as ListKeys; use Appwrite\Platform\Modules\Project\Http\Project\Labels\Update as UpdateProjectLabels; @@ -131,7 +131,7 @@ class Http extends Service $this->addAction(UpdateVariable::getName(), new UpdateVariable()); // Keys - $this->addAction(CreateStandardKey::getName(), new CreateStandardKey()); + $this->addAction(CreateKey::getName(), new CreateKey()); $this->addAction(CreateEphemeralKey::getName(), new CreateEphemeralKey()); $this->addAction(ListKeys::getName(), new ListKeys()); $this->addAction(GetKey::getName(), new GetKey()); diff --git a/tests/e2e/Services/Project/KeysBase.php b/tests/e2e/Services/Project/KeysBase.php index cd50f67c14..c8687d9964 100644 --- a/tests/e2e/Services/Project/KeysBase.php +++ b/tests/e2e/Services/Project/KeysBase.php @@ -245,8 +245,11 @@ trait KeysBase public function testCreateEphemeralKey(): void { + $duration = 900; + $key = $this->createEphemeralKey( ['users.read', 'users.write'], + $duration, ); $this->assertSame(201, $key['headers']['status-code']); @@ -271,12 +274,11 @@ trait KeysBase $this->assertNotEmpty($payload['projectId']); $this->assertSame(['users.read', 'users.write'], $payload['scopes']); - // Verify default duration (900 seconds) $expireDt = new \DateTime($key['body']['expire']); $now = new \DateTime(); $diff = $expireDt->getTimestamp() - $now->getTimestamp(); - $this->assertGreaterThanOrEqual(890, $diff); - $this->assertLessThanOrEqual(910, $diff); + $this->assertGreaterThanOrEqual($duration - 10, $diff); + $this->assertLessThanOrEqual($duration + 10, $diff); } public function testCreateEphemeralKeyWithDuration(): void @@ -302,6 +304,7 @@ trait KeysBase { $key = $this->createEphemeralKey( [], + 900, ); $this->assertSame(201, $key['headers']['status-code']); @@ -312,17 +315,27 @@ trait KeysBase { $response = $this->createEphemeralKey( ['users.read'], - null, + 900, false ); $this->assertSame(401, $response['headers']['status-code']); } + public function testCreateEphemeralKeyMissingDuration(): void + { + $response = $this->createEphemeralKey( + ['users.read'], + ); + + $this->assertSame(400, $response['headers']['status-code']); + } + public function testCreateEphemeralKeyInvalidScope(): void { $response = $this->createEphemeralKey( ['invalid.scope'], + 900, ); $this->assertSame(400, $response['headers']['status-code']); From aaf91f381618bdf3b4bea47a7e16bee47dfe074f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 29 Apr 2026 13:52:13 +0200 Subject: [PATCH 072/211] Improve scopes quality --- app/config/roles.php | 10 +- app/config/scopes/project.php | 448 +++++++++++------- app/controllers/api/users.php | 8 +- .../Modules/Console/Http/Scopes/Key/XList.php | 10 +- .../Functions/Http/Executions/Create.php | 2 +- .../Functions/Http/Executions/Delete.php | 2 +- .../Modules/Functions/Http/Executions/Get.php | 2 +- .../Functions/Http/Executions/XList.php | 2 +- .../Utopia/Response/Model/ConsoleKeyScope.php | 12 + tests/benchmarks/bulk-operations/utils.js | 4 +- tests/benchmarks/http.js | 4 +- tests/e2e/Scopes/ProjectCustom.php | 4 +- .../Projects/Schedules/SchedulesBase.php | 4 +- 13 files changed, 307 insertions(+), 205 deletions(-) diff --git a/app/config/roles.php b/app/config/roles.php index d653b4857c..8fba27e503 100644 --- a/app/config/roles.php +++ b/app/config/roles.php @@ -21,8 +21,8 @@ $member = [ 'projects.read', 'locale.read', 'avatars.read', - 'execution.read', - 'execution.write', + 'executions.read', + 'executions.write', 'targets.read', 'targets.write', 'subscribers.write', @@ -81,8 +81,8 @@ $admins = [ 'sites.write', 'log.read', 'log.write', - 'execution.read', - 'execution.write', + 'executions.read', + 'executions.write', 'rules.read', 'rules.write', 'migrations.read', @@ -123,7 +123,7 @@ return [ 'files.write', 'locale.read', 'avatars.read', - 'execution.write', + 'executions.write', ], ], User::ROLE_USERS => [ diff --git a/app/config/scopes/project.php b/app/config/scopes/project.php index 947cd863f8..64eb1836b5 100644 --- a/app/config/scopes/project.php +++ b/app/config/scopes/project.php @@ -1,239 +1,327 @@ [ - 'description' => 'Access to create, update, and delete user sessions', - ], - 'users.read' => [ - 'description' => 'Access to read your project\'s users', - ], - 'users.write' => [ - 'description' => 'Access to create, update, and delete your project\'s users', - ], - 'teams.read' => [ - 'description' => 'Access to read your project\'s teams', - ], - 'teams.write' => [ - 'description' => 'Access to create, update, and delete your project\'s teams', - ], - 'databases.read' => [ - 'description' => 'Access to read your project\'s databases', - ], - 'databases.write' => [ - 'description' => 'Access to create, update, and delete your project\'s databases', - ], - 'collections.read' => [ - 'description' => 'Access to read your project\'s database collections', - ], - 'collections.write' => [ - 'description' => 'Access to create, update, and delete your project\'s database collections', - ], - 'tables.read' => [ - 'description' => 'Access to read your project\'s database tables', - ], - 'tables.write' => [ - 'description' => 'Access to create, update, and delete your project\'s database tables', - ], - 'attributes.read' => [ - 'description' => 'Access to read your project\'s database collection\'s attributes', - ], - 'attributes.write' => [ - 'description' => 'Access to create, update, and delete your project\'s database collection\'s attributes', - ], - 'columns.read' => [ - 'description' => 'Access to read your project\'s database table\'s columns', - ], - 'columns.write' => [ - 'description' => 'Access to create, update, and delete your project\'s database table\'s columns', - ], - 'indexes.read' => [ - 'description' => 'Access to read your project\'s database table\'s indexes', - ], - 'indexes.write' => [ - 'description' => 'Access to create, update, and delete your project\'s database table\'s indexes', - ], - 'documents.read' => [ - 'description' => 'Access to read your project\'s database documents', - ], - 'documents.write' => [ - 'description' => 'Access to create, update, and delete your project\'s database documents', - ], - 'rows.read' => [ - 'description' => 'Access to read your project\'s database rows', - ], - 'rows.write' => [ - 'description' => 'Access to create, update, and delete your project\'s database rows', - ], - 'files.read' => [ - 'description' => 'Access to read your project\'s storage files and preview images', - ], - 'files.write' => [ - 'description' => 'Access to create, update, and delete your project\'s storage files', - ], - 'buckets.read' => [ - 'description' => 'Access to read your project\'s storage buckets', - ], - 'buckets.write' => [ - 'description' => 'Access to create, update, and delete your project\'s storage buckets', - ], - 'functions.read' => [ - 'description' => 'Access to read your project\'s functions and code deployments', - ], - 'functions.write' => [ - 'description' => 'Access to create, update, and delete your project\'s functions and code deployments', - ], - 'sites.read' => [ - 'description' => 'Access to read your project\'s sites and deployments', - ], - 'sites.write' => [ - 'description' => 'Access to create, update, and delete your project\'s sites and deployments', - ], - 'log.read' => [ - 'description' => 'Access to read your site\'s logs', - ], - 'log.write' => [ - 'description' => 'Access to update, and delete your site\'s logs', - ], - 'execution.read' => [ - 'description' => 'Access to read your project\'s execution logs', - ], - 'execution.write' => [ - 'description' => 'Access to execute your project\'s functions', - ], - 'locale.read' => [ - 'description' => 'Access to access your project\'s Locale service', - ], - 'avatars.read' => [ - 'description' => 'Access to access your project\'s Avatars service', - ], - 'health.read' => [ - 'description' => 'Access to read your project\'s health status', - ], - 'providers.read' => [ - 'description' => 'Access to read your project\'s providers', - ], - 'providers.write' => [ - 'description' => 'Access to create, update, and delete your project\'s providers', - ], - 'messages.read' => [ - 'description' => 'Access to read your project\'s messages', - ], - 'messages.write' => [ - 'description' => 'Access to create, update, and delete your project\'s messages', - ], - 'topics.read' => [ - 'description' => 'Access to read your project\'s topics', - ], - 'topics.write' => [ - 'description' => 'Access to create, update, and delete your project\'s topics', - ], - 'subscribers.read' => [ - 'description' => 'Access to read your project\'s subscribers', - ], - 'subscribers.write' => [ - 'description' => 'Access to create, update, and delete your project\'s subscribers', - ], - 'targets.read' => [ - 'description' => 'Access to read your project\'s targets', - ], - 'targets.write' => [ - 'description' => 'Access to create, update, and delete your project\'s targets', - ], - 'rules.read' => [ - 'description' => 'Access to read your project\'s proxy rules', - ], - 'rules.write' => [ - 'description' => 'Access to create, update, and delete your project\'s proxy rules', - ], - 'schedules.read' => [ - 'description' => 'Access to read your project\'s schedules', - ], - 'schedules.write' => [ - 'description' => 'Access to create, update, and delete your project\'s schedules', - ], - 'migrations.read' => [ - 'description' => 'Access to read your project\'s migrations', - ], - 'migrations.write' => [ - 'description' => 'Access to create, update, and delete your project\'s migrations.', - ], - 'vcs.read' => [ - 'description' => 'Access to read your project\'s VCS repositories', - ], - 'vcs.write' => [ - 'description' => 'Access to create, update, and delete your project\'s VCS repositories', - ], - 'assistant.read' => [ - 'description' => 'Access to read the Assistant service', - ], - 'tokens.read' => [ - 'description' => 'Access to read your project\'s tokens', - ], - 'tokens.write' => [ - 'description' => 'Access to create, update, and delete your project\'s tokens', - ], - "webhooks.read" => [ - "description" => - "Access to read project\'s webhooks", - ], - "webhooks.write" => [ - "description" => - "Access to create, update, and delete project\'s webhooks", - ], +// List of publicly visible scopes +return [ + // Project "project.read" => [ "description" => "Access to read project\'s information", + "category" => "Project", ], "project.write" => [ "description" => "Access to update project\'s information", + "category" => "Project", ], "keys.read" => [ "description" => "Access to read project\'s keys", + "category" => "Project", ], "keys.write" => [ "description" => "Access to create, update, and delete project\'s keys", + "category" => "Project", ], "platforms.read" => [ "description" => "Access to read project\'s platforms", + "category" => "Project", ], "platforms.write" => [ "description" => "Access to create, update, and delete project\'s platforms", + "category" => "Project", ], "mocks.read" => [ "description" => "Access to read project\'s mocks", + "category" => "Project", ], "mocks.write" => [ "description" => "Access to create, update, and delete project\'s mocks", + "category" => "Project", ], "policies.read" => [ "description" => "Access to read project\'s policies", + "category" => "Project", ], "policies.write" => [ "description" => "Access to update project\'s policies", + "category" => "Project", ], "templates.read" => [ "description" => "Access to read project\'s templates", + "category" => "Project", ], "templates.write" => [ "description" => "Access to create, update, and delete project\'s templates", + "category" => "Project", ], "oauth2.read" => [ "description" => "Access to read project\'s OAuth2 configuration", + "category" => "Project", ], "oauth2.write" => [ "description" => "Access to update project\'s OAuth2 configuration", + "category" => "Project", ], + + // Auth + 'users.read' => [ + 'description' => 'Access to read users', + 'category' => 'Auth', + ], + 'users.write' => [ + 'description' => 'Access to create, update, and delete users', + 'category' => 'Auth', + ], + 'sessions.read' => [ + 'description' => 'Access to read user sessions', + 'category' => 'Auth', + ], + 'sessions.write' => [ + 'description' => 'Access to create, update, and delete user sessions', + 'category' => 'Auth', + ], + 'teams.read' => [ + 'description' => 'Access to read teams', + 'category' => 'Auth', + ], + 'teams.write' => [ + 'description' => 'Access to create, update, and delete teams', + 'category' => 'Auth', + ], + + // Databases + 'databases.read' => [ + 'description' => 'Access to read databases', + 'category' => 'Databases', + ], + 'databases.write' => [ + 'description' => 'Access to create, update, and delete databases', + 'category' => 'Databases', + ], + 'tables.read' => [ + 'description' => 'Access to read database tables', + 'category' => 'Databases', + ], + 'tables.write' => [ + 'description' => 'Access to create, update, and delete database tables', + 'category' => 'Databases', + ], + 'columns.read' => [ + 'description' => 'Access to read database table columns', + 'category' => 'Databases', + ], + 'columns.write' => [ + 'description' => 'Access to create, update, and delete database table columns', + 'category' => 'Databases', + ], + 'indexes.read' => [ + 'description' => 'Access to read database table indexes', + 'category' => 'Databases', + ], + 'indexes.write' => [ + 'description' => 'Access to create, update, and delete database table indexes', + 'category' => 'Databases', + ], + 'rows.read' => [ + 'description' => 'Access to read database table rows', + 'category' => 'Databases', + ], + 'rows.write' => [ + 'description' => 'Access to create, update, and delete database table rows', + 'category' => 'Databases', + ], + 'collections.read' => [ + 'description' => 'Access to read database collections', + 'category' => 'Databases', + 'deprecated' => true, + ], + 'collections.write' => [ + 'description' => 'Access to create, update, and delete database collections', + 'category' => 'Databases', + 'deprecated' => true, + ], + 'attributes.read' => [ + 'description' => 'Access to read database collection attributes', + 'category' => 'Databases', + 'deprecated' => true, + ], + 'attributes.write' => [ + 'description' => 'Access to create, update, and delete database collection attributes', + 'category' => 'Databases', + 'deprecated' => true, + ], + 'documents.read' => [ + 'description' => 'Access to read database collection documents', + 'category' => 'Databases', + 'deprecated' => true, + ], + 'documents.write' => [ + 'description' => 'Access to create, update, and delete database collection\ documents', + 'category' => 'Databases', + 'deprecated' => true, + ], + + // Storage + 'buckets.read' => [ + 'description' => 'Access to read storage buckets', + 'category' => 'Storage', + ], + 'buckets.write' => [ + 'description' => 'Access to create, update, and delete storage buckets', + 'category' => 'Storage', + ], + 'files.read' => [ + 'description' => 'Access to read storage files and preview images', + 'category' => 'Storage', + ], + 'files.write' => [ + 'description' => 'Access to create, update, and delete storage files', + 'category' => 'Storage', + ], + 'tokens.read' => [ + 'description' => 'Access to read storage file tokens', + 'category' => 'Storage', + ], + 'tokens.write' => [ + 'description' => 'Access to create, update, and delete storage file tokens', + 'category' => 'Storage', + ], + + // Functions + 'functions.read' => [ + 'description' => 'Access to read functions and deployments', + 'category' => 'Functions', + ], + 'functions.write' => [ + 'description' => 'Access to create, update, and delete functions and deployments', + 'category' => 'Functions', + ], + 'executions.read' => [ + 'description' => 'Access to read function executions', + 'category' => 'Functions', + ], + 'executions.write' => [ + 'description' => 'Access to create function executions', + 'category' => 'Functions', + ], + + // Sites + 'sites.read' => [ + 'description' => 'Access to read sites and deployments', + 'category' => 'Sites', + ], + 'sites.write' => [ + 'description' => 'Access to create, update, and delete sites and deployments', + 'category' => 'Sites', + ], + 'log.read' => [ + 'description' => 'Access to read site logs', + 'category' => 'Sites', + ], + 'log.write' => [ + 'description' => 'Access to update, and delete site logs', + 'category' => 'Sites', + ], + + // Messaging + 'providers.read' => [ + 'description' => 'Access to read messaging providers', + 'category' => 'Messaging', + ], + 'providers.write' => [ + 'description' => 'Access to create, update, and delete messaging providers', + 'category' => 'Messaging', + ], + 'topics.read' => [ + 'description' => 'Access to read messaging topics', + 'category' => 'Messaging', + ], + 'topics.write' => [ + 'description' => 'Access to create, update, and delete messaging topics', + 'category' => 'Messaging', + ], + 'subscribers.read' => [ + 'description' => 'Access to read messaging subscribers', + 'category' => 'Messaging', + ], + 'subscribers.write' => [ + 'description' => 'Access to create, update, and delete messaging subscribers', + 'category' => 'Messaging', + ], + 'targets.read' => [ + 'description' => 'Access to read messaging targets', + 'category' => 'Messaging', + ], + 'targets.write' => [ + 'description' => 'Access to create, update, and delete messaging targets', + 'category' => 'Messaging', + ], + 'messages.read' => [ + 'description' => 'Access to read messaging messages', + 'category' => 'Messaging', + ], + 'messages.write' => [ + 'description' => 'Access to create, update, and delete messaging messages', + 'category' => 'Messaging', + ], + + // Proxy + 'rules.read' => [ + 'description' => 'Access to read proxy rules', + 'category' => 'Proxy', + ], + 'rules.write' => [ + 'description' => 'Access to create, update, and delete proxy rules', + 'category' => 'Proxy', + ], + + // TODO: VCS + + // Other + "webhooks.read" => [ + "description" => + "Access to read webhooks", + 'category' => 'Other', + ], + "webhooks.write" => [ + "description" => + "Access to create, update, and delete webhooks", + 'category' => 'Other', + ], + 'locale.read' => [ + 'description' => 'Access to use Locale service', + 'category' => 'Other', + ], + 'avatars.read' => [ + 'description' => 'Access to use Avatars service', + 'category' => 'Other', + ], + 'health.read' => [ + 'description' => 'Access to use Health service', + 'category' => 'Other', + ], + 'assistant.read' => [ + 'description' => 'Access to use Assistant service', + 'category' => 'Other', + ], + 'migrations.read' => [ + 'description' => 'Access to read migrations', + 'category' => 'Other', + ], + 'migrations.write' => [ + 'description' => 'Access to create, update, and delete migrations.', + 'category' => 'Other', + ], + // TODO: Figure out schedules.read, schedules.write ]; diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 1346812668..abcecac396 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -856,7 +856,7 @@ Http::get('/v1/users/:userId/targets/:targetId') Http::get('/v1/users/:userId/sessions') ->desc('List user sessions') ->groups(['api', 'users']) - ->label('scope', 'users.read') + ->label('scope', ['users.read', 'sessions.read']) ->label('sdk', new Method( namespace: 'users', group: 'sessions', @@ -2314,7 +2314,7 @@ Http::post('/v1/users/:userId/sessions') ->desc('Create session') ->groups(['api', 'users']) ->label('event', 'users.[userId].sessions.[sessionId].create') - ->label('scope', 'users.write') + ->label('scope', ['users.write', 'sessions.write']) ->label('audits.event', 'session.create') ->label('audits.resource', 'user/{request.userId}') ->label('usage.metric', 'sessions.{scope}.requests.create') @@ -2470,7 +2470,7 @@ Http::delete('/v1/users/:userId/sessions/:sessionId') ->desc('Delete user session') ->groups(['api', 'users']) ->label('event', 'users.[userId].sessions.[sessionId].delete') - ->label('scope', 'users.write') + ->label('scope', ['users.write', 'sessions.write']) ->label('audits.event', 'session.delete') ->label('audits.resource', 'user/{request.userId}') ->label('sdk', new Method( @@ -2521,7 +2521,7 @@ Http::delete('/v1/users/:userId/sessions') ->desc('Delete user sessions') ->groups(['api', 'users']) ->label('event', 'users.[userId].sessions.delete') - ->label('scope', 'users.write') + ->label('scope', ['users.write', 'sessions.write']) ->label('audits.event', 'session.delete') ->label('audits.resource', 'user/{user.$id}') ->label('sdk', new Method( diff --git a/src/Appwrite/Platform/Modules/Console/Http/Scopes/Key/XList.php b/src/Appwrite/Platform/Modules/Console/Http/Scopes/Key/XList.php index 255a7583bb..d951e93886 100644 --- a/src/Appwrite/Platform/Modules/Console/Http/Scopes/Key/XList.php +++ b/src/Appwrite/Platform/Modules/Console/Http/Scopes/Key/XList.php @@ -18,21 +18,21 @@ class XList extends Action public static function getName(): string { - return 'listKeyScopes'; + return 'listConsoleProjectScopes'; } public function __construct() { $this ->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) - ->setHttpPath('/v1/console/scopes/key') - ->desc('List key scopes') + ->setHttpPath('/v1/console/scopes/project') + ->desc('List project scopes') ->groups(['api']) ->label('scope', 'public') ->label('sdk', new Method( namespace: 'console', group: 'console', - name: 'listKeyScopes', + name: 'listProjectScopes', description: 'List all scopes available for project API keys, along with a description for each scope.', auth: [AuthType::ADMIN], responses: [ @@ -56,6 +56,8 @@ class XList extends Action $scopes[] = new Document([ '$id' => $scopeId, 'description' => $scope['description'] ?? '', + 'category' => $scope['category'] ?? '', + 'deprecated' => $scope['deprecated'] ?? false, ]); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index 4bf2fbc48f..9f15cf9d1e 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -60,7 +60,7 @@ class Create extends Base ->setHttpPath('/v1/functions/:functionId/executions') ->desc('Create execution') ->groups(['api', 'functions']) - ->label('scope', 'execution.write') + ->label('scope', ['executions.write', 'execution.write']) ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('event', 'functions.[functionId].executions.[executionId].create') ->label('sdk', new Method( diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Delete.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Delete.php index 21ec3c66ce..9ecb5c0bf0 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Delete.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Delete.php @@ -35,7 +35,7 @@ class Delete extends Base ->setHttpPath('/v1/functions/:functionId/executions/:executionId') ->desc('Delete execution') ->groups(['api', 'functions']) - ->label('scope', 'execution.write') + ->label('scope', ['executions.write', 'execution.write']) ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('event', 'functions.[functionId].executions.[executionId].delete') ->label('audits.event', 'executions.delete') diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php index aec9d56543..0a9dd01b7e 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php @@ -31,7 +31,7 @@ class Get extends Base ->setHttpPath('/v1/functions/:functionId/executions/:executionId') ->desc('Get execution') ->groups(['api', 'functions']) - ->label('scope', 'execution.read') + ->label('scope', ['executions.read', 'execution.read']) ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php index b12980b222..6ad2a5ae55 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php @@ -39,7 +39,7 @@ class XList extends Base ->setHttpPath('/v1/functions/:functionId/executions') ->desc('List executions') ->groups(['api', 'functions']) - ->label('scope', 'execution.read') + ->label('scope', ['executions.read', 'execution.read']) ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) ->label('sdk', new Method( namespace: 'functions', diff --git a/src/Appwrite/Utopia/Response/Model/ConsoleKeyScope.php b/src/Appwrite/Utopia/Response/Model/ConsoleKeyScope.php index 4932707d21..224d114271 100644 --- a/src/Appwrite/Utopia/Response/Model/ConsoleKeyScope.php +++ b/src/Appwrite/Utopia/Response/Model/ConsoleKeyScope.php @@ -22,6 +22,18 @@ class ConsoleKeyScope extends Model 'default' => '', 'example' => 'Access to read your project\'s users', ]) + ->addRule('category', [ + 'type' => self::TYPE_STRING, + 'description' => 'Scope category.', + 'default' => '', + 'example' => 'Auth', + ]) + ->addRule('deprecated', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Scope is deprecated.', + 'default' => false, + 'example' => true, + ]) ; } diff --git a/tests/benchmarks/bulk-operations/utils.js b/tests/benchmarks/bulk-operations/utils.js index dc8dcac569..5b8bbc6c67 100644 --- a/tests/benchmarks/bulk-operations/utils.js +++ b/tests/benchmarks/bulk-operations/utils.js @@ -197,8 +197,8 @@ const SCOPES = [ "buckets.write", "functions.read", "functions.write", - "execution.read", - "execution.write", + "executions.read", + "executions.write", "targets.read", "targets.write", "providers.read", diff --git a/tests/benchmarks/http.js b/tests/benchmarks/http.js index 6466ffd361..f7bb54024d 100644 --- a/tests/benchmarks/http.js +++ b/tests/benchmarks/http.js @@ -75,8 +75,8 @@ const API_SCOPES = [ 'functions.write', 'log.read', 'log.write', - 'execution.read', - 'execution.write', + 'executions.read', + 'executions.write', 'locale.read', 'avatars.read', 'rules.read', diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index 31d85524af..3071ddfa2a 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -137,8 +137,8 @@ trait ProjectCustom 'functions.write', 'sites.read', 'sites.write', - 'execution.read', - 'execution.write', + 'executions.read', + 'executions.write', 'log.read', 'log.write', 'locale.read', diff --git a/tests/e2e/Services/Projects/Schedules/SchedulesBase.php b/tests/e2e/Services/Projects/Schedules/SchedulesBase.php index 681e39b662..4baaca4e5b 100644 --- a/tests/e2e/Services/Projects/Schedules/SchedulesBase.php +++ b/tests/e2e/Services/Projects/Schedules/SchedulesBase.php @@ -62,8 +62,8 @@ trait SchedulesBase 'scopes' => [ 'functions.read', 'functions.write', - 'execution.read', - 'execution.write', + 'executions.read', + 'executions.write', 'messages.read', 'messages.write', ], From e010bf25d5a09a8bdb5b330134e70c3f9e28f7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 29 Apr 2026 13:57:16 +0200 Subject: [PATCH 073/211] Fix formatting --- app/config/scopes/project.php | 44 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/app/config/scopes/project.php b/app/config/scopes/project.php index 64eb1836b5..aa6752967d 100644 --- a/app/config/scopes/project.php +++ b/app/config/scopes/project.php @@ -11,67 +11,67 @@ return [ "project.write" => [ "description" => "Access to update project\'s information", - "category" => "Project", + "category" => "Project", ], "keys.read" => [ "description" => "Access to read project\'s keys", - "category" => "Project", + "category" => "Project", ], "keys.write" => [ "description" => "Access to create, update, and delete project\'s keys", - "category" => "Project", + "category" => "Project", ], "platforms.read" => [ "description" => "Access to read project\'s platforms", - "category" => "Project", + "category" => "Project", ], "platforms.write" => [ "description" => "Access to create, update, and delete project\'s platforms", - "category" => "Project", + "category" => "Project", ], "mocks.read" => [ "description" => "Access to read project\'s mocks", - "category" => "Project", + "category" => "Project", ], "mocks.write" => [ "description" => "Access to create, update, and delete project\'s mocks", - "category" => "Project", + "category" => "Project", ], "policies.read" => [ "description" => "Access to read project\'s policies", - "category" => "Project", + "category" => "Project", ], "policies.write" => [ "description" => "Access to update project\'s policies", - "category" => "Project", + "category" => "Project", ], "templates.read" => [ "description" => "Access to read project\'s templates", - "category" => "Project", + "category" => "Project", ], "templates.write" => [ "description" => "Access to create, update, and delete project\'s templates", - "category" => "Project", + "category" => "Project", ], "oauth2.read" => [ "description" => "Access to read project\'s OAuth2 configuration", - "category" => "Project", + "category" => "Project", ], "oauth2.write" => [ "description" => "Access to update project\'s OAuth2 configuration", - "category" => "Project", + "category" => "Project", ], // Auth @@ -99,7 +99,7 @@ return [ 'description' => 'Access to create, update, and delete teams', 'category' => 'Auth', ], - + // Databases 'databases.read' => [ 'description' => 'Access to read databases', @@ -197,7 +197,7 @@ return [ 'description' => 'Access to create, update, and delete storage file tokens', 'category' => 'Storage', ], - + // Functions 'functions.read' => [ 'description' => 'Access to read functions and deployments', @@ -215,7 +215,7 @@ return [ 'description' => 'Access to create function executions', 'category' => 'Functions', ], - + // Sites 'sites.read' => [ 'description' => 'Access to read sites and deployments', @@ -233,7 +233,7 @@ return [ 'description' => 'Access to update, and delete site logs', 'category' => 'Sites', ], - + // Messaging 'providers.read' => [ 'description' => 'Access to read messaging providers', @@ -275,7 +275,7 @@ return [ 'description' => 'Access to create, update, and delete messaging messages', 'category' => 'Messaging', ], - + // Proxy 'rules.read' => [ 'description' => 'Access to read proxy rules', @@ -285,19 +285,19 @@ return [ 'description' => 'Access to create, update, and delete proxy rules', 'category' => 'Proxy', ], - + // TODO: VCS - + // Other "webhooks.read" => [ "description" => "Access to read webhooks", - 'category' => 'Other', + 'category' => 'Other', ], "webhooks.write" => [ "description" => "Access to create, update, and delete webhooks", - 'category' => 'Other', + 'category' => 'Other', ], 'locale.read' => [ 'description' => 'Access to use Locale service', From b3e3b2a330b8f1180d6f524c8d26068b637a148d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 29 Apr 2026 14:00:14 +0200 Subject: [PATCH 074/211] Fix missing index scopes --- .../Modules/Databases/Http/TablesDB/Tables/Indexes/Create.php | 2 +- .../Modules/Databases/Http/TablesDB/Tables/Indexes/Delete.php | 2 +- .../Modules/Databases/Http/TablesDB/Tables/Indexes/Get.php | 2 +- .../Modules/Databases/Http/TablesDB/Tables/Indexes/XList.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) 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 e683aafba1..d377bed184 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 @@ -37,7 +37,7 @@ class Create extends IndexCreate ->desc('Create index') ->groups(['api', 'database']) ->label('event', 'databases.[databaseId].tables.[tableId].indexes.[indexId].create') - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'indexes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('audits.event', 'index.create') ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Delete.php index 7750408e29..ca7e4fc2da 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Delete.php @@ -36,7 +36,7 @@ class Delete extends IndexDelete ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/indexes/:key') ->desc('Delete index') ->groups(['api', 'database']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'indexes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].indexes.[indexId].update') ->label('audits.event', 'index.delete') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Get.php index 8f721abf0e..9918bcb2b8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Get.php @@ -32,7 +32,7 @@ class Get extends IndexGet ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/indexes/:key') ->desc('Get index') ->groups(['api', 'database']) - ->label('scope', ['tables.read', 'collections.read']) + ->label('scope', ['tables.read', 'collections.read', 'indexes.read']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/XList.php index ff1e736c31..5fe3be4c05 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/XList.php @@ -33,7 +33,7 @@ class XList extends IndexXList ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/indexes') ->desc('List indexes') ->groups(['api', 'database']) - ->label('scope', ['tables.read', 'collections.read']) + ->label('scope', ['tables.read', 'collections.read', 'indexes.read']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), From 4d86e670068c4dc4b63596a2ffa6ecc84080d09f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 29 Apr 2026 14:03:44 +0200 Subject: [PATCH 075/211] Fix missing scopes for tables --- app/config/scopes/project.php | 14 +------------- .../TablesDB/Tables/Columns/Boolean/Create.php | 2 +- .../TablesDB/Tables/Columns/Boolean/Update.php | 2 +- .../TablesDB/Tables/Columns/Datetime/Create.php | 2 +- .../TablesDB/Tables/Columns/Datetime/Update.php | 2 +- .../Http/TablesDB/Tables/Columns/Delete.php | 2 +- .../Http/TablesDB/Tables/Columns/Email/Create.php | 2 +- .../Http/TablesDB/Tables/Columns/Email/Update.php | 2 +- .../Http/TablesDB/Tables/Columns/Enum/Create.php | 2 +- .../Http/TablesDB/Tables/Columns/Enum/Update.php | 2 +- .../Http/TablesDB/Tables/Columns/Float/Create.php | 2 +- .../Http/TablesDB/Tables/Columns/Float/Update.php | 2 +- .../Databases/Http/TablesDB/Tables/Columns/Get.php | 2 +- .../Http/TablesDB/Tables/Columns/IP/Create.php | 2 +- .../Http/TablesDB/Tables/Columns/IP/Update.php | 2 +- .../TablesDB/Tables/Columns/Integer/Create.php | 2 +- .../TablesDB/Tables/Columns/Integer/Update.php | 2 +- .../Http/TablesDB/Tables/Columns/Line/Create.php | 2 +- .../Http/TablesDB/Tables/Columns/Line/Update.php | 2 +- .../TablesDB/Tables/Columns/Longtext/Create.php | 2 +- .../TablesDB/Tables/Columns/Longtext/Update.php | 2 +- .../TablesDB/Tables/Columns/Mediumtext/Create.php | 2 +- .../TablesDB/Tables/Columns/Mediumtext/Update.php | 2 +- .../Http/TablesDB/Tables/Columns/Point/Create.php | 2 +- .../Http/TablesDB/Tables/Columns/Point/Update.php | 2 +- .../TablesDB/Tables/Columns/Polygon/Create.php | 2 +- .../TablesDB/Tables/Columns/Polygon/Update.php | 2 +- .../Tables/Columns/Relationship/Create.php | 2 +- .../Tables/Columns/Relationship/Update.php | 2 +- .../Http/TablesDB/Tables/Columns/String/Create.php | 2 +- .../Http/TablesDB/Tables/Columns/String/Update.php | 2 +- .../Http/TablesDB/Tables/Columns/Text/Create.php | 2 +- .../Http/TablesDB/Tables/Columns/Text/Update.php | 2 +- .../Http/TablesDB/Tables/Columns/URL/Create.php | 2 +- .../Http/TablesDB/Tables/Columns/URL/Update.php | 2 +- .../TablesDB/Tables/Columns/Varchar/Create.php | 2 +- .../TablesDB/Tables/Columns/Varchar/Update.php | 2 +- .../Http/TablesDB/Tables/Columns/XList.php | 2 +- 38 files changed, 38 insertions(+), 50 deletions(-) diff --git a/app/config/scopes/project.php b/app/config/scopes/project.php index aa6752967d..c9c8786f38 100644 --- a/app/config/scopes/project.php +++ b/app/config/scopes/project.php @@ -276,18 +276,6 @@ return [ 'category' => 'Messaging', ], - // Proxy - 'rules.read' => [ - 'description' => 'Access to read proxy rules', - 'category' => 'Proxy', - ], - 'rules.write' => [ - 'description' => 'Access to create, update, and delete proxy rules', - 'category' => 'Proxy', - ], - - // TODO: VCS - // Other "webhooks.read" => [ "description" => @@ -323,5 +311,5 @@ return [ 'description' => 'Access to create, update, and delete migrations.', 'category' => 'Other', ], - // TODO: Figure out schedules.read, schedules.write + // TODO: Figure out schedules.read, schedules.write. Remove, likely ]; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Boolean/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Boolean/Create.php index ddfb023d25..10cd65bc98 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Boolean/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Boolean/Create.php @@ -34,7 +34,7 @@ class Create extends BooleanCreate ->desc('Create boolean column') ->groups(['api', 'database', 'schema']) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/Boolean/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Boolean/Update.php index c808021796..1e0fe04bdc 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Boolean/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Boolean/Update.php @@ -34,7 +34,7 @@ class Update extends BooleanUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/boolean/:key') ->desc('Update boolean column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/Datetime/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Datetime/Create.php index 0698002f61..64e73e310e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Datetime/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Datetime/Create.php @@ -34,7 +34,7 @@ class Create extends DatetimeCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/datetime') ->desc('Create datetime column') ->groups(['api', 'database']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Datetime/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Datetime/Update.php index 035893f33f..44c1a06da8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Datetime/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Datetime/Update.php @@ -35,7 +35,7 @@ class Update extends DatetimeUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/datetime/:key') ->desc('Update dateTime column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Delete.php index 81e71df07a..f4d606637d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Delete.php @@ -33,7 +33,7 @@ class Delete extends AttributesDelete ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/:key') ->desc('Delete column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].update') ->label('audits.event', 'column.delete') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Email/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Email/Create.php index b0e81ed6b7..d0b2ed3e4b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Email/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Email/Create.php @@ -34,7 +34,7 @@ class Create extends EmailCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/email') ->desc('Create email column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Email/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Email/Update.php index d1278376c1..c116d8c5b1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Email/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Email/Update.php @@ -35,7 +35,7 @@ class Update extends EmailUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/email/:key') ->desc('Update email column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/Enum/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Enum/Create.php index 9aeb9b2d4b..e58ae115fc 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Enum/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Enum/Create.php @@ -35,7 +35,7 @@ class Create extends EnumCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/enum') ->desc('Create enum column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Enum/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Enum/Update.php index 43503ee8ed..208fa9c8cf 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Enum/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Enum/Update.php @@ -36,7 +36,7 @@ class Update extends EnumUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/enum/:key') ->desc('Update enum column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/Float/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Float/Create.php index 0dd0ef39e1..b8e81820aa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Float/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Float/Create.php @@ -34,7 +34,7 @@ class Create extends FloatCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/float') ->desc('Create float column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Float/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Float/Update.php index 716923cc63..9ab61e642b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Float/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Float/Update.php @@ -35,7 +35,7 @@ class Update extends FloatUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/float/:key') ->desc('Update float column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Get.php index 0fe5fa062a..b0ef9e8a85 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Get.php @@ -42,7 +42,7 @@ class Get extends AttributesGet ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/:key') ->desc('Get column') ->groups(['api', 'database']) - ->label('scope', ['tables.read', 'collections.read']) + ->label('scope', ['tables.read', 'collections.read', 'columns.read', 'attributes.read']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/IP/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/IP/Create.php index c359feaab4..c2faec9aeb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/IP/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/IP/Create.php @@ -34,7 +34,7 @@ class Create extends IPCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/ip') ->desc('Create IP address column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/IP/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/IP/Update.php index 0c7cc6644b..dcc4160580 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/IP/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/IP/Update.php @@ -35,7 +35,7 @@ class Update extends IPUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/ip/:key') ->desc('Update IP address column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/Integer/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Integer/Create.php index bbb1710866..1a965c19dc 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Integer/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Integer/Create.php @@ -34,7 +34,7 @@ class Create extends IntegerCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/integer') ->desc('Create integer column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Integer/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Integer/Update.php index a9348f51e0..58dea7c848 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Integer/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Integer/Update.php @@ -35,7 +35,7 @@ class Update extends IntegerUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/integer/:key') ->desc('Update integer column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php index fb2c4fd1a8..c2f480d5d0 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 @@ -35,7 +35,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', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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 564b743a2a..e2e8c59121 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 @@ -35,7 +35,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', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/Longtext/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Longtext/Create.php index da9471f37c..8e2dbd911d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Longtext/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Longtext/Create.php @@ -33,7 +33,7 @@ class Create extends LongtextCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/longtext') ->desc('Create longtext column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Longtext/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Longtext/Update.php index fe93530cfb..9b90b745a2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Longtext/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Longtext/Update.php @@ -34,7 +34,7 @@ class Update extends LongtextUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/longtext/:key') ->desc('Update longtext column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/Mediumtext/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Mediumtext/Create.php index 585856cab9..f0b8099f02 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Mediumtext/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Mediumtext/Create.php @@ -33,7 +33,7 @@ class Create extends MediumtextCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/mediumtext') ->desc('Create mediumtext column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Mediumtext/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Mediumtext/Update.php index 733159d1d4..03009da25c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Mediumtext/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Mediumtext/Update.php @@ -34,7 +34,7 @@ class Update extends MediumtextUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/mediumtext/:key') ->desc('Update mediumtext column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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 9736e33158..138ee482c3 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 @@ -35,7 +35,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', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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 f104b170bd..66fb451a1f 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 @@ -35,7 +35,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', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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 177399396c..a03a34f310 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 @@ -35,7 +35,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', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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 e66e19a7b9..7a2fd8a5de 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 @@ -35,7 +35,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', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Relationship/Create.php index 84ee3e6863..87544926fe 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Relationship/Create.php @@ -34,7 +34,7 @@ class Create extends RelationshipCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/relationship') ->desc('Create relationship column') ->groups(['api', 'database']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Relationship/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Relationship/Update.php index da5c8ca477..47884eda80 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Relationship/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Relationship/Update.php @@ -34,7 +34,7 @@ class Update extends RelationshipUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/:key/relationship') ->desc('Update relationship column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/String/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/String/Create.php index 122c8625f9..17f60f61c1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/String/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/String/Create.php @@ -37,7 +37,7 @@ class Create extends StringCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/string') ->desc('Create string column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/String/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/String/Update.php index 0974a44d5d..2ec806d4fe 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/String/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/String/Update.php @@ -37,7 +37,7 @@ class Update extends StringUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/string/:key') ->desc('Update string column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/Text/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Text/Create.php index 2c68431d8c..a8fde7d271 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Text/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Text/Create.php @@ -33,7 +33,7 @@ class Create extends TextCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/text') ->desc('Create text column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Text/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Text/Update.php index 599c93988d..4c1477fb9e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Text/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Text/Update.php @@ -34,7 +34,7 @@ class Update extends TextUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/text/:key') ->desc('Update text column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/URL/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/URL/Create.php index 0b386c23f6..19b33594b7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/URL/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/URL/Create.php @@ -34,7 +34,7 @@ class Create extends URLCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/url') ->desc('Create URL column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/URL/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/URL/Update.php index df6117ea77..d680389d9e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/URL/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/URL/Update.php @@ -35,7 +35,7 @@ class Update extends URLUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/url/:key') ->desc('Update URL column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/Varchar/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Varchar/Create.php index 0ee04f5f63..7595f16c45 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Varchar/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Varchar/Create.php @@ -35,7 +35,7 @@ class Create extends VarcharCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/varchar') ->desc('Create varchar column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Varchar/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Varchar/Update.php index 2b8eb9fbd7..dd170a0a19 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Varchar/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Varchar/Update.php @@ -36,7 +36,7 @@ class Update extends VarcharUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/varchar/:key') ->desc('Update varchar column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.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/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/XList.php index b38edf6218..56c436a13e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/XList.php @@ -33,7 +33,7 @@ class XList extends AttributesXList ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns') ->desc('List columns') ->groups(['api', 'database']) - ->label('scope', ['tables.read', 'collections.read']) + ->label('scope', ['tables.read', 'collections.read', 'columns.read', 'attributes.read']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: $this->getSDKNamespace(), From e1b8f5bf98bf30319714b9374723e1e3901076a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 29 Apr 2026 14:04:54 +0200 Subject: [PATCH 076/211] review improvements --- app/config/scopes/project.php | 2 +- .../Modules/Project/Http/Project/Keys/Ephemeral/Create.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/config/scopes/project.php b/app/config/scopes/project.php index c9c8786f38..934a08b9ac 100644 --- a/app/config/scopes/project.php +++ b/app/config/scopes/project.php @@ -167,7 +167,7 @@ return [ 'deprecated' => true, ], 'documents.write' => [ - 'description' => 'Access to create, update, and delete database collection\ documents', + 'description' => 'Access to create, update, and delete database collection documents', 'category' => 'Databases', 'deprecated' => true, ], diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php index 1d4b625343..7fdefca218 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php @@ -59,7 +59,7 @@ class Create extends Base ], )) ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.', optional: false) - ->param('duration', null, new Range(1, 3600), 'Time in seconds before ephemeral key expires. Default duration is 900 seconds, and maximum is 3600 seconds.', optional: false) + ->param('duration', null, new Range(1, 3600), 'Time in seconds before ephemeral key expires. Maximum duration is 3600 seconds.', optional: false) ->inject('response') ->inject('queueForEvents') ->inject('project') From 32ebfc6cb8838743d718387d496a66071b3ec20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 29 Apr 2026 14:14:49 +0200 Subject: [PATCH 077/211] Fix backwards compatibility --- app/config/scopes/project.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/config/scopes/project.php b/app/config/scopes/project.php index 934a08b9ac..63b946f74f 100644 --- a/app/config/scopes/project.php +++ b/app/config/scopes/project.php @@ -311,5 +311,30 @@ return [ 'description' => 'Access to create, update, and delete migrations.', 'category' => 'Other', ], - // TODO: Figure out schedules.read, schedules.write. Remove, likely + + // TODO: Figure out where to move those + 'schedules.read' => [ + 'description' => 'Access to read schedules.', + 'category' => 'Other', + ], + 'schedules.write' => [ + 'description' => 'Access to create, update, and delete schedules.', + 'category' => 'Other', + ], + 'vcs.read' => [ + 'description' => 'Access to read resources under VCS service.', + 'category' => 'Other', + ], + 'vcs.write' => [ + 'description' => 'Access to create, update, and delete resources under VCS service.', + 'category' => 'Other', + ], + 'rules.read' => [ + 'description' => 'Access to read proxy rules.', + 'category' => 'Other', + ], + 'rules.write' => [ + 'description' => 'Access to create, update, and delete proxy rules.', + 'category' => 'Other', + ], ]; From 794d8eac5b57e0d496917138aed0da18543dbb8c Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 29 Apr 2026 17:55:06 +0530 Subject: [PATCH 078/211] Fix project delete platform cleanup ordering --- src/Appwrite/Platform/Workers/Deletes.php | 102 +++++++++++----------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 8f5397f630..23ea6934ab 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -633,6 +633,57 @@ class Deletes extends Action $dsn = new DSN('mysql://' . $document->getAttribute('database', 'console')); } + // Delete Platforms + $this->deleteByGroup('platforms', [ + Query::equal('projectInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform); + + // Delete project and function rules + $this->deleteByGroup('rules', [ + Query::equal('projectInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform, function (Document $document) use ($dbForPlatform, $certificates) { + $this->deleteRule($dbForPlatform, $document, $certificates); + }); + + // Delete Keys + $this->deleteByGroup('keys', [ + Query::equal('resourceType', ['projects']), + Query::equal('resourceInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform); + + // Delete Webhooks + $this->deleteByGroup('webhooks', [ + Query::equal('projectInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform); + + // Delete VCS Installations + $this->deleteByGroup('installations', [ + Query::equal('projectInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform); + + // Delete VCS Repositories + $this->deleteByGroup('repositories', [ + Query::equal('projectInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform); + + // Delete VCS comments + $this->deleteByGroup('vcsComments', [ + Query::equal('projectInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform); + + // Delete Schedules + $this->deleteByGroup('schedules', [ + Query::equal('projectId', [$projectId]), + Query::orderAsc() + ], $dbForPlatform); + /** * @var Database $dbForProject */ @@ -694,57 +745,6 @@ class Deletes extends Action $databasesToClean )); - // Delete Platforms - $this->deleteByGroup('platforms', [ - Query::equal('projectInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform); - - // Delete project and function rules - $this->deleteByGroup('rules', [ - Query::equal('projectInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform, function (Document $document) use ($dbForPlatform, $certificates) { - $this->deleteRule($dbForPlatform, $document, $certificates); - }); - - // Delete Keys - $this->deleteByGroup('keys', [ - Query::equal('resourceType', ['projects']), - Query::equal('resourceInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform); - - // Delete Webhooks - $this->deleteByGroup('webhooks', [ - Query::equal('projectInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform); - - // Delete VCS Installations - $this->deleteByGroup('installations', [ - Query::equal('projectInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform); - - // Delete VCS Repositories - $this->deleteByGroup('repositories', [ - Query::equal('projectInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform); - - // Delete VCS comments - $this->deleteByGroup('vcsComments', [ - Query::equal('projectInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform); - - // Delete Schedules - $this->deleteByGroup('schedules', [ - Query::equal('projectId', [$projectId]), - Query::orderAsc() - ], $dbForPlatform); - // Delete metadata table if ($projectTables) { batch(array_map( From 36486ccc934e914b01c457ece547d1733444dbf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 29 Apr 2026 14:41:19 +0200 Subject: [PATCH 079/211] Fix tests --- .../Services/Console/ConsoleConsoleClientTest.php | 6 ++++-- .../Services/Console/ConsoleCustomServerTest.php | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php index e4566837e9..8235ebb7bc 100644 --- a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php +++ b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php @@ -131,7 +131,7 @@ class ConsoleConsoleClientTest extends Scope public function testListKeyScopes(): void { - $response = $this->client->call(Client::METHOD_GET, '/console/scopes/key', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/console/scopes/project', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -158,6 +158,8 @@ class ConsoleConsoleClientTest extends Scope $this->assertArrayHasKey('description', $scope); $this->assertIsString($scope['description']); $this->assertNotEmpty($scope['description']); + $this->assertArrayHasKey('deprecated', $scope); + $this->assertIsBool($scope['deprecated']); } // A specific scope has the expected description @@ -169,6 +171,6 @@ class ConsoleConsoleClientTest extends Scope } } $this->assertNotNull($usersRead); - $this->assertEquals('Access to read your project\'s users', $usersRead['description']); + $this->assertEquals('Access to read users', $usersRead['description']); } } diff --git a/tests/e2e/Services/Console/ConsoleCustomServerTest.php b/tests/e2e/Services/Console/ConsoleCustomServerTest.php index 0c914fade7..f06011843f 100644 --- a/tests/e2e/Services/Console/ConsoleCustomServerTest.php +++ b/tests/e2e/Services/Console/ConsoleCustomServerTest.php @@ -48,7 +48,7 @@ class ConsoleCustomServerTest extends Scope { // Public endpoint: must succeed without admin authentication. Drop the // headers from getHeaders() and only pass project + content-type. - $response = $this->client->call(Client::METHOD_GET, '/console/scopes/key', [ + $response = $this->client->call(Client::METHOD_GET, '/console/scopes/project', [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]); @@ -60,5 +60,18 @@ class ConsoleCustomServerTest extends Scope $scopeIds = \array_column($response['body']['scopes'], '$id'); $this->assertContains('users.read', $scopeIds); + + $usersRead = null; + foreach ($response['body']['scopes'] as $scope) { + if ($scope['$id'] === 'users.read') { + $usersRead = $scope; + break; + } + } + $this->assertNotNull($usersRead); + $this->assertIsString($usersRead['description']); + $this->assertNotEmpty($usersRead['description']); + $this->assertArrayHasKey('deprecated', $usersRead); + $this->assertIsBool($usersRead['deprecated']); } } From 7a9a2899ff32c785ffaa9583037128d28c696955 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 29 Apr 2026 15:41:56 +0300 Subject: [PATCH 080/211] setGlobalCollections --- app/cli.php | 24 ++++++++++++++++++- app/init/resources.php | 10 +++++++- app/init/resources/request.php | 35 ++++++++++++++++++++++++++- app/init/worker/message.php | 44 +++++++++++++++++++++++++++++++++- app/realtime.php | 6 +++++ 5 files changed, 115 insertions(+), 4 deletions(-) diff --git a/app/cli.php b/app/cli.php index a6267fa341..dd7c172cab 100644 --- a/app/cli.php +++ b/app/cli.php @@ -157,12 +157,19 @@ $container->set('getProjectDB', function (Group $pools, Database $dbForPlatform, } if (isset($databases[$dsn->getHost()])) { + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $projectCollections = $collections['projects'] ?? []; + $projectsGlobalCollections = array_keys($projectCollections); + $projectsGlobalCollections[] = 'audit'; + $database = $databases[$dsn->getHost()]; $sharedTables = \explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', '')); if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) + ->setGlobalCollections($projectsGlobalCollections) ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { @@ -182,9 +189,16 @@ $container->set('getProjectDB', function (Group $pools, Database $dbForPlatform, $sharedTables = \explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', '')); if (\in_array($dsn->getHost(), $sharedTables)) { + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $projectCollections = $collections['projects'] ?? []; + $projectsGlobalCollections = array_keys($projectCollections); + $projectsGlobalCollections[] = 'audit'; + $database ->setSharedTables(true) ->setTenant($project->getSequence()) + ->setGlobalCollections($projectsGlobalCollections) ->setNamespace($dsn->getParam('namespace')); } else { $database @@ -225,7 +239,15 @@ $container->set('getLogsDB', function (Group $pools, Cache $cache, Authorization // set tenant if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getSequence()); + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $logsCollections = $collections['logs'] ?? []; + $logsCollections = array_keys($logsCollections); + + $database + ->setTenant($project->getSequence()) + ->setGlobalCollections($logsCollections) + ; } return $database; diff --git a/app/init/resources.php b/app/init/resources.php index 29506bfc9c..12438c3fae 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -169,7 +169,15 @@ $container->set('getLogsDB', function (Group $pools, Cache $cache, Authorization // set tenant if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getSequence()); + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $logsCollections = $collections['logs'] ?? []; + $logsCollections = array_keys($logsCollections); + + $database + ->setTenant($project->getSequence()) + ->setGlobalCollections($logsCollections) + ; } return $database; diff --git a/app/init/resources/request.php b/app/init/resources/request.php index 1aa53b7403..ec2b24566f 100644 --- a/app/init/resources/request.php +++ b/app/init/resources/request.php @@ -204,9 +204,16 @@ return function (Container $container): void { $sharedTables = \explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', '')); if (\in_array($dsn->getHost(), $sharedTables)) { + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $projectCollections = $collections['projects'] ?? []; + $projectsGlobalCollections = array_keys($projectCollections); + $projectsGlobalCollections[] = 'audit'; + $database ->setSharedTables(true) ->setTenant($project->getSequence()) + ->setGlobalCollections($projectsGlobalCollections) ->setNamespace($dsn->getParam('namespace')); } else { $database @@ -235,7 +242,15 @@ return function (Container $container): void { ->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES); if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getSequence()); + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $logsCollections = $collections['logs'] ?? []; + $logsCollections = array_keys($logsCollections); + + $database + ->setTenant($project->getSequence()) + ->setGlobalCollections($logsCollections) + ; } return $database; @@ -690,8 +705,15 @@ return function (Container $container): void { $sharedTables = \explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', '')); if (\in_array($dsn->getHost(), $sharedTables)) { + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $projectCollections = $collections['projects'] ?? []; + $projectsGlobalCollections = array_keys($projectCollections); + $projectsGlobalCollections[] = 'audit'; + $database ->setSharedTables(true) + ->setGlobalCollections($projectsGlobalCollections) ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { @@ -1338,6 +1360,17 @@ return function (Container $container): void { $database->setTimeout($timeout); } + if ($database->getSharedTables() && $database->getTenant() !== null) { + //Do we need to set it for DOCUMENTSDB/VECTORSDB??? + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $projectCollections = $collections['projects'] ?? []; + $projectsGlobalCollections = array_keys($projectCollections); + $projectsGlobalCollections[] = 'audit'; + + $database->setGlobalCollections($projectsGlobalCollections); + } + // Register database event listeners for usage stats collection $documentsMetric = METRIC_DOCUMENTS; $databaseIdDocumentsMetric = METRIC_DATABASE_ID_DOCUMENTS; diff --git a/app/init/worker/message.php b/app/init/worker/message.php index dfe6af9bd9..a9c356bcec 100644 --- a/app/init/worker/message.php +++ b/app/init/worker/message.php @@ -14,6 +14,7 @@ use Appwrite\Utopia\Database\Documents\User; use Utopia\Audit\Adapter\Database as AdapterDatabase; use Utopia\Audit\Audit as UtopiaAudit; use Utopia\Cache\Cache; +use Utopia\Config\Config; use Utopia\Console; use Utopia\Database\Adapter\Pool as DatabasePool; use Utopia\Database\Database; @@ -90,8 +91,15 @@ return function (Container $container): void { $sharedTables = \explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', '')); if (\in_array($dsn->getHost(), $sharedTables)) { + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $projectCollections = $collections['projects'] ?? []; + $projectsGlobalCollections = array_keys($projectCollections); + $projectsGlobalCollections[] = 'audit'; + $database ->setSharedTables(true) + ->setGlobalCollections($projectsGlobalCollections) ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { @@ -130,8 +138,15 @@ return function (Container $container): void { $sharedTables = \explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', '')); if (\in_array($dsn->getHost(), $sharedTables)) { + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $projectCollections = $collections['projects'] ?? []; + $projectsGlobalCollections = array_keys($projectCollections); + $projectsGlobalCollections[] = 'audit'; + $database ->setSharedTables(true) + ->setGlobalCollections($projectsGlobalCollections) ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { @@ -152,8 +167,15 @@ return function (Container $container): void { $sharedTables = \explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', '')); if (\in_array($dsn->getHost(), $sharedTables)) { + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $projectCollections = $collections['projects'] ?? []; + $projectsGlobalCollections = array_keys($projectCollections); + $projectsGlobalCollections[] = 'audit'; + $database ->setSharedTables(true) + ->setGlobalCollections($projectsGlobalCollections) ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { @@ -243,6 +265,18 @@ return function (Container $container): void { } $database->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_WORKER); + + if ($database->getSharedTables() && $database->getTenant() !== null){ + // Do we need to set for DOCUMENTSDB/VECTORSDB??? + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $projectCollections = $collections['projects'] ?? []; + $projectsGlobalCollections = array_keys($projectCollections); + $projectsGlobalCollections[] = 'audit'; + + $database->setGlobalCollections($projectsGlobalCollections); + } + return $database; }; }, ['cache', 'register', 'project', 'authorization']); @@ -269,7 +303,15 @@ return function (Container $container): void { ->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES_WORKER); if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getSequence()); + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $logsCollections = $collections['logs'] ?? []; + $logsCollections = array_keys($logsCollections); + + $database + ->setTenant($project->getSequence()) + ->setGlobalCollections($logsCollections) + ; } return $database; diff --git a/app/realtime.php b/app/realtime.php index 352903d942..826d751b14 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -130,8 +130,14 @@ if (!function_exists('getProjectDB')) { $sharedTables = \explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', '')); if (\in_array($dsn->getHost(), $sharedTables)) { + $collections = Config::getParam('collections', []); + $projectCollections = $collections['projects'] ?? []; + $projectsGlobalCollections = array_keys($projectCollections); + $projectsGlobalCollections[] = 'audit'; + $database ->setSharedTables(true) + ->setGlobalCollections($projectsGlobalCollections) ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { From 8eed06678b857cfbacc41a07728f94034e5d277c Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 29 Apr 2026 15:54:05 +0300 Subject: [PATCH 081/211] formatting --- app/init/resources/request.php | 20 +++++++++----------- app/init/worker/message.php | 22 +++++++++++----------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/app/init/resources/request.php b/app/init/resources/request.php index ec2b24566f..f118fde7ee 100644 --- a/app/init/resources/request.php +++ b/app/init/resources/request.php @@ -1314,6 +1314,13 @@ return function (Container $container): void { $database = new Database($adapter, $cache); $sharedTables = \array_filter(\explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', ''))); + //Do we need to set it for DOCUMENTSDB/VECTORSDB??? + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $projectCollections = $collections['projects'] ?? []; + $projectsGlobalCollections = array_keys($projectCollections); + $projectsGlobalCollections[] = 'audit'; + $database ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) @@ -1336,6 +1343,7 @@ return function (Container $container): void { if (\in_array($databaseHost, $dbTypeSharedTables)) { $database ->setSharedTables(true) + ->setGlobalCollections($projectsGlobalCollections) ->setTenant($project->getSequence()) ->setNamespace($databaseDSN->getParam('namespace')); } else { @@ -1347,6 +1355,7 @@ return function (Container $container): void { } elseif (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) + ->setGlobalCollections($projectsGlobalCollections) ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { @@ -1360,17 +1369,6 @@ return function (Container $container): void { $database->setTimeout($timeout); } - if ($database->getSharedTables() && $database->getTenant() !== null) { - //Do we need to set it for DOCUMENTSDB/VECTORSDB??? - /** @var array $collections */ - $collections = Config::getParam('collections', []); - $projectCollections = $collections['projects'] ?? []; - $projectsGlobalCollections = array_keys($projectCollections); - $projectsGlobalCollections[] = 'audit'; - - $database->setGlobalCollections($projectsGlobalCollections); - } - // Register database event listeners for usage stats collection $documentsMetric = METRIC_DOCUMENTS; $databaseIdDocumentsMetric = METRIC_DATABASE_ID_DOCUMENTS; diff --git a/app/init/worker/message.php b/app/init/worker/message.php index a9c356bcec..555784437a 100644 --- a/app/init/worker/message.php +++ b/app/init/worker/message.php @@ -232,6 +232,15 @@ return function (Container $container): void { $sharedTables = \array_filter(\explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', ''))); + // Do we need to set for DOCUMENTSDB/VECTORSDB???????? + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $projectCollections = $collections['projects'] ?? []; + $projectsGlobalCollections = array_keys($projectCollections); + $projectsGlobalCollections[] = 'audit'; + + $database->setGlobalCollections($projectsGlobalCollections); + // For separate pools (documentsdb/vectorsdb), check their own shared tables config. // If not configured, use dedicated mode to avoid cross-engine tenant type mismatches. if ($databaseHost !== $dsn->getHost()) { @@ -244,6 +253,7 @@ return function (Container $container): void { if (\in_array($databaseHost, $dbTypeSharedTables)) { $database ->setSharedTables(true) + ->setGlobalCollections($projectsGlobalCollections) ->setTenant($projectDocument->getSequence()) ->setNamespace($databaseDSN->getParam('namespace')); } else { @@ -255,6 +265,7 @@ return function (Container $container): void { } elseif (\in_array($dsn->getHost(), $sharedTables, true)) { $database ->setSharedTables(true) + ->setGlobalCollections($projectsGlobalCollections) ->setTenant($projectDocument->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { @@ -266,17 +277,6 @@ return function (Container $container): void { $database->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_WORKER); - if ($database->getSharedTables() && $database->getTenant() !== null){ - // Do we need to set for DOCUMENTSDB/VECTORSDB??? - /** @var array $collections */ - $collections = Config::getParam('collections', []); - $projectCollections = $collections['projects'] ?? []; - $projectsGlobalCollections = array_keys($projectCollections); - $projectsGlobalCollections[] = 'audit'; - - $database->setGlobalCollections($projectsGlobalCollections); - } - return $database; }; }, ['cache', 'register', 'project', 'authorization']); From 18b976967258ffad4c971ad2e2010006d9bba17d Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 29 Apr 2026 16:14:21 +0300 Subject: [PATCH 082/211] lock file --- composer.lock | 60 +++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/composer.lock b/composer.lock index 2cf57b95a3..c19bd1dfec 100644 --- a/composer.lock +++ b/composer.lock @@ -3351,16 +3351,16 @@ }, { "name": "utopia-php/abuse", - "version": "1.2.2", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "20bee84fd14dbe81d50ecabf1ffd81cceca06152" + "reference": "53f4274939353522ba331f55bcff6e6011ffc56c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/20bee84fd14dbe81d50ecabf1ffd81cceca06152", - "reference": "20bee84fd14dbe81d50ecabf1ffd81cceca06152", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/53f4274939353522ba331f55bcff6e6011ffc56c", + "reference": "53f4274939353522ba331f55bcff6e6011ffc56c", "shasum": "" }, "require": { @@ -3397,9 +3397,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/1.2.2" + "source": "https://github.com/utopia-php/abuse/tree/1.2.3" }, - "time": "2026-02-02T10:43:10+00:00" + "time": "2026-04-29T11:19:08+00:00" }, { "name": "utopia-php/agents", @@ -3850,16 +3850,16 @@ }, { "name": "utopia-php/database", - "version": "5.3.22", + "version": "5.4.1", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "d765945da6b3141852014b2f96ecf1fe7e3d6ba7" + "reference": "688d9422b5ff42ac2ecc29397d94891cfd772e93" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/d765945da6b3141852014b2f96ecf1fe7e3d6ba7", - "reference": "d765945da6b3141852014b2f96ecf1fe7e3d6ba7", + "url": "https://api.github.com/repos/utopia-php/database/zipball/688d9422b5ff42ac2ecc29397d94891cfd772e93", + "reference": "688d9422b5ff42ac2ecc29397d94891cfd772e93", "shasum": "" }, "require": { @@ -3903,9 +3903,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/5.3.22" + "source": "https://github.com/utopia-php/database/tree/5.4.1" }, - "time": "2026-04-20T07:12:46+00:00" + "time": "2026-04-29T07:32:59+00:00" }, { "name": "utopia-php/detector", @@ -4062,16 +4062,16 @@ }, { "name": "utopia-php/domains", - "version": "1.0.5", + "version": "1.0.6", "source": { "type": "git", "url": "https://github.com/utopia-php/domains.git", - "reference": "0edf6bb2b07f30db849a267027077bf5abb994c6" + "reference": "c87ba0a1da4cbf75d2cff9d3ea0262b78f1d86f6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/domains/zipball/0edf6bb2b07f30db849a267027077bf5abb994c6", - "reference": "0edf6bb2b07f30db849a267027077bf5abb994c6", + "url": "https://api.github.com/repos/utopia-php/domains/zipball/c87ba0a1da4cbf75d2cff9d3ea0262b78f1d86f6", + "reference": "c87ba0a1da4cbf75d2cff9d3ea0262b78f1d86f6", "shasum": "" }, "require": { @@ -4118,9 +4118,9 @@ ], "support": { "issues": "https://github.com/utopia-php/domains/issues", - "source": "https://github.com/utopia-php/domains/tree/1.0.5" + "source": "https://github.com/utopia-php/domains/tree/1.0.6" }, - "time": "2026-03-03T09:20:50+00:00" + "time": "2026-04-29T11:08:10+00:00" }, { "name": "utopia-php/dsn", @@ -5466,16 +5466,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.24.0", + "version": "1.25.1", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "6d4d26659bc7a1c347c1d4d8dae3b77b5562e0cb" + "reference": "f21a556b9acdbf75bbdcdc90a078af641646eade" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/6d4d26659bc7a1c347c1d4d8dae3b77b5562e0cb", - "reference": "6d4d26659bc7a1c347c1d4d8dae3b77b5562e0cb", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/f21a556b9acdbf75bbdcdc90a078af641646eade", + "reference": "f21a556b9acdbf75bbdcdc90a078af641646eade", "shasum": "" }, "require": { @@ -5511,9 +5511,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.24.0" + "source": "https://github.com/appwrite/sdk-generator/tree/1.25.1" }, - "time": "2026-04-24T12:50:05+00:00" + "time": "2026-04-28T11:12:22+00:00" }, { "name": "brianium/paratest", @@ -6222,11 +6222,11 @@ }, { "name": "phpstan/phpstan", - "version": "2.1.51", + "version": "2.1.53", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dc3b523c45e714c70de2ac5113b958223b55dc59", - "reference": "dc3b523c45e714c70de2ac5113b958223b55dc59", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/ef67586798c003274797b288a68b221e4270dca7", + "reference": "ef67586798c003274797b288a68b221e4270dca7", "shasum": "" }, "require": { @@ -6271,7 +6271,7 @@ "type": "github" } ], - "time": "2026-04-21T18:22:01+00:00" + "time": "2026-04-28T16:09:00+00:00" }, { "name": "phpunit/php-code-coverage", @@ -8445,7 +8445,7 @@ ], "aliases": [], "minimum-stability": "dev", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": true, "prefer-lowest": false, "platform": { @@ -8466,5 +8466,5 @@ "platform-dev": { "ext-fileinfo": "*" }, - "plugin-api-version": "2.9.0" + "plugin-api-version": "2.6.0" } From 9d3255f5cd0ceb8e654e7abec95e7c7bb9aed563 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 29 Apr 2026 17:08:14 +0300 Subject: [PATCH 083/211] Update lock --- composer.lock | 72 +++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/composer.lock b/composer.lock index 50b6355c46..3edbc39614 100644 --- a/composer.lock +++ b/composer.lock @@ -3351,16 +3351,16 @@ }, { "name": "utopia-php/abuse", - "version": "1.2.2", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "20bee84fd14dbe81d50ecabf1ffd81cceca06152" + "reference": "53f4274939353522ba331f55bcff6e6011ffc56c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/20bee84fd14dbe81d50ecabf1ffd81cceca06152", - "reference": "20bee84fd14dbe81d50ecabf1ffd81cceca06152", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/53f4274939353522ba331f55bcff6e6011ffc56c", + "reference": "53f4274939353522ba331f55bcff6e6011ffc56c", "shasum": "" }, "require": { @@ -3397,9 +3397,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/1.2.2" + "source": "https://github.com/utopia-php/abuse/tree/1.2.3" }, - "time": "2026-02-02T10:43:10+00:00" + "time": "2026-04-29T11:19:08+00:00" }, { "name": "utopia-php/agents", @@ -3850,16 +3850,16 @@ }, { "name": "utopia-php/database", - "version": "5.3.22", + "version": "5.4.1", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "d765945da6b3141852014b2f96ecf1fe7e3d6ba7" + "reference": "688d9422b5ff42ac2ecc29397d94891cfd772e93" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/d765945da6b3141852014b2f96ecf1fe7e3d6ba7", - "reference": "d765945da6b3141852014b2f96ecf1fe7e3d6ba7", + "url": "https://api.github.com/repos/utopia-php/database/zipball/688d9422b5ff42ac2ecc29397d94891cfd772e93", + "reference": "688d9422b5ff42ac2ecc29397d94891cfd772e93", "shasum": "" }, "require": { @@ -3903,9 +3903,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/5.3.22" + "source": "https://github.com/utopia-php/database/tree/5.4.1" }, - "time": "2026-04-20T07:12:46+00:00" + "time": "2026-04-29T07:32:59+00:00" }, { "name": "utopia-php/detector", @@ -4062,16 +4062,16 @@ }, { "name": "utopia-php/domains", - "version": "1.0.5", + "version": "1.0.6", "source": { "type": "git", "url": "https://github.com/utopia-php/domains.git", - "reference": "0edf6bb2b07f30db849a267027077bf5abb994c6" + "reference": "c87ba0a1da4cbf75d2cff9d3ea0262b78f1d86f6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/domains/zipball/0edf6bb2b07f30db849a267027077bf5abb994c6", - "reference": "0edf6bb2b07f30db849a267027077bf5abb994c6", + "url": "https://api.github.com/repos/utopia-php/domains/zipball/c87ba0a1da4cbf75d2cff9d3ea0262b78f1d86f6", + "reference": "c87ba0a1da4cbf75d2cff9d3ea0262b78f1d86f6", "shasum": "" }, "require": { @@ -4118,9 +4118,9 @@ ], "support": { "issues": "https://github.com/utopia-php/domains/issues", - "source": "https://github.com/utopia-php/domains/tree/1.0.5" + "source": "https://github.com/utopia-php/domains/tree/1.0.6" }, - "time": "2026-03-03T09:20:50+00:00" + "time": "2026-04-29T11:08:10+00:00" }, { "name": "utopia-php/dsn", @@ -4530,16 +4530,16 @@ }, { "name": "utopia-php/migration", - "version": "1.9.4", + "version": "1.9.5", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "969dc9477ea962f16da9254facdbd8944cf13477" + "reference": "952a4dfe232702f80e45c35129466a8d8cb4c599" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/969dc9477ea962f16da9254facdbd8944cf13477", - "reference": "969dc9477ea962f16da9254facdbd8944cf13477", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/952a4dfe232702f80e45c35129466a8d8cb4c599", + "reference": "952a4dfe232702f80e45c35129466a8d8cb4c599", "shasum": "" }, "require": { @@ -4579,9 +4579,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.9.4" + "source": "https://github.com/utopia-php/migration/tree/1.9.5" }, - "time": "2026-04-27T12:42:51+00:00" + "time": "2026-04-29T11:19:13+00:00" }, { "name": "utopia-php/mongo", @@ -5020,16 +5020,16 @@ }, { "name": "utopia-php/storage", - "version": "2.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "52d1f89a47165ef0d3deff63043cda182175adfb" + "reference": "8a2e3a86fd01aaed675884146665308c2122264e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/52d1f89a47165ef0d3deff63043cda182175adfb", - "reference": "52d1f89a47165ef0d3deff63043cda182175adfb", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/8a2e3a86fd01aaed675884146665308c2122264e", + "reference": "8a2e3a86fd01aaed675884146665308c2122264e", "shasum": "" }, "require": { @@ -5066,9 +5066,9 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/2.0.0" + "source": "https://github.com/utopia-php/storage/tree/2.0.1" }, - "time": "2026-04-27T11:39:32+00:00" + "time": "2026-04-29T09:05:48+00:00" }, { "name": "utopia-php/system", @@ -6221,11 +6221,11 @@ }, { "name": "phpstan/phpstan", - "version": "2.1.52", + "version": "2.1.54", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/08a34f8db7ca4daabff74a474fe13c0e56e2b4e5", - "reference": "08a34f8db7ca4daabff74a474fe13c0e56e2b4e5", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8be50c3992107dc837b17da4d140fbbdf9a5c5bd", + "reference": "8be50c3992107dc837b17da4d140fbbdf9a5c5bd", "shasum": "" }, "require": { @@ -6270,7 +6270,7 @@ "type": "github" } ], - "time": "2026-04-28T12:17:53+00:00" + "time": "2026-04-29T13:31:09+00:00" }, { "name": "phpunit/php-code-coverage", @@ -8444,7 +8444,7 @@ ], "aliases": [], "minimum-stability": "dev", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": true, "prefer-lowest": false, "platform": { @@ -8465,5 +8465,5 @@ "platform-dev": { "ext-fileinfo": "*" }, - "plugin-api-version": "2.9.0" + "plugin-api-version": "2.6.0" } From d099167d18dab7cad8fc646fcb154d709df94d3a Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 29 Apr 2026 17:09:25 +0300 Subject: [PATCH 084/211] Shared env --- .env | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.env b/.env index 3dc7afe34a..4a6a3ac344 100644 --- a/.env +++ b/.env @@ -47,6 +47,8 @@ _APP_DB_SCHEMA=appwrite _APP_DB_USER=user _APP_DB_PASS=password _APP_DB_ROOT_PASS=rootsecretpassword +_APP_DATABASE_SHARED_TABLES= +_APP_DATABASE_SHARED_NAMESPACE= _APP_DB_ADAPTER_DOCUMENTSDB=mongodb _APP_DB_HOST_DOCUMENTSDB=mongodb _APP_DB_PORT_DOCUMENTSDB=27017 From 4050b9ded1e66b937282b80a268d6407be4f442b Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 30 Apr 2026 09:28:22 +0530 Subject: [PATCH 085/211] Continue project cleanup after resource failures --- src/Appwrite/Platform/Workers/Deletes.php | 185 +++++++++++++++------- 1 file changed, 128 insertions(+), 57 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 23ea6934ab..a5fe352b07 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -634,55 +634,87 @@ class Deletes extends Action } // Delete Platforms - $this->deleteByGroup('platforms', [ - Query::equal('projectInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform); + try { + $this->deleteByGroup('platforms', [ + Query::equal('projectInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform); + } catch (Throwable $th) { + Console::error('Failed to delete platforms: ' . $th->getMessage()); + } // Delete project and function rules - $this->deleteByGroup('rules', [ - Query::equal('projectInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform, function (Document $document) use ($dbForPlatform, $certificates) { - $this->deleteRule($dbForPlatform, $document, $certificates); - }); + try { + $this->deleteByGroup('rules', [ + Query::equal('projectInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform, function (Document $document) use ($dbForPlatform, $certificates) { + $this->deleteRule($dbForPlatform, $document, $certificates); + }); + } catch (Throwable $th) { + Console::error('Failed to delete rules: ' . $th->getMessage()); + } // Delete Keys - $this->deleteByGroup('keys', [ - Query::equal('resourceType', ['projects']), - Query::equal('resourceInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform); + try { + $this->deleteByGroup('keys', [ + Query::equal('resourceType', ['projects']), + Query::equal('resourceInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform); + } catch (Throwable $th) { + Console::error('Failed to delete keys: ' . $th->getMessage()); + } // Delete Webhooks - $this->deleteByGroup('webhooks', [ - Query::equal('projectInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform); + try { + $this->deleteByGroup('webhooks', [ + Query::equal('projectInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform); + } catch (Throwable $th) { + Console::error('Failed to delete webhooks: ' . $th->getMessage()); + } // Delete VCS Installations - $this->deleteByGroup('installations', [ - Query::equal('projectInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform); + try { + $this->deleteByGroup('installations', [ + Query::equal('projectInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform); + } catch (Throwable $th) { + Console::error('Failed to delete installations: ' . $th->getMessage()); + } // Delete VCS Repositories - $this->deleteByGroup('repositories', [ - Query::equal('projectInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform); + try { + $this->deleteByGroup('repositories', [ + Query::equal('projectInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform); + } catch (Throwable $th) { + Console::error('Failed to delete repositories: ' . $th->getMessage()); + } // Delete VCS comments - $this->deleteByGroup('vcsComments', [ - Query::equal('projectInternalId', [$projectInternalId]), - Query::orderAsc() - ], $dbForPlatform); + try { + $this->deleteByGroup('vcsComments', [ + Query::equal('projectInternalId', [$projectInternalId]), + Query::orderAsc() + ], $dbForPlatform); + } catch (Throwable $th) { + Console::error('Failed to delete VCS comments: ' . $th->getMessage()); + } // Delete Schedules - $this->deleteByGroup('schedules', [ - Query::equal('projectId', [$projectId]), - Query::orderAsc() - ], $dbForPlatform); + try { + $this->deleteByGroup('schedules', [ + Query::equal('projectId', [$projectId]), + Query::orderAsc() + ], $dbForPlatform); + } catch (Throwable $th) { + Console::error('Failed to delete schedules: ' . $th->getMessage()); + } /** * @var Database $dbForProject @@ -736,24 +768,35 @@ class Deletes extends Action }; batch(array_map( - fn ($databaseDoc) => fn () => $this->cleanDatabase( - $databaseDoc, - $executionActionPerDatabase, - $projectTables, - $projectCollectionIds - ), + fn ($databaseDoc) => function () use ($databaseDoc, $executionActionPerDatabase, $projectTables, $projectCollectionIds) { + try { + $this->cleanDatabase( + $databaseDoc, + $executionActionPerDatabase, + $projectTables, + $projectCollectionIds + ); + } catch (Throwable $th) { + Console::error('Failed to delete database ' . $databaseDoc->getAttribute('database') . ': ' . $th->getMessage()); + } + }, $databasesToClean )); // Delete metadata table if ($projectTables) { batch(array_map( - fn ($databaseDoc) => fn () => - $executionActionPerDatabase( - $databaseDoc, - fn (Database $dbForDatabases) => - $dbForDatabases->deleteCollection(Database::METADATA) - ), + fn ($databaseDoc) => function () use ($databaseDoc, $executionActionPerDatabase) { + try { + $executionActionPerDatabase( + $databaseDoc, + fn (Database $dbForDatabases) => + $dbForDatabases->deleteCollection(Database::METADATA) + ); + } catch (Throwable $th) { + Console::error('Failed to delete metadata table for database ' . $databaseDoc->getAttribute('database') . ': ' . $th->getMessage()); + } + }, $databasesToClean )); } else { @@ -764,19 +807,47 @@ class Deletes extends Action $queries[] = Query::orderAsc(); - $this->deleteByGroup( - Database::METADATA, - $queries, - $dbForProject - ); + try { + $this->deleteByGroup( + Database::METADATA, + $queries, + $dbForProject + ); + } catch (Throwable $th) { + Console::error('Failed to delete metadata documents: ' . $th->getMessage()); + } } // Delete all storage directories - $deviceForFiles->delete($deviceForFiles->getRoot(), true); - $deviceForSites->delete($deviceForSites->getRoot(), true); - $deviceForFunctions->delete($deviceForFunctions->getRoot(), true); - $deviceForBuilds->delete($deviceForBuilds->getRoot(), true); - $deviceForCache->delete($deviceForCache->getRoot(), true); + try { + $deviceForFiles->delete($deviceForFiles->getRoot(), true); + } catch (Throwable $th) { + Console::error('Failed to delete files storage directory: ' . $th->getMessage()); + } + + try { + $deviceForSites->delete($deviceForSites->getRoot(), true); + } catch (Throwable $th) { + Console::error('Failed to delete sites storage directory: ' . $th->getMessage()); + } + + try { + $deviceForFunctions->delete($deviceForFunctions->getRoot(), true); + } catch (Throwable $th) { + Console::error('Failed to delete functions storage directory: ' . $th->getMessage()); + } + + try { + $deviceForBuilds->delete($deviceForBuilds->getRoot(), true); + } catch (Throwable $th) { + Console::error('Failed to delete builds storage directory: ' . $th->getMessage()); + } + + try { + $deviceForCache->delete($deviceForCache->getRoot(), true); + } catch (Throwable $th) { + Console::error('Failed to delete cache storage directory: ' . $th->getMessage()); + } } finally { $dbForProject->enableValidation(); From 337d47b1d9f5609aa6721f6903c57c4fec9fd4f6 Mon Sep 17 00:00:00 2001 From: frubio Date: Thu, 30 Apr 2026 09:33:08 +0200 Subject: [PATCH 086/211] fix(locale): add Spanish session alert translations --- app/config/locale/translations/es.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/config/locale/translations/es.json b/app/config/locale/translations/es.json index 21a406b418..1bbc8062be 100644 --- a/app/config/locale/translations/es.json +++ b/app/config/locale/translations/es.json @@ -28,6 +28,16 @@ "emails.invitation.thanks": "Gracias.,", "emails.invitation.buttonText": "Aceptar invitación a {{team}}", "emails.invitation.signature": "El equipo de {{project}}", + "emails.sessionAlert.subject": "Alerta de seguridad: nueva sesión en tu cuenta de {{project}}", + "emails.sessionAlert.preview": "Nuevo inicio de sesión detectado en {{project}} a las {{time}} UTC.", + "emails.sessionAlert.hello": "Hola {{user}},", + "emails.sessionAlert.body": "Se ha creado una nueva sesión en tu cuenta de {{b}}{{project}}{{/b}}, {{b}}el {{date}} de {{year}} a las {{time}} UTC{{/b}}.\nEstos son los detalles de la nueva sesión:", + "emails.sessionAlert.listDevice": "Dispositivo: {{b}}{{device}}{{/b}}", + "emails.sessionAlert.listIpAddress": "Dirección IP: {{b}}{{ipAddress}}{{/b}}", + "emails.sessionAlert.listCountry": "País: {{b}}{{country}}{{/b}}", + "emails.sessionAlert.footer": "Si has sido tú, no tienes que hacer nada más.\nSi no has iniciado esta sesión o sospechas actividad no autorizada, protege tu cuenta.", + "emails.sessionAlert.thanks": "Gracias,", + "emails.sessionAlert.signature": "El equipo de {{project}}", "locale.country.unknown": "Desconocido", "countries.af": "Afganistán", "countries.ao": "Angola", From c0bba74eee628b3811a29f8e984ce377b2d3d481 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 30 Apr 2026 10:36:12 +0300 Subject: [PATCH 087/211] set setGlobalCollections logs --- app/cli.php | 16 +++++++--------- app/init/resources.php | 16 +++++++--------- app/init/resources/request.php | 17 +++++++---------- app/init/worker/message.php | 17 +++++++---------- 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/app/cli.php b/app/cli.php index dd7c172cab..ada155c4dc 100644 --- a/app/cli.php +++ b/app/cli.php @@ -226,6 +226,11 @@ $container->set('getLogsDB', function (Group $pools, Cache $cache, Authorization return $database; } + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $logsCollections = $collections['logs'] ?? []; + $logsCollections = array_keys($logsCollections); + $adapter = new DatabasePool($pools->get('logs')); $database = new Database($adapter, $cache); @@ -234,20 +239,13 @@ $container->set('getLogsDB', function (Group $pools, Cache $cache, Authorization ->setAuthorization($authorization) ->setSharedTables(true) ->setNamespace('logsV1') + ->setGlobalCollections($logsCollections) ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_TASK) ->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES); // set tenant if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - /** @var array $collections */ - $collections = Config::getParam('collections', []); - $logsCollections = $collections['logs'] ?? []; - $logsCollections = array_keys($logsCollections); - - $database - ->setTenant($project->getSequence()) - ->setGlobalCollections($logsCollections) - ; + $database->setTenant($project->getSequence()); } return $database; diff --git a/app/init/resources.php b/app/init/resources.php index 12438c3fae..96457294de 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -159,25 +159,23 @@ $container->set('getLogsDB', function (Group $pools, Cache $cache, Authorization $adapter = new DatabasePool($pools->get('logs')); $database = new Database($adapter, $cache); + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $logsCollections = $collections['logs'] ?? []; + $logsCollections = array_keys($logsCollections); + $database ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setSharedTables(true) + ->setGlobalCollections($logsCollections) ->setNamespace('logsV1') ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_API) ->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES); // set tenant if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - /** @var array $collections */ - $collections = Config::getParam('collections', []); - $logsCollections = $collections['logs'] ?? []; - $logsCollections = array_keys($logsCollections); - - $database - ->setTenant($project->getSequence()) - ->setGlobalCollections($logsCollections) - ; + $database->setTenant($project->getSequence()); } return $database; diff --git a/app/init/resources/request.php b/app/init/resources/request.php index f118fde7ee..70d691370d 100644 --- a/app/init/resources/request.php +++ b/app/init/resources/request.php @@ -230,6 +230,11 @@ return function (Container $container): void { $adapter = null; return function (?Document $project = null) use ($pools, $cache, $authorization, &$adapter) { + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $logsCollections = $collections['logs'] ?? []; + $logsCollections = array_keys($logsCollections); + $adapter ??= new DatabasePool($pools->get('logs')); $database = new Database($adapter, $cache); @@ -237,20 +242,13 @@ return function (Container $container): void { ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setSharedTables(true) + ->setGlobalCollections($logsCollections) ->setNamespace('logsV1') ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_API) ->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES); if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - /** @var array $collections */ - $collections = Config::getParam('collections', []); - $logsCollections = $collections['logs'] ?? []; - $logsCollections = array_keys($logsCollections); - - $database - ->setTenant($project->getSequence()) - ->setGlobalCollections($logsCollections) - ; + $database->setTenant($project->getSequence()); } return $database; @@ -1314,7 +1312,6 @@ return function (Container $container): void { $database = new Database($adapter, $cache); $sharedTables = \array_filter(\explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', ''))); - //Do we need to set it for DOCUMENTSDB/VECTORSDB??? /** @var array $collections */ $collections = Config::getParam('collections', []); $projectCollections = $collections['projects'] ?? []; diff --git a/app/init/worker/message.php b/app/init/worker/message.php index 555784437a..08900c9bee 100644 --- a/app/init/worker/message.php +++ b/app/init/worker/message.php @@ -232,7 +232,6 @@ return function (Container $container): void { $sharedTables = \array_filter(\explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', ''))); - // Do we need to set for DOCUMENTSDB/VECTORSDB???????? /** @var array $collections */ $collections = Config::getParam('collections', []); $projectCollections = $collections['projects'] ?? []; @@ -291,6 +290,11 @@ return function (Container $container): void { return $database; } + /** @var array $collections */ + $collections = Config::getParam('collections', []); + $logsCollections = $collections['logs'] ?? []; + $logsCollections = array_keys($logsCollections); + $adapter = new DatabasePool($pools->get('logs')); $database = new Database($adapter, $cache); @@ -298,20 +302,13 @@ return function (Container $container): void { ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setSharedTables(true) + ->setGlobalCollections($logsCollections) ->setNamespace('logsV1') ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_WORKER) ->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES_WORKER); if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - /** @var array $collections */ - $collections = Config::getParam('collections', []); - $logsCollections = $collections['logs'] ?? []; - $logsCollections = array_keys($logsCollections); - - $database - ->setTenant($project->getSequence()) - ->setGlobalCollections($logsCollections) - ; + $database->setTenant($project->getSequence()); } return $database; From d98bd8c9723e969a686f372d638ab4e3adfa8964 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 30 Apr 2026 10:44:21 +0300 Subject: [PATCH 088/211] Remove line --- app/init/worker/message.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/init/worker/message.php b/app/init/worker/message.php index 08900c9bee..17796fadcd 100644 --- a/app/init/worker/message.php +++ b/app/init/worker/message.php @@ -275,7 +275,6 @@ return function (Container $container): void { } $database->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_WORKER); - return $database; }; }, ['cache', 'register', 'project', 'authorization']); From b73ba68bfb13c6fdae4714f3363796ab41046469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 30 Apr 2026 10:21:38 +0200 Subject: [PATCH 089/211] Fix oauth order; Fix apple secreting too much --- .../Console/Http/OAuth2Providers/XList.php | 6 ++-- .../Http/Project/OAuth2/Apple/Update.php | 5 ++-- .../Console/ConsoleConsoleClientTest.php | 2 ++ tests/e2e/Services/Project/OAuth2Base.php | 30 ++++++++----------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Console/Http/OAuth2Providers/XList.php b/src/Appwrite/Platform/Modules/Console/Http/OAuth2Providers/XList.php index 79a36643a1..e253292ca9 100644 --- a/src/Appwrite/Platform/Modules/Console/Http/OAuth2Providers/XList.php +++ b/src/Appwrite/Platform/Modules/Console/Http/OAuth2Providers/XList.php @@ -54,9 +54,9 @@ class XList extends Action $actions = OAuth2Base::getProviderActions(); $providers = []; - foreach ($actions as $providerId => $updateClass) { - $config = $providersConfig[$providerId] ?? null; - if ($config === null) { + foreach ($providersConfig as $providerId => $config) { + $updateClass = $actions[$providerId] ?? null; + if ($updateClass === null) { continue; } if (!($config['enabled'] ?? false)) { diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Apple/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Apple/Update.php index 08fc7dbf6b..dc9eede2b4 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Apple/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Apple/Update.php @@ -146,13 +146,14 @@ class Update extends Base { $providerId = static::getProviderId(); $oAuthProviders = $project->getAttribute('oAuthProviders', []); + $storedSecret = $this->decodeStoredSecret($project); return new Document([ '$id' => $providerId, 'enabled' => $oAuthProviders[$providerId . 'Enabled'] ?? false, static::getClientIdParamName() => $oAuthProviders[$providerId . 'Appid'] ?? '', - 'keyId' => '', - 'teamId' => '', + 'keyId' => $storedSecret['keyID'] ?? '', + 'teamId' => $storedSecret['teamID'] ?? '', 'p8File' => '', ]); } diff --git a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php index 8235ebb7bc..c111b744c3 100644 --- a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php +++ b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php @@ -56,6 +56,8 @@ class ConsoleConsoleClientTest extends Scope $this->assertEquals($response['body']['total'], \count($response['body']['oAuth2Providers'])); $providerIds = \array_column($response['body']['oAuth2Providers'], '$id'); + $this->assertEquals('amazon', $providerIds[0]); + $this->assertEquals('zoom', $providerIds[\count($providerIds) - 1]); // Well-known providers must be present $this->assertContains('github', $providerIds); diff --git a/tests/e2e/Services/Project/OAuth2Base.php b/tests/e2e/Services/Project/OAuth2Base.php index 8345bfab0a..9ff3830ec5 100644 --- a/tests/e2e/Services/Project/OAuth2Base.php +++ b/tests/e2e/Services/Project/OAuth2Base.php @@ -478,9 +478,8 @@ trait OAuth2Base $this->assertSame(200, $response['headers']['status-code']); $this->assertSame('apple', $response['body']['$id']); $this->assertSame('ip.appwrite.app.web', $response['body']['serviceId']); - // keyId / teamId / p8File are write-only — PATCH response must not echo them back. - $this->assertSame('', $response['body']['keyId']); - $this->assertSame('', $response['body']['teamId']); + $this->assertSame('P4000000N8', $response['body']['keyId']); + $this->assertSame('D4000000R6', $response['body']['teamId']); $this->assertSame('', $response['body']['p8File']); $this->assertSame(false, $response['body']['enabled']); @@ -511,12 +510,10 @@ trait OAuth2Base ]); $this->assertSame(200, $response['headers']['status-code']); - // serviceId is the (non-secret) clientId; keyId/teamId are write-only - // and must not surface in the response. Persistence of the merged - // values is verified separately via the enable-after-merge tests. $this->assertSame('ip.appwrite.app.seed', $response['body']['serviceId']); - $this->assertSame('', $response['body']['keyId']); - $this->assertSame('', $response['body']['teamId']); + $this->assertSame('KEYUPDATED', $response['body']['keyId']); + $this->assertSame('TEAMSEED01', $response['body']['teamId']); + $this->assertSame('', $response['body']['p8File']); // Cleanup $this->updateOAuth2('apple', [ @@ -546,9 +543,9 @@ trait OAuth2Base 'teamId' => 'TEAMROTATED', ]); $this->assertSame(200, $teamOnly['headers']['status-code']); - // teamId is write-only; verify only the non-secret serviceId echo. - // The actual merge is validated by the enable-after-merge call below. - $this->assertSame('', $teamOnly['body']['teamId']); + $this->assertSame('TEAMROTATED', $teamOnly['body']['teamId']); + $this->assertSame('KEYMERGE01', $teamOnly['body']['keyId']); + $this->assertSame('', $teamOnly['body']['p8File']); $this->assertSame('ip.appwrite.app.merge', $teamOnly['body']['serviceId']); // Patch only `serviceId` — keyId/teamId/p8File live in the JSON blob @@ -669,9 +666,8 @@ trait OAuth2Base $this->assertSame(200, $response['headers']['status-code']); $this->assertSame('ip.appwrite.app.read', $response['body']['serviceId']); - // All three secret-bearing fields must be hidden on read. - $this->assertSame('', $response['body']['keyId']); - $this->assertSame('', $response['body']['teamId']); + $this->assertSame('KEYREAD', $response['body']['keyId']); + $this->assertSame('TEAMREAD', $response['body']['teamId']); $this->assertSame('', $response['body']['p8File']); // Cleanup @@ -699,13 +695,13 @@ trait OAuth2Base $this->assertSame(200, $update['headers']['status-code']); $this->assertTrue($update['body']['enabled']); - // GET must hide all three secret-bearing fields while keeping serviceId. + // GET must hide p8File while keeping the non-secret fields. $get = $this->getOAuth2Provider('apple'); $this->assertSame(200, $get['headers']['status-code']); $this->assertTrue($get['body']['enabled']); $this->assertSame('ip.appwrite.app.enable', $get['body']['serviceId']); - $this->assertSame('', $get['body']['keyId']); - $this->assertSame('', $get['body']['teamId']); + $this->assertSame('ENABLEKEY', $get['body']['keyId']); + $this->assertSame('ENABLETEAM', $get['body']['teamId']); $this->assertSame('', $get['body']['p8File']); // Cleanup From 62b7d5558faa9512f4ea24365c6a6290fbf7773c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 30 Apr 2026 12:36:45 +0200 Subject: [PATCH 090/211] Mark params nonrequired --- src/Appwrite/Auth/OAuth2/Authentik.php | 7 +++++++ src/Appwrite/Auth/OAuth2/FusionAuth.php | 7 +++++++ src/Appwrite/Auth/OAuth2/Keycloak.php | 11 +++++++++++ src/Appwrite/Auth/OAuth2/Microsoft.php | 11 +++++++++-- .../Project/Http/Project/OAuth2/Authentik/Update.php | 6 +++--- .../Project/Http/Project/OAuth2/FusionAuth/Update.php | 6 +++--- .../Project/Http/Project/OAuth2/GitHub/Update.php | 2 +- .../Project/Http/Project/OAuth2/Keycloak/Update.php | 10 +++++----- .../Project/Http/Project/OAuth2/Microsoft/Update.php | 6 +++--- .../e2e/Services/Console/ConsoleConsoleClientTest.php | 2 +- 10 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2/Authentik.php b/src/Appwrite/Auth/OAuth2/Authentik.php index 5d2445088b..aa4b126ae8 100644 --- a/src/Appwrite/Auth/OAuth2/Authentik.php +++ b/src/Appwrite/Auth/OAuth2/Authentik.php @@ -37,6 +37,13 @@ class Authentik extends OAuth2 return 'authentik'; } + public function verifyCredentials(): void + { + if (empty($this->getAuthentikDomain())) { + throw new \Exception('Authentik endpoint is required.'); + } + } + /** * @return string */ diff --git a/src/Appwrite/Auth/OAuth2/FusionAuth.php b/src/Appwrite/Auth/OAuth2/FusionAuth.php index 415be4c6ad..fa8b45dc72 100644 --- a/src/Appwrite/Auth/OAuth2/FusionAuth.php +++ b/src/Appwrite/Auth/OAuth2/FusionAuth.php @@ -37,6 +37,13 @@ class FusionAuth extends OAuth2 return 'fusionauth'; } + public function verifyCredentials(): void + { + if (empty($this->getFusionAuthDomain())) { + throw new \Exception('FusionAuth endpoint is required.'); + } + } + /** * @return string */ diff --git a/src/Appwrite/Auth/OAuth2/Keycloak.php b/src/Appwrite/Auth/OAuth2/Keycloak.php index 05e007eb7d..b53b08e2d9 100644 --- a/src/Appwrite/Auth/OAuth2/Keycloak.php +++ b/src/Appwrite/Auth/OAuth2/Keycloak.php @@ -37,6 +37,17 @@ class Keycloak extends OAuth2 return 'keycloak'; } + public function verifyCredentials(): void + { + if (empty($this->getKeycloakDomain())) { + throw new \Exception('Keycloak endpoint is required.'); + } + + if (empty($this->getKeycloakRealm())) { + throw new \Exception('Keycloak realm name is required.'); + } + } + /** * @return string */ diff --git a/src/Appwrite/Auth/OAuth2/Microsoft.php b/src/Appwrite/Auth/OAuth2/Microsoft.php index bc05843b37..19966ec1ac 100644 --- a/src/Appwrite/Auth/OAuth2/Microsoft.php +++ b/src/Appwrite/Auth/OAuth2/Microsoft.php @@ -36,6 +36,13 @@ class Microsoft extends OAuth2 return 'microsoft'; } + public function verifyCredentials(): void + { + if (empty($this->getTenantID())) { + throw new \Exception('Microsoft tenant is required.'); + } + } + /** * @return string */ @@ -201,7 +208,7 @@ class Microsoft extends OAuth2 } /** - * Extracts the Tenant Id from the JSON stored in appSecret. Defaults to 'common' as a fallback + * Extracts the Tenant Id from the JSON stored in appSecret. * * @return string */ @@ -209,6 +216,6 @@ class Microsoft extends OAuth2 { $secret = $this->getAppSecret(); - return $secret['tenantID'] ?? 'common'; + return $secret['tenantID'] ?? ''; } } diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php index d5d465c3d4..683f8cca92 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php @@ -105,7 +105,7 @@ class Update extends Base )) ->param(static::getClientIdParamName(), null, new Nullable(new Text(256, 0)), static::getClientIdDescription(), optional: true) ->param(static::getClientSecretParamName(), null, new Nullable(new Text(512, 0)), static::getClientSecretDescription(), optional: true) - ->param('endpoint', '', new Text(256, 1), 'Domain of Authentik instance. For example: example.authentik.com', optional: false) + ->param('endpoint', '', new Text(256, 1), 'Domain of Authentik instance. For example: example.authentik.com', optional: true) ->param('enabled', null, new Nullable(new Boolean()), 'OAuth2 sign-in method status. Set to true to enable new session creation. Setting to true will trigger end-to-end credentials validation, and will throw if the credentials are invalid.', true) ->inject('response') ->inject('dbForPlatform') @@ -151,7 +151,7 @@ class Update extends Base // The secret is stored as JSON `{"clientSecret": "...", "authentikDomain": "..."}` // to match the shape Authentik's OAuth2 adapter expects (getAuthentikDomain()). - // The `endpoint` param is required on every call, so it's always written. + // The `endpoint` param is optional; if omitted, the existing stored endpoint is preserved. // `clientSecret` is optional; if omitted, the existing stored secret is preserved. $storedRaw = $project->getAttribute('oAuthProviders', [])[$providerId . 'Secret'] ?? ''; $existing = []; @@ -160,7 +160,7 @@ class Update extends Base } $encodedSecret = \json_encode([ 'clientSecret' => $clientSecret ?? ($existing['clientSecret'] ?? ''), - 'authentikDomain' => $endpoint, + 'authentikDomain' => $endpoint !== '' ? $endpoint : ($existing['authentikDomain'] ?? ''), ]); $project = $this->persistCredentials($project, $dbForPlatform, $authorization, $clientId, $encodedSecret, $enabled); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php index 25f81e1459..e0846621dc 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php @@ -105,7 +105,7 @@ class Update extends Base )) ->param(static::getClientIdParamName(), null, new Nullable(new Text(256, 0)), static::getClientIdDescription(), optional: true) ->param(static::getClientSecretParamName(), null, new Nullable(new Text(512, 0)), static::getClientSecretDescription(), optional: true) - ->param('endpoint', '', new Text(256, 1), 'Domain of FusionAuth instance. For example: example.fusionauth.io', optional: false) + ->param('endpoint', '', new Text(256, 1), 'Domain of FusionAuth instance. For example: example.fusionauth.io', optional: true) ->param('enabled', null, new Nullable(new Boolean()), 'OAuth2 sign-in method status. Set to true to enable new session creation. Setting to true will trigger end-to-end credentials validation, and will throw if the credentials are invalid.', true) ->inject('response') ->inject('dbForPlatform') @@ -151,7 +151,7 @@ class Update extends Base // The secret is stored as JSON `{"clientSecret": "...", "fusionAuthDomain": "..."}` // to match the shape FusionAuth's OAuth2 adapter expects (getFusionAuthDomain()). - // The `endpoint` param is required on every call, so it's always written. + // The `endpoint` param is optional; if omitted, the existing stored endpoint is preserved. // `clientSecret` is optional; if omitted, the existing stored secret is preserved. $storedRaw = $project->getAttribute('oAuthProviders', [])[$providerId . 'Secret'] ?? ''; $existing = []; @@ -160,7 +160,7 @@ class Update extends Base } $encodedSecret = \json_encode([ 'clientSecret' => $clientSecret ?? ($existing['clientSecret'] ?? ''), - 'fusionAuthDomain' => $endpoint, + 'fusionAuthDomain' => $endpoint !== '' ? $endpoint : ($existing['fusionAuthDomain'] ?? ''), ]); $project = $this->persistCredentials($project, $dbForPlatform, $authorization, $clientId, $encodedSecret, $enabled); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/GitHub/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/GitHub/Update.php index 3b6f89db06..7c680e5141 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/GitHub/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/GitHub/Update.php @@ -35,7 +35,7 @@ class Update extends Base public static function getClientIdName(): string { - return 'OAuth 2 app Client ID, or App ID'; + return 'OAuth2 app Client ID, or App ID'; } public static function getClientIdExample(): string diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php index 797875cab2..121c6115b4 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php @@ -111,8 +111,8 @@ class Update extends Base )) ->param(static::getClientIdParamName(), null, new Nullable(new Text(256, 0)), static::getClientIdDescription(), optional: true) ->param(static::getClientSecretParamName(), null, new Nullable(new Text(512, 0)), static::getClientSecretDescription(), optional: true) - ->param('endpoint', '', new Text(256, 1), 'Domain of Keycloak instance. For example: keycloak.example.com', optional: false) - ->param('realmName', '', new Text(256, 1), 'Keycloak realm name. For example: appwrite-realm', optional: false) + ->param('endpoint', '', new Text(256, 1), 'Domain of Keycloak instance. For example: keycloak.example.com', optional: true) + ->param('realmName', '', new Text(256, 1), 'Keycloak realm name. For example: appwrite-realm', optional: true) ->param('enabled', null, new Nullable(new Boolean()), 'OAuth2 sign-in method status. Set to true to enable new session creation. Setting to true will trigger end-to-end credentials validation, and will throw if the credentials are invalid.', true) ->inject('response') ->inject('dbForPlatform') @@ -161,7 +161,7 @@ class Update extends Base // The secret is stored as JSON `{"clientSecret": "...", "keycloakDomain": "...", "keycloakRealm": "..."}` // to match the shape Keycloak's OAuth2 adapter expects (getKeycloakDomain(), getKeycloakRealm()). - // The `endpoint` and `realmName` params are required on every call, so they're always written. + // The `endpoint` and `realmName` params are optional; if omitted, existing stored values are preserved. // `clientSecret` is optional; if omitted, the existing stored secret is preserved. $storedRaw = $project->getAttribute('oAuthProviders', [])[$providerId . 'Secret'] ?? ''; $existing = []; @@ -170,8 +170,8 @@ class Update extends Base } $encodedSecret = \json_encode([ 'clientSecret' => $clientSecret ?? ($existing['clientSecret'] ?? ''), - 'keycloakDomain' => $endpoint, - 'keycloakRealm' => $realmName, + 'keycloakDomain' => $endpoint !== '' ? $endpoint : ($existing['keycloakDomain'] ?? ''), + 'keycloakRealm' => $realmName !== '' ? $realmName : ($existing['keycloakRealm'] ?? ''), ]); $project = $this->persistCredentials($project, $dbForPlatform, $authorization, $clientId, $encodedSecret, $enabled); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php index 0690ee333a..a4db4c1aee 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php @@ -115,7 +115,7 @@ class Update extends Base )) ->param(static::getClientIdParamName(), null, new Nullable(new Text(256, 0)), static::getClientIdDescription(), optional: true) ->param(static::getClientSecretParamName(), null, new Nullable(new Text(512, 0)), static::getClientSecretDescription(), optional: true) - ->param('tenant', '', new Text(256, 1), 'Microsoft Entra ID tenant identifier. Use \'common\', \'organizations\', \'consumers\' or a specific tenant ID. For example: common', optional: false) + ->param('tenant', '', new Text(256, 1), 'Microsoft Entra ID tenant identifier. Use \'common\', \'organizations\', \'consumers\' or a specific tenant ID. For example: common', true) ->param('enabled', null, new Nullable(new Boolean()), 'OAuth2 sign-in method status. Set to true to enable new session creation. Setting to true will trigger end-to-end credentials validation, and will throw if the credentials are invalid.', true) ->inject('response') ->inject('dbForPlatform') @@ -161,7 +161,7 @@ class Update extends Base // The secret is stored as JSON `{"clientSecret": "...", "tenantID": "..."}` // to match the shape Microsoft's OAuth2 adapter expects (getTenantID()). - // The `tenant` param is required on every call, so it's always written. + // The `tenant` param is optional; if omitted, the existing stored tenant is preserved. // `applicationSecret` is optional; if omitted, the existing stored secret is preserved. $storedRaw = $project->getAttribute('oAuthProviders', [])[$providerId . 'Secret'] ?? ''; $existing = []; @@ -170,7 +170,7 @@ class Update extends Base } $encodedSecret = \json_encode([ 'clientSecret' => $applicationSecret ?? ($existing['clientSecret'] ?? ''), - 'tenantID' => $tenant, + 'tenantID' => $tenant !== '' ? $tenant : ($existing['tenantID'] ?? ''), ]); $project = $this->persistCredentials($project, $dbForPlatform, $authorization, $applicationId, $encodedSecret, $enabled); diff --git a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php index c111b744c3..c8f921f2ec 100644 --- a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php +++ b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php @@ -101,7 +101,7 @@ class ConsoleConsoleClientTest extends Scope $this->assertCount(2, $github['parameters']); $clientId = $github['parameters'][0]; $this->assertEquals('clientId', $clientId['$id']); - $this->assertEquals('OAuth 2 app Client ID, or App ID', $clientId['name']); + $this->assertEquals('OAuth2 app Client ID, or App ID', $clientId['name']); $this->assertEquals('e4d87900000000540733', $clientId['example']); $this->assertEquals('Example of wrong value: 370006', $clientId['hint']); $clientSecret = $github['parameters'][1]; From 8785aa987768847d59eaf6c8ed7f38add4671e44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 30 Apr 2026 12:41:55 +0200 Subject: [PATCH 091/211] Fix nullable implementation oauth --- .../Project/Http/Project/OAuth2/Authentik/Update.php | 6 +++--- .../Http/Project/OAuth2/FusionAuth/Update.php | 6 +++--- .../Project/Http/Project/OAuth2/Keycloak/Update.php | 12 ++++++------ .../Project/Http/Project/OAuth2/Microsoft/Update.php | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php index 683f8cca92..af6b12618a 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Authentik/Update.php @@ -105,7 +105,7 @@ class Update extends Base )) ->param(static::getClientIdParamName(), null, new Nullable(new Text(256, 0)), static::getClientIdDescription(), optional: true) ->param(static::getClientSecretParamName(), null, new Nullable(new Text(512, 0)), static::getClientSecretDescription(), optional: true) - ->param('endpoint', '', new Text(256, 1), 'Domain of Authentik instance. For example: example.authentik.com', optional: true) + ->param('endpoint', null, new Nullable(new Text(256, 0)), 'Domain of Authentik instance. For example: example.authentik.com', optional: true) ->param('enabled', null, new Nullable(new Boolean()), 'OAuth2 sign-in method status. Set to true to enable new session creation. Setting to true will trigger end-to-end credentials validation, and will throw if the credentials are invalid.', true) ->inject('response') ->inject('dbForPlatform') @@ -138,7 +138,7 @@ class Update extends Base public function handle( ?string $clientId, ?string $clientSecret, - string $endpoint, + ?string $endpoint, ?bool $enabled, Response $response, Database $dbForPlatform, @@ -160,7 +160,7 @@ class Update extends Base } $encodedSecret = \json_encode([ 'clientSecret' => $clientSecret ?? ($existing['clientSecret'] ?? ''), - 'authentikDomain' => $endpoint !== '' ? $endpoint : ($existing['authentikDomain'] ?? ''), + 'authentikDomain' => $endpoint ?? ($existing['authentikDomain'] ?? ''), ]); $project = $this->persistCredentials($project, $dbForPlatform, $authorization, $clientId, $encodedSecret, $enabled); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php index e0846621dc..3cdf0eeb89 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/FusionAuth/Update.php @@ -105,7 +105,7 @@ class Update extends Base )) ->param(static::getClientIdParamName(), null, new Nullable(new Text(256, 0)), static::getClientIdDescription(), optional: true) ->param(static::getClientSecretParamName(), null, new Nullable(new Text(512, 0)), static::getClientSecretDescription(), optional: true) - ->param('endpoint', '', new Text(256, 1), 'Domain of FusionAuth instance. For example: example.fusionauth.io', optional: true) + ->param('endpoint', null, new Nullable(new Text(256, 0)), 'Domain of FusionAuth instance. For example: example.fusionauth.io', optional: true) ->param('enabled', null, new Nullable(new Boolean()), 'OAuth2 sign-in method status. Set to true to enable new session creation. Setting to true will trigger end-to-end credentials validation, and will throw if the credentials are invalid.', true) ->inject('response') ->inject('dbForPlatform') @@ -138,7 +138,7 @@ class Update extends Base public function handle( ?string $clientId, ?string $clientSecret, - string $endpoint, + ?string $endpoint, ?bool $enabled, Response $response, Database $dbForPlatform, @@ -160,7 +160,7 @@ class Update extends Base } $encodedSecret = \json_encode([ 'clientSecret' => $clientSecret ?? ($existing['clientSecret'] ?? ''), - 'fusionAuthDomain' => $endpoint !== '' ? $endpoint : ($existing['fusionAuthDomain'] ?? ''), + 'fusionAuthDomain' => $endpoint ?? ($existing['fusionAuthDomain'] ?? ''), ]); $project = $this->persistCredentials($project, $dbForPlatform, $authorization, $clientId, $encodedSecret, $enabled); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php index 121c6115b4..aa41e8a5e9 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Keycloak/Update.php @@ -111,8 +111,8 @@ class Update extends Base )) ->param(static::getClientIdParamName(), null, new Nullable(new Text(256, 0)), static::getClientIdDescription(), optional: true) ->param(static::getClientSecretParamName(), null, new Nullable(new Text(512, 0)), static::getClientSecretDescription(), optional: true) - ->param('endpoint', '', new Text(256, 1), 'Domain of Keycloak instance. For example: keycloak.example.com', optional: true) - ->param('realmName', '', new Text(256, 1), 'Keycloak realm name. For example: appwrite-realm', optional: true) + ->param('endpoint', null, new Nullable(new Text(256, 0)), 'Domain of Keycloak instance. For example: keycloak.example.com', optional: true) + ->param('realmName', null, new Nullable(new Text(256, 0)), 'Keycloak realm name. For example: appwrite-realm', optional: true) ->param('enabled', null, new Nullable(new Boolean()), 'OAuth2 sign-in method status. Set to true to enable new session creation. Setting to true will trigger end-to-end credentials validation, and will throw if the credentials are invalid.', true) ->inject('response') ->inject('dbForPlatform') @@ -147,8 +147,8 @@ class Update extends Base public function handle( ?string $clientId, ?string $clientSecret, - string $endpoint, - string $realmName, + ?string $endpoint, + ?string $realmName, ?bool $enabled, Response $response, Database $dbForPlatform, @@ -170,8 +170,8 @@ class Update extends Base } $encodedSecret = \json_encode([ 'clientSecret' => $clientSecret ?? ($existing['clientSecret'] ?? ''), - 'keycloakDomain' => $endpoint !== '' ? $endpoint : ($existing['keycloakDomain'] ?? ''), - 'keycloakRealm' => $realmName !== '' ? $realmName : ($existing['keycloakRealm'] ?? ''), + 'keycloakDomain' => $endpoint ?? ($existing['keycloakDomain'] ?? ''), + 'keycloakRealm' => $realmName ?? ($existing['keycloakRealm'] ?? ''), ]); $project = $this->persistCredentials($project, $dbForPlatform, $authorization, $clientId, $encodedSecret, $enabled); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php index a4db4c1aee..811819a05c 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Microsoft/Update.php @@ -115,7 +115,7 @@ class Update extends Base )) ->param(static::getClientIdParamName(), null, new Nullable(new Text(256, 0)), static::getClientIdDescription(), optional: true) ->param(static::getClientSecretParamName(), null, new Nullable(new Text(512, 0)), static::getClientSecretDescription(), optional: true) - ->param('tenant', '', new Text(256, 1), 'Microsoft Entra ID tenant identifier. Use \'common\', \'organizations\', \'consumers\' or a specific tenant ID. For example: common', true) + ->param('tenant', null, new Nullable(new Text(256, 0)), 'Microsoft Entra ID tenant identifier. Use \'common\', \'organizations\', \'consumers\' or a specific tenant ID. For example: common', true) ->param('enabled', null, new Nullable(new Boolean()), 'OAuth2 sign-in method status. Set to true to enable new session creation. Setting to true will trigger end-to-end credentials validation, and will throw if the credentials are invalid.', true) ->inject('response') ->inject('dbForPlatform') @@ -148,7 +148,7 @@ class Update extends Base public function handle( ?string $applicationId, ?string $applicationSecret, - string $tenant, + ?string $tenant, ?bool $enabled, Response $response, Database $dbForPlatform, @@ -170,7 +170,7 @@ class Update extends Base } $encodedSecret = \json_encode([ 'clientSecret' => $applicationSecret ?? ($existing['clientSecret'] ?? ''), - 'tenantID' => $tenant !== '' ? $tenant : ($existing['tenantID'] ?? ''), + 'tenantID' => $tenant ?? ($existing['tenantID'] ?? ''), ]); $project = $this->persistCredentials($project, $dbForPlatform, $authorization, $applicationId, $encodedSecret, $enabled); From d4e32af792883202c047f81cfc9acce70889b908 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 30 Apr 2026 11:45:33 +0100 Subject: [PATCH 092/211] Migrate appwrite to OnDuplicate::Overwrite ('overwrite') MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Maintainer review on utopia-php/migration#171 renamed OnDuplicate::Upsert -> OnDuplicate::Overwrite (value 'upsert' -> 'overwrite') to align with Appwrite terms (skip / overwrite / fail). Applying the cross-repo ripple here: - app/controllers/api/migrations.php: 3 endpoint param descriptions updated ('upsert' -> 'overwrite' in the help text). The validator still uses OnDuplicate::values() so it auto-picks up the new value. - tests/e2e/Services/Migrations/MigrationsBase.php: all 'onDuplicate' => 'upsert' -> 'overwrite'; method names testAppwriteMigrationUpsert* -> testAppwriteMigrationOverwrite*; comments / assertion messages / local var names switched. - Left untouched: utopia's upsertDocuments operation, transaction TransactionState 'upsert' action, Operation validator — those refer to the database-level upsert primitive, not the OnDuplicate enum. composer.lock: utopia-php/migration 7d71505 -> b8ae7bc. --- app/controllers/api/migrations.php | 6 +- composer.lock | 8 +- .../Services/Migrations/MigrationsBase.php | 130 +++++++++--------- 3 files changed, 72 insertions(+), 72 deletions(-) diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index c9f810f353..73b93c4c5f 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -89,7 +89,7 @@ Http::post('/v1/migrations/appwrite') ->param('endpoint', '', new URL(), 'Source Appwrite endpoint') ->param('projectId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Source Project ID', false, ['dbForProject']) ->param('apiKey', '', new Text(512), 'Source API Key') - ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "upsert": replace existing row.', true) + ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true) ->inject('response') ->inject('dbForProject') ->inject('project') @@ -358,7 +358,7 @@ Http::post('/v1/migrations/csv/imports') ->param('fileId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'File ID.', false, ['dbForProject']) ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.') ->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true) - ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "upsert": replace existing row.', true) + ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true) ->inject('response') ->inject('dbForProject') ->inject('dbForPlatform') @@ -665,7 +665,7 @@ Http::post('/v1/migrations/json/imports') ->param('fileId', '', new UID(), 'File ID.') ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.') ->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true) - ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "upsert": replace existing row.', true) + ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true) ->inject('response') ->inject('dbForProject') ->inject('dbForPlatform') diff --git a/composer.lock b/composer.lock index 6ee740d807..191eba9608 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,12 +4532,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "7d71505ec0a5731f322bbdc83cc9bee32053df2e" + "reference": "b8ae7bc953d1897994eaa0de7e677687a19e5133" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/7d71505ec0a5731f322bbdc83cc9bee32053df2e", - "reference": "7d71505ec0a5731f322bbdc83cc9bee32053df2e", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/b8ae7bc953d1897994eaa0de7e677687a19e5133", + "reference": "b8ae7bc953d1897994eaa0de7e677687a19e5133", "shasum": "" }, "require": { @@ -4579,7 +4579,7 @@ "issues": "https://github.com/utopia-php/migration/issues", "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" }, - "time": "2026-04-28T07:10:11+00:00" + "time": "2026-04-30T10:24:12+00:00" }, { "name": "utopia-php/mongo", diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 35dfad297d..0f54eff658 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -824,20 +824,20 @@ trait MigrationsBase $this->assertEquals(200, $rowAfterSkip['headers']['status-code']); $this->assertEquals('Mutated', $rowAfterSkip['body']['name'], 'onDuplicate=skip must not overwrite destination row'); - // Re-migration with onDuplicate=upsert — strict completion; destination + // Re-migration with onDuplicate=overwrite — strict completion; destination // row restored to source value. - $upsertResult = $this->performMigrationSync([ + $overwriteResult = $this->performMigrationSync([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], - 'onDuplicate' => 'upsert', + 'onDuplicate' => 'overwrite', ]); - $this->assertEquals('completed', $upsertResult['status']); + $this->assertEquals('completed', $overwriteResult['status']); - $rowAfterUpsert = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); - $this->assertEquals(200, $rowAfterUpsert['headers']['status-code']); - $this->assertEquals('Original', $rowAfterUpsert['body']['name'], 'onDuplicate=upsert must restore source value'); + $rowAfterOverwrite = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); + $this->assertEquals(200, $rowAfterOverwrite['headers']['status-code']); + $this->assertEquals('Original', $rowAfterOverwrite['body']['name'], 'onDuplicate=overwrite must restore source value'); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); @@ -846,7 +846,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** Unchanged source under Skip/Upsert is a no-op — every resource Tolerated. */ + /** Unchanged source under Skip/Overwrite is a no-op — every resource Tolerated. */ public function testAppwriteMigrationReRunIsIdempotent(): void { $sourceHeaders = [ @@ -900,16 +900,16 @@ trait MigrationsBase ]); $this->assertEquals('completed', $reRunSkip['status']); - // Re-run under Upsert: same unchanged source. Schema tolerance path + // Re-run under Overwrite: same unchanged source. Schema tolerance path // fires for each resource; rows go through DB-native upsert. - $reRunUpsert = $this->performMigrationSync([ + $reRunOverwrite = $this->performMigrationSync([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], - 'onDuplicate' => 'upsert', + 'onDuplicate' => 'overwrite', ]); - $this->assertEquals('completed', $reRunUpsert['status']); + $this->assertEquals('completed', $reRunOverwrite['status']); foreach (['row-a', 'row-b'] as $rowId) { $check = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); @@ -924,8 +924,8 @@ trait MigrationsBase self::$cachedTableData = []; } - /** Upsert reconciles container drift via UpdateInPlace; children (rows) preserved. */ - public function testAppwriteMigrationUpsertUpdatesContainerMetadata(): void + /** Overwrite reconciles container drift via UpdateInPlace; children (rows) preserved. */ + public function testAppwriteMigrationOverwriteUpdatesContainerMetadata(): void { $sourceHeaders = [ 'content-type' => 'application/json', @@ -980,15 +980,15 @@ trait MigrationsBase 'enabled' => false, ]); - // Upsert re-migration: UpdateInPlace path fires for database + table. - $upsertResult = $this->performMigrationSync([ + // Overwrite re-migration: UpdateInPlace path fires for database + table. + $overwriteResult = $this->performMigrationSync([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], - 'onDuplicate' => 'upsert', + 'onDuplicate' => 'overwrite', ]); - $this->assertEquals('completed', $upsertResult['status']); + $this->assertEquals('completed', $overwriteResult['status']); // Assert dest database metadata reflects source's new values. $destDb = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId, $destHeaders); @@ -999,13 +999,13 @@ trait MigrationsBase $destTable = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId, $destHeaders); $this->assertEquals(200, $destTable['headers']['status-code']); $this->assertEquals('Renamed Source Table', $destTable['body']['name']); - $this->assertFalse($destTable['body']['enabled'], 'Upsert must propagate source enabled=false'); - $this->assertTrue($destTable['body']['documentSecurity'] ?? $destTable['body']['rowSecurity'], 'Upsert must propagate source rowSecurity=true'); + $this->assertFalse($destTable['body']['enabled'], 'Overwrite must propagate source enabled=false'); + $this->assertTrue($destTable['body']['documentSecurity'] ?? $destTable['body']['rowSecurity'], 'Overwrite must propagate source rowSecurity=true'); // Child row untouched — UpdateInPlace only rewrites container metadata. $row = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); $this->assertEquals(200, $row['headers']['status-code']); - $this->assertEquals('SeedRow', $row['body']['name'], 'Upsert must not touch child rows when updating container metadata'); + $this->assertEquals('SeedRow', $row['body']['name'], 'Overwrite must not touch child rows when updating container metadata'); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); @@ -1089,8 +1089,8 @@ trait MigrationsBase self::$cachedTableData = []; } - /** Upsert drops dest columns source no longer declares; cleanup runs before rows land. */ - public function testAppwriteMigrationUpsertDropsOrphanColumn(): void + /** Overwrite drops dest columns source no longer declares; cleanup runs before rows land. */ + public function testAppwriteMigrationOverwriteDropsOrphanColumn(): void { $sourceHeaders = [ 'content-type' => 'application/json', @@ -1151,23 +1151,23 @@ trait MigrationsBase 'data' => ['name' => 'seed'], ]); - // Upsert re-migration: orphan_col must be dropped from dest. - $upsertResult = $this->performMigrationSync([ + // Overwrite re-migration: orphan_col must be dropped from dest. + $overwriteResult = $this->performMigrationSync([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], - 'onDuplicate' => 'upsert', + 'onDuplicate' => 'overwrite', ]); - $this->assertEquals('completed', $upsertResult['status']); + $this->assertEquals('completed', $overwriteResult['status']); // Orphan column dropped. $orphanCheck = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/orphan_col', $destHeaders); - $this->assertEquals(404, $orphanCheck['headers']['status-code'], 'Upsert must drop destination column source no longer declares'); + $this->assertEquals(404, $orphanCheck['headers']['status-code'], 'Overwrite must drop destination column source no longer declares'); // Source's column preserved. $nameCheck = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $destHeaders); - $this->assertEquals(200, $nameCheck['headers']['status-code'], 'Upsert must preserve columns source declared'); + $this->assertEquals(200, $nameCheck['headers']['status-code'], 'Overwrite must preserve columns source declared'); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $destHeaders); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, $sourceHeaders); @@ -1176,7 +1176,7 @@ trait MigrationsBase self::$cachedTableData = []; } - /** Skip preserves orphan columns; cleanup is Upsert-only. */ + /** Skip preserves orphan columns; cleanup is Overwrite-only. */ public function testAppwriteMigrationSkipKeepsOrphanColumn(): void { $sourceHeaders = [ @@ -1253,7 +1253,7 @@ trait MigrationsBase } /** SDK-reachable attribute change propagates via updateAttributeInPlace; row data preserved. */ - public function testAppwriteMigrationUpsertUpdatesAttributeInPlace(): void + public function testAppwriteMigrationOverwriteUpdatesAttributeInPlace(): void { $sourceHeaders = [ 'content-type' => 'application/json', @@ -1320,14 +1320,14 @@ trait MigrationsBase $this->assertEquals('unknown', $r['body']['default']); }, 5000, 500); - $upsertResult = $this->performMigrationSync([ + $overwriteResult = $this->performMigrationSync([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], - 'onDuplicate' => 'upsert', + 'onDuplicate' => 'overwrite', ]); - $this->assertEquals('completed', $upsertResult['status']); + $this->assertEquals('completed', $overwriteResult['status']); $this->assertEventually(function () use ($databaseId, $tableId, $destHeaders) { $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $destHeaders); @@ -1401,7 +1401,7 @@ trait MigrationsBase sleep(1); // Source advances strictly later (and to a different value). Under - // Upsert this would propagate to dest; under Skip it must not. + // Overwrite this would propagate to dest; under Skip it must not. $sourcePatch = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/string/name', $sourceHeaders, [ 'required' => true, 'default' => null, @@ -1437,7 +1437,7 @@ trait MigrationsBase } /** Two-way onDelete change updates in place on both sides; partner meta refreshed by hand. */ - public function testAppwriteMigrationUpsertUpdatesRelationshipOnDeleteInPlace(): void + public function testAppwriteMigrationOverwriteUpdatesRelationshipOnDeleteInPlace(): void { $sourceHeaders = [ 'content-type' => 'application/json', @@ -1525,14 +1525,14 @@ trait MigrationsBase $this->assertEquals(Database::RELATION_MUTATE_RESTRICT, $r['body']['onDelete']); }, 5000, 500); - $upsertResult = $this->performMigrationSync([ + $overwriteResult = $this->performMigrationSync([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], - 'onDuplicate' => 'upsert', + 'onDuplicate' => 'overwrite', ]); - $this->assertEquals('completed', $upsertResult['status']); + $this->assertEquals('completed', $overwriteResult['status']); // Both sides on dest must reflect onDelete=restrict. Asserting the // partner side is the regression guard for the previously-missed @@ -1559,7 +1559,7 @@ trait MigrationsBase } /** Two-way recreate with same spec: spec-match guard tolerates parent; pair-key dedup tolerates partner. Both sides + child rows preserved. */ - public function testAppwriteMigrationUpsertTwoWayRecreateSkipsPartnerSide(): void + public function testAppwriteMigrationOverwriteTwoWayRecreateSkipsPartnerSide(): void { $sourceHeaders = [ 'content-type' => 'application/json', @@ -1670,14 +1670,14 @@ trait MigrationsBase ]); $this->assertEquals(200, $relink['headers']['status-code']); - $upsertResult = $this->performMigrationSync([ + $overwriteResult = $this->performMigrationSync([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], - 'onDuplicate' => 'upsert', + 'onDuplicate' => 'overwrite', ]); - $this->assertEquals('completed', $upsertResult['status']); + $this->assertEquals('completed', $overwriteResult['status']); $this->assertEventually(function () use ($databaseId, $destHeaders) { $parent = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $destHeaders); @@ -1704,7 +1704,7 @@ trait MigrationsBase } /** One-way + onDelete change falls through to DropAndRecreate (in-place gated off for one-way). */ - public function testAppwriteMigrationUpsertOneWayRelationshipDropAndRecreate(): void + public function testAppwriteMigrationOverwriteOneWayRelationshipDropAndRecreate(): void { $sourceHeaders = [ 'content-type' => 'application/json', @@ -1781,14 +1781,14 @@ trait MigrationsBase $this->assertEquals(Database::RELATION_MUTATE_RESTRICT, $r['body']['onDelete']); }, 5000, 500); - $upsertResult = $this->performMigrationSync([ + $overwriteResult = $this->performMigrationSync([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], - 'onDuplicate' => 'upsert', + 'onDuplicate' => 'overwrite', ]); - $this->assertEquals('completed', $upsertResult['status']); + $this->assertEquals('completed', $overwriteResult['status']); $this->assertEventually(function () use ($databaseId, $destHeaders) { $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/kids', $destHeaders); @@ -1807,7 +1807,7 @@ trait MigrationsBase } /** Recreate with non-SDK spec change (array toggle): updateAttributeInPlace bails → drop+recreate; row pass refills. */ - public function testAppwriteMigrationUpsertAttributeRecreateDropsAndRecreates(): void + public function testAppwriteMigrationOverwriteAttributeRecreateDropsAndRecreates(): void { $sourceHeaders = [ 'content-type' => 'application/json', @@ -1882,14 +1882,14 @@ trait MigrationsBase ]); $this->assertEquals(200, $relink['headers']['status-code']); - $upsertResult = $this->performMigrationSync([ + $overwriteResult = $this->performMigrationSync([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], - 'onDuplicate' => 'upsert', + 'onDuplicate' => 'overwrite', ]); - $this->assertEquals('completed', $upsertResult['status']); + $this->assertEquals('completed', $overwriteResult['status']); $this->assertEventually(function () use ($databaseId, $tableId, $destHeaders) { $col = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/name', $destHeaders); @@ -1911,7 +1911,7 @@ trait MigrationsBase } /** Source drops+recreates with SAME spec: spec-match guard forces Tolerate; dest meta untouched. */ - public function testAppwriteMigrationUpsertSameSpecRecreateTolerates(): void + public function testAppwriteMigrationOverwriteSameSpecRecreateTolerates(): void { $sourceHeaders = [ 'content-type' => 'application/json', @@ -1984,14 +1984,14 @@ trait MigrationsBase ]); $this->assertEquals(200, $relink['headers']['status-code']); - $upsertResult = $this->performMigrationSync([ + $overwriteResult = $this->performMigrationSync([ 'resources' => $resources, 'endpoint' => $this->webEndpoint, 'projectId' => $this->getProject()['$id'], 'apiKey' => $this->getProject()['apiKey'], - 'onDuplicate' => 'upsert', + 'onDuplicate' => 'overwrite', ]); - $this->assertEquals('completed', $upsertResult['status']); + $this->assertEquals('completed', $overwriteResult['status']); // Spec-match guard fired → dest column's $createdAt stayed at the // first-migration value. If DropAndRecreate had run, $createdAt @@ -2002,7 +2002,7 @@ trait MigrationsBase $this->assertEquals(100, $destAfter['body']['size']); $this->assertTrue($destAfter['body']['required']); - // Row pass under Upsert still propagated source's new row value. + // Row pass under Overwrite still propagated source's new row value. $rowAfter = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, $destHeaders); $this->assertEquals(200, $rowAfter['headers']['status-code']); $this->assertEquals('after-recreate', $rowAfter['body']['name']); @@ -2884,7 +2884,7 @@ trait MigrationsBase } /** - * onDuplicate=upsert on re-import: existing rows are replaced with imported values. + * onDuplicate=overwrite on re-import: existing rows are replaced with imported values. */ public function testCreateCSVImportOverwrite(): void { @@ -2905,7 +2905,7 @@ trait MigrationsBase $this->assertEquals(100, $migration['body']['statusCounters'][Resource::TYPE_ROW]['success']); }, 10_000, 500); - // Mutate one row so we can prove upsert restores it to the CSV's original value + // Mutate one row so we can prove overwrite restores it to the CSV's original value $mutate = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -2916,12 +2916,12 @@ trait MigrationsBase $this->assertEquals(200, $mutate['headers']['status-code']); $this->assertEquals(22, $mutate['body']['age']); - // Second import with onDuplicate=upsert: mutated row restored to CSV value + // Second import with onDuplicate=overwrite: mutated row restored to CSV value $second = $this->performCsvMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, 'resourceId' => $databaseId . ':' . $tableId, - 'onDuplicate' => 'upsert', + 'onDuplicate' => 'overwrite', ]); $this->assertEventually(function () use ($second) { $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $second['body']['$id'], array_merge([ @@ -2931,14 +2931,14 @@ trait MigrationsBase $this->assertEquals('completed', $migration['body']['status']); }, 10_000, 500); - // Mutated row is back to CSV's original age (proving upsert actually replaced the row) + // Mutated row is back to CSV's original age (proving overwrite actually replaced the row) $row = $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, $row['headers']['status-code']); $this->assertEquals($originalName, $row['body']['name']); - $this->assertEquals($originalAge, $row['body']['age'], 'onDuplicate=upsert must restore row to imported value'); + $this->assertEquals($originalAge, $row['body']['age'], 'onDuplicate=overwrite must restore row to imported value'); // Row count still 100 (no duplicates created) $rows = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ @@ -3141,7 +3141,7 @@ trait MigrationsBase } /** - * onDuplicate=upsert on JSON re-import: existing rows replaced with imported values. + * onDuplicate=overwrite on JSON re-import: existing rows replaced with imported values. */ public function testCreateJSONImportOverwrite(): void { @@ -3175,7 +3175,7 @@ trait MigrationsBase 'fileId' => $fileId, 'bucketId' => $bucketId, 'resourceId' => $databaseId . ':' . $tableId, - 'onDuplicate' => 'upsert', + 'onDuplicate' => 'overwrite', ]); $this->assertEventually(function () use ($second) { $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $second['body']['$id'], array_merge([ @@ -3191,7 +3191,7 @@ trait MigrationsBase ], $this->getHeaders())); $this->assertEquals(200, $row['headers']['status-code']); $this->assertEquals($originalName, $row['body']['name']); - $this->assertEquals($originalAge, $row['body']['age'], 'onDuplicate=upsert must restore row to imported value'); + $this->assertEquals($originalAge, $row['body']['age'], 'onDuplicate=overwrite must restore row to imported value'); $rows = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([ 'content-type' => 'application/json', From 71300383b2cb7aadb1c20fa3fc40e08b7b9b7d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 30 Apr 2026 12:48:59 +0200 Subject: [PATCH 093/211] Update tests --- tests/e2e/Services/Project/OAuth2Base.php | 202 ++++++++++++---------- 1 file changed, 110 insertions(+), 92 deletions(-) diff --git a/tests/e2e/Services/Project/OAuth2Base.php b/tests/e2e/Services/Project/OAuth2Base.php index 9ff3830ec5..5451435c3c 100644 --- a/tests/e2e/Services/Project/OAuth2Base.php +++ b/tests/e2e/Services/Project/OAuth2Base.php @@ -872,30 +872,36 @@ trait OAuth2Base } // ========================================================================= - // Update Authentik (clientId + clientSecret + REQUIRED endpoint) + // Update Authentik (clientId + clientSecret + optional endpoint) // ========================================================================= - public function testUpdateOAuth2AuthentikRequiresEndpoint(): void + public function testUpdateOAuth2AuthentikAllowsOmittedEndpointWhenDisabled(): void { - // The `endpoint` param is required (Text(min=1)); omitting → 400. $response = $this->updateOAuth2('authentik', [ 'clientId' => 'whatever', 'clientSecret' => 'whatever', + 'enabled' => false, ]); - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame('authentik', $response['body']['$id']); + + // Cleanup + $this->updateOAuth2('authentik', [ + 'clientId' => '', + 'clientSecret' => '', + 'endpoint' => '', + 'enabled' => false, + ]); } - public function testUpdateOAuth2AuthentikEmptyEndpointRejected(): void + public function testUpdateOAuth2AuthentikEmptyEndpointRejectedWhenEnabling(): void { - // The `endpoint` validator is Text(min=1). Sending `''` must be - // rejected the same way as omitting — the validator should treat the - // empty-string degenerate case as a missing required field. $response = $this->updateOAuth2('authentik', [ 'clientId' => 'whatever', 'clientSecret' => 'whatever', 'endpoint' => '', + 'enabled' => true, ]); $this->assertSame(400, $response['headers']['status-code']); @@ -920,15 +926,14 @@ trait OAuth2Base $this->updateOAuth2('authentik', [ 'clientId' => '', 'clientSecret' => '', - 'endpoint' => 'cleanup.authentik.com', + 'endpoint' => '', 'enabled' => false, ]); } public function testUpdateOAuth2AuthentikPartialPreservesSecret(): void { - // Authentik's `endpoint` is required on every call, so we always - // re-send it. The `clientSecret` lives in the JSON blob and must + // The `clientSecret` and `endpoint` live in the JSON blob and must // survive when omitted on a subsequent call that only changes clientId. $this->updateOAuth2('authentik', [ 'clientId' => 'authentik-merge-client', @@ -939,27 +944,24 @@ trait OAuth2Base $response = $this->updateOAuth2('authentik', [ 'clientId' => 'authentik-rotated-client', - 'endpoint' => 'merge.authentik.com', ]); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame('authentik-rotated-client', $response['body']['clientId']); $this->assertSame('merge.authentik.com', $response['body']['endpoint']); // Confirm clientSecret survived the omitted-field merge by enabling - // — Authentik has no verifyCredentials() hook, so non-empty stored - // secret is enough. `endpoint` must be re-sent (required on enable too). + // without re-sending endpoint. $enable = $this->updateOAuth2('authentik', [ - 'endpoint' => 'merge.authentik.com', 'enabled' => true, ]); $this->assertSame(200, $enable['headers']['status-code']); $this->assertTrue($enable['body']['enabled']); - // Cleanup — endpoint is required, use a placeholder. + // Cleanup $this->updateOAuth2('authentik', [ 'clientId' => '', 'clientSecret' => '', - 'endpoint' => 'cleanup.authentik.com', + 'endpoint' => '', 'enabled' => false, ]); } @@ -984,40 +986,46 @@ trait OAuth2Base $this->assertSame('enable.authentik.com', $get['body']['endpoint']); $this->assertSame('', $get['body']['clientSecret']); - // Cleanup — endpoint is required (Text(min=1)) so use a placeholder. + // Cleanup $this->updateOAuth2('authentik', [ 'clientId' => '', 'clientSecret' => '', - 'endpoint' => 'cleanup.authentik.com', + 'endpoint' => '', 'enabled' => false, ]); } // ========================================================================= - // Update FusionAuth (clientId + clientSecret + REQUIRED endpoint) + // Update FusionAuth (clientId + clientSecret + optional endpoint) // ========================================================================= - public function testUpdateOAuth2FusionAuthRequiresEndpoint(): void + public function testUpdateOAuth2FusionAuthAllowsOmittedEndpointWhenDisabled(): void { - // The `endpoint` param is required (Text(min=1)); omitting → 400. $response = $this->updateOAuth2('fusionauth', [ 'clientId' => 'whatever', 'clientSecret' => 'whatever', + 'enabled' => false, ]); - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame('fusionauth', $response['body']['$id']); + + // Cleanup + $this->updateOAuth2('fusionauth', [ + 'clientId' => '', + 'clientSecret' => '', + 'endpoint' => '', + 'enabled' => false, + ]); } - public function testUpdateOAuth2FusionAuthEmptyEndpointRejected(): void + public function testUpdateOAuth2FusionAuthEmptyEndpointRejectedWhenEnabling(): void { - // The `endpoint` validator is Text(min=1). Sending `''` must be - // rejected the same way as omitting — the validator should treat the - // empty-string degenerate case as a missing required field. $response = $this->updateOAuth2('fusionauth', [ 'clientId' => 'whatever', 'clientSecret' => 'whatever', 'endpoint' => '', + 'enabled' => true, ]); $this->assertSame(400, $response['headers']['status-code']); @@ -1042,15 +1050,14 @@ trait OAuth2Base $this->updateOAuth2('fusionauth', [ 'clientId' => '', 'clientSecret' => '', - 'endpoint' => 'cleanup.fusionauth.io', + 'endpoint' => '', 'enabled' => false, ]); } public function testUpdateOAuth2FusionAuthPartialPreservesSecret(): void { - // FusionAuth's `endpoint` is required on every call, so we always - // re-send it. The `clientSecret` lives in the JSON blob and must + // The `clientSecret` and `endpoint` live in the JSON blob and must // survive when omitted on a subsequent call that only changes clientId. $this->updateOAuth2('fusionauth', [ 'clientId' => 'fusionauth-merge-client', @@ -1061,27 +1068,24 @@ trait OAuth2Base $response = $this->updateOAuth2('fusionauth', [ 'clientId' => 'fusionauth-rotated-client', - 'endpoint' => 'merge.fusionauth.io', ]); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame('fusionauth-rotated-client', $response['body']['clientId']); $this->assertSame('merge.fusionauth.io', $response['body']['endpoint']); // Confirm clientSecret survived the omitted-field merge by enabling - // — FusionAuth has no verifyCredentials() hook, so non-empty stored - // secret is enough. `endpoint` must be re-sent (required on enable too). + // without re-sending endpoint. $enable = $this->updateOAuth2('fusionauth', [ - 'endpoint' => 'merge.fusionauth.io', 'enabled' => true, ]); $this->assertSame(200, $enable['headers']['status-code']); $this->assertTrue($enable['body']['enabled']); - // Cleanup — endpoint is required, use a placeholder. + // Cleanup $this->updateOAuth2('fusionauth', [ 'clientId' => '', 'clientSecret' => '', - 'endpoint' => 'cleanup.fusionauth.io', + 'endpoint' => '', 'enabled' => false, ]); } @@ -1106,70 +1110,85 @@ trait OAuth2Base $this->assertSame('enable.fusionauth.io', $get['body']['endpoint']); $this->assertSame('', $get['body']['clientSecret']); - // Cleanup — endpoint is required (Text(min=1)) so use a placeholder. + // Cleanup $this->updateOAuth2('fusionauth', [ 'clientId' => '', 'clientSecret' => '', - 'endpoint' => 'cleanup.fusionauth.io', + 'endpoint' => '', 'enabled' => false, ]); } // ========================================================================= - // Update Keycloak (clientId + clientSecret + REQUIRED endpoint + REQUIRED realmName) + // Update Keycloak (clientId + clientSecret + optional endpoint + optional realmName) // ========================================================================= - public function testUpdateOAuth2KeycloakRequiresEndpoint(): void + public function testUpdateOAuth2KeycloakAllowsOmittedEndpointWhenDisabled(): void { - // The `endpoint` param is required (Text(min=1)); omitting → 400. $response = $this->updateOAuth2('keycloak', [ 'clientId' => 'whatever', 'clientSecret' => 'whatever', 'realmName' => 'appwrite-realm', + 'enabled' => false, ]); - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame('keycloak', $response['body']['$id']); + + // Cleanup + $this->updateOAuth2('keycloak', [ + 'clientId' => '', + 'clientSecret' => '', + 'endpoint' => '', + 'realmName' => '', + 'enabled' => false, + ]); } - public function testUpdateOAuth2KeycloakEmptyEndpointRejected(): void + public function testUpdateOAuth2KeycloakEmptyEndpointRejectedWhenEnabling(): void { - // The `endpoint` validator is Text(min=1). Sending `''` must be - // rejected the same way as omitting — the validator should treat the - // empty-string degenerate case as a missing required field. $response = $this->updateOAuth2('keycloak', [ 'clientId' => 'whatever', 'clientSecret' => 'whatever', 'endpoint' => '', 'realmName' => 'appwrite-realm', + 'enabled' => true, ]); $this->assertSame(400, $response['headers']['status-code']); $this->assertSame('general_argument_invalid', $response['body']['type']); } - public function testUpdateOAuth2KeycloakRequiresRealmName(): void + public function testUpdateOAuth2KeycloakAllowsOmittedRealmNameWhenDisabled(): void { - // The `realmName` param is required (Text(min=1)); omitting → 400. $response = $this->updateOAuth2('keycloak', [ 'clientId' => 'whatever', 'clientSecret' => 'whatever', 'endpoint' => 'keycloak.example.com', + 'enabled' => false, ]); - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame('keycloak', $response['body']['$id']); + + // Cleanup + $this->updateOAuth2('keycloak', [ + 'clientId' => '', + 'clientSecret' => '', + 'endpoint' => '', + 'realmName' => '', + 'enabled' => false, + ]); } - public function testUpdateOAuth2KeycloakEmptyRealmNameRejected(): void + public function testUpdateOAuth2KeycloakEmptyRealmNameRejectedWhenEnabling(): void { - // The `realmName` validator is Text(min=1). Sending `''` must be - // rejected the same way as omitting. $response = $this->updateOAuth2('keycloak', [ 'clientId' => 'whatever', 'clientSecret' => 'whatever', 'endpoint' => 'keycloak.example.com', 'realmName' => '', + 'enabled' => true, ]); $this->assertSame(400, $response['headers']['status-code']); @@ -1196,16 +1215,15 @@ trait OAuth2Base $this->updateOAuth2('keycloak', [ 'clientId' => '', 'clientSecret' => '', - 'endpoint' => 'cleanup.keycloak.com', - 'realmName' => 'cleanup-realm', + 'endpoint' => '', + 'realmName' => '', 'enabled' => false, ]); } public function testUpdateOAuth2KeycloakPartialPreservesSecret(): void { - // Keycloak's `endpoint` and `realmName` are required on every call, - // so we always re-send them. The `clientSecret` lives in the JSON + // The `clientSecret`, `endpoint`, and `realmName` live in the JSON // blob and must survive when omitted on a subsequent call that only // changes clientId. $this->updateOAuth2('keycloak', [ @@ -1218,8 +1236,6 @@ trait OAuth2Base $response = $this->updateOAuth2('keycloak', [ 'clientId' => 'keycloak-rotated-client', - 'endpoint' => 'merge.keycloak.com', - 'realmName' => 'merge-realm', ]); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame('keycloak-rotated-client', $response['body']['clientId']); @@ -1227,23 +1243,19 @@ trait OAuth2Base $this->assertSame('merge-realm', $response['body']['realmName']); // Confirm clientSecret survived the omitted-field merge by enabling - // — Keycloak has no verifyCredentials() hook, so non-empty stored - // secret is enough. `endpoint`/`realmName` must be re-sent (required - // on enable too). + // without re-sending endpoint or realmName. $enable = $this->updateOAuth2('keycloak', [ - 'endpoint' => 'merge.keycloak.com', - 'realmName' => 'merge-realm', 'enabled' => true, ]); $this->assertSame(200, $enable['headers']['status-code']); $this->assertTrue($enable['body']['enabled']); - // Cleanup — endpoint and realmName are required, use placeholders. + // Cleanup $this->updateOAuth2('keycloak', [ 'clientId' => '', 'clientSecret' => '', - 'endpoint' => 'cleanup.keycloak.com', - 'realmName' => 'cleanup-realm', + 'endpoint' => '', + 'realmName' => '', 'enabled' => false, ]); } @@ -1270,40 +1282,47 @@ trait OAuth2Base $this->assertSame('enable-realm', $get['body']['realmName']); $this->assertSame('', $get['body']['clientSecret']); - // Cleanup — endpoint and realmName are required (Text(min=1)) so use placeholders. + // Cleanup $this->updateOAuth2('keycloak', [ 'clientId' => '', 'clientSecret' => '', - 'endpoint' => 'cleanup.keycloak.com', - 'realmName' => 'cleanup-realm', + 'endpoint' => '', + 'realmName' => '', 'enabled' => false, ]); } // ========================================================================= - // Update Microsoft (applicationId + applicationSecret + REQUIRED tenant) + // Update Microsoft (applicationId + applicationSecret + optional tenant) // ========================================================================= - public function testUpdateOAuth2MicrosoftRequiresTenant(): void + public function testUpdateOAuth2MicrosoftAllowsOmittedTenantWhenDisabled(): void { $response = $this->updateOAuth2('microsoft', [ 'applicationId' => 'whatever', 'applicationSecret' => 'whatever', + 'enabled' => false, ]); - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame('microsoft', $response['body']['$id']); + + // Cleanup + $this->updateOAuth2('microsoft', [ + 'applicationId' => '', + 'applicationSecret' => '', + 'tenant' => '', + 'enabled' => false, + ]); } - public function testUpdateOAuth2MicrosoftEmptyTenantRejected(): void + public function testUpdateOAuth2MicrosoftEmptyTenantRejectedWhenEnabling(): void { - // The `tenant` validator is Text(min=1). Sending `''` must be rejected - // the same way as omitting — the validator should treat the empty - // string as a missing required field. $response = $this->updateOAuth2('microsoft', [ 'applicationId' => 'whatever', 'applicationSecret' => 'whatever', 'tenant' => '', + 'enabled' => true, ]); $this->assertSame(400, $response['headers']['status-code']); @@ -1331,7 +1350,7 @@ trait OAuth2Base $this->updateOAuth2('microsoft', [ 'applicationId' => '', 'applicationSecret' => '', - 'tenant' => 'common', + 'tenant' => '', 'enabled' => false, ]); } @@ -1346,23 +1365,21 @@ trait OAuth2Base 'enabled' => false, ]); - // Patch with only `tenant` (it's required on every call) and a new - // applicationId, leaving applicationSecret omitted. The stored secret - // must not be wiped. + // Patch with only a new applicationId, leaving applicationSecret and + // tenant omitted. The stored JSON values must not be wiped. $response = $this->updateOAuth2('microsoft', [ 'applicationId' => 'updated-app-id', - 'tenant' => 'organizations', ]); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame('updated-app-id', $response['body']['applicationId']); - $this->assertSame('organizations', $response['body']['tenant']); + $this->assertSame('common', $response['body']['tenant']); // Cleanup $this->updateOAuth2('microsoft', [ 'applicationId' => '', 'applicationSecret' => '', - 'tenant' => 'common', + 'tenant' => '', 'enabled' => false, ]); } @@ -1387,11 +1404,11 @@ trait OAuth2Base $this->assertSame('common', $get['body']['tenant']); $this->assertSame('', $get['body']['applicationSecret']); - // Cleanup — tenant is required (Text(min=1)) so use a placeholder. + // Cleanup $this->updateOAuth2('microsoft', [ 'applicationId' => '', 'applicationSecret' => '', - 'tenant' => 'common', + 'tenant' => '', 'enabled' => false, ]); } @@ -2401,8 +2418,9 @@ trait OAuth2Base // // Ensures each provider's Update endpoint is wired up correctly: routing, // provider class, response model and `$id`. Custom-shaped providers - // (apple, auth0, authentik, gitlab, microsoft, oidc, okta, dropbox) and - // sandboxes (paypalSandbox, tradeshiftSandbox) have dedicated tests above. + // (apple, auth0, authentik, fusionauth, gitlab, keycloak, microsoft, oidc, + // okta, dropbox) and sandboxes (paypalSandbox, tradeshiftSandbox) have + // dedicated tests above. // Github is excluded because its `verifyCredentials()` hook is exercised // separately. // ========================================================================= From b79637eef51a7cb900491d3d6e15b2ef5e8a49fb Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 30 Apr 2026 17:01:57 +0100 Subject: [PATCH 094/211] Re-add onDuplicate param to modular migration endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.9.x reorganized app/controllers/api/migrations.php into the Platform/Modules/Migrations structure but dropped the onDuplicate param. After the merge, every e2e migration test that passed 'onDuplicate' => 'overwrite' would 400 since the param wasn't in the allowlist anymore. Restoring it on the three endpoints that take row-level conflict behavior: Appwrite/Create, CSV/Imports/Create, JSON/Imports/Create. Each: - Imports OnDuplicate + WhiteList. - Adds optional ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), …). - Threads $onDuplicate through the action signature. - Stores it on the migration document's 'options' attribute so Workers/Migrations.php can pick it up via OnDuplicate::tryFrom($options['onDuplicate'] ?? '') ?? OnDuplicate::Fail. Worker code already reads options['onDuplicate'] (unchanged) — no edits needed there. --- .../Modules/Migrations/Http/Migrations/Appwrite/Create.php | 6 ++++++ .../Migrations/Http/Migrations/CSV/Imports/Create.php | 5 +++++ .../Migrations/Http/Migrations/JSON/Imports/Create.php | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Appwrite/Create.php b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Appwrite/Create.php index 006ab3ae90..fa700877a1 100644 --- a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Appwrite/Create.php +++ b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Appwrite/Create.php @@ -13,6 +13,7 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Validator\UID; +use Utopia\Migration\Destinations\OnDuplicate; use Utopia\Migration\Sources\Appwrite as AppwriteSource; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; @@ -57,6 +58,7 @@ class Create extends Action ->param('endpoint', '', new URL(), 'Source Appwrite endpoint') ->param('projectId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Source Project ID', false, ['dbForProject']) ->param('apiKey', '', new Text(512), 'Source API Key') + ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true) ->inject('response') ->inject('dbForProject') ->inject('project') @@ -71,6 +73,7 @@ class Create extends Action string $endpoint, string $projectId, string $apiKey, + string $onDuplicate, Response $response, Database $dbForProject, Document $project, @@ -93,6 +96,9 @@ class Create extends Action 'statusCounters' => '{}', 'resourceData' => '{}', 'errors' => [], + 'options' => [ + 'onDuplicate' => $onDuplicate, + ], ])); $queueForEvents->setParam('migrationId', $migration->getId()); diff --git a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Imports/Create.php b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Imports/Create.php index 5cc21241c3..4b47ed7d58 100644 --- a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Imports/Create.php +++ b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Imports/Create.php @@ -20,6 +20,7 @@ use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; +use Utopia\Migration\Destinations\OnDuplicate; use Utopia\Migration\Resource; use Utopia\Migration\Sources\Appwrite as AppwriteSource; use Utopia\Migration\Sources\CSV; @@ -29,6 +30,7 @@ use Utopia\Platform\Scope\HTTP; use Utopia\Storage\Device; use Utopia\System\System; use Utopia\Validator\Boolean; +use Utopia\Validator\WhiteList; class Create extends Action { @@ -67,6 +69,7 @@ class Create extends Action ->param('fileId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'File ID.', false, ['dbForProject']) ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.') ->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true) + ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true) ->inject('response') ->inject('dbForProject') ->inject('dbForPlatform') @@ -85,6 +88,7 @@ class Create extends Action string $fileId, string $resourceId, bool $internalFile, + string $onDuplicate, Response $response, Database $dbForProject, Database $dbForPlatform, @@ -183,6 +187,7 @@ class Create extends Action 'options' => [ 'path' => $newPath, 'size' => $fileSize, + 'onDuplicate' => $onDuplicate, ], ])); diff --git a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/JSON/Imports/Create.php b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/JSON/Imports/Create.php index 55081b2645..c5d936711e 100644 --- a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/JSON/Imports/Create.php +++ b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/JSON/Imports/Create.php @@ -20,6 +20,7 @@ use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; +use Utopia\Migration\Destinations\OnDuplicate; use Utopia\Migration\Resource; use Utopia\Migration\Sources\Appwrite as AppwriteSource; use Utopia\Migration\Sources\JSON as JSONSource; @@ -29,6 +30,7 @@ use Utopia\Platform\Scope\HTTP; use Utopia\Storage\Device; use Utopia\System\System; use Utopia\Validator\Boolean; +use Utopia\Validator\WhiteList; class Create extends Action { @@ -66,6 +68,7 @@ class Create extends Action ->param('fileId', '', new UID(), 'File ID.') ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.') ->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true) + ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true) ->inject('response') ->inject('dbForProject') ->inject('dbForPlatform') @@ -84,6 +87,7 @@ class Create extends Action string $fileId, string $resourceId, bool $internalFile, + string $onDuplicate, Response $response, Database $dbForProject, Database $dbForPlatform, @@ -183,6 +187,7 @@ class Create extends Action 'options' => [ 'path' => $newPath, 'size' => $fileSize, + 'onDuplicate' => $onDuplicate, ], ])); From 65f926b4c58c75c4b0704901462b19646e74d09e Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 1 May 2026 18:55:13 +0530 Subject: [PATCH 095/211] Update appwrite runtimes to 0.20 --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 683da6f21b..735955d980 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "ext-openssl": "*", "ext-zlib": "*", "ext-sockets": "*", - "appwrite/php-runtimes": "0.19.*", + "appwrite/php-runtimes": "0.20.*", "appwrite/php-clamav": "2.0.*", "utopia-php/abuse": "1.2.*", "utopia-php/agents": "1.2.*", diff --git a/composer.lock b/composer.lock index 3edbc39614..2889069e67 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": "4bee36b21a57e754d2b3417e72dc9599", + "content-hash": "bd45829c252971301370d62300be106d", "packages": [ { "name": "adhocore/jwt", @@ -161,16 +161,16 @@ }, { "name": "appwrite/php-runtimes", - "version": "0.19.5", + "version": "0.20.0", "source": { "type": "git", "url": "https://github.com/appwrite/runtimes.git", - "reference": "aa2f7760cd0493c0880209b92df812c9386b3546" + "reference": "7d9b7f4eef5c0a142a60907b06de2219d025c5c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/runtimes/zipball/aa2f7760cd0493c0880209b92df812c9386b3546", - "reference": "aa2f7760cd0493c0880209b92df812c9386b3546", + "url": "https://api.github.com/repos/appwrite/runtimes/zipball/7d9b7f4eef5c0a142a60907b06de2219d025c5c3", + "reference": "7d9b7f4eef5c0a142a60907b06de2219d025c5c3", "shasum": "" }, "require": { @@ -210,9 +210,9 @@ ], "support": { "issues": "https://github.com/appwrite/runtimes/issues", - "source": "https://github.com/appwrite/runtimes/tree/0.19.5" + "source": "https://github.com/appwrite/runtimes/tree/0.20.0" }, - "time": "2026-04-01T01:39:23+00:00" + "time": "2026-05-01T07:47:07+00:00" }, { "name": "brick/math", From 413930a15edd9f630ee29483964073a585bc148a Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Sat, 2 May 2026 12:10:03 +0530 Subject: [PATCH 096/211] Add Rust starter function template runtime --- app/config/templates/function.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/config/templates/function.php b/app/config/templates/function.php index df3a569705..c6ac446509 100644 --- a/app/config/templates/function.php +++ b/app/config/templates/function.php @@ -79,12 +79,13 @@ return [ ...getRuntimes($templateRuntimes['DENO'], 'deno cache src/main.ts', 'src/main.ts', 'deno/starter', $allowList), ...getRuntimes($templateRuntimes['BUN'], 'bun install', 'src/main.ts', 'bun/starter', $allowList), ...getRuntimes($templateRuntimes['RUBY'], 'bundle install', 'lib/main.rb', 'ruby/starter', $allowList), + ...getRuntimes($templateRuntimes['RUST'], '', 'main.rs', 'rust/starter', $allowList), ], - 'instructions' => 'For documentation and instructions check out file.', + 'instructions' => 'For documentation and instructions check out the templates repository.', 'vcsProvider' => 'github', 'providerRepositoryId' => 'templates', 'providerOwner' => 'appwrite', - 'providerVersion' => '0.2.*', + 'providerVersion' => '0.3.*', 'variables' => [], 'scopes' => ['users.read'] ], From 7f27851dab09b52f5abba84af1bdff009d936215 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Sun, 3 May 2026 15:15:27 +0100 Subject: [PATCH 097/211] chore: bump base image to 1.3.1 Co-Authored-By: Claude Opus 4.7 (1M context) --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1922a0d2b9..5f43b1527f 100755 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN composer install --ignore-platform-reqs --optimize-autoloader \ --no-plugins --no-scripts --prefer-dist \ `if [ "$TESTING" != "true" ]; then echo "--no-dev"; fi` -FROM appwrite/base:1.2.1 AS base +FROM appwrite/base:1.3.1 AS base LABEL maintainer="team@appwrite.io" From 4e20e382d21647c44f6d41445467d7768477c67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sun, 3 May 2026 19:49:13 +0200 Subject: [PATCH 098/211] Add deprecated function scopes --- app/config/scopes/project.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/config/scopes/project.php b/app/config/scopes/project.php index 63b946f74f..3aaf5469de 100644 --- a/app/config/scopes/project.php +++ b/app/config/scopes/project.php @@ -210,10 +210,20 @@ return [ 'executions.read' => [ 'description' => 'Access to read function executions', 'category' => 'Functions', + 'deprecated' => true, ], 'executions.write' => [ 'description' => 'Access to create function executions', 'category' => 'Functions', + 'deprecated' => true, + ], + 'execution.read' => [ + 'description' => 'Access to read function executions. This scope is deprecated for consistency purposes, and replaced by `executions.read`.', + 'category' => 'Functions', + ], + 'execution.write' => [ + 'description' => 'Access to create function executions. This scope is deprecated for consistency purposes, and replaced by `executions.write`.', + 'category' => 'Functions', ], // Sites From 6051b8150c5bf671db43ab93b6f6e7bec0f18e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sun, 3 May 2026 19:51:10 +0200 Subject: [PATCH 099/211] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matej Bačo --- app/config/scopes/project.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/config/scopes/project.php b/app/config/scopes/project.php index 3aaf5469de..716caa3b8e 100644 --- a/app/config/scopes/project.php +++ b/app/config/scopes/project.php @@ -210,7 +210,6 @@ return [ 'executions.read' => [ 'description' => 'Access to read function executions', 'category' => 'Functions', - 'deprecated' => true, ], 'executions.write' => [ 'description' => 'Access to create function executions', From 8f68a59a797e9297b9229bc19c318502b6ef7893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sun, 3 May 2026 19:51:56 +0200 Subject: [PATCH 100/211] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matej Bačo --- app/config/scopes/project.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/config/scopes/project.php b/app/config/scopes/project.php index 716caa3b8e..a048920de9 100644 --- a/app/config/scopes/project.php +++ b/app/config/scopes/project.php @@ -214,15 +214,16 @@ return [ 'executions.write' => [ 'description' => 'Access to create function executions', 'category' => 'Functions', - 'deprecated' => true, ], 'execution.read' => [ 'description' => 'Access to read function executions. This scope is deprecated for consistency purposes, and replaced by `executions.read`.', 'category' => 'Functions', + 'deprecated' => true, ], 'execution.write' => [ 'description' => 'Access to create function executions. This scope is deprecated for consistency purposes, and replaced by `executions.write`.', 'category' => 'Functions', + 'deprecated' => true, ], // Sites From 92eceba2181134d19263ec90fdd6bddd5237c8f2 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Sun, 3 May 2026 19:21:00 +0100 Subject: [PATCH 101/211] chore: bump base image to 1.4.1 Co-Authored-By: Claude Opus 4.7 (1M context) --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5f43b1527f..9a61635415 100755 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN composer install --ignore-platform-reqs --optimize-autoloader \ --no-plugins --no-scripts --prefer-dist \ `if [ "$TESTING" != "true" ]; then echo "--no-dev"; fi` -FROM appwrite/base:1.3.1 AS base +FROM appwrite/base:1.4.1 AS base LABEL maintainer="team@appwrite.io" From 4703e4ba1465d78dbc7228f9ab66ef64111fecc4 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 4 May 2026 05:05:00 +0100 Subject: [PATCH 102/211] Gate Sentry logging in migrations worker by exception type The outer catch in the migrations worker now only calls logError when the caught Throwable is not a MigrationException. User-facing setup errors (invalid source type, missing project, etc.) are thrown as MigrationException with appropriate codes and stay in the migration report only. Removed the foreach loop that re-published collected errors to Sentry; with the library-side fix in utopia-php/migration, items in $source->getErrors() / $destination->getErrors() are by construction user errors that don't need Sentry routing. Hoisted setAttribute('errors', sanitizeErrors(...)) into finally so the migration document always reflects the consolidated error list, including on bug paths. --- src/Appwrite/Platform/Workers/Migrations.php | 47 +++++++++----------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 69f72b8e27..63956bc90d 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -196,13 +196,13 @@ class Migrations extends Action $projectDB = null; $useAppwriteApiSource = false; if ($source === SourceAppwrite::getName() && empty($credentials['projectId'])) { - throw new \Exception('Source projectId is required for Appwrite migrations'); + throw new MigrationException('', '', message: 'Source projectId is required for Appwrite migrations', code: MigrationException::CODE_VALIDATION); } if (! empty($credentials['projectId'])) { $this->sourceProject = $this->dbForPlatform->getDocument('projects', $credentials['projectId']); if ($this->sourceProject->isEmpty()) { - throw new \Exception('Source project not found for provided projectId'); + throw new MigrationException('', '', message: 'Source project not found for provided projectId', code: MigrationException::CODE_NOT_FOUND); } $sourceRegion = $this->sourceProject->getAttribute('region', 'default'); @@ -265,7 +265,7 @@ class Migrations extends Action $this->deviceForMigrations, $this->dbForProject, ), - default => throw new \Exception('Invalid source type'), + default => throw new MigrationException('', '', message: 'Invalid source type', code: MigrationException::CODE_VALIDATION), }; $resources = $migration->getAttribute('resources', []); @@ -310,7 +310,7 @@ class Migrations extends Action $options['filename'], $options['columns'] ?? [], ), - default => throw new \Exception('Invalid destination type'), + default => throw new MigrationException('', '', message: 'Invalid destination type', code: MigrationException::CODE_VALIDATION), }; } @@ -521,7 +521,6 @@ class Migrations extends Action if (!empty($sourceErrors) || ! empty($destinationErrors)) { $migration->setAttribute('status', 'failed'); $migration->setAttribute('stage', 'finished'); - $migration->setAttribute('errors', $this->sanitizeErrors($sourceErrors, $destinationErrors)); return; } @@ -536,35 +535,29 @@ class Migrations extends Action $migration->setAttribute('status', 'failed'); $migration->setAttribute('stage', 'finished'); - call_user_func($this->logError, $th, 'appwrite-worker', 'appwrite-queue-' . self::getName(), [ - 'migrationId' => $migration->getId(), - 'source' => $migration->getAttribute('source') ?? '', - 'destination' => $migration->getAttribute('destination') ?? '', - ]); - + // User-facing failures (validation, not found, conflict) are routed through + // MigrationException and stay in the migration report only. Anything else is + // a bug or infra failure and goes to Sentry with the full trace. + if (!$th instanceof MigrationException) { + call_user_func($this->logError, $th, 'appwrite-worker', 'appwrite-queue-' . self::getName(), [ + 'migrationId' => $migration->getId(), + 'source' => $migration->getAttribute('source') ?? '', + 'destination' => $migration->getAttribute('destination') ?? '', + ]); + } } finally { try { + // Persist the consolidated error list regardless of which code path fired. + $migration->setAttribute('errors', $this->sanitizeErrors( + $source?->getErrors() ?? [], + $destination?->getErrors() ?? [], + )); + $this->updateMigrationDocument($migration, $project, $queueForRealtime); if ($migration->getAttribute('status', '') === 'failed') { Console::error('Migration(' . $migration->getSequence() . ':' . $migration->getId() . ') failed, Project(' . $this->project->getSequence() . ':' . $this->project->getId() . ')'); - $sourceErrors = $source?->getErrors() ?? []; - $destinationErrors = $destination?->getErrors() ?? []; - - foreach ([...$sourceErrors, ...$destinationErrors] as $error) { - /** @var MigrationException $error */ - if ($error->getCode() === 0 || $error->getCode() >= 500) { - ($this->logError)($error, 'appwrite-worker', 'appwrite-queue-' . self::getName(), [ - 'migrationId' => $migration->getId(), - 'source' => $migration->getAttribute('source') ?? '', - 'destination' => $migration->getAttribute('destination') ?? '', - 'resourceName' => $error->getResourceName(), - 'resourceGroup' => $error->getResourceGroup(), - ]); - } - } - $source?->error(); $destination?->error(); } From c2e4bc2ae3901d040dd2d942ed74ac082e0f10f2 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 4 May 2026 07:27:27 +0100 Subject: [PATCH 103/211] Simplify sanitizeErrors now that jsonSerialize doesn't emit trace With Migration\Exception::jsonSerialize() no longer including the stack trace, sanitizeErrors no longer needs to decode/strip/re-encode each entry. Reduce it to a single json_encode pass. --- src/Appwrite/Platform/Workers/Migrations.php | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 63956bc90d..03578b4ddc 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -857,7 +857,7 @@ class Migrations extends Action } /** - * Sanitize migration errors, removing sensitive information like stack traces + * Encode migration errors as JSON strings for storage on the migration document. * * @param array $sourceErrors * @param array $destinationErrors @@ -867,20 +867,10 @@ class Migrations extends Action array $sourceErrors, array $destinationErrors, ): array { - $errors = []; - foreach ([...$sourceErrors, ...$destinationErrors] as $error) { - $encoded = \json_decode(\json_encode($error), true); - if (\is_array($encoded)) { - if (isset($encoded['trace'])) { - unset($encoded['trace']); - } - $errors[] = \json_encode($encoded); - } else { - $errors[] = \json_encode($error); - } - } - - return $errors; + return \array_map( + fn ($error) => \json_encode($error), + [...$sourceErrors, ...$destinationErrors], + ); } private function processMigrationResourceStats(array $resources, Context $usage, Document $projectDocument, UsagePublisher $publisherForUsage, string $source, Authorization $authorization, ?string $resourceId) From f5a7cfd2ea0135d1b01a01fd60d378bd81acba8c Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 4 May 2026 12:22:48 +0530 Subject: [PATCH 104/211] fix: resolve query syntax errors and improve error handling in Request class --- src/Appwrite/Utopia/Request.php | 65 ++++++----- .../e2e/Services/Databases/DatabasesBase.php | 45 ++++++++ .../Utopia/Request/Filters/ThrowingFilter.php | 24 +++++ tests/unit/Utopia/RequestTest.php | 101 ++++++++++++++++++ 4 files changed, 207 insertions(+), 28 deletions(-) create mode 100644 tests/unit/Utopia/Request/Filters/ThrowingFilter.php diff --git a/src/Appwrite/Utopia/Request.php b/src/Appwrite/Utopia/Request.php index 3004392f76..945a3d2bf6 100644 --- a/src/Appwrite/Utopia/Request.php +++ b/src/Appwrite/Utopia/Request.php @@ -51,38 +51,47 @@ class Request extends UtopiaRequest if (!\is_array($methods)) { $id = $methods->getNamespace() . '.' . $methods->getMethodName(); + } else { + $matched = null; + foreach ($methods as $method) { + /** @var Method|null $method */ + if ($method === null) { + continue; + } + + // Find the method that matches the parameters passed + $methodParamNames = \array_map(fn ($param) => $param->getName(), $method->getParameters()); + $invalidParams = \array_diff(\array_keys($parameters), $methodParamNames); + + // No params defined, or all params are valid + if (empty($methodParamNames) || empty($invalidParams)) { + $matched = $method; + break; + } + } + + $id = $matched !== null + ? $matched->getNamespace() . '.' . $matched->getMethodName() + : 'unknown.unknown'; + } + + try { foreach ($this->getFilters() as $filter) { $parameters = $filter->parse($parameters, $id); } - $this->filteredParams = $parameters; - return $parameters; - } - - $matched = null; - foreach ($methods as $method) { - /** @var Method|null $method */ - if ($method === null) { - continue; + } catch (\Throwable $e) { + // 4xx filter throws are user-input errors that the action layer + // revalidates and reports. Cache the raw, pre-filter parameters + // so a subsequent getParams() — e.g. when the framework builds + // arguments for an error hook — returns without re-running + // filters. Otherwise the second throw gets wrapped as + // "Error handler had an error: ..." (HTTP 500), masking the + // intended 400. + $code = $e->getCode(); + if (\is_int($code) && $code >= 400 && $code < 500) { + $this->filteredParams = parent::getParams(); } - - // Find the method that matches the parameters passed - $methodParamNames = \array_map(fn ($param) => $param->getName(), $method->getParameters()); - $invalidParams = \array_diff(\array_keys($parameters), $methodParamNames); - - // No params defined, or all params are valid - if (empty($methodParamNames) || empty($invalidParams)) { - $matched = $method; - break; - } - } - - $id = $matched !== null - ? $matched->getNamespace() . '.' . $matched->getMethodName() - : 'unknown.unknown'; - - // Apply filters - foreach ($this->getFilters() as $filter) { - $parameters = $filter->parse($parameters, $id); + throw $e; } $this->filteredParams = $parameters; diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index e3efe3bbd9..315f40475a 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -4339,6 +4339,51 @@ trait DatabasesBase // $this->assertEquals('Invalid query: Cannot query search on attribute "actors" because it is an array.', $documents['body']['message']); } + public function testDocumentsListInvalidQuerySyntax(): void + { + $data = $this->setupDocuments(); + $databaseId = $data['databaseId']; + + // Each entry in `queries` must be a JSON-encoded object (e.g. + // `{"method":"limit","values":[5]}`). Anything else — including the + // legacy SDK shorthand `limit(5)`, a hand-rolled non-JSON string, or a + // JSON value that isn't an object — must be rejected by Query::parse + // with the same `Invalid query: Syntax error` message so callers get + // a consistent 400. + $invalidQueries = [ + 'legacy shorthand' => 'limit(5)', + 'plain string' => 'not-json', + 'json non-object' => '"limit"', + 'malformed json' => '{"method":"limit","values":[5}', + 'unquoted attribute' => '{method:"limit",values:[5]}', + ]; + + foreach ($invalidQueries as $label => $rawQuery) { + $documents = $this->client->call(Client::METHOD_GET, $this->getRecordUrl($databaseId, $data['moviesId']), array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [$rawQuery], + ]); + + $this->assertEquals(400, $documents['headers']['status-code'], "Expected 400 for [$label]: $rawQuery"); + $this->assertEquals('Invalid query: Syntax error', $documents['body']['message'], "Wrong error for [$label]: $rawQuery"); + } + + // Sanity check: the JSON form the SDK actually emits still works. + $documents = $this->client->call(Client::METHOD_GET, $this->getRecordUrl($databaseId, $data['moviesId']), array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + Query::limit(5)->toString(), + ], + ]); + + $this->assertEquals(200, $documents['headers']['status-code']); + $this->assertLessThanOrEqual(5, count($documents['body'][$this->getRecordResource()])); + } + public function testUpdateDocument(): void { $data = $this->setupDocuments(); diff --git a/tests/unit/Utopia/Request/Filters/ThrowingFilter.php b/tests/unit/Utopia/Request/Filters/ThrowingFilter.php new file mode 100644 index 0000000000..8e02b92e39 --- /dev/null +++ b/tests/unit/Utopia/Request/Filters/ThrowingFilter.php @@ -0,0 +1,24 @@ +calls++; + throw new \Exception($this->reason, $this->code); + } +} diff --git a/tests/unit/Utopia/RequestTest.php b/tests/unit/Utopia/RequestTest.php index 57ebae6d1e..d6f911da8d 100644 --- a/tests/unit/Utopia/RequestTest.php +++ b/tests/unit/Utopia/RequestTest.php @@ -5,10 +5,12 @@ namespace Tests\Unit\Utopia; use Appwrite\SDK\Method; use Appwrite\SDK\Parameter; use Appwrite\Utopia\Request; +use Appwrite\Utopia\Request\Filter; use PHPUnit\Framework\TestCase; use Swoole\Http\Request as SwooleRequest; use Tests\Unit\Utopia\Request\Filters\First; use Tests\Unit\Utopia\Request\Filters\Second; +use Tests\Unit\Utopia\Request\Filters\ThrowingFilter; use Utopia\Http\Route; class RequestTest extends TestCase @@ -192,6 +194,105 @@ class RequestTest extends TestCase $this->assertSame('fallback', $request->getHeader('referer', 'fallback')); } + public function testGetParamsCachesRawParamsWhenFilterThrows4xx(): void + { + // Regression: when a request filter throws a 4xx exception during + // Request::getParams() (e.g. RequestV20 rejecting an unparseable + // queries[]), the framework's error path calls getParams() again to + // build error-hook arguments. Without caching, that second call + // re-runs the filter and re-throws, which the framework wraps as + // "Error handler had an error: ..." (HTTP 500), masking the intended + // 400. This test pins that behavior: the first call throws (so the + // action's argument resolution aborts), but the second call returns + // the raw, pre-filter params without re-invoking filters. + $filter = new ThrowingFilter(400, 'invalid input'); + + $this->setupSingleMethodRoute($filter); + $this->request->setQueryString(['foo' => 'bar']); + + $threw = false; + try { + $this->request->getParams(); + } catch (\Throwable $e) { + $threw = true; + $this->assertSame(400, $e->getCode()); + $this->assertSame('invalid input', $e->getMessage()); + } + $this->assertTrue($threw, 'First getParams() call must rethrow the filter exception.'); + $this->assertSame(1, $filter->calls, 'Filter ran once on the first call.'); + + // Second call: framework's error hook arg resolution. Must return raw + // params without re-invoking the filter. + $params = $this->request->getParams(); + $this->assertSame(['foo' => 'bar'], $params); + $this->assertSame(1, $filter->calls, 'Filter must not run again after a cached 4xx failure.'); + } + + public function testGetParamsDoesNotCacheRawParamsForServerError(): void + { + // 5xx filter throws indicate genuine server-side problems, not + // user-input mistakes. They must keep rethrowing on every call so + // the framework's normal error handling sees the failure each time + // — caching raw params would silently swallow real bugs. + $filter = new ThrowingFilter(500, 'boom'); + + $this->setupSingleMethodRoute($filter); + $this->request->setQueryString(['foo' => 'bar']); + + for ($attempt = 1; $attempt <= 2; $attempt++) { + $threw = false; + try { + $this->request->getParams(); + } catch (\Throwable $e) { + $threw = true; + $this->assertSame(500, $e->getCode()); + } + $this->assertTrue($threw, "Call #$attempt must rethrow."); + $this->assertSame($attempt, $filter->calls, "Filter must run on call #$attempt."); + } + } + + public function testGetParamsDoesNotCacheRawParamsForUncodedException(): void + { + // \Exception with the default code of 0 is treated as "unknown" and + // must propagate every call — same reasoning as 5xx. + $filter = new ThrowingFilter(0, 'unknown'); + + $this->setupSingleMethodRoute($filter); + $this->request->setQueryString(['foo' => 'bar']); + + for ($attempt = 1; $attempt <= 2; $attempt++) { + $threw = false; + try { + $this->request->getParams(); + } catch (\Throwable) { + $threw = true; + } + $this->assertTrue($threw, "Call #$attempt must rethrow."); + $this->assertSame($attempt, $filter->calls, "Filter must run on call #$attempt."); + } + } + + /** + * Helper to attach a route with a single SDK method and one filter. + */ + private function setupSingleMethodRoute(Filter $filter): void + { + $route = new Route(Request::METHOD_GET, '/single'); + $route->label('sdk', new Method( + namespace: 'namespace', + group: 'group', + name: 'method', + description: 'description', + auth: [], + responses: [], + )); + + $this->request->addHeader('EXAMPLE', 'VALUE'); + $this->request->setRoute($route); + $this->request->addFilter($filter); + } + /** * Helper to attach a route with multiple SDK methods to the request. */ From f27172018ff73c74928834a7361cde9e9d506b60 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 4 May 2026 06:56:56 +0000 Subject: [PATCH 105/211] chore: bump utopia-php/audit to 2.2.2 --- composer.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index 2889069e67..9f34d2dbe1 100644 --- a/composer.lock +++ b/composer.lock @@ -3502,16 +3502,16 @@ }, { "name": "utopia-php/audit", - "version": "2.2.1", + "version": "2.2.2", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "e3e2d6ad5c7f6377d9237df296a12eb7943892fd" + "reference": "90886c202e7983999e6b6a8201004d5ab61d4b57" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/e3e2d6ad5c7f6377d9237df296a12eb7943892fd", - "reference": "e3e2d6ad5c7f6377d9237df296a12eb7943892fd", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/90886c202e7983999e6b6a8201004d5ab61d4b57", + "reference": "90886c202e7983999e6b6a8201004d5ab61d4b57", "shasum": "" }, "require": { @@ -3545,9 +3545,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/2.2.1" + "source": "https://github.com/utopia-php/audit/tree/2.2.2" }, - "time": "2026-02-02T10:39:25+00:00" + "time": "2026-05-04T06:48:58+00:00" }, { "name": "utopia-php/auth", @@ -8444,7 +8444,7 @@ ], "aliases": [], "minimum-stability": "dev", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": true, "prefer-lowest": false, "platform": { @@ -8465,5 +8465,5 @@ "platform-dev": { "ext-fileinfo": "*" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" } From c32294743ac428769fff11948f4a3c510ba3fa1d Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 4 May 2026 12:31:50 +0530 Subject: [PATCH 106/211] reverted e2e --- src/Appwrite/Utopia/Request.php | 2 +- .../e2e/Services/Databases/DatabasesBase.php | 45 ------------------- 2 files changed, 1 insertion(+), 46 deletions(-) diff --git a/src/Appwrite/Utopia/Request.php b/src/Appwrite/Utopia/Request.php index 945a3d2bf6..123b13cc8b 100644 --- a/src/Appwrite/Utopia/Request.php +++ b/src/Appwrite/Utopia/Request.php @@ -89,7 +89,7 @@ class Request extends UtopiaRequest // intended 400. $code = $e->getCode(); if (\is_int($code) && $code >= 400 && $code < 500) { - $this->filteredParams = parent::getParams(); + $this->filteredParams = $parameters; } throw $e; } diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 315f40475a..e3efe3bbd9 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -4339,51 +4339,6 @@ trait DatabasesBase // $this->assertEquals('Invalid query: Cannot query search on attribute "actors" because it is an array.', $documents['body']['message']); } - public function testDocumentsListInvalidQuerySyntax(): void - { - $data = $this->setupDocuments(); - $databaseId = $data['databaseId']; - - // Each entry in `queries` must be a JSON-encoded object (e.g. - // `{"method":"limit","values":[5]}`). Anything else — including the - // legacy SDK shorthand `limit(5)`, a hand-rolled non-JSON string, or a - // JSON value that isn't an object — must be rejected by Query::parse - // with the same `Invalid query: Syntax error` message so callers get - // a consistent 400. - $invalidQueries = [ - 'legacy shorthand' => 'limit(5)', - 'plain string' => 'not-json', - 'json non-object' => '"limit"', - 'malformed json' => '{"method":"limit","values":[5}', - 'unquoted attribute' => '{method:"limit",values:[5]}', - ]; - - foreach ($invalidQueries as $label => $rawQuery) { - $documents = $this->client->call(Client::METHOD_GET, $this->getRecordUrl($databaseId, $data['moviesId']), array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'queries' => [$rawQuery], - ]); - - $this->assertEquals(400, $documents['headers']['status-code'], "Expected 400 for [$label]: $rawQuery"); - $this->assertEquals('Invalid query: Syntax error', $documents['body']['message'], "Wrong error for [$label]: $rawQuery"); - } - - // Sanity check: the JSON form the SDK actually emits still works. - $documents = $this->client->call(Client::METHOD_GET, $this->getRecordUrl($databaseId, $data['moviesId']), array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'queries' => [ - Query::limit(5)->toString(), - ], - ]); - - $this->assertEquals(200, $documents['headers']['status-code']); - $this->assertLessThanOrEqual(5, count($documents['body'][$this->getRecordResource()])); - } - public function testUpdateDocument(): void { $data = $this->setupDocuments(); From 1fc3a8803ca1e393ac7cc89cad6280c4107fe9c4 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 4 May 2026 12:45:32 +0530 Subject: [PATCH 107/211] multiline comment --- src/Appwrite/Utopia/Request.php | 16 +++++++++------- tests/unit/Utopia/RequestTest.php | 20 +++++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/Appwrite/Utopia/Request.php b/src/Appwrite/Utopia/Request.php index 123b13cc8b..24803eeaa7 100644 --- a/src/Appwrite/Utopia/Request.php +++ b/src/Appwrite/Utopia/Request.php @@ -80,13 +80,15 @@ class Request extends UtopiaRequest $parameters = $filter->parse($parameters, $id); } } catch (\Throwable $e) { - // 4xx filter throws are user-input errors that the action layer - // revalidates and reports. Cache the raw, pre-filter parameters - // so a subsequent getParams() — e.g. when the framework builds - // arguments for an error hook — returns without re-running - // filters. Otherwise the second throw gets wrapped as - // "Error handler had an error: ..." (HTTP 500), masking the - // intended 400. + /* + * 4xx filter throws are user-input errors that the action layer + * revalidates and reports. Cache the raw, pre-filter parameters + * so a subsequent getParams() — e.g. when the framework builds + * arguments for an error hook — returns without re-running + * filters. Otherwise the second throw gets wrapped as + * "Error handler had an error: ..." (HTTP 500), masking the + * intended 400. + */ $code = $e->getCode(); if (\is_int($code) && $code >= 400 && $code < 500) { $this->filteredParams = $parameters; diff --git a/tests/unit/Utopia/RequestTest.php b/tests/unit/Utopia/RequestTest.php index d6f911da8d..a242d74f46 100644 --- a/tests/unit/Utopia/RequestTest.php +++ b/tests/unit/Utopia/RequestTest.php @@ -196,15 +196,17 @@ class RequestTest extends TestCase public function testGetParamsCachesRawParamsWhenFilterThrows4xx(): void { - // Regression: when a request filter throws a 4xx exception during - // Request::getParams() (e.g. RequestV20 rejecting an unparseable - // queries[]), the framework's error path calls getParams() again to - // build error-hook arguments. Without caching, that second call - // re-runs the filter and re-throws, which the framework wraps as - // "Error handler had an error: ..." (HTTP 500), masking the intended - // 400. This test pins that behavior: the first call throws (so the - // action's argument resolution aborts), but the second call returns - // the raw, pre-filter params without re-invoking filters. + /* + * Regression: when a request filter throws a 4xx exception during + * Request::getParams() (e.g. RequestV20 rejecting an unparseable + * queries[]), the framework's error path calls getParams() again to + * build error-hook arguments. Without caching, that second call + * re-runs the filter and re-throws, which the framework wraps as + * "Error handler had an error: ..." (HTTP 500), masking the intended + * 400. This test pins that behavior: the first call throws (so the + * action's argument resolution aborts), but the second call returns + * the raw, pre-filter params without re-invoking filters. + */ $filter = new ThrowingFilter(400, 'invalid input'); $this->setupSingleMethodRoute($filter); From 737c85822d6b5ad95cb5885d73fc1c00172d3a9d Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 4 May 2026 12:46:44 +0530 Subject: [PATCH 108/211] multi line comment --- tests/unit/Utopia/RequestTest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/unit/Utopia/RequestTest.php b/tests/unit/Utopia/RequestTest.php index a242d74f46..2247ff71f1 100644 --- a/tests/unit/Utopia/RequestTest.php +++ b/tests/unit/Utopia/RequestTest.php @@ -232,10 +232,12 @@ class RequestTest extends TestCase public function testGetParamsDoesNotCacheRawParamsForServerError(): void { - // 5xx filter throws indicate genuine server-side problems, not - // user-input mistakes. They must keep rethrowing on every call so - // the framework's normal error handling sees the failure each time - // — caching raw params would silently swallow real bugs. + /* + * 5xx filter throws indicate genuine server-side problems, not + * user-input mistakes. They must keep rethrowing on every call so + * the framework's normal error handling sees the failure each time + * — caching raw params would silently swallow real bugs. + */ $filter = new ThrowingFilter(500, 'boom'); $this->setupSingleMethodRoute($filter); From c849e652b3d454e78b830a8b69eded42fb467ed3 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 4 May 2026 08:36:38 +0100 Subject: [PATCH 109/211] Pin utopia-php/migration to fix-migration-sentry-leak branch for testing Wires the worker against the matching utopia-php/migration branch so end-to-end testing of the Sentry-routing fix can run against both sides of the change set. Run `composer update utopia-php/migration --with-all-dependencies` after pulling to refresh composer.lock. Revert before merging. --- composer.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 683da6f21b..163e9bf839 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,7 @@ "utopia-php/locale": "0.8.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.22.*", - "utopia-php/migration": "1.9.*", + "utopia-php/migration": "dev-fix-migration-sentry-leak as 1.9.999", "utopia-php/platform": "0.13.*", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", @@ -118,5 +118,11 @@ "php-http/discovery": true, "tbachert/spi": true } - } + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/utopia-php/migration" + } + ] } From 581fdb26dd0d399423fd514f28bf4ea123fb9233 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 4 May 2026 08:57:56 +0100 Subject: [PATCH 110/211] Update composer.lock for utopia-php/migration branch pin --- composer.lock | 76 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/composer.lock b/composer.lock index 3edbc39614..7f38aea1cf 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": "4bee36b21a57e754d2b3417e72dc9599", + "content-hash": "0e8cd1a2446dfb54015d25fa130d081a", "packages": [ { "name": "adhocore/jwt", @@ -2708,16 +2708,16 @@ }, { "name": "symfony/http-client", - "version": "v7.4.8", + "version": "v7.4.9", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "01933e626c3de76bea1e22641e205e78f6a34342" + "reference": "7e941c6abf4e3bf7dca160bf0e11ef36a9f832f6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/01933e626c3de76bea1e22641e205e78f6a34342", - "reference": "01933e626c3de76bea1e22641e205e78f6a34342", + "url": "https://api.github.com/repos/symfony/http-client/zipball/7e941c6abf4e3bf7dca160bf0e11ef36a9f832f6", + "reference": "7e941c6abf4e3bf7dca160bf0e11ef36a9f832f6", "shasum": "" }, "require": { @@ -2785,7 +2785,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.4.8" + "source": "https://github.com/symfony/http-client/tree/v7.4.9" }, "funding": [ { @@ -2805,7 +2805,7 @@ "type": "tidelift" } ], - "time": "2026-03-30T12:55:43+00:00" + "time": "2026-04-29T13:25:15+00:00" }, { "name": "symfony/http-client-contracts", @@ -3850,22 +3850,23 @@ }, { "name": "utopia-php/database", - "version": "5.4.1", + "version": "5.6.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "688d9422b5ff42ac2ecc29397d94891cfd772e93" + "reference": "609ebcd64be1ec6fab00c5f46fce54acb0031b3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/688d9422b5ff42ac2ecc29397d94891cfd772e93", - "reference": "688d9422b5ff42ac2ecc29397d94891cfd772e93", + "url": "https://api.github.com/repos/utopia-php/database/zipball/609ebcd64be1ec6fab00c5f46fce54acb0031b3c", + "reference": "609ebcd64be1ec6fab00c5f46fce54acb0031b3c", "shasum": "" }, "require": { "ext-mbstring": "*", "ext-mongodb": "*", "ext-pdo": "*", + "ext-redis": "*", "php": ">=8.4", "utopia-php/cache": "1.*", "utopia-php/console": "0.1.*", @@ -3903,9 +3904,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/5.4.1" + "source": "https://github.com/utopia-php/database/tree/5.6.0" }, - "time": "2026-04-29T07:32:59+00:00" + "time": "2026-05-01T01:28:07+00:00" }, { "name": "utopia-php/detector", @@ -4530,16 +4531,16 @@ }, { "name": "utopia-php/migration", - "version": "1.9.5", + "version": "dev-fix-migration-sentry-leak", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "952a4dfe232702f80e45c35129466a8d8cb4c599" + "reference": "276e7c25077a4dee670a806f715869f11367d932" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/952a4dfe232702f80e45c35129466a8d8cb4c599", - "reference": "952a4dfe232702f80e45c35129466a8d8cb4c599", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/276e7c25077a4dee670a806f715869f11367d932", + "reference": "276e7c25077a4dee670a806f715869f11367d932", "shasum": "" }, "require": { @@ -4565,7 +4566,25 @@ "Utopia\\Migration\\": "src/Migration" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "Utopia\\Tests\\": "tests/Migration" + } + }, + "scripts": { + "test": [ + "./vendor/bin/phpunit" + ], + "lint": [ + "./vendor/bin/pint --test" + ], + "format": [ + "./vendor/bin/pint" + ], + "check": [ + "./vendor/bin/phpstan analyse --level 3 src tests --memory-limit 2G" + ] + }, "license": [ "MIT" ], @@ -4578,10 +4597,10 @@ "utopia" ], "support": { - "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.9.5" + "source": "https://github.com/utopia-php/migration/tree/fix-migration-sentry-leak", + "issues": "https://github.com/utopia-php/migration/issues" }, - "time": "2026-04-29T11:19:13+00:00" + "time": "2026-05-04T07:20:31+00:00" }, { "name": "utopia-php/mongo", @@ -8442,9 +8461,18 @@ "time": "2024-11-07T12:36:22+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/migration", + "version": "dev-fix-migration-sentry-leak", + "alias": "1.9.999", + "alias_normalized": "1.9.999.0" + } + ], "minimum-stability": "dev", - "stability-flags": [], + "stability-flags": { + "utopia-php/migration": 20 + }, "prefer-stable": true, "prefer-lowest": false, "platform": { @@ -8465,5 +8493,5 @@ "platform-dev": { "ext-fileinfo": "*" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" } From 07d60bb36d25e9a8e307d29c56c10f8071630ad0 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 4 May 2026 10:23:40 +0100 Subject: [PATCH 111/211] Capture bubbled exception in migration error report The catch block recorded status='failed' but didn't surface the bubbling exception's message on the migration document. Setup-time failures (e.g. "Source project not found for provided projectId") left the user looking at status='failed' with errors=[]. Capture the throwable in the catch and include it in the consolidated errors list when finally serializes to the migration document. --- src/Appwrite/Platform/Workers/Migrations.php | 26 ++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 03578b4ddc..fa3900881d 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -428,6 +428,7 @@ class Migrations extends Action $transfer = $source = $destination = null; $aggregatedResources = []; + $caughtError = null; $host = System::getEnv('_APP_MIGRATION_HOST'); if (empty($host)) { @@ -535,6 +536,11 @@ class Migrations extends Action $migration->setAttribute('status', 'failed'); $migration->setAttribute('stage', 'finished'); + // Remember the bubbled exception so the finally block can include it in the + // migration's errors attribute — otherwise setup-time failures (e.g. invalid + // credentials) would leave the user looking at status='failed' with no message. + $caughtError = $th; + // User-facing failures (validation, not found, conflict) are routed through // MigrationException and stay in the migration report only. Anything else is // a bug or infra failure and goes to Sentry with the full trace. @@ -547,10 +553,26 @@ class Migrations extends Action } } finally { try { + $sourceErrors = $source?->getErrors() ?? []; + $destinationErrors = $destination?->getErrors() ?? []; + + if ($caughtError !== null) { + $bubbled = $caughtError instanceof MigrationException + ? $caughtError + : new MigrationException( + resourceName: '', + resourceGroup: '', + message: $caughtError->getMessage(), + code: $caughtError->getCode(), + previous: $caughtError, + ); + $destinationErrors[] = $bubbled; + } + // Persist the consolidated error list regardless of which code path fired. $migration->setAttribute('errors', $this->sanitizeErrors( - $source?->getErrors() ?? [], - $destination?->getErrors() ?? [], + $sourceErrors, + $destinationErrors, )); $this->updateMigrationDocument($migration, $project, $queueForRealtime); From 9c9bde2ce689a0bfec68e4b69323a0f66b7d2a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 May 2026 11:36:54 +0200 Subject: [PATCH 112/211] Introduce project key console tests --- .env | 2 +- tests/e2e/Services/Proxy/ProxyBase.php | 923 +++++++++++++----- .../Services/Proxy/ProxyConsoleClientTest.php | 14 + .../Services/Proxy/ProxyCustomServerTest.php | 745 -------------- tests/e2e/Services/Proxy/ProxyHelpers.php | 293 ++++++ 5 files changed, 997 insertions(+), 980 deletions(-) create mode 100644 tests/e2e/Services/Proxy/ProxyConsoleClientTest.php create mode 100644 tests/e2e/Services/Proxy/ProxyHelpers.php diff --git a/.env b/.env index 4a6a3ac344..d57e7cf421 100644 --- a/.env +++ b/.env @@ -20,7 +20,7 @@ _APP_EMAIL_CERTIFICATES=certificates@appwrite.io _APP_SYSTEM_RESPONSE_FORMAT= _APP_CUSTOM_DOMAIN_DENY_LIST= _APP_OPTIONS_ABUSE=disabled -_APP_OPTIONS_ROUTER_PROTECTION=disabled +_APP_OPTIONS_ROUTER_PROTECTION=enabled _APP_OPTIONS_FORCE_HTTPS=disabled _APP_OPTIONS_ROUTER_FORCE_HTTPS=disabled _APP_OPENSSL_KEY_V1=your-secret-key diff --git a/tests/e2e/Services/Proxy/ProxyBase.php b/tests/e2e/Services/Proxy/ProxyBase.php index 59a853bfc8..33ef64591b 100644 --- a/tests/e2e/Services/Proxy/ProxyBase.php +++ b/tests/e2e/Services/Proxy/ProxyBase.php @@ -2,298 +2,753 @@ namespace Tests\E2E\Services\Proxy; -use Appwrite\ID; -use Appwrite\Tests\Async; -use CURLFile; use Tests\E2E\Client; -use Utopia\Console; +use Utopia\Database\Query; +use Utopia\System\System; trait ProxyBase { - use Async; + use ProxyHelpers; - protected function listRules(array $params = []): mixed + protected function tearDown(): void { - $rule = $this->client->call(Client::METHOD_GET, '/proxy/rules', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), $params); - - return $rule; - } - - protected function createAPIRule(string $domain): mixed - { - $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'domain' => $domain, + // Cleanup for testRuleVerification test + // Required as it uses static domain name + $rules = $this->listRules([ + 'queries' => [ + Query::endsWith('domain', 'webapp.com')->toString(), + Query::limit(1000)->toString(), + ] ]); + $this->assertEquals(200, $rules['headers']['status-code']); + foreach ($rules['body']['rules'] as $rule) { + $ruleId = $rule['$id']; + $response = $this->deleteRule($ruleId); + $this->assertEquals(204, $response['headers']['status-code']); + } - return $rule; + if ($rules['body']['total'] > 0) { + $rules = $this->listRules([ + 'queries' => [ + Query::endsWith('domain', 'webapp.com')->toString(), + Query::limit(1)->toString() + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(0, count($rules['body']['rules'])); + $this->assertEquals(0, $rules['body']['total']); + } } - protected function updateRuleVerification(string $ruleId): mixed - { - $rule = $this->client->call(Client::METHOD_PATCH, '/proxy/rules/' . $ruleId . '/verification', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - - return $rule; - } - - protected function createSiteRule(string $domain, string $siteId, string $branch = ''): mixed - { - $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/site', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'domain' => $domain, - 'siteId' => $siteId, - 'branch' => $branch, - ]); - - return $rule; - } - - protected function getRule(string $ruleId): mixed - { - $rule = $this->client->call(Client::METHOD_GET, '/proxy/rules/' . $ruleId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - - return $rule; - } - - protected function createRedirectRule(string $domain, string $url, int $statusCode, string $resourceType, string $resourceId): mixed - { - $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/redirect', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'domain' => $domain, - 'url' => $url, - 'statusCode' => $statusCode, - 'resourceType' => $resourceType, - 'resourceId' => $resourceId, - ]); - - return $rule; - } - - protected function createFunctionRule(string $domain, string $functionId, string $branch = ''): mixed - { - $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/function', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'domain' => $domain, - 'functionId' => $functionId, - 'branch' => $branch, - ]); - - return $rule; - } - - protected function deleteRule(string $ruleId): mixed - { - $rule = $this->client->call(Client::METHOD_DELETE, '/proxy/rules/' . $ruleId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - - return $rule; - } - - protected function setupAPIRule(string $domain): string + public function testCreateRule(): void { + $domain = \uniqid() . '-api.myapp.com'; $rule = $this->createAPIRule($domain); - $this->assertEquals(201, $rule['headers']['status-code'], 'Failed to setup rule: ' . \json_encode($rule)); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals($domain, $rule['body']['domain']); + $this->assertEquals('manual', $rule['body']['trigger']); + $this->assertArrayHasKey('$id', $rule['body']); + $this->assertArrayHasKey('domain', $rule['body']); + $this->assertArrayHasKey('type', $rule['body']); + $this->assertArrayHasKey('redirectUrl', $rule['body']); + $this->assertArrayHasKey('redirectStatusCode', $rule['body']); + $this->assertArrayHasKey('deploymentResourceType', $rule['body']); + $this->assertArrayHasKey('deploymentId', $rule['body']); + $this->assertArrayHasKey('deploymentResourceId', $rule['body']); + $this->assertArrayHasKey('deploymentVcsProviderBranch', $rule['body']); + $this->assertArrayHasKey('logs', $rule['body']); + $this->assertArrayHasKey('renewAt', $rule['body']); - return $rule['body']['$id']; - } + $ruleId = $rule['body']['$id']; - protected function setupRedirectRule(string $domain, string $url, int $statusCode, string $resourceType, string $resourceId): string - { - $rule = $this->createRedirectRule($domain, $url, $statusCode, $resourceType, $resourceId); + $rule = $this->createAPIRule($domain); + $this->assertEquals(409, $rule['headers']['status-code']); - $this->assertEquals(201, $rule['headers']['status-code'], 'Failed to setup rule: ' . \json_encode($rule)); - - return $rule['body']['$id']; - } - - protected function setupFunctionRule(string $domain, string $functionId, string $branch = ''): string - { - $rule = $this->createFunctionRule($domain, $functionId, $branch); - - $this->assertEquals(201, $rule['headers']['status-code'], 'Failed to setup rule: ' . \json_encode($rule)); - - return $rule['body']['$id']; - } - - protected function setupSiteRule(string $domain, string $siteId, string $branch = ''): string - { - $rule = $this->createSiteRule($domain, $siteId, $branch); - - $this->assertEquals(201, $rule['headers']['status-code'], 'Failed to setup rule: ' . \json_encode($rule)); - - return $rule['body']['$id']; - } - - protected function cleanupRule(string $ruleId): void - { $rule = $this->deleteRule($ruleId); - $this->assertEquals(204, $rule['headers']['status-code'], 'Failed to cleanup rule: ' . \json_encode($rule)); + + $this->assertEquals(204, $rule['headers']['status-code']); } - protected function cleanupSite(string $siteId): void + public function testCreateRuleSetup(): void { - $site = $this->client->call(Client::METHOD_DELETE, '/sites/' . $siteId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - - $this->assertEquals(204, $site['headers']['status-code'], 'Failed to cleanup site: ' . \json_encode($site)); + $ruleId = $this->setupAPIRule(\uniqid() . '-api2.myapp.com'); + $this->cleanupRule($ruleId); } - protected function cleanupFunction(string $functionId): void + public function testCreateRuleApex(): void { - $function = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - - $this->assertEquals(204, $function['headers']['status-code'], 'Failed to cleanup function: ' . \json_encode($function)); + $domain = \uniqid() . '.com'; + $rule = $this->createAPIRule($domain); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); } - protected function setupSite(): mixed + public function testCreateRuleVcs(): void { - // Site - $site = $this->client->call(Client::METHOD_POST, '/sites', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ]), [ - 'siteId' => ID::unique(), - 'name' => 'Proxy site', - 'framework' => 'other', - 'adapter' => 'static', - 'buildRuntime' => 'static-1', - 'outputDirectory' => './', - 'buildCommand' => '', - 'installCommand' => '', - 'fallbackFile' => '', - ]); + $domain = \uniqid() . '-vcs.myapp.com'; - $this->assertEquals($site['headers']['status-code'], 201, 'Setup site failed with status code: ' . $site['headers']['status-code'] . ' and response: ' . json_encode($site['body'], JSON_PRETTY_PRINT)); + $setup = $this->setupSite(); + $siteId = $setup['siteId']; + $deploymentId = $setup['deploymentId']; - $siteId = $site['body']['$id']; + $this->assertNotEmpty($siteId); + $this->assertNotEmpty($deploymentId); - // Deployment - $deployment = $this->client->call(Client::METHOD_POST, '/sites/' . $siteId . '/deployments', array_merge([ - 'content-type' => 'multipart/form-data', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ]), [ - 'code' => $this->packageSite('static'), - 'activate' => 'true' - ]); + $rule = $this->createSiteRule('commit-' . $domain, $siteId); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->cleanupRule($rule['body']['$id']); - $this->assertEquals($deployment['headers']['status-code'], 202, 'Setup deployment failed with status code: ' . $deployment['headers']['status-code'] . ' and response: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); - $deploymentId = $deployment['body']['$id'] ?? ''; + $rule = $this->createSiteRule('branch-' . $domain, $siteId); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->cleanupRule($rule['body']['$id']); - $this->assertEventually(function () use ($siteId, $deploymentId) { - $site = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ])); - $this->assertEquals($deploymentId, $site['body']['deploymentId'], 'Deployment is not activated, deployment: ' . json_encode($site['body'], JSON_PRETTY_PRINT)); - }, 120000, 500); + $rule = $this->createSiteRule('anything-' . $domain, $siteId); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->cleanupRule($rule['body']['$id']); - return ['siteId' => $siteId, 'deploymentId' => $deploymentId]; + $sitesDomain = \explode(',', System::getEnv('_APP_DOMAIN_SITES', ''))[0]; + $domain = \uniqid() . '-vcs.' . $sitesDomain; + + $rule = $this->createSiteRule('commit-' . $domain, $siteId); + $this->assertEquals(400, $rule['headers']['status-code']); + + $rule = $this->createSiteRule('branch-' . $domain, $siteId); + $this->assertEquals(400, $rule['headers']['status-code']); + + $rule = $this->createSiteRule('subdomain.anything-' . $domain, $siteId); + $this->assertEquals(400, $rule['headers']['status-code']); + + $rule = $this->createSiteRule('anything-' . $domain, $siteId); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->cleanupRule($rule['body']['$id']); } - protected function setupFunction(): mixed + public function testCreateAPIRule(): void { - // Function - $function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ]), [ - 'functionId' => ID::unique(), - 'runtime' => 'node-22', - 'name' => 'Proxy Function', - 'entrypoint' => 'index.js', - 'commands' => '', - 'execute' => ['any'] + $domain = \uniqid() . '-api.custom.localhost'; + + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://appwrite.test'); + $proxyClient->addHeader('x-appwrite-hostname', $domain); + + $response = $proxyClient->call(Client::METHOD_GET, '/versions'); + $this->assertEquals(401, $response['headers']['status-code']); + + $ruleId = $this->setupAPIRule($domain); + + $this->assertNotEmpty($ruleId); + + $response = $proxyClient->call(Client::METHOD_GET, '/versions'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(APP_VERSION_STABLE, $response['body']['server']); + + $this->cleanupRule($ruleId); + + $rule = $this->createAPIRule('http://' . $domain); + $this->assertEquals(400, $rule['headers']['status-code']); + + $rule = $this->createAPIRule('https://' . $domain); + $this->assertEquals(400, $rule['headers']['status-code']); + + $rule = $this->createAPIRule('wss://' . $domain); + $this->assertEquals(400, $rule['headers']['status-code']); + + $rule = $this->createAPIRule($domain . '/some-path'); + $this->assertEquals(400, $rule['headers']['status-code']); + } + + public function testCreateRedirectRule(): void + { + $domain = \uniqid() . '-redirect.custom.localhost'; + + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://appwrite.test'); + $proxyClient->addHeader('x-appwrite-hostname', $domain); + + $response = $proxyClient->call(Client::METHOD_GET, '/todos/1'); + $this->assertEquals(401, $response['headers']['status-code']); + + $siteId = $this->setupSite()['siteId']; + + $ruleId = $this->setupRedirectRule($domain, 'https://jsonplaceholder.typicode.com/todos/1', 301, 'site', $siteId); + $this->assertNotEmpty($ruleId); + + $response = $proxyClient->call(Client::METHOD_GET, '/todos/1'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['id']); + + $response = $proxyClient->call(Client::METHOD_GET, '/'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['id']); + + $response = $proxyClient->call(Client::METHOD_GET, '/', followRedirects: false); + $this->assertEquals(301, $response['headers']['status-code']); + $this->assertEquals('https://jsonplaceholder.typicode.com/todos/1', $response['headers']['location']); + + $domain = \uniqid() . '-redirect-307.custom.localhost'; + $ruleId = $this->setupRedirectRule($domain, 'https://jsonplaceholder.typicode.com/todos/1', 307, 'site', $siteId); + $this->assertNotEmpty($ruleId); + + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://appwrite.test'); + $proxyClient->addHeader('x-appwrite-hostname', $domain); + + $response = $proxyClient->call(Client::METHOD_GET, '/', followRedirects: false); + $this->assertEquals(307, $response['headers']['status-code']); + $this->assertEquals('https://jsonplaceholder.typicode.com/todos/1', $response['headers']['location']); + + $rules = $this->listRules([ + 'queries' => [ + Query::equal('type', ['redirect'])->toString(), + Query::equal('trigger', ['manual'])->toString(), + Query::equal('deploymentResourceType', ['site'])->toString(), + Query::equal('deploymentResourceId', [$siteId])->toString(), + ], ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(2, $rules['body']['total']); - $this->assertEquals($function['headers']['status-code'], 201, 'Setup function failed with status code: ' . $function['headers']['status-code'] . ' and response: ' . json_encode($function['body'], JSON_PRETTY_PRINT)); + $this->cleanupSite($siteId); + $this->cleanupRule($ruleId); + } - $functionId = $function['body']['$id']; + public function testCreateFunctionRule(): void + { + $domain = \uniqid() . '-function.custom.localhost'; - // Deployment - $deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge([ - 'content-type' => 'multipart/form-data', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ]), [ - 'code' => $this->packageFunction('basic'), - 'activate' => 'true' - ]); + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://appwrite.test'); + $proxyClient->addHeader('x-appwrite-hostname', $domain); - $this->assertEquals($deployment['headers']['status-code'], 202, 'Setup deployment failed with status code: ' . $deployment['headers']['status-code'] . ' and response: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); - $deploymentId = $deployment['body']['$id'] ?? ''; + $response = $proxyClient->call(Client::METHOD_GET, '/ping'); + $this->assertEquals(401, $response['headers']['status-code']); + + $setup = $this->setupFunction(); + $functionId = $setup['functionId']; + $deploymentId = $setup['deploymentId']; + + $this->assertNotEmpty($functionId); + $this->assertNotEmpty($deploymentId); + + $ruleId = $this->setupFunctionRule($domain, $functionId); + $this->assertNotEmpty($ruleId); + + $response = $proxyClient->call(Client::METHOD_GET, '/ping'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals($functionId, $response['body']['APPWRITE_FUNCTION_ID']); + + $this->cleanupRule($ruleId); + + $this->cleanupFunction($functionId); $this->assertEventually(function () use ($functionId, $deploymentId) { - $function = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ])); - $this->assertEquals($deploymentId, $function['body']['deploymentId'], 'Deployment is not activated, deployment: ' . json_encode($function['body'], JSON_PRETTY_PRINT)); - }, 100000, 500); + $rules = $this->listRules([ + 'queries' => [ + Query::limit(1)->toString(), + Query::equal('type', ['deployment'])->toString(), + Query::equal('deploymentResourceType', ['function'])->toString(), + Query::equal('deploymentResourceId', [$functionId])->toString(), + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(0, $rules['body']['total']); + $this->assertCount(0, $rules['body']['rules']); - return ['functionId' => $functionId, 'deploymentId' => $deploymentId]; + $rules = $this->listRules([ + 'queries' => [ + Query::limit(1)->toString(), + Query::equal('type', ['deployment'])->toString(), + Query::equal('deploymentId', [$deploymentId])->toString() + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(0, $rules['body']['total']); + $this->assertCount(0, $rules['body']['rules']); + }); } - private function packageSite(string $site): CURLFile + public function testCreateSiteRule(): void { - $stdout = ''; - $stderr = ''; + $domain = \uniqid() . '-site.custom.localhost'; - $folderPath = realpath(__DIR__ . '/../../../resources/sites') . "/$site"; - $tarPath = "$folderPath/code.tar.gz"; + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://appwrite.test'); + $proxyClient->addHeader('x-appwrite-hostname', $domain); - Console::execute("cd $folderPath && tar --exclude code.tar.gz --exclude node_modules -czf code.tar.gz .", '', $stdout, $stderr); + $response = $proxyClient->call(Client::METHOD_GET, '/contact'); + $this->assertEquals(401, $response['headers']['status-code']); - if (filesize($tarPath) > 1024 * 1024 * 5) { - throw new \Exception('Code package is too large. Use the chunked upload method instead.'); + $setup = $this->setupSite(); + $siteId = $setup['siteId']; + $deploymentId = $setup['deploymentId']; + + $this->assertNotEmpty($siteId); + $this->assertNotEmpty($deploymentId); + + $ruleId = $this->setupSiteRule($domain, $siteId); + $this->assertNotEmpty($ruleId); + $rule = $this->getRule($ruleId); + $this->assertSame(200, $rule['headers']['status-code']); + $this->assertSame('created', $rule['body']['status']); + + $response = $proxyClient->call(Client::METHOD_GET, '/contact'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString('Contact page', $response['body']); + + // Wildcard domains automatically get verified status + $domains = [ + \uniqid() . '.sites.localhost', + \uniqid() . '.rebranded.localhost', + ]; + foreach ($domains as $domain) { + $wildcardRuleId = $this->setupSiteRule($domain, $siteId); + $this->assertNotEmpty($wildcardRuleId); + $rule = $this->getRule($wildcardRuleId); + $this->assertSame(200, $rule['headers']['status-code']); + $this->assertSame('verified', $rule['body']['status']); + $this->cleanupRule($wildcardRuleId); } - return new CURLFile($tarPath, 'application/x-gzip', \basename($tarPath)); + $rules = $this->listRules([ + 'queries' => [ + Query::limit(1)->toString(), + Query::equal('trigger', ['deployment'])->toString(), + Query::equal('type', ['deployment'])->toString(), + Query::equal('deploymentResourceType', ['site'])->toString(), + Query::equal('deploymentResourceId', [$siteId])->toString(), + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertGreaterThan(0, $rules['body']['total']); + + $this->cleanupRule($ruleId); + + $this->cleanupSite($siteId); + + $this->assertEventually(function () use ($siteId, $deploymentId) { + $rules = $this->listRules([ + 'queries' => [ + Query::limit(1)->toString(), + Query::equal('type', ['deployment'])->toString(), + Query::equal('deploymentResourceType', ['site'])->toString(), + Query::equal('deploymentResourceId', [$siteId])->toString(), + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(0, $rules['body']['total']); + $this->assertCount(0, $rules['body']['rules']); + + $rules = $this->listRules([ + 'queries' => [ + Query::limit(1)->toString(), + Query::equal('type', ['deployment'])->toString(), + Query::equal('deploymentId', [$deploymentId])->toString() + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(0, $rules['body']['total']); + $this->assertCount(0, $rules['body']['rules']); + }); } - private function packageFunction(string $function): CURLFile + public function testCreateSiteBranchRule(): void { - $stdout = ''; - $stderr = ''; + $domain = \uniqid() . '-site-branch.custom.localhost'; - $folderPath = realpath(__DIR__ . '/../../../resources/functions') . "/$function"; - $tarPath = "$folderPath/code.tar.gz"; + $setup = $this->setupSite(); + $siteId = $setup['siteId']; + $deploymentId = $setup['deploymentId']; - Console::execute("cd $folderPath && tar --exclude code.tar.gz --exclude node_modules -czf code.tar.gz .", '', $stdout, $stderr); + $this->assertNotEmpty($siteId); + $this->assertNotEmpty($deploymentId); - if (filesize($tarPath) > 1024 * 1024 * 5) { - throw new \Exception('Code package is too large. Use the chunked upload method instead.'); + $ruleId = $this->setupSiteRule($domain, $siteId, 'dev'); + $this->assertNotEmpty($ruleId); + + $rule = $this->getRule($ruleId); + $this->assertEquals(200, $rule['headers']['status-code']); + + $this->cleanupRule($ruleId); + } + + public function testCreateFunctionBranchRule(): void + { + $domain = \uniqid() . '-function-branch.custom.localhost'; + + $setup = $this->setupFunction(); + $functionId = $setup['functionId']; + $deploymentId = $setup['deploymentId']; + + $this->assertNotEmpty($functionId); + $this->assertNotEmpty($deploymentId); + + $ruleId = $this->setupFunctionRule($domain, $functionId, 'dev'); + $this->assertNotEmpty($ruleId); + + $rule = $this->getRule($ruleId); + $this->assertEquals(200, $rule['headers']['status-code']); + + $this->cleanupRule($ruleId); + + $this->cleanupFunction($functionId); + } + + public function testUpdateRule(): void + { + // Create function appwrite-network domain + $functionsDomain = \explode(',', System::getEnv('_APP_DOMAIN_FUNCTIONS', ''))[0]; + $domain = \uniqid() . '-cname-api.' . $functionsDomain; + + $rule = $this->createAPIRule($domain); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('verified', $rule['body']['status']); + + $this->cleanupRule($rule['body']['$id']); + + // Create site appwrite-network domain + $sitesDomain = \explode(',', System::getEnv('_APP_DOMAIN_SITES', ''))[0]; + $domain = \uniqid() . '-cname-api.' . $sitesDomain; + + $rule = $this->createAPIRule($domain); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('verified', $rule['body']['status']); + + $this->cleanupRule($rule['body']['$id']); + + // Create + update + $domain = \uniqid() . '-cname-api.custom.com'; + + $rule = $this->createAPIRule($domain); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + + $ruleId = $rule['body']['$id']; + + $rule = $this->updateRuleVerification($ruleId); + $this->assertEquals(400, $rule['headers']['status-code']); + + $this->cleanupRule($ruleId); + } + + public function testGetRule() + { + $domain = \uniqid() . '-get.custom.localhost'; + $ruleId = $this->setupAPIRule($domain); + + $this->assertNotEmpty($ruleId); + + $rule = $this->getRule($ruleId); + $this->assertEquals(200, $rule['headers']['status-code']); + $this->assertEquals($domain, $rule['body']['domain']); + $this->assertEquals('manual', $rule['body']['trigger']); + $this->assertArrayHasKey('$id', $rule['body']); + $this->assertArrayHasKey('domain', $rule['body']); + $this->assertArrayHasKey('type', $rule['body']); + $this->assertArrayHasKey('redirectUrl', $rule['body']); + $this->assertArrayHasKey('redirectStatusCode', $rule['body']); + $this->assertArrayHasKey('deploymentResourceType', $rule['body']); + $this->assertArrayHasKey('deploymentId', $rule['body']); + $this->assertArrayHasKey('deploymentResourceId', $rule['body']); + $this->assertArrayHasKey('deploymentVcsProviderBranch', $rule['body']); + $this->assertArrayHasKey('logs', $rule['body']); + $this->assertArrayHasKey('renewAt', $rule['body']); + + $this->cleanupRule($ruleId); + } + + public function testListRules() + { + $rules = $this->listRules(); + $this->assertEquals(200, $rules['headers']['status-code']); + foreach ($rules['body']['rules'] as $rule) { + $rule = $this->deleteRule($rule['$id']); + $this->assertEquals(204, $rule['headers']['status-code']); } - return new CURLFile($tarPath, 'application/x-gzip', \basename($tarPath)); + $rules = $this->listRules(); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(0, $rules['body']['total']); + $this->assertCount(0, $rules['body']['rules']); + + $rule1Domain = \uniqid() . '-list1.custom.localhost'; + $rule1Id = $this->setupAPIRule($rule1Domain); + $this->assertNotEmpty($rule1Id); + + $rules = $this->listRules(); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(1, $rules['body']['total']); + $this->assertCount(1, $rules['body']['rules']); + $this->assertEquals($rule1Domain, $rules['body']['rules'][0]['domain']); + + $this->assertEquals('manual', $rules['body']['rules'][0]['trigger']); + $this->assertArrayHasKey('$id', $rules['body']['rules'][0]); + $this->assertArrayHasKey('domain', $rules['body']['rules'][0]); + $this->assertArrayHasKey('type', $rules['body']['rules'][0]); + $this->assertArrayHasKey('redirectUrl', $rules['body']['rules'][0]); + $this->assertArrayHasKey('redirectStatusCode', $rules['body']['rules'][0]); + $this->assertArrayHasKey('deploymentResourceType', $rules['body']['rules'][0]); + $this->assertArrayHasKey('deploymentId', $rules['body']['rules'][0]); + $this->assertArrayHasKey('deploymentResourceId', $rules['body']['rules'][0]); + $this->assertArrayHasKey('deploymentVcsProviderBranch', $rules['body']['rules'][0]); + $this->assertArrayHasKey('logs', $rules['body']['rules'][0]); + $this->assertArrayHasKey('renewAt', $rules['body']['rules'][0]); + + $rule2Domain = \uniqid() . '-list1.custom.localhost'; + $rule2Id = $this->setupAPIRule($rule2Domain); + $this->assertNotEmpty($rule2Id); + + $rules = $this->listRules(); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(2, $rules['body']['total']); + $this->assertCount(2, $rules['body']['rules']); + + $rules = $this->listRules([ + 'queries' => [ + Query::limit(1)->toString() + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(2, $rules['body']['total']); + $this->assertCount(1, $rules['body']['rules']); + + $rules = $this->listRules([ + 'queries' => [ + Query::equal('$id', [$rule1Id])->toString() + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertCount(1, $rules['body']['rules']); + $this->assertEquals($rule1Domain, $rules['body']['rules'][0]['domain']); + + $rules = $this->listRules([ + 'queries' => [ + Query::orderDesc('$id')->toString() + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertCount(2, $rules['body']['rules']); + $this->assertEquals($rule2Id, $rules['body']['rules'][0]['$id']); + + $rules = $this->listRules([ + 'queries' => [ + Query::equal('domain', [$rule2Domain])->toString() + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertCount(1, $rules['body']['rules']); + $this->assertEquals($rule2Id, $rules['body']['rules'][0]['$id']); + + $rules = $this->listRules([ + 'search' => $rule1Domain, + 'queries' => [ Query::orderDesc('$createdAt')->toString() ] + ]); + + $this->assertEquals(200, $rules['headers']['status-code']); + $ruleIds = \array_column($rules['body']['rules'], '$id'); + $this->assertContains($rule1Id, $ruleIds); + + $rules = $this->listRules([ + 'search' => $rule2Domain, + 'queries' => [ Query::orderDesc('$createdAt')->toString() ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $ruleIds = \array_column($rules['body']['rules'], '$id'); + $this->assertContains($rule2Id, $ruleIds); + + $rules = $this->listRules([ + 'search' => $rule1Id, + 'queries' => [ Query::orderDesc('$createdAt')->toString() ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $ruleDomains = \array_column($rules['body']['rules'], 'domain'); + $this->assertContains($rule1Domain, $ruleDomains); + + $rules = $this->listRules([ + 'search' => $rule2Id, + 'queries' => [ Query::orderDesc('$createdAt')->toString() ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $ruleDomains = \array_column($rules['body']['rules'], 'domain'); + $this->assertContains($rule2Domain, $ruleDomains); + + $rules = $this->listRules(); + $this->assertEquals(200, $rules['headers']['status-code']); + foreach ($rules['body']['rules'] as $rule) { + $rule = $this->deleteRule($rule['$id']); + $this->assertEquals(204, $rule['headers']['status-code']); + } + + $rules = $this->listRules(); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(0, $rules['body']['total']); + $this->assertCount(0, $rules['body']['rules']); + } + + public function testRuleVerification(): void + { + + // 1. Site rule can verify + $site = $this->setupSite(); + $siteId = $site['siteId']; + + $rule = $this->createSiteRule('stage-site.webapp.com', $siteId); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('verifying', $rule['body']['status']); + $this->assertEmpty($rule['body']['logs']); + $this->assertNotEmpty($rule['body']['$id']); + $ruleId = $rule['body']['$id']; + + $rule = $this->updateRuleVerification($ruleId); + $this->assertEquals(200, $rule['headers']['status-code']); + $this->assertEquals($ruleId, $rule['body']['$id']); + $this->assertEquals('verifying', $rule['body']['status']); + $this->assertEmpty($rule['body']['logs']); + + $this->cleanupRule($rule['body']['$id']); + $this->cleanupSite($siteId); + + // 2. Function rule can verify + $function = $this->setupFunction(); + $functionId = $function['functionId']; + + $rule = $this->createFunctionRule('stage-function.webapp.com', $functionId); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('verifying', $rule['body']['status']); + $this->assertEmpty($rule['body']['logs']); + $this->cleanupRule($rule['body']['$id']); + + $rule = $this->createAPIRule('stage-site.webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['logs']); + $this->cleanupRule($rule['body']['$id']); + + $this->cleanupFunction($functionId); + + // 3. Wrong A record fails to verify + $rule = $this->createAPIRule('wrong-a-webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->assertStringContainsString('is missing CNAME record', $rule['body']['logs']); + + $ruleId = $rule['body']['$id']; + $rule = $this->updateRuleVerification($ruleId); + $this->assertEquals(400, $rule['headers']['status-code']); + $this->assertStringContainsString('is missing CNAME record', $rule['body']['message']); + + $rule = $this->getRule($ruleId); + $this->assertEquals(200, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + + $this->cleanupRule($ruleId); + + // 4. Correct A record can verify + $rule = $this->createAPIRule('webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('verifying', $rule['body']['status']); + $this->assertEmpty($rule['body']['logs']); + + $this->cleanupRule($rule['body']['$id']); + + // 5. Correct CNAME record can verify (no CAA record) + $rule = $this->createAPIRule('stage.webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('verifying', $rule['body']['status']); + $this->assertEmpty($rule['body']['logs']); + + $this->cleanupRule($rule['body']['$id']); + + // 6. Missing CNAME record fails to verify + $rule = $this->createAPIRule('stage-missing-cname.webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->assertStringContainsString('is missing CNAME record', $rule['body']['logs']); + + $ruleId = $rule['body']['$id']; + $rule = $this->updateRuleVerification($ruleId); + $this->assertEquals(400, $rule['headers']['status-code']); + $this->assertStringContainsString('is missing CNAME record', $rule['body']['message']); + + $rule = $this->getRule($ruleId); + $this->assertEquals(200, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + + $this->cleanupRule($ruleId); + + // 7. Wrong CNAME record fails to verify + $rule = $this->createAPIRule('stage-wrong-cname.webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['logs']); + + $ruleId = $rule['body']['$id']; + $rule = $this->updateRuleVerification($ruleId); + $this->assertEquals(400, $rule['headers']['status-code']); + $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['message']); + + $rule = $this->getRule($ruleId); + $this->assertEquals(200, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + + $this->cleanupRule($ruleId); + + // 8. Wrong CAA record fails to verify + $rule = $this->createAPIRule('stage-wrong-caa.webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->assertStringContainsString('has incorrect CAA value', $rule['body']['logs']); + + $ruleId = $rule['body']['$id']; + $rule = $this->updateRuleVerification($ruleId); + $this->assertEquals(400, $rule['headers']['status-code']); + $this->assertStringContainsString('has incorrect CAA value', $rule['body']['message']); + + $rule = $this->getRule($ruleId); + $this->assertEquals(200, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + + $this->cleanupRule($ruleId); + + // 9. Correct CAA record can verify + $rule = $this->createAPIRule('stage-correct-caa.webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('verifying', $rule['body']['status']); + $this->assertEmpty($rule['body']['logs']); + + $this->cleanupRule($rule['body']['$id']); + } + + public function testUpdateRuleVerificationWithSameDataUpdatesTimestamp(): void + { + $domain = \uniqid() . '-timestamp-test.webapp.com'; + $rule = $this->createAPIRule($domain); + + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->assertNotEmpty($rule['body']['logs']); + + $ruleId = $rule['body']['$id']; + $initialUpdatedAt = $rule['body']['$updatedAt']; + $initiallogs = $rule['body']['logs']; + + sleep(1); + + $updatedRule = $this->updateRuleVerification($ruleId); + + $this->assertEquals(400, $updatedRule['headers']['status-code']); + $this->assertStringContainsString($initiallogs, $updatedRule['body']['message']); + + $ruleAfterUpdate = $this->getRule($ruleId); + $this->assertEquals(200, $ruleAfterUpdate['headers']['status-code']); + $this->assertEquals('created', $ruleAfterUpdate['body']['status']); + $this->assertEquals($initiallogs, $ruleAfterUpdate['body']['logs']); + $this->assertNotEquals($initialUpdatedAt, $ruleAfterUpdate['body']['$updatedAt']); + + $initialTime = new \DateTime($initialUpdatedAt); + $updatedTime = new \DateTime($ruleAfterUpdate['body']['$updatedAt']); + $this->assertGreaterThan($initialTime, $updatedTime); + + $this->cleanupRule($ruleId); } } diff --git a/tests/e2e/Services/Proxy/ProxyConsoleClientTest.php b/tests/e2e/Services/Proxy/ProxyConsoleClientTest.php new file mode 100644 index 0000000000..68761f34a9 --- /dev/null +++ b/tests/e2e/Services/Proxy/ProxyConsoleClientTest.php @@ -0,0 +1,14 @@ +listRules([ - 'queries' => [ - Query::endsWith('domain', 'webapp.com')->toString(), - Query::limit(1000)->toString(), - ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - foreach ($rules['body']['rules'] as $rule) { - $ruleId = $rule['$id']; - $response = $this->deleteRule($ruleId); - $this->assertEquals(204, $response['headers']['status-code']); - } - - if ($rules['body']['total'] > 0) { - $rules = $this->listRules([ - 'queries' => [ - Query::endsWith('domain', 'webapp.com')->toString(), - Query::limit(1)->toString() - ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertEquals(0, count($rules['body']['rules'])); - $this->assertEquals(0, $rules['body']['total']); - } - } - - public function testCreateRule(): void - { - $domain = \uniqid() . '-api.myapp.com'; - $rule = $this->createAPIRule($domain); - - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals($domain, $rule['body']['domain']); - $this->assertEquals('manual', $rule['body']['trigger']); - $this->assertArrayHasKey('$id', $rule['body']); - $this->assertArrayHasKey('domain', $rule['body']); - $this->assertArrayHasKey('type', $rule['body']); - $this->assertArrayHasKey('redirectUrl', $rule['body']); - $this->assertArrayHasKey('redirectStatusCode', $rule['body']); - $this->assertArrayHasKey('deploymentResourceType', $rule['body']); - $this->assertArrayHasKey('deploymentId', $rule['body']); - $this->assertArrayHasKey('deploymentResourceId', $rule['body']); - $this->assertArrayHasKey('deploymentVcsProviderBranch', $rule['body']); - $this->assertArrayHasKey('logs', $rule['body']); - $this->assertArrayHasKey('renewAt', $rule['body']); - - $ruleId = $rule['body']['$id']; - - $rule = $this->createAPIRule($domain); - $this->assertEquals(409, $rule['headers']['status-code']); - - $rule = $this->deleteRule($ruleId); - - $this->assertEquals(204, $rule['headers']['status-code']); - } - - public function testCreateRuleSetup(): void - { - $ruleId = $this->setupAPIRule(\uniqid() . '-api2.myapp.com'); - $this->cleanupRule($ruleId); - } - - public function testCreateRuleApex(): void - { - $domain = \uniqid() . '.com'; - $rule = $this->createAPIRule($domain); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); - } - - public function testCreateRuleVcs(): void - { - $domain = \uniqid() . '-vcs.myapp.com'; - - $setup = $this->setupSite(); - $siteId = $setup['siteId']; - $deploymentId = $setup['deploymentId']; - - $this->assertNotEmpty($siteId); - $this->assertNotEmpty($deploymentId); - - $rule = $this->createSiteRule('commit-' . $domain, $siteId); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->cleanupRule($rule['body']['$id']); - - $rule = $this->createSiteRule('branch-' . $domain, $siteId); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->cleanupRule($rule['body']['$id']); - - $rule = $this->createSiteRule('anything-' . $domain, $siteId); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->cleanupRule($rule['body']['$id']); - - $sitesDomain = \explode(',', System::getEnv('_APP_DOMAIN_SITES', ''))[0]; - $domain = \uniqid() . '-vcs.' . $sitesDomain; - - $rule = $this->createSiteRule('commit-' . $domain, $siteId); - $this->assertEquals(400, $rule['headers']['status-code']); - - $rule = $this->createSiteRule('branch-' . $domain, $siteId); - $this->assertEquals(400, $rule['headers']['status-code']); - - $rule = $this->createSiteRule('subdomain.anything-' . $domain, $siteId); - $this->assertEquals(400, $rule['headers']['status-code']); - - $rule = $this->createSiteRule('anything-' . $domain, $siteId); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->cleanupRule($rule['body']['$id']); - } - - public function testCreateAPIRule(): void - { - $domain = \uniqid() . '-api.custom.localhost'; - - $proxyClient = new Client(); - $proxyClient->setEndpoint('http://appwrite.test'); - $proxyClient->addHeader('x-appwrite-hostname', $domain); - - $response = $proxyClient->call(Client::METHOD_GET, '/versions'); - $this->assertEquals(401, $response['headers']['status-code']); - - $ruleId = $this->setupAPIRule($domain); - - $this->assertNotEmpty($ruleId); - - $response = $proxyClient->call(Client::METHOD_GET, '/versions'); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(APP_VERSION_STABLE, $response['body']['server']); - - $this->cleanupRule($ruleId); - - $rule = $this->createAPIRule('http://' . $domain); - $this->assertEquals(400, $rule['headers']['status-code']); - - $rule = $this->createAPIRule('https://' . $domain); - $this->assertEquals(400, $rule['headers']['status-code']); - - $rule = $this->createAPIRule('wss://' . $domain); - $this->assertEquals(400, $rule['headers']['status-code']); - - $rule = $this->createAPIRule($domain . '/some-path'); - $this->assertEquals(400, $rule['headers']['status-code']); - } - - public function testCreateRedirectRule(): void - { - $domain = \uniqid() . '-redirect.custom.localhost'; - - $proxyClient = new Client(); - $proxyClient->setEndpoint('http://appwrite.test'); - $proxyClient->addHeader('x-appwrite-hostname', $domain); - - $response = $proxyClient->call(Client::METHOD_GET, '/todos/1'); - $this->assertEquals(401, $response['headers']['status-code']); - - $siteId = $this->setupSite()['siteId']; - - $ruleId = $this->setupRedirectRule($domain, 'https://jsonplaceholder.typicode.com/todos/1', 301, 'site', $siteId); - $this->assertNotEmpty($ruleId); - - $response = $proxyClient->call(Client::METHOD_GET, '/todos/1'); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(1, $response['body']['id']); - - $response = $proxyClient->call(Client::METHOD_GET, '/'); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(1, $response['body']['id']); - - $response = $proxyClient->call(Client::METHOD_GET, '/', followRedirects: false); - $this->assertEquals(301, $response['headers']['status-code']); - $this->assertEquals('https://jsonplaceholder.typicode.com/todos/1', $response['headers']['location']); - - $domain = \uniqid() . '-redirect-307.custom.localhost'; - $ruleId = $this->setupRedirectRule($domain, 'https://jsonplaceholder.typicode.com/todos/1', 307, 'site', $siteId); - $this->assertNotEmpty($ruleId); - - $proxyClient = new Client(); - $proxyClient->setEndpoint('http://appwrite.test'); - $proxyClient->addHeader('x-appwrite-hostname', $domain); - - $response = $proxyClient->call(Client::METHOD_GET, '/', followRedirects: false); - $this->assertEquals(307, $response['headers']['status-code']); - $this->assertEquals('https://jsonplaceholder.typicode.com/todos/1', $response['headers']['location']); - - $rules = $this->listRules([ - 'queries' => [ - Query::equal('type', ['redirect'])->toString(), - Query::equal('trigger', ['manual'])->toString(), - Query::equal('deploymentResourceType', ['site'])->toString(), - Query::equal('deploymentResourceId', [$siteId])->toString(), - ], - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertEquals(2, $rules['body']['total']); - - $this->cleanupSite($siteId); - $this->cleanupRule($ruleId); - } - - public function testCreateFunctionRule(): void - { - $domain = \uniqid() . '-function.custom.localhost'; - - $proxyClient = new Client(); - $proxyClient->setEndpoint('http://appwrite.test'); - $proxyClient->addHeader('x-appwrite-hostname', $domain); - - $response = $proxyClient->call(Client::METHOD_GET, '/ping'); - $this->assertEquals(401, $response['headers']['status-code']); - - $setup = $this->setupFunction(); - $functionId = $setup['functionId']; - $deploymentId = $setup['deploymentId']; - - $this->assertNotEmpty($functionId); - $this->assertNotEmpty($deploymentId); - - $ruleId = $this->setupFunctionRule($domain, $functionId); - $this->assertNotEmpty($ruleId); - - $response = $proxyClient->call(Client::METHOD_GET, '/ping'); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals($functionId, $response['body']['APPWRITE_FUNCTION_ID']); - - $this->cleanupRule($ruleId); - - $this->cleanupFunction($functionId); - - $this->assertEventually(function () use ($functionId, $deploymentId) { - $rules = $this->listRules([ - 'queries' => [ - Query::limit(1)->toString(), - Query::equal('type', ['deployment'])->toString(), - Query::equal('deploymentResourceType', ['function'])->toString(), - Query::equal('deploymentResourceId', [$functionId])->toString(), - ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertEquals(0, $rules['body']['total']); - $this->assertCount(0, $rules['body']['rules']); - - $rules = $this->listRules([ - 'queries' => [ - Query::limit(1)->toString(), - Query::equal('type', ['deployment'])->toString(), - Query::equal('deploymentId', [$deploymentId])->toString() - ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertEquals(0, $rules['body']['total']); - $this->assertCount(0, $rules['body']['rules']); - }); - } - - public function testCreateSiteRule(): void - { - $domain = \uniqid() . '-site.custom.localhost'; - - $proxyClient = new Client(); - $proxyClient->setEndpoint('http://appwrite.test'); - $proxyClient->addHeader('x-appwrite-hostname', $domain); - - $response = $proxyClient->call(Client::METHOD_GET, '/contact'); - $this->assertEquals(401, $response['headers']['status-code']); - - $setup = $this->setupSite(); - $siteId = $setup['siteId']; - $deploymentId = $setup['deploymentId']; - - $this->assertNotEmpty($siteId); - $this->assertNotEmpty($deploymentId); - - $ruleId = $this->setupSiteRule($domain, $siteId); - $this->assertNotEmpty($ruleId); - $rule = $this->getRule($ruleId); - $this->assertSame(200, $rule['headers']['status-code']); - $this->assertSame('created', $rule['body']['status']); - - $response = $proxyClient->call(Client::METHOD_GET, '/contact'); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertStringContainsString('Contact page', $response['body']); - - // Wildcard domains automatically get verified status - $domains = [ - \uniqid() . '.sites.localhost', - \uniqid() . '.rebranded.localhost', - ]; - foreach ($domains as $domain) { - $wildcardRuleId = $this->setupSiteRule($domain, $siteId); - $this->assertNotEmpty($wildcardRuleId); - $rule = $this->getRule($wildcardRuleId); - $this->assertSame(200, $rule['headers']['status-code']); - $this->assertSame('verified', $rule['body']['status']); - $this->cleanupRule($wildcardRuleId); - } - - $rules = $this->listRules([ - 'queries' => [ - Query::limit(1)->toString(), - Query::equal('trigger', ['deployment'])->toString(), - Query::equal('type', ['deployment'])->toString(), - Query::equal('deploymentResourceType', ['site'])->toString(), - Query::equal('deploymentResourceId', [$siteId])->toString(), - ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertGreaterThan(0, $rules['body']['total']); - - $this->cleanupRule($ruleId); - - $this->cleanupSite($siteId); - - $this->assertEventually(function () use ($siteId, $deploymentId) { - $rules = $this->listRules([ - 'queries' => [ - Query::limit(1)->toString(), - Query::equal('type', ['deployment'])->toString(), - Query::equal('deploymentResourceType', ['site'])->toString(), - Query::equal('deploymentResourceId', [$siteId])->toString(), - ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertEquals(0, $rules['body']['total']); - $this->assertCount(0, $rules['body']['rules']); - - $rules = $this->listRules([ - 'queries' => [ - Query::limit(1)->toString(), - Query::equal('type', ['deployment'])->toString(), - Query::equal('deploymentId', [$deploymentId])->toString() - ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertEquals(0, $rules['body']['total']); - $this->assertCount(0, $rules['body']['rules']); - }); - } - - public function testCreateSiteBranchRule(): void - { - $domain = \uniqid() . '-site-branch.custom.localhost'; - - $setup = $this->setupSite(); - $siteId = $setup['siteId']; - $deploymentId = $setup['deploymentId']; - - $this->assertNotEmpty($siteId); - $this->assertNotEmpty($deploymentId); - - $ruleId = $this->setupSiteRule($domain, $siteId, 'dev'); - $this->assertNotEmpty($ruleId); - - $rule = $this->getRule($ruleId); - $this->assertEquals(200, $rule['headers']['status-code']); - - $this->cleanupRule($ruleId); - } - - public function testCreateFunctionBranchRule(): void - { - $domain = \uniqid() . '-function-branch.custom.localhost'; - - $setup = $this->setupFunction(); - $functionId = $setup['functionId']; - $deploymentId = $setup['deploymentId']; - - $this->assertNotEmpty($functionId); - $this->assertNotEmpty($deploymentId); - - $ruleId = $this->setupFunctionRule($domain, $functionId, 'dev'); - $this->assertNotEmpty($ruleId); - - $rule = $this->getRule($ruleId); - $this->assertEquals(200, $rule['headers']['status-code']); - - $this->cleanupRule($ruleId); - - $this->cleanupFunction($functionId); - } - - public function testUpdateRule(): void - { - // Create function appwrite-network domain - $functionsDomain = \explode(',', System::getEnv('_APP_DOMAIN_FUNCTIONS', ''))[0]; - $domain = \uniqid() . '-cname-api.' . $functionsDomain; - - $rule = $this->createAPIRule($domain); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('verified', $rule['body']['status']); - - $this->cleanupRule($rule['body']['$id']); - - // Create site appwrite-network domain - $sitesDomain = \explode(',', System::getEnv('_APP_DOMAIN_SITES', ''))[0]; - $domain = \uniqid() . '-cname-api.' . $sitesDomain; - - $rule = $this->createAPIRule($domain); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('verified', $rule['body']['status']); - - $this->cleanupRule($rule['body']['$id']); - - // Create + update - $domain = \uniqid() . '-cname-api.custom.com'; - - $rule = $this->createAPIRule($domain); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); - - $ruleId = $rule['body']['$id']; - - $rule = $this->updateRuleVerification($ruleId); - $this->assertEquals(400, $rule['headers']['status-code']); - - $this->cleanupRule($ruleId); - } - - public function testGetRule() - { - $domain = \uniqid() . '-get.custom.localhost'; - $ruleId = $this->setupAPIRule($domain); - - $this->assertNotEmpty($ruleId); - - $rule = $this->getRule($ruleId); - $this->assertEquals(200, $rule['headers']['status-code']); - $this->assertEquals($domain, $rule['body']['domain']); - $this->assertEquals('manual', $rule['body']['trigger']); - $this->assertArrayHasKey('$id', $rule['body']); - $this->assertArrayHasKey('domain', $rule['body']); - $this->assertArrayHasKey('type', $rule['body']); - $this->assertArrayHasKey('redirectUrl', $rule['body']); - $this->assertArrayHasKey('redirectStatusCode', $rule['body']); - $this->assertArrayHasKey('deploymentResourceType', $rule['body']); - $this->assertArrayHasKey('deploymentId', $rule['body']); - $this->assertArrayHasKey('deploymentResourceId', $rule['body']); - $this->assertArrayHasKey('deploymentVcsProviderBranch', $rule['body']); - $this->assertArrayHasKey('logs', $rule['body']); - $this->assertArrayHasKey('renewAt', $rule['body']); - - $this->cleanupRule($ruleId); - } - - public function testListRules() - { - $rules = $this->listRules(); - $this->assertEquals(200, $rules['headers']['status-code']); - foreach ($rules['body']['rules'] as $rule) { - $rule = $this->deleteRule($rule['$id']); - $this->assertEquals(204, $rule['headers']['status-code']); - } - - $rules = $this->listRules(); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertEquals(0, $rules['body']['total']); - $this->assertCount(0, $rules['body']['rules']); - - $rule1Domain = \uniqid() . '-list1.custom.localhost'; - $rule1Id = $this->setupAPIRule($rule1Domain); - $this->assertNotEmpty($rule1Id); - - $rules = $this->listRules(); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertEquals(1, $rules['body']['total']); - $this->assertCount(1, $rules['body']['rules']); - $this->assertEquals($rule1Domain, $rules['body']['rules'][0]['domain']); - - $this->assertEquals('manual', $rules['body']['rules'][0]['trigger']); - $this->assertArrayHasKey('$id', $rules['body']['rules'][0]); - $this->assertArrayHasKey('domain', $rules['body']['rules'][0]); - $this->assertArrayHasKey('type', $rules['body']['rules'][0]); - $this->assertArrayHasKey('redirectUrl', $rules['body']['rules'][0]); - $this->assertArrayHasKey('redirectStatusCode', $rules['body']['rules'][0]); - $this->assertArrayHasKey('deploymentResourceType', $rules['body']['rules'][0]); - $this->assertArrayHasKey('deploymentId', $rules['body']['rules'][0]); - $this->assertArrayHasKey('deploymentResourceId', $rules['body']['rules'][0]); - $this->assertArrayHasKey('deploymentVcsProviderBranch', $rules['body']['rules'][0]); - $this->assertArrayHasKey('logs', $rules['body']['rules'][0]); - $this->assertArrayHasKey('renewAt', $rules['body']['rules'][0]); - - $rule2Domain = \uniqid() . '-list1.custom.localhost'; - $rule2Id = $this->setupAPIRule($rule2Domain); - $this->assertNotEmpty($rule2Id); - - $rules = $this->listRules(); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertEquals(2, $rules['body']['total']); - $this->assertCount(2, $rules['body']['rules']); - - $rules = $this->listRules([ - 'queries' => [ - Query::limit(1)->toString() - ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertEquals(2, $rules['body']['total']); - $this->assertCount(1, $rules['body']['rules']); - - $rules = $this->listRules([ - 'queries' => [ - Query::equal('$id', [$rule1Id])->toString() - ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertCount(1, $rules['body']['rules']); - $this->assertEquals($rule1Domain, $rules['body']['rules'][0]['domain']); - - $rules = $this->listRules([ - 'queries' => [ - Query::orderDesc('$id')->toString() - ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertCount(2, $rules['body']['rules']); - $this->assertEquals($rule2Id, $rules['body']['rules'][0]['$id']); - - $rules = $this->listRules([ - 'queries' => [ - Query::equal('domain', [$rule2Domain])->toString() - ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertCount(1, $rules['body']['rules']); - $this->assertEquals($rule2Id, $rules['body']['rules'][0]['$id']); - - $rules = $this->listRules([ - 'search' => $rule1Domain, - 'queries' => [ Query::orderDesc('$createdAt')->toString() ] - ]); - - $this->assertEquals(200, $rules['headers']['status-code']); - $ruleIds = \array_column($rules['body']['rules'], '$id'); - $this->assertContains($rule1Id, $ruleIds); - - $rules = $this->listRules([ - 'search' => $rule2Domain, - 'queries' => [ Query::orderDesc('$createdAt')->toString() ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $ruleIds = \array_column($rules['body']['rules'], '$id'); - $this->assertContains($rule2Id, $ruleIds); - - $rules = $this->listRules([ - 'search' => $rule1Id, - 'queries' => [ Query::orderDesc('$createdAt')->toString() ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $ruleDomains = \array_column($rules['body']['rules'], 'domain'); - $this->assertContains($rule1Domain, $ruleDomains); - - $rules = $this->listRules([ - 'search' => $rule2Id, - 'queries' => [ Query::orderDesc('$createdAt')->toString() ] - ]); - $this->assertEquals(200, $rules['headers']['status-code']); - $ruleDomains = \array_column($rules['body']['rules'], 'domain'); - $this->assertContains($rule2Domain, $ruleDomains); - - $rules = $this->listRules(); - $this->assertEquals(200, $rules['headers']['status-code']); - foreach ($rules['body']['rules'] as $rule) { - $rule = $this->deleteRule($rule['$id']); - $this->assertEquals(204, $rule['headers']['status-code']); - } - - $rules = $this->listRules(); - $this->assertEquals(200, $rules['headers']['status-code']); - $this->assertEquals(0, $rules['body']['total']); - $this->assertCount(0, $rules['body']['rules']); - } - - public function testRuleVerification(): void - { - - // 1. Site rule can verify - $site = $this->setupSite(); - $siteId = $site['siteId']; - - $rule = $this->createSiteRule('stage-site.webapp.com', $siteId); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('verifying', $rule['body']['status']); - $this->assertEmpty($rule['body']['logs']); - $this->assertNotEmpty($rule['body']['$id']); - $ruleId = $rule['body']['$id']; - - $rule = $this->updateRuleVerification($ruleId); - $this->assertEquals(200, $rule['headers']['status-code']); - $this->assertEquals($ruleId, $rule['body']['$id']); - $this->assertEquals('verifying', $rule['body']['status']); - $this->assertEmpty($rule['body']['logs']); - - $this->cleanupRule($rule['body']['$id']); - $this->cleanupSite($siteId); - - // 2. Function rule can verify - $function = $this->setupFunction(); - $functionId = $function['functionId']; - - $rule = $this->createFunctionRule('stage-function.webapp.com', $functionId); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('verifying', $rule['body']['status']); - $this->assertEmpty($rule['body']['logs']); - $this->cleanupRule($rule['body']['$id']); - - $rule = $this->createAPIRule('stage-site.webapp.com'); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); - $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['logs']); - $this->cleanupRule($rule['body']['$id']); - - $this->cleanupFunction($functionId); - - // 3. Wrong A record fails to verify - $rule = $this->createAPIRule('wrong-a-webapp.com'); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); - $this->assertStringContainsString('is missing CNAME record', $rule['body']['logs']); - - $ruleId = $rule['body']['$id']; - $rule = $this->updateRuleVerification($ruleId); - $this->assertEquals(400, $rule['headers']['status-code']); - $this->assertStringContainsString('is missing CNAME record', $rule['body']['message']); - - $rule = $this->getRule($ruleId); - $this->assertEquals(200, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); - - $this->cleanupRule($ruleId); - - // 4. Correct A record can verify - $rule = $this->createAPIRule('webapp.com'); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('verifying', $rule['body']['status']); - $this->assertEmpty($rule['body']['logs']); - - $this->cleanupRule($rule['body']['$id']); - - // 5. Correct CNAME record can verify (no CAA record) - $rule = $this->createAPIRule('stage.webapp.com'); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('verifying', $rule['body']['status']); - $this->assertEmpty($rule['body']['logs']); - - $this->cleanupRule($rule['body']['$id']); - - // 6. Missing CNAME record fails to verify - $rule = $this->createAPIRule('stage-missing-cname.webapp.com'); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); - $this->assertStringContainsString('is missing CNAME record', $rule['body']['logs']); - - $ruleId = $rule['body']['$id']; - $rule = $this->updateRuleVerification($ruleId); - $this->assertEquals(400, $rule['headers']['status-code']); - $this->assertStringContainsString('is missing CNAME record', $rule['body']['message']); - - $rule = $this->getRule($ruleId); - $this->assertEquals(200, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); - - $this->cleanupRule($ruleId); - - // 7. Wrong CNAME record fails to verify - $rule = $this->createAPIRule('stage-wrong-cname.webapp.com'); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); - $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['logs']); - - $ruleId = $rule['body']['$id']; - $rule = $this->updateRuleVerification($ruleId); - $this->assertEquals(400, $rule['headers']['status-code']); - $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['message']); - - $rule = $this->getRule($ruleId); - $this->assertEquals(200, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); - - $this->cleanupRule($ruleId); - - // 8. Wrong CAA record fails to verify - $rule = $this->createAPIRule('stage-wrong-caa.webapp.com'); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); - $this->assertStringContainsString('has incorrect CAA value', $rule['body']['logs']); - - $ruleId = $rule['body']['$id']; - $rule = $this->updateRuleVerification($ruleId); - $this->assertEquals(400, $rule['headers']['status-code']); - $this->assertStringContainsString('has incorrect CAA value', $rule['body']['message']); - - $rule = $this->getRule($ruleId); - $this->assertEquals(200, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); - - $this->cleanupRule($ruleId); - - // 9. Correct CAA record can verify - $rule = $this->createAPIRule('stage-correct-caa.webapp.com'); - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('verifying', $rule['body']['status']); - $this->assertEmpty($rule['body']['logs']); - - $this->cleanupRule($rule['body']['$id']); - } - - public function testUpdateRuleVerificationWithSameDataUpdatesTimestamp(): void - { - $domain = \uniqid() . '-timestamp-test.webapp.com'; - $rule = $this->createAPIRule($domain); - - $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); - $this->assertNotEmpty($rule['body']['logs']); - - $ruleId = $rule['body']['$id']; - $initialUpdatedAt = $rule['body']['$updatedAt']; - $initiallogs = $rule['body']['logs']; - - sleep(1); - - $updatedRule = $this->updateRuleVerification($ruleId); - - $this->assertEquals(400, $updatedRule['headers']['status-code']); - $this->assertStringContainsString($initiallogs, $updatedRule['body']['message']); - - $ruleAfterUpdate = $this->getRule($ruleId); - $this->assertEquals(200, $ruleAfterUpdate['headers']['status-code']); - $this->assertEquals('created', $ruleAfterUpdate['body']['status']); - $this->assertEquals($initiallogs, $ruleAfterUpdate['body']['logs']); - $this->assertNotEquals($initialUpdatedAt, $ruleAfterUpdate['body']['$updatedAt']); - - $initialTime = new \DateTime($initialUpdatedAt); - $updatedTime = new \DateTime($ruleAfterUpdate['body']['$updatedAt']); - $this->assertGreaterThan($initialTime, $updatedTime); - - $this->cleanupRule($ruleId); - } } diff --git a/tests/e2e/Services/Proxy/ProxyHelpers.php b/tests/e2e/Services/Proxy/ProxyHelpers.php new file mode 100644 index 0000000000..ef962ce725 --- /dev/null +++ b/tests/e2e/Services/Proxy/ProxyHelpers.php @@ -0,0 +1,293 @@ +client->call(Client::METHOD_GET, '/proxy/rules', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), $params); + + return $rule; + } + + protected function createAPIRule(string $domain): mixed + { + $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'domain' => $domain, + ]); + + return $rule; + } + + protected function updateRuleVerification(string $ruleId): mixed + { + $rule = $this->client->call(Client::METHOD_PATCH, '/proxy/rules/' . $ruleId . '/verification', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + return $rule; + } + + protected function createSiteRule(string $domain, string $siteId, string $branch = ''): mixed + { + $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/site', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'domain' => $domain, + 'siteId' => $siteId, + 'branch' => $branch, + ]); + + return $rule; + } + + protected function getRule(string $ruleId): mixed + { + $rule = $this->client->call(Client::METHOD_GET, '/proxy/rules/' . $ruleId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + return $rule; + } + + protected function createRedirectRule(string $domain, string $url, int $statusCode, string $resourceType, string $resourceId): mixed + { + $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/redirect', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'domain' => $domain, + 'url' => $url, + 'statusCode' => $statusCode, + 'resourceType' => $resourceType, + 'resourceId' => $resourceId, + ]); + + return $rule; + } + + protected function createFunctionRule(string $domain, string $functionId, string $branch = ''): mixed + { + $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/function', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'domain' => $domain, + 'functionId' => $functionId, + 'branch' => $branch, + ]); + + return $rule; + } + + protected function deleteRule(string $ruleId): mixed + { + $rule = $this->client->call(Client::METHOD_DELETE, '/proxy/rules/' . $ruleId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + return $rule; + } + + protected function setupAPIRule(string $domain): string + { + $rule = $this->createAPIRule($domain); + + $this->assertEquals(201, $rule['headers']['status-code'], 'Failed to setup rule: ' . \json_encode($rule)); + + return $rule['body']['$id']; + } + + protected function setupRedirectRule(string $domain, string $url, int $statusCode, string $resourceType, string $resourceId): string + { + $rule = $this->createRedirectRule($domain, $url, $statusCode, $resourceType, $resourceId); + + $this->assertEquals(201, $rule['headers']['status-code'], 'Failed to setup rule: ' . \json_encode($rule)); + + return $rule['body']['$id']; + } + + protected function setupFunctionRule(string $domain, string $functionId, string $branch = ''): string + { + $rule = $this->createFunctionRule($domain, $functionId, $branch); + + $this->assertEquals(201, $rule['headers']['status-code'], 'Failed to setup rule: ' . \json_encode($rule)); + + return $rule['body']['$id']; + } + + protected function setupSiteRule(string $domain, string $siteId, string $branch = ''): string + { + $rule = $this->createSiteRule($domain, $siteId, $branch); + + $this->assertEquals(201, $rule['headers']['status-code'], 'Failed to setup rule: ' . \json_encode($rule)); + + return $rule['body']['$id']; + } + + protected function cleanupRule(string $ruleId): void + { + $rule = $this->deleteRule($ruleId); + $this->assertEquals(204, $rule['headers']['status-code'], 'Failed to cleanup rule: ' . \json_encode($rule)); + } + + protected function cleanupSite(string $siteId): void + { + $site = $this->client->call(Client::METHOD_DELETE, '/sites/' . $siteId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(204, $site['headers']['status-code'], 'Failed to cleanup site: ' . \json_encode($site)); + } + + protected function cleanupFunction(string $functionId): void + { + $function = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(204, $function['headers']['status-code'], 'Failed to cleanup function: ' . \json_encode($function)); + } + + protected function setupSite(): mixed + { + // Site + $site = $this->client->call(Client::METHOD_POST, '/sites', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'siteId' => ID::unique(), + 'name' => 'Proxy site', + 'framework' => 'other', + 'adapter' => 'static', + 'buildRuntime' => 'static-1', + 'outputDirectory' => './', + 'buildCommand' => '', + 'installCommand' => '', + 'fallbackFile' => '', + ]); + + $this->assertEquals($site['headers']['status-code'], 201, 'Setup site failed with status code: ' . $site['headers']['status-code'] . ' and response: ' . json_encode($site['body'], JSON_PRETTY_PRINT)); + + $siteId = $site['body']['$id']; + + // Deployment + $deployment = $this->client->call(Client::METHOD_POST, '/sites/' . $siteId . '/deployments', array_merge([ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'code' => $this->packageSite('static'), + 'activate' => 'true' + ]); + + $this->assertEquals($deployment['headers']['status-code'], 202, 'Setup deployment failed with status code: ' . $deployment['headers']['status-code'] . ' and response: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); + $deploymentId = $deployment['body']['$id'] ?? ''; + + $this->assertEventually(function () use ($siteId, $deploymentId) { + $site = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals($deploymentId, $site['body']['deploymentId'], 'Deployment is not activated, deployment: ' . json_encode($site['body'], JSON_PRETTY_PRINT)); + }, 120000, 500); + + return ['siteId' => $siteId, 'deploymentId' => $deploymentId]; + } + + protected function setupFunction(): mixed + { + // Function + $function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'functionId' => ID::unique(), + 'runtime' => 'node-22', + 'name' => 'Proxy Function', + 'entrypoint' => 'index.js', + 'commands' => '', + 'execute' => ['any'] + ]); + + $this->assertEquals($function['headers']['status-code'], 201, 'Setup function failed with status code: ' . $function['headers']['status-code'] . ' and response: ' . json_encode($function['body'], JSON_PRETTY_PRINT)); + + $functionId = $function['body']['$id']; + + // Deployment + $deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge([ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'code' => $this->packageFunction('basic'), + 'activate' => 'true' + ]); + + $this->assertEquals($deployment['headers']['status-code'], 202, 'Setup deployment failed with status code: ' . $deployment['headers']['status-code'] . ' and response: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); + $deploymentId = $deployment['body']['$id'] ?? ''; + + $this->assertEventually(function () use ($functionId, $deploymentId) { + $function = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals($deploymentId, $function['body']['deploymentId'], 'Deployment is not activated, deployment: ' . json_encode($function['body'], JSON_PRETTY_PRINT)); + }, 100000, 500); + + return ['functionId' => $functionId, 'deploymentId' => $deploymentId]; + } + + private function packageSite(string $site): CURLFile + { + $stdout = ''; + $stderr = ''; + + $folderPath = realpath(__DIR__ . '/../../../resources/sites') . "/$site"; + $tarPath = "$folderPath/code.tar.gz"; + + Console::execute("cd $folderPath && tar --exclude code.tar.gz --exclude node_modules -czf code.tar.gz .", '', $stdout, $stderr); + + if (filesize($tarPath) > 1024 * 1024 * 5) { + throw new \Exception('Code package is too large. Use the chunked upload method instead.'); + } + + return new CURLFile($tarPath, 'application/x-gzip', \basename($tarPath)); + } + + private function packageFunction(string $function): CURLFile + { + $stdout = ''; + $stderr = ''; + + $folderPath = realpath(__DIR__ . '/../../../resources/functions') . "/$function"; + $tarPath = "$folderPath/code.tar.gz"; + + Console::execute("cd $folderPath && tar --exclude code.tar.gz --exclude node_modules -czf code.tar.gz .", '', $stdout, $stderr); + + if (filesize($tarPath) > 1024 * 1024 * 5) { + throw new \Exception('Code package is too large. Use the chunked upload method instead.'); + } + + return new CURLFile($tarPath, 'application/x-gzip', \basename($tarPath)); + } +} From ec75f101bb0d1082c2aed451ddf763a86a4f4f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 May 2026 11:37:00 +0200 Subject: [PATCH 113/211] SDK quality fix --- .../Modules/Project/Http/Project/Keys/Ephemeral/Create.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php index 7fdefca218..4130effe69 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php @@ -59,7 +59,7 @@ class Create extends Base ], )) ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.', optional: false) - ->param('duration', null, new Range(1, 3600), 'Time in seconds before ephemeral key expires. Maximum duration is 3600 seconds.', optional: false) + ->param('duration', null, new Range(1, 3600), 'Time in seconds before ephemeral key expires. Maximum duration is 3600 seconds.', optional: false, example: 600) ->inject('response') ->inject('queueForEvents') ->inject('project') From d8349544d20b698e559de53aae0b3bcf38c4e3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 May 2026 11:37:26 +0200 Subject: [PATCH 114/211] Revert unwanted change --- .env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env b/.env index d57e7cf421..4a6a3ac344 100644 --- a/.env +++ b/.env @@ -20,7 +20,7 @@ _APP_EMAIL_CERTIFICATES=certificates@appwrite.io _APP_SYSTEM_RESPONSE_FORMAT= _APP_CUSTOM_DOMAIN_DENY_LIST= _APP_OPTIONS_ABUSE=disabled -_APP_OPTIONS_ROUTER_PROTECTION=enabled +_APP_OPTIONS_ROUTER_PROTECTION=disabled _APP_OPTIONS_FORCE_HTTPS=disabled _APP_OPTIONS_ROUTER_FORCE_HTTPS=disabled _APP_OPENSSL_KEY_V1=your-secret-key From cd6f5c64f08eff7d5c78cc1efbda528bbcecda17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 May 2026 11:48:02 +0200 Subject: [PATCH 115/211] Improve proxy API quality --- app/config/scopes/project.php | 18 ++++++++------- .../Modules/Proxy/Http/Rules/API/Create.php | 22 ++++++++++++++---- .../Modules/Proxy/Http/Rules/Delete.php | 11 +++++---- .../Platform/Modules/Proxy/Http/Rules/Get.php | 11 +++++---- .../Proxy/Http/Rules/Verification/Update.php | 23 +++++++++++-------- .../Modules/Proxy/Http/Rules/XList.php | 19 ++++++++------- 6 files changed, 66 insertions(+), 38 deletions(-) diff --git a/app/config/scopes/project.php b/app/config/scopes/project.php index a048920de9..5f9e4877b3 100644 --- a/app/config/scopes/project.php +++ b/app/config/scopes/project.php @@ -286,6 +286,16 @@ return [ 'category' => 'Messaging', ], + // Proxy + 'rules.read' => [ + 'description' => 'Access to read proxy rules.', + 'category' => 'Proxy', + ], + 'rules.write' => [ + 'description' => 'Access to create, update, and delete proxy rules.', + 'category' => 'Proxy', + ], + // Other "webhooks.read" => [ "description" => @@ -339,12 +349,4 @@ return [ 'description' => 'Access to create, update, and delete resources under VCS service.', 'category' => 'Other', ], - 'rules.read' => [ - 'description' => 'Access to read proxy rules.', - 'category' => 'Other', - ], - 'rules.write' => [ - 'description' => 'Access to create, update, and delete proxy rules.', - 'category' => 'Other', - ], ]; diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php index a6a3e44194..13c06c3e91 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -9,11 +9,13 @@ use Appwrite\Platform\Modules\Proxy\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\CustomId; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Helpers\ID; +use Utopia\Database\Validator\Authorization; use Utopia\Logger\Log; use Utopia\Platform\Scope\HTTP; use Utopia\System\System; @@ -47,8 +49,10 @@ class Create extends Action name: 'createAPIRule', description: <<inject('dbForPlatform') ->inject('platform') ->inject('log') + ->inject('authorization') ->callback($this->action(...)); } - public function action(string $domain, Response $response, Document $project, Certificate $publisherForCertificates, Event $queueForEvents, Database $dbForPlatform, array $platform, Log $log) - { + public function action( + string $domain, + Response $response, + Document $project, + Certificate $publisherForCertificates, + Event $queueForEvents, + Database $dbForPlatform, + array $platform, + Log $log, + Authorization $authorization, + ) { $this->validateDomainRestrictions($domain, $platform); // TODO: (@Meldiron) Remove after 1.7.x migration @@ -108,7 +122,7 @@ class Create extends Action } try { - $rule = $dbForPlatform->createDocument('rules', $rule); + $rule = $authorization->skip(fn() => $dbForPlatform->createDocument('rules', $rule)); } catch (Duplicate $e) { throw new Exception(Exception::RULE_ALREADY_EXISTS); } diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php index 1d5b770496..2bbe4a530a 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php @@ -12,6 +12,7 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; @@ -43,7 +44,7 @@ class Delete extends Action description: <<inject('dbForPlatform') ->inject('queueForDeletes') ->inject('queueForEvents') + ->inject('authorization') ->callback($this->action(...)); } @@ -67,15 +69,16 @@ class Delete extends Action Document $project, Database $dbForPlatform, DeleteEvent $queueForDeletes, - Event $queueForEvents + Event $queueForEvents, + Authorization $authorization, ) { - $rule = $dbForPlatform->getDocument('rules', $ruleId); + $rule = $authorization->skip(fn() => $dbForPlatform->getDocument('rules', $ruleId)); if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) { throw new Exception(Exception::RULE_NOT_FOUND); } - $dbForPlatform->deleteDocument('rules', $rule->getId()); + $authorization->skip(fn() => $dbForPlatform->deleteDocument('rules', $rule->getId())); $queueForDeletes ->setType(DELETE_TYPE_DOCUMENT) diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php index b88a4ffc06..03841bf1e5 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php @@ -10,6 +10,7 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; use Utopia\Platform\Scope\HTTP; @@ -39,7 +40,7 @@ class Get extends Action description: <<inject('response') ->inject('project') ->inject('dbForPlatform') + ->inject('authorization') ->callback($this->action(...)); } @@ -58,15 +60,16 @@ class Get extends Action string $ruleId, Response $response, Document $project, - Database $dbForPlatform + Database $dbForPlatform, + Authorization $authorization, ) { - $rule = $dbForPlatform->getDocument('rules', $ruleId); + $rule = $authorization->skip(fn() => $dbForPlatform->getDocument('rules', $ruleId)); if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) { throw new Exception(Exception::RULE_NOT_FOUND); } - $certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')); + $certificate = $authorization->skip(fn() => $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', ''))); // Give priority to certificate generation logs if present if (!empty($certificate->getAttribute('logs', ''))) { diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php index 9e81f6ff18..f567077c23 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php @@ -13,6 +13,7 @@ use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\DateTime; use Utopia\Database\Document; +use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; use Utopia\Logger\Log; use Utopia\Platform\Scope\HTTP; @@ -44,9 +45,9 @@ class Update extends Action group: null, name: 'updateRuleVerification', description: <<inject('project') ->inject('dbForPlatform') ->inject('log') + ->inject('authorization') ->callback($this->action(...)); } @@ -71,9 +73,10 @@ class Update extends Action Event $queueForEvents, Document $project, Database $dbForPlatform, - Log $log + Log $log, + Authorization $authorization, ) { - $rule = $dbForPlatform->getDocument('rules', $ruleId); + $rule = $authorization->skip(fn() => $dbForPlatform->getDocument('rules', $ruleId)); if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) { throw new Exception(Exception::RULE_NOT_FOUND); @@ -90,22 +93,22 @@ class Update extends Action try { $this->verifyRule($rule, $log); // Reset logs and status for the rule - $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + $rule = $authorization->skip(fn() => $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ 'logs' => '', 'status' => RULE_STATUS_CERTIFICATE_GENERATING, - ])); + ]))); $certificateId = $rule->getAttribute('certificateId', ''); // Reset logs for the associated certificate. if (!empty($certificateId)) { - $certificate = $dbForPlatform->updateDocument('certificates', $certificateId, new Document([ + $certificate = $authorization->skip(fn() => $dbForPlatform->updateDocument('certificates', $certificateId, new Document([ 'logs' => '', - ])); + ]))); } } catch (Exception $err) { - $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + $authorization->skip(fn() => $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ '$updatedAt' => DateTime::now(), - ])); + ]))); throw $err; } diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php index 19daf8c8d2..655563aa3b 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php @@ -13,6 +13,7 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Query; +use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Query\Cursor; use Utopia\Platform\Scope\HTTP; use Utopia\Validator\Boolean; @@ -44,7 +45,7 @@ class XList extends Action description: <<param('queries', [], new Rules(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Rules::ALLOWED_ATTRIBUTES), true) - ->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true) ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) + ->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true, deprecated: true) ->inject('response') ->inject('project') ->inject('dbForPlatform') + ->inject('authorization') ->callback($this->action(...)); } public function action( array $queries, + bool $total, string $search, - bool $includeTotal, Response $response, Document $project, - Database $dbForPlatform + Database $dbForPlatform, + Authorization $authorization, ) { try { $queries = Query::parseQueries($queries); @@ -91,7 +94,7 @@ class XList extends Action } $ruleId = $cursor->getValue(); - $cursorDocument = $dbForPlatform->getDocument('rules', $ruleId); + $cursorDocument = $authorization->skip(fn() => $dbForPlatform->getDocument('rules', $ruleId)); if ($cursorDocument->isEmpty()) { throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Rule '{$ruleId}' for the 'cursor' value not found."); @@ -102,9 +105,9 @@ class XList extends Action $filterQueries = Query::groupByType($queries)['filters']; - $rules = $dbForPlatform->find('rules', $queries); + $rules = $authorization->skip(fn() => $dbForPlatform->find('rules', $queries)); foreach ($rules as $rule) { - $certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')); + $certificate = $authorization->skip(fn() => $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', ''))); // Give priority to certificate generation logs if present if (!empty($certificate->getAttribute('logs', ''))) { @@ -116,7 +119,7 @@ class XList extends Action $response->dynamic(new Document([ 'rules' => $rules, - 'total' => $includeTotal ? $dbForPlatform->count('rules', $filterQueries, APP_LIMIT_COUNT) : 0, + 'total' => $total ? $authorization->skip(fn() => $dbForPlatform->count('rules', $filterQueries, APP_LIMIT_COUNT)) : 0, ]), Response::MODEL_PROXY_RULE_LIST); } } From 22318308260309c8228883a1cdab067fa09cdb45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 May 2026 11:59:04 +0200 Subject: [PATCH 116/211] Further proxy API improvements --- .../Modules/Proxy/Http/Rules/API/Create.php | 12 +++++++++--- .../Modules/Proxy/Http/Rules/Delete.php | 8 ++++---- .../Platform/Modules/Proxy/Http/Rules/Get.php | 13 ++++++++++--- .../Rules/{Verification => Status}/Update.php | 19 ++++++++++--------- .../Modules/Proxy/Http/Rules/XList.php | 19 +++++++++++++------ .../Platform/Modules/Proxy/Services/Http.php | 4 ++-- src/Appwrite/Utopia/Response/Model/Rule.php | 8 ++++---- tests/e2e/Services/Proxy/ProxyBase.php | 14 +++++++------- tests/e2e/Services/Proxy/ProxyHelpers.php | 4 ++-- 9 files changed, 61 insertions(+), 40 deletions(-) rename src/Appwrite/Platform/Modules/Proxy/Http/Rules/{Verification => Status}/Update.php (84%) diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php index 13c06c3e91..aaf94ef427 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -9,7 +9,6 @@ use Appwrite\Platform\Modules\Proxy\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; -use Appwrite\Utopia\Database\Validator\CustomId; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; @@ -45,7 +44,7 @@ class Create extends Action ->label('audits.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', - group: null, + group: 'rules', name: 'createAPIRule', description: <<skip(fn() => $dbForPlatform->createDocument('rules', $rule)); + $rule = $authorization->skip(fn () => $dbForPlatform->createDocument('rules', $rule)); } catch (Duplicate $e) { throw new Exception(Exception::RULE_ALREADY_EXISTS); } @@ -140,6 +139,13 @@ class Create extends Action $queueForEvents->setParam('ruleId', $rule->getId()); + // Rename 'created' status to 'unverified' for consistency. + // 'verifying' and 'verified' statuses stay as is. + // 'unverified' in the meaning of failed certificate generation stays as is. + if ($rule->getAttribute('status') === 'created') { + $rule->setAttribute('status', 'unverified'); + } + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($rule, Response::MODEL_PROXY_RULE); diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php index 2bbe4a530a..29751ff20a 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Delete.php @@ -39,7 +39,7 @@ class Delete extends Action ->label('audits.resource', 'rule/{request.ruleId}') ->label('sdk', new Method( namespace: 'proxy', - group: null, + group: 'rules', name: 'deleteRule', description: <<inject('dbForPlatform') ->inject('queueForDeletes') ->inject('queueForEvents') - ->inject('authorization') + ->inject('authorization') ->callback($this->action(...)); } @@ -72,13 +72,13 @@ class Delete extends Action Event $queueForEvents, Authorization $authorization, ) { - $rule = $authorization->skip(fn() => $dbForPlatform->getDocument('rules', $ruleId)); + $rule = $authorization->skip(fn () => $dbForPlatform->getDocument('rules', $ruleId)); if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) { throw new Exception(Exception::RULE_NOT_FOUND); } - $authorization->skip(fn() => $dbForPlatform->deleteDocument('rules', $rule->getId())); + $authorization->skip(fn () => $dbForPlatform->deleteDocument('rules', $rule->getId())); $queueForDeletes ->setType(DELETE_TYPE_DOCUMENT) diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php index 03841bf1e5..103ab1fddc 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php @@ -35,7 +35,7 @@ class Get extends Action ->label('scope', 'rules.read') ->label('sdk', new Method( namespace: 'proxy', - group: null, + group: 'rules', name: 'getRule', description: <<skip(fn() => $dbForPlatform->getDocument('rules', $ruleId)); + $rule = $authorization->skip(fn () => $dbForPlatform->getDocument('rules', $ruleId)); if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) { throw new Exception(Exception::RULE_NOT_FOUND); } - $certificate = $authorization->skip(fn() => $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', ''))); + $certificate = $authorization->skip(fn () => $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', ''))); // Give priority to certificate generation logs if present if (!empty($certificate->getAttribute('logs', ''))) { @@ -78,6 +78,13 @@ class Get extends Action $rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', '')); + // Rename 'created' status to 'unverified' for consistency. + // 'verifying' and 'verified' statuses stay as is. + // 'unverified' in the meaning of failed certificate generation stays as is. + if ($rule->getAttribute('status') === 'created') { + $rule->setAttribute('status', 'unverified'); + } + $response->dynamic($rule, Response::MODEL_PROXY_RULE); } } diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Status/Update.php similarity index 84% rename from src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php rename to src/Appwrite/Platform/Modules/Proxy/Http/Rules/Status/Update.php index f567077c23..1ad6f730b3 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Status/Update.php @@ -1,6 +1,6 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/proxy/rules/:ruleId/verification') - ->desc('Update rule verification status') + ->setHttpPath('/v1/proxy/rules/:ruleId/status') + ->httpAlias('/v1/proxy/rules/:ruleId/verification') + ->desc('Update rule status') ->groups(['api', 'proxy']) ->label('scope', 'rules.write') ->label('event', 'rules.[ruleId].update') @@ -42,8 +43,8 @@ class Update extends Action ->label('audits.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', - group: null, - name: 'updateRuleVerification', + group: 'rules', + name: 'updateRuleStatus', description: <<skip(fn() => $dbForPlatform->getDocument('rules', $ruleId)); + $rule = $authorization->skip(fn () => $dbForPlatform->getDocument('rules', $ruleId)); if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) { throw new Exception(Exception::RULE_NOT_FOUND); @@ -93,7 +94,7 @@ class Update extends Action try { $this->verifyRule($rule, $log); // Reset logs and status for the rule - $rule = $authorization->skip(fn() => $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + $rule = $authorization->skip(fn () => $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ 'logs' => '', 'status' => RULE_STATUS_CERTIFICATE_GENERATING, ]))); @@ -101,12 +102,12 @@ class Update extends Action $certificateId = $rule->getAttribute('certificateId', ''); // Reset logs for the associated certificate. if (!empty($certificateId)) { - $certificate = $authorization->skip(fn() => $dbForPlatform->updateDocument('certificates', $certificateId, new Document([ + $certificate = $authorization->skip(fn () => $dbForPlatform->updateDocument('certificates', $certificateId, new Document([ 'logs' => '', ]))); } } catch (Exception $err) { - $authorization->skip(fn() => $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + $authorization->skip(fn () => $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ '$updatedAt' => DateTime::now(), ]))); throw $err; diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php index 655563aa3b..999b4c8d74 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php @@ -40,7 +40,7 @@ class XList extends Action ->label('scope', 'rules.read') ->label('sdk', new Method( namespace: 'proxy', - group: null, + group: 'rules', name: 'listRules', description: <<inject('response') ->inject('project') ->inject('dbForPlatform') - ->inject('authorization') + ->inject('authorization') ->callback($this->action(...)); } @@ -94,7 +94,7 @@ class XList extends Action } $ruleId = $cursor->getValue(); - $cursorDocument = $authorization->skip(fn() => $dbForPlatform->getDocument('rules', $ruleId)); + $cursorDocument = $authorization->skip(fn () => $dbForPlatform->getDocument('rules', $ruleId)); if ($cursorDocument->isEmpty()) { throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Rule '{$ruleId}' for the 'cursor' value not found."); @@ -105,9 +105,9 @@ class XList extends Action $filterQueries = Query::groupByType($queries)['filters']; - $rules = $authorization->skip(fn() => $dbForPlatform->find('rules', $queries)); + $rules = $authorization->skip(fn () => $dbForPlatform->find('rules', $queries)); foreach ($rules as $rule) { - $certificate = $authorization->skip(fn() => $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', ''))); + $certificate = $authorization->skip(fn () => $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', ''))); // Give priority to certificate generation logs if present if (!empty($certificate->getAttribute('logs', ''))) { @@ -115,11 +115,18 @@ class XList extends Action } $rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', '')); + + // Rename 'created' status to 'unverified' for consistency. + // 'verifying' and 'verified' statuses stay as is. + // 'unverified' in the meaning of failed certificate generation stays as is. + if ($rule->getAttribute('status') === 'created') { + $rule->setAttribute('status', 'unverified'); + } } $response->dynamic(new Document([ 'rules' => $rules, - 'total' => $total ? $authorization->skip(fn() => $dbForPlatform->count('rules', $filterQueries, APP_LIMIT_COUNT)) : 0, + 'total' => $total ? $authorization->skip(fn () => $dbForPlatform->count('rules', $filterQueries, APP_LIMIT_COUNT)) : 0, ]), Response::MODEL_PROXY_RULE_LIST); } } diff --git a/src/Appwrite/Platform/Modules/Proxy/Services/Http.php b/src/Appwrite/Platform/Modules/Proxy/Services/Http.php index 980c64cc54..b2a9de1933 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Proxy/Services/Http.php @@ -8,7 +8,7 @@ use Appwrite\Platform\Modules\Proxy\Http\Rules\Function\Create as CreateFunction use Appwrite\Platform\Modules\Proxy\Http\Rules\Get as GetRule; use Appwrite\Platform\Modules\Proxy\Http\Rules\Redirect\Create as CreateRedirectRule; use Appwrite\Platform\Modules\Proxy\Http\Rules\Site\Create as CreateSiteRule; -use Appwrite\Platform\Modules\Proxy\Http\Rules\Verification\Update as UpdateRuleVerification; +use Appwrite\Platform\Modules\Proxy\Http\Rules\Status\Update as UpdateRuleStatus; use Appwrite\Platform\Modules\Proxy\Http\Rules\XList as ListRules; use Utopia\Platform\Service; @@ -26,6 +26,6 @@ class Http extends Service $this->addAction(GetRule::getName(), new GetRule()); $this->addAction(ListRules::getName(), new ListRules()); $this->addAction(DeleteRule::getName(), new DeleteRule()); - $this->addAction(UpdateRuleVerification::getName(), new UpdateRuleVerification()); + $this->addAction(UpdateRuleStatus::getName(), new UpdateRuleStatus()); } } diff --git a/src/Appwrite/Utopia/Response/Model/Rule.php b/src/Appwrite/Utopia/Response/Model/Rule.php index 1ff854e7ce..d5ea9ee0b7 100644 --- a/src/Appwrite/Utopia/Response/Model/Rule.php +++ b/src/Appwrite/Utopia/Response/Model/Rule.php @@ -74,7 +74,7 @@ class Rule extends Model ]) ->addRule('deploymentResourceId', [ 'type' => self::TYPE_STRING, - 'description' => 'ID deployment\'s resource. Used if type is "deployment"', + 'description' => 'ID of deployment\'s resource (site or function ID). Used if type is "deployment"', 'default' => '', 'example' => 'n3u9feiwmf', ]) @@ -86,10 +86,10 @@ class Rule extends Model ]) ->addRule('status', [ 'type' => self::TYPE_ENUM, - 'description' => 'Domain verification status. Possible values are "created", "verifying", "verified" and "unverified"', - 'default' => 'created', + 'description' => 'Domain verification status. Possible values are "unverified", "verifying", "verified"', + 'default' => 'unverified', 'example' => 'verified', - 'enum' => ['created', 'verifying', 'verified', 'unverified'], + 'enum' => ['unverified', 'verifying', 'verified'], ]) ->addRule('logs', [ 'type' => self::TYPE_STRING, diff --git a/tests/e2e/Services/Proxy/ProxyBase.php b/tests/e2e/Services/Proxy/ProxyBase.php index 33ef64591b..c33dfbe778 100644 --- a/tests/e2e/Services/Proxy/ProxyBase.php +++ b/tests/e2e/Services/Proxy/ProxyBase.php @@ -425,7 +425,7 @@ trait ProxyBase $ruleId = $rule['body']['$id']; - $rule = $this->updateRuleVerification($ruleId); + $rule = $this->updateRuleStatus($ruleId); $this->assertEquals(400, $rule['headers']['status-code']); $this->cleanupRule($ruleId); @@ -599,7 +599,7 @@ trait ProxyBase $this->assertNotEmpty($rule['body']['$id']); $ruleId = $rule['body']['$id']; - $rule = $this->updateRuleVerification($ruleId); + $rule = $this->updateRuleStatus($ruleId); $this->assertEquals(200, $rule['headers']['status-code']); $this->assertEquals($ruleId, $rule['body']['$id']); $this->assertEquals('verifying', $rule['body']['status']); @@ -633,7 +633,7 @@ trait ProxyBase $this->assertStringContainsString('is missing CNAME record', $rule['body']['logs']); $ruleId = $rule['body']['$id']; - $rule = $this->updateRuleVerification($ruleId); + $rule = $this->updateRuleStatus($ruleId); $this->assertEquals(400, $rule['headers']['status-code']); $this->assertStringContainsString('is missing CNAME record', $rule['body']['message']); @@ -666,7 +666,7 @@ trait ProxyBase $this->assertStringContainsString('is missing CNAME record', $rule['body']['logs']); $ruleId = $rule['body']['$id']; - $rule = $this->updateRuleVerification($ruleId); + $rule = $this->updateRuleStatus($ruleId); $this->assertEquals(400, $rule['headers']['status-code']); $this->assertStringContainsString('is missing CNAME record', $rule['body']['message']); @@ -683,7 +683,7 @@ trait ProxyBase $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['logs']); $ruleId = $rule['body']['$id']; - $rule = $this->updateRuleVerification($ruleId); + $rule = $this->updateRuleStatus($ruleId); $this->assertEquals(400, $rule['headers']['status-code']); $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['message']); @@ -700,7 +700,7 @@ trait ProxyBase $this->assertStringContainsString('has incorrect CAA value', $rule['body']['logs']); $ruleId = $rule['body']['$id']; - $rule = $this->updateRuleVerification($ruleId); + $rule = $this->updateRuleStatus($ruleId); $this->assertEquals(400, $rule['headers']['status-code']); $this->assertStringContainsString('has incorrect CAA value', $rule['body']['message']); @@ -734,7 +734,7 @@ trait ProxyBase sleep(1); - $updatedRule = $this->updateRuleVerification($ruleId); + $updatedRule = $this->updateRuleStatus($ruleId); $this->assertEquals(400, $updatedRule['headers']['status-code']); $this->assertStringContainsString($initiallogs, $updatedRule['body']['message']); diff --git a/tests/e2e/Services/Proxy/ProxyHelpers.php b/tests/e2e/Services/Proxy/ProxyHelpers.php index ef962ce725..6f15abdad8 100644 --- a/tests/e2e/Services/Proxy/ProxyHelpers.php +++ b/tests/e2e/Services/Proxy/ProxyHelpers.php @@ -34,9 +34,9 @@ trait ProxyHelpers return $rule; } - protected function updateRuleVerification(string $ruleId): mixed + protected function updateRuleStatus(string $ruleId): mixed { - $rule = $this->client->call(Client::METHOD_PATCH, '/proxy/rules/' . $ruleId . '/verification', array_merge([ + $rule = $this->client->call(Client::METHOD_PATCH, '/proxy/rules/' . $ruleId . '/status', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); From 3bb68ef4559ccf0880b9221d3b2f5d61d648ff2c Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 4 May 2026 11:03:51 +0100 Subject: [PATCH 117/211] Trim verbose comments in migrations worker outer catch --- src/Appwrite/Platform/Workers/Migrations.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index fa3900881d..8025c20677 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -536,14 +536,9 @@ class Migrations extends Action $migration->setAttribute('status', 'failed'); $migration->setAttribute('stage', 'finished'); - // Remember the bubbled exception so the finally block can include it in the - // migration's errors attribute — otherwise setup-time failures (e.g. invalid - // credentials) would leave the user looking at status='failed' with no message. $caughtError = $th; - // User-facing failures (validation, not found, conflict) are routed through - // MigrationException and stay in the migration report only. Anything else is - // a bug or infra failure and goes to Sentry with the full trace. + // MigrationException is reserved for user-facing failures and stays in the migration report only. if (!$th instanceof MigrationException) { call_user_func($this->logError, $th, 'appwrite-worker', 'appwrite-queue-' . self::getName(), [ 'migrationId' => $migration->getId(), @@ -569,7 +564,6 @@ class Migrations extends Action $destinationErrors[] = $bubbled; } - // Persist the consolidated error list regardless of which code path fired. $migration->setAttribute('errors', $this->sanitizeErrors( $sourceErrors, $destinationErrors, From 2263632f7d269f2e49e8c6006a048340b7c5becc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 May 2026 12:06:37 +0200 Subject: [PATCH 118/211] Fix all proxy create endpoints --- .../Proxy/Http/Rules/Function/Create.php | 34 +++++++++++++++--- .../Proxy/Http/Rules/Redirect/Create.php | 36 ++++++++++++++++--- .../Modules/Proxy/Http/Rules/Site/Create.php | 34 +++++++++++++++--- 3 files changed, 89 insertions(+), 15 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php index 4a8bd4897e..200182cf03 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php @@ -14,6 +14,7 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Helpers\ID; +use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; use Utopia\Logger\Log; use Utopia\Platform\Scope\HTTP; @@ -45,12 +46,14 @@ class Create extends Action ->label('audits.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', - group: null, + group: 'rules', name: 'createFunctionRule', description: <<inject('dbForProject') ->inject('platform') ->inject('log') + ->inject('authorization') ->callback($this->action(...)); } - public function action(string $domain, string $functionId, string $branch, Response $response, Document $project, Certificate $publisherForCertificates, Event $queueForEvents, Database $dbForPlatform, Database $dbForProject, array $platform, Log $log) - { + public function action( + string $domain, + string $functionId, + string $branch, + Response $response, + Document $project, + Certificate $publisherForCertificates, + Event $queueForEvents, + Database $dbForPlatform, + Database $dbForProject, + array $platform, + Log $log, + Authorization $authorization, + ) { + $this->validateDomainRestrictions($domain, $platform); $function = $dbForProject->getDocument('functions', $functionId); @@ -126,7 +143,7 @@ class Create extends Action } try { - $rule = $dbForPlatform->createDocument('rules', $rule); + $rule = $authorization->skip(fn () => $dbForPlatform->createDocument('rules', $rule)); } catch (Duplicate $e) { throw new Exception(Exception::RULE_ALREADY_EXISTS); } @@ -144,6 +161,13 @@ class Create extends Action $queueForEvents->setParam('ruleId', $rule->getId()); + // Rename 'created' status to 'unverified' for consistency. + // 'verifying' and 'verified' statuses stay as is. + // 'unverified' in the meaning of failed certificate generation stays as is. + if ($rule->getAttribute('status') === 'created') { + $rule->setAttribute('status', 'unverified'); + } + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($rule, Response::MODEL_PROXY_RULE); diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php index 5964a20772..f5105704ce 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php @@ -14,6 +14,7 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Helpers\ID; +use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; use Utopia\Logger\Log; use Utopia\Platform\Scope\HTTP; @@ -46,12 +47,14 @@ class Create extends Action ->label('audits.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', - group: null, + group: 'rules', name: 'createRedirectRule', description: <<inject('dbForProject') ->inject('platform') ->inject('log') + ->inject('authorization') ->callback($this->action(...)); } - public function action(string $domain, string $url, int $statusCode, string $resourceId, string $resourceType, Response $response, Document $project, Certificate $publisherForCertificates, Event $queueForEvents, Database $dbForPlatform, Database $dbForProject, array $platform, Log $log) - { + public function action( + string $domain, + string $url, + int $statusCode, + string $resourceId, + string $resourceType, + Response $response, + Document $project, + Certificate $publisherForCertificates, + Event $queueForEvents, + Database $dbForPlatform, + Database $dbForProject, + array $platform, + Log $log, + Authorization $authorization, + ) { + $this->validateDomainRestrictions($domain, $platform); $collection = match ($resourceType) { @@ -131,7 +150,7 @@ class Create extends Action } try { - $rule = $dbForPlatform->createDocument('rules', $rule); + $rule = $authorization->skip(fn () => $dbForPlatform->createDocument('rules', $rule)); } catch (Duplicate $e) { throw new Exception(Exception::RULE_ALREADY_EXISTS); } @@ -149,6 +168,13 @@ class Create extends Action $queueForEvents->setParam('ruleId', $rule->getId()); + // Rename 'created' status to 'unverified' for consistency. + // 'verifying' and 'verified' statuses stay as is. + // 'unverified' in the meaning of failed certificate generation stays as is. + if ($rule->getAttribute('status') === 'created') { + $rule->setAttribute('status', 'unverified'); + } + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($rule, Response::MODEL_PROXY_RULE); diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php index a9dfa93a49..7b959055dc 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php @@ -14,6 +14,7 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Helpers\ID; +use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; use Utopia\Logger\Log; use Utopia\Platform\Scope\HTTP; @@ -45,12 +46,14 @@ class Create extends Action ->label('audits.resource', 'rule/{response.$id}') ->label('sdk', new Method( namespace: 'proxy', - group: null, + group: 'rules', name: 'createSiteRule', description: <<inject('dbForProject') ->inject('platform') ->inject('log') + ->inject('authorization') ->callback($this->action(...)); } - public function action(string $domain, string $siteId, ?string $branch, Response $response, Document $project, Certificate $publisherForCertificates, Event $queueForEvents, Database $dbForPlatform, Database $dbForProject, array $platform, Log $log) - { + public function action( + string $domain, + string $siteId, + ?string $branch, + Response $response, + Document $project, + Certificate $publisherForCertificates, + Event $queueForEvents, + Database $dbForPlatform, + Database $dbForProject, + array $platform, + Log $log, + Authorization $authorization, + ) { + $this->validateDomainRestrictions($domain, $platform); $site = $dbForProject->getDocument('sites', $siteId); @@ -126,7 +143,7 @@ class Create extends Action } try { - $rule = $dbForPlatform->createDocument('rules', $rule); + $rule = $authorization->skip(fn () => $dbForPlatform->createDocument('rules', $rule)); } catch (Duplicate $e) { throw new Exception(Exception::RULE_ALREADY_EXISTS); } @@ -144,6 +161,13 @@ class Create extends Action $queueForEvents->setParam('ruleId', $rule->getId()); + // Rename 'created' status to 'unverified' for consistency. + // 'verifying' and 'verified' statuses stay as is. + // 'unverified' in the meaning of failed certificate generation stays as is. + if ($rule->getAttribute('status') === 'created') { + $rule->setAttribute('status', 'unverified'); + } + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($rule, Response::MODEL_PROXY_RULE); From 879dc6873ec3f27e43f8453a1159e362e233082f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 May 2026 12:07:52 +0200 Subject: [PATCH 119/211] review fixes --- .../Modules/Proxy/Http/Rules/API/Create.php | 2 +- .../Proxy/Http/Rules/Function/Create.php | 2 +- .../Proxy/Http/Rules/Redirect/Create.php | 2 +- .../Modules/Proxy/Http/Rules/Site/Create.php | 2 +- tests/e2e/Services/Proxy/ProxyBase.php | 24 +++++++++---------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php index aaf94ef427..6f2e40d13f 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -49,7 +49,7 @@ class Create extends Action description: <<createAPIRule($domain); $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); + $this->assertEquals('unverified', $rule['body']['status']); } public function testCreateRuleVcs(): void @@ -421,7 +421,7 @@ trait ProxyBase $rule = $this->createAPIRule($domain); $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); + $this->assertEquals('unverified', $rule['body']['status']); $ruleId = $rule['body']['$id']; @@ -620,7 +620,7 @@ trait ProxyBase $rule = $this->createAPIRule('stage-site.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); + $this->assertEquals('unverified', $rule['body']['status']); $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['logs']); $this->cleanupRule($rule['body']['$id']); @@ -629,7 +629,7 @@ trait ProxyBase // 3. Wrong A record fails to verify $rule = $this->createAPIRule('wrong-a-webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); + $this->assertEquals('unverified', $rule['body']['status']); $this->assertStringContainsString('is missing CNAME record', $rule['body']['logs']); $ruleId = $rule['body']['$id']; @@ -639,7 +639,7 @@ trait ProxyBase $rule = $this->getRule($ruleId); $this->assertEquals(200, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); + $this->assertEquals('unverified', $rule['body']['status']); $this->cleanupRule($ruleId); @@ -662,7 +662,7 @@ trait ProxyBase // 6. Missing CNAME record fails to verify $rule = $this->createAPIRule('stage-missing-cname.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); + $this->assertEquals('unverified', $rule['body']['status']); $this->assertStringContainsString('is missing CNAME record', $rule['body']['logs']); $ruleId = $rule['body']['$id']; @@ -672,14 +672,14 @@ trait ProxyBase $rule = $this->getRule($ruleId); $this->assertEquals(200, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); + $this->assertEquals('unverified', $rule['body']['status']); $this->cleanupRule($ruleId); // 7. Wrong CNAME record fails to verify $rule = $this->createAPIRule('stage-wrong-cname.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); + $this->assertEquals('unverified', $rule['body']['status']); $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['logs']); $ruleId = $rule['body']['$id']; @@ -689,14 +689,14 @@ trait ProxyBase $rule = $this->getRule($ruleId); $this->assertEquals(200, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); + $this->assertEquals('unverified', $rule['body']['status']); $this->cleanupRule($ruleId); // 8. Wrong CAA record fails to verify $rule = $this->createAPIRule('stage-wrong-caa.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); + $this->assertEquals('unverified', $rule['body']['status']); $this->assertStringContainsString('has incorrect CAA value', $rule['body']['logs']); $ruleId = $rule['body']['$id']; @@ -706,7 +706,7 @@ trait ProxyBase $rule = $this->getRule($ruleId); $this->assertEquals(200, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); + $this->assertEquals('unverified', $rule['body']['status']); $this->cleanupRule($ruleId); @@ -725,7 +725,7 @@ trait ProxyBase $rule = $this->createAPIRule($domain); $this->assertEquals(201, $rule['headers']['status-code']); - $this->assertEquals('created', $rule['body']['status']); + $this->assertEquals('unverified', $rule['body']['status']); $this->assertNotEmpty($rule['body']['logs']); $ruleId = $rule['body']['$id']; From d7d0ecb106f385ddeb53d59f4831badfbfa132e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 May 2026 12:17:34 +0200 Subject: [PATCH 120/211] Fix failing tests --- tests/e2e/Services/Proxy/ProxyBase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Services/Proxy/ProxyBase.php b/tests/e2e/Services/Proxy/ProxyBase.php index 307c4b20db..32ee13b5f7 100644 --- a/tests/e2e/Services/Proxy/ProxyBase.php +++ b/tests/e2e/Services/Proxy/ProxyBase.php @@ -290,7 +290,7 @@ trait ProxyBase $this->assertNotEmpty($ruleId); $rule = $this->getRule($ruleId); $this->assertSame(200, $rule['headers']['status-code']); - $this->assertSame('created', $rule['body']['status']); + $this->assertSame('unverified', $rule['body']['status']); $response = $proxyClient->call(Client::METHOD_GET, '/contact'); $this->assertEquals(200, $response['headers']['status-code']); @@ -741,7 +741,7 @@ trait ProxyBase $ruleAfterUpdate = $this->getRule($ruleId); $this->assertEquals(200, $ruleAfterUpdate['headers']['status-code']); - $this->assertEquals('created', $ruleAfterUpdate['body']['status']); + $this->assertEquals('unverified', $ruleAfterUpdate['body']['status']); $this->assertEquals($initiallogs, $ruleAfterUpdate['body']['logs']); $this->assertNotEquals($initialUpdatedAt, $ruleAfterUpdate['body']['$updatedAt']); From 561b482e5439d4cce20b1c8735794453d7676e44 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 4 May 2026 11:20:00 +0100 Subject: [PATCH 121/211] Restore original sanitizeErrors decode/strip/encode flow --- src/Appwrite/Platform/Workers/Migrations.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 8025c20677..f5cc57a6c2 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -873,7 +873,7 @@ class Migrations extends Action } /** - * Encode migration errors as JSON strings for storage on the migration document. + * Sanitize migration errors, removing sensitive information like stack traces * * @param array $sourceErrors * @param array $destinationErrors @@ -883,10 +883,20 @@ class Migrations extends Action array $sourceErrors, array $destinationErrors, ): array { - return \array_map( - fn ($error) => \json_encode($error), - [...$sourceErrors, ...$destinationErrors], - ); + $errors = []; + foreach ([...$sourceErrors, ...$destinationErrors] as $error) { + $encoded = \json_decode(\json_encode($error), true); + if (\is_array($encoded)) { + if (isset($encoded['trace'])) { + unset($encoded['trace']); + } + $errors[] = \json_encode($encoded); + } else { + $errors[] = \json_encode($error); + } + } + + return $errors; } private function processMigrationResourceStats(array $resources, Context $usage, Document $projectDocument, UsagePublisher $publisherForUsage, string $source, Authorization $authorization, ?string $resourceId) From 1e9b364f5858db0036b692bcd6e58d3230394e8b Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 4 May 2026 16:50:38 +0530 Subject: [PATCH 122/211] feat(specs): include union of auth headers in every platform's securityDefinitions Each platform spec previously declared only the auth headers referenced by endpoints in that platform's surface. The unified web SDK now exposes a single Client class with cross-platform auth factories (fromSession, fromCookie, fromDevKey, etc.), which means an SDK generator targeting one platform still needs setter generation for headers that other platforms expose. The web SDK currently papers over this with a webClientHeaders augmentation in the SDK generator. Add the missing securityDefinitions entries directly so every platform spec carries the union, removing the need for SDK-side augmentation: - client: + Cookie (for SSR cookie forwarding) - server: + Cookie, DevKey - console: + Session, DevKey Per-endpoint security requirements continue to be filtered per platform as before; only the securityDefinitions registry expands to declare schemes that exist API-wide. SDKs that iterate the registry to emit auth setters now produce the union without per-SDK fallback code. --- src/Appwrite/Platform/Tasks/Specs.php | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index 82020b05b1..92f1f3d3f5 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -163,6 +163,12 @@ class Specs extends Action 'description' => 'Your secret dev API key', 'in' => 'header', ], + 'Cookie' => [ + 'type' => 'apiKey', + 'name' => 'Cookie', + 'description' => 'The user cookie to authenticate with. Used by SDKs that forward an incoming Cookie header in server-side runtimes.', + 'in' => 'header', + ], 'ImpersonateUserId' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Id', @@ -219,6 +225,18 @@ class Specs extends Action 'description' => 'The user agent string of the client that made the request', 'in' => 'header', ], + 'DevKey' => [ + 'type' => 'apiKey', + 'name' => 'X-Appwrite-Dev-Key', + 'description' => 'Your secret dev API key', + 'in' => 'header', + ], + 'Cookie' => [ + 'type' => 'apiKey', + 'name' => 'Cookie', + 'description' => 'The user cookie to authenticate with. Used by SDKs that forward an incoming Cookie header in server-side runtimes.', + 'in' => 'header', + ], 'ImpersonateUserId' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Id', @@ -275,6 +293,18 @@ class Specs extends Action 'description' => 'The user cookie to authenticate with', 'in' => 'header', ], + 'Session' => [ + 'type' => 'apiKey', + 'name' => 'X-Appwrite-Session', + 'description' => 'The user session to authenticate with', + 'in' => 'header', + ], + 'DevKey' => [ + 'type' => 'apiKey', + 'name' => 'X-Appwrite-Dev-Key', + 'description' => 'Your secret dev API key', + 'in' => 'header', + ], 'ImpersonateUserId' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Id', From e81ae6774576afebfae8cc114bfa5eaf26937e16 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 4 May 2026 16:53:22 +0530 Subject: [PATCH 123/211] fix(specs): align console Cookie description with client/server --- src/Appwrite/Platform/Tasks/Specs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index 92f1f3d3f5..c8120bd017 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -290,7 +290,7 @@ class Specs extends Action 'Cookie' => [ 'type' => 'apiKey', 'name' => 'Cookie', - 'description' => 'The user cookie to authenticate with', + 'description' => 'The user cookie to authenticate with. Used by SDKs that forward an incoming Cookie header in server-side runtimes.', 'in' => 'header', ], 'Session' => [ From d18f64d526187de8890b876553a21604954fe343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 May 2026 15:22:23 +0200 Subject: [PATCH 124/211] Fix endpoint consistency, apply request filter alias --- composer.json | 10 +- composer.lock | 193 +++++++++++------- .../Project/Http/Project/OAuth2/Get.php | 12 +- 3 files changed, 126 insertions(+), 89 deletions(-) diff --git a/composer.json b/composer.json index 735955d980..d6182ba750 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ "utopia-php/audit": "2.2.*", "utopia-php/auth": "0.5.*", "utopia-php/cache": "1.0.*", - "utopia-php/cli": "0.23.*", + "utopia-php/cli": "dev-feat-param-alias as 0.23.99", "utopia-php/compression": "0.1.*", "utopia-php/config": "1.*", "utopia-php/console": "0.1.*", @@ -67,7 +67,7 @@ "utopia-php/emails": "0.6.*", "utopia-php/dns": "1.6.*", "utopia-php/dsn": "0.2.1", - "utopia-php/http": "0.34.*", + "utopia-php/http": "dev-feat-param-aliases as 0.34.99", "utopia-php/fetch": "0.5.*", "utopia-php/validators": "0.2.*", "utopia-php/image": "0.8.*", @@ -75,12 +75,12 @@ "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.22.*", "utopia-php/migration": "1.9.*", - "utopia-php/platform": "0.13.*", + "utopia-php/platform": "dev-feat-param-aliases as 0.13.99", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", "utopia-php/preloader": "0.2.*", - "utopia-php/queue": "0.17.*", - "utopia-php/servers": "0.3.*", + "utopia-php/queue": "dev-feat-param-aliases as 0.17.99", + "utopia-php/servers": "dev-feat-param-aliases as 0.3.99", "utopia-php/registry": "0.5.*", "utopia-php/storage": "2.*", "utopia-php/system": "0.10.*", diff --git a/composer.lock b/composer.lock index 9f34d2dbe1..89ed556028 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": "bd45829c252971301370d62300be106d", + "content-hash": "ff46a826bc257b5ed2f0a8c821d8a0c4", "packages": [ { "name": "adhocore/jwt", @@ -2708,16 +2708,16 @@ }, { "name": "symfony/http-client", - "version": "v7.4.8", + "version": "v7.4.9", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "01933e626c3de76bea1e22641e205e78f6a34342" + "reference": "7e941c6abf4e3bf7dca160bf0e11ef36a9f832f6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/01933e626c3de76bea1e22641e205e78f6a34342", - "reference": "01933e626c3de76bea1e22641e205e78f6a34342", + "url": "https://api.github.com/repos/symfony/http-client/zipball/7e941c6abf4e3bf7dca160bf0e11ef36a9f832f6", + "reference": "7e941c6abf4e3bf7dca160bf0e11ef36a9f832f6", "shasum": "" }, "require": { @@ -2785,7 +2785,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.4.8" + "source": "https://github.com/symfony/http-client/tree/v7.4.9" }, "funding": [ { @@ -2805,7 +2805,7 @@ "type": "tidelift" } ], - "time": "2026-03-30T12:55:43+00:00" + "time": "2026-04-29T13:25:15+00:00" }, { "name": "symfony/http-client-contracts", @@ -3658,21 +3658,21 @@ }, { "name": "utopia-php/cli", - "version": "0.23.2", + "version": "dev-feat-param-alias", "source": { "type": "git", "url": "https://github.com/utopia-php/cli.git", - "reference": "145b91fef827853bcceaa3ab8ca2b1d6faaca2ab" + "reference": "c01a4af02249f20f5a9b3e23b6e8ee20f52857a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cli/zipball/145b91fef827853bcceaa3ab8ca2b1d6faaca2ab", - "reference": "145b91fef827853bcceaa3ab8ca2b1d6faaca2ab", + "url": "https://api.github.com/repos/utopia-php/cli/zipball/c01a4af02249f20f5a9b3e23b6e8ee20f52857a2", + "reference": "c01a4af02249f20f5a9b3e23b6e8ee20f52857a2", "shasum": "" }, "require": { "php": ">=7.4", - "utopia-php/servers": "0.3.*" + "utopia-php/servers": "dev-feat-param-aliases" }, "require-dev": { "laravel/pint": "1.2.*", @@ -3703,9 +3703,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cli/issues", - "source": "https://github.com/utopia-php/cli/tree/0.23.2" + "source": "https://github.com/utopia-php/cli/tree/feat-param-alias" }, - "time": "2026-04-27T09:19:04+00:00" + "time": "2026-05-04T12:39:30+00:00" }, { "name": "utopia-php/compression", @@ -3850,22 +3850,23 @@ }, { "name": "utopia-php/database", - "version": "5.4.1", + "version": "5.6.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "688d9422b5ff42ac2ecc29397d94891cfd772e93" + "reference": "609ebcd64be1ec6fab00c5f46fce54acb0031b3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/688d9422b5ff42ac2ecc29397d94891cfd772e93", - "reference": "688d9422b5ff42ac2ecc29397d94891cfd772e93", + "url": "https://api.github.com/repos/utopia-php/database/zipball/609ebcd64be1ec6fab00c5f46fce54acb0031b3c", + "reference": "609ebcd64be1ec6fab00c5f46fce54acb0031b3c", "shasum": "" }, "require": { "ext-mbstring": "*", "ext-mongodb": "*", "ext-pdo": "*", + "ext-redis": "*", "php": ">=8.4", "utopia-php/cache": "1.*", "utopia-php/console": "0.1.*", @@ -3903,9 +3904,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/5.4.1" + "source": "https://github.com/utopia-php/database/tree/5.6.0" }, - "time": "2026-04-29T07:32:59+00:00" + "time": "2026-05-01T01:28:07+00:00" }, { "name": "utopia-php/detector", @@ -4271,23 +4272,23 @@ }, { "name": "utopia-php/http", - "version": "0.34.24", + "version": "dev-feat-param-aliases", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "d1eced0627c5a9fceddf53992ed97d664b810d33" + "reference": "4439705c8c2e81af826f4b6d694469c9ebc84a9f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/d1eced0627c5a9fceddf53992ed97d664b810d33", - "reference": "d1eced0627c5a9fceddf53992ed97d664b810d33", + "url": "https://api.github.com/repos/utopia-php/http/zipball/4439705c8c2e81af826f4b6d694469c9ebc84a9f", + "reference": "4439705c8c2e81af826f4b6d694469c9ebc84a9f", "shasum": "" }, "require": { "php": ">=8.3", "utopia-php/compression": "0.1.*", "utopia-php/di": "0.3.*", - "utopia-php/servers": "0.3.*", + "utopia-php/servers": "dev-feat-param-aliases as 0.3.x-dev", "utopia-php/telemetry": "0.2.*", "utopia-php/validators": "0.2.*" }, @@ -4321,9 +4322,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.34.24" + "source": "https://github.com/utopia-php/http/tree/feat-param-aliases" }, - "time": "2026-04-24T12:16:53+00:00" + "time": "2026-05-04T11:52:49+00:00" }, { "name": "utopia-php/image", @@ -4530,16 +4531,16 @@ }, { "name": "utopia-php/migration", - "version": "1.9.5", + "version": "1.9.6", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "952a4dfe232702f80e45c35129466a8d8cb4c599" + "reference": "b164631404ec759f8c368fe2321f44c22bc258ab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/952a4dfe232702f80e45c35129466a8d8cb4c599", - "reference": "952a4dfe232702f80e45c35129466a8d8cb4c599", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/b164631404ec759f8c368fe2321f44c22bc258ab", + "reference": "b164631404ec759f8c368fe2321f44c22bc258ab", "shasum": "" }, "require": { @@ -4579,9 +4580,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.9.5" + "source": "https://github.com/utopia-php/migration/tree/1.9.6" }, - "time": "2026-04-29T11:19:13+00:00" + "time": "2026-04-30T08:11:07+00:00" }, { "name": "utopia-php/mongo", @@ -4646,26 +4647,26 @@ }, { "name": "utopia-php/platform", - "version": "0.13.0", + "version": "dev-feat-param-aliases", "source": { "type": "git", "url": "https://github.com/utopia-php/platform.git", - "reference": "d23af5349a7ea9ee11f9920a13626226f985522e" + "reference": "7fa008758c869671014ae4c4d52bb8cd686212f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/platform/zipball/d23af5349a7ea9ee11f9920a13626226f985522e", - "reference": "d23af5349a7ea9ee11f9920a13626226f985522e", + "url": "https://api.github.com/repos/utopia-php/platform/zipball/7fa008758c869671014ae4c4d52bb8cd686212f9", + "reference": "7fa008758c869671014ae4c4d52bb8cd686212f9", "shasum": "" }, "require": { "ext-json": "*", "ext-redis": "*", - "php": ">=8.1", - "utopia-php/cli": "0.23.*", - "utopia-php/http": "0.34.*", - "utopia-php/queue": "0.17.*", - "utopia-php/servers": "0.3.*" + "php": ">=8.3", + "utopia-php/cli": "dev-feat-param-alias as 0.23.99", + "utopia-php/http": "dev-feat-param-aliases as 0.34.99", + "utopia-php/queue": "dev-feat-param-aliases as 0.18.99", + "utopia-php/servers": "dev-feat-param-aliases as 0.3.99" }, "require-dev": { "laravel/pint": "1.2.*", @@ -4691,9 +4692,9 @@ ], "support": { "issues": "https://github.com/utopia-php/platform/issues", - "source": "https://github.com/utopia-php/platform/tree/0.13.0" + "source": "https://github.com/utopia-php/platform/tree/feat-param-aliases" }, - "time": "2026-04-17T09:57:18+00:00" + "time": "2026-05-04T13:12:58+00:00" }, { "name": "utopia-php/pools", @@ -4803,25 +4804,24 @@ }, { "name": "utopia-php/queue", - "version": "0.17.0", + "version": "dev-feat-param-aliases", "source": { "type": "git", "url": "https://github.com/utopia-php/queue.git", - "reference": "0fbc7d7312f5cf76ec112513fb93317000901f5f" + "reference": "32b0c439a8fa4fc06b8b8793800a04be894bf03c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/queue/zipball/0fbc7d7312f5cf76ec112513fb93317000901f5f", - "reference": "0fbc7d7312f5cf76ec112513fb93317000901f5f", + "url": "https://api.github.com/repos/utopia-php/queue/zipball/32b0c439a8fa4fc06b8b8793800a04be894bf03c", + "reference": "32b0c439a8fa4fc06b8b8793800a04be894bf03c", "shasum": "" }, "require": { "php": ">=8.3", "php-amqplib/php-amqplib": "^3.7", "utopia-php/di": "0.3.*", - "utopia-php/fetch": "0.5.*", "utopia-php/pools": "1.*", - "utopia-php/servers": "0.3.*", + "utopia-php/servers": "dev-feat-param-aliases as 0.3.99", "utopia-php/telemetry": "0.2.*", "utopia-php/validators": "0.2.*" }, @@ -4864,9 +4864,9 @@ ], "support": { "issues": "https://github.com/utopia-php/queue/issues", - "source": "https://github.com/utopia-php/queue/tree/0.17.0" + "source": "https://github.com/utopia-php/queue/tree/feat-param-aliases" }, - "time": "2026-03-23T16:21:31+00:00" + "time": "2026-05-04T12:59:54+00:00" }, { "name": "utopia-php/registry", @@ -4922,16 +4922,16 @@ }, { "name": "utopia-php/servers", - "version": "0.3.0", + "version": "dev-feat-param-aliases", "source": { "type": "git", "url": "https://github.com/utopia-php/servers.git", - "reference": "235be31200df9437fc96a1c270ffef4c64fafe52" + "reference": "24bbd8fbb6550bc72f2816d9b0c3b690e38e17fa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/235be31200df9437fc96a1c270ffef4c64fafe52", - "reference": "235be31200df9437fc96a1c270ffef4c64fafe52", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/24bbd8fbb6550bc72f2816d9b0c3b690e38e17fa", + "reference": "24bbd8fbb6550bc72f2816d9b0c3b690e38e17fa", "shasum": "" }, "require": { @@ -4970,9 +4970,9 @@ ], "support": { "issues": "https://github.com/utopia-php/servers/issues", - "source": "https://github.com/utopia-php/servers/tree/0.3.0" + "source": "https://github.com/utopia-php/servers/tree/feat-param-aliases" }, - "time": "2026-03-13T11:31:42+00:00" + "time": "2026-05-04T11:57:44+00:00" }, { "name": "utopia-php/span", @@ -5465,16 +5465,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.25.1", + "version": "1.26.0", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "f21a556b9acdbf75bbdcdc90a078af641646eade" + "reference": "c14a7232ef0f22f594453730407c2719a2854973" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/f21a556b9acdbf75bbdcdc90a078af641646eade", - "reference": "f21a556b9acdbf75bbdcdc90a078af641646eade", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/c14a7232ef0f22f594453730407c2719a2854973", + "reference": "c14a7232ef0f22f594453730407c2719a2854973", "shasum": "" }, "require": { @@ -5510,9 +5510,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.25.1" + "source": "https://github.com/appwrite/sdk-generator/tree/1.26.0" }, - "time": "2026-04-28T11:12:22+00:00" + "time": "2026-05-04T09:46:22+00:00" }, { "name": "brianium/paratest", @@ -6619,16 +6619,16 @@ }, { "name": "phpunit/phpunit", - "version": "12.5.23", + "version": "12.5.24", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c54fcf3d6bcb6e96ac2f7e40097dc37b5f139969" + "reference": "d75dd30597caa80e72fad2ef7904601a30ef1046" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c54fcf3d6bcb6e96ac2f7e40097dc37b5f139969", - "reference": "c54fcf3d6bcb6e96ac2f7e40097dc37b5f139969", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d75dd30597caa80e72fad2ef7904601a30ef1046", + "reference": "d75dd30597caa80e72fad2ef7904601a30ef1046", "shasum": "" }, "require": { @@ -6697,7 +6697,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.23" + "source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.24" }, "funding": [ { @@ -6705,7 +6705,7 @@ "type": "other" } ], - "time": "2026-04-18T06:12:49+00:00" + "time": "2026-05-01T04:21:04+00:00" }, { "name": "sebastian/cli-parser", @@ -7690,16 +7690,16 @@ }, { "name": "symfony/console", - "version": "v8.0.8", + "version": "v8.0.9", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "5b66d385dc58f69652e56f78a4184615e3f2b7f7" + "reference": "7113778e2e91f4709cb3194a75dfa9c0d028d94d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/5b66d385dc58f69652e56f78a4184615e3f2b7f7", - "reference": "5b66d385dc58f69652e56f78a4184615e3f2b7f7", + "url": "https://api.github.com/repos/symfony/console/zipball/7113778e2e91f4709cb3194a75dfa9c0d028d94d", + "reference": "7113778e2e91f4709cb3194a75dfa9c0d028d94d", "shasum": "" }, "require": { @@ -7756,7 +7756,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v8.0.8" + "source": "https://github.com/symfony/console/tree/v8.0.9" }, "funding": [ { @@ -7776,7 +7776,7 @@ "type": "tidelift" } ], - "time": "2026-03-30T15:14:47+00:00" + "time": "2026-04-29T15:02:55+00:00" }, { "name": "symfony/polyfill-ctype", @@ -8442,9 +8442,46 @@ "time": "2024-11-07T12:36:22+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/cli", + "version": "dev-feat-param-alias", + "alias": "0.23.99", + "alias_normalized": "0.23.99.0" + }, + { + "package": "utopia-php/http", + "version": "dev-feat-param-aliases", + "alias": "0.34.99", + "alias_normalized": "0.34.99.0" + }, + { + "package": "utopia-php/platform", + "version": "dev-feat-param-aliases", + "alias": "0.13.99", + "alias_normalized": "0.13.99.0" + }, + { + "package": "utopia-php/queue", + "version": "dev-feat-param-aliases", + "alias": "0.17.99", + "alias_normalized": "0.17.99.0" + }, + { + "package": "utopia-php/servers", + "version": "dev-feat-param-aliases", + "alias": "0.3.99", + "alias_normalized": "0.3.99.0" + } + ], "minimum-stability": "dev", - "stability-flags": {}, + "stability-flags": { + "utopia-php/cli": 20, + "utopia-php/http": 20, + "utopia-php/platform": 20, + "utopia-php/queue": 20, + "utopia-php/servers": 20 + }, "prefer-stable": true, "prefer-lowest": false, "platform": { diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Get.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Get.php index ae46a59c67..97358548d6 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Get.php @@ -11,7 +11,7 @@ use Utopia\Config\Config; use Utopia\Database\Document; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; -use Utopia\Validator\Text; +use Utopia\Validator\WhiteList; class Get extends Action { @@ -86,28 +86,28 @@ class Get extends Action ) ] )) - ->param('provider', '', new Text(128), 'OAuth2 provider key. For example: github, google, apple.') + ->param('providerId', '', new WhiteList(Config::getParam('oAuthProviders', [])), 'OAuth2 provider key. For example: github, google, apple.', aliases: ['provider']) ->inject('response') ->inject('project') ->callback($this->action(...)); } public function action( - string $provider, + string $providerId, Response $response, Document $project, ): void { $providers = Config::getParam('oAuthProviders', []); - if (!\array_key_exists($provider, $providers) || !($providers[$provider]['enabled'] ?? false)) { + if (!\array_key_exists($providerId, $providers) || !($providers[$providerId]['enabled'] ?? false)) { throw new Exception(Exception::PROJECT_PROVIDER_UNSUPPORTED); } $actions = Base::getProviderActions(); - if (!isset($actions[$provider])) { + if (!isset($actions[$providerId])) { throw new Exception(Exception::PROJECT_PROVIDER_UNSUPPORTED); } - $updateClass = $actions[$provider]; + $updateClass = $actions[$providerId]; $action = new $updateClass(); $response->dynamic($action->buildReadResponse($project), $updateClass::getResponseModel()); From b1c3fc090885e0782c6a9f99f159b7e6ebb330d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 May 2026 15:40:32 +0200 Subject: [PATCH 125/211] Update tests --- tests/e2e/Services/Project/OAuth2Base.php | 26 +++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Services/Project/OAuth2Base.php b/tests/e2e/Services/Project/OAuth2Base.php index 5451435c3c..5286e3f653 100644 --- a/tests/e2e/Services/Project/OAuth2Base.php +++ b/tests/e2e/Services/Project/OAuth2Base.php @@ -188,6 +188,28 @@ trait OAuth2Base $this->assertSame('', $response['body']['clientSecret']); } + public function testGetOAuth2ProviderWithAlias(): void + { + // The action declares the canonical param name as `providerId` and + // registers `provider` as an alias so that older SDK versions that + // send the provider in the query string continue to work. + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]; + $headers = \array_merge($headers, $this->getHeaders()); + + // Call with `provider` in query string (legacy behaviour) + $response = $this->client->call( + Client::METHOD_GET, + '/project/oauth2/github?provider=github', + $headers, + ); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame('github', $response['body']['$id']); + } + public function testGetOAuth2ProviderClientSecretWriteOnly(): void { $this->updateOAuth2('amazon', [ @@ -2573,7 +2595,7 @@ trait OAuth2Base ); } - protected function getOAuth2Provider(string $provider, bool $authenticated = true): mixed + protected function getOAuth2Provider(string $providerId, bool $authenticated = true): mixed { $headers = [ 'content-type' => 'application/json', @@ -2586,7 +2608,7 @@ trait OAuth2Base return $this->client->call( Client::METHOD_GET, - '/project/oauth2/' . $provider, + '/project/oauth2/' . $providerId, $headers, ); } From d2922e7d5d064f88fd4dc0078be63041d65470e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 May 2026 15:49:05 +0200 Subject: [PATCH 126/211] Fix failing tests --- .../Modules/Project/Http/Project/OAuth2/Get.php | 2 +- tests/e2e/Services/Project/OAuth2Base.php | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Get.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Get.php index 97358548d6..250a3e5df1 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Get.php @@ -86,7 +86,7 @@ class Get extends Action ) ] )) - ->param('providerId', '', new WhiteList(Config::getParam('oAuthProviders', [])), 'OAuth2 provider key. For example: github, google, apple.', aliases: ['provider']) + ->param('providerId', '', new WhiteList(\array_keys(Config::getParam('oAuthProviders', [])), true), 'OAuth2 provider key. For example: github, google, apple.', aliases: ['provider']) ->inject('response') ->inject('project') ->callback($this->action(...)); diff --git a/tests/e2e/Services/Project/OAuth2Base.php b/tests/e2e/Services/Project/OAuth2Base.php index 5286e3f653..97ffc4a50b 100644 --- a/tests/e2e/Services/Project/OAuth2Base.php +++ b/tests/e2e/Services/Project/OAuth2Base.php @@ -243,19 +243,23 @@ trait OAuth2Base public function testGetOAuth2ProviderUnsupported(): void { + // The `providerId` param is validated by a WhiteList of registered + // OAuth2 provider keys, so an unknown value is rejected at validation + // time — before the action runs — and surfaces as a generic argument + // error rather than `project_provider_unsupported`. $response = $this->getOAuth2Provider('not-a-real-provider'); $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('project_provider_unsupported', $response['body']['type']); + $this->assertSame('general_argument_invalid', $response['body']['type']); } public function testGetOAuth2ProviderRegisteredInConfigButNoUpdateClass(): void { - // `mock` is present in oAuthProviders config (enabled: true) but is NOT - // registered in Base::getProviderActions(). Get::action has two - // separate `unsupported` throw branches — testGetOAuth2ProviderUnsupported - // covers the first (provider missing from config); this covers the - // second (provider in config but missing from the action registry). + // `mock` is present in oAuthProviders config (enabled: true) but is + // NOT registered in Base::getProviderActions(). It passes the + // WhiteList validator (which only checks config membership) and + // reaches the action body, where the action-registry check throws + // `project_provider_unsupported`. $response = $this->getOAuth2Provider('mock'); $this->assertSame(400, $response['headers']['status-code']); From c35d5e348b5d01ae2619961e8b38c931e5bb908c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 May 2026 16:05:46 +0200 Subject: [PATCH 127/211] Support queries in oauth list endpoint --- .../Project/Http/Project/OAuth2/XList.php | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/XList.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/XList.php index d0780e4bae..6a84868286 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/XList.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/XList.php @@ -2,14 +2,21 @@ namespace Appwrite\Platform\Modules\Project\Http\Project\OAuth2; +use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response; use Utopia\Config\Config; use Utopia\Database\Document; +use Utopia\Database\Exception\Query as QueryException; +use Utopia\Database\Query; +use Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Query\Limit; +use Utopia\Database\Validator\Query\Offset; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; +use Utopia\Validator\Boolean; class XList extends Action { @@ -43,15 +50,28 @@ class XList extends Action ) ] )) + ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('project') ->callback($this->action(...)); } + /** + * @param array $queries + */ public function action( + array $queries, + bool $includeTotal, Response $response, Document $project, ): void { + try { + $queries = Query::parseQueries($queries); + } catch (QueryException $e) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); + } + $providers = Config::getParam('oAuthProviders', []); $actions = Base::getProviderActions(); @@ -66,8 +86,16 @@ class XList extends Action $documents[] = $action->buildReadResponse($project); } + $total = $includeTotal ? \count($documents) : 0; + + $grouped = Query::groupByType($queries); + $offset = $grouped['offset'] ?? 0; + $limit = $grouped['limit'] ?? null; + + $documents = \array_slice($documents, $offset, $limit); + $response->dynamic(new Document([ - 'total' => \count($documents), + 'total' => $total, 'providers' => $documents, ]), Response::MODEL_OAUTH2_PROVIDER_LIST); } From 4d5bb309179d12cec7fb4bf1b45f721c1db85fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 May 2026 16:05:56 +0200 Subject: [PATCH 128/211] tests for oauth list endpoint ueries and total --- tests/e2e/Services/Project/OAuth2Base.php | 48 ++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/e2e/Services/Project/OAuth2Base.php b/tests/e2e/Services/Project/OAuth2Base.php index 5451435c3c..955f95c608 100644 --- a/tests/e2e/Services/Project/OAuth2Base.php +++ b/tests/e2e/Services/Project/OAuth2Base.php @@ -5,6 +5,7 @@ namespace Tests\E2E\Services\Project; use PHPUnit\Framework\Attributes\Before; use PHPUnit\Framework\Attributes\DataProvider; use Tests\E2E\Client; +use Utopia\Database\Query; trait OAuth2Base { @@ -172,6 +173,40 @@ trait OAuth2Base $this->assertNotContains('mock-unverified', $ids); } + public function testListOAuth2ProvidersTotalFalse(): void + { + $response = $this->listOAuth2Providers(total: false); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame(0, $response['body']['total']); + $this->assertGreaterThan(0, \count($response['body']['providers'])); + } + + public function testListOAuth2ProvidersWithLimit(): void + { + $response = $this->listOAuth2Providers([ + Query::limit(1)->toString(), + ]); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertCount(1, $response['body']['providers']); + $this->assertGreaterThan(1, $response['body']['total']); + } + + public function testListOAuth2ProvidersWithOffset(): void + { + $listAll = $this->listOAuth2Providers(); + $this->assertSame(200, $listAll['headers']['status-code']); + + $listOffset = $this->listOAuth2Providers([ + Query::offset(1)->toString(), + ]); + + $this->assertSame(200, $listOffset['headers']['status-code']); + $this->assertCount(\count($listAll['body']['providers']) - 1, $listOffset['body']['providers']); + $this->assertSame($listAll['body']['total'], $listOffset['body']['total']); + } + // ========================================================================= // Get OAuth2 provider // ========================================================================= @@ -2591,8 +2626,18 @@ trait OAuth2Base ); } - protected function listOAuth2Providers(bool $authenticated = true): mixed + protected function listOAuth2Providers(?array $queries = null, ?bool $total = null, bool $authenticated = true): mixed { + $params = []; + + if ($queries !== null) { + $params['queries'] = $queries; + } + + if ($total !== null) { + $params['total'] = $total; + } + $headers = [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -2606,6 +2651,7 @@ trait OAuth2Base Client::METHOD_GET, '/project/oauth2', $headers, + $params, ); } } From 1a410c43d79ec837e54c48d4d34753c61e16fbef Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 5 May 2026 10:54:01 +0530 Subject: [PATCH 129/211] fix: update graphql php dependency --- composer.json | 2 +- composer.lock | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 735955d980..236e3aa83d 100644 --- a/composer.json +++ b/composer.json @@ -93,7 +93,7 @@ "chillerlan/php-qrcode": "4.3.*", "adhocore/jwt": "1.1.*", "spomky-labs/otphp": "11.*", - "webonyx/graphql-php": "15.31.*", + "webonyx/graphql-php": "15.32.*", "league/csv": "9.14.*", "enshrined/svg-sanitize": "0.22.*" }, diff --git a/composer.lock b/composer.lock index 9f34d2dbe1..a155f3f68b 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": "bd45829c252971301370d62300be106d", + "content-hash": "2af4d953af2a624be8bf2f89ea27336c", "packages": [ { "name": "adhocore/jwt", @@ -5384,16 +5384,16 @@ }, { "name": "webonyx/graphql-php", - "version": "v15.31.5", + "version": "v15.32.3", "source": { "type": "git", "url": "https://github.com/webonyx/graphql-php.git", - "reference": "089c4ef7e112df85788cfe06596278a8f99f4aa9" + "reference": "993bf0bea17f870412ad8a90f60c41cb8d5f1145" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/089c4ef7e112df85788cfe06596278a8f99f4aa9", - "reference": "089c4ef7e112df85788cfe06596278a8f99f4aa9", + "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/993bf0bea17f870412ad8a90f60c41cb8d5f1145", + "reference": "993bf0bea17f870412ad8a90f60c41cb8d5f1145", "shasum": "" }, "require": { @@ -5402,16 +5402,16 @@ "php": "^7.4 || ^8" }, "require-dev": { - "amphp/amp": "^2.6", - "amphp/http-server": "^2.1", + "amphp/amp": "^2.6 || ^3", + "amphp/http-server": "^2.1 || ^3", "dms/phpunit-arraysubset-asserts": "dev-master", "ergebnis/composer-normalize": "^2.28", - "friendsofphp/php-cs-fixer": "3.94.2", + "friendsofphp/php-cs-fixer": "3.95.1", "mll-lab/php-cs-fixer-config": "5.13.0", "nyholm/psr7": "^1.5", "phpbench/phpbench": "^1.2", "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "2.1.46", + "phpstan/phpstan": "2.1.51", "phpstan/phpstan-phpunit": "2.0.16", "phpstan/phpstan-strict-rules": "2.0.10", "phpunit/phpunit": "^9.5 || ^10.5.21 || ^11", @@ -5425,6 +5425,7 @@ "ticketswap/phpstan-error-formatter": "1.3.0" }, "suggest": { + "amphp/amp": "To leverage async resolving on AMPHP platform (v3 with AmpFutureAdapter, v2 with AmpPromiseAdapter)", "amphp/http-server": "To leverage async resolving with webserver on AMPHP platform", "psr/http-message": "To use standard GraphQL server", "react/promise": "To leverage async resolving on React PHP platform" @@ -5447,7 +5448,7 @@ ], "support": { "issues": "https://github.com/webonyx/graphql-php/issues", - "source": "https://github.com/webonyx/graphql-php/tree/v15.31.5" + "source": "https://github.com/webonyx/graphql-php/tree/v15.32.3" }, "funding": [ { @@ -5459,7 +5460,7 @@ "type": "open_collective" } ], - "time": "2026-04-11T18:06:15+00:00" + "time": "2026-04-24T13:49:35+00:00" } ], "packages-dev": [ From 9ab546d743ed4932974111884f3fc0817b23e1b4 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 5 May 2026 09:11:18 +0100 Subject: [PATCH 130/211] composer: pin utopia-php/migration to 1.9.7 (released) --- composer.json | 2 +- composer.lock | 27 +++++++++------------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index a040ce2de8..683da6f21b 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,7 @@ "utopia-php/locale": "0.8.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.22.*", - "utopia-php/migration": "dev-feat/skip-duplicates as 1.9.99", + "utopia-php/migration": "1.9.*", "utopia-php/platform": "0.13.*", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", diff --git a/composer.lock b/composer.lock index ee77812b4b..6323a9a20a 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": "988e787481b0b962a21266142ec03467", + "content-hash": "4bee36b21a57e754d2b3417e72dc9599", "packages": [ { "name": "adhocore/jwt", @@ -4530,16 +4530,16 @@ }, { "name": "utopia-php/migration", - "version": "dev-feat/skip-duplicates", + "version": "1.9.7", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "d7c3d0536dbb9e37a4894cd0b3b0134a483e04e8" + "reference": "81b608a6871f56b70496803d12010823300aab6e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/d7c3d0536dbb9e37a4894cd0b3b0134a483e04e8", - "reference": "d7c3d0536dbb9e37a4894cd0b3b0134a483e04e8", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/81b608a6871f56b70496803d12010823300aab6e", + "reference": "81b608a6871f56b70496803d12010823300aab6e", "shasum": "" }, "require": { @@ -4579,9 +4579,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/feat/skip-duplicates" + "source": "https://github.com/utopia-php/migration/tree/1.9.7" }, - "time": "2026-04-30T11:08:08+00:00" + "time": "2026-05-05T07:18:48+00:00" }, { "name": "utopia-php/mongo", @@ -8442,18 +8442,9 @@ "time": "2024-11-07T12:36:22+00:00" } ], - "aliases": [ - { - "package": "utopia-php/migration", - "version": "dev-feat/skip-duplicates", - "alias": "1.9.99", - "alias_normalized": "1.9.99.0" - } - ], + "aliases": [], "minimum-stability": "dev", - "stability-flags": { - "utopia-php/migration": 20 - }, + "stability-flags": {}, "prefer-stable": true, "prefer-lowest": false, "platform": { From b0220292a706c8256c0c61c6a8d506f37cd97ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 5 May 2026 12:58:06 +0200 Subject: [PATCH 131/211] Rename policies to prevent double scope usease --- app/config/roles.php | 4 ++-- app/config/scopes/project.php | 14 +++++++++++++- .../Modules/Project/Http/Project/Policies/Get.php | 2 +- .../Project/Http/Project/Policies/XList.php | 2 +- src/Appwrite/Platform/Workers/Migrations.php | 4 ++-- tests/e2e/Scopes/ProjectCustom.php | 4 ++-- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/config/roles.php b/app/config/roles.php index 8fba27e503..04175ac1d5 100644 --- a/app/config/roles.php +++ b/app/config/roles.php @@ -59,8 +59,8 @@ $admins = [ 'oauth2.write', 'mocks.read', 'mocks.write', - 'policies.read', - 'policies.write', + 'project.policies.read', + 'project.policies.write', 'templates.read', 'templates.write', 'projects.write', diff --git a/app/config/scopes/project.php b/app/config/scopes/project.php index a048920de9..6e019e7b93 100644 --- a/app/config/scopes/project.php +++ b/app/config/scopes/project.php @@ -44,11 +44,23 @@ return [ "category" => "Project", ], "policies.read" => [ + "description" => + "Access to read project\'s policies. Replaced by \'project.policies.read\' for more granular control.", + "category" => "Project", + 'deprecated' => true, + ], + "policies.write" => [ + "description" => + "Access to update project\'s policies. Replaces by \'project.policies.read\' for more granular control.", + "category" => "Project", + 'deprecated' => true, + ], + "project.policies.read" => [ "description" => "Access to read project\'s policies", "category" => "Project", ], - "policies.write" => [ + "project.policies.write" => [ "description" => "Access to update project\'s policies", "category" => "Project", diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php index 3ffe30f1fa..21342332d9 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php @@ -27,7 +27,7 @@ class Get extends Action ->setHttpPath('/v1/project/policies/:policyId') ->desc('Get project policy') ->groups(['api', 'project']) - ->label('scope', 'policies.read') + ->label('scope', ['policies.read', 'project.policies.read']) ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php index 893b28fef2..3020fa79dd 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php @@ -33,7 +33,7 @@ class XList extends Action ->setHttpPath('/v1/project/policies') ->desc('List project policies') ->groups(['api', 'project']) - ->label('scope', 'policies.read') + ->label('scope', ['policies.read', 'project.policies.read']) ->label('sdk', new Method( namespace: 'project', group: 'policies', diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index c25a83c231..3fd86baea9 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -380,8 +380,8 @@ class Migrations extends Action 'oauth2.write', 'mocks.read', 'mocks.write', - 'policies.read', - 'policies.write', + 'project.policies.read', + 'project.policies.write', 'templates.read', 'templates.write', ]; diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index 3071ddfa2a..99219ebf99 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -173,8 +173,8 @@ trait ProjectCustom 'oauth2.write', 'mocks.read', 'mocks.write', - 'policies.read', - 'policies.write', + 'project.policies.read', + 'project.policies.write', 'templates.read', 'templates.write', ], From 32d30dfd9d1e9a823611296859afa5168b3a0639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 5 May 2026 13:06:57 +0200 Subject: [PATCH 132/211] Fix copy --- app/config/scopes/project.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/config/scopes/project.php b/app/config/scopes/project.php index 6e019e7b93..7a61524b87 100644 --- a/app/config/scopes/project.php +++ b/app/config/scopes/project.php @@ -45,13 +45,13 @@ return [ ], "policies.read" => [ "description" => - "Access to read project\'s policies. Replaced by \'project.policies.read\' for more granular control.", + "Access to read project\'s policies. Replaced by \'project.policies.read\' for more granular control", "category" => "Project", 'deprecated' => true, ], "policies.write" => [ "description" => - "Access to update project\'s policies. Replaces by \'project.policies.read\' for more granular control.", + "Access to update project\'s policies. Replaces by \'project.policies.write\' for more granular control", "category" => "Project", 'deprecated' => true, ], From fef4cbf3b04006f7f96879e6a6c2118bad20953f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 5 May 2026 13:37:51 +0200 Subject: [PATCH 133/211] Fix missing new scope --- .../Project/Http/Project/Policies/MembershipPrivacy/Update.php | 2 +- .../Project/Http/Project/Policies/PasswordDictionary/Update.php | 2 +- .../Project/Http/Project/Policies/PasswordHistory/Update.php | 2 +- .../Http/Project/Policies/PasswordPersonalData/Update.php | 2 +- .../Project/Http/Project/Policies/SessionAlert/Update.php | 2 +- .../Project/Http/Project/Policies/SessionDuration/Update.php | 2 +- .../Http/Project/Policies/SessionInvalidation/Update.php | 2 +- .../Project/Http/Project/Policies/SessionLimit/Update.php | 2 +- .../Modules/Project/Http/Project/Policies/UserLimit/Update.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php index c947ff225a..41a6168b07 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php @@ -31,7 +31,7 @@ class Update extends Action ->httpAlias('/v1/projects/:projectId/auth/memberships-privacy') ->desc('Update membership privacy policy') ->groups(['api', 'project']) - ->label('scope', 'policies.write') + ->label('scope', ['policies.write', 'project.policies.write']) ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php index e2c678abb6..d7ee99fbfe 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php @@ -31,7 +31,7 @@ class Update extends Action ->httpAlias('/v1/projects/:projectId/auth/password-dictionary') ->desc('Update password dictionary policy') ->groups(['api', 'project']) - ->label('scope', 'policies.write') + ->label('scope', ['policies.write', 'project.policies.write']) ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php index a8ae81caff..84861a19e1 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php @@ -32,7 +32,7 @@ class Update extends Action ->httpAlias('/v1/projects/:projectId/auth/password-history') ->desc('Update password history policy') ->groups(['api', 'project']) - ->label('scope', 'policies.write') + ->label('scope', ['policies.write', 'project.policies.write']) ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php index 9db7cf0549..435f00fc39 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php @@ -31,7 +31,7 @@ class Update extends Action ->httpAlias('/v1/projects/:projectId/auth/personal-data') ->desc('Update password personal data policy') ->groups(['api', 'project']) - ->label('scope', 'policies.write') + ->label('scope', ['policies.write', 'project.policies.write']) ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php index 22b7a44b04..79653d46ad 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php @@ -31,7 +31,7 @@ class Update extends Action ->httpAlias('/v1/projects/:projectId/auth/session-alerts') ->desc('Update session alert policy') ->groups(['api', 'project']) - ->label('scope', 'policies.write') + ->label('scope', ['policies.write', 'project.policies.write']) ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php index ba72c93a6f..0a7f33218a 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php @@ -31,7 +31,7 @@ class Update extends Action ->httpAlias('/v1/projects/:projectId/auth/duration') ->desc('Update session duration policy') ->groups(['api', 'project']) - ->label('scope', 'policies.write') + ->label('scope', ['policies.write', 'project.policies.write']) ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php index 8f8a959959..a1feb67346 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php @@ -31,7 +31,7 @@ class Update extends Action ->httpAlias('/v1/projects/:projectId/auth/session-invalidation') ->desc('Update session invalidation policy') ->groups(['api', 'project']) - ->label('scope', 'policies.write') + ->label('scope', ['policies.write', 'project.policies.write']) ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php index 382ed6f0d9..936a541249 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php @@ -32,7 +32,7 @@ class Update extends Action ->httpAlias('/v1/projects/:projectId/auth/max-sessions') ->desc('Update session limit policy') ->groups(['api', 'project']) - ->label('scope', 'policies.write') + ->label('scope', ['policies.write', 'project.policies.write']) ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php index 9129b81250..2b7e704853 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php @@ -32,7 +32,7 @@ class Update extends Action ->httpAlias('/v1/projects/:projectId/auth/limit') ->desc('Update user limit policy') ->groups(['api', 'project']) - ->label('scope', 'policies.write') + ->label('scope', ['policies.write', 'project.policies.write']) ->label('event', 'projects.[projectId].policies.[policy].update') ->label('audits.event', 'projects.[projectId].policies.[policy].update') ->label('audits.resource', 'project/{response.$id}') From 90e681a9066da41177dd9a2211cee4c126df2069 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 5 May 2026 19:20:47 +0530 Subject: [PATCH 134/211] updated --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index d8c19b75ac..eb6212a620 100644 --- a/composer.lock +++ b/composer.lock @@ -3854,12 +3854,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "dd1077a1548a2a0a07469181e3421f35e27daf3b" + "reference": "ee8895a3ae835978fa4eb143619e4950e7001648" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/dd1077a1548a2a0a07469181e3421f35e27daf3b", - "reference": "dd1077a1548a2a0a07469181e3421f35e27daf3b", + "url": "https://api.github.com/repos/utopia-php/database/zipball/ee8895a3ae835978fa4eb143619e4950e7001648", + "reference": "ee8895a3ae835978fa4eb143619e4950e7001648", "shasum": "" }, "require": { @@ -3906,7 +3906,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/big-init" }, - "time": "2026-05-05T13:22:35+00:00" + "time": "2026-05-05T13:27:52+00:00" }, { "name": "utopia-php/detector", From 57dd7cf95229157828398adb06e6f428e79d999b Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 5 May 2026 19:22:00 +0530 Subject: [PATCH 135/211] updated --- src/Appwrite/Utopia/Response/Model/AttributeBigInt.php | 1 + src/Appwrite/Utopia/Response/Model/ColumnBigInt.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php b/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php index 217589c578..baa93ff103 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeBigInt.php @@ -41,6 +41,7 @@ class AttributeBigInt extends Attribute ]) ->addRule('default', [ 'type' => self::TYPE_INTEGER, + 'format' => 'int64', '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/ColumnBigInt.php b/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php index e001b6aedf..895356dbf2 100644 --- a/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php +++ b/src/Appwrite/Utopia/Response/Model/ColumnBigInt.php @@ -41,6 +41,7 @@ class ColumnBigInt extends Column ]) ->addRule('default', [ 'type' => self::TYPE_INTEGER, + 'format' => 'int64', 'description' => 'Default value for column when not provided. Cannot be set when column is required.', 'default' => null, 'required' => false, From 7ccf2b1a1e5f70915dd4083ebe0105e5c5475127 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 5 May 2026 19:28:28 +0530 Subject: [PATCH 136/211] updated --- .../Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php | 2 +- .../Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php index 1b7b33291b..1d32c6bad9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php @@ -34,7 +34,7 @@ class Create extends BigIntCreate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/bigint') ->desc('Create bigint column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].create') ->label('audits.event', 'column.create') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php index 387dd08238..b2754a2b7d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Update.php @@ -35,7 +35,7 @@ class Update extends BigIntUpdate ->setHttpPath('/v1/tablesdb/:databaseId/tables/:tableId/columns/bigint/:key') ->desc('Update bigint column') ->groups(['api', 'database', 'schema']) - ->label('scope', ['tables.write', 'collections.write']) + ->label('scope', ['tables.write', 'collections.write', 'columns.write', 'attributes.write']) ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].columns.[columnId].update') ->label('audits.event', 'column.update') From fd1a4542e78ff688e5ad358e827221e397b80ece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 5 May 2026 16:09:17 +0200 Subject: [PATCH 137/211] Fix variables API feature parity --- .../Functions/Http/Variables/Create.php | 11 +++- .../Functions/Http/Variables/Delete.php | 6 ++ .../Functions/Http/Variables/Update.php | 40 +++++++---- .../Functions/Http/Variables/XList.php | 66 +++++++++++++++++-- .../Modules/Sites/Http/Variables/Create.php | 11 +++- .../Modules/Sites/Http/Variables/Delete.php | 7 +- .../Modules/Sites/Http/Variables/Update.php | 40 +++++++---- .../Modules/Sites/Http/Variables/XList.php | 59 ++++++++++++++++- 8 files changed, 204 insertions(+), 36 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php index fee5b0095d..a33d25b630 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php @@ -2,11 +2,13 @@ namespace Appwrite\Platform\Modules\Functions\Http\Variables; +use Appwrite\Event\Event as QueueEvent; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\CustomId; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\DateTime; @@ -38,6 +40,7 @@ class Create extends Base ->groups(['api', 'functions']) ->label('scope', 'functions.write') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) + ->label('event', 'variables.[variableId].create') ->label('audits.event', 'variable.create') ->label('audits.resource', 'function/{request.functionId}') ->label('sdk', new Method( @@ -56,10 +59,12 @@ class Create extends Base ] )) ->param('functionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Function unique ID.', false, ['dbForProject']) + ->param('variableId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Variable ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', true, ['dbForProject']) ->param('key', null, new Text(Database::LENGTH_KEY), 'Variable key. Max length: ' . Database::LENGTH_KEY . ' chars.', false) ->param('value', null, new Text(8192, 0), 'Variable value. Max length: 8192 chars.', false) ->param('secret', true, new Boolean(), 'Secret variables can be updated or deleted, but only functions can read them during build and runtime.', true) ->inject('response') + ->inject('queueForEvents') ->inject('dbForProject') ->inject('dbForPlatform') ->inject('project') @@ -69,10 +74,12 @@ class Create extends Base public function action( string $functionId, + string $variableId, string $key, string $value, bool $secret, Response $response, + QueueEvent $queueForEvents, Database $dbForProject, Database $dbForPlatform, Document $project, @@ -84,7 +91,7 @@ class Create extends Base throw new Exception(Exception::FUNCTION_NOT_FOUND); } - $variableId = ID::unique(); + $variableId = ($variableId === '' || $variableId === 'unique()') ? ID::unique() : $variableId; $teamId = $project->getAttribute('teamId', ''); $variable = new Document([ @@ -120,6 +127,8 @@ class Create extends Base 'active' => $schedule->getAttribute('active'), ]))); + $queueForEvents->setParam('variableId', $variable->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($variable, Response::MODEL_VARIABLE); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Delete.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Delete.php index f6d77c2a0d..fa9f19ba8f 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Delete.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Delete.php @@ -2,6 +2,7 @@ namespace Appwrite\Platform\Modules\Functions\Http\Variables; +use Appwrite\Event\Event as QueueEvent; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; use Appwrite\SDK\AuthType; @@ -35,6 +36,7 @@ class Delete extends Base ->groups(['api', 'functions']) ->label('scope', 'functions.write') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) + ->label('event', 'variables.[variableId].delete') ->label('audits.event', 'variable.delete') ->label('audits.resource', 'function/{request.functionId}') ->label('sdk', new Method( @@ -56,6 +58,7 @@ class Delete extends Base ->param('functionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Function unique ID.', false, ['dbForProject']) ->param('variableId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Variable unique ID.', false, ['dbForProject']) ->inject('response') + ->inject('queueForEvents') ->inject('dbForProject') ->inject('dbForPlatform') ->inject('authorization') @@ -66,6 +69,7 @@ class Delete extends Base string $functionId, string $variableId, Response $response, + QueueEvent $queueForEvents, Database $dbForProject, Database $dbForPlatform, Authorization $authorization @@ -98,6 +102,8 @@ class Delete extends Base 'active' => $schedule->getAttribute('active'), ]))); + $queueForEvents->setParam('variableId', $variable->getId()); + $response->noContent(); } } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Update.php index 54d7a647a3..6413b29f82 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Update.php @@ -2,6 +2,7 @@ namespace Appwrite\Platform\Modules\Functions\Http\Variables; +use Appwrite\Event\Event as QueueEvent; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; use Appwrite\SDK\AuthType; @@ -38,6 +39,7 @@ class Update extends Base ->groups(['api', 'functions']) ->label('scope', 'functions.write') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) + ->label('event', 'variables.[variableId].update') ->label('audits.event', 'variable.update') ->label('audits.resource', 'function/{request.functionId}') ->label('sdk', new Method( @@ -57,10 +59,11 @@ class Update extends Base )) ->param('functionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Function unique ID.', false, ['dbForProject']) ->param('variableId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Variable unique ID.', false, ['dbForProject']) - ->param('key', null, new Text(255), 'Variable key. Max length: 255 chars.', false) + ->param('key', null, new Nullable(new Text(255, 0)), 'Variable key. Max length: 255 chars.', true) ->param('value', null, new Nullable(new Text(8192, 0)), 'Variable value. Max length: 8192 chars.', true) ->param('secret', null, new Nullable(new Boolean()), 'Secret variables can be updated or deleted, but only functions can read them during build and runtime.', true) ->inject('response') + ->inject('queueForEvents') ->inject('dbForProject') ->inject('dbForPlatform') ->inject('authorization') @@ -70,10 +73,11 @@ class Update extends Base public function action( string $functionId, string $variableId, - string $key, + ?string $key, ?string $value, ?bool $secret, Response $response, + QueueEvent $queueForEvents, Database $dbForProject, Database $dbForPlatform, Authorization $authorization @@ -93,19 +97,27 @@ class Update extends Base throw new Exception(Exception::VARIABLE_CANNOT_UNSET_SECRET); } - $variable - ->setAttribute('key', $key) - ->setAttribute('value', $value ?? $variable->getAttribute('value')) - ->setAttribute('secret', $secret ?? $variable->getAttribute('secret')) - ->setAttribute('search', implode(' ', [$variableId, $function->getId(), $key, 'function'])); + if (\is_null($key) && \is_null($value) && \is_null($secret)) { + throw new Exception(Exception::GENERAL_ARGUMENT_INVALID); + } + + $updates = new Document(); + + if (!\is_null($key)) { + $updates->setAttribute('key', $key); + $updates->setAttribute('search', implode(' ', [$variableId, $function->getId(), $key, 'function'])); + } + + if (!\is_null($value)) { + $updates->setAttribute('value', $value); + } + + if (!\is_null($secret)) { + $updates->setAttribute('secret', $secret); + } try { - $dbForProject->updateDocument('variables', $variable->getId(), new Document([ - 'key' => $key, - 'value' => $value ?? $variable->getAttribute('value'), - 'secret' => $secret ?? $variable->getAttribute('secret'), - 'search' => implode(' ', [$variableId, $function->getId(), $key, 'function']), - ])); + $variable = $dbForProject->updateDocument('variables', $variable->getId(), $updates); } catch (DuplicateException $th) { throw new Exception(Exception::VARIABLE_ALREADY_EXISTS); } @@ -125,6 +137,8 @@ class Update extends Base 'active' => $schedule->getAttribute('active'), ]))); + $queueForEvents->setParam('variableId', $variable->getId()); + $response->dynamic($variable, Response::MODEL_VARIABLE); } } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/XList.php index 55dea3be1e..b330812b96 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/XList.php @@ -7,12 +7,18 @@ use Appwrite\Platform\Modules\Compute\Base; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Queries\Variables; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Exception\Order as OrderException; +use Utopia\Database\Exception\Query as QueryException; +use Utopia\Database\Query; +use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; +use Utopia\Validator\Boolean; class XList extends Base { @@ -51,22 +57,74 @@ class XList extends Base ) ) ->param('functionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Function unique ID.', false, ['dbForProject']) + ->param('queries', [], new Variables(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Variables::ALLOWED_ATTRIBUTES), true) + ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') ->callback($this->action(...)); } - public function action(string $functionId, Response $response, Database $dbForProject) - { + /** + * @param array $queries + */ + public function action( + string $functionId, + array $queries, + bool $includeTotal, + Response $response, + Database $dbForProject + ) { $function = $dbForProject->getDocument('functions', $functionId); if ($function->isEmpty()) { throw new Exception(Exception::FUNCTION_NOT_FOUND); } + try { + $queries = Query::parseQueries($queries); + } catch (QueryException $e) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); + } + + $queries[] = Query::equal('resourceType', ['function']); + $queries[] = Query::equal('resourceInternalId', [$function->getSequence()]); + $queries[] = Query::orderAsc(); + + $cursor = Query::getCursorQueries($queries, false); + $cursor = \reset($cursor); + + if ($cursor !== false) { + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + + $variableId = $cursor->getValue(); + $cursorDocument = $dbForProject->findOne('variables', [ + Query::equal('$id', [$variableId]), + Query::equal('resourceType', ['function']), + Query::equal('resourceInternalId', [$function->getSequence()]), + ]); + + if ($cursorDocument->isEmpty()) { + throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Variable '{$variableId}' for the 'cursor' value not found."); + } + + $cursor->setValue($cursorDocument); + } + + $filterQueries = Query::groupByType($queries)['filters']; + + try { + $variables = $dbForProject->find('variables', $queries); + $total = $includeTotal ? $dbForProject->count('variables', $filterQueries, APP_LIMIT_COUNT) : 0; + } catch (OrderException $e) { + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); + } + $response->dynamic(new Document([ - 'variables' => $function->getAttribute('vars', []), - 'total' => \count($function->getAttribute('vars', [])), + 'variables' => $variables, + 'total' => $total, ]), Response::MODEL_VARIABLE_LIST); } } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php index 04b30fbc9c..92253d4350 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php @@ -2,11 +2,13 @@ namespace Appwrite\Platform\Modules\Sites\Http\Variables; +use Appwrite\Event\Event as QueueEvent; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\CustomId; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; @@ -36,6 +38,7 @@ class Create extends Base ->groups(['api', 'sites']) ->label('scope', 'sites.write') ->label('resourceType', RESOURCE_TYPE_SITES) + ->label('event', 'variables.[variableId].create') ->label('audits.event', 'variable.create') ->label('audits.resource', 'site/{request.siteId}') ->label('sdk', new Method( @@ -54,16 +57,18 @@ class Create extends Base ] )) ->param('siteId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Site unique ID.', false, ['dbForProject']) + ->param('variableId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Variable ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', true, ['dbForProject']) ->param('key', null, new Text(Database::LENGTH_KEY), 'Variable key. Max length: ' . Database::LENGTH_KEY . ' chars.', false) ->param('value', null, new Text(8192, 0), 'Variable value. Max length: 8192 chars.', false) ->param('secret', true, new Boolean(), 'Secret variables can be updated or deleted, but only sites can read them during build and runtime.', true) ->inject('response') + ->inject('queueForEvents') ->inject('dbForProject') ->inject('project') ->callback($this->action(...)); } - public function action(string $siteId, string $key, string $value, bool $secret, Response $response, Database $dbForProject, Document $project) + public function action(string $siteId, string $variableId, string $key, string $value, bool $secret, Response $response, QueueEvent $queueForEvents, Database $dbForProject, Document $project) { $site = $dbForProject->getDocument('sites', $siteId); @@ -71,7 +76,7 @@ class Create extends Base throw new Exception(Exception::SITE_NOT_FOUND); } - $variableId = ID::unique(); + $variableId = ($variableId === '' || $variableId === 'unique()') ? ID::unique() : $variableId; $teamId = $project->getAttribute('teamId', ''); $variable = new Document([ @@ -96,6 +101,8 @@ class Create extends Base 'live' => false, ])); + $queueForEvents->setParam('variableId', $variable->getId()); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($variable, Response::MODEL_VARIABLE); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Delete.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Delete.php index d61c9892cf..74c638bddc 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Delete.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Delete.php @@ -2,6 +2,7 @@ namespace Appwrite\Platform\Modules\Sites\Http\Variables; +use Appwrite\Event\Event as QueueEvent; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; use Appwrite\SDK\AuthType; @@ -33,6 +34,7 @@ class Delete extends Base ->groups(['api', 'sites']) ->label('scope', 'sites.write') ->label('resourceType', RESOURCE_TYPE_SITES) + ->label('event', 'variables.[variableId].delete') ->label('audits.event', 'variable.delete') ->label('audits.resource', 'site/{request.siteId}') ->label('sdk', new Method( @@ -54,11 +56,12 @@ class Delete extends Base ->param('siteId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Site unique ID.', false, ['dbForProject']) ->param('variableId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Variable unique ID.', false, ['dbForProject']) ->inject('response') + ->inject('queueForEvents') ->inject('dbForProject') ->callback($this->action(...)); } - public function action(string $siteId, string $variableId, Response $response, Database $dbForProject) + public function action(string $siteId, string $variableId, Response $response, QueueEvent $queueForEvents, Database $dbForProject) { $site = $dbForProject->getDocument('sites', $siteId); @@ -77,6 +80,8 @@ class Delete extends Base 'live' => false, ])); + $queueForEvents->setParam('variableId', $variable->getId()); + $response->noContent(); } } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Update.php index 08cdd4ac38..0ed7414b9d 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Update.php @@ -2,6 +2,7 @@ namespace Appwrite\Platform\Modules\Sites\Http\Variables; +use Appwrite\Event\Event as QueueEvent; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; use Appwrite\SDK\AuthType; @@ -35,6 +36,7 @@ class Update extends Base ->desc('Update variable') ->groups(['api', 'sites']) ->label('scope', 'sites.write') + ->label('event', 'variables.[variableId].update') ->label('audits.event', 'variable.update') ->label('audits.resource', 'site/{request.siteId}') ->label('resourceType', RESOURCE_TYPE_SITES) @@ -55,10 +57,11 @@ class Update extends Base )) ->param('siteId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Site unique ID.', false, ['dbForProject']) ->param('variableId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Variable unique ID.', false, ['dbForProject']) - ->param('key', null, new Text(255), 'Variable key. Max length: 255 chars.', false) + ->param('key', null, new Nullable(new Text(255, 0)), 'Variable key. Max length: 255 chars.', true) ->param('value', null, new Nullable(new Text(8192, 0)), 'Variable value. Max length: 8192 chars.', true) ->param('secret', null, new Nullable(new Boolean()), 'Secret variables can be updated or deleted, but only sites can read them during build and runtime.', true) ->inject('response') + ->inject('queueForEvents') ->inject('dbForProject') ->callback($this->action(...)); } @@ -66,10 +69,11 @@ class Update extends Base public function action( string $siteId, string $variableId, - string $key, + ?string $key, ?string $value, ?bool $secret, Response $response, + QueueEvent $queueForEvents, Database $dbForProject ) { $site = $dbForProject->getDocument('sites', $siteId); @@ -87,19 +91,27 @@ class Update extends Base throw new Exception(Exception::VARIABLE_CANNOT_UNSET_SECRET); } - $variable - ->setAttribute('key', $key) - ->setAttribute('value', $value ?? $variable->getAttribute('value')) - ->setAttribute('secret', $secret ?? $variable->getAttribute('secret')) - ->setAttribute('search', implode(' ', [$variableId, $site->getId(), $key, 'site'])); + if (\is_null($key) && \is_null($value) && \is_null($secret)) { + throw new Exception(Exception::GENERAL_ARGUMENT_INVALID); + } + + $updates = new Document(); + + if (!\is_null($key)) { + $updates->setAttribute('key', $key); + $updates->setAttribute('search', implode(' ', [$variableId, $site->getId(), $key, 'site'])); + } + + if (!\is_null($value)) { + $updates->setAttribute('value', $value); + } + + if (!\is_null($secret)) { + $updates->setAttribute('secret', $secret); + } try { - $dbForProject->updateDocument('variables', $variable->getId(), new Document([ - 'key' => $variable->getAttribute('key'), - 'value' => $variable->getAttribute('value'), - 'secret' => $variable->getAttribute('secret'), - 'search' => $variable->getAttribute('search'), - ])); + $variable = $dbForProject->updateDocument('variables', $variable->getId(), $updates); } catch (DuplicateException $th) { throw new Exception(Exception::VARIABLE_ALREADY_EXISTS); } @@ -108,6 +120,8 @@ class Update extends Base 'live' => false, ])); + $queueForEvents->setParam('variableId', $variable->getId()); + $response->dynamic($variable, Response::MODEL_VARIABLE); } } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/XList.php index 669aa8be98..1270fe4925 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/XList.php @@ -7,12 +7,18 @@ use Appwrite\Platform\Modules\Compute\Base; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Queries\Variables; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Exception\Order as OrderException; +use Utopia\Database\Exception\Query as QueryException; +use Utopia\Database\Query; +use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; +use Utopia\Validator\Boolean; class XList extends Base { @@ -51,13 +57,20 @@ class XList extends Base ) ) ->param('siteId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Site unique ID.', false, ['dbForProject']) + ->param('queries', [], new Variables(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Variables::ALLOWED_ATTRIBUTES), true) + ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') ->callback($this->action(...)); } + /** + * @param array $queries + */ public function action( string $siteId, + array $queries, + bool $includeTotal, Response $response, Database $dbForProject ) { @@ -67,9 +80,51 @@ class XList extends Base throw new Exception(Exception::SITE_NOT_FOUND); } + try { + $queries = Query::parseQueries($queries); + } catch (QueryException $e) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); + } + + $queries[] = Query::equal('resourceType', ['site']); + $queries[] = Query::equal('resourceInternalId', [$site->getSequence()]); + $queries[] = Query::orderAsc(); + + $cursor = Query::getCursorQueries($queries, false); + $cursor = \reset($cursor); + + if ($cursor !== false) { + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + + $variableId = $cursor->getValue(); + $cursorDocument = $dbForProject->findOne('variables', [ + Query::equal('$id', [$variableId]), + Query::equal('resourceType', ['site']), + Query::equal('resourceInternalId', [$site->getSequence()]), + ]); + + if ($cursorDocument->isEmpty()) { + throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Variable '{$variableId}' for the 'cursor' value not found."); + } + + $cursor->setValue($cursorDocument); + } + + $filterQueries = Query::groupByType($queries)['filters']; + + try { + $variables = $dbForProject->find('variables', $queries); + $total = $includeTotal ? $dbForProject->count('variables', $filterQueries, APP_LIMIT_COUNT) : 0; + } catch (OrderException $e) { + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); + } + $response->dynamic(new Document([ - 'variables' => $site->getAttribute('vars', []), - 'total' => \count($site->getAttribute('vars', [])), + 'variables' => $variables, + 'total' => $total, ]), Response::MODEL_VARIABLE_LIST); } } From 93515fcc1d69f8e8e89c835dfa8aee9c8d98bfc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 5 May 2026 16:17:47 +0200 Subject: [PATCH 138/211] Finalize variables rework --- .../Platform/Modules/Functions/Http/Variables/Create.php | 4 ++-- .../Modules/Project/Http/Project/Variables/Create.php | 3 ++- .../Modules/Project/Http/Project/Variables/Delete.php | 3 ++- .../Platform/Modules/Project/Http/Project/Variables/Get.php | 3 ++- .../Modules/Project/Http/Project/Variables/Update.php | 3 ++- .../Platform/Modules/Project/Http/Project/Variables/XList.php | 1 + src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php | 4 ++-- 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php index a33d25b630..e619e28928 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php @@ -59,7 +59,7 @@ class Create extends Base ] )) ->param('functionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Function unique ID.', false, ['dbForProject']) - ->param('variableId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Variable ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', true, ['dbForProject']) + ->param('variableId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Variable ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('key', null, new Text(Database::LENGTH_KEY), 'Variable key. Max length: ' . Database::LENGTH_KEY . ' chars.', false) ->param('value', null, new Text(8192, 0), 'Variable value. Max length: 8192 chars.', false) ->param('secret', true, new Boolean(), 'Secret variables can be updated or deleted, but only functions can read them during build and runtime.', true) @@ -91,7 +91,7 @@ class Create extends Base throw new Exception(Exception::FUNCTION_NOT_FOUND); } - $variableId = ($variableId === '' || $variableId === 'unique()') ? ID::unique() : $variableId; + $variableId = ($variableId == 'unique()') ? ID::unique() : $variableId; $teamId = $project->getAttribute('teamId', ''); $variable = new Document([ diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php index 8dbc720045..c9af0b25e0 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php @@ -35,6 +35,7 @@ class Create extends Action ->desc('Create project variable') ->groups(['api', 'project']) ->label('scope', 'project.write') + ->label('resourceType', RESOURCE_TYPE_PROJECTS) ->label('event', 'variables.[variableId].create') ->label('audits.event', 'project.variable.create') ->label('audits.resource', 'project.variable/{response.$id}') @@ -53,7 +54,7 @@ class Create extends Action ) ], )) - ->param('variableId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Variable ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) + ->param('variableId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Variable unique ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('key', null, new Text(Database::LENGTH_KEY), 'Variable key. Max length: ' . Database::LENGTH_KEY . ' chars.') ->param('value', null, new Text(8192, 0), 'Variable value. Max length: 8192 chars.') ->param('secret', true, new Boolean(), 'Secret variables can be updated or deleted, but only projects can read them during build and runtime.', true) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php index 2b0ae8feb1..5e268b0e36 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php @@ -32,6 +32,7 @@ class Delete extends Action ->desc('Delete project variable') ->groups(['api', 'project']) ->label('scope', 'project.write') + ->label('resourceType', RESOURCE_TYPE_PROJECTS) ->label('event', 'variables.[variableId].delete') ->label('audits.event', 'project.variable.delete') ->label('audits.resource', 'project.variable/{request.variableId}') @@ -51,7 +52,7 @@ class Delete extends Action ], contentType: ContentType::NONE )) - ->param('variableId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Variable ID.', false, ['dbForProject']) + ->param('variableId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Variable unique ID.', false, ['dbForProject']) ->inject('response') ->inject('dbForProject') ->inject('queueForEvents') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Get.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Get.php index af14148c92..7cbd4456a7 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Get.php @@ -29,6 +29,7 @@ class Get extends Action ->desc('Get project variable') ->groups(['api', 'project']) ->label('scope', 'project.read') + ->label('resourceType', RESOURCE_TYPE_PROJECTS) ->label('sdk', new Method( namespace: 'project', group: 'variables', @@ -44,7 +45,7 @@ class Get extends Action ) ] )) - ->param('variableId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Variable ID.', false, ['dbForProject']) + ->param('variableId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Variable unique ID.', false, ['dbForProject']) ->inject('response') ->inject('dbForProject') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php index 988a7c0849..66cfb60740 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php @@ -34,6 +34,7 @@ class Update extends Action ->desc('Update project variable') ->groups(['api', 'project']) ->label('scope', 'project.write') + ->label('resourceType', RESOURCE_TYPE_PROJECTS) ->label('event', 'variables.[variableId].update') ->label('audits.event', 'project.variable.update') ->label('audits.resource', 'project.variable/{response.$id}') @@ -52,7 +53,7 @@ class Update extends Action ) ] )) - ->param('variableId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Variable ID.', false, ['dbForProject']) + ->param('variableId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Variable unique ID.', false, ['dbForProject']) ->param('key', null, new Nullable(new Text(255, 0)), 'Variable key. Max length: 255 chars.', true) ->param('value', null, new Nullable(new Text(8192, 0)), 'Variable value. Max length: 8192 chars.', true) ->param('secret', null, new Nullable(new Boolean()), 'Secret variables can be updated or deleted, but only projects can read them during build and runtime.', true) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/XList.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/XList.php index bd391ea3b4..582fed93c9 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/XList.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/XList.php @@ -35,6 +35,7 @@ class XList extends Action ->desc('List project variables') ->groups(['api', 'project']) ->label('scope', 'project.read') + ->label('resourceType', RESOURCE_TYPE_PROJECTS) ->label('sdk', new Method( namespace: 'project', group: 'variables', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php index 92253d4350..da58f84f0b 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php @@ -57,7 +57,7 @@ class Create extends Base ] )) ->param('siteId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Site unique ID.', false, ['dbForProject']) - ->param('variableId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Variable ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', true, ['dbForProject']) + ->param('variableId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Variable ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('key', null, new Text(Database::LENGTH_KEY), 'Variable key. Max length: ' . Database::LENGTH_KEY . ' chars.', false) ->param('value', null, new Text(8192, 0), 'Variable value. Max length: 8192 chars.', false) ->param('secret', true, new Boolean(), 'Secret variables can be updated or deleted, but only sites can read them during build and runtime.', true) @@ -76,7 +76,7 @@ class Create extends Base throw new Exception(Exception::SITE_NOT_FOUND); } - $variableId = ($variableId === '' || $variableId === 'unique()') ? ID::unique() : $variableId; + $variableId = ($variableId == 'unique()') ? ID::unique() : $variableId; $teamId = $project->getAttribute('teamId', ''); $variable = new Document([ From 305e8e1ec719a516f3cb710988c33dd482887e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 5 May 2026 16:24:41 +0200 Subject: [PATCH 139/211] Add request filter --- app/controllers/general.php | 8 ++++++ app/init/constants.php | 2 +- src/Appwrite/Migration/Migration.php | 1 + src/Appwrite/Utopia/Request/Filters/V25.php | 27 ++++++++++++++++++++ src/Appwrite/Utopia/Response/Filters/V25.php | 17 ++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/Appwrite/Utopia/Request/Filters/V25.php create mode 100644 src/Appwrite/Utopia/Response/Filters/V25.php diff --git a/app/controllers/general.php b/app/controllers/general.php index eb4899a3d8..11cae2af88 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -28,6 +28,7 @@ use Appwrite\Utopia\Request\Filters\V21 as RequestV21; use Appwrite\Utopia\Request\Filters\V22 as RequestV22; use Appwrite\Utopia\Request\Filters\V23 as RequestV23; use Appwrite\Utopia\Request\Filters\V24 as RequestV24; +use Appwrite\Utopia\Request\Filters\V25 as RequestV25; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Filters\V16 as ResponseV16; use Appwrite\Utopia\Response\Filters\V17 as ResponseV17; @@ -38,6 +39,7 @@ use Appwrite\Utopia\Response\Filters\V21 as ResponseV21; use Appwrite\Utopia\Response\Filters\V22 as ResponseV22; use Appwrite\Utopia\Response\Filters\V23 as ResponseV23; use Appwrite\Utopia\Response\Filters\V24 as ResponseV24; +use Appwrite\Utopia\Response\Filters\V25 as ResponseV25; use Appwrite\Utopia\View; use Executor\Executor; use MaxMind\Db\Reader; @@ -904,6 +906,9 @@ Http::init() if (version_compare($requestFormat, '1.9.3', '<')) { $request->addFilter(new RequestV24()); } + if (version_compare($requestFormat, '1.9.4', '<')) { + $request->addFilter(new RequestV25()); + } } $localeParam = (string) $request->getParam('locale', $request->getHeader('x-appwrite-locale', '')); @@ -931,6 +936,9 @@ Http::init() if (version_compare($responseFormat, '1.9.3', '<')) { $response->addFilter(new ResponseV24()); } + if (version_compare($responseFormat, '1.9.4', '<')) { + $response->addFilter(new ResponseV25()); + } if (version_compare($responseFormat, '1.9.2', '<')) { $response->addFilter(new ResponseV23()); } diff --git a/app/init/constants.php b/app/init/constants.php index f27d0c7c70..64635bab2a 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -45,7 +45,7 @@ const APP_RESOURCE_TOKEN_ACCESS = 24 * 60 * 60; // 24 hours const APP_FILE_ACCESS = 24 * 60 * 60; // 24 hours const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours const APP_CACHE_BUSTER = 4324; -const APP_VERSION_STABLE = '1.9.3'; +const APP_VERSION_STABLE = '1.9.4'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; const APP_DATABASE_ATTRIBUTE_ENUM = 'enum'; const APP_DATABASE_ATTRIBUTE_IP = 'ip'; diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 359925e368..004e09cd23 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -96,6 +96,7 @@ abstract class Migration '1.9.1' => 'V24', '1.9.2' => 'V24', '1.9.3' => 'V24', + '1.9.4' => 'V25', ]; /** diff --git a/src/Appwrite/Utopia/Request/Filters/V25.php b/src/Appwrite/Utopia/Request/Filters/V25.php new file mode 100644 index 0000000000..cba70a5f7b --- /dev/null +++ b/src/Appwrite/Utopia/Request/Filters/V25.php @@ -0,0 +1,27 @@ +fillVariableId($content); + break; + } + + return $content; + } + + protected function fillVariableId(array $content): array + { + $content['variableId'] = $content['variableId'] ?? 'unique()'; + return $content; + } +} diff --git a/src/Appwrite/Utopia/Response/Filters/V25.php b/src/Appwrite/Utopia/Response/Filters/V25.php new file mode 100644 index 0000000000..03d19d2cc1 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Filters/V25.php @@ -0,0 +1,17 @@ + $content, + }; + } +} From 9b120e9db7a62373988ee3ce31446d50c8f02c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 5 May 2026 16:29:09 +0200 Subject: [PATCH 140/211] Remove unwanted changes --- .../Platform/Modules/Project/Http/Project/Variables/Create.php | 1 - .../Platform/Modules/Project/Http/Project/Variables/Delete.php | 1 - .../Platform/Modules/Project/Http/Project/Variables/Get.php | 1 - .../Platform/Modules/Project/Http/Project/Variables/Update.php | 1 - .../Platform/Modules/Project/Http/Project/Variables/XList.php | 1 - 5 files changed, 5 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php index c9af0b25e0..f4e27def72 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php @@ -35,7 +35,6 @@ class Create extends Action ->desc('Create project variable') ->groups(['api', 'project']) ->label('scope', 'project.write') - ->label('resourceType', RESOURCE_TYPE_PROJECTS) ->label('event', 'variables.[variableId].create') ->label('audits.event', 'project.variable.create') ->label('audits.resource', 'project.variable/{response.$id}') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php index 5e268b0e36..553fb09e54 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Delete.php @@ -32,7 +32,6 @@ class Delete extends Action ->desc('Delete project variable') ->groups(['api', 'project']) ->label('scope', 'project.write') - ->label('resourceType', RESOURCE_TYPE_PROJECTS) ->label('event', 'variables.[variableId].delete') ->label('audits.event', 'project.variable.delete') ->label('audits.resource', 'project.variable/{request.variableId}') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Get.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Get.php index 7cbd4456a7..d9030421d7 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Get.php @@ -29,7 +29,6 @@ class Get extends Action ->desc('Get project variable') ->groups(['api', 'project']) ->label('scope', 'project.read') - ->label('resourceType', RESOURCE_TYPE_PROJECTS) ->label('sdk', new Method( namespace: 'project', group: 'variables', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php index 66cfb60740..6b05e19a78 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Update.php @@ -34,7 +34,6 @@ class Update extends Action ->desc('Update project variable') ->groups(['api', 'project']) ->label('scope', 'project.write') - ->label('resourceType', RESOURCE_TYPE_PROJECTS) ->label('event', 'variables.[variableId].update') ->label('audits.event', 'project.variable.update') ->label('audits.resource', 'project.variable/{response.$id}') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/XList.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/XList.php index 582fed93c9..bd391ea3b4 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/XList.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/XList.php @@ -35,7 +35,6 @@ class XList extends Action ->desc('List project variables') ->groups(['api', 'project']) ->label('scope', 'project.read') - ->label('resourceType', RESOURCE_TYPE_PROJECTS) ->label('sdk', new Method( namespace: 'project', group: 'variables', From 48fbb591133d123b7647368a0f807f5f5eb2530c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 5 May 2026 16:44:47 +0200 Subject: [PATCH 141/211] pr review fixes --- app/controllers/general.php | 6 +++--- .../Platform/Modules/Functions/Http/Variables/Create.php | 2 +- .../Modules/Project/Http/Project/Variables/Create.php | 2 +- .../Platform/Modules/Sites/Http/Variables/Create.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 11cae2af88..21bcded22c 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -933,12 +933,12 @@ Http::init() */ $responseFormat = $request->getHeader('x-appwrite-response-format', System::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '')); if ($responseFormat) { - if (version_compare($responseFormat, '1.9.3', '<')) { - $response->addFilter(new ResponseV24()); - } if (version_compare($responseFormat, '1.9.4', '<')) { $response->addFilter(new ResponseV25()); } + if (version_compare($responseFormat, '1.9.3', '<')) { + $response->addFilter(new ResponseV24()); + } if (version_compare($responseFormat, '1.9.2', '<')) { $response->addFilter(new ResponseV23()); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php index e619e28928..de572cd41e 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php @@ -91,7 +91,7 @@ class Create extends Base throw new Exception(Exception::FUNCTION_NOT_FOUND); } - $variableId = ($variableId == 'unique()') ? ID::unique() : $variableId; + $variableId = ($variableId === 'unique()') ? ID::unique() : $variableId; $teamId = $project->getAttribute('teamId', ''); $variable = new Document([ diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php index f4e27def72..8c76ed2a8e 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php @@ -72,7 +72,7 @@ class Create extends Action QueueEvent $queueForEvents, Database $dbForProject, ) { - $variableId = ($variableId == 'unique()') ? ID::unique() : $variableId; + $variableId = ($variableId === 'unique()') ? ID::unique() : $variableId; $variable = new Document([ '$id' => $variableId, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php index da58f84f0b..edd3412b8f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php @@ -76,7 +76,7 @@ class Create extends Base throw new Exception(Exception::SITE_NOT_FOUND); } - $variableId = ($variableId == 'unique()') ? ID::unique() : $variableId; + $variableId = ($variableId === 'unique()') ? ID::unique() : $variableId; $teamId = $project->getAttribute('teamId', ''); $variable = new Document([ From 15f21daa2bc7ba42db852478ff98491117d304b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 5 May 2026 16:45:09 +0200 Subject: [PATCH 142/211] Add tests --- .../Functions/FunctionsConsoleClientTest.php | 303 ++++++++++++++++- .../Services/Sites/SitesCustomServerTest.php | 317 ++++++++++++++++++ 2 files changed, 619 insertions(+), 1 deletion(-) diff --git a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php index 06044d9984..eaf3f089e1 100644 --- a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php @@ -7,8 +7,10 @@ use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideConsole; use Utopia\Console; +use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Role; +use Utopia\Database\Query; class FunctionsConsoleClientTest extends Scope { @@ -70,6 +72,7 @@ class FunctionsConsoleClientTest extends Scope $variable = $this->createVariable( $functionId, [ + 'variableId' => ID::unique(), 'key' => 'APP_TEST', 'value' => 'TESTINGVALUE', 'secret' => false @@ -82,6 +85,7 @@ class FunctionsConsoleClientTest extends Scope $secretVariable = $this->createVariable( $functionId, [ + 'variableId' => ID::unique(), 'key' => 'APP_TEST_1', 'value' => 'TESTINGVALUE_1', 'secret' => true @@ -196,6 +200,7 @@ class FunctionsConsoleClientTest extends Scope $variable = $this->createVariable( $functionId, [ + 'variableId' => ID::unique(), 'key' => 'APP_TEST', 'value' => 'TESTINGVALUE', 'secret' => false @@ -208,6 +213,7 @@ class FunctionsConsoleClientTest extends Scope $variable = $this->createVariable( $functionId, [ + 'variableId' => ID::unique(), 'key' => 'APP_TEST_1', 'value' => 'TESTINGVALUE_1', 'secret' => true @@ -226,6 +232,7 @@ class FunctionsConsoleClientTest extends Scope $variable = $this->createVariable( $functionId, [ + 'variableId' => ID::unique(), 'key' => 'APP_TEST', 'value' => 'ANOTHERTESTINGVALUE', 'secret' => false @@ -234,10 +241,47 @@ class FunctionsConsoleClientTest extends Scope $this->assertEquals(409, $variable['headers']['status-code']); + // Test for invalid variableId + $variable = $this->createVariable( + $functionId, + [ + 'variableId' => '!invalid-id!', + 'key' => 'INVALID_ID_KEY', + 'value' => 'value', + ] + ); + + $this->assertEquals(400, $variable['headers']['status-code']); + + // Test for duplicate variableId + $duplicateVariableId = ID::unique(); + $variable = $this->createVariable( + $functionId, + [ + 'variableId' => $duplicateVariableId, + 'key' => 'DUP_ID_KEY_1', + 'value' => 'value1', + ] + ); + + $this->assertEquals(201, $variable['headers']['status-code']); + + $duplicate = $this->createVariable( + $functionId, + [ + 'variableId' => $duplicateVariableId, + 'key' => 'DUP_ID_KEY_2', + 'value' => 'value2', + ] + ); + + $this->assertEquals(409, $duplicate['headers']['status-code']); + // Test for invalid key $variable = $this->createVariable( $functionId, [ + 'variableId' => ID::unique(), 'key' => str_repeat("A", 256), 'value' => 'TESTINGVALUE' ] @@ -249,6 +293,7 @@ class FunctionsConsoleClientTest extends Scope $variable = $this->createVariable( $functionId, [ + 'variableId' => ID::unique(), 'key' => 'LONGKEY', 'value' => str_repeat("#", 8193), ] @@ -283,6 +328,150 @@ class FunctionsConsoleClientTest extends Scope */ } + public function testListVariablesWithLimit(): void + { + // Create a fresh function for this test + $function = $this->createFunction([ + 'functionId' => ID::unique(), + 'name' => 'Test List Variables With Limit', + 'execute' => [Role::user($this->getUser()['$id'])->toString()], + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', + 'timeout' => 10, + ]); + $this->assertEquals(201, $function['headers']['status-code']); + $functionId = $function['body']['$id']; + + $variable1 = $this->createVariable($functionId, [ + 'variableId' => ID::unique(), + 'key' => 'LIMIT_KEY_1', + 'value' => 'limit-value-1', + ]); + $this->assertEquals(201, $variable1['headers']['status-code']); + + $variable2 = $this->createVariable($functionId, [ + 'variableId' => ID::unique(), + 'key' => 'LIMIT_KEY_2', + 'value' => 'limit-value-2', + ]); + $this->assertEquals(201, $variable2['headers']['status-code']); + + // List with limit of 1 + $response = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/variables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + Query::limit(1)->toString(), + ], + 'total' => true, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(1, $response['body']['variables']); + $this->assertGreaterThanOrEqual(2, $response['body']['total']); + + $this->cleanupFunction($functionId); + } + + public function testListVariablesWithoutTotal(): void + { + // Create a fresh function for this test + $function = $this->createFunction([ + 'functionId' => ID::unique(), + 'name' => 'Test List Variables Without Total', + 'execute' => [Role::user($this->getUser()['$id'])->toString()], + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', + 'timeout' => 10, + ]); + $this->assertEquals(201, $function['headers']['status-code']); + $functionId = $function['body']['$id']; + + $variable = $this->createVariable($functionId, [ + 'variableId' => ID::unique(), + 'key' => 'NO_TOTAL_KEY', + 'value' => 'no-total-value', + ]); + $this->assertEquals(201, $variable['headers']['status-code']); + + // List with total=false + $response = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/variables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'total' => false, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(0, $response['body']['total']); + $this->assertGreaterThanOrEqual(1, \count($response['body']['variables'])); + + $this->cleanupFunction($functionId); + } + + public function testListVariablesCursorPagination(): void + { + // Create a fresh function for this test + $function = $this->createFunction([ + 'functionId' => ID::unique(), + 'name' => 'Test List Variables Cursor Pagination', + 'execute' => [Role::user($this->getUser()['$id'])->toString()], + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', + 'timeout' => 10, + ]); + $this->assertEquals(201, $function['headers']['status-code']); + $functionId = $function['body']['$id']; + + $variable1 = $this->createVariable($functionId, [ + 'variableId' => ID::unique(), + 'key' => 'CURSOR_KEY_1', + 'value' => 'cursor-value-1', + ]); + $this->assertEquals(201, $variable1['headers']['status-code']); + + $variable2 = $this->createVariable($functionId, [ + 'variableId' => ID::unique(), + 'key' => 'CURSOR_KEY_2', + 'value' => 'cursor-value-2', + ]); + $this->assertEquals(201, $variable2['headers']['status-code']); + + // Get first page with limit 1 + $page1 = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/variables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + Query::limit(1)->toString(), + ], + 'total' => true, + ]); + + $this->assertEquals(200, $page1['headers']['status-code']); + $this->assertCount(1, $page1['body']['variables']); + $cursorId = $page1['body']['variables'][0]['$id']; + + // Get next page using cursor + $page2 = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/variables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + Query::limit(1)->toString(), + Query::cursorAfter(new Document(['$id' => $cursorId]))->toString(), + ], + 'total' => true, + ]); + + $this->assertEquals(200, $page2['headers']['status-code']); + $this->assertCount(1, $page2['body']['variables']); + $this->assertNotEquals($cursorId, $page2['body']['variables'][0]['$id']); + + $this->cleanupFunction($functionId); + } + public function testGetVariable(): void { $data = $this->setupTestVariables(); @@ -337,6 +526,7 @@ class FunctionsConsoleClientTest extends Scope $functionId = $function['body']['$id']; $variable = $this->createVariable($functionId, [ + 'variableId' => ID::unique(), 'key' => 'APP_TEST', 'value' => 'TESTINGVALUE', 'secret' => false @@ -345,6 +535,7 @@ class FunctionsConsoleClientTest extends Scope $variableId = $variable['body']['$id']; $secretVariable = $this->createVariable($functionId, [ + 'variableId' => ID::unique(), 'key' => 'APP_TEST_1', 'value' => 'TESTINGVALUE_1', 'secret' => true @@ -457,6 +648,7 @@ class FunctionsConsoleClientTest extends Scope * Test for FAILURE */ + // Update with no parameters should fail with 400 $response = $this->client->call(Client::METHOD_PUT, '/functions/' . $functionId . '/variables/' . $variableId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -464,6 +656,7 @@ class FunctionsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); + // Update with only value should succeed $response = $this->client->call(Client::METHOD_PUT, '/functions/' . $functionId . '/variables/' . $variableId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -471,7 +664,8 @@ class FunctionsConsoleClientTest extends Scope 'value' => 'TESTINGVALUEUPDATED_2' ]); - $this->assertEquals(400, $response['headers']['status-code']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals("TESTINGVALUEUPDATED_2", $response['body']['value']); $longKey = str_repeat("A", 256); $response = $this->client->call(Client::METHOD_PUT, '/functions/' . $functionId . '/variables/' . $variableId, array_merge([ @@ -496,6 +690,110 @@ class FunctionsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); } + public function testUpdateVariableKey(): void + { + // Create a fresh function and variable for this test + $function = $this->createFunction([ + 'functionId' => ID::unique(), + 'name' => 'Test Update Variable Key', + 'execute' => [Role::user($this->getUser()['$id'])->toString()], + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', + 'timeout' => 10, + ]); + $this->assertEquals(201, $function['headers']['status-code']); + $functionId = $function['body']['$id']; + + $variable = $this->createVariable($functionId, [ + 'variableId' => ID::unique(), + 'key' => 'KEY_BEFORE', + 'value' => 'unchanged-value', + 'secret' => false + ]); + $this->assertEquals(201, $variable['headers']['status-code']); + $variableId = $variable['body']['$id']; + + // Update only key (key is nullable, but we provide a new key) + $response = $this->client->call(Client::METHOD_PUT, '/functions/' . $functionId . '/variables/' . $variableId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'key' => 'KEY_AFTER', + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('KEY_AFTER', $response['body']['key']); + $this->assertEquals('unchanged-value', $response['body']['value']); + + $this->cleanupFunction($functionId); + } + + public function testUpdateVariableValueOnly(): void + { + // Create a fresh function and variable for this test + $function = $this->createFunction([ + 'functionId' => ID::unique(), + 'name' => 'Test Update Variable Value', + 'execute' => [Role::user($this->getUser()['$id'])->toString()], + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', + 'timeout' => 10, + ]); + $this->assertEquals(201, $function['headers']['status-code']); + $functionId = $function['body']['$id']; + + $variable = $this->createVariable($functionId, [ + 'variableId' => ID::unique(), + 'key' => 'UNCHANGED_KEY', + 'value' => 'value-before', + 'secret' => false + ]); + $this->assertEquals(201, $variable['headers']['status-code']); + $variableId = $variable['body']['$id']; + + // Update only value + $response = $this->client->call(Client::METHOD_PUT, '/functions/' . $functionId . '/variables/' . $variableId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'value' => 'value-after', + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('UNCHANGED_KEY', $response['body']['key']); + $this->assertEquals('value-after', $response['body']['value']); + + $this->cleanupFunction($functionId); + } + + public function testUpdateVariableNotFound(): void + { + // Create a fresh function for this test + $function = $this->createFunction([ + 'functionId' => ID::unique(), + 'name' => 'Test Update Variable Not Found', + 'execute' => [Role::user($this->getUser()['$id'])->toString()], + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', + 'timeout' => 10, + ]); + $this->assertEquals(201, $function['headers']['status-code']); + $functionId = $function['body']['$id']; + + $response = $this->client->call(Client::METHOD_PUT, '/functions/' . $functionId . '/variables/non-existent-id', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'key' => 'NEW_KEY', + 'value' => 'new-value', + ]); + + $this->assertEquals(404, $response['headers']['status-code']); + $this->assertEquals('variable_not_found', $response['body']['type']); + + $this->cleanupFunction($functionId); + } + public function testDeleteVariable(): void { // Create a fresh function and variables for this test since it deletes them @@ -512,6 +810,7 @@ class FunctionsConsoleClientTest extends Scope $functionId = $function['body']['$id']; $variable = $this->createVariable($functionId, [ + 'variableId' => ID::unique(), 'key' => 'APP_TEST', 'value' => 'TESTINGVALUE', 'secret' => false @@ -520,6 +819,7 @@ class FunctionsConsoleClientTest extends Scope $variableId = $variable['body']['$id']; $secretVariable = $this->createVariable($functionId, [ + 'variableId' => ID::unique(), 'key' => 'APP_TEST_1', 'value' => 'TESTINGVALUE_1', 'secret' => true @@ -585,6 +885,7 @@ class FunctionsConsoleClientTest extends Scope // create variable $variable = $this->createVariable($functionId, [ + 'variableId' => ID::unique(), 'key' => 'CUSTOM_VARIABLE', 'value' => 'a_secret_value', 'secret' => true, diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 7d9257c699..2beae74d3e 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -104,14 +104,17 @@ class SitesCustomServerTest extends Scope $this->assertEquals('./', $site['body']['outputDirectory']); $variable = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), 'key' => 'siteKey1', 'value' => 'siteValue1', ]); $variable2 = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), 'key' => 'siteKey2', 'value' => 'siteValue2', ]); $variable3 = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), 'key' => 'siteKey3', 'value' => 'siteValue3', ]); @@ -211,6 +214,7 @@ class SitesCustomServerTest extends Scope $this->assertEquals('Test Site', $site['body']['name']); $variable = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), 'key' => 'siteKey1', 'value' => 'siteValue1', 'secret' => false, @@ -223,6 +227,7 @@ class SitesCustomServerTest extends Scope $this->assertEquals(false, $variable['body']['secret']); $variable2 = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), 'key' => 'siteKey2', 'value' => 'siteValue2', 'secret' => false, @@ -235,6 +240,7 @@ class SitesCustomServerTest extends Scope $this->assertEquals(false, $variable2['body']['secret']); $secretVariable = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), 'key' => 'siteKey3', 'value' => 'siteValue3', 'secret' => true, @@ -330,6 +336,316 @@ class SitesCustomServerTest extends Scope $this->cleanupSite($siteId); } + public function testListVariablesWithLimit(): void + { + $site = $this->createSite([ + 'buildRuntime' => 'node-22', + 'fallbackFile' => '', + 'framework' => 'other', + 'name' => 'Test List Variables Limit', + 'outputDirectory' => './', + 'siteId' => ID::unique() + ]); + $siteId = $site['body']['$id'] ?? ''; + $this->assertEquals(201, $site['headers']['status-code']); + + $variable1 = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), + 'key' => 'LIMIT_KEY_1', + 'value' => 'limit-value-1', + ]); + $this->assertEquals(201, $variable1['headers']['status-code']); + + $variable2 = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), + 'key' => 'LIMIT_KEY_2', + 'value' => 'limit-value-2', + ]); + $this->assertEquals(201, $variable2['headers']['status-code']); + + // List with limit of 1 + $response = $this->listVariables($siteId, [ + 'queries' => [ + Query::limit(1)->toString(), + ], + 'total' => true, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(1, $response['body']['variables']); + $this->assertGreaterThanOrEqual(2, $response['body']['total']); + + $this->cleanupSite($siteId); + } + + public function testListVariablesWithoutTotal(): void + { + $site = $this->createSite([ + 'buildRuntime' => 'node-22', + 'fallbackFile' => '', + 'framework' => 'other', + 'name' => 'Test List Variables No Total', + 'outputDirectory' => './', + 'siteId' => ID::unique() + ]); + $siteId = $site['body']['$id'] ?? ''; + $this->assertEquals(201, $site['headers']['status-code']); + + $variable = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), + 'key' => 'NO_TOTAL_KEY', + 'value' => 'no-total-value', + ]); + $this->assertEquals(201, $variable['headers']['status-code']); + + // List with total=false + $response = $this->listVariables($siteId, [ + 'total' => false, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(0, $response['body']['total']); + $this->assertGreaterThanOrEqual(1, \count($response['body']['variables'])); + + $this->cleanupSite($siteId); + } + + public function testListVariablesCursorPagination(): void + { + $site = $this->createSite([ + 'buildRuntime' => 'node-22', + 'fallbackFile' => '', + 'framework' => 'other', + 'name' => 'Test List Variables Cursor', + 'outputDirectory' => './', + 'siteId' => ID::unique() + ]); + $siteId = $site['body']['$id'] ?? ''; + $this->assertEquals(201, $site['headers']['status-code']); + + $variable1 = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), + 'key' => 'CURSOR_KEY_1', + 'value' => 'cursor-value-1', + ]); + $this->assertEquals(201, $variable1['headers']['status-code']); + + $variable2 = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), + 'key' => 'CURSOR_KEY_2', + 'value' => 'cursor-value-2', + ]); + $this->assertEquals(201, $variable2['headers']['status-code']); + + // Get first page with limit 1 + $page1 = $this->listVariables($siteId, [ + 'queries' => [ + Query::limit(1)->toString(), + ], + 'total' => true, + ]); + + $this->assertEquals(200, $page1['headers']['status-code']); + $this->assertCount(1, $page1['body']['variables']); + $cursorId = $page1['body']['variables'][0]['$id']; + + // Get next page using cursor + $page2 = $this->listVariables($siteId, [ + 'queries' => [ + Query::limit(1)->toString(), + Query::cursorAfter(new Document(['$id' => $cursorId]))->toString(), + ], + 'total' => true, + ]); + + $this->assertEquals(200, $page2['headers']['status-code']); + $this->assertCount(1, $page2['body']['variables']); + $this->assertNotEquals($cursorId, $page2['body']['variables'][0]['$id']); + + $this->cleanupSite($siteId); + } + + public function testUpdateVariableKey(): void + { + $site = $this->createSite([ + 'buildRuntime' => 'node-22', + 'fallbackFile' => '', + 'framework' => 'other', + 'name' => 'Test Update Variable Key', + 'outputDirectory' => './', + 'siteId' => ID::unique() + ]); + $siteId = $site['body']['$id'] ?? ''; + $this->assertEquals(201, $site['headers']['status-code']); + + $variable = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), + 'key' => 'KEY_BEFORE', + 'value' => 'unchanged-value', + 'secret' => false + ]); + $this->assertEquals(201, $variable['headers']['status-code']); + $variableId = $variable['body']['$id']; + + // Update only key + $response = $this->updateVariable($siteId, $variableId, [ + 'key' => 'KEY_AFTER', + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('KEY_AFTER', $response['body']['key']); + $this->assertEquals('unchanged-value', $response['body']['value']); + + $this->cleanupSite($siteId); + } + + public function testUpdateVariableValueOnly(): void + { + $site = $this->createSite([ + 'buildRuntime' => 'node-22', + 'fallbackFile' => '', + 'framework' => 'other', + 'name' => 'Test Update Variable Value', + 'outputDirectory' => './', + 'siteId' => ID::unique() + ]); + $siteId = $site['body']['$id'] ?? ''; + $this->assertEquals(201, $site['headers']['status-code']); + + $variable = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), + 'key' => 'UNCHANGED_KEY', + 'value' => 'value-before', + 'secret' => false + ]); + $this->assertEquals(201, $variable['headers']['status-code']); + $variableId = $variable['body']['$id']; + + // Update only value + $response = $this->updateVariable($siteId, $variableId, [ + 'value' => 'value-after', + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('UNCHANGED_KEY', $response['body']['key']); + $this->assertEquals('value-after', $response['body']['value']); + + $this->cleanupSite($siteId); + } + + public function testUpdateVariableNoOp(): void + { + $site = $this->createSite([ + 'buildRuntime' => 'node-22', + 'fallbackFile' => '', + 'framework' => 'other', + 'name' => 'Test Update Variable NoOp', + 'outputDirectory' => './', + 'siteId' => ID::unique() + ]); + $siteId = $site['body']['$id'] ?? ''; + $this->assertEquals(201, $site['headers']['status-code']); + + $variable = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), + 'key' => 'NOOP_KEY', + 'value' => 'noop-value', + 'secret' => false + ]); + $this->assertEquals(201, $variable['headers']['status-code']); + $variableId = $variable['body']['$id']; + + // Update with no parameters should fail with 400 + $response = $this->updateVariable($siteId, $variableId, []); + + $this->assertEquals(400, $response['headers']['status-code']); + + $this->cleanupSite($siteId); + } + + public function testUpdateVariableNotFound(): void + { + $site = $this->createSite([ + 'buildRuntime' => 'node-22', + 'fallbackFile' => '', + 'framework' => 'other', + 'name' => 'Test Update Variable Not Found', + 'outputDirectory' => './', + 'siteId' => ID::unique() + ]); + $siteId = $site['body']['$id'] ?? ''; + $this->assertEquals(201, $site['headers']['status-code']); + + $response = $this->updateVariable($siteId, 'non-existent-id', [ + 'key' => 'NEW_KEY', + 'value' => 'new-value', + ]); + + $this->assertEquals(404, $response['headers']['status-code']); + $this->assertEquals('variable_not_found', $response['body']['type']); + + $this->cleanupSite($siteId); + } + + public function testCreateVariableInvalidId(): void + { + $site = $this->createSite([ + 'buildRuntime' => 'node-22', + 'fallbackFile' => '', + 'framework' => 'other', + 'name' => 'Test Invalid Variable ID', + 'outputDirectory' => './', + 'siteId' => ID::unique() + ]); + $siteId = $site['body']['$id'] ?? ''; + $this->assertEquals(201, $site['headers']['status-code']); + + $variable = $this->createVariable($siteId, [ + 'variableId' => '!invalid-id!', + 'key' => 'INVALID_ID_KEY', + 'value' => 'value', + ]); + + $this->assertEquals(400, $variable['headers']['status-code']); + + $this->cleanupSite($siteId); + } + + public function testCreateVariableDuplicateId(): void + { + $site = $this->createSite([ + 'buildRuntime' => 'node-22', + 'fallbackFile' => '', + 'framework' => 'other', + 'name' => 'Test Duplicate Variable ID', + 'outputDirectory' => './', + 'siteId' => ID::unique() + ]); + $siteId = $site['body']['$id'] ?? ''; + $this->assertEquals(201, $site['headers']['status-code']); + + $variableId = ID::unique(); + + $variable = $this->createVariable($siteId, [ + 'variableId' => $variableId, + 'key' => 'DUP_ID_KEY_1', + 'value' => 'value1', + ]); + $this->assertEquals(201, $variable['headers']['status-code']); + + // Attempt to create with same ID + $duplicate = $this->createVariable($siteId, [ + 'variableId' => $variableId, + 'key' => 'DUP_ID_KEY_2', + 'value' => 'value2', + ]); + + $this->assertEquals(409, $duplicate['headers']['status-code']); + $this->assertEquals('variable_already_exists', $duplicate['body']['type']); + + $this->cleanupSite($siteId); + } + // This is first Sites test with Proxy // If this fails, it may not be related to variables; but Router flow failing public function testVariablesE2E(): void @@ -351,6 +667,7 @@ class SitesCustomServerTest extends Scope $domain = $this->setupSiteDomain($siteId); $secretVariable = $this->createVariable($siteId, [ + 'variableId' => ID::unique(), 'key' => 'name', 'value' => 'Appwrite', ]); From 1975ab251363e5d17e1bf5b1c54f5fdff387df36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 5 May 2026 16:45:15 +0200 Subject: [PATCH 143/211] Fix linter --- src/Appwrite/Utopia/Response/Filters/V25.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response/Filters/V25.php b/src/Appwrite/Utopia/Response/Filters/V25.php index 03d19d2cc1..3040ef681b 100644 --- a/src/Appwrite/Utopia/Response/Filters/V25.php +++ b/src/Appwrite/Utopia/Response/Filters/V25.php @@ -2,7 +2,6 @@ namespace Appwrite\Utopia\Response\Filters; -use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Filter; // Convert 1.9.4 Data format to 1.9.3 format From 3e58500e13450c878e1d47b490aee71c5e718c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 5 May 2026 16:51:57 +0200 Subject: [PATCH 144/211] Upgrade libs --- composer.json | 13 ++-- composer.lock | 165 ++++++++++++++++++++------------------------------ 2 files changed, 72 insertions(+), 106 deletions(-) diff --git a/composer.json b/composer.json index d6182ba750..b2b89fcee6 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ "utopia-php/audit": "2.2.*", "utopia-php/auth": "0.5.*", "utopia-php/cache": "1.0.*", - "utopia-php/cli": "dev-feat-param-alias as 0.23.99", + "utopia-php/cli": "0.23.*", "utopia-php/compression": "0.1.*", "utopia-php/config": "1.*", "utopia-php/console": "0.1.*", @@ -67,7 +67,7 @@ "utopia-php/emails": "0.6.*", "utopia-php/dns": "1.6.*", "utopia-php/dsn": "0.2.1", - "utopia-php/http": "dev-feat-param-aliases as 0.34.99", + "utopia-php/http": "0.34.*", "utopia-php/fetch": "0.5.*", "utopia-php/validators": "0.2.*", "utopia-php/image": "0.8.*", @@ -75,12 +75,12 @@ "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.22.*", "utopia-php/migration": "1.9.*", - "utopia-php/platform": "dev-feat-param-aliases as 0.13.99", + "utopia-php/platform": "0.13.*", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", "utopia-php/preloader": "0.2.*", - "utopia-php/queue": "dev-feat-param-aliases as 0.17.99", - "utopia-php/servers": "dev-feat-param-aliases as 0.3.99", + "utopia-php/queue": "0.18.*", + "utopia-php/servers": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/storage": "2.*", "utopia-php/system": "0.10.*", @@ -117,6 +117,9 @@ "allow-plugins": { "php-http/discovery": true, "tbachert/spi": true + }, + "audit": { + "ignore": ["PKSA-sf9j-1gs7-xzvx"] } } } diff --git a/composer.lock b/composer.lock index 89ed556028..a92ecd0474 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": "ff46a826bc257b5ed2f0a8c821d8a0c4", + "content-hash": "842fa93d1bddb5eeef66ef09627ae84d", "packages": [ { "name": "adhocore/jwt", @@ -3658,21 +3658,21 @@ }, { "name": "utopia-php/cli", - "version": "dev-feat-param-alias", + "version": "0.23.3", "source": { "type": "git", "url": "https://github.com/utopia-php/cli.git", - "reference": "c01a4af02249f20f5a9b3e23b6e8ee20f52857a2" + "reference": "3c45ae5bcdcd3c7916e1909d74c60b8e771610db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cli/zipball/c01a4af02249f20f5a9b3e23b6e8ee20f52857a2", - "reference": "c01a4af02249f20f5a9b3e23b6e8ee20f52857a2", + "url": "https://api.github.com/repos/utopia-php/cli/zipball/3c45ae5bcdcd3c7916e1909d74c60b8e771610db", + "reference": "3c45ae5bcdcd3c7916e1909d74c60b8e771610db", "shasum": "" }, "require": { "php": ">=7.4", - "utopia-php/servers": "dev-feat-param-aliases" + "utopia-php/servers": "0.4.0" }, "require-dev": { "laravel/pint": "1.2.*", @@ -3703,9 +3703,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cli/issues", - "source": "https://github.com/utopia-php/cli/tree/feat-param-alias" + "source": "https://github.com/utopia-php/cli/tree/0.23.3" }, - "time": "2026-05-04T12:39:30+00:00" + "time": "2026-05-05T04:38:59+00:00" }, { "name": "utopia-php/compression", @@ -4272,23 +4272,23 @@ }, { "name": "utopia-php/http", - "version": "dev-feat-param-aliases", + "version": "0.34.25", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "4439705c8c2e81af826f4b6d694469c9ebc84a9f" + "reference": "76be330d4197bae680eb4ccc29c573456fe91904" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/4439705c8c2e81af826f4b6d694469c9ebc84a9f", - "reference": "4439705c8c2e81af826f4b6d694469c9ebc84a9f", + "url": "https://api.github.com/repos/utopia-php/http/zipball/76be330d4197bae680eb4ccc29c573456fe91904", + "reference": "76be330d4197bae680eb4ccc29c573456fe91904", "shasum": "" }, "require": { "php": ">=8.3", "utopia-php/compression": "0.1.*", "utopia-php/di": "0.3.*", - "utopia-php/servers": "dev-feat-param-aliases as 0.3.x-dev", + "utopia-php/servers": "0.4.0", "utopia-php/telemetry": "0.2.*", "utopia-php/validators": "0.2.*" }, @@ -4322,9 +4322,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/feat-param-aliases" + "source": "https://github.com/utopia-php/http/tree/0.34.25" }, - "time": "2026-05-04T11:52:49+00:00" + "time": "2026-05-05T04:39:15+00:00" }, { "name": "utopia-php/image", @@ -4531,16 +4531,16 @@ }, { "name": "utopia-php/migration", - "version": "1.9.6", + "version": "1.9.7", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "b164631404ec759f8c368fe2321f44c22bc258ab" + "reference": "81b608a6871f56b70496803d12010823300aab6e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/b164631404ec759f8c368fe2321f44c22bc258ab", - "reference": "b164631404ec759f8c368fe2321f44c22bc258ab", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/81b608a6871f56b70496803d12010823300aab6e", + "reference": "81b608a6871f56b70496803d12010823300aab6e", "shasum": "" }, "require": { @@ -4580,9 +4580,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.9.6" + "source": "https://github.com/utopia-php/migration/tree/1.9.7" }, - "time": "2026-04-30T08:11:07+00:00" + "time": "2026-05-05T07:18:48+00:00" }, { "name": "utopia-php/mongo", @@ -4647,26 +4647,26 @@ }, { "name": "utopia-php/platform", - "version": "dev-feat-param-aliases", + "version": "0.13.2", "source": { "type": "git", "url": "https://github.com/utopia-php/platform.git", - "reference": "7fa008758c869671014ae4c4d52bb8cd686212f9" + "reference": "a20cb8b20a1e4c9886309c2d033a0292ba0937b9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/platform/zipball/7fa008758c869671014ae4c4d52bb8cd686212f9", - "reference": "7fa008758c869671014ae4c4d52bb8cd686212f9", + "url": "https://api.github.com/repos/utopia-php/platform/zipball/a20cb8b20a1e4c9886309c2d033a0292ba0937b9", + "reference": "a20cb8b20a1e4c9886309c2d033a0292ba0937b9", "shasum": "" }, "require": { "ext-json": "*", "ext-redis": "*", "php": ">=8.3", - "utopia-php/cli": "dev-feat-param-alias as 0.23.99", - "utopia-php/http": "dev-feat-param-aliases as 0.34.99", - "utopia-php/queue": "dev-feat-param-aliases as 0.18.99", - "utopia-php/servers": "dev-feat-param-aliases as 0.3.99" + "utopia-php/cli": "0.23.3", + "utopia-php/http": "0.34.25", + "utopia-php/queue": "0.18.2", + "utopia-php/servers": "0.4.0" }, "require-dev": { "laravel/pint": "1.2.*", @@ -4692,9 +4692,9 @@ ], "support": { "issues": "https://github.com/utopia-php/platform/issues", - "source": "https://github.com/utopia-php/platform/tree/feat-param-aliases" + "source": "https://github.com/utopia-php/platform/tree/0.13.2" }, - "time": "2026-05-04T13:12:58+00:00" + "time": "2026-05-05T06:00:26+00:00" }, { "name": "utopia-php/pools", @@ -4804,16 +4804,16 @@ }, { "name": "utopia-php/queue", - "version": "dev-feat-param-aliases", + "version": "0.18.2", "source": { "type": "git", "url": "https://github.com/utopia-php/queue.git", - "reference": "32b0c439a8fa4fc06b8b8793800a04be894bf03c" + "reference": "f85ca003c99ff475708c05466643d067403c0c22" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/queue/zipball/32b0c439a8fa4fc06b8b8793800a04be894bf03c", - "reference": "32b0c439a8fa4fc06b8b8793800a04be894bf03c", + "url": "https://api.github.com/repos/utopia-php/queue/zipball/f85ca003c99ff475708c05466643d067403c0c22", + "reference": "f85ca003c99ff475708c05466643d067403c0c22", "shasum": "" }, "require": { @@ -4821,7 +4821,7 @@ "php-amqplib/php-amqplib": "^3.7", "utopia-php/di": "0.3.*", "utopia-php/pools": "1.*", - "utopia-php/servers": "dev-feat-param-aliases as 0.3.99", + "utopia-php/servers": "0.4.0", "utopia-php/telemetry": "0.2.*", "utopia-php/validators": "0.2.*" }, @@ -4864,9 +4864,9 @@ ], "support": { "issues": "https://github.com/utopia-php/queue/issues", - "source": "https://github.com/utopia-php/queue/tree/feat-param-aliases" + "source": "https://github.com/utopia-php/queue/tree/0.18.2" }, - "time": "2026-05-04T12:59:54+00:00" + "time": "2026-05-05T04:38:59+00:00" }, { "name": "utopia-php/registry", @@ -4922,16 +4922,16 @@ }, { "name": "utopia-php/servers", - "version": "dev-feat-param-aliases", + "version": "0.4.0", "source": { "type": "git", "url": "https://github.com/utopia-php/servers.git", - "reference": "24bbd8fbb6550bc72f2816d9b0c3b690e38e17fa" + "reference": "7db346ef377503efe0acafe0791085270cd9ed70" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/24bbd8fbb6550bc72f2816d9b0c3b690e38e17fa", - "reference": "24bbd8fbb6550bc72f2816d9b0c3b690e38e17fa", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/7db346ef377503efe0acafe0791085270cd9ed70", + "reference": "7db346ef377503efe0acafe0791085270cd9ed70", "shasum": "" }, "require": { @@ -4970,9 +4970,9 @@ ], "support": { "issues": "https://github.com/utopia-php/servers/issues", - "source": "https://github.com/utopia-php/servers/tree/feat-param-aliases" + "source": "https://github.com/utopia-php/servers/tree/0.4.0" }, - "time": "2026-05-04T11:57:44+00:00" + "time": "2026-05-05T04:08:30+00:00" }, { "name": "utopia-php/span", @@ -5020,16 +5020,16 @@ }, { "name": "utopia-php/storage", - "version": "2.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "8a2e3a86fd01aaed675884146665308c2122264e" + "reference": "64e132a3768e22243eda36fe4262da22fd204f3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/8a2e3a86fd01aaed675884146665308c2122264e", - "reference": "8a2e3a86fd01aaed675884146665308c2122264e", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/64e132a3768e22243eda36fe4262da22fd204f3c", + "reference": "64e132a3768e22243eda36fe4262da22fd204f3c", "shasum": "" }, "require": { @@ -5066,22 +5066,22 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/2.0.1" + "source": "https://github.com/utopia-php/storage/tree/2.0.2" }, - "time": "2026-04-29T09:05:48+00:00" + "time": "2026-05-01T15:06:16+00:00" }, { "name": "utopia-php/system", - "version": "0.10.1", + "version": "0.10.2", "source": { "type": "git", "url": "https://github.com/utopia-php/system.git", - "reference": "7c1669533bb9c285de19191270c8c1439161a78a" + "reference": "04229a822b147c1abaf1a92fb42c2d7aad4625df" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/system/zipball/7c1669533bb9c285de19191270c8c1439161a78a", - "reference": "7c1669533bb9c285de19191270c8c1439161a78a", + "url": "https://api.github.com/repos/utopia-php/system/zipball/04229a822b147c1abaf1a92fb42c2d7aad4625df", + "reference": "04229a822b147c1abaf1a92fb42c2d7aad4625df", "shasum": "" }, "require": { @@ -5122,9 +5122,9 @@ ], "support": { "issues": "https://github.com/utopia-php/system/issues", - "source": "https://github.com/utopia-php/system/tree/0.10.1" + "source": "https://github.com/utopia-php/system/tree/0.10.2" }, - "time": "2026-03-15T21:07:41+00:00" + "time": "2026-05-05T14:33:41+00:00" }, { "name": "utopia-php/telemetry", @@ -5465,16 +5465,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.26.0", + "version": "1.27.5", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "c14a7232ef0f22f594453730407c2719a2854973" + "reference": "9faa38b48d422f3da764a719712905c83b3922cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/c14a7232ef0f22f594453730407c2719a2854973", - "reference": "c14a7232ef0f22f594453730407c2719a2854973", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/9faa38b48d422f3da764a719712905c83b3922cb", + "reference": "9faa38b48d422f3da764a719712905c83b3922cb", "shasum": "" }, "require": { @@ -5510,9 +5510,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.26.0" + "source": "https://github.com/appwrite/sdk-generator/tree/1.27.5" }, - "time": "2026-05-04T09:46:22+00:00" + "time": "2026-05-05T12:09:40+00:00" }, { "name": "brianium/paratest", @@ -8442,46 +8442,9 @@ "time": "2024-11-07T12:36:22+00:00" } ], - "aliases": [ - { - "package": "utopia-php/cli", - "version": "dev-feat-param-alias", - "alias": "0.23.99", - "alias_normalized": "0.23.99.0" - }, - { - "package": "utopia-php/http", - "version": "dev-feat-param-aliases", - "alias": "0.34.99", - "alias_normalized": "0.34.99.0" - }, - { - "package": "utopia-php/platform", - "version": "dev-feat-param-aliases", - "alias": "0.13.99", - "alias_normalized": "0.13.99.0" - }, - { - "package": "utopia-php/queue", - "version": "dev-feat-param-aliases", - "alias": "0.17.99", - "alias_normalized": "0.17.99.0" - }, - { - "package": "utopia-php/servers", - "version": "dev-feat-param-aliases", - "alias": "0.3.99", - "alias_normalized": "0.3.99.0" - } - ], + "aliases": [], "minimum-stability": "dev", - "stability-flags": { - "utopia-php/cli": 20, - "utopia-php/http": 20, - "utopia-php/platform": 20, - "utopia-php/queue": 20, - "utopia-php/servers": 20 - }, + "stability-flags": {}, "prefer-stable": true, "prefer-lowest": false, "platform": { From b382a9c3e5412084101775de0b2cebfdb40643c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 5 May 2026 16:53:24 +0200 Subject: [PATCH 145/211] Fix mistakes after AI --- composer.json | 3 --- composer.lock | 23 ++++++++++++----------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 693fe8bc47..76d16ef558 100644 --- a/composer.json +++ b/composer.json @@ -117,9 +117,6 @@ "allow-plugins": { "php-http/discovery": true, "tbachert/spi": true - }, - "audit": { - "ignore": ["PKSA-sf9j-1gs7-xzvx"] } } } diff --git a/composer.lock b/composer.lock index a92ecd0474..5f93f5b0a8 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": "842fa93d1bddb5eeef66ef09627ae84d", + "content-hash": "17ccba478a5cace1251b2211e25021f2", "packages": [ { "name": "adhocore/jwt", @@ -5384,16 +5384,16 @@ }, { "name": "webonyx/graphql-php", - "version": "v15.31.5", + "version": "v15.32.3", "source": { "type": "git", "url": "https://github.com/webonyx/graphql-php.git", - "reference": "089c4ef7e112df85788cfe06596278a8f99f4aa9" + "reference": "993bf0bea17f870412ad8a90f60c41cb8d5f1145" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/089c4ef7e112df85788cfe06596278a8f99f4aa9", - "reference": "089c4ef7e112df85788cfe06596278a8f99f4aa9", + "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/993bf0bea17f870412ad8a90f60c41cb8d5f1145", + "reference": "993bf0bea17f870412ad8a90f60c41cb8d5f1145", "shasum": "" }, "require": { @@ -5402,16 +5402,16 @@ "php": "^7.4 || ^8" }, "require-dev": { - "amphp/amp": "^2.6", - "amphp/http-server": "^2.1", + "amphp/amp": "^2.6 || ^3", + "amphp/http-server": "^2.1 || ^3", "dms/phpunit-arraysubset-asserts": "dev-master", "ergebnis/composer-normalize": "^2.28", - "friendsofphp/php-cs-fixer": "3.94.2", + "friendsofphp/php-cs-fixer": "3.95.1", "mll-lab/php-cs-fixer-config": "5.13.0", "nyholm/psr7": "^1.5", "phpbench/phpbench": "^1.2", "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "2.1.46", + "phpstan/phpstan": "2.1.51", "phpstan/phpstan-phpunit": "2.0.16", "phpstan/phpstan-strict-rules": "2.0.10", "phpunit/phpunit": "^9.5 || ^10.5.21 || ^11", @@ -5425,6 +5425,7 @@ "ticketswap/phpstan-error-formatter": "1.3.0" }, "suggest": { + "amphp/amp": "To leverage async resolving on AMPHP platform (v3 with AmpFutureAdapter, v2 with AmpPromiseAdapter)", "amphp/http-server": "To leverage async resolving with webserver on AMPHP platform", "psr/http-message": "To use standard GraphQL server", "react/promise": "To leverage async resolving on React PHP platform" @@ -5447,7 +5448,7 @@ ], "support": { "issues": "https://github.com/webonyx/graphql-php/issues", - "source": "https://github.com/webonyx/graphql-php/tree/v15.31.5" + "source": "https://github.com/webonyx/graphql-php/tree/v15.32.3" }, "funding": [ { @@ -5459,7 +5460,7 @@ "type": "open_collective" } ], - "time": "2026-04-11T18:06:15+00:00" + "time": "2026-04-24T13:49:35+00:00" } ], "packages-dev": [ From f90f618bffe07c8407a3bcd8df128fed6e9a4b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 5 May 2026 17:14:05 +0200 Subject: [PATCH 146/211] Fix failing tests --- src/Appwrite/Migration/Migration.php | 2 +- .../e2e/Services/Functions/FunctionsCustomServerTest.php | 9 +++++++++ .../e2e/Services/Projects/ProjectsConsoleClientTest.php | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 004e09cd23..08e32a9c74 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -96,7 +96,7 @@ abstract class Migration '1.9.1' => 'V24', '1.9.2' => 'V24', '1.9.3' => 'V24', - '1.9.4' => 'V25', + '1.9.4' => 'V24', ]; /** diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 899c0ff71f..f08b711fb2 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -53,14 +53,17 @@ class FunctionsCustomServerTest extends Scope $functionId = $function['body']['$id'] ?? ''; $variable = $this->createVariable($functionId, [ + 'variableId' => 'unique()', 'key' => 'funcKey1', 'value' => 'funcValue1', ]); $variable2 = $this->createVariable($functionId, [ + 'variableId' => 'unique()', 'key' => 'funcKey2', 'value' => 'funcValue2', ]); $variable3 = $this->createVariable($functionId, [ + 'variableId' => 'unique()', 'key' => 'funcKey3', 'value' => 'funcValue3', ]); @@ -109,6 +112,7 @@ class FunctionsCustomServerTest extends Scope // Create a variable for later tests $variable = $this->createVariable($functionId, [ + 'variableId' => 'unique()', 'key' => 'GLOBAL_VARIABLE', 'value' => 'Global Variable Value', ]); @@ -278,14 +282,17 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(10, $function['body']['timeout']); $variable = $this->createVariable($functionId, [ + 'variableId' => 'unique()', 'key' => 'funcKey1', 'value' => 'funcValue1', ]); $variable2 = $this->createVariable($functionId, [ + 'variableId' => 'unique()', 'key' => 'funcKey2', 'value' => 'funcValue2', ]); $variable3 = $this->createVariable($functionId, [ + 'variableId' => 'unique()', 'key' => 'funcKey3', 'value' => 'funcValue3', ]); @@ -521,6 +528,7 @@ class FunctionsCustomServerTest extends Scope // Create a variable for later tests $variable = $this->createVariable($functionId, [ + 'variableId' => 'unique()', 'key' => 'GLOBAL_VARIABLE', 'value' => 'Global Variable Value', ]); @@ -2011,6 +2019,7 @@ class FunctionsCustomServerTest extends Scope ]); $variable = $this->createVariable($functionId, [ + 'variableId' => 'unique()', 'key' => 'CUSTOM_VARIABLE', 'value' => 'variable' ]); diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 6936de9aff..3a9037c368 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -6813,6 +6813,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, ], [ + 'variableId' => $variableId, 'key' => 'APP_TEST_' . $variableId, 'value' => 'TESTINGVALUE', 'secret' => false @@ -6832,6 +6833,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, ], [ + 'variableId' => $variableId, 'key' => 'APP_TEST_' . $variableId, 'value' => 'TESTINGVALUE', 'secret' => false From 803f646239d8b39b0e411d75bbbc38cc60b11c0f Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 5 May 2026 17:19:40 +0100 Subject: [PATCH 147/211] Update composer.lock for utopia-php/migration da8205e --- composer.lock | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/composer.lock b/composer.lock index 7f38aea1cf..43dd28b150 100644 --- a/composer.lock +++ b/composer.lock @@ -4535,12 +4535,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "276e7c25077a4dee670a806f715869f11367d932" + "reference": "da8205e8f3e927b2b860dddc2efca0e408171116" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/276e7c25077a4dee670a806f715869f11367d932", - "reference": "276e7c25077a4dee670a806f715869f11367d932", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/da8205e8f3e927b2b860dddc2efca0e408171116", + "reference": "da8205e8f3e927b2b860dddc2efca0e408171116", "shasum": "" }, "require": { @@ -4600,7 +4600,7 @@ "source": "https://github.com/utopia-php/migration/tree/fix-migration-sentry-leak", "issues": "https://github.com/utopia-php/migration/issues" }, - "time": "2026-05-04T07:20:31+00:00" + "time": "2026-05-05T15:50:58+00:00" }, { "name": "utopia-php/mongo", @@ -5039,16 +5039,16 @@ }, { "name": "utopia-php/storage", - "version": "2.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "8a2e3a86fd01aaed675884146665308c2122264e" + "reference": "64e132a3768e22243eda36fe4262da22fd204f3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/8a2e3a86fd01aaed675884146665308c2122264e", - "reference": "8a2e3a86fd01aaed675884146665308c2122264e", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/64e132a3768e22243eda36fe4262da22fd204f3c", + "reference": "64e132a3768e22243eda36fe4262da22fd204f3c", "shasum": "" }, "require": { @@ -5085,22 +5085,22 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/2.0.1" + "source": "https://github.com/utopia-php/storage/tree/2.0.2" }, - "time": "2026-04-29T09:05:48+00:00" + "time": "2026-05-01T15:06:16+00:00" }, { "name": "utopia-php/system", - "version": "0.10.1", + "version": "0.10.2", "source": { "type": "git", "url": "https://github.com/utopia-php/system.git", - "reference": "7c1669533bb9c285de19191270c8c1439161a78a" + "reference": "04229a822b147c1abaf1a92fb42c2d7aad4625df" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/system/zipball/7c1669533bb9c285de19191270c8c1439161a78a", - "reference": "7c1669533bb9c285de19191270c8c1439161a78a", + "url": "https://api.github.com/repos/utopia-php/system/zipball/04229a822b147c1abaf1a92fb42c2d7aad4625df", + "reference": "04229a822b147c1abaf1a92fb42c2d7aad4625df", "shasum": "" }, "require": { @@ -5141,9 +5141,9 @@ ], "support": { "issues": "https://github.com/utopia-php/system/issues", - "source": "https://github.com/utopia-php/system/tree/0.10.1" + "source": "https://github.com/utopia-php/system/tree/0.10.2" }, - "time": "2026-03-15T21:07:41+00:00" + "time": "2026-05-05T14:33:41+00:00" }, { "name": "utopia-php/telemetry", From 94c968e9414a9b37b9a6a11c36dfeb12a140f6ed Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 6 May 2026 04:35:29 +0000 Subject: [PATCH 148/211] feat(indexes): add 4 missing indexes (CLO-2333) - memberships: _key_team_confirm on (teamInternalId, confirm) for team-membership confirm-state queries - projects: _key_teamInternalId on teamInternalId for team-scoped project lookups - platforms: _key_project_id on projectId for user-facing-id lookups - webhooks: _key_project_id on projectId for user-facing-id lookups Re-applies the indexes from the stale PR #9629 (1.7.x base, conflicting) onto a fresh 1.9.x branch. None of these are in 1.9.x today; existing similar indexes target projectInternalId / teamId rather than the user-facing projectId / teamInternalId queries this addresses. --- app/config/collections/common.php | 7 +++++++ app/config/collections/platform.php | 23 ++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/config/collections/common.php b/app/config/collections/common.php index 80bb717423..37fbcc8ca3 100644 --- a/app/config/collections/common.php +++ b/app/config/collections/common.php @@ -1523,6 +1523,13 @@ return [ 'lengths' => [], 'orders' => [Database::ORDER_ASC], ], + [ + '$id' => ID::custom('_key_team_confirm'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['teamInternalId', 'confirm'], + 'lengths' => [], + 'orders' => [], + ], ], ], diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index 6195c11724..bb3413da5c 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -404,6 +404,13 @@ $platformCollections = [ 'lengths' => [], 'orders' => [], ], + [ + '$id' => ID::custom('_key_teamInternalId'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['teamInternalId'], + 'lengths' => [], + 'orders' => [], + ], ], ], @@ -635,6 +642,13 @@ $platformCollections = [ 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], + [ + '$id' => ID::custom('_key_project_id'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['projectId'], + 'lengths' => [], + 'orders' => [], + ], ], ], @@ -1007,7 +1021,14 @@ $platformCollections = [ 'attributes' => ['projectInternalId'], 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], - ] + ], + [ + '$id' => ID::custom('_key_project_id'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['projectId'], + 'lengths' => [], + 'orders' => [], + ], ], ], From 83d56a2f368854c88a5644d09608a84ddcae3c7a Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 6 May 2026 04:44:58 +0000 Subject: [PATCH 149/211] fix(indexes): set explicit lengths + orders on new indexes (greptile P1) All four new indexes left lengths/orders as empty arrays; greptile flagged the inconsistency vs every existing string-attribute index in the file (e.g. _key_team uses [LENGTH_KEY], _key_unique uses [LENGTH_KEY, LENGTH_KEY]). - memberships._key_team_confirm: [LENGTH_KEY, 0] for (string, boolean) + [ORDER_ASC, ORDER_ASC] - projects._key_teamInternalId: [LENGTH_KEY] + [ORDER_ASC] - platforms._key_project_id: [LENGTH_KEY] + [ORDER_ASC] - webhooks._key_project_id: [LENGTH_KEY] + [ORDER_ASC] --- app/config/collections/common.php | 4 ++-- app/config/collections/platform.php | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/config/collections/common.php b/app/config/collections/common.php index 37fbcc8ca3..8b5d623185 100644 --- a/app/config/collections/common.php +++ b/app/config/collections/common.php @@ -1527,8 +1527,8 @@ return [ '$id' => ID::custom('_key_team_confirm'), 'type' => Database::INDEX_KEY, 'attributes' => ['teamInternalId', 'confirm'], - 'lengths' => [], - 'orders' => [], + 'lengths' => [Database::LENGTH_KEY, 0], + 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC], ], ], ], diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index bb3413da5c..748211f222 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -408,8 +408,8 @@ $platformCollections = [ '$id' => ID::custom('_key_teamInternalId'), 'type' => Database::INDEX_KEY, 'attributes' => ['teamInternalId'], - 'lengths' => [], - 'orders' => [], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], ], ], ], @@ -646,8 +646,8 @@ $platformCollections = [ '$id' => ID::custom('_key_project_id'), 'type' => Database::INDEX_KEY, 'attributes' => ['projectId'], - 'lengths' => [], - 'orders' => [], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], ], ], ], @@ -1026,8 +1026,8 @@ $platformCollections = [ '$id' => ID::custom('_key_project_id'), 'type' => Database::INDEX_KEY, 'attributes' => ['projectId'], - 'lengths' => [], - 'orders' => [], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], ], ], ], From c9ad685e11352a96d3b868ff2219e7bf07223cad Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 6 May 2026 04:48:53 +0000 Subject: [PATCH 150/211] fix(indexes): use empty lengths for mixed-type composite to match existing pattern greptile flagged missing lengths but the codebase has two conventions: - all-string composite: [LENGTH_KEY, LENGTH_KEY] (_key_unique, _key_provider_providerUid) - mixed/non-string composite: [] (e.g. ('enabled', 'type'), ('region', 'accessedAt'), ('targetInternalId', 'topicInternalId'), ('period', 'time'), ('metric', 'period', 'time')) (teamInternalId, confirm) is string+boolean; closest match is ('enabled', 'type') which uses lengths => [] and orders => []. Aligning to that established pattern instead of inventing [LENGTH_KEY, 0]. --- app/config/collections/common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/config/collections/common.php b/app/config/collections/common.php index 8b5d623185..37fbcc8ca3 100644 --- a/app/config/collections/common.php +++ b/app/config/collections/common.php @@ -1527,8 +1527,8 @@ return [ '$id' => ID::custom('_key_team_confirm'), 'type' => Database::INDEX_KEY, 'attributes' => ['teamInternalId', 'confirm'], - 'lengths' => [Database::LENGTH_KEY, 0], - 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC], + 'lengths' => [], + 'orders' => [], ], ], ], From 03f7b62ff1a18a5adf3da1848af8d1eed1dbbe11 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 6 May 2026 11:24:22 +0530 Subject: [PATCH 151/211] refactor: update database version constraints and simplify bigint handling in collection creation Co-authored-by: Copilot --- composer.json | 4 +- composer.lock | 41 ++++++++----------- .../Http/Databases/Collections/Create.php | 20 +++------ 3 files changed, 24 insertions(+), 41 deletions(-) diff --git a/composer.json b/composer.json index f9c1072108..0138ad4f57 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "utopia-php/compression": "0.1.*", "utopia-php/config": "1.*", "utopia-php/console": "0.1.*", - "utopia-php/database": "dev-big-init as 5.7", + "utopia-php/database": "5.*", "utopia-php/agents": "1.*", "utopia-php/detector": "0.2.*", "utopia-php/domains": "1.*", @@ -74,7 +74,7 @@ "utopia-php/locale": "0.8.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.22.*", - "utopia-php/migration": "1.9.*", + "utopia-php/migration": "1.*", "utopia-php/platform": "0.13.*", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", diff --git a/composer.lock b/composer.lock index eb6212a620..9b88cedefc 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": "29610e3ef365af01d018077f2638ffb3", + "content-hash": "4440b62bc2eb25841157914c2b91b087", "packages": [ { "name": "adhocore/jwt", @@ -3850,16 +3850,16 @@ }, { "name": "utopia-php/database", - "version": "dev-big-init", + "version": "5.7.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "ee8895a3ae835978fa4eb143619e4950e7001648" + "reference": "eb35e68f7f90932d5a60bd72e70158ae7a4e0511" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/ee8895a3ae835978fa4eb143619e4950e7001648", - "reference": "ee8895a3ae835978fa4eb143619e4950e7001648", + "url": "https://api.github.com/repos/utopia-php/database/zipball/eb35e68f7f90932d5a60bd72e70158ae7a4e0511", + "reference": "eb35e68f7f90932d5a60bd72e70158ae7a4e0511", "shasum": "" }, "require": { @@ -3904,9 +3904,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/big-init" + "source": "https://github.com/utopia-php/database/tree/5.7.0" }, - "time": "2026-05-05T13:27:52+00:00" + "time": "2026-05-06T01:04:08+00:00" }, { "name": "utopia-php/detector", @@ -4531,16 +4531,16 @@ }, { "name": "utopia-php/migration", - "version": "1.9.6", + "version": "1.10.0", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "b164631404ec759f8c368fe2321f44c22bc258ab" + "reference": "55f4863d690e775f44fec3cae4bd1f4491fed5ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/b164631404ec759f8c368fe2321f44c22bc258ab", - "reference": "b164631404ec759f8c368fe2321f44c22bc258ab", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/55f4863d690e775f44fec3cae4bd1f4491fed5ea", + "reference": "55f4863d690e775f44fec3cae4bd1f4491fed5ea", "shasum": "" }, "require": { @@ -4549,7 +4549,7 @@ "ext-openssl": "*", "halaxa/json-machine": "^1.2", "php": ">=8.1", - "utopia-php/database": "dev-big-init as 5.4", + "utopia-php/database": "5.*", "utopia-php/dsn": "0.2.*", "utopia-php/storage": "2.*" }, @@ -4580,9 +4580,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.9.6" + "source": "https://github.com/utopia-php/migration/tree/1.10.0" }, - "time": "2026-04-30T08:11:07+00:00" + "time": "2026-05-06T04:35:32+00:00" }, { "name": "utopia-php/mongo", @@ -8444,18 +8444,9 @@ "time": "2024-11-07T12:36:22+00:00" } ], - "aliases": [ - { - "package": "utopia-php/database", - "version": "dev-big-init", - "alias": "5.7", - "alias_normalized": "5.7.0.0" - } - ], + "aliases": [], "minimum-stability": "dev", - "stability-flags": { - "utopia-php/database": 20 - }, + "stability-flags": {}, "prefer-stable": true, "prefer-lowest": false, "platform": { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index 32c311b10a..3a53a49579 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -276,13 +276,7 @@ class Create extends Action ): array { $key = $attribute['key']; $type = $attribute['type']; - switch ($type) { - case Database::VAR_BIGINT: - $size = 8; - break; - default: - $size = $attribute['size'] ?? 0; - } + $size = $attribute['size'] ?? 0; $required = $attribute['required'] ?? false; $signed = $attribute['signed'] ?? true; $array = $attribute['array'] ?? false; @@ -296,13 +290,11 @@ class Create extends Action } if (isset($attribute['min']) || isset($attribute['max'])) { - if ($type === Database::VAR_INTEGER) { - $format = APP_DATABASE_ATTRIBUTE_INT_RANGE; - } elseif ($type === Database::VAR_BIGINT) { - $format = APP_DATABASE_ATTRIBUTE_BIGINT_RANGE; - } else { - $format = APP_DATABASE_ATTRIBUTE_FLOAT_RANGE; - } + $format = match($type) { + Database::VAR_INTEGER => APP_DATABASE_ATTRIBUTE_INT_RANGE, + Database::VAR_BIGINT => APP_DATABASE_ATTRIBUTE_BIGINT_RANGE, + default => APP_DATABASE_ATTRIBUTE_FLOAT_RANGE, + }; $formatOptions = [ 'min' => $attribute['min'] ?? ($type === Database::VAR_INTEGER || $type === Database::VAR_BIGINT ? \PHP_INT_MIN : -\PHP_FLOAT_MAX), From 93ce542d31b370208988015cb2beb0c429e9dc5d Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 6 May 2026 11:37:05 +0530 Subject: [PATCH 152/211] updated composer --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 0138ad4f57..dac5be561f 100644 --- a/composer.json +++ b/composer.json @@ -52,6 +52,7 @@ "appwrite/php-runtimes": "0.20.*", "appwrite/php-clamav": "2.0.*", "utopia-php/abuse": "1.2.*", + "utopia-php/agents": "1.2.*", "utopia-php/analytics": "0.15.*", "utopia-php/audit": "2.2.*", "utopia-php/auth": "0.5.*", @@ -61,7 +62,6 @@ "utopia-php/config": "1.*", "utopia-php/console": "0.1.*", "utopia-php/database": "5.*", - "utopia-php/agents": "1.*", "utopia-php/detector": "0.2.*", "utopia-php/domains": "1.*", "utopia-php/emails": "0.6.*", diff --git a/composer.lock b/composer.lock index 9b88cedefc..64c703cf2d 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": "4440b62bc2eb25841157914c2b91b087", + "content-hash": "67c7d160c4a122b14eaa235d2417ea60", "packages": [ { "name": "adhocore/jwt", @@ -3403,16 +3403,16 @@ }, { "name": "utopia-php/agents", - "version": "1.3.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/utopia-php/agents.git", - "reference": "06064fd9fb19b77ae45a12ec7bcbc17670912c30" + "reference": "052227953678a30ecc4b5467401fcb0b2386471e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/agents/zipball/06064fd9fb19b77ae45a12ec7bcbc17670912c30", - "reference": "06064fd9fb19b77ae45a12ec7bcbc17670912c30", + "url": "https://api.github.com/repos/utopia-php/agents/zipball/052227953678a30ecc4b5467401fcb0b2386471e", + "reference": "052227953678a30ecc4b5467401fcb0b2386471e", "shasum": "" }, "require": { @@ -3450,9 +3450,9 @@ ], "support": { "issues": "https://github.com/utopia-php/agents/issues", - "source": "https://github.com/utopia-php/agents/tree/1.3.0" + "source": "https://github.com/utopia-php/agents/tree/1.2.1" }, - "time": "2026-03-26T03:51:11+00:00" + "time": "2026-02-24T06:03:55+00:00" }, { "name": "utopia-php/analytics", From fc918d8b3c3945a8a1223e7a663c759e7960e71f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 6 May 2026 11:48:47 +0530 Subject: [PATCH 153/211] feat: add support for unsigned integer and bigint columns in database tests Co-authored-by: Copilot --- .../TablesDB/DatabasesNumericTypesTest.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php b/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php index 0e46d9466c..4280bfece9 100644 --- a/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php +++ b/tests/e2e/Services/TablesDB/DatabasesNumericTypesTest.php @@ -80,6 +80,26 @@ class DatabasesNumericTypesTest extends Scope 'default' => 9007199254740000, ]); + // Create unsigned integer column + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer', $headers, [ + 'key' => 'unsigned_int_field', + 'required' => false, + 'min' => 0, + 'max' => 100, + 'default' => 0, + 'signed' => false, + ]); + + // Create unsigned bigint column + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/bigint', $headers, [ + 'key' => 'unsigned_bigint_field', + 'required' => false, + 'min' => 0, + 'max' => 9223372036854775807, + 'default' => 0, + 'signed' => false, + ]); + // Cache before waiting so that if waitForAllAttributes times out, // subsequent calls don't try to re-create the same columns (causing 409) self::$setupCache[$cacheKey] = [ @@ -144,6 +164,22 @@ class DatabasesNumericTypesTest extends Scope 'default' => 9007199254740000, ]); + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/integer', $headers, [ + 'key' => 'unsigned_int_field', + 'required' => false, + 'max' => 100, + 'default' => 0, + 'signed' => false, + ]); + + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/bigint', $headers, [ + 'key' => 'unsigned_bigint_field', + 'required' => false, + 'max' => 9223372036854775807, + 'default' => 0, + 'signed' => false, + ]); + $this->waitForAllAttributes($databaseId, $tableId); return [ @@ -218,6 +254,45 @@ class DatabasesNumericTypesTest extends Scope $this->assertEquals(9007199254740000, $bigintColumn['body']['default']); } + public function testGetUnsignedIntegerAndBigIntColumns(): void + { + $data = $this->setupDatabaseAndTable(); + $databaseId = $data['databaseId']; + $tableId = $data['tableId']; + + $unsignedIntColumn = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/unsigned_int_field', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(200, $unsignedIntColumn['headers']['status-code']); + $this->assertEquals('unsigned_int_field', $unsignedIntColumn['body']['key']); + $this->assertEquals('integer', $unsignedIntColumn['body']['type']); + $this->assertEquals(false, $unsignedIntColumn['body']['required']); + $this->assertEquals(false, $unsignedIntColumn['body']['array']); + $this->assertEquals(false, $unsignedIntColumn['body']['signed']); + $this->assertEquals(0, $unsignedIntColumn['body']['min']); + $this->assertEquals(100, $unsignedIntColumn['body']['max']); + $this->assertEquals(0, $unsignedIntColumn['body']['default']); + + $unsignedBigintColumn = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns/unsigned_bigint_field', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(200, $unsignedBigintColumn['headers']['status-code']); + $this->assertEquals('unsigned_bigint_field', $unsignedBigintColumn['body']['key']); + $this->assertEquals('bigint', $unsignedBigintColumn['body']['type']); + $this->assertEquals(false, $unsignedBigintColumn['body']['required']); + $this->assertEquals(false, $unsignedBigintColumn['body']['array']); + $this->assertEquals(false, $unsignedBigintColumn['body']['signed']); + $this->assertEquals(0, $unsignedBigintColumn['body']['min']); + $this->assertEquals(9223372036854775807, $unsignedBigintColumn['body']['max']); + $this->assertEquals(0, $unsignedBigintColumn['body']['default']); + } + public function testListColumnsWithNumericTypes(): void { $data = $this->setupDatabaseAndTable(); @@ -237,6 +312,8 @@ class DatabasesNumericTypesTest extends Scope $columnKeys = array_map(fn ($col) => $col['key'], $columns['body']['columns']); $this->assertContains('integer_field', $columnKeys); $this->assertContains('bigint_field', $columnKeys); + $this->assertContains('unsigned_int_field', $columnKeys); + $this->assertContains('unsigned_bigint_field', $columnKeys); $columnTypeByKey = []; foreach ($columns['body']['columns'] as $col) { @@ -245,6 +322,8 @@ class DatabasesNumericTypesTest extends Scope $this->assertEquals('integer', $columnTypeByKey['integer_field']); $this->assertEquals('bigint', $columnTypeByKey['bigint_field']); + $this->assertEquals('integer', $columnTypeByKey['unsigned_int_field']); + $this->assertEquals('bigint', $columnTypeByKey['unsigned_bigint_field']); } public function testCreateRowWithIntegerAndBigIntTypes(): void @@ -262,6 +341,8 @@ class DatabasesNumericTypesTest extends Scope 'data' => [ 'integer_field' => 5, 'bigint_field' => 456, + 'unsigned_int_field' => 50, + 'unsigned_bigint_field' => 9007199254740000, ], 'permissions' => [ Permission::read(Role::any()), @@ -271,6 +352,8 @@ class DatabasesNumericTypesTest extends Scope $this->assertEquals(201, $row['headers']['status-code']); $this->assertEquals(5, $row['body']['integer_field']); $this->assertEquals(456, $row['body']['bigint_field']); + $this->assertEquals(50, $row['body']['unsigned_int_field']); + $this->assertEquals(9007199254740000, $row['body']['unsigned_bigint_field']); } public function testUpdateIntegerAndBigIntColumns(): void From e63f9fd6a5784f0ebe9a063372453766dccd7161 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Wed, 6 May 2026 08:40:17 +0100 Subject: [PATCH 154/211] tests: send non-empty parent row data in TwoWayRecreate test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit server-ce 1.9.x's tablesdb POST /rows tightened input validation: the modular Documents/Create.php rejects `data => []` with a 400 "missing data" because TablesDB's Rows/Create.php inherits the strict default of getSupportForEmptyDocument() = false (only DocumentsDB overrides it to true). The test was relying on the older permissive behavior to seed an empty parent row before the relationship cascade links it. Add a non-relationship `label` string column on the parents table and populate it with `data => ['label' => 'p1']` so the POST passes the empty-data guard. The test's actual assertion target — partner-side pair-key dedup on DropAndRecreate — is unchanged. Cascade fixes: testAppwriteMigrationOverwriteAttributeRecreate and testAppwriteMigrationOverwriteSameSpecRecreate were failing in the retry pass because TwoWayRecreate's bail at L1616 left source/dest state uncleaned. Once TwoWayRecreate completes, those tests see a clean project again. Caught in CI run 25419479164 / job 74562934987 on the MongoDB (dedicated) Migrations matrix. --- .../e2e/Services/Migrations/MigrationsBase.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index fa360bfce8..387f4fe0e1 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1593,6 +1593,22 @@ trait MigrationsBase $this->assertEquals(201, $createTable['headers']['status-code']); } + // Add a non-relationship column on parents so we can POST a row with + // non-empty data. tablesdb POST /rows rejects empty data arrays in + // 1.9.x (Create.php:161 — getSupportForEmptyDocument() defaults false). + $createLabel = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/parents/columns/string', $sourceHeaders, [ + 'key' => 'label', + 'size' => 32, + 'required' => false, + ]); + $this->assertEquals(202, $createLabel['headers']['status-code']); + + $this->assertEventually(function () use ($databaseId, $sourceHeaders) { + $r = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/parents/columns/label', $sourceHeaders); + $this->assertEquals(200, $r['headers']['status-code']); + $this->assertEquals('available', $r['body']['status']); + }, 10000, 500); + $createRel = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/parents/columns/relationship', $sourceHeaders, [ 'relatedTableId' => 'children', 'type' => Database::RELATION_ONE_TO_MANY, @@ -1611,7 +1627,7 @@ trait MigrationsBase $parentRow = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/parents/rows', $sourceHeaders, [ 'rowId' => 'parent-1', - 'data' => [], + 'data' => ['label' => 'p1'], ]); $this->assertEquals(201, $parentRow['headers']['status-code']); $childRow = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/children/rows', $sourceHeaders, [ From a286b78a0bf8a486319e7fef2fb4126ba3137d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 6 May 2026 09:41:00 +0200 Subject: [PATCH 155/211] Fix function tests --- tests/e2e/Services/Functions/FunctionsConsoleClientTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php index eaf3f089e1..5d501486fd 100644 --- a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php @@ -665,7 +665,6 @@ class FunctionsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals("TESTINGVALUEUPDATED_2", $response['body']['value']); $longKey = str_repeat("A", 256); $response = $this->client->call(Client::METHOD_PUT, '/functions/' . $functionId . '/variables/' . $variableId, array_merge([ From 1ccf058c142313cd3292c710dfbeefdfbaac6565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 6 May 2026 10:19:30 +0200 Subject: [PATCH 156/211] Fix failing tests --- app/init/constants.php | 2 +- tests/e2e/Services/GraphQL/FunctionsClientTest.php | 4 ++-- tests/e2e/Services/Migrations/MigrationsBase.php | 1 + .../e2e/Services/ProjectWebhooks/WebhooksCustomServerTest.php | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/init/constants.php b/app/init/constants.php index 64635bab2a..ccf446676e 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -44,7 +44,7 @@ const APP_PROJECT_ACCESS = 24 * 60 * 60; // 24 hours const APP_RESOURCE_TOKEN_ACCESS = 24 * 60 * 60; // 24 hours const APP_FILE_ACCESS = 24 * 60 * 60; // 24 hours const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours -const APP_CACHE_BUSTER = 4324; +const APP_CACHE_BUSTER = 4325; const APP_VERSION_STABLE = '1.9.4'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; const APP_DATABASE_ATTRIBUTE_ENUM = 'enum'; diff --git a/tests/e2e/Services/GraphQL/FunctionsClientTest.php b/tests/e2e/Services/GraphQL/FunctionsClientTest.php index ed436ad075..e8e033f353 100644 --- a/tests/e2e/Services/GraphQL/FunctionsClientTest.php +++ b/tests/e2e/Services/GraphQL/FunctionsClientTest.php @@ -55,10 +55,10 @@ class FunctionsClientTest extends Scope $query = ' mutation createVariables($functionId: String!) { - var1: functionsCreateVariable(functionId: $functionId, key: "name", value: "John Doe") { + var1: functionsCreateVariable(functionId: $functionId, variableId: "unique()", key: "name", value: "John Doe") { _id } - var2: functionsCreateVariable(functionId: $functionId, key: "age", value: "42") { + var2: functionsCreateVariable(functionId: $functionId, variableId: "unique()", key: "age", value: "42") { _id } } diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 4346e5a5fa..2621240900 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -1096,6 +1096,7 @@ trait MigrationsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], + 'x-appwrite-response-format' => '1.9.3' ], [ 'key' => 'TEST_VAR', 'value' => 'test_value', diff --git a/tests/e2e/Services/ProjectWebhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/ProjectWebhooks/WebhooksCustomServerTest.php index 9085733b70..fa369cefc9 100644 --- a/tests/e2e/Services/ProjectWebhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/ProjectWebhooks/WebhooksCustomServerTest.php @@ -89,6 +89,7 @@ class WebhooksCustomServerTest extends Scope $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/variables', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-response-format' => '1.9.3', ], $this->getHeaders()), [ 'key' => 'key1', 'value' => 'value1', From d27b5788889b92bf3110241616e1b8da3e32eab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 6 May 2026 10:34:37 +0200 Subject: [PATCH 157/211] Fix more tests --- tests/e2e/Services/GraphQL/FunctionsServerTest.php | 4 ++-- .../e2e/Services/ProjectWebhooks/WebhooksCustomServerTest.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Services/GraphQL/FunctionsServerTest.php b/tests/e2e/Services/GraphQL/FunctionsServerTest.php index 572fde49bf..95b52bcbe3 100644 --- a/tests/e2e/Services/GraphQL/FunctionsServerTest.php +++ b/tests/e2e/Services/GraphQL/FunctionsServerTest.php @@ -55,10 +55,10 @@ class FunctionsServerTest extends Scope $query = ' mutation createVariables($functionId: String!) { - var1: functionsCreateVariable(functionId: $functionId, key: "name", value: "John Doe") { + var1: functionsCreateVariable(functionId: $functionId, variableId: "unique()", key: "name", value: "John Doe") { _id } - var2: functionsCreateVariable(functionId: $functionId, key: "age", value: "42") { + var2: functionsCreateVariable(functionId: $functionId, variableId: "unique()", key: "age", value: "42") { _id } } diff --git a/tests/e2e/Services/ProjectWebhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/ProjectWebhooks/WebhooksCustomServerTest.php index fa369cefc9..eb08da56f2 100644 --- a/tests/e2e/Services/ProjectWebhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/ProjectWebhooks/WebhooksCustomServerTest.php @@ -700,6 +700,7 @@ class WebhooksCustomServerTest extends Scope $variable = $this->client->call(Client::METHOD_POST, '/functions/' . $id . '/variables', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-response-format' => '1.9.3', ], $this->getHeaders()), [ 'key' => 'key1', 'value' => 'value1', From 00ee9c6b0e697e6567581bc26ce82e144181141b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 6 May 2026 11:09:11 +0200 Subject: [PATCH 158/211] Fix benchmark --- tests/benchmarks/http.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/benchmarks/http.js b/tests/benchmarks/http.js index f7bb54024d..ef42e99663 100644 --- a/tests/benchmarks/http.js +++ b/tests/benchmarks/http.js @@ -380,6 +380,7 @@ function computeFlow(ctx) { api('GET', '/functions/runtimes', null, ctx.sessionHeaders, [200], 'functions.runtimes.list'); api('GET', '/functions/specifications', null, ctx.apiHeaders, [200], 'functions.specifications.list'); const functionVariable = api('POST', `/functions/${functionId}/variables`, { + variableId: 'unique()', key: 'BENCHMARK', value: 'true', secret: false, From dcef7ef559ebf1f51604b8b2d2db3e9c165cfac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 6 May 2026 11:24:53 +0200 Subject: [PATCH 159/211] OIDC param name improvement --- .../Http/Project/OAuth2/Oidc/Update.php | 22 ++--- src/Appwrite/Utopia/Response/Filters/V25.php | 17 ++++ .../Utopia/Response/Model/OAuth2Oidc.php | 4 +- tests/e2e/Services/Project/OAuth2Base.php | 92 +++++++++---------- 4 files changed, 76 insertions(+), 59 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Oidc/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Oidc/Update.php index 9598ff4c43..697b306be8 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Oidc/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Oidc/Update.php @@ -82,13 +82,13 @@ class Update extends Base 'hint' => '', ], [ - '$id' => 'tokenUrl', + '$id' => 'tokenURL', 'name' => 'Token URL', 'example' => 'https://myoauth.com/oauth2/token', 'hint' => '', ], [ - '$id' => 'userInfoUrl', + '$id' => 'userInfoURL', 'name' => 'User Info URL', 'example' => 'https://myoauth.com/oauth2/userinfo', 'hint' => '', @@ -127,8 +127,8 @@ class Update extends Base ->param(static::getClientSecretParamName(), null, new Nullable(new Text(512, 0)), static::getClientSecretDescription(), optional: true) ->param('wellKnownURL', null, new Nullable(new URL(allowEmpty: true)), 'OpenID Connect well-known configuration URL. When provided, authorization, token, and user info endpoints can be discovered automatically. For example: https://myoauth.com/.well-known/openid-configuration', optional: true) ->param('authorizationURL', null, new Nullable(new URL(allowEmpty: true)), 'OpenID Connect authorization endpoint URL. Required when wellKnownURL is not provided. For example: https://myoauth.com/oauth2/authorize', optional: true) - ->param('tokenUrl', null, new Nullable(new URL(allowEmpty: true)), 'OpenID Connect token endpoint URL. Required when wellKnownURL is not provided. For example: https://myoauth.com/oauth2/token', optional: true) - ->param('userInfoUrl', null, new Nullable(new URL(allowEmpty: true)), 'OpenID Connect user info endpoint URL. Required when wellKnownURL is not provided. For example: https://myoauth.com/oauth2/userinfo', optional: true) + ->param('tokenURL', null, new Nullable(new URL(allowEmpty: true)), 'OpenID Connect token endpoint URL. Required when wellKnownURL is not provided. For example: https://myoauth.com/oauth2/token', optional: true, aliases: ['tokenUrl']) + ->param('userInfoURL', null, new Nullable(new URL(allowEmpty: true)), 'OpenID Connect user info endpoint URL. Required when wellKnownURL is not provided. For example: https://myoauth.com/oauth2/userinfo', optional: true, aliases: ['userInfoUrl']) ->param('enabled', null, new Nullable(new Boolean()), 'OAuth2 sign-in method status. Set to true to enable new session creation. Setting to true will trigger end-to-end credentials validation, and will throw if the credentials are invalid.', true) ->inject('response') ->inject('dbForPlatform') @@ -151,8 +151,8 @@ class Update extends Base static::getClientSecretParamName() => '', 'wellKnownURL' => $decoded['wellKnownEndpoint'] ?? '', 'authorizationURL' => $decoded['authorizationEndpoint'] ?? '', - 'tokenUrl' => $decoded['tokenEndpoint'] ?? '', - 'userInfoUrl' => $decoded['userInfoEndpoint'] ?? '', + 'tokenURL' => $decoded['tokenEndpoint'] ?? '', + 'userInfoURL' => $decoded['userInfoEndpoint'] ?? '', ]); } @@ -174,8 +174,8 @@ class Update extends Base ?string $clientSecret, ?string $wellKnownURL, ?string $authorizationURL, - ?string $tokenUrl, - ?string $userInfoUrl, + ?string $tokenURL, + ?string $userInfoURL, ?bool $enabled, Response $response, Database $dbForPlatform, @@ -201,8 +201,8 @@ class Update extends Base 'clientSecret' => $clientSecret ?? ($existing['clientSecret'] ?? ''), 'wellKnownEndpoint' => $wellKnownURL ?? ($existing['wellKnownEndpoint'] ?? ''), 'authorizationEndpoint' => $authorizationURL ?? ($existing['authorizationEndpoint'] ?? ''), - 'tokenEndpoint' => $tokenUrl ?? ($existing['tokenEndpoint'] ?? ''), - 'userInfoEndpoint' => $userInfoUrl ?? ($existing['userInfoEndpoint'] ?? ''), + 'tokenEndpoint' => $tokenURL ?? ($existing['tokenEndpoint'] ?? ''), + 'userInfoEndpoint' => $userInfoURL ?? ($existing['userInfoEndpoint'] ?? ''), ]; // When enabling, require either wellKnownEndpoint alone, or all three @@ -215,7 +215,7 @@ class Update extends Base && !empty($merged['userInfoEndpoint']); if (!$hasWellKnown && !$hasAllDiscovery) { - throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Enabling OpenID Connect requires either wellKnownURL, or all of authorizationURL, tokenUrl, and userInfoUrl.'); + throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Enabling OpenID Connect requires either wellKnownURL, or all of authorizationURL, tokenURL, and userInfoURL.'); } } diff --git a/src/Appwrite/Utopia/Response/Filters/V25.php b/src/Appwrite/Utopia/Response/Filters/V25.php index 3040ef681b..e0ce76c724 100644 --- a/src/Appwrite/Utopia/Response/Filters/V25.php +++ b/src/Appwrite/Utopia/Response/Filters/V25.php @@ -2,6 +2,7 @@ namespace Appwrite\Utopia\Response\Filters; +use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Filter; // Convert 1.9.4 Data format to 1.9.3 format @@ -10,7 +11,23 @@ class V25 extends Filter public function parse(array $content, string $model): array { return match ($model) { + Response::MODEL_OAUTH2_OIDC => $this->parseOAuth2Oidc($content), default => $content, }; } + + private function parseOAuth2Oidc(array $content): array + { + if (isset($content['tokenURL'])) { + $content['tokenUrl'] = $content['tokenURL']; + unset($content['tokenURL']); + } + + if (isset($content['userInfoURL'])) { + $content['userInfoUrl'] = $content['userInfoURL']; + unset($content['userInfoURL']); + } + + return $content; + } } diff --git a/src/Appwrite/Utopia/Response/Model/OAuth2Oidc.php b/src/Appwrite/Utopia/Response/Model/OAuth2Oidc.php index e4f0919666..0b18539423 100644 --- a/src/Appwrite/Utopia/Response/Model/OAuth2Oidc.php +++ b/src/Appwrite/Utopia/Response/Model/OAuth2Oidc.php @@ -42,13 +42,13 @@ class OAuth2Oidc extends OAuth2Base 'default' => '', 'example' => 'https://myoauth.com/oauth2/authorize', ]) - ->addRule('tokenUrl', [ + ->addRule('tokenURL', [ 'type' => self::TYPE_STRING, 'description' => 'OpenID Connect token endpoint URL.', 'default' => '', 'example' => 'https://myoauth.com/oauth2/token', ]) - ->addRule('userInfoUrl', [ + ->addRule('userInfoURL', [ 'type' => self::TYPE_STRING, 'description' => 'OpenID Connect user info endpoint URL.', 'default' => '', diff --git a/tests/e2e/Services/Project/OAuth2Base.php b/tests/e2e/Services/Project/OAuth2Base.php index a55cc559b2..5a3fa764f6 100644 --- a/tests/e2e/Services/Project/OAuth2Base.php +++ b/tests/e2e/Services/Project/OAuth2Base.php @@ -1651,8 +1651,8 @@ trait OAuth2Base $this->assertSame(200, $response['headers']['status-code']); $this->assertSame('https://idp.example.com/.well-known/openid-configuration', $response['body']['wellKnownURL']); $this->assertArrayHasKey('authorizationURL', $response['body']); - $this->assertArrayHasKey('tokenUrl', $response['body']); - $this->assertArrayHasKey('userInfoUrl', $response['body']); + $this->assertArrayHasKey('tokenURL', $response['body']); + $this->assertArrayHasKey('userInfoURL', $response['body']); // Cleanup $this->updateOAuth2('oidc', [ @@ -1660,8 +1660,8 @@ trait OAuth2Base 'clientSecret' => '', 'wellKnownURL' => '', 'authorizationURL' => '', - 'tokenUrl' => '', - 'userInfoUrl' => '', + 'tokenURL' => '', + 'userInfoURL' => '', 'enabled' => false, ]); } @@ -1672,15 +1672,15 @@ trait OAuth2Base 'clientId' => 'oidc-discovery', 'clientSecret' => 'oidc-discovery-secret', 'authorizationURL' => 'https://idp.example.com/oauth2/authorize', - 'tokenUrl' => 'https://idp.example.com/oauth2/token', - 'userInfoUrl' => 'https://idp.example.com/oauth2/userinfo', + 'tokenURL' => 'https://idp.example.com/oauth2/token', + 'userInfoURL' => 'https://idp.example.com/oauth2/userinfo', 'enabled' => false, ]); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame('https://idp.example.com/oauth2/authorize', $response['body']['authorizationURL']); - $this->assertSame('https://idp.example.com/oauth2/token', $response['body']['tokenUrl']); - $this->assertSame('https://idp.example.com/oauth2/userinfo', $response['body']['userInfoUrl']); + $this->assertSame('https://idp.example.com/oauth2/token', $response['body']['tokenURL']); + $this->assertSame('https://idp.example.com/oauth2/userinfo', $response['body']['userInfoURL']); // Cleanup $this->updateOAuth2('oidc', [ @@ -1688,8 +1688,8 @@ trait OAuth2Base 'clientSecret' => '', 'wellKnownURL' => '', 'authorizationURL' => '', - 'tokenUrl' => '', - 'userInfoUrl' => '', + 'tokenURL' => '', + 'userInfoURL' => '', 'enabled' => false, ]); } @@ -1701,8 +1701,8 @@ trait OAuth2Base 'clientSecret' => '', 'wellKnownURL' => '', 'authorizationURL' => '', - 'tokenUrl' => '', - 'userInfoUrl' => '', + 'tokenURL' => '', + 'userInfoURL' => '', 'enabled' => false, ]); @@ -1731,8 +1731,8 @@ trait OAuth2Base 'clientSecret' => '', 'wellKnownURL' => '', 'authorizationURL' => '', - 'tokenUrl' => '', - 'userInfoUrl' => '', + 'tokenURL' => '', + 'userInfoURL' => '', 'enabled' => false, ]); @@ -1740,7 +1740,7 @@ trait OAuth2Base 'clientId' => 'oidc-partial', 'clientSecret' => 'oidc-partial-secret', 'authorizationURL' => 'https://idp.example.com/oauth2/authorize', - 'tokenUrl' => 'https://idp.example.com/oauth2/token', + 'tokenURL' => 'https://idp.example.com/oauth2/token', 'enabled' => true, ]); @@ -1753,8 +1753,8 @@ trait OAuth2Base 'clientSecret' => '', 'wellKnownURL' => '', 'authorizationURL' => '', - 'tokenUrl' => '', - 'userInfoUrl' => '', + 'tokenURL' => '', + 'userInfoURL' => '', 'enabled' => false, ]); } @@ -1785,8 +1785,8 @@ trait OAuth2Base 'clientSecret' => '', 'wellKnownURL' => '', 'authorizationURL' => '', - 'tokenUrl' => '', - 'userInfoUrl' => '', + 'tokenURL' => '', + 'userInfoURL' => '', 'enabled' => false, ]); } @@ -1816,8 +1816,8 @@ trait OAuth2Base 'clientSecret' => '', 'wellKnownURL' => '', 'authorizationURL' => '', - 'tokenUrl' => '', - 'userInfoUrl' => '', + 'tokenURL' => '', + 'userInfoURL' => '', 'enabled' => false, ]); } @@ -1831,8 +1831,8 @@ trait OAuth2Base 'clientSecret' => '', 'wellKnownURL' => '', 'authorizationURL' => '', - 'tokenUrl' => '', - 'userInfoUrl' => '', + 'tokenURL' => '', + 'userInfoURL' => '', 'enabled' => false, ]); @@ -1841,7 +1841,7 @@ trait OAuth2Base 'clientId' => 'oidc-split-discovery', 'clientSecret' => 'oidc-split-discovery-secret', 'authorizationURL' => 'https://idp.example.com/oauth2/authorize', - 'tokenUrl' => 'https://idp.example.com/oauth2/token', + 'tokenURL' => 'https://idp.example.com/oauth2/token', 'enabled' => false, ]); @@ -1849,19 +1849,19 @@ trait OAuth2Base // state must include the two stored URLs + the new one to satisfy // the all-three-discovery-URLs branch of the enable check. $enable = $this->updateOAuth2('oidc', [ - 'userInfoUrl' => 'https://idp.example.com/oauth2/userinfo', + 'userInfoURL' => 'https://idp.example.com/oauth2/userinfo', 'enabled' => true, ]); $this->assertSame(200, $enable['headers']['status-code']); $this->assertTrue($enable['body']['enabled']); // Confirm all three URLs ended up persisted (merge wrote the new - // userInfoUrl while preserving the previously stored two). + // userInfoURL while preserving the previously stored two). $get = $this->getOAuth2Provider('oidc'); $this->assertSame(200, $get['headers']['status-code']); $this->assertSame('https://idp.example.com/oauth2/authorize', $get['body']['authorizationURL']); - $this->assertSame('https://idp.example.com/oauth2/token', $get['body']['tokenUrl']); - $this->assertSame('https://idp.example.com/oauth2/userinfo', $get['body']['userInfoUrl']); + $this->assertSame('https://idp.example.com/oauth2/token', $get['body']['tokenURL']); + $this->assertSame('https://idp.example.com/oauth2/userinfo', $get['body']['userInfoURL']); // Cleanup $this->updateOAuth2('oidc', [ @@ -1869,8 +1869,8 @@ trait OAuth2Base 'clientSecret' => '', 'wellKnownURL' => '', 'authorizationURL' => '', - 'tokenUrl' => '', - 'userInfoUrl' => '', + 'tokenURL' => '', + 'userInfoURL' => '', 'enabled' => false, ]); } @@ -1883,8 +1883,8 @@ trait OAuth2Base 'clientSecret' => 'oidc-clear-then-enable-secret', 'wellKnownURL' => 'https://idp.example.com/.well-known/openid-configuration', 'authorizationURL' => '', - 'tokenUrl' => '', - 'userInfoUrl' => '', + 'tokenURL' => '', + 'userInfoURL' => '', 'enabled' => false, ]); @@ -1907,8 +1907,8 @@ trait OAuth2Base 'clientSecret' => '', 'wellKnownURL' => '', 'authorizationURL' => '', - 'tokenUrl' => '', - 'userInfoUrl' => '', + 'tokenURL' => '', + 'userInfoURL' => '', 'enabled' => false, ]); } @@ -1929,16 +1929,16 @@ trait OAuth2Base $switch = $this->updateOAuth2('oidc', [ 'wellKnownURL' => '', 'authorizationURL' => 'https://idp.example.com/oauth2/authorize', - 'tokenUrl' => 'https://idp.example.com/oauth2/token', - 'userInfoUrl' => 'https://idp.example.com/oauth2/userinfo', + 'tokenURL' => 'https://idp.example.com/oauth2/token', + 'userInfoURL' => 'https://idp.example.com/oauth2/userinfo', 'enabled' => true, ]); $this->assertSame(200, $switch['headers']['status-code']); $this->assertTrue($switch['body']['enabled']); $this->assertSame('', $switch['body']['wellKnownURL']); $this->assertSame('https://idp.example.com/oauth2/authorize', $switch['body']['authorizationURL']); - $this->assertSame('https://idp.example.com/oauth2/token', $switch['body']['tokenUrl']); - $this->assertSame('https://idp.example.com/oauth2/userinfo', $switch['body']['userInfoUrl']); + $this->assertSame('https://idp.example.com/oauth2/token', $switch['body']['tokenURL']); + $this->assertSame('https://idp.example.com/oauth2/userinfo', $switch['body']['userInfoURL']); // Cleanup $this->updateOAuth2('oidc', [ @@ -1946,8 +1946,8 @@ trait OAuth2Base 'clientSecret' => '', 'wellKnownURL' => '', 'authorizationURL' => '', - 'tokenUrl' => '', - 'userInfoUrl' => '', + 'tokenURL' => '', + 'userInfoURL' => '', 'enabled' => false, ]); } @@ -1961,23 +1961,23 @@ trait OAuth2Base 'clientSecret' => 'oidc-clear-secret', 'wellKnownURL' => 'https://idp.example.com/.well-known/openid-configuration', 'authorizationURL' => 'https://idp.example.com/oauth2/authorize', - 'tokenUrl' => 'https://idp.example.com/oauth2/token', - 'userInfoUrl' => 'https://idp.example.com/oauth2/userinfo', + 'tokenURL' => 'https://idp.example.com/oauth2/token', + 'userInfoURL' => 'https://idp.example.com/oauth2/userinfo', 'enabled' => false, ]); $response = $this->updateOAuth2('oidc', [ 'wellKnownURL' => '', 'authorizationURL' => '', - 'tokenUrl' => '', - 'userInfoUrl' => '', + 'tokenURL' => '', + 'userInfoURL' => '', ]); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame('', $response['body']['wellKnownURL']); $this->assertSame('', $response['body']['authorizationURL']); - $this->assertSame('', $response['body']['tokenUrl']); - $this->assertSame('', $response['body']['userInfoUrl']); + $this->assertSame('', $response['body']['tokenURL']); + $this->assertSame('', $response['body']['userInfoURL']); // Cleanup $this->updateOAuth2('oidc', [ From 389146c6256bb48106e9e2aaa3f15d44e2309273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 6 May 2026 11:32:00 +0200 Subject: [PATCH 160/211] oidc backwards compatibiltiy test --- tests/e2e/Services/Project/OAuth2Base.php | 90 +++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tests/e2e/Services/Project/OAuth2Base.php b/tests/e2e/Services/Project/OAuth2Base.php index 5a3fa764f6..47d92a2a58 100644 --- a/tests/e2e/Services/Project/OAuth2Base.php +++ b/tests/e2e/Services/Project/OAuth2Base.php @@ -1987,6 +1987,96 @@ trait OAuth2Base ]); } + public function testUpdateOAuth2OidcBackwardCompatibleResponseFormat(): void + { + // Reset to clean state + $this->updateOAuth2('oidc', [ + 'clientId' => '', + 'clientSecret' => '', + 'wellKnownURL' => '', + 'authorizationURL' => '', + 'tokenURL' => '', + 'userInfoURL' => '', + 'enabled' => false, + ]); + + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-response-format' => '1.9.3', + ]; + $headers = \array_merge($headers, $this->getHeaders()); + + // Update using OLD param names (aliases must still work) + $response = $this->client->call( + Client::METHOD_PATCH, + '/project/oauth2/oidc', + $headers, + [ + 'clientId' => 'oidc-compat-client', + 'clientSecret' => 'oidc-compat-secret', + 'tokenUrl' => 'https://idp.example.com/oauth2/token', + 'userInfoUrl' => 'https://idp.example.com/oauth2/userinfo', + 'enabled' => false, + ], + ); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertArrayHasKey('tokenUrl', $response['body']); + $this->assertArrayHasKey('userInfoUrl', $response['body']); + $this->assertArrayNotHasKey('tokenURL', $response['body']); + $this->assertArrayNotHasKey('userInfoURL', $response['body']); + $this->assertSame('https://idp.example.com/oauth2/token', $response['body']['tokenUrl']); + $this->assertSame('https://idp.example.com/oauth2/userinfo', $response['body']['userInfoUrl']); + + // GET with 1.9.3 format must also return old param names + $get = $this->client->call( + Client::METHOD_GET, + '/project/oauth2/oidc', + $headers, + ); + + $this->assertSame(200, $get['headers']['status-code']); + $this->assertArrayHasKey('tokenUrl', $get['body']); + $this->assertArrayHasKey('userInfoUrl', $get['body']); + $this->assertArrayNotHasKey('tokenURL', $get['body']); + $this->assertArrayNotHasKey('userInfoURL', $get['body']); + $this->assertSame('https://idp.example.com/oauth2/token', $get['body']['tokenUrl']); + $this->assertSame('https://idp.example.com/oauth2/userinfo', $get['body']['userInfoUrl']); + + // LIST with 1.9.3 format must also return old param names for OIDC + $list = $this->client->call( + Client::METHOD_GET, + '/project/oauth2', + $headers, + ); + + $this->assertSame(200, $list['headers']['status-code']); + $oidcEntry = null; + foreach ($list['body']['providers'] as $provider) { + if ($provider['$id'] === 'oidc') { + $oidcEntry = $provider; + break; + } + } + $this->assertNotNull($oidcEntry, 'OIDC provider missing from listOAuth2Providers response'); + $this->assertArrayHasKey('tokenUrl', $oidcEntry); + $this->assertArrayHasKey('userInfoUrl', $oidcEntry); + $this->assertArrayNotHasKey('tokenURL', $oidcEntry); + $this->assertArrayNotHasKey('userInfoURL', $oidcEntry); + $this->assertSame('https://idp.example.com/oauth2/token', $oidcEntry['tokenUrl']); + $this->assertSame('https://idp.example.com/oauth2/userinfo', $oidcEntry['userInfoUrl']); + + // Cleanup + $this->updateOAuth2('oidc', [ + 'clientId' => '', + 'clientSecret' => '', + 'tokenURL' => '', + 'userInfoURL' => '', + 'enabled' => false, + ]); + } + // ========================================================================= // Update Okta (clientId + clientSecret + optional domain/authServer) // ========================================================================= From 140cbb633d008c3d1e3d66adeaa264b5027bb2ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 6 May 2026 11:45:35 +0200 Subject: [PATCH 161/211] Fix tests --- src/Appwrite/Utopia/Response/Filters/V25.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Appwrite/Utopia/Response/Filters/V25.php b/src/Appwrite/Utopia/Response/Filters/V25.php index e0ce76c724..e445843b51 100644 --- a/src/Appwrite/Utopia/Response/Filters/V25.php +++ b/src/Appwrite/Utopia/Response/Filters/V25.php @@ -12,6 +12,7 @@ class V25 extends Filter { return match ($model) { Response::MODEL_OAUTH2_OIDC => $this->parseOAuth2Oidc($content), + Response::MODEL_OAUTH2_PROVIDER_LIST => $this->handleList($content, 'providers', fn ($item) => $this->parseOAuth2Oidc($item)), default => $content, }; } From a65c6136f45cec9f3fc1d85a36159a47e2781709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 6 May 2026 12:08:02 +0200 Subject: [PATCH 162/211] Improve code quality --- src/Appwrite/Utopia/Response/Filters/V25.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response/Filters/V25.php b/src/Appwrite/Utopia/Response/Filters/V25.php index e445843b51..bda98ed0d8 100644 --- a/src/Appwrite/Utopia/Response/Filters/V25.php +++ b/src/Appwrite/Utopia/Response/Filters/V25.php @@ -12,7 +12,7 @@ class V25 extends Filter { return match ($model) { Response::MODEL_OAUTH2_OIDC => $this->parseOAuth2Oidc($content), - Response::MODEL_OAUTH2_PROVIDER_LIST => $this->handleList($content, 'providers', fn ($item) => $this->parseOAuth2Oidc($item)), + Response::MODEL_OAUTH2_PROVIDER_LIST => $this->handleList($content, 'providers', fn ($item) => ($item['$id'] ?? null) === 'oidc' ? $this->parseOAuth2Oidc($item) : $item), default => $content, }; } From b094993f77b9f7036ff863cb5c8ff0b741dc9506 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Wed, 6 May 2026 12:34:50 +0100 Subject: [PATCH 163/211] spike: convert worker throws to AppwriteException + isPublishable gate --- app/config/errors.php | 20 ++++++++++++++++++ src/Appwrite/Extend/Exception.php | 4 ++++ src/Appwrite/Platform/Workers/Migrations.php | 22 ++++++++++++++------ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index fa112bcb6f..08cc497b3f 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -1236,6 +1236,26 @@ return [ 'description' => 'The specified database type is not supported for CSV import or export operations.', 'code' => 400, ], + Exception::MIGRATION_SOURCE_PROJECT_ID_REQUIRED => [ + 'name' => Exception::MIGRATION_SOURCE_PROJECT_ID_REQUIRED, + 'description' => 'A source projectId is required for Appwrite migrations. Provide it in the migration credentials.', + 'code' => 400, + ], + Exception::MIGRATION_SOURCE_PROJECT_NOT_FOUND => [ + 'name' => Exception::MIGRATION_SOURCE_PROJECT_NOT_FOUND, + 'description' => 'The source project for the provided projectId was not found. Verify the projectId and the API key has access to it.', + 'code' => 404, + ], + Exception::MIGRATION_SOURCE_TYPE_INVALID => [ + 'name' => Exception::MIGRATION_SOURCE_TYPE_INVALID, + 'description' => 'The migration source type is invalid. Use one of the supported source types.', + 'code' => 400, + ], + Exception::MIGRATION_DESTINATION_TYPE_INVALID => [ + 'name' => Exception::MIGRATION_DESTINATION_TYPE_INVALID, + 'description' => 'The migration destination type is invalid. Use one of the supported destination types.', + 'code' => 400, + ], /** Realtime */ Exception::REALTIME_MESSAGE_FORMAT_INVALID => [ diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 6fc3e88635..54ee4069d1 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -346,6 +346,10 @@ class Exception extends \Exception public const string MIGRATION_IN_PROGRESS = 'migration_in_progress'; public const string MIGRATION_PROVIDER_ERROR = 'migration_provider_error'; public const string MIGRATION_DATABASE_TYPE_UNSUPPORTED = 'migration_database_type_unsupported'; + public const string MIGRATION_SOURCE_PROJECT_ID_REQUIRED = 'migration_source_project_id_required'; + public const string MIGRATION_SOURCE_PROJECT_NOT_FOUND = 'migration_source_project_not_found'; + public const string MIGRATION_SOURCE_TYPE_INVALID = 'migration_source_type_invalid'; + public const string MIGRATION_DESTINATION_TYPE_INVALID = 'migration_destination_type_invalid'; /** Realtime */ public const string REALTIME_MESSAGE_FORMAT_INVALID = 'realtime_message_format_invalid'; diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index f5cc57a6c2..f37571d2b0 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -196,13 +196,13 @@ class Migrations extends Action $projectDB = null; $useAppwriteApiSource = false; if ($source === SourceAppwrite::getName() && empty($credentials['projectId'])) { - throw new MigrationException('', '', message: 'Source projectId is required for Appwrite migrations', code: MigrationException::CODE_VALIDATION); + throw new Exception(Exception::MIGRATION_SOURCE_PROJECT_ID_REQUIRED); } if (! empty($credentials['projectId'])) { $this->sourceProject = $this->dbForPlatform->getDocument('projects', $credentials['projectId']); if ($this->sourceProject->isEmpty()) { - throw new MigrationException('', '', message: 'Source project not found for provided projectId', code: MigrationException::CODE_NOT_FOUND); + throw new Exception(Exception::MIGRATION_SOURCE_PROJECT_NOT_FOUND); } $sourceRegion = $this->sourceProject->getAttribute('region', 'default'); @@ -265,7 +265,7 @@ class Migrations extends Action $this->deviceForMigrations, $this->dbForProject, ), - default => throw new MigrationException('', '', message: 'Invalid source type', code: MigrationException::CODE_VALIDATION), + default => throw new Exception(Exception::MIGRATION_SOURCE_TYPE_INVALID), }; $resources = $migration->getAttribute('resources', []); @@ -310,7 +310,7 @@ class Migrations extends Action $options['filename'], $options['columns'] ?? [], ), - default => throw new MigrationException('', '', message: 'Invalid destination type', code: MigrationException::CODE_VALIDATION), + default => throw new Exception(Exception::MIGRATION_DESTINATION_TYPE_INVALID), }; } @@ -538,8 +538,18 @@ class Migrations extends Action $caughtError = $th; - // MigrationException is reserved for user-facing failures and stays in the migration report only. - if (!$th instanceof MigrationException) { + // Mirror general.php's HTTP-error pattern: typed AppwriteException uses its + // registry-driven isPublishable() flag; library-thrown Migration\Exception is + // always user-facing; anything else falls back to the code heuristic. + if ($th instanceof Exception) { + $publish = $th->isPublishable(); + } elseif ($th instanceof MigrationException) { + $publish = false; + } else { + $publish = $th->getCode() === 0 || $th->getCode() >= 500; + } + + if ($publish) { call_user_func($this->logError, $th, 'appwrite-worker', 'appwrite-queue-' . self::getName(), [ 'migrationId' => $migration->getId(), 'source' => $migration->getAttribute('source') ?? '', From d2b551cd122bbce9388c3a6e298f82403cd9386b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 6 May 2026 15:50:18 +0200 Subject: [PATCH 164/211] Fix refreshing nonoauth sessions --- app/controllers/api/account.php | 4 +- .../Account/AccountCustomClientTest.php | 68 +++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index c6a5fd6f97..a3060c16c5 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -830,11 +830,11 @@ Http::patch('/v1/account/sessions/:sessionId') $refreshToken = $session->getAttribute('providerRefreshToken', ''); $oAuthProviders = Config::getParam('oAuthProviders') ?? []; $className = $oAuthProviders[$provider]['class'] ?? null; - if (!empty($provider) && ($className === null || !\class_exists($className))) { + if (!empty($refreshToken) && ($className === null || !\class_exists($className))) { throw new Exception(Exception::PROJECT_PROVIDER_UNSUPPORTED); } - if (!empty($provider) && \class_exists($className)) { + if (\class_exists($className)) { $appId = $project->getAttribute('oAuthProviders', [])[$provider . 'Appid'] ?? ''; $appSecret = $project->getAttribute('oAuthProviders', [])[$provider . 'Secret'] ?? '{}'; diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index da788c3caa..671937e704 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -4163,4 +4163,72 @@ class AccountCustomClientTest extends Scope $this->assertEquals(401, $verification3['headers']['status-code']); } + + public function testRefreshEmailPasswordSession(): void + { + $email = uniqid() . 'user@localhost.test'; + + $account = $this->client->call(Client::METHOD_POST, '/account', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'userId' => ID::unique(), + 'email' => $email, + 'password' => 'password', + ]); + + $this->assertEquals(201, $account['headers']['status-code']); + + $session = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'email' => $email, + 'password' => 'password', + ]); + + $this->assertEquals(201, $session['headers']['status-code']); + $this->assertNotEmpty($session['body']['$id']); + + $sessionId = $session['body']['$id']; + $cookie = 'a_session_' . $this->getProject()['$id'] . '=' .$session['cookies']['a_session_' . $this->getProject()['$id']]; + + $session = $this->client->call(Client::METHOD_GET, '/account/sessions/current', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => $cookie, + ])); + + $this->assertEquals(200, $session['headers']['status-code']); + $this->assertNotEmpty($session['body']['expire']); + $expiryBefore = $session['body']['expire']; + + \sleep(3); // Small delay to ensure expiry an expand + + $session = $this->client->call(Client::METHOD_PATCH, '/account/sessions/' . $sessionId, array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => $cookie, + ])); + + $this->assertEquals(200, $session['headers']['status-code']); + $this->assertNotEmpty($session['body']['expire']); + $expiryAfter = $session['body']['expire']; + + $this->assertGreaterThan($expiryAfter, $expiryBefore); + + $session = $this->client->call(Client::METHOD_GET, '/account/sessions/current', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => $cookie, + ])); + + $this->assertEquals(200, $session['headers']['status-code']); + $this->assertEquals($expiryAfter, $session['body']['expire']); + } } From a9dd957a7affca5730af3dd10b82ec3f7da09442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 6 May 2026 15:57:25 +0200 Subject: [PATCH 165/211] Fix test --- tests/e2e/Services/Account/AccountCustomClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index 671937e704..0fe0f31b4f 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -4229,6 +4229,6 @@ class AccountCustomClientTest extends Scope ])); $this->assertEquals(200, $session['headers']['status-code']); - $this->assertEquals($expiryAfter, $session['body']['expire']); + $this->assertEquals(\strtotime($expiryAfter), \strtotime($session['body']['expire'])); } } From e834a95213de38cc97f2ed12640089d2c6c42f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 6 May 2026 16:21:50 +0200 Subject: [PATCH 166/211] PR review improvements --- app/controllers/api/account.php | 2 +- tests/e2e/Services/Account/AccountCustomClientTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index a3060c16c5..65fd0bfb83 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -834,7 +834,7 @@ Http::patch('/v1/account/sessions/:sessionId') throw new Exception(Exception::PROJECT_PROVIDER_UNSUPPORTED); } - if (\class_exists($className)) { + if ($className !== null && \class_exists($className)) { $appId = $project->getAttribute('oAuthProviders', [])[$provider . 'Appid'] ?? ''; $appSecret = $project->getAttribute('oAuthProviders', [])[$provider . 'Secret'] ?? '{}'; diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index 0fe0f31b4f..160ee39e21 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -4219,7 +4219,7 @@ class AccountCustomClientTest extends Scope $this->assertNotEmpty($session['body']['expire']); $expiryAfter = $session['body']['expire']; - $this->assertGreaterThan($expiryAfter, $expiryBefore); + $this->assertGreaterThan(\strtotime($expiryBefore), \strtotime($expiryAfter)); $session = $this->client->call(Client::METHOD_GET, '/account/sessions/current', array_merge([ 'origin' => 'http://localhost', From 8201fea9efab00598d2fa710cb73ceac1d469ca0 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 6 May 2026 15:50:36 +0100 Subject: [PATCH 167/211] Differentiate executor timeouts for builds, sync, and async executions Adds Executor\Exception\Timeout (with timeoutSeconds) and translates it at each call site into BUILD_TIMEOUT, FUNCTION_SYNCHRONOUS_TIMEOUT, or FUNCTION_ASYNCHRONOUS_TIMEOUT instead of always using the misleading sync function error. Build timeouts now append to streamed buildLogs rather than replacing them, and the build worker reports its timeout via Span. --- app/config/errors.php | 10 +++++ app/controllers/general.php | 45 ++++++++++--------- src/Appwrite/Extend/Exception.php | 2 + .../Functions/Http/Executions/Create.php | 43 ++++++++++-------- .../Modules/Functions/Workers/Builds.php | 20 ++++++--- src/Appwrite/Platform/Workers/Functions.php | 41 +++++++++-------- src/Executor/Exception.php | 7 +++ src/Executor/Exception/Timeout.php | 23 ++++++++++ src/Executor/Executor.php | 18 ++++---- 9 files changed, 136 insertions(+), 73 deletions(-) create mode 100644 src/Executor/Exception.php create mode 100644 src/Executor/Exception/Timeout.php diff --git a/app/config/errors.php b/app/config/errors.php index fa112bcb6f..0293be3212 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -623,6 +623,11 @@ return [ 'description' => 'Synchronous function execution timed out. Use asynchronous execution instead, or ensure the execution duration doesn\'t exceed 30 seconds.', 'code' => 408, ], + Exception::FUNCTION_ASYNCHRONOUS_TIMEOUT => [ + 'name' => Exception::FUNCTION_ASYNCHRONOUS_TIMEOUT, + 'description' => 'Asynchronous function execution timed out. Ensure the execution duration doesn\'t exceed the configured function timeout.', + 'code' => 408, + ], Exception::FUNCTION_TEMPLATE_NOT_FOUND => [ 'name' => Exception::FUNCTION_TEMPLATE_NOT_FOUND, 'description' => 'Function Template with the requested ID could not be found.', @@ -687,6 +692,11 @@ return [ 'description' => 'Build with the requested ID failed. Please check the logs for more information.', 'code' => 400, ], + Exception::BUILD_TIMEOUT => [ + 'name' => Exception::BUILD_TIMEOUT, + 'description' => 'Build timed out. Increase the build timeout via the `_APP_COMPUTE_BUILD_TIMEOUT` environment variable, or simplify the build to complete within the limit.', + 'code' => 408, + ], /** Deployments */ Exception::DEPLOYMENT_NOT_FOUND => [ diff --git a/app/controllers/general.php b/app/controllers/general.php index 21bcded22c..bc63d200d7 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -41,6 +41,7 @@ use Appwrite\Utopia\Response\Filters\V23 as ResponseV23; use Appwrite\Utopia\Response\Filters\V24 as ResponseV24; use Appwrite\Utopia\Response\Filters\V25 as ResponseV25; use Appwrite\Utopia\View; +use Executor\Exception\Timeout as ExecutorTimeout; use Executor\Executor; use MaxMind\Db\Reader; use Swoole\Http\Request as SwooleRequest; @@ -581,26 +582,30 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S 'site' => '', }; - $executionResponse = $executor->createExecution( - projectId: $project->getId(), - deploymentId: $deployment->getId(), - body: \strlen($body) > 0 ? $body : null, - variables: $vars, - timeout: $resource->getAttribute('timeout', 30), - image: $runtime['image'], - source: $source, - entrypoint: $entrypoint, - version: $version, - path: $path, - method: $method, - headers: $headers, - runtimeEntrypoint: $runtimeEntrypoint, - cpus: $spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT, - memory: $spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT, - logging: $resource->getAttribute('logging', true), - requestTimeout: 30, - responseFormat: Executor::RESPONSE_FORMAT_ARRAY_HEADERS - ); + try { + $executionResponse = $executor->createExecution( + projectId: $project->getId(), + deploymentId: $deployment->getId(), + body: \strlen($body) > 0 ? $body : null, + variables: $vars, + timeout: $resource->getAttribute('timeout', 30), + image: $runtime['image'], + source: $source, + entrypoint: $entrypoint, + version: $version, + path: $path, + method: $method, + headers: $headers, + runtimeEntrypoint: $runtimeEntrypoint, + cpus: $spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT, + memory: $spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT, + logging: $resource->getAttribute('logging', true), + requestTimeout: 30, + responseFormat: Executor::RESPONSE_FORMAT_ARRAY_HEADERS + ); + } catch (ExecutorTimeout $th) { + throw new AppwriteException(AppwriteException::FUNCTION_SYNCHRONOUS_TIMEOUT, previous: $th); + } $headerOverrides = []; diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 6fc3e88635..2cf8e79944 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -178,6 +178,7 @@ class Exception extends \Exception public const string FUNCTION_RUNTIME_UNSUPPORTED = 'function_runtime_unsupported'; public const string FUNCTION_ENTRYPOINT_MISSING = 'function_entrypoint_missing'; public const string FUNCTION_SYNCHRONOUS_TIMEOUT = 'function_synchronous_timeout'; + public const string FUNCTION_ASYNCHRONOUS_TIMEOUT = 'function_asynchronous_timeout'; public const string FUNCTION_TEMPLATE_NOT_FOUND = 'function_template_not_found'; public const string FUNCTION_RUNTIME_NOT_DETECTED = 'function_runtime_not_detected'; public const string FUNCTION_EXECUTE_PERMISSION_MISSING = 'function_execute_permission_missing'; @@ -192,6 +193,7 @@ class Exception extends \Exception public const string BUILD_ALREADY_COMPLETED = 'build_already_completed'; public const string BUILD_CANCELED = 'build_canceled'; public const string BUILD_FAILED = 'build_failed'; + public const string BUILD_TIMEOUT = 'build_timeout'; /** Execution */ public const string EXECUTION_NOT_FOUND = 'execution_not_found'; diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index 9f15cf9d1e..02dd76294e 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -17,6 +17,7 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Usage\Context; use Appwrite\Utopia\Database\Documents\User; use Appwrite\Utopia\Response; +use Executor\Exception\Timeout as ExecutorTimeout; use Executor\Executor; use MaxMind\Db\Reader; use Utopia\Auth\Proofs\Token; @@ -417,25 +418,29 @@ class Create extends Base $source = $deployment->getAttribute('buildPath', ''); $extension = str_ends_with($source, '.tar') ? 'tar' : 'tar.gz'; $command = $version === 'v2' ? '' : "cp /tmp/code.$extension /mnt/code/code.$extension && nohup helpers/start.sh \"$command\""; - $executionResponse = $executor->createExecution( - projectId: $project->getId(), - deploymentId: $deployment->getId(), - body: \strlen($body) > 0 ? $body : null, - variables: $vars, - timeout: $function->getAttribute('timeout', 0), - image: $runtime['image'], - source: $source, - entrypoint: $deployment->getAttribute('entrypoint', ''), - version: $version, - path: $path, - method: $method, - headers: $headers, - runtimeEntrypoint: $command, - cpus: $spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT, - memory: $spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT, - logging: $function->getAttribute('logging', true), - requestTimeout: 30 - ); + try { + $executionResponse = $executor->createExecution( + projectId: $project->getId(), + deploymentId: $deployment->getId(), + body: \strlen($body) > 0 ? $body : null, + variables: $vars, + timeout: $function->getAttribute('timeout', 0), + image: $runtime['image'], + source: $source, + entrypoint: $deployment->getAttribute('entrypoint', ''), + version: $version, + path: $path, + method: $method, + headers: $headers, + runtimeEntrypoint: $command, + cpus: $spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT, + memory: $spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT, + logging: $function->getAttribute('logging', true), + requestTimeout: 30 + ); + } catch (ExecutorTimeout $th) { + throw new AppwriteException(AppwriteException::FUNCTION_SYNCHRONOUS_TIMEOUT, previous: $th); + } $headersFiltered = []; foreach ($executionResponse['headers'] as $key => $value) { diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 352fb56e28..d285cf3a36 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -14,7 +14,9 @@ use Appwrite\Filter\BranchDomain as BranchDomainFilter; use Appwrite\Usage\Context; use Appwrite\Utopia\Response\Model\Deployment; use Appwrite\Vcs\Comment; +use Appwrite\Extend\Exception as AppwriteException; use Exception; +use Executor\Exception\Timeout as ExecutorTimeout; use Executor\Executor; use Swoole\Coroutine as Co; use Utopia\Cache\Cache; @@ -34,6 +36,7 @@ use Utopia\Detector\Detector\Rendering; use Utopia\Logger\Log; use Utopia\Platform\Action; use Utopia\Queue\Message; +use Utopia\Span\Span; use Utopia\Storage\Device; use Utopia\Storage\Device\Local; use Utopia\System\System; @@ -183,6 +186,8 @@ class Builds extends Action array $platform, int $timeout ): void { + Span::add('timeout', $timeout); + Console::info('Deployment action started'); $startTime = DateTime::now(); @@ -720,6 +725,9 @@ class Builds extends Action ); Console::log('createRuntime finished'); + } catch (ExecutorTimeout $error) { + Console::warning('createRuntime timed out'); + $err = new AppwriteException(AppwriteException::BUILD_TIMEOUT, previous: $error); } catch (\Throwable $error) { Console::warning('createRuntime failed'); $err = $error; @@ -1147,13 +1155,11 @@ class Builds extends Action $message = \str_replace('{APPWRITE_DETECTION_SEPARATOR_START}', '', $message); $message = \str_replace('{APPWRITE_DETECTION_SEPARATOR_END}', '', $message); - // Combine with previous logs if deployment got past build process - $previousLogs = ''; - if (! is_null($deployment->getAttribute('buildSize', null))) { - $previousLogs = $deployment->getAttribute('buildLogs', ''); - if (! empty($previousLogs)) { - $message = $previousLogs . "\n" . $message; - } + // Append error to whatever build logs were already streamed + $deployment = $dbForProject->getDocument('deployments', $deploymentId); + $previousLogs = $deployment->getAttribute('buildLogs', ''); + if (! empty($previousLogs)) { + $message = $previousLogs . "\n" . $message; } $endTime = DateTime::now(); diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 8167fb975d..a72b16cc23 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -10,6 +10,7 @@ use Appwrite\Event\Realtime; use Appwrite\Event\Webhook; use Appwrite\Extend\Exception as AppwriteException; use Appwrite\Utopia\Response\Model\Execution; +use Executor\Exception\Timeout as ExecutorTimeout; use Executor\Executor; use Utopia\Bus\Bus; use Utopia\Config\Config; @@ -565,24 +566,28 @@ class Functions extends Action Span::add('trigger', $trigger); Span::current()?->finish(); } - $executionResponse = $executor->createExecution( - projectId: $project->getId(), - deploymentId: $deploymentId, - body: \strlen($body) > 0 ? $body : null, - variables: $vars, - timeout: $function->getAttribute('timeout', 0), - image: $runtime['image'], - source: $source, - entrypoint: $deployment->getAttribute('entrypoint', ''), - version: $version, - path: $path, - method: $method, - headers: $headers, - runtimeEntrypoint: $command, - cpus: $spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT, - memory: $spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT, - logging: $function->getAttribute('logging', true), - ); + try { + $executionResponse = $executor->createExecution( + projectId: $project->getId(), + deploymentId: $deploymentId, + body: \strlen($body) > 0 ? $body : null, + variables: $vars, + timeout: $function->getAttribute('timeout', 0), + image: $runtime['image'], + source: $source, + entrypoint: $deployment->getAttribute('entrypoint', ''), + version: $version, + path: $path, + method: $method, + headers: $headers, + runtimeEntrypoint: $command, + cpus: $spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT, + memory: $spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT, + logging: $function->getAttribute('logging', true), + ); + } catch (ExecutorTimeout $th) { + throw new AppwriteException(AppwriteException::FUNCTION_ASYNCHRONOUS_TIMEOUT, previous: $th); + } $status = $executionResponse['statusCode'] >= 500 ? 'failed' : 'completed'; diff --git a/src/Executor/Exception.php b/src/Executor/Exception.php new file mode 100644 index 0000000000..b799d22567 --- /dev/null +++ b/src/Executor/Exception.php @@ -0,0 +1,7 @@ +timeoutSeconds; + } +} diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index eb74867c9c..c570970732 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -2,9 +2,9 @@ namespace Executor; -use Appwrite\Extend\Exception as AppwriteException; use Appwrite\Utopia\Fetch\BodyMultipart; -use Exception; +use Executor\Exception as ExecutorException; +use Executor\Exception\Timeout as ExecutorTimeout; use Utopia\System\System; class Executor @@ -104,7 +104,7 @@ class Executor $status = $response['headers']['status-code']; if ($status >= 400) { $message = \is_string($response['body']) ? $response['body'] : $response['body']['message']; - throw new \Exception($message, $status); + throw new ExecutorException($message, $status); } return $response['body']; @@ -163,7 +163,7 @@ class Executor } if ($status >= 400) { - throw new \Exception($message, $status); + throw new ExecutorException($message, $status); } return $response['body']; @@ -247,7 +247,7 @@ class Executor $status = $response['headers']['status-code']; if ($status >= 400) { $message = \is_string($response['body']) ? $response['body'] : $response['body']['message']; - throw new \Exception($message, $status); + throw new ExecutorException($message, $status); } $headers = $response['body']['headers'] ?? []; @@ -281,7 +281,7 @@ class Executor $status = $response['headers']['status-code']; if ($status >= 400) { $message = \is_string($response['body']) ? $response['body'] : $response['body']['message']; - throw new \Exception($message, $status); + throw new ExecutorException($message, $status); } return $response['body']; @@ -401,7 +401,7 @@ class Executor $json = json_decode($responseBody, true); if ($json === null) { - throw new Exception('Failed to parse response: ' . $responseBody); + throw new ExecutorException('Failed to parse response: ' . $responseBody); } $responseBody = $json; @@ -412,9 +412,9 @@ class Executor if ($curlError) { if ($curlError == CURLE_OPERATION_TIMEDOUT) { - throw new AppwriteException(AppwriteException::FUNCTION_SYNCHRONOUS_TIMEOUT); + throw new ExecutorTimeout('Executor request timed out', $timeout); } - throw new Exception($curlErrorMessage . ' with status code ' . $responseStatus, $responseStatus); + throw new ExecutorException($curlErrorMessage . ' with status code ' . $responseStatus, $responseStatus); } $responseHeaders['status-code'] = $responseStatus; From 9387c480f50cd699c282a05612d61e9db43556bd Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 6 May 2026 19:56:17 +0100 Subject: [PATCH 168/211] Add Span attributes to build worker for trace observability --- .../Platform/Modules/Functions/Workers/Builds.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index d285cf3a36..a0bd37732f 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -10,11 +10,11 @@ use Appwrite\Event\Publisher\Screenshot; use Appwrite\Event\Publisher\Usage as UsagePublisher; use Appwrite\Event\Realtime; use Appwrite\Event\Webhook; +use Appwrite\Extend\Exception as AppwriteException; use Appwrite\Filter\BranchDomain as BranchDomainFilter; use Appwrite\Usage\Context; use Appwrite\Utopia\Response\Model\Deployment; use Appwrite\Vcs\Comment; -use Appwrite\Extend\Exception as AppwriteException; use Exception; use Executor\Exception\Timeout as ExecutorTimeout; use Executor\Executor; @@ -186,6 +186,10 @@ class Builds extends Action array $platform, int $timeout ): void { + Span::add('projectId', $project->getId()); + Span::add('resourceId', $resource->getId()); + Span::add('resourceType', $resource->getCollection()); + Span::add('deploymentId', $deployment->getId()); Span::add('timeout', $timeout); Console::info('Deployment action started'); @@ -228,8 +232,12 @@ class Builds extends Action $version = $this->getVersion($resource); $runtime = $this->getRuntime($resource, $version); + Span::add('runtime', $resource->getAttribute($resource->getCollection() === 'sites' ? 'buildRuntime' : 'runtime', '')); + Span::add('version', $version); $spec = Config::getParam('specifications')[$resource->getAttribute('buildSpecification', APP_COMPUTE_SPECIFICATION_DEFAULT)]; + Span::add('cpus', (float) ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT)); + Span::add('memory', (int) ($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT)); // Realtime preparation $event = "{$resource->getCollection()}.[{$resourceKey}].deployments.[deploymentId].update"; From 85d7c27a38c62bfd9e20efd9b3d06d65ddd16053 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 7 May 2026 03:50:08 +0100 Subject: [PATCH 169/211] spike: treat null exception code as publishable in fallback gate --- src/Appwrite/Platform/Workers/Migrations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 2af3752085..5588a77799 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -554,7 +554,7 @@ class Migrations extends Action } elseif ($th instanceof MigrationException) { $publish = false; } else { - $publish = $th->getCode() === 0 || $th->getCode() >= 500; + $publish = $th->getCode() === null || $th->getCode() === 0 || $th->getCode() >= 500; } if ($publish) { From 8e9fd3256615b0a38e6f808b058baa8c4446a1b6 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 7 May 2026 07:41:47 +0100 Subject: [PATCH 170/211] spike: simplify gate fallback to always publish on unknown exception types --- src/Appwrite/Platform/Workers/Migrations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 5588a77799..e4274b2a8c 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -554,7 +554,7 @@ class Migrations extends Action } elseif ($th instanceof MigrationException) { $publish = false; } else { - $publish = $th->getCode() === null || $th->getCode() === 0 || $th->getCode() >= 500; + $publish = true; } if ($publish) { From e7d338466083cc1e72a7d6b4b3f71b20dda15f19 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 7 May 2026 09:22:21 +0100 Subject: [PATCH 171/211] Pin utopia-php/migration to 1.10.* (release with Sentry-leak fix) --- composer.json | 2 +- composer.lock | 77 +++++++++++++++++++++++++-------------------------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/composer.json b/composer.json index 35961a37cf..e396f6ad10 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,7 @@ "utopia-php/locale": "0.8.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.22.*", - "utopia-php/migration": "dev-fix-migration-sentry-leak as 1.9.999", + "utopia-php/migration": "1.10.*", "utopia-php/platform": "0.13.*", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", diff --git a/composer.lock b/composer.lock index ad0ad5b137..a1f8309c17 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": "b6fc61ff6050d420307ba99ed2e59d46", + "content-hash": "d0e14ee465162e3b5e56d6cef9ddbb8d", "packages": [ { "name": "adhocore/jwt", @@ -2641,16 +2641,16 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.6.0", + "version": "v3.7.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62" + "reference": "50f59d1f3ca46d41ac911f97a78626b6756af35b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62", - "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/50f59d1f3ca46d41ac911f97a78626b6756af35b", + "reference": "50f59d1f3ca46d41ac911f97a78626b6756af35b", "shasum": "" }, "require": { @@ -2663,7 +2663,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "3.6-dev" + "dev-main": "3.7-dev" } }, "autoload": { @@ -2688,7 +2688,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.7.0" }, "funding": [ { @@ -2699,12 +2699,16 @@ "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": "2024-09-25T14:21:43+00:00" + "time": "2026-04-13T15:52:40+00:00" }, { "name": "symfony/http-client", @@ -2809,16 +2813,16 @@ }, { "name": "symfony/http-client-contracts", - "version": "v3.6.0", + "version": "v3.7.0", "source": { "type": "git", "url": "https://github.com/symfony/http-client-contracts.git", - "reference": "75d7043853a42837e68111812f4d964b01e5101c" + "reference": "4a2d00c37651c0bdc2b9e1c773487a8bf4edb12d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/75d7043853a42837e68111812f4d964b01e5101c", - "reference": "75d7043853a42837e68111812f4d964b01e5101c", + "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/4a2d00c37651c0bdc2b9e1c773487a8bf4edb12d", + "reference": "4a2d00c37651c0bdc2b9e1c773487a8bf4edb12d", "shasum": "" }, "require": { @@ -2831,7 +2835,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "3.6-dev" + "dev-main": "3.7-dev" } }, "autoload": { @@ -2867,7 +2871,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/http-client-contracts/tree/v3.6.0" + "source": "https://github.com/symfony/http-client-contracts/tree/v3.7.0" }, "funding": [ { @@ -2878,12 +2882,16 @@ "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-29T11:18:49+00:00" + "time": "2026-03-06T13:17:50+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -3212,16 +3220,16 @@ }, { "name": "symfony/service-contracts", - "version": "v3.6.1", + "version": "v3.7.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "45112560a3ba2d715666a509a0bc9521d10b6c43" + "reference": "d25d82433a80eba6aa0e6c24b61d7370d99e444a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/45112560a3ba2d715666a509a0bc9521d10b6c43", - "reference": "45112560a3ba2d715666a509a0bc9521d10b6c43", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/d25d82433a80eba6aa0e6c24b61d7370d99e444a", + "reference": "d25d82433a80eba6aa0e6c24b61d7370d99e444a", "shasum": "" }, "require": { @@ -3239,7 +3247,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "3.6-dev" + "dev-main": "3.7-dev" } }, "autoload": { @@ -3275,7 +3283,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.6.1" + "source": "https://github.com/symfony/service-contracts/tree/v3.7.0" }, "funding": [ { @@ -3295,7 +3303,7 @@ "type": "tidelift" } ], - "time": "2025-07-15T11:30:57+00:00" + "time": "2026-03-28T09:44:51+00:00" }, { "name": "tbachert/spi", @@ -4531,16 +4539,16 @@ }, { "name": "utopia-php/migration", - "version": "dev-fix-migration-sentry-leak", + "version": "1.10.1", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "da8205e8f3e927b2b860dddc2efca0e408171116" + "reference": "759d6d61b327313cbeeeb4ea0c3e2459164b4827" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/da8205e8f3e927b2b860dddc2efca0e408171116", - "reference": "da8205e8f3e927b2b860dddc2efca0e408171116", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/759d6d61b327313cbeeeb4ea0c3e2459164b4827", + "reference": "759d6d61b327313cbeeeb4ea0c3e2459164b4827", "shasum": "" }, "require": { @@ -4597,10 +4605,10 @@ "utopia" ], "support": { - "source": "https://github.com/utopia-php/migration/tree/fix-migration-sentry-leak", + "source": "https://github.com/utopia-php/migration/tree/1.10.1", "issues": "https://github.com/utopia-php/migration/issues" }, - "time": "2026-05-05T15:50:58+00:00" + "time": "2026-05-07T07:23:57+00:00" }, { "name": "utopia-php/mongo", @@ -8461,18 +8469,9 @@ "time": "2024-11-07T12:36:22+00:00" } ], - "aliases": [ - { - "package": "utopia-php/migration", - "version": "dev-fix-migration-sentry-leak", - "alias": "1.9.999", - "alias_normalized": "1.9.999.0" - } - ], + "aliases": [], "minimum-stability": "dev", - "stability-flags": { - "utopia-php/migration": 20 - }, + "stability-flags": {}, "prefer-stable": true, "prefer-lowest": false, "platform": { From 4721523ea8eedd501fbe11f397b0dcd469d17062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 7 May 2026 10:30:56 +0200 Subject: [PATCH 172/211] Improve project tests --- .../Projects/ProjectsConsoleClientTest.php | 430 +++++++++++++++++- 1 file changed, 428 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 3a9037c368..f3643f0959 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -787,12 +787,117 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), + 'description' => 'My description', + 'logo' => 'https://google.com/logo.png', + 'url' => 'https://myapp.com/', + 'legalName' => 'Legal company', + 'legalCountry' => 'Slovakia', + 'legalState' => 'Custom state', + 'legalCity' => 'Košice', + 'legalAddress' => 'Main street 32', + 'legalTaxId' => 'TAXID_123456' ]); - + $this->assertEquals(201, $response['headers']['status-code']); $id = $response['body']['$id']; + // Add mock numbers + $response = $this->client->call(Client::METHOD_POST, '/project/' . $id . '/mock-phones', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'number' => '+421123456789', + 'otp' => '123456' + ]); + $this->assertEquals(201, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_POST, '/project/' . $id . '/mock-phones', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'number' => '+420987654321', + 'otp' => '654321' + ]); + $this->assertEquals(201, $response['headers']['status-code']); + + // Setup custom values for project policies + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/session-duration', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'duration' => 135 + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/user-limit', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'total' => 54 + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/session-limit', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'total' => 7 + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/password-history', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'total' => 9 + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/password-dictionary', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => true + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/password-personal-data', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => true + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/session-alert', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => true + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/membership-privacy', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'userId' => true, + 'userEmail' => true, + 'userPhone' => true, + 'userName' => true, + 'userMFA' => true, + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/session-invalidation', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => false + ]); + $this->assertEquals(200, $response['headers']['status-code']); + /** * Test for SUCCESS */ @@ -806,6 +911,327 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals($id, $response['body']['$id']); $this->assertEquals('Project Test', $response['body']['name']); + $this->assertArrayHasKey('$createdAt', $response); + $this->assertIsString($response['$createdAt']); + $this->assertNotFalse(\strtotime($response['$createdAt'])); + + $this->assertArrayHasKey('$updatedAt', $response); + $this->assertIsString($response['$updatedAt']); + $this->assertNotFalse(\strtotime($response['$updatedAt'])); + + $this->assertArrayHasKey('description', $response); + $this->assertIsString($response['description']); + $this->assertEquals('My description', $response['description']); + + $this->assertArrayHasKey('teamId', $response); + $this->assertIsString($response['teamId']); + $this->assertEquals($team['body']['$id'], $response['teamId']); + + $this->assertArrayHasKey('logo', $response); + $this->assertIsString($response['logo']); + $this->assertEquals('https://google.com/logo.png', $response['logo']); + + $this->assertArrayHasKey('url', $response); + $this->assertIsString($response['url']); + $this->assertEquals('https://myapp.com/', $response['url']); + + $this->assertArrayHasKey('legalName', $response); + $this->assertIsString($response['legalName']); + $this->assertEquals('Legal company', $response['legalName']); + + $this->assertArrayHasKey('legalCountry', $response); + $this->assertIsString($response['legalCountry']); + $this->assertEquals('Slovakia', $response['legalCountry']); + + $this->assertArrayHasKey('legalState', $response); + $this->assertIsString($response['legalState']); + $this->assertEquals('Custom state', $response['legalState']); + + $this->assertArrayHasKey('legalCity', $response); + $this->assertIsString($response['legalCity']); + $this->assertEquals('Košice', $response['legalCity']); + + $this->assertArrayHasKey('legalAddress', $response); + $this->assertIsString($response['legalAddress']); + $this->assertEquals('Main street 32', $response['legalAddress']); + + $this->assertArrayHasKey('legalTaxId', $response); + $this->assertIsString($response['legalTaxId']); + $this->assertEquals('TAXID_123456', $response['legalTaxId']); + + $this->assertArrayHasKey('authDuration', $response); + $this->assertIsInt($response['authDuration']); + $this->assertEquals(135, $response['authDuration']); + + $this->assertArrayHasKey('authLimit', $response); + $this->assertIsInt($response['authLimit']); + $this->assertEquals(54, $response['authLimit']); + + $this->assertArrayHasKey('authSessionsLimit', $response); + $this->assertIsInt($response['authSessionsLimit']); + $this->assertEquals(7, $response['authLimit']); + + $this->assertArrayHasKey('authPasswordHistory', $response); + $this->assertIsInt($response['authPasswordHistory']); + $this->assertEquals(9, $response['authPasswordHistory']); + + $this->assertArrayHasKey('authPasswordDictionary', $response); + $this->assertIsBool($response['authPasswordDictionary']); + $this->assertTrue($response['authPasswordDictionary']); + + $this->assertArrayHasKey('authPersonalDataCheck', $response); + $this->assertIsBool($response['authPersonalDataCheck']); + $this->assertTrue($response['authPersonalDataCheck']); + + $this->assertArrayHasKey('authDisposableEmails', $response); + $this->assertIsBool($response['authDisposableEmails']); + $this->assertFalse($response['authDisposableEmails']); + + $this->assertArrayHasKey('authCanonicalEmails', $response); + $this->assertIsBool($response['authCanonicalEmails']); + $this->assertFalse($response['authCanonicalEmails']); + + $this->assertArrayHasKey('authFreeEmails', $response); + $this->assertIsBool($response['authFreeEmails']); + $this->assertFalse($response['authFreeEmails']); + + $this->assertArrayHasKey('authMockNumbers', $response); + $this->assertIsArray($response['authMockNumbers']); + $this->assertCount(2, $response['authMockNumbers']); + + $this->assertEquals('+421123456789', $response['authMockNumbers'][0]['number']); + $this->assertEquals('+420987654321', $response['authMockNumbers'][1]['number']); + + $this->assertEquals('123456', $response['authMockNumbers'][0]['otp']); + $this->assertEquals('654321', $response['authMockNumbers'][1]['otp']); + + foreach($response['authMockNumbers'] as $mockNumber) { + $this->assertArrayHasKey('$createdAt', $mockNumber); + $this->assertIsString($mockNumber['$createdAt']); + $this->assertNotFalse(\strtotime($mockNumber['$createdAt'])); + + $this->assertArrayHasKey('$updatedAt', $mockNumber); + $this->assertIsString($mockNumber['$updatedAt']); + $this->assertNotFalse(\strtotime($mockNumber['$updatedAt'])); + + $this->assertArrayHasKey('number', $mockNumber); + $this->assertIsString($mockNumber['number']); + $this->assertNotEmpty($mockNumber['number']); + + $this->assertArrayHasKey('otp', $mockNumber); + $this->assertIsString($mockNumber['otp']); + $this->assertNotEmpty($mockNumber['otp']); + } + + $this->assertArrayHasKey('authSessionAlerts', $response); + $this->assertIsBool($response['authSessionAlerts']); + $this->assertTrue($response['authSessionAlerts']); + + $this->assertArrayHasKey('authMembershipsUserName', $response); + $this->assertIsBool($response['authMembershipsUserName']); + $this->assertTrue($response['authMembershipsUserName']); + + $this->assertArrayHasKey('authMembershipsUserEmail', $response); + $this->assertIsBool($response['authMembershipsUserEmail']); + $this->assertTrue($response['authMembershipsUserEmail']); + + $this->assertArrayHasKey('authMembershipsMfa', $response); + $this->assertIsBool($response['authMembershipsMfa']); + $this->assertTrue($response['authMembershipsMfa']); + + $this->assertArrayHasKey('authMembershipsUserId', $response); + $this->assertIsBool($project['authMembershipsUserId']); + $this->assertTrue($response['authMembershipsUserId']); + + $this->assertArrayHasKey('authMembershipsUserPhone', $response); + $this->assertIsBool($response['authMembershipsUserPhone']); + $this->assertTrue($response['authMembershipsUserPhone']); + + $this->assertArrayHasKey('authInvalidateSessions', $response); + $this->assertIsBool($response['authInvalidateSessions']); + $this->assertTrue($response['authInvalidateSessions']); + + /* + $this->assertArrayHasKey('oAuthProviders', $project); + $this->assertIsArray($project['oAuthProviders']); + + $this->assertArrayHasKey('platforms', $project); + $this->assertIsArray($project['platforms']); + + $this->assertArrayHasKey('webhooks', $project); + $this->assertIsArray($project['webhooks']); + + $this->assertArrayHasKey('keys', $project); + $this->assertIsArray($project['keys']); + + $this->assertArrayHasKey('devKeys', $project); + $this->assertIsArray($project['devKeys']); + */ + + /* + $this->assertArrayHasKey('smtpEnabled', $project); + $this->assertIsBool($project['smtpEnabled']); + + $this->assertArrayHasKey('smtpSenderName', $project); + $this->assertIsString($project['smtpSenderName']); + + $this->assertArrayHasKey('smtpSenderEmail', $project); + $this->assertIsString($project['smtpSenderEmail']); + + $this->assertArrayHasKey('smtpReplyToName', $project); + $this->assertIsString($project['smtpReplyToName']); + + $this->assertArrayHasKey('smtpReplyToEmail', $project); + $this->assertIsString($project['smtpReplyToEmail']); + + $this->assertArrayHasKey('smtpHost', $project); + $this->assertIsString($project['smtpHost']); + + $this->assertArrayHasKey('smtpPort', $project); + $this->assertTrue( + is_int($project['smtpPort']) || $project['smtpPort'] === '', + 'smtpPort should be an integer or an empty string' + ); + + $this->assertArrayHasKey('smtpUsername', $project); + $this->assertIsString($project['smtpUsername']); + + $this->assertArrayHasKey('smtpPassword', $project); + $this->assertIsString($project['smtpPassword']); + + $this->assertArrayHasKey('smtpSecure', $project); + $this->assertIsString($project['smtpSecure']); + */ + + + /* + $this->assertArrayHasKey('pingCount', $project); + $this->assertIsInt($project['pingCount']); + + $this->assertArrayHasKey('pingedAt', $project); + $this->assertIsString($project['pingedAt']); + + $this->assertArrayHasKey('labels', $project); + $this->assertIsArray($project['labels']); + + $this->assertArrayHasKey('status', $project); + $this->assertIsString($project['status']); + */ + + /* + $auth = require(__DIR__ . '/../../../../app/config/auth.php'); + foreach ($auth as $method) { + $key = 'auth' . ucfirst($method['key'] ?? ''); + $this->assertArrayHasKey($key, $project, 'Missing auth field: ' . $key); + $this->assertIsBool($project[$key], 'Auth field should be boolean: ' . $key); + } + + $services = require(__DIR__ . '/../../../../app/config/services.php'); + foreach ($services as $service) { + if (!($service['optional'] ?? false)) { + continue; + } + $key = 'serviceStatusFor' . ucfirst($service['key'] ?? ''); + $this->assertArrayHasKey($key, $project, 'Missing service field: ' . $key); + $this->assertIsBool($project[$key], 'Service field should be boolean: ' . $key); + } + + // Dynamic protocol status fields + $protocols = require(__DIR__ . '/../../../../app/config/protocols.php'); + foreach ($protocols as $protocol) { + $key = 'protocolStatusFor' . ucfirst($protocol['key'] ?? ''); + $this->assertArrayHasKey($key, $project, 'Missing protocol field: ' . $key); + $this->assertIsBool($project[$key], 'Protocol field should be boolean: ' . $key); + } + */ + + // Ensure policies can be falsy + + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/password-dictionary', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => false + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/password-personal-data', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => false + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/session-alert', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => false + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/membership-privacy', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'userId' => false, + 'userEmail' => false, + 'userPhone' => false, + 'userName' => false, + 'userMFA' => false, + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/session-invalidation', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => false + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertArrayHasKey('authPasswordDictionary', $response); + $this->assertIsBool($response['authPasswordDictionary']); + $this->assertFalse($response['authPasswordDictionary']); + + $this->assertArrayHasKey('authPersonalDataCheck', $response); + $this->assertIsBool($response['authPersonalDataCheck']); + $this->assertFalse($response['authPersonalDataCheck']); + + $this->assertArrayHasKey('authSessionAlerts', $response); + $this->assertIsBool($response['authSessionAlerts']); + $this->assertFalse($response['authSessionAlerts']); + + $this->assertArrayHasKey('authMembershipsUserName', $response); + $this->assertIsBool($response['authMembershipsUserName']); + $this->assertFalse($response['authMembershipsUserName']); + + $this->assertArrayHasKey('authMembershipsUserEmail', $response); + $this->assertIsBool($response['authMembershipsUserEmail']); + $this->assertFalse($response['authMembershipsUserEmail']); + + $this->assertArrayHasKey('authMembershipsMfa', $response); + $this->assertIsBool($response['authMembershipsMfa']); + $this->assertFalse($response['authMembershipsMfa']); + + $this->assertArrayHasKey('authMembershipsUserId', $response); + $this->assertIsBool($project['authMembershipsUserId']); + $this->assertFalse($response['authMembershipsUserId']); + + $this->assertArrayHasKey('authMembershipsUserPhone', $response); + $this->assertIsBool($response['authMembershipsUserPhone']); + $this->assertFalse($response['authMembershipsUserPhone']); + + $this->assertArrayHasKey('authInvalidateSessions', $response); + $this->assertIsBool($response['authInvalidateSessions']); + $this->assertFalse($response['authInvalidateSessions']); + /** * Test for FAILURE */ From 8ad106632e1e1442cde72726864137d3c2863079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 7 May 2026 10:40:54 +0200 Subject: [PATCH 173/211] Improve tests further --- phpunit.xml | 2 +- .../Projects/ProjectsConsoleClientTest.php | 181 ++++++++++++------ 2 files changed, 128 insertions(+), 55 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 9748c5a5c8..b566e232cd 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -5,7 +5,7 @@ bootstrap="app/init.php" colors="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" stopOnError="false" cacheDirectory=".phpunit.cache" > diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index f3643f0959..6ed45e36df 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -802,19 +802,41 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $id = $response['body']['$id']; + // Configure SMTP + $response = $this->client->call( + Client::METHOD_PATCH, + '/project/smtp', + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ], $this->getHeaders()), + [ + 'enabled' => true, + 'senderName' => 'Custom sender', + 'senderEmail' => 'email@custom.com', + 'host' => 'maildev', + 'port' => 1025, + 'replyTo' => 'replyto@custom.com', + 'replyToName' => 'Reply sender', + ], + ); + // Add mock numbers - $response = $this->client->call(Client::METHOD_POST, '/project/' . $id . '/mock-phones', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/project/mock-phones', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'number' => '+421123456789', 'otp' => '123456' ]); + \var_dump($id); + \var_dump($this->getHeaders()); $this->assertEquals(201, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_POST, '/project/' . $id . '/mock-phones', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/project/mock-phones', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id ], $this->getHeaders()), [ 'number' => '+420987654321', 'otp' => '654321' @@ -822,65 +844,65 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); // Setup custom values for project policies - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/session-duration', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/session-duration', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id ], $this->getHeaders()), [ 'duration' => 135 ]); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/user-limit', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/user-limit', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, ], $this->getHeaders()), [ 'total' => 54 ]); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/session-limit', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/session-limit', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, ], $this->getHeaders()), [ 'total' => 7 ]); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/password-history', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-history', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, ], $this->getHeaders()), [ 'total' => 9 ]); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/password-dictionary', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-dictionary', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, ], $this->getHeaders()), [ 'enabled' => true ]); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/password-personal-data', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-personal-data', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, ], $this->getHeaders()), [ 'enabled' => true ]); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/session-alert', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/session-alert', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, ], $this->getHeaders()), [ 'enabled' => true ]); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/membership-privacy', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/membership-privacy', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, ], $this->getHeaders()), [ 'userId' => true, 'userEmail' => true, @@ -890,9 +912,9 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/session-invalidation', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/session-invalidation', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, ], $this->getHeaders()), [ 'enabled' => false ]); @@ -1051,6 +1073,46 @@ class ProjectsConsoleClientTest extends Scope $this->assertIsBool($response['authInvalidateSessions']); $this->assertTrue($response['authInvalidateSessions']); + $this->assertArrayHasKey('smtpEnabled', $response); + $this->assertIsBool($response['smtpEnabled']); + $this->assertTrue($response['smtpEnabled']); + + $this->assertArrayHasKey('smtpSenderName', $response); + $this->assertIsString($response['smtpSenderName']); + $this->assertSame('Custom sender', $response['smtpSenderName']); + + $this->assertArrayHasKey('smtpSenderEmail', $response); + $this->assertIsString($response['smtpSenderEmail']); + $this->assertSame('email@custom.com', $response['smtpSenderEmail']); + + $this->assertArrayHasKey('smtpReplyToName', $response); + $this->assertIsString($response['smtpReplyToName']); + $this->assertSame('Reply sender', $response['smtpReplyToName']); + + $this->assertArrayHasKey('smtpReplyToEmail', $response); + $this->assertIsString($response['smtpReplyToEmail']); + $this->assertSame('replyto@custom.com', $response['smtpReplyToEmail']); + + $this->assertArrayHasKey('smtpHost', $response); + $this->assertIsString($response['smtpHost']); + $this->assertSame('maildev', $response['smtpHost']); + + $this->assertArrayHasKey('smtpPort', $response); + $this->assertIsInt($response['smtpPort']); + $this->assertSame(1025, $response['smtpPort']); + + $this->assertArrayHasKey('smtpUsername', $response); + $this->assertIsString($response['smtpUsername']); + $this->assertSame('', $response['smtpUsername']); + + $this->assertArrayHasKey('smtpPassword', $response); + $this->assertIsString($response['smtpPassword']); + $this->assertSame('', $response['smtpPassword']); + + $this->assertArrayHasKey('smtpSecure', $response); + $this->assertIsString($response['smtpSecure']); + $this->assertSame('', $response['smtpSecure']); + /* $this->assertArrayHasKey('oAuthProviders', $project); $this->assertIsArray($project['oAuthProviders']); @@ -1069,38 +1131,7 @@ class ProjectsConsoleClientTest extends Scope */ /* - $this->assertArrayHasKey('smtpEnabled', $project); - $this->assertIsBool($project['smtpEnabled']); - - $this->assertArrayHasKey('smtpSenderName', $project); - $this->assertIsString($project['smtpSenderName']); - - $this->assertArrayHasKey('smtpSenderEmail', $project); - $this->assertIsString($project['smtpSenderEmail']); - - $this->assertArrayHasKey('smtpReplyToName', $project); - $this->assertIsString($project['smtpReplyToName']); - - $this->assertArrayHasKey('smtpReplyToEmail', $project); - $this->assertIsString($project['smtpReplyToEmail']); - - $this->assertArrayHasKey('smtpHost', $project); - $this->assertIsString($project['smtpHost']); - - $this->assertArrayHasKey('smtpPort', $project); - $this->assertTrue( - is_int($project['smtpPort']) || $project['smtpPort'] === '', - 'smtpPort should be an integer or an empty string' - ); - - $this->assertArrayHasKey('smtpUsername', $project); - $this->assertIsString($project['smtpUsername']); - - $this->assertArrayHasKey('smtpPassword', $project); - $this->assertIsString($project['smtpPassword']); - - $this->assertArrayHasKey('smtpSecure', $project); - $this->assertIsString($project['smtpSecure']); + */ @@ -1190,6 +1221,24 @@ class ProjectsConsoleClientTest extends Scope 'enabled' => false ]); $this->assertEquals(200, $response['headers']['status-code']); + + // Configure SMTP + $response = $this->client->call( + Client::METHOD_PATCH, + '/project/smtp', + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), + [ + 'enabled' => false, + 'host' => 'customhost.com', + 'port' => 4444, + 'username' => 'myuser', + 'password' => 'mypassword', + 'secure' => 'ssl', + ], + ); $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', @@ -1232,6 +1281,30 @@ class ProjectsConsoleClientTest extends Scope $this->assertIsBool($response['authInvalidateSessions']); $this->assertFalse($response['authInvalidateSessions']); + $this->assertArrayHasKey('smtpEnabled', $response); + $this->assertIsBool($response['smtpEnabled']); + $this->assertFalse($response['smtpEnabled']); + + $this->assertArrayHasKey('smtpHost', $response); + $this->assertIsString($response['smtpHost']); + $this->assertSame('customhost.com', $response['smtpHost']); + + $this->assertArrayHasKey('smtpPort', $response); + $this->assertIsInt($response['smtpPort']); + $this->assertSame(4444, $response['smtpPort']); + + $this->assertArrayHasKey('smtpUsername', $response); + $this->assertIsString($response['smtpUsername']); + $this->assertSame('myuser', $response['smtpUsername']); + + $this->assertArrayHasKey('smtpPassword', $response); + $this->assertIsString($response['smtpPassword']); + $this->assertSame('', $response['smtpPassword']); + + $this->assertArrayHasKey('smtpSecure', $response); + $this->assertIsString($response['smtpSecure']); + $this->assertSame('ssl', $response['smtpSecure']); + /** * Test for FAILURE */ From fe27ae058406963ad8f1ec9fd3c2b8a076fface6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 7 May 2026 10:58:05 +0200 Subject: [PATCH 174/211] Fix failing tests --- .../Projects/ProjectsConsoleClientTest.php | 405 ++++++------------ 1 file changed, 129 insertions(+), 276 deletions(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 6ed45e36df..a8bfaa0f7f 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -798,7 +798,7 @@ class ProjectsConsoleClientTest extends Scope 'legalAddress' => 'Main street 32', 'legalTaxId' => 'TAXID_123456' ]); - + $this->assertEquals(201, $response['headers']['status-code']); $id = $response['body']['$id']; @@ -809,6 +809,7 @@ class ProjectsConsoleClientTest extends Scope array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'enabled' => true, @@ -816,10 +817,11 @@ class ProjectsConsoleClientTest extends Scope 'senderEmail' => 'email@custom.com', 'host' => 'maildev', 'port' => 1025, - 'replyTo' => 'replyto@custom.com', + 'replyToEmail' => 'replyto@custom.com', 'replyToName' => 'Reply sender', ], ); + $this->assertEquals(200, $response['headers']['status-code']); // Add mock numbers $response = $this->client->call(Client::METHOD_POST, '/project/mock-phones', array_merge([ @@ -830,13 +832,12 @@ class ProjectsConsoleClientTest extends Scope 'number' => '+421123456789', 'otp' => '123456' ]); - \var_dump($id); - \var_dump($this->getHeaders()); $this->assertEquals(201, $response['headers']['status-code']); $response = $this->client->call(Client::METHOD_POST, '/project/mock-phones', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $id + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'number' => '+420987654321', 'otp' => '654321' @@ -846,15 +847,17 @@ class ProjectsConsoleClientTest extends Scope // Setup custom values for project policies $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/session-duration', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $id + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'duration' => 135 ]); $this->assertEquals(200, $response['headers']['status-code']); - + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/user-limit', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'total' => 54 ]); @@ -863,22 +866,25 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/session-limit', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'total' => 7 ]); $this->assertEquals(200, $response['headers']['status-code']); - + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-history', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'total' => 9 ]); $this->assertEquals(200, $response['headers']['status-code']); - + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-dictionary', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'enabled' => true ]); @@ -887,6 +893,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-personal-data', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'enabled' => true ]); @@ -894,7 +901,8 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/session-alert', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $id, + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'enabled' => true ]); @@ -903,6 +911,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/membership-privacy', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'userId' => true, 'userEmail' => true, @@ -915,8 +924,9 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/session-invalidation', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => false + 'enabled' => true ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -929,190 +939,76 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertNotEmpty($response['body']); $this->assertEquals($id, $response['body']['$id']); $this->assertEquals('Project Test', $response['body']['name']); - $this->assertArrayHasKey('$createdAt', $response); - $this->assertIsString($response['$createdAt']); - $this->assertNotFalse(\strtotime($response['$createdAt'])); + $this->assertIsString($response['body']['$createdAt']); + $this->assertNotEmpty($response['body']['$createdAt']); + $this->assertNotFalse(\strtotime($response['body']['$createdAt'])); - $this->assertArrayHasKey('$updatedAt', $response); - $this->assertIsString($response['$updatedAt']); - $this->assertNotFalse(\strtotime($response['$updatedAt'])); + $this->assertIsString($response['body']['$updatedAt']); + $this->assertNotEmpty($response['body']['$updatedAt']); + $this->assertNotFalse(\strtotime($response['body']['$updatedAt'])); - $this->assertArrayHasKey('description', $response); - $this->assertIsString($response['description']); - $this->assertEquals('My description', $response['description']); + $this->assertEquals('My description', $response['body']['description']); + $this->assertEquals($team['body']['$id'], $response['body']['teamId']); + $this->assertEquals('https://google.com/logo.png', $response['body']['logo']); + $this->assertEquals('https://myapp.com/', $response['body']['url']); + $this->assertEquals('Legal company', $response['body']['legalName']); + $this->assertEquals('Slovakia', $response['body']['legalCountry']); + $this->assertEquals('Custom state', $response['body']['legalState']); + $this->assertEquals('Košice', $response['body']['legalCity']); + $this->assertEquals('Main street 32', $response['body']['legalAddress']); + $this->assertEquals('TAXID_123456', $response['body']['legalTaxId']); + $this->assertEquals(135, $response['body']['authDuration']); + $this->assertEquals(54, $response['body']['authLimit']); + $this->assertEquals(7, $response['body']['authSessionsLimit']); + $this->assertEquals(9, $response['body']['authPasswordHistory']); + $this->assertTrue($response['body']['authPasswordDictionary']); + $this->assertTrue($response['body']['authPersonalDataCheck']); + $this->assertFalse($response['body']['authDisposableEmails']); + $this->assertFalse($response['body']['authCanonicalEmails']); + $this->assertFalse($response['body']['authFreeEmails']); + $this->assertTrue($response['body']['authSessionAlerts']); + $this->assertTrue($response['body']['authMembershipsUserName']); + $this->assertTrue($response['body']['authMembershipsUserEmail']); + $this->assertTrue($response['body']['authMembershipsMfa']); + $this->assertTrue($response['body']['authMembershipsUserId']); + $this->assertTrue($response['body']['authMembershipsUserPhone']); + $this->assertTrue($response['body']['authInvalidateSessions']); + $this->assertTrue($response['body']['smtpEnabled']); + $this->assertSame('Custom sender', $response['body']['smtpSenderName']); + $this->assertSame('email@custom.com', $response['body']['smtpSenderEmail']); + $this->assertSame('Reply sender', $response['body']['smtpReplyToName']); + $this->assertSame('replyto@custom.com', $response['body']['smtpReplyToEmail']); + $this->assertSame('maildev', $response['body']['smtpHost']); + $this->assertSame(1025, $response['body']['smtpPort']); + $this->assertSame('', $response['body']['smtpUsername']); + $this->assertSame('', $response['body']['smtpPassword']); // Write only + $this->assertSame('', $response['body']['smtpSecure']); - $this->assertArrayHasKey('teamId', $response); - $this->assertIsString($response['teamId']); - $this->assertEquals($team['body']['$id'], $response['teamId']); + $this->assertCount(2, $response['body']['authMockNumbers']); + $this->assertEquals('+421123456789', $response['body']['authMockNumbers'][0]['phone']); + $this->assertEquals('+420987654321', $response['body']['authMockNumbers'][1]['phone']); + $this->assertEquals('123456', $response['body']['authMockNumbers'][0]['otp']); + $this->assertEquals('654321', $response['body']['authMockNumbers'][1]['otp']); - $this->assertArrayHasKey('logo', $response); - $this->assertIsString($response['logo']); - $this->assertEquals('https://google.com/logo.png', $response['logo']); - - $this->assertArrayHasKey('url', $response); - $this->assertIsString($response['url']); - $this->assertEquals('https://myapp.com/', $response['url']); - - $this->assertArrayHasKey('legalName', $response); - $this->assertIsString($response['legalName']); - $this->assertEquals('Legal company', $response['legalName']); - - $this->assertArrayHasKey('legalCountry', $response); - $this->assertIsString($response['legalCountry']); - $this->assertEquals('Slovakia', $response['legalCountry']); - - $this->assertArrayHasKey('legalState', $response); - $this->assertIsString($response['legalState']); - $this->assertEquals('Custom state', $response['legalState']); - - $this->assertArrayHasKey('legalCity', $response); - $this->assertIsString($response['legalCity']); - $this->assertEquals('Košice', $response['legalCity']); - - $this->assertArrayHasKey('legalAddress', $response); - $this->assertIsString($response['legalAddress']); - $this->assertEquals('Main street 32', $response['legalAddress']); - - $this->assertArrayHasKey('legalTaxId', $response); - $this->assertIsString($response['legalTaxId']); - $this->assertEquals('TAXID_123456', $response['legalTaxId']); - - $this->assertArrayHasKey('authDuration', $response); - $this->assertIsInt($response['authDuration']); - $this->assertEquals(135, $response['authDuration']); - - $this->assertArrayHasKey('authLimit', $response); - $this->assertIsInt($response['authLimit']); - $this->assertEquals(54, $response['authLimit']); - - $this->assertArrayHasKey('authSessionsLimit', $response); - $this->assertIsInt($response['authSessionsLimit']); - $this->assertEquals(7, $response['authLimit']); - - $this->assertArrayHasKey('authPasswordHistory', $response); - $this->assertIsInt($response['authPasswordHistory']); - $this->assertEquals(9, $response['authPasswordHistory']); - - $this->assertArrayHasKey('authPasswordDictionary', $response); - $this->assertIsBool($response['authPasswordDictionary']); - $this->assertTrue($response['authPasswordDictionary']); - - $this->assertArrayHasKey('authPersonalDataCheck', $response); - $this->assertIsBool($response['authPersonalDataCheck']); - $this->assertTrue($response['authPersonalDataCheck']); - - $this->assertArrayHasKey('authDisposableEmails', $response); - $this->assertIsBool($response['authDisposableEmails']); - $this->assertFalse($response['authDisposableEmails']); - - $this->assertArrayHasKey('authCanonicalEmails', $response); - $this->assertIsBool($response['authCanonicalEmails']); - $this->assertFalse($response['authCanonicalEmails']); - - $this->assertArrayHasKey('authFreeEmails', $response); - $this->assertIsBool($response['authFreeEmails']); - $this->assertFalse($response['authFreeEmails']); - - $this->assertArrayHasKey('authMockNumbers', $response); - $this->assertIsArray($response['authMockNumbers']); - $this->assertCount(2, $response['authMockNumbers']); - - $this->assertEquals('+421123456789', $response['authMockNumbers'][0]['number']); - $this->assertEquals('+420987654321', $response['authMockNumbers'][1]['number']); - - $this->assertEquals('123456', $response['authMockNumbers'][0]['otp']); - $this->assertEquals('654321', $response['authMockNumbers'][1]['otp']); - - foreach($response['authMockNumbers'] as $mockNumber) { - $this->assertArrayHasKey('$createdAt', $mockNumber); + foreach ($response['body']['authMockNumbers'] as $mockNumber) { $this->assertIsString($mockNumber['$createdAt']); + $this->assertNotEmpty($mockNumber['$createdAt']); $this->assertNotFalse(\strtotime($mockNumber['$createdAt'])); - - $this->assertArrayHasKey('$updatedAt', $mockNumber); + $this->assertIsString($mockNumber['$updatedAt']); + $this->assertNotEmpty($mockNumber['$updatedAt']); $this->assertNotFalse(\strtotime($mockNumber['$updatedAt'])); - $this->assertArrayHasKey('number', $mockNumber); - $this->assertIsString($mockNumber['number']); - $this->assertNotEmpty($mockNumber['number']); - - $this->assertArrayHasKey('otp', $mockNumber); + $this->assertIsString($mockNumber['phone']); + $this->assertNotEmpty($mockNumber['phone']); + $this->assertIsString($mockNumber['otp']); $this->assertNotEmpty($mockNumber['otp']); } - $this->assertArrayHasKey('authSessionAlerts', $response); - $this->assertIsBool($response['authSessionAlerts']); - $this->assertTrue($response['authSessionAlerts']); - - $this->assertArrayHasKey('authMembershipsUserName', $response); - $this->assertIsBool($response['authMembershipsUserName']); - $this->assertTrue($response['authMembershipsUserName']); - - $this->assertArrayHasKey('authMembershipsUserEmail', $response); - $this->assertIsBool($response['authMembershipsUserEmail']); - $this->assertTrue($response['authMembershipsUserEmail']); - - $this->assertArrayHasKey('authMembershipsMfa', $response); - $this->assertIsBool($response['authMembershipsMfa']); - $this->assertTrue($response['authMembershipsMfa']); - - $this->assertArrayHasKey('authMembershipsUserId', $response); - $this->assertIsBool($project['authMembershipsUserId']); - $this->assertTrue($response['authMembershipsUserId']); - - $this->assertArrayHasKey('authMembershipsUserPhone', $response); - $this->assertIsBool($response['authMembershipsUserPhone']); - $this->assertTrue($response['authMembershipsUserPhone']); - - $this->assertArrayHasKey('authInvalidateSessions', $response); - $this->assertIsBool($response['authInvalidateSessions']); - $this->assertTrue($response['authInvalidateSessions']); - - $this->assertArrayHasKey('smtpEnabled', $response); - $this->assertIsBool($response['smtpEnabled']); - $this->assertTrue($response['smtpEnabled']); - - $this->assertArrayHasKey('smtpSenderName', $response); - $this->assertIsString($response['smtpSenderName']); - $this->assertSame('Custom sender', $response['smtpSenderName']); - - $this->assertArrayHasKey('smtpSenderEmail', $response); - $this->assertIsString($response['smtpSenderEmail']); - $this->assertSame('email@custom.com', $response['smtpSenderEmail']); - - $this->assertArrayHasKey('smtpReplyToName', $response); - $this->assertIsString($response['smtpReplyToName']); - $this->assertSame('Reply sender', $response['smtpReplyToName']); - - $this->assertArrayHasKey('smtpReplyToEmail', $response); - $this->assertIsString($response['smtpReplyToEmail']); - $this->assertSame('replyto@custom.com', $response['smtpReplyToEmail']); - - $this->assertArrayHasKey('smtpHost', $response); - $this->assertIsString($response['smtpHost']); - $this->assertSame('maildev', $response['smtpHost']); - - $this->assertArrayHasKey('smtpPort', $response); - $this->assertIsInt($response['smtpPort']); - $this->assertSame(1025, $response['smtpPort']); - - $this->assertArrayHasKey('smtpUsername', $response); - $this->assertIsString($response['smtpUsername']); - $this->assertSame('', $response['smtpUsername']); - - $this->assertArrayHasKey('smtpPassword', $response); - $this->assertIsString($response['smtpPassword']); - $this->assertSame('', $response['smtpPassword']); - - $this->assertArrayHasKey('smtpSecure', $response); - $this->assertIsString($response['smtpSecure']); - $this->assertSame('', $response['smtpSecure']); - /* $this->assertArrayHasKey('oAuthProviders', $project); $this->assertIsArray($project['oAuthProviders']); @@ -1130,12 +1026,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertIsArray($project['devKeys']); */ - /* - - */ - - - /* + /* $this->assertArrayHasKey('pingCount', $project); $this->assertIsInt($project['pingCount']); @@ -1147,64 +1038,68 @@ class ProjectsConsoleClientTest extends Scope $this->assertArrayHasKey('status', $project); $this->assertIsString($project['status']); - */ + */ - /* + /* $auth = require(__DIR__ . '/../../../../app/config/auth.php'); foreach ($auth as $method) { - $key = 'auth' . ucfirst($method['key'] ?? ''); - $this->assertArrayHasKey($key, $project, 'Missing auth field: ' . $key); - $this->assertIsBool($project[$key], 'Auth field should be boolean: ' . $key); + $key = 'auth' . ucfirst($method['key'] ?? ''); + $this->assertArrayHasKey($key, $project, 'Missing auth field: ' . $key); + $this->assertIsBool($project[$key], 'Auth field should be boolean: ' . $key); } $services = require(__DIR__ . '/../../../../app/config/services.php'); foreach ($services as $service) { - if (!($service['optional'] ?? false)) { - continue; - } - $key = 'serviceStatusFor' . ucfirst($service['key'] ?? ''); - $this->assertArrayHasKey($key, $project, 'Missing service field: ' . $key); - $this->assertIsBool($project[$key], 'Service field should be boolean: ' . $key); + if (!($service['optional'] ?? false)) { + continue; + } + $key = 'serviceStatusFor' . ucfirst($service['key'] ?? ''); + $this->assertArrayHasKey($key, $project, 'Missing service field: ' . $key); + $this->assertIsBool($project[$key], 'Service field should be boolean: ' . $key); } // Dynamic protocol status fields $protocols = require(__DIR__ . '/../../../../app/config/protocols.php'); foreach ($protocols as $protocol) { - $key = 'protocolStatusFor' . ucfirst($protocol['key'] ?? ''); - $this->assertArrayHasKey($key, $project, 'Missing protocol field: ' . $key); - $this->assertIsBool($project[$key], 'Protocol field should be boolean: ' . $key); + $key = 'protocolStatusFor' . ucfirst($protocol['key'] ?? ''); + $this->assertArrayHasKey($key, $project, 'Missing protocol field: ' . $key); + $this->assertIsBool($project[$key], 'Protocol field should be boolean: ' . $key); } */ // Ensure policies can be falsy - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/password-dictionary', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-dictionary', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'enabled' => false ]); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/password-personal-data', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-personal-data', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'enabled' => false - ]); - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/session-alert', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'enabled' => false ]); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/membership-privacy', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/session-alert', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'enabled' => false + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/membership-privacy', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'userId' => false, 'userEmail' => false, @@ -1214,9 +1109,10 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/' . $id . '/policies/session-invalidation', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/session-invalidation', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'enabled' => false ]); @@ -1228,7 +1124,8 @@ class ProjectsConsoleClientTest extends Scope '/project/smtp', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'enabled' => false, @@ -1239,71 +1136,27 @@ class ProjectsConsoleClientTest extends Scope 'secure' => 'ssl', ], ); - + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); - - $this->assertArrayHasKey('authPasswordDictionary', $response); - $this->assertIsBool($response['authPasswordDictionary']); - $this->assertFalse($response['authPasswordDictionary']); - $this->assertArrayHasKey('authPersonalDataCheck', $response); - $this->assertIsBool($response['authPersonalDataCheck']); - $this->assertFalse($response['authPersonalDataCheck']); - - $this->assertArrayHasKey('authSessionAlerts', $response); - $this->assertIsBool($response['authSessionAlerts']); - $this->assertFalse($response['authSessionAlerts']); - - $this->assertArrayHasKey('authMembershipsUserName', $response); - $this->assertIsBool($response['authMembershipsUserName']); - $this->assertFalse($response['authMembershipsUserName']); - - $this->assertArrayHasKey('authMembershipsUserEmail', $response); - $this->assertIsBool($response['authMembershipsUserEmail']); - $this->assertFalse($response['authMembershipsUserEmail']); - - $this->assertArrayHasKey('authMembershipsMfa', $response); - $this->assertIsBool($response['authMembershipsMfa']); - $this->assertFalse($response['authMembershipsMfa']); - - $this->assertArrayHasKey('authMembershipsUserId', $response); - $this->assertIsBool($project['authMembershipsUserId']); - $this->assertFalse($response['authMembershipsUserId']); - - $this->assertArrayHasKey('authMembershipsUserPhone', $response); - $this->assertIsBool($response['authMembershipsUserPhone']); - $this->assertFalse($response['authMembershipsUserPhone']); - - $this->assertArrayHasKey('authInvalidateSessions', $response); - $this->assertIsBool($response['authInvalidateSessions']); - $this->assertFalse($response['authInvalidateSessions']); - - $this->assertArrayHasKey('smtpEnabled', $response); - $this->assertIsBool($response['smtpEnabled']); - $this->assertFalse($response['smtpEnabled']); - - $this->assertArrayHasKey('smtpHost', $response); - $this->assertIsString($response['smtpHost']); - $this->assertSame('customhost.com', $response['smtpHost']); - - $this->assertArrayHasKey('smtpPort', $response); - $this->assertIsInt($response['smtpPort']); - $this->assertSame(4444, $response['smtpPort']); - - $this->assertArrayHasKey('smtpUsername', $response); - $this->assertIsString($response['smtpUsername']); - $this->assertSame('myuser', $response['smtpUsername']); - - $this->assertArrayHasKey('smtpPassword', $response); - $this->assertIsString($response['smtpPassword']); - $this->assertSame('', $response['smtpPassword']); - - $this->assertArrayHasKey('smtpSecure', $response); - $this->assertIsString($response['smtpSecure']); - $this->assertSame('ssl', $response['smtpSecure']); + $this->assertFalse($response['body']['authPasswordDictionary']); + $this->assertFalse($response['body']['authPersonalDataCheck']); + $this->assertFalse($response['body']['authSessionAlerts']); + $this->assertFalse($response['body']['authMembershipsUserName']); + $this->assertFalse($response['body']['authMembershipsUserEmail']); + $this->assertFalse($response['body']['authMembershipsMfa']); + $this->assertFalse($response['body']['authMembershipsUserId']); + $this->assertFalse($response['body']['authMembershipsUserPhone']); + $this->assertFalse($response['body']['authInvalidateSessions']); + $this->assertFalse($response['body']['smtpEnabled']); + $this->assertSame('customhost.com', $response['body']['smtpHost']); + $this->assertSame(4444, $response['body']['smtpPort']); + $this->assertSame('myuser', $response['body']['smtpUsername']); + $this->assertSame('', $response['body']['smtpPassword']); // Write only + $this->assertSame('ssl', $response['body']['smtpSecure']); /** * Test for FAILURE From 38575d7620c62dae3c54c80f4331c0c5b58112f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 7 May 2026 11:06:47 +0200 Subject: [PATCH 175/211] Improve get project tests --- .../Projects/ProjectsConsoleClientTest.php | 60 ++++++++++++------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index a8bfaa0f7f..4ab57a3012 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -1040,32 +1040,50 @@ class ProjectsConsoleClientTest extends Scope $this->assertIsString($project['status']); */ - /* - $auth = require(__DIR__ . '/../../../../app/config/auth.php'); - foreach ($auth as $method) { - $key = 'auth' . ucfirst($method['key'] ?? ''); - $this->assertArrayHasKey($key, $project, 'Missing auth field: ' . $key); - $this->assertIsBool($project[$key], 'Auth field should be boolean: ' . $key); + $authsKeys = [ + 'authEmailPassword', + 'authUsersAuthMagicURL', + 'authEmailOtp', + 'authAnonymous', + 'authInvites', + 'authJWT', + 'authPhone', + ]; + foreach ($authsKeys as $authsKey) { + $this->assertTrue($response['body'][$authsKey], 'Auth method should be enabled: ' . $authsKey); } - $services = require(__DIR__ . '/../../../../app/config/services.php'); - foreach ($services as $service) { - if (!($service['optional'] ?? false)) { - continue; - } - $key = 'serviceStatusFor' . ucfirst($service['key'] ?? ''); - $this->assertArrayHasKey($key, $project, 'Missing service field: ' . $key); - $this->assertIsBool($project[$key], 'Service field should be boolean: ' . $key); + $serviceKeys = [ + 'serviceStatusForAccount', + 'serviceStatusForAvatars', + 'serviceStatusForDatabases', + 'serviceStatusForTablesdb', + 'serviceStatusForLocale', + 'serviceStatusForHealth', + 'serviceStatusForProject', + 'serviceStatusForStorage', + 'serviceStatusForTeams', + 'serviceStatusForUsers', + 'serviceStatusForVcs', + 'serviceStatusForSites', + 'serviceStatusForFunctions', + 'serviceStatusForProxy', + 'serviceStatusForGraphql', + 'serviceStatusForMigrations', + 'serviceStatusForMessaging', + ]; + foreach ($serviceKeys as $serviceKey) { + $this->assertTrue($response['body'][$serviceKey], 'Service should be enabled: ' . $serviceKey); } - // Dynamic protocol status fields - $protocols = require(__DIR__ . '/../../../../app/config/protocols.php'); - foreach ($protocols as $protocol) { - $key = 'protocolStatusFor' . ucfirst($protocol['key'] ?? ''); - $this->assertArrayHasKey($key, $project, 'Missing protocol field: ' . $key); - $this->assertIsBool($project[$key], 'Protocol field should be boolean: ' . $key); + $protocolKeys = [ + 'protocolStatusForRest', + 'protocolStatusForGraphql', + 'protocolStatusForWebsocket', + ]; + foreach ($protocolKeys as $protocolKey) { + $this->assertTrue($response['body'][$protocolKey], 'Protocol should be enabled: ' . $protocolKey); } - */ // Ensure policies can be falsy From 379a388f61d33751618b2e7a0a4196b9f6f4a618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 7 May 2026 11:12:05 +0200 Subject: [PATCH 176/211] auth security get project tests --- .../Projects/ProjectsConsoleClientTest.php | 128 +++++++++++++++++- 1 file changed, 124 insertions(+), 4 deletions(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 4ab57a3012..324d7d2bdb 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -1050,7 +1050,7 @@ class ProjectsConsoleClientTest extends Scope 'authPhone', ]; foreach ($authsKeys as $authsKey) { - $this->assertTrue($response['body'][$authsKey], 'Auth method should be enabled: ' . $authsKey); + $this->assertTrue($response['body'][$authsKey], 'Auth method should be enabled: ' . $authsKey); } $serviceKeys = [ @@ -1073,7 +1073,7 @@ class ProjectsConsoleClientTest extends Scope 'serviceStatusForMessaging', ]; foreach ($serviceKeys as $serviceKey) { - $this->assertTrue($response['body'][$serviceKey], 'Service should be enabled: ' . $serviceKey); + $this->assertTrue($response['body'][$serviceKey], 'Service should be enabled: ' . $serviceKey); } $protocolKeys = [ @@ -1082,10 +1082,10 @@ class ProjectsConsoleClientTest extends Scope 'protocolStatusForWebsocket', ]; foreach ($protocolKeys as $protocolKey) { - $this->assertTrue($response['body'][$protocolKey], 'Protocol should be enabled: ' . $protocolKey); + $this->assertTrue($response['body'][$protocolKey], 'Protocol should be enabled: ' . $protocolKey); } - // Ensure policies can be falsy + // Ensure booleans can be falsy $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-dictionary', array_merge([ 'content-type' => 'application/json', @@ -1136,6 +1136,78 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); + // Toggle auth methods, services, protocols + + $authMethods = ['email-password', 'magic-url', 'email-otp', 'anonymous', 'invites', 'jwt', 'phone']; + foreach ($authMethods as $authMethod) { + $response = $this->client->call( + Client::METHOD_PATCH, + '/project/auth-methods/' . $authMethod, + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), + [ + 'enabled' => false, + ], + ); + $this->assertEquals(200, $response['headers']['status-code']); + } + + $protocols = ['rest', 'graphql', 'websocket']; + foreach ($protocols as $protocol) { + $response = $this->client->call( + Client::METHOD_PATCH, + '/project/protocols/' . $protocol, + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), + [ + 'enabled' => false, + ], + ); + $this->assertEquals(200, $response['headers']['status-code']); + } + + $services = [ + 'account', + 'avatars', + 'databases', + 'tablesdb', + 'locale', + 'health', + 'project', + 'storage', + 'teams', + 'users', + 'vcs', + 'sites', + 'functions', + 'proxy', + 'graphql', + 'migrations', + 'messaging', + ]; + + foreach ($services as $service) { + $response = $this->client->call( + Client::METHOD_PATCH, + '/project/services/' . $service, + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), + [ + 'enabled' => false, + ], + ); + $this->assertEquals(200, $response['headers']['status-code']); + } + // Configure SMTP $response = $this->client->call( Client::METHOD_PATCH, @@ -1154,12 +1226,15 @@ class ProjectsConsoleClientTest extends Scope 'secure' => 'ssl', ], ); + $this->assertEquals(200, $response['headers']['status-code']); $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertFalse($response['body']['authPasswordDictionary']); $this->assertFalse($response['body']['authPersonalDataCheck']); $this->assertFalse($response['body']['authSessionAlerts']); @@ -1176,6 +1251,51 @@ class ProjectsConsoleClientTest extends Scope $this->assertSame('', $response['body']['smtpPassword']); // Write only $this->assertSame('ssl', $response['body']['smtpSecure']); + $authsKeys = [ + 'authEmailPassword', + 'authUsersAuthMagicURL', + 'authEmailOtp', + 'authAnonymous', + 'authInvites', + 'authJWT', + 'authPhone', + ]; + foreach ($authsKeys as $authsKey) { + $this->assertFalse($response['body'][$authsKey], 'Auth method should be enabled: ' . $authsKey); + } + + $serviceKeys = [ + 'serviceStatusForAccount', + 'serviceStatusForAvatars', + 'serviceStatusForDatabases', + 'serviceStatusForTablesdb', + 'serviceStatusForLocale', + 'serviceStatusForHealth', + 'serviceStatusForProject', + 'serviceStatusForStorage', + 'serviceStatusForTeams', + 'serviceStatusForUsers', + 'serviceStatusForVcs', + 'serviceStatusForSites', + 'serviceStatusForFunctions', + 'serviceStatusForProxy', + 'serviceStatusForGraphql', + 'serviceStatusForMigrations', + 'serviceStatusForMessaging', + ]; + foreach ($serviceKeys as $serviceKey) { + $this->assertFalse($response['body'][$serviceKey], 'Service should be enabled: ' . $serviceKey); + } + + $protocolKeys = [ + 'protocolStatusForRest', + 'protocolStatusForGraphql', + 'protocolStatusForWebsocket', + ]; + foreach ($protocolKeys as $protocolKey) { + $this->assertFalse($response['body'][$protocolKey], 'Protocol should be enabled: ' . $protocolKey); + } + /** * Test for FAILURE */ From c4a941015ff453ad0090154dad96ad6b39ee6264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 7 May 2026 11:26:55 +0200 Subject: [PATCH 177/211] Continue adding project get tests --- .../Projects/ProjectsConsoleClientTest.php | 97 +++++++++++++++---- 1 file changed, 80 insertions(+), 17 deletions(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 324d7d2bdb..96416cbd5a 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -15,6 +15,7 @@ use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; use Utopia\Database\Query; +use Utopia\Database\Validator\Datetime as ValidatorDatetime; use Utopia\System\System; class ProjectsConsoleClientTest extends Scope @@ -802,6 +803,19 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $id = $response['body']['$id']; + // Increase ping 3x + for ($i = 0; $i < 3; $i++) { + $response = $this->client->call( + Client::METHOD_GET, + '/ping', + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ], $this->getHeaders()), + ); + $this->assertEquals(200, $response['headers']['status-code']); + } + // Configure SMTP $response = $this->client->call( Client::METHOD_PATCH, @@ -834,6 +848,33 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(201, $response['headers']['status-code']); + // Add labels + $response = $this->client->call(Client::METHOD_PUT, '/project/labels', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'labels' => ['custom1', 'custom2'] + ]); + $this->assertEquals(200, $response['headers']['status-code']); + + // Create dev keys + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([ + 'content-type' => 'application/json', + ], $this->getHeaders()), [ + 'name' => 'Custom key 1', + 'expire' => '2026-05-07 09:23:30.713', + ]); + $this->assertEquals(201, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([ + 'content-type' => 'application/json', + ], $this->getHeaders()), [ + 'name' => 'Custom key 2', + 'expire' => '2026-05-07 11:23:30.713' + ]); + $this->assertEquals(201, $response['headers']['status-code']); + $response = $this->client->call(Client::METHOD_POST, '/project/mock-phones', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, @@ -952,6 +993,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('My description', $response['body']['description']); $this->assertEquals($team['body']['$id'], $response['body']['teamId']); + $this->assertEquals('active', $response['body']['status']); $this->assertEquals('https://google.com/logo.png', $response['body']['logo']); $this->assertEquals('https://myapp.com/', $response['body']['url']); $this->assertEquals('Legal company', $response['body']['legalName']); @@ -986,7 +1028,44 @@ class ProjectsConsoleClientTest extends Scope $this->assertSame('', $response['body']['smtpUsername']); $this->assertSame('', $response['body']['smtpPassword']); // Write only $this->assertSame('', $response['body']['smtpSecure']); + $this->assertSame(3, $response['body']['pingCount']); + $this->assertIsString($response['body']['pingedAt']); + $this->assertNotEmpty($response['body']['pingedAt']); + $this->assertNotFalse(\strtotime($response['body']['pingedAt'])); + + $this->assertCount(2, $response['body']['labels']); + $this->assertEquals('custom1', $response['body']['labels'][0]); + $this->assertEquals('custom2', $response['body']['labels'][1]); + + $this->assertCount(2, $response['body']['devKeys']); + $this->assertEquals('Custom key 1', $response['body']['devKeys'][0]['name']); + $this->assertEquals('Custom key 2', $response['body']['devKeys'][1]['name']); + $this->assertEquals('2026-05-07T09:23:30.713+00:00', $response['body']['devKeys'][0]['expire']); + $this->assertEquals('2026-05-07T11:23:30.713+00:00', $response['body']['devKeys'][1]['expire']); + + foreach ($response['body']['devKeys'] as $devKey) { + $this->assertIsString($devKey['$id']); + $this->assertNotEmpty($devKey['$id']); + + $this->assertIsString($devKey['secret']); + $this->assertNotEmpty($devKey['secret']); + + $this->assertIsString($devKey['accessedAt']); + $this->assertEmpty($devKey['accessedAt']); + + $this->assertIsString($devKey['$createdAt']); + $this->assertNotEmpty($devKey['$createdAt']); + $this->assertNotFalse(\strtotime($devKey['$createdAt'])); + + $this->assertIsString($devKey['$updatedAt']); + $this->assertNotEmpty($devKey['$updatedAt']); + $this->assertNotFalse(\strtotime($devKey['$updatedAt'])); + + $this->assertIsArray($devKey['sdks']); + $this->assertCount(0, $devKey['sdks']); + } + $this->assertCount(2, $response['body']['authMockNumbers']); $this->assertEquals('+421123456789', $response['body']['authMockNumbers'][0]['phone']); $this->assertEquals('+420987654321', $response['body']['authMockNumbers'][1]['phone']); @@ -1010,6 +1089,7 @@ class ProjectsConsoleClientTest extends Scope } /* + TODO: $this->assertArrayHasKey('oAuthProviders', $project); $this->assertIsArray($project['oAuthProviders']); @@ -1021,25 +1101,8 @@ class ProjectsConsoleClientTest extends Scope $this->assertArrayHasKey('keys', $project); $this->assertIsArray($project['keys']); - - $this->assertArrayHasKey('devKeys', $project); - $this->assertIsArray($project['devKeys']); */ - /* - $this->assertArrayHasKey('pingCount', $project); - $this->assertIsInt($project['pingCount']); - - $this->assertArrayHasKey('pingedAt', $project); - $this->assertIsString($project['pingedAt']); - - $this->assertArrayHasKey('labels', $project); - $this->assertIsArray($project['labels']); - - $this->assertArrayHasKey('status', $project); - $this->assertIsString($project['status']); - */ - $authsKeys = [ 'authEmailPassword', 'authUsersAuthMagicURL', From 0b881ec58ae29147bbc44a2df5742f0067b9bc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 7 May 2026 11:45:25 +0200 Subject: [PATCH 178/211] Finish test improvements for get project --- .../Projects/ProjectsConsoleClientTest.php | 149 ++++++++++++++++-- 1 file changed, 133 insertions(+), 16 deletions(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 96416cbd5a..95859f8dea 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -15,7 +15,6 @@ use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; use Utopia\Database\Query; -use Utopia\Database\Validator\Datetime as ValidatorDatetime; use Utopia\System\System; class ProjectsConsoleClientTest extends Scope @@ -866,7 +865,7 @@ class ProjectsConsoleClientTest extends Scope 'expire' => '2026-05-07 09:23:30.713', ]); $this->assertEquals(201, $response['headers']['status-code']); - + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([ 'content-type' => 'application/json', ], $this->getHeaders()), [ @@ -971,6 +970,57 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); + // Create webhook + $webhook = $this->client->call(Client::METHOD_POST, '/webhooks', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'webhookId' => 'unique()', + 'name' => 'Webhook Test', + 'events' => ['users.*.create', 'users.*.update.email'], + 'url' => 'https://appwrite.io', + 'tls' => true, + 'authUsername' => 'username', + 'authPassword' => 'password', + ]); + $this->assertEquals(201, $webhook['headers']['status-code']); + + // Create API key + $key = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'keyId' => ID::unique(), + 'name' => 'Key Test', + 'scopes' => ['teams.read', 'teams.write'], + ]); + $this->assertEquals(201, $key['headers']['status-code']); + + // Create platform + $platform = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'platformId' => ID::unique(), + 'type' => 'web', + 'name' => 'Web App', + 'hostname' => 'localhost', + ]); + $this->assertEquals(201, $platform['headers']['status-code']); + + // Configure OAuth provider + $oauth = $this->client->call(Client::METHOD_PATCH, '/project/oauth2/github', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'clientId' => 'github-client-id', + 'clientSecret' => 'github-client-secret', + 'enabled' => false, + ]); + $this->assertEquals(200, $oauth['headers']['status-code']); + /** * Test for SUCCESS */ @@ -1053,7 +1103,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertIsString($devKey['accessedAt']); $this->assertEmpty($devKey['accessedAt']); - + $this->assertIsString($devKey['$createdAt']); $this->assertNotEmpty($devKey['$createdAt']); $this->assertNotFalse(\strtotime($devKey['$createdAt'])); @@ -1061,11 +1111,11 @@ class ProjectsConsoleClientTest extends Scope $this->assertIsString($devKey['$updatedAt']); $this->assertNotEmpty($devKey['$updatedAt']); $this->assertNotFalse(\strtotime($devKey['$updatedAt'])); - + $this->assertIsArray($devKey['sdks']); $this->assertCount(0, $devKey['sdks']); } - + $this->assertCount(2, $response['body']['authMockNumbers']); $this->assertEquals('+421123456789', $response['body']['authMockNumbers'][0]['phone']); $this->assertEquals('+420987654321', $response['body']['authMockNumbers'][1]['phone']); @@ -1088,20 +1138,87 @@ class ProjectsConsoleClientTest extends Scope $this->assertNotEmpty($mockNumber['otp']); } - /* - TODO: - $this->assertArrayHasKey('oAuthProviders', $project); - $this->assertIsArray($project['oAuthProviders']); + $this->assertIsArray($response['body']['oAuthProviders']); + $this->assertGreaterThan(0, count($response['body']['oAuthProviders'])); - $this->assertArrayHasKey('platforms', $project); - $this->assertIsArray($project['platforms']); + $githubProvider = null; + foreach ($response['body']['oAuthProviders'] as $provider) { + $this->assertIsString($provider['key']); + $this->assertNotEmpty($provider['key']); - $this->assertArrayHasKey('webhooks', $project); - $this->assertIsArray($project['webhooks']); + $this->assertIsString($provider['name']); + $this->assertIsString($provider['appId']); + $this->assertIsString($provider['secret']); + $this->assertIsBool($provider['enabled']); - $this->assertArrayHasKey('keys', $project); - $this->assertIsArray($project['keys']); - */ + if ($provider['key'] === 'github') { + $githubProvider = $provider; + } + } + + $this->assertNotNull($githubProvider, 'GitHub provider not found'); + $this->assertEquals('github-client-id', $githubProvider['appId']); + $this->assertEquals('', $githubProvider['secret']); // Write only + $this->assertEquals(false, $githubProvider['enabled']); + + $this->assertIsArray($response['body']['platforms']); + $this->assertCount(1, $response['body']['platforms']); + $this->assertIsString($response['body']['platforms'][0]['$id']); + $this->assertNotEmpty($response['body']['platforms'][0]['$id']); + $this->assertEquals('Web App', $response['body']['platforms'][0]['name']); + $this->assertEquals('web', $response['body']['platforms'][0]['type']); + $this->assertEquals('localhost', $response['body']['platforms'][0]['hostname']); + + $this->assertIsString($response['body']['platforms'][0]['$createdAt']); + $this->assertNotEmpty($response['body']['platforms'][0]['$createdAt']); + $this->assertNotFalse(\strtotime($response['body']['platforms'][0]['$createdAt'])); + + $this->assertIsString($response['body']['platforms'][0]['$updatedAt']); + $this->assertNotEmpty($response['body']['platforms'][0]['$updatedAt']); + $this->assertNotFalse(\strtotime($response['body']['platforms'][0]['$updatedAt'])); + + $this->assertArrayHasKey('webhooks', $response['body']); + $this->assertIsArray($response['body']['webhooks']); + $this->assertCount(1, $response['body']['webhooks']); + $this->assertIsString($response['body']['webhooks'][0]['$id']); + $this->assertNotEmpty($response['body']['webhooks'][0]['$id']); + $this->assertEquals('Webhook Test', $response['body']['webhooks'][0]['name']); + $this->assertEquals('https://appwrite.io', $response['body']['webhooks'][0]['url']); + $this->assertContains('users.*.create', $response['body']['webhooks'][0]['events']); + $this->assertContains('users.*.update.email', $response['body']['webhooks'][0]['events']); + $this->assertCount(2, $response['body']['webhooks'][0]['events']); + $this->assertTrue($response['body']['webhooks'][0]['tls']); + $this->assertEquals('username', $response['body']['webhooks'][0]['authUsername']); + $this->assertEquals('password', $response['body']['webhooks'][0]['authPassword']); + $this->assertTrue($response['body']['webhooks'][0]['enabled']); + $this->assertIsString($response['body']['webhooks'][0]['secret']); + $this->assertNotEmpty($response['body']['webhooks'][0]['secret']); + $this->assertIsString($response['body']['webhooks'][0]['$createdAt']); + $this->assertNotEmpty($response['body']['webhooks'][0]['$createdAt']); + $this->assertNotFalse(\strtotime($response['body']['webhooks'][0]['$createdAt'])); + $this->assertIsString($response['body']['webhooks'][0]['$updatedAt']); + $this->assertNotEmpty($response['body']['webhooks'][0]['$updatedAt']); + $this->assertNotFalse(\strtotime($response['body']['webhooks'][0]['$updatedAt'])); + + $this->assertArrayHasKey('keys', $response['body']); + $this->assertIsArray($response['body']['keys']); + $this->assertCount(1, $response['body']['keys']); + $this->assertIsString($response['body']['keys'][0]['$id']); + $this->assertNotEmpty($response['body']['keys'][0]['$id']); + $this->assertEquals('Key Test', $response['body']['keys'][0]['name']); + $this->assertContains('teams.read', $response['body']['keys'][0]['scopes']); + $this->assertContains('teams.write', $response['body']['keys'][0]['scopes']); + $this->assertCount(2, $response['body']['keys'][0]['scopes']); + $this->assertNotEmpty($response['body']['keys'][0]['secret']); + $this->assertEmpty($response['body']['keys'][0]['accessedAt']); + $this->assertIsArray($response['body']['keys'][0]['sdks']); + $this->assertCount(0, $response['body']['keys'][0]['sdks']); + $this->assertIsString($response['body']['keys'][0]['$createdAt']); + $this->assertNotEmpty($response['body']['keys'][0]['$createdAt']); + $this->assertNotFalse(\strtotime($response['body']['keys'][0]['$createdAt'])); + $this->assertIsString($response['body']['keys'][0]['$updatedAt']); + $this->assertNotEmpty($response['body']['keys'][0]['$updatedAt']); + $this->assertNotFalse(\strtotime($response['body']['keys'][0]['$updatedAt'])); $authsKeys = [ 'authEmailPassword', From a1e51d27eb0b1c4f6ed96c6968d6927e0cf0ed49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 7 May 2026 11:57:14 +0200 Subject: [PATCH 179/211] PR review fixes --- phpunit.xml | 2 +- .../Projects/ProjectsConsoleClientTest.php | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index b566e232cd..9748c5a5c8 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -5,7 +5,7 @@ bootstrap="app/init.php" colors="true" processIsolation="false" - stopOnFailure="true" + stopOnFailure="false" stopOnError="false" cacheDirectory=".phpunit.cache" > diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 95859f8dea..8b0c1af57f 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -862,7 +862,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', ], $this->getHeaders()), [ 'name' => 'Custom key 1', - 'expire' => '2026-05-07 09:23:30.713', + 'expire' => '2099-05-07 09:23:30.713', ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -870,7 +870,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', ], $this->getHeaders()), [ 'name' => 'Custom key 2', - 'expire' => '2026-05-07 11:23:30.713' + 'expire' => '2099-05-07 11:23:30.713' ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -1091,8 +1091,8 @@ class ProjectsConsoleClientTest extends Scope $this->assertCount(2, $response['body']['devKeys']); $this->assertEquals('Custom key 1', $response['body']['devKeys'][0]['name']); $this->assertEquals('Custom key 2', $response['body']['devKeys'][1]['name']); - $this->assertEquals('2026-05-07T09:23:30.713+00:00', $response['body']['devKeys'][0]['expire']); - $this->assertEquals('2026-05-07T11:23:30.713+00:00', $response['body']['devKeys'][1]['expire']); + $this->assertEquals('2099-05-07T09:23:30.713+00:00', $response['body']['devKeys'][0]['expire']); + $this->assertEquals('2099-05-07T11:23:30.713+00:00', $response['body']['devKeys'][1]['expire']); foreach ($response['body']['devKeys'] as $devKey) { $this->assertIsString($devKey['$id']); @@ -1441,7 +1441,7 @@ class ProjectsConsoleClientTest extends Scope 'authPhone', ]; foreach ($authsKeys as $authsKey) { - $this->assertFalse($response['body'][$authsKey], 'Auth method should be enabled: ' . $authsKey); + $this->assertFalse($response['body'][$authsKey], 'Auth method should be disabled: ' . $authsKey); } $serviceKeys = [ @@ -1464,7 +1464,7 @@ class ProjectsConsoleClientTest extends Scope 'serviceStatusForMessaging', ]; foreach ($serviceKeys as $serviceKey) { - $this->assertFalse($response['body'][$serviceKey], 'Service should be enabled: ' . $serviceKey); + $this->assertFalse($response['body'][$serviceKey], 'Service should be disabled: ' . $serviceKey); } $protocolKeys = [ @@ -1473,7 +1473,7 @@ class ProjectsConsoleClientTest extends Scope 'protocolStatusForWebsocket', ]; foreach ($protocolKeys as $protocolKey) { - $this->assertFalse($response['body'][$protocolKey], 'Protocol should be enabled: ' . $protocolKey); + $this->assertFalse($response['body'][$protocolKey], 'Protocol should be disabled: ' . $protocolKey); } /** From 7e9d6f33c8377e19bd9f15efc5ed989b7e467f6e Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 7 May 2026 15:56:44 +0530 Subject: [PATCH 180/211] updated methods --- src/Appwrite/SDK/Specification/Format.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Appwrite/SDK/Specification/Format.php b/src/Appwrite/SDK/Specification/Format.php index 30df5acf52..69bdf7f67a 100644 --- a/src/Appwrite/SDK/Specification/Format.php +++ b/src/Appwrite/SDK/Specification/Format.php @@ -743,6 +743,18 @@ abstract class Format break; case 'project': switch ($method) { + case 'updateAuthMethod': + switch ($param) { + case 'methodId': + return 'AuthMethodId'; + } + break; + case 'getPolicy': + switch ($param) { + case 'policyId': + return 'ProjectPolicyId'; + } + break; case 'getEmailTemplate': case 'updateEmailTemplate': switch ($param) { From 706459e3140d6dc27470bcfb0eba9a5ebe4f6418 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 7 May 2026 16:01:52 +0530 Subject: [PATCH 181/211] updated --- src/Appwrite/SDK/Specification/Format.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/SDK/Specification/Format.php b/src/Appwrite/SDK/Specification/Format.php index 69bdf7f67a..8db06b726a 100644 --- a/src/Appwrite/SDK/Specification/Format.php +++ b/src/Appwrite/SDK/Specification/Format.php @@ -746,7 +746,7 @@ abstract class Format case 'updateAuthMethod': switch ($param) { case 'methodId': - return 'AuthMethodId'; + return 'AuthMethod'; } break; case 'getPolicy': From 7917506b5880d267fdf50bd618d030e442efb166 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 7 May 2026 16:30:23 +0530 Subject: [PATCH 182/211] updated oauth --- src/Appwrite/SDK/Specification/Format.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Appwrite/SDK/Specification/Format.php b/src/Appwrite/SDK/Specification/Format.php index 8db06b726a..32ef4723f1 100644 --- a/src/Appwrite/SDK/Specification/Format.php +++ b/src/Appwrite/SDK/Specification/Format.php @@ -755,6 +755,12 @@ abstract class Format return 'ProjectPolicyId'; } break; + case 'getOAuth2Provider': + switch ($param) { + case 'providerId': + return 'OAuthProvider'; + } + break; case 'getEmailTemplate': case 'updateEmailTemplate': switch ($param) { From 399f75e8e7a02d9b386a3af164c67e0c70d8d8ce Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 7 May 2026 16:35:56 +0530 Subject: [PATCH 183/211] updated --- src/Appwrite/SDK/Specification/Format.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Appwrite/SDK/Specification/Format.php b/src/Appwrite/SDK/Specification/Format.php index 32ef4723f1..777479f7e3 100644 --- a/src/Appwrite/SDK/Specification/Format.php +++ b/src/Appwrite/SDK/Specification/Format.php @@ -68,6 +68,17 @@ abstract class Format 'mock-unverified' ], ], + [ + 'namespace' => 'project', + 'methods' => [ + 'getOAuth2Provider' + ], + 'parameter' => 'providerId', + 'excludeKeys' => [ + 'mock', + 'mock-unverified' + ], + ], ]; /** From e4b51d0abbc4d1820b34e38bb067c60274c14885 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 7 May 2026 13:10:05 +0100 Subject: [PATCH 184/211] Drop custom utopia-php/migration VCS repo (now resolved via Packagist) --- composer.json | 8 +------- composer.lock | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index e396f6ad10..4a60944351 100644 --- a/composer.json +++ b/composer.json @@ -118,11 +118,5 @@ "php-http/discovery": true, "tbachert/spi": true } - }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/utopia-php/migration" - } - ] + } } diff --git a/composer.lock b/composer.lock index a1f8309c17..eb06192bb9 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": "d0e14ee465162e3b5e56d6cef9ddbb8d", + "content-hash": "acd8a12e57d36a970effa84f5c8ccf50", "packages": [ { "name": "adhocore/jwt", From 409cebb26e4f50fb041b54a5f0552dc4a9277a89 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 8 May 2026 00:12:20 +1200 Subject: [PATCH 185/211] Apply suggestion from @greptile-apps[bot] Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- src/Appwrite/Platform/Workers/Migrations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index c893d022b8..bf64285299 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -556,7 +556,7 @@ class Migrations extends Action } elseif ($th instanceof MigrationException) { $publish = false; } else { - $publish = true; + $publish = $th->getCode() === 0 || $th->getCode() >= 500; } if ($publish) { From 7d0843cc7fa9c94c9c4332f028c7604eb694909e Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 7 May 2026 13:23:21 +0100 Subject: [PATCH 186/211] Migrate queueForBuilds to publisherForBuilds pattern Replaces the stateful Appwrite\Event\Build queue class with a stateless BuildPublisher and BuildMessage DTO, matching the publisher pattern used by audits, certificates, executions, migrations, screenshots, stats, and usage. Call sites now enqueue messages directly instead of mutating a shared event object and relying on the API shutdown hook. Co-Authored-By: Claude Opus 4.7 --- app/controllers/shared/api.php | 13 +- app/init/resources.php | 5 + app/init/resources/request.php | 4 - app/init/worker/message.php | 5 - src/Appwrite/Event/Build.php | 146 ------------------ src/Appwrite/Event/Message/Build.php | 42 +++++ src/Appwrite/Event/Publisher/Build.php | 27 ++++ .../Platform/Modules/Compute/Base.php | 33 ++-- .../Functions/Http/Deployments/Create.php | 22 ++- .../Http/Deployments/Duplicate/Create.php | 24 ++- .../Http/Deployments/Template/Create.php | 27 ++-- .../Functions/Http/Deployments/Vcs/Create.php | 11 +- .../Functions/Http/Functions/Create.php | 23 +-- .../Functions/Http/Functions/Update.php | 12 +- .../Health/Http/Health/Queue/Builds/Get.php | 8 +- .../Health/Http/Health/Queue/Failed/Get.php | 8 +- .../Modules/Sites/Http/Deployments/Create.php | 18 ++- .../Http/Deployments/Duplicate/Create.php | 18 ++- .../Http/Deployments/Template/Create.php | 22 +-- .../Sites/Http/Deployments/Vcs/Create.php | 8 +- .../Modules/Sites/Http/Sites/Update.php | 12 +- .../Http/GitHub/Authorize/External/Update.php | 8 +- .../Modules/VCS/Http/GitHub/Deployment.php | 25 +-- .../Modules/VCS/Http/GitHub/Events/Create.php | 18 +-- 24 files changed, 251 insertions(+), 288 deletions(-) delete mode 100644 src/Appwrite/Event/Build.php create mode 100644 src/Appwrite/Event/Message/Build.php create mode 100644 src/Appwrite/Event/Publisher/Build.php diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index c9e4f8b47d..3ca45ea783 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -3,7 +3,6 @@ use Appwrite\Auth\Key; use Appwrite\Auth\MFA\Type\TOTP; use Appwrite\Bus\Events\RequestCompleted; -use Appwrite\Event\Build; use Appwrite\Event\Context\Audit as AuditContext; use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Delete; @@ -489,7 +488,6 @@ Http::init() ->inject('auditContext') ->inject('queueForDeletes') ->inject('queueForDatabase') - ->inject('queueForBuilds') ->inject('usage') ->inject('queueForFunctions') ->inject('queueForMails') @@ -503,7 +501,7 @@ Http::init() ->inject('telemetry') ->inject('platform') ->inject('authorization') - ->action(function (Http $utopia, Request $request, Response $response, Document $project, User $user, Event $queueForEvents, Messaging $queueForMessaging, AuditContext $auditContext, Delete $queueForDeletes, EventDatabase $queueForDatabase, Build $queueForBuilds, Context $usage, Func $queueForFunctions, Mail $queueForMails, Database $dbForProject, callable $timelimit, Document $resourceToken, string $mode, ?Key $apiKey, array $plan, Document $devKey, Telemetry $telemetry, array $platform, Authorization $authorization) { + ->action(function (Http $utopia, Request $request, Response $response, Document $project, User $user, Event $queueForEvents, Messaging $queueForMessaging, AuditContext $auditContext, Delete $queueForDeletes, EventDatabase $queueForDatabase, Context $usage, Func $queueForFunctions, Mail $queueForMails, Database $dbForProject, callable $timelimit, Document $resourceToken, string $mode, ?Key $apiKey, array $plan, Document $devKey, Telemetry $telemetry, array $platform, Authorization $authorization) { $response->setUser($user); $request->setUser($user); @@ -618,12 +616,10 @@ Http::init() $queueForDatabase->setProject($project); $queueForMessaging->setProject($project); $queueForFunctions->setProject($project); - $queueForBuilds->setProject($project); $queueForMails->setProject($project); /* Auto-set platforms */ $queueForFunctions->setPlatform($platform); - $queueForBuilds->setPlatform($platform); $queueForMails->setPlatform($platform); $useCache = $route->getLabel('cache', false); @@ -800,7 +796,6 @@ Http::shutdown() ->inject('publisherForUsage') ->inject('queueForDeletes') ->inject('queueForDatabase') - ->inject('queueForBuilds') ->inject('queueForMessaging') ->inject('queueForFunctions') ->inject('queueForWebhooks') @@ -812,7 +807,7 @@ Http::shutdown() ->inject('bus') ->inject('apiKey') ->inject('mode') - ->action(function (Http $utopia, Request $request, Response $response, Document $project, User $user, Event $queueForEvents, AuditContext $auditContext, Audit $publisherForAudits, Context $usage, UsagePublisher $publisherForUsage, Delete $queueForDeletes, EventDatabase $queueForDatabase, Build $queueForBuilds, Messaging $queueForMessaging, Func $queueForFunctions, Event $queueForWebhooks, Realtime $queueForRealtime, Database $dbForProject, Authorization $authorization, callable $timelimit, EventProcessor $eventProcessor, Bus $bus, ?Key $apiKey, string $mode) use ($parseLabel) { + ->action(function (Http $utopia, Request $request, Response $response, Document $project, User $user, Event $queueForEvents, AuditContext $auditContext, Audit $publisherForAudits, Context $usage, UsagePublisher $publisherForUsage, Delete $queueForDeletes, EventDatabase $queueForDatabase, Messaging $queueForMessaging, Func $queueForFunctions, Event $queueForWebhooks, Realtime $queueForRealtime, Database $dbForProject, Authorization $authorization, callable $timelimit, EventProcessor $eventProcessor, Bus $bus, ?Key $apiKey, string $mode) use ($parseLabel) { $responsePayload = $response->getPayload(); @@ -961,10 +956,6 @@ Http::shutdown() $queueForDatabase->trigger(); } - if (! empty($queueForBuilds->getType())) { - $queueForBuilds->trigger(); - } - if (! empty($queueForMessaging->getType())) { $queueForMessaging->trigger(); } diff --git a/app/init/resources.php b/app/init/resources.php index 96457294de..15f669b2d0 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -2,6 +2,7 @@ use Appwrite\Event\Event; use Appwrite\Event\Publisher\Audit as AuditPublisher; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Event\Publisher\Certificate as CertificatePublisher; use Appwrite\Event\Publisher\Execution as ExecutionPublisher; use Appwrite\Event\Publisher\Migration as MigrationPublisher; @@ -112,6 +113,10 @@ $container->set('publisherForStatsResources', fn (Publisher $publisher) => new S $publisher, new Queue(System::getEnv('_APP_STATS_RESOURCES_QUEUE_NAME', Event::STATS_RESOURCES_QUEUE_NAME)) ), ['publisher']); +$container->set('publisherForBuilds', fn (Publisher $publisher) => new BuildPublisher( + $publisher, + new Queue(System::getEnv('_APP_BUILDS_QUEUE_NAME', Event::BUILDS_QUEUE_NAME)) +), ['publisher']); /** * Platform configuration diff --git a/app/init/resources/request.php b/app/init/resources/request.php index 70d691370d..9fd282c4ed 100644 --- a/app/init/resources/request.php +++ b/app/init/resources/request.php @@ -4,7 +4,6 @@ use Ahc\Jwt\JWT; use Ahc\Jwt\JWTException; use Appwrite\Auth\Key; use Appwrite\Databases\TransactionState; -use Appwrite\Event\Build; use Appwrite\Event\Context\Audit as AuditContext; use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Delete; @@ -123,9 +122,6 @@ return function (Container $container): void { $container->set('queueForMails', function (Publisher $publisher) { return new Mail($publisher); }, ['publisher']); - $container->set('queueForBuilds', function (Publisher $publisher) { - return new Build($publisher); - }, ['publisher']); $container->set('queueForDatabase', function (Publisher $publisher) { return new EventDatabase($publisher); }, ['publisher']); diff --git a/app/init/worker/message.php b/app/init/worker/message.php index 17796fadcd..1469934ad4 100644 --- a/app/init/worker/message.php +++ b/app/init/worker/message.php @@ -1,6 +1,5 @@ set('queueForBuilds', function (Publisher $publisher) { - return new Build($publisher); - }, ['publisher']); - $container->set('queueForDeletes', function (Publisher $publisher) { return new Delete($publisher); }, ['publisher']); diff --git a/src/Appwrite/Event/Build.php b/src/Appwrite/Event/Build.php deleted file mode 100644 index 4eaf108f15..0000000000 --- a/src/Appwrite/Event/Build.php +++ /dev/null @@ -1,146 +0,0 @@ -setQueue(System::getEnv('_APP_BUILDS_QUEUE_NAME', Event::BUILDS_QUEUE_NAME)) - ->setClass(System::getEnv('_APP_BUILDS_CLASS_NAME', Event::BUILDS_CLASS_NAME)); - } - - /** - * Sets template for the build event. - * - * @param Document $template - * @return self - */ - public function setTemplate(Document $template): self - { - $this->template = $template; - - return $this; - } - - /** - * Sets resource document for the build event. - * - * @param Document $resource - * @return self - */ - public function setResource(Document $resource): self - { - $this->resource = $resource; - - return $this; - } - - /** - * Returns set resource document for the build event. - * - * @return null|Document - */ - public function getResource(): ?Document - { - return $this->resource; - } - - /** - * Sets deployment for the build event. - * - * @param Document $deployment - * @return self - */ - public function setDeployment(Document $deployment): self - { - $this->deployment = $deployment; - - return $this; - } - - /** - * Returns set deployment for the build event. - * - * @return null|Document - */ - public function getDeployment(): ?Document - { - return $this->deployment; - } - - /** - * Sets type for the build event. - * - * @param string $type Can be `BUILD_TYPE_DEPLOYMENT` or `BUILD_TYPE_RETRY`. - * @return self - */ - public function setType(string $type): self - { - $this->type = $type; - - return $this; - } - - /** - * Returns set type for the function event. - * - * @return string - */ - public function getType(): string - { - return $this->type; - } - - /** - * Prepare payload for queue. - * - * @return array - */ - protected function preparePayload(): array - { - $platform = $this->platform; - if (empty($platform)) { - $platform = Config::getParam('platform', []); - } - - return [ - 'project' => $this->project, - 'resource' => $this->resource, - 'deployment' => $this->deployment, - 'type' => $this->type, - 'template' => $this->template, - 'platform' => $platform, - ]; - } - - /** - * Resets event. - * - * @return self - */ - public function reset(): self - { - $this->type = ''; - $this->resource = null; - $this->deployment = null; - $this->template = null; - $this->platform = []; - parent::reset(); - - return $this; - } -} diff --git a/src/Appwrite/Event/Message/Build.php b/src/Appwrite/Event/Message/Build.php new file mode 100644 index 0000000000..7dfc8ea39a --- /dev/null +++ b/src/Appwrite/Event/Message/Build.php @@ -0,0 +1,42 @@ + $this->project->getArrayCopy(), + 'resource' => $this->resource->getArrayCopy(), + 'deployment' => $this->deployment->getArrayCopy(), + 'type' => $this->type, + 'template' => $this->template?->getArrayCopy() ?? [], + 'platform' => $this->platform, + ]; + } + + public static function fromArray(array $data): static + { + return new self( + project: new Document($data['project'] ?? []), + resource: new Document($data['resource'] ?? []), + deployment: new Document($data['deployment'] ?? []), + type: $data['type'] ?? '', + template: isset($data['template']) ? new Document($data['template']) : null, + platform: $data['platform'] ?? [], + ); + } +} diff --git a/src/Appwrite/Event/Publisher/Build.php b/src/Appwrite/Event/Publisher/Build.php new file mode 100644 index 0000000000..9b2a3b68a0 --- /dev/null +++ b/src/Appwrite/Event/Publisher/Build.php @@ -0,0 +1,27 @@ +publish($queue ?? $this->queue, $message); + } + + public function getSize(bool $failed = false, ?Queue $queue = null): int + { + return $this->getQueueSize($queue ?? $this->queue, $failed); + } +} diff --git a/src/Appwrite/Platform/Modules/Compute/Base.php b/src/Appwrite/Platform/Modules/Compute/Base.php index 85dfec3cfd..b0efac3829 100644 --- a/src/Appwrite/Platform/Modules/Compute/Base.php +++ b/src/Appwrite/Platform/Modules/Compute/Base.php @@ -2,7 +2,8 @@ namespace Appwrite\Platform\Modules\Compute; -use Appwrite\Event\Build; +use Appwrite\Event\Message\Build as BuildMessage; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\Filter\BranchDomain as BranchDomainFilter; use Appwrite\Platform\Action; @@ -57,7 +58,7 @@ class Base extends Action return $allowedSpecifications[0] ?? APP_COMPUTE_SPECIFICATION_DEFAULT; } - public function redeployVcsFunction(Request $request, Document $function, Document $project, Document $installation, Database $dbForProject, Build $queueForBuilds, Document $template, GitHub $github, bool $activate, string $referenceType = 'branch', string $reference = ''): Document + public function redeployVcsFunction(Request $request, Document $function, Document $project, Document $installation, Database $dbForProject, BuildPublisher $publisherForBuilds, Document $template, GitHub $github, bool $activate, array $platform = [], string $referenceType = 'branch', string $reference = ''): Document { $deploymentId = ID::unique(); $entrypoint = $function->getAttribute('entrypoint', ''); @@ -150,16 +151,19 @@ class Base extends Action 'latestDeploymentStatus' => $deployment->getAttribute('status', ''), ])); - $queueForBuilds - ->setType(BUILD_TYPE_DEPLOYMENT) - ->setResource($function) - ->setDeployment($deployment) - ->setTemplate($template); + $publisherForBuilds->enqueue(new BuildMessage( + project: $project, + resource: $function, + deployment: $deployment, + type: BUILD_TYPE_DEPLOYMENT, + template: $template, + platform: $platform, + )); return $deployment; } - public function redeployVcsSite(Request $request, Document $site, Document $project, Document $installation, Database $dbForProject, Database $dbForPlatform, Build $queueForBuilds, Document $template, GitHub $github, bool $activate, Authorization $authorization, array $platform, string $referenceType = 'branch', string $reference = ''): Document + public function redeployVcsSite(Request $request, Document $site, Document $project, Document $installation, Database $dbForProject, Database $dbForPlatform, BuildPublisher $publisherForBuilds, Document $template, GitHub $github, bool $activate, Authorization $authorization, array $platform, string $referenceType = 'branch', string $reference = ''): Document { $deploymentId = ID::unique(); $providerInstallationId = $installation->getAttribute('providerInstallationId', ''); @@ -358,11 +362,14 @@ class Base extends Action $this->updateEmptyManualRule($project, $site, $deployment, $dbForPlatform, $authorization); - $queueForBuilds - ->setType(BUILD_TYPE_DEPLOYMENT) - ->setResource($site) - ->setDeployment($deployment) - ->setTemplate($template); + $publisherForBuilds->enqueue(new BuildMessage( + project: $project, + resource: $site, + deployment: $deployment, + type: BUILD_TYPE_DEPLOYMENT, + template: $template, + platform: $platform, + )); return $deployment; } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php index 757edc0484..57c465faef 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php @@ -2,8 +2,9 @@ namespace Appwrite\Platform\Modules\Functions\Http\Deployments; -use Appwrite\Event\Build; use Appwrite\Event\Event; +use Appwrite\Event\Message\Build as BuildMessage; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -87,9 +88,10 @@ class Create extends Action ->inject('project') ->inject('deviceForFunctions') ->inject('deviceForLocal') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('plan') ->inject('authorization') + ->inject('platform') ->callback($this->action(...)); } @@ -106,9 +108,10 @@ class Create extends Action Document $project, Device $deviceForFunctions, Device $deviceForLocal, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, array $plan, - Authorization $authorization + Authorization $authorization, + array $platform ) { $activate = \strval($activate) === 'true' || \strval($activate) === '1'; @@ -272,10 +275,13 @@ class Create extends Action } // Start the build - $queueForBuilds - ->setType(BUILD_TYPE_DEPLOYMENT) - ->setResource($function) - ->setDeployment($deployment); + $publisherForBuilds->enqueue(new BuildMessage( + project: $project, + resource: $function, + deployment: $deployment, + type: BUILD_TYPE_DEPLOYMENT, + platform: $platform, + )); } else { if ($deployment->isEmpty()) { $deployment = $dbForProject->createDocument('deployments', new Document([ diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php index 9884b12dba..76070c8bf5 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php @@ -2,8 +2,9 @@ namespace Appwrite\Platform\Modules\Functions\Http\Deployments\Duplicate; -use Appwrite\Event\Build; use Appwrite\Event\Event; +use Appwrite\Event\Message\Build as BuildMessage; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -61,8 +62,10 @@ class Create extends Action ->inject('response') ->inject('dbForProject') ->inject('queueForEvents') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('deviceForFunctions') + ->inject('project') + ->inject('platform') ->callback($this->action(...)); } @@ -73,8 +76,10 @@ class Create extends Action Response $response, Database $dbForProject, Event $queueForEvents, - Build $queueForBuilds, - Device $deviceForFunctions + BuildPublisher $publisherForBuilds, + Device $deviceForFunctions, + Document $project, + array $platform ) { $function = $dbForProject->getDocument('functions', $functionId); @@ -127,10 +132,13 @@ class Create extends Action 'latestDeploymentStatus' => $function->getAttribute('latestDeploymentStatus'), ])); - $queueForBuilds - ->setType(BUILD_TYPE_DEPLOYMENT) - ->setResource($function) - ->setDeployment($deployment); + $publisherForBuilds->enqueue(new BuildMessage( + project: $project, + resource: $function, + deployment: $deployment, + type: BUILD_TYPE_DEPLOYMENT, + platform: $platform, + )); $queueForEvents ->setParam('functionId', $function->getId()) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php index 53af82e701..f18543c60e 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php @@ -2,8 +2,9 @@ namespace Appwrite\Platform\Modules\Functions\Http\Deployments\Template; -use Appwrite\Event\Build; use Appwrite\Event\Event; +use Appwrite\Event\Message\Build as BuildMessage; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; use Appwrite\SDK\AuthType; @@ -76,9 +77,10 @@ class Create extends Base ->inject('dbForPlatform') ->inject('queueForEvents') ->inject('project') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('gitHub') ->inject('authorization') + ->inject('platform') ->callback($this->action(...)); } @@ -96,9 +98,10 @@ class Create extends Base Database $dbForPlatform, Event $queueForEvents, Document $project, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, GitHub $github, - Authorization $authorization + Authorization $authorization, + array $platform ) { $function = $dbForProject->getDocument('functions', $functionId); @@ -127,10 +130,11 @@ class Create extends Base project: $project, installation: $installation, dbForProject: $dbForProject, - queueForBuilds: $queueForBuilds, + publisherForBuilds: $publisherForBuilds, template: $template, github: $github, activate: $activate, + platform: $platform, referenceType: $type, reference: $reference ); @@ -184,11 +188,14 @@ class Create extends Base $this->updateEmptyManualRule($project, $function, $deployment, $dbForPlatform, $authorization); - $queueForBuilds - ->setType(BUILD_TYPE_DEPLOYMENT) - ->setResource($function) - ->setDeployment($deployment) - ->setTemplate($template); + $publisherForBuilds->enqueue(new BuildMessage( + project: $project, + resource: $function, + deployment: $deployment, + type: BUILD_TYPE_DEPLOYMENT, + template: $template, + platform: $platform, + )); $queueForEvents ->setParam('functionId', $function->getId()) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Vcs/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Vcs/Create.php index 587c09beba..a74fc12593 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Vcs/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Vcs/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Functions\Http\Deployments\Vcs; -use Appwrite\Event\Build; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; use Appwrite\SDK\AuthType; @@ -70,8 +70,9 @@ class Create extends Base ->inject('dbForPlatform') ->inject('project') ->inject('queueForEvents') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('gitHub') + ->inject('platform') ->callback($this->action(...)); } @@ -86,8 +87,9 @@ class Create extends Base Database $dbForPlatform, Document $project, Event $queueForEvents, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, GitHub $github, + array $platform, ) { $function = $dbForProject->getDocument('functions', $functionId); @@ -105,10 +107,11 @@ class Create extends Base project: $project, installation: $installation, dbForProject: $dbForProject, - queueForBuilds: $queueForBuilds, + publisherForBuilds: $publisherForBuilds, template: $template, github: $github, activate: $activate, + platform: $platform, reference: $reference, referenceType: $type ); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php index 7b294f3f90..00a91141fb 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php @@ -2,9 +2,10 @@ namespace Appwrite\Platform\Modules\Functions\Http\Functions; -use Appwrite\Event\Build; use Appwrite\Event\Event; use Appwrite\Event\Func; +use Appwrite\Event\Message\Build as BuildMessage; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Event\Realtime; use Appwrite\Event\Validator\FunctionEvent; use Appwrite\Event\Webhook; @@ -115,7 +116,7 @@ class Create extends Base ->inject('timelimit') ->inject('project') ->inject('queueForEvents') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('queueForRealtime') ->inject('queueForWebhooks') ->inject('queueForFunctions') @@ -157,7 +158,7 @@ class Create extends Base callable $timelimit, Document $project, Event $queueForEvents, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, Realtime $queueForRealtime, Webhook $queueForWebhooks, Func $queueForFunctions, @@ -326,10 +327,11 @@ class Create extends Base project: $project, installation: $installation, dbForProject: $dbForProject, - queueForBuilds: $queueForBuilds, + publisherForBuilds: $publisherForBuilds, template: $template, github: $github, activate: true, + platform: $platform, reference: $providerBranch, referenceType: 'branch' ); @@ -367,11 +369,14 @@ class Create extends Base 'latestDeploymentStatus' => $deployment->getAttribute('status', ''), ])); - $queueForBuilds - ->setType(BUILD_TYPE_DEPLOYMENT) - ->setResource($function) - ->setDeployment($deployment) - ->setTemplate($template); + $publisherForBuilds->enqueue(new BuildMessage( + project: $project, + resource: $function, + deployment: $deployment, + type: BUILD_TYPE_DEPLOYMENT, + template: $template, + platform: $platform, + )); } $functionsDomain = $platform['functionsDomain']; diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index 7d6572d336..b3fcb2c021 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Functions\Http\Functions; -use Appwrite\Event\Build; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Event\Validator\FunctionEvent; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; @@ -105,11 +105,12 @@ class Update extends Base ->inject('dbForProject') ->inject('project') ->inject('queueForEvents') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('dbForPlatform') ->inject('gitHub') ->inject('executor') ->inject('authorization') + ->inject('platform') ->callback($this->action(...)); } @@ -139,11 +140,12 @@ class Update extends Base Database $dbForProject, Document $project, Event $queueForEvents, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, Database $dbForPlatform, GitHub $github, Executor $executor, - Authorization $authorization + Authorization $authorization, + array $platform ) { // TODO: If only branch changes, re-deploy $function = $dbForProject->getDocument('functions', $functionId); @@ -281,7 +283,7 @@ class Update extends Base // Redeploy logic if (!$isConnected && !empty($providerRepositoryId)) { - $this->redeployVcsFunction($request, $function, $project, $installation, $dbForProject, $queueForBuilds, new Document(), $github, true); + $this->redeployVcsFunction($request, $function, $project, $installation, $dbForProject, $publisherForBuilds, new Document(), $github, true, $platform); } // Inform scheduler if function is still active diff --git a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Builds/Get.php b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Builds/Get.php index 8ae7c8687a..98e65e37e5 100644 --- a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Builds/Get.php +++ b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Builds/Get.php @@ -2,7 +2,7 @@ namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Builds; -use Appwrite\Event\Build; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -42,16 +42,16 @@ class Get extends Base contentType: ContentType::JSON )) ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('response') ->callback($this->action(...)); } - public function action(int|string $threshold, Build $queueForBuilds, Response $response): void + public function action(int|string $threshold, BuildPublisher $publisherForBuilds, Response $response): void { $threshold = (int) $threshold; - $size = $queueForBuilds->getSize(); + $size = $publisherForBuilds->getSize(); $this->assertQueueThreshold($size, $threshold); diff --git a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php index 7602de45d3..0d0a787b46 100644 --- a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php +++ b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Failed; -use Appwrite\Event\Build; use Appwrite\Event\Database; use Appwrite\Event\Delete; use Appwrite\Event\Event; @@ -10,6 +9,7 @@ use Appwrite\Event\Func; use Appwrite\Event\Mail; use Appwrite\Event\Messaging; use Appwrite\Event\Publisher\Audit; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Event\Publisher\Certificate; use Appwrite\Event\Publisher\Migration as MigrationPublisher; use Appwrite\Event\Publisher\Screenshot; @@ -83,7 +83,7 @@ class Get extends Base ->inject('publisherForUsage') ->inject('queueForWebhooks') ->inject('publisherForCertificates') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('queueForMessaging') ->inject('publisherForMigrations') ->inject('publisherForScreenshots') @@ -103,7 +103,7 @@ class Get extends Base UsagePublisher $publisherForUsage, Webhook $queueForWebhooks, Certificate $publisherForCertificates, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, Messaging $queueForMessaging, MigrationPublisher $publisherForMigrations, Screenshot $publisherForScreenshots, @@ -120,7 +120,7 @@ class Get extends Base System::getEnv('_APP_STATS_USAGE_QUEUE_NAME', Event::STATS_USAGE_QUEUE_NAME) => $publisherForUsage, System::getEnv('_APP_WEBHOOK_QUEUE_NAME', Event::WEBHOOK_QUEUE_NAME) => $queueForWebhooks, System::getEnv('_APP_CERTIFICATES_QUEUE_NAME', Event::CERTIFICATES_QUEUE_NAME) => $publisherForCertificates, - System::getEnv('_APP_BUILDS_QUEUE_NAME', Event::BUILDS_QUEUE_NAME) => $queueForBuilds, + System::getEnv('_APP_BUILDS_QUEUE_NAME', Event::BUILDS_QUEUE_NAME) => $publisherForBuilds, System::getEnv('_APP_SCREENSHOTS_QUEUE_NAME', Event::SCREENSHOTS_QUEUE_NAME) => $publisherForScreenshots, System::getEnv('_APP_MESSAGING_QUEUE_NAME', Event::MESSAGING_QUEUE_NAME) => $queueForMessaging, System::getEnv('_APP_MIGRATIONS_QUEUE_NAME', Event::MIGRATIONS_QUEUE_NAME) => $publisherForMigrations, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php index 71ea5ceb2f..63ed776709 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php @@ -2,8 +2,9 @@ namespace Appwrite\Platform\Modules\Sites\Http\Deployments; -use Appwrite\Event\Build; use Appwrite\Event\Event; +use Appwrite\Event\Message\Build as BuildMessage; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -85,7 +86,7 @@ class Create extends Action ->inject('queueForEvents') ->inject('deviceForSites') ->inject('deviceForLocal') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('plan') ->inject('authorization') ->inject('platform') @@ -107,7 +108,7 @@ class Create extends Action Event $queueForEvents, Device $deviceForSites, Device $deviceForLocal, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, array $plan, Authorization $authorization, array $platform, @@ -315,10 +316,13 @@ class Create extends Action } // Start the build - $queueForBuilds - ->setType(BUILD_TYPE_DEPLOYMENT) - ->setResource($site) - ->setDeployment($deployment); + $publisherForBuilds->enqueue(new BuildMessage( + project: $project, + resource: $site, + deployment: $deployment, + type: BUILD_TYPE_DEPLOYMENT, + platform: $platform, + )); } else { if ($deployment->isEmpty()) { $deployment = $dbForProject->createDocument('deployments', new Document([ diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php index 546549604b..b3619c6017 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php @@ -2,8 +2,9 @@ namespace Appwrite\Platform\Modules\Sites\Http\Deployments\Duplicate; -use Appwrite\Event\Build; use Appwrite\Event\Event; +use Appwrite\Event\Message\Build as BuildMessage; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -63,7 +64,7 @@ class Create extends Action ->inject('dbForProject') ->inject('dbForPlatform') ->inject('queueForEvents') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('deviceForSites') ->inject('authorization') ->inject('platform') @@ -79,7 +80,7 @@ class Create extends Action Database $dbForProject, Database $dbForPlatform, Event $queueForEvents, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, Device $deviceForSites, Authorization $authorization, array $platform @@ -177,10 +178,13 @@ class Create extends Action ])) ); - $queueForBuilds - ->setType(BUILD_TYPE_DEPLOYMENT) - ->setResource($site) - ->setDeployment($deployment); + $publisherForBuilds->enqueue(new BuildMessage( + project: $project, + resource: $site, + deployment: $deployment, + type: BUILD_TYPE_DEPLOYMENT, + platform: $platform, + )); $queueForEvents ->setParam('siteId', $site->getId()) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php index f648c57a83..29854d473b 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php @@ -2,8 +2,9 @@ namespace Appwrite\Platform\Modules\Sites\Http\Deployments\Template; -use Appwrite\Event\Build; use Appwrite\Event\Event; +use Appwrite\Event\Message\Build as BuildMessage; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; use Appwrite\SDK\AuthType; @@ -77,7 +78,7 @@ class Create extends Base ->inject('dbForPlatform') ->inject('project') ->inject('queueForEvents') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('gitHub') ->inject('authorization') ->inject('platform') @@ -98,7 +99,7 @@ class Create extends Base Database $dbForPlatform, Document $project, Event $queueForEvents, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, GitHub $github, Authorization $authorization, array $platform @@ -130,7 +131,7 @@ class Create extends Base installation: $installation, dbForProject: $dbForProject, dbForPlatform: $dbForPlatform, - queueForBuilds: $queueForBuilds, + publisherForBuilds: $publisherForBuilds, template: $template, github: $github, activate: $activate, @@ -223,11 +224,14 @@ class Create extends Base $this->updateEmptyManualRule($project, $site, $deployment, $dbForPlatform, $authorization); - $queueForBuilds - ->setType(BUILD_TYPE_DEPLOYMENT) - ->setResource($site) - ->setDeployment($deployment) - ->setTemplate($template); + $publisherForBuilds->enqueue(new BuildMessage( + project: $project, + resource: $site, + deployment: $deployment, + type: BUILD_TYPE_DEPLOYMENT, + template: $template, + platform: $platform, + )); $queueForEvents ->setParam('siteId', $site->getId()) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Vcs/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Vcs/Create.php index 4351dd8dd9..d34b8c4055 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Vcs/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Vcs/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Sites\Http\Deployments\Vcs; -use Appwrite\Event\Build; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; use Appwrite\SDK\AuthType; @@ -71,7 +71,7 @@ class Create extends Base ->inject('dbForPlatform') ->inject('project') ->inject('queueForEvents') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('gitHub') ->inject('authorization') ->inject('platform') @@ -89,7 +89,7 @@ class Create extends Base Database $dbForPlatform, Document $project, Event $queueForEvents, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, GitHub $github, Authorization $authorization, array $platform @@ -111,7 +111,7 @@ class Create extends Base installation: $installation, dbForProject: $dbForProject, dbForPlatform: $dbForPlatform, - queueForBuilds: $queueForBuilds, + publisherForBuilds: $publisherForBuilds, template: $template, github: $github, activate: $activate, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 3c0d090b7b..2aee03265e 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Sites\Http\Sites; -use Appwrite\Event\Build; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; use Appwrite\Platform\Modules\Compute\Validator\Specification; @@ -99,10 +99,11 @@ class Update extends Base ->inject('dbForProject') ->inject('project') ->inject('queueForEvents') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('dbForPlatform') ->inject('gitHub') ->inject('executor') + ->inject('platform') ->callback($this->action(...)); } @@ -133,10 +134,11 @@ class Update extends Base Database $dbForProject, Document $project, Event $queueForEvents, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, Database $dbForPlatform, GitHub $github, - Executor $executor + Executor $executor, + array $platform ) { if (!empty($adapter)) { $configFramework = Config::getParam('frameworks')[$framework] ?? []; @@ -279,7 +281,7 @@ class Update extends Base // Redeploy logic if (!$isConnected && !empty($providerRepositoryId)) { - $this->redeployVcsFunction($request, $site, $project, $installation, $dbForProject, $queueForBuilds, new Document(), $github, true); + $this->redeployVcsFunction($request, $site, $project, $installation, $dbForProject, $publisherForBuilds, new Document(), $github, true, $platform); } $queueForEvents->setParam('siteId', $site->getId()); diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Authorize/External/Update.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Authorize/External/Update.php index 8b320535e9..a40d7fc6b9 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Authorize/External/Update.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Authorize/External/Update.php @@ -2,7 +2,7 @@ namespace Appwrite\Platform\Modules\VCS\Http\GitHub\Authorize\External; -use Appwrite\Event\Build; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Action; use Appwrite\Platform\Modules\VCS\Http\GitHub\Deployment; @@ -60,7 +60,7 @@ class Update extends Action ->inject('dbForPlatform') ->inject('authorization') ->inject('getProjectDB') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('platform') ->callback($this->action(...)); } @@ -75,7 +75,7 @@ class Update extends Action Database $dbForPlatform, Authorization $authorization, callable $getProjectDB, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, array $platform ) { $installation = $dbForPlatform->getDocument('installations', $installationId); @@ -130,7 +130,7 @@ class Update extends Action $providerCommitAuthor = $commitDetails["commitAuthor"] ?? ''; $providerCommitAuthorUrl = $commitDetails["commitAuthorUrl"] ?? ''; - $this->createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthor, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, $providerPullRequestId, true, $dbForPlatform, $authorization, $queueForBuilds, $getProjectDB, $platform); + $this->createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthor, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, $providerPullRequestId, true, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform); $response->noContent(); } diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php index 33d7e984fb..8bc090bb03 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php @@ -2,8 +2,9 @@ namespace Appwrite\Platform\Modules\VCS\Http\GitHub; -use Appwrite\Event\Build; use Appwrite\Event\Event; +use Appwrite\Event\Message\Build as BuildMessage; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\Filter\BranchDomain as BranchDomainFilter; use Appwrite\Vcs\Comment; @@ -43,7 +44,7 @@ trait Deployment bool $external, Database $dbForPlatform, Authorization $authorization, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, callable $getProjectDB, array $platform, ) { @@ -528,14 +529,16 @@ trait Deployment $queueName = $this->getBuildQueueName($project, $dbForPlatform, $authorization); - $queueForBuilds - ->setQueue($queueName) - ->setType(BUILD_TYPE_DEPLOYMENT) - ->setResource($resource) - ->setDeployment($deployment) - ->setProject($project); // set the project because it won't be set for git deployments - - $queueForBuilds->trigger(); // must trigger here so that we create a build for each function/site + $publisherForBuilds->enqueue( + new BuildMessage( + project: $project, + resource: $resource, + deployment: $deployment, + type: BUILD_TYPE_DEPLOYMENT, + platform: $platform, + ), + new \Utopia\Queue\Queue($queueName) + ); Span::add("{$logBase}.build.triggered", 'true'); //TODO: Add event? @@ -545,8 +548,6 @@ trait Deployment } } - $queueForBuilds->reset(); // prevent shutdown hook from triggering again - if (!empty($errors)) { throw new Exception(Exception::GENERAL_UNKNOWN, \implode("\n", $errors)); } diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php index e3dbcfa0e9..0b81504309 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php @@ -2,7 +2,7 @@ namespace Appwrite\Platform\Modules\VCS\Http\GitHub\Events; -use Appwrite\Event\Build; +use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Action; use Appwrite\Platform\Modules\VCS\Http\GitHub\Deployment; @@ -41,7 +41,7 @@ class Create extends Action ->inject('dbForPlatform') ->inject('authorization') ->inject('getProjectDB') - ->inject('queueForBuilds') + ->inject('publisherForBuilds') ->inject('platform') ->callback($this->action(...)); } @@ -53,7 +53,7 @@ class Create extends Action Database $dbForPlatform, Authorization $authorization, callable $getProjectDB, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, array $platform ) { $this->preprocessEvent($request); @@ -78,8 +78,8 @@ class Create extends Action match ($event) { $github::EVENT_INSTALLATION => $this->handleInstallationEvent($parsedPayload, $dbForPlatform, $authorization), - $github::EVENT_PUSH => $this->handlePushEvent($parsedPayload, $githubAppId, $privateKey, $github, $dbForPlatform, $authorization, $queueForBuilds, $getProjectDB, $platform), - $github::EVENT_PULL_REQUEST => $this->handlePullRequestEvent($parsedPayload, $privateKey, $githubAppId, $github, $dbForPlatform, $authorization, $queueForBuilds, $getProjectDB, $platform), + $github::EVENT_PUSH => $this->handlePushEvent($parsedPayload, $githubAppId, $privateKey, $github, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform), + $github::EVENT_PULL_REQUEST => $this->handlePullRequestEvent($parsedPayload, $privateKey, $githubAppId, $github, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform), default => null, }; @@ -129,7 +129,7 @@ class Create extends Action GitHub $github, Database $dbForPlatform, Authorization $authorization, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, callable $getProjectDB, array $platform, ) { @@ -164,7 +164,7 @@ class Create extends Action // Create new deployment only on push (not committed by us) and not when branch is deleted if ($providerCommitAuthorEmail !== APP_VCS_GITHUB_EMAIL && !$providerBranchDeleted) { - $this->createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthorName, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, '', false, $dbForPlatform, $authorization, $queueForBuilds, $getProjectDB, $platform); + $this->createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthorName, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, '', false, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform); } } @@ -175,7 +175,7 @@ class Create extends Action GitHub $github, Database $dbForPlatform, Authorization $authorization, - Build $queueForBuilds, + BuildPublisher $publisherForBuilds, callable $getProjectDB, array $platform, ) { @@ -216,7 +216,7 @@ class Create extends Action Query::orderDesc('$createdAt') ])); - $this->createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthor, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, $providerPullRequestId, $external, $dbForPlatform, $authorization, $queueForBuilds, $getProjectDB, $platform); + $this->createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthor, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, $providerPullRequestId, $external, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform); } elseif ($action == "closed") { // Allowed external contributions cleanup From 98b4e9b0639ced493044e7716ea35bd7b6be3f59 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 7 May 2026 13:30:21 +0100 Subject: [PATCH 187/211] Loosen utopia-php/migration constraint back to 1.* (matches 1.9.x baseline) --- composer.json | 2 +- composer.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 4a60944351..9a84be6111 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,7 @@ "utopia-php/locale": "0.8.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.22.*", - "utopia-php/migration": "1.10.*", + "utopia-php/migration": "1.*", "utopia-php/platform": "0.13.*", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", diff --git a/composer.lock b/composer.lock index eb06192bb9..d356362788 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": "acd8a12e57d36a970effa84f5c8ccf50", + "content-hash": "ec2ad489c60f0102f0dfab223b6d1fe4", "packages": [ { "name": "adhocore/jwt", From 81e57ea30e2a0b2884185a4716ac106034ad3fee Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 7 May 2026 13:36:49 +0100 Subject: [PATCH 188/211] Revert gate fallback to always-publish on unknown exception types --- src/Appwrite/Platform/Workers/Migrations.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index bf64285299..f77a1cede0 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -550,13 +550,13 @@ class Migrations extends Action // Mirror general.php's HTTP-error pattern: typed AppwriteException uses its // registry-driven isPublishable() flag; library-thrown Migration\Exception is - // always user-facing; anything else falls back to the code heuristic. + // always user-facing; anything else is unknown and surfaced to Sentry. if ($th instanceof Exception) { $publish = $th->isPublishable(); } elseif ($th instanceof MigrationException) { $publish = false; } else { - $publish = $th->getCode() === 0 || $th->getCode() >= 500; + $publish = true; } if ($publish) { From 3676af925c19ace8ae9ddb36d456ac05d6ea33b7 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Thu, 7 May 2026 13:45:57 +0100 Subject: [PATCH 189/211] Sanitize bubbled message for non-typed exceptions on migration document --- src/Appwrite/Platform/Workers/Migrations.php | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index f77a1cede0..b6c295b3bb 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -572,15 +572,30 @@ class Migrations extends Action $destinationErrors = $destination?->getErrors() ?? []; if ($caughtError !== null) { - $bubbled = $caughtError instanceof MigrationException - ? $caughtError - : new MigrationException( + if ($caughtError instanceof MigrationException) { + // library-thrown, message constructed by us + $bubbled = $caughtError; + } elseif ($caughtError instanceof Exception) { + // typed AppwriteException — message comes from the curated registry + $bubbled = new MigrationException( resourceName: '', resourceGroup: '', message: $caughtError->getMessage(), code: $caughtError->getCode(), previous: $caughtError, ); + } else { + // unknown throwable — raw message may embed internal hostnames, + // DSNs, tokens, etc. Replace with a generic user-facing string; + // the original is preserved on `previous:` for Sentry. + $bubbled = new MigrationException( + resourceName: '', + resourceGroup: '', + message: 'Migration failed due to an unexpected error.', + code: $caughtError->getCode() ?: 500, + previous: $caughtError, + ); + } $destinationErrors[] = $bubbled; } From f947fde7013eb25f94e4cc8dec63a867816dcc7a Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 7 May 2026 13:56:46 +0100 Subject: [PATCH 190/211] Restore platform fallback and null-template round-trip in BuildMessage - toArray() falls back to Config::getParam('platform') when the in-memory platform is empty, matching the old Build event behavior so workers always receive a populated platform array. - toArray() emits null for an absent template instead of an empty array, and fromArray() treats empty/null/missing template as null so the round-trip preserves the no-template case. Co-Authored-By: Claude Opus 4.7 --- src/Appwrite/Event/Message/Build.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Event/Message/Build.php b/src/Appwrite/Event/Message/Build.php index 7dfc8ea39a..0c8967aff6 100644 --- a/src/Appwrite/Event/Message/Build.php +++ b/src/Appwrite/Event/Message/Build.php @@ -2,6 +2,7 @@ namespace Appwrite\Event\Message; +use Utopia\Config\Config; use Utopia\Database\Document; final class Build extends Base @@ -18,13 +19,15 @@ final class Build extends Base public function toArray(): array { + $platform = !empty($this->platform) ? $this->platform : Config::getParam('platform', []); + return [ 'project' => $this->project->getArrayCopy(), 'resource' => $this->resource->getArrayCopy(), 'deployment' => $this->deployment->getArrayCopy(), 'type' => $this->type, - 'template' => $this->template?->getArrayCopy() ?? [], - 'platform' => $this->platform, + 'template' => $this->template?->getArrayCopy(), + 'platform' => $platform, ]; } @@ -35,7 +38,7 @@ final class Build extends Base resource: new Document($data['resource'] ?? []), deployment: new Document($data['deployment'] ?? []), type: $data['type'] ?? '', - template: isset($data['template']) ? new Document($data['template']) : null, + template: !empty($data['template']) ? new Document($data['template']) : null, platform: $data['platform'] ?? [], ); } From 708aea25324eaa585c08871609a5904c22f725df Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 8 May 2026 01:07:12 +1200 Subject: [PATCH 191/211] chore: pin github actions to sha and bump to latest Pin every third-party action in .github/workflows/ to a full commit SHA with a trailing version comment, and bump to the latest stable release. Defends against tag-rewrite supply-chain attacks while keeping versions legible. --- .github/workflows/ai-moderator.yml | 2 +- .github/workflows/auto-label-issue.yml | 2 +- .github/workflows/ci.yml | 104 ++++++++++++------------- .github/workflows/cleanup-cache.yml | 2 +- .github/workflows/codeql-analysis.yml | 8 +- .github/workflows/nightly.yml | 12 +-- .github/workflows/publish.yml | 12 +-- .github/workflows/release.yml | 12 +-- .github/workflows/sdk-preview.yml | 4 +- .github/workflows/specs.yml | 2 +- .github/workflows/stale.yml | 2 +- 11 files changed, 81 insertions(+), 81 deletions(-) diff --git a/.github/workflows/ai-moderator.yml b/.github/workflows/ai-moderator.yml index 483f3dbeee..948fa6c0c1 100644 --- a/.github/workflows/ai-moderator.yml +++ b/.github/workflows/ai-moderator.yml @@ -25,6 +25,6 @@ jobs: runs-on: ubuntu-latest steps: - name: AI Moderator - uses: github/ai-moderator@v1 + uses: github/ai-moderator@81159c370785e295c97461ade67d7c33576e9319 # v1.1.4 with: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/auto-label-issue.yml b/.github/workflows/auto-label-issue.yml index e0eb0de98d..0151c2f9c1 100644 --- a/.github/workflows/auto-label-issue.yml +++ b/.github/workflows/auto-label-issue.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Issue Labeler - uses: github/issue-labeler@v3.4 + uses: github/issue-labeler@c1b0f9f52a63158c4adc09425e858e87b32e9685 # v3.4 with: configuration-path: .github/labeler.yml enable-versioned-regex: false diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8cc3b3e113..29cc1d129e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: actions: read security-events: write contents: read - uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable-pr.yml@v2.3.3" + uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable-pr.yml@c51854704019a247608d928f370c98740469d4b5" # v2.3.5 security: name: Checks / Image @@ -43,13 +43,13 @@ jobs: security-events: write steps: - name: Check out code - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: fetch-depth: 0 submodules: 'recursive' - name: Build the Docker image - uses: docker/build-push-action@v6 + uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0 with: context: . push: false @@ -58,7 +58,7 @@ jobs: target: production - name: Run Trivy vulnerability scanner on image - uses: aquasecurity/trivy-action@0.35.0 + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 with: image-ref: 'pr_image:${{ github.sha }}' format: 'sarif' @@ -66,7 +66,7 @@ jobs: severity: 'CRITICAL,HIGH' - name: Run Trivy vulnerability scanner on source code - uses: aquasecurity/trivy-action@0.35.0 + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 with: scan-type: 'fs' scan-ref: '.' @@ -76,14 +76,14 @@ jobs: skip-setup-trivy: true - name: Upload image scan results - uses: github/codeql-action/upload-sarif@v4 + uses: github/codeql-action/upload-sarif@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3 if: always() && hashFiles('trivy-image-results.sarif') != '' with: sarif_file: 'trivy-image-results.sarif' category: 'trivy-image' - name: Upload source code scan results - uses: github/codeql-action/upload-sarif@v4 + uses: github/codeql-action/upload-sarif@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3 if: always() && hashFiles('trivy-fs-results.sarif') != '' with: sarif_file: 'trivy-fs-results.sarif' @@ -94,10 +94,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Setup PHP - uses: shivammathur/setup-php@v2 + uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 with: php-version: '8.3' tools: composer:v2 @@ -119,7 +119,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: fetch-depth: 2 @@ -127,7 +127,7 @@ jobs: if: github.event_name == 'pull_request' - name: Setup PHP - uses: shivammathur/setup-php@v2 + uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 with: php-version: '8.3' tools: composer:v2 @@ -144,10 +144,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out the repo - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Setup PHP - uses: shivammathur/setup-php@v2 + uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 with: php-version: '8.3' tools: composer:v2 @@ -157,7 +157,7 @@ jobs: run: composer install --prefer-dist --no-progress --ignore-platform-reqs - name: Cache PHPStan result cache - uses: actions/cache@v4 + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: path: .phpstan-cache key: phpstan-${{ github.sha }} @@ -172,10 +172,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out the repo - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Setup PHP - uses: shivammathur/setup-php@v2 + uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 with: php-version: '8.3' extensions: swoole @@ -193,10 +193,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out the repo - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Setup Node - uses: actions/setup-node@v4 + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 with: node-version: '24' @@ -212,7 +212,7 @@ jobs: steps: - name: Generate matrix id: generate - uses: actions/github-script@v8 + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | const allDatabases = ['MariaDB', 'PostgreSQL', 'MongoDB']; @@ -253,28 +253,28 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: submodules: recursive - name: Login to Docker Hub - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to GHCR - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 - name: Build and push Appwrite - uses: docker/build-push-action@v6 + uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0 with: context: . push: true @@ -297,16 +297,16 @@ jobs: packages: read steps: - name: checkout - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Login to Docker Hub - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to GHCR - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -327,7 +327,7 @@ jobs: run: docker compose exec -T appwrite vars - name: Run Unit Tests - uses: itznotabug/php-retry@v3 + uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 with: max_attempts: 2 retry_wait_seconds: 60 @@ -350,16 +350,16 @@ jobs: packages: read steps: - name: checkout - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Login to Docker Hub - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to GHCR - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -385,7 +385,7 @@ jobs: done - name: Run General Tests - uses: itznotabug/php-retry@v3 + uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 with: max_attempts: 2 retry_wait_seconds: 60 @@ -464,7 +464,7 @@ jobs: paratest_processes: 1 steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Set environment run: | @@ -488,13 +488,13 @@ jobs: fi - name: Login to Docker Hub - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to GHCR - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -525,7 +525,7 @@ jobs: done - name: Run tests - uses: itznotabug/php-retry@v3 + uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 with: max_attempts: 2 retry_wait_seconds: 60 @@ -573,18 +573,18 @@ jobs: mode: ${{ fromJSON(needs.matrix.outputs.modes) }} steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: fetch-depth: 1 - name: Login to Docker Hub - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to GHCR - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -607,7 +607,7 @@ jobs: docker compose up -d --quiet-pull --wait - name: Run tests - uses: itznotabug/php-retry@v3 + uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 with: max_attempts: 2 retry_wait_seconds: 60 @@ -640,16 +640,16 @@ jobs: mode: ${{ fromJSON(needs.matrix.outputs.modes) }} steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Login to Docker Hub - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to GHCR - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -679,7 +679,7 @@ jobs: done - name: Run tests - uses: itznotabug/php-retry@v3 + uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 with: max_attempts: 2 retry_wait_seconds: 60 @@ -711,18 +711,18 @@ jobs: packages: read steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: fetch-depth: 1 - name: Login to Docker Hub - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to GHCR - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -735,7 +735,7 @@ jobs: docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }}:after - name: Setup k6 - uses: grafana/setup-k6-action@ffe7d7290dfa715e48c2ccc924d068444c94bde2 + uses: grafana/setup-k6-action@db07bd9765aac508ef18982e52ab937fe633a065 # v1.2.1 with: k6-version: ${{ env.K6_VERSION }} @@ -774,7 +774,7 @@ jobs: - name: Benchmark before if: steps.benchmark_before_start.outcome == 'success' continue-on-error: true - uses: grafana/run-k6-action@a15e2072ede004e8d46141e33d7f7dad8ad08d9d + uses: grafana/run-k6-action@de51a7390bdf0ac85a3bef493691bd71d4c7c158 # v1.4.0 env: APPWRITE_ENDPOINT: 'http://localhost/v1' APPWRITE_BENCHMARK_ITERATIONS: '5' @@ -826,7 +826,7 @@ jobs: - name: Benchmark after id: benchmark_after continue-on-error: true - uses: grafana/run-k6-action@a15e2072ede004e8d46141e33d7f7dad8ad08d9d + uses: grafana/run-k6-action@de51a7390bdf0ac85a3bef493691bd71d4c7c158 # v1.4.0 env: APPWRITE_ENDPOINT: 'http://localhost/v1' APPWRITE_BENCHMARK_ITERATIONS: '5' @@ -846,7 +846,7 @@ jobs: - name: Comment on PR if: always() - uses: actions/github-script@v8 + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: BENCHMARK_BASE_REF: ${{ github.event.pull_request.base.ref }} BENCHMARK_HEAD_REF: ${{ github.event.pull_request.head.ref }} @@ -856,7 +856,7 @@ jobs: await comment({ github, context, core }); - name: Save results - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 if: ${{ !cancelled() }} with: name: benchmark-results diff --git a/.github/workflows/cleanup-cache.yml b/.github/workflows/cleanup-cache.yml index 4b6b13d35d..e4f28816be 100644 --- a/.github/workflows/cleanup-cache.yml +++ b/.github/workflows/cleanup-cache.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Cleanup run: | diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 7edfde0aae..cb9b09b496 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -34,7 +34,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. @@ -47,14 +47,14 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3 with: languages: ${{ matrix.language }} # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3 # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -68,4 +68,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3 diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index c4289678bb..0a49f658ac 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -10,13 +10,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: submodules: recursive - name: Build the Docker image run: DOCKER_BUILDKIT=1 docker build . --target production -t appwrite_image:latest - name: Run Trivy vulnerability scanner on image - uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0 + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 with: image-ref: 'appwrite_image:latest' format: 'sarif' @@ -24,7 +24,7 @@ jobs: ignore-unfixed: 'false' severity: 'CRITICAL,HIGH' - name: Upload Docker Image Scan Results - uses: github/codeql-action/upload-sarif@v4 + uses: github/codeql-action/upload-sarif@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3 if: always() && hashFiles('trivy-image-results.sarif') != '' with: sarif_file: 'trivy-image-results.sarif' @@ -35,16 +35,16 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Run Trivy vulnerability scanner on filesystem - uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0 + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 with: scan-type: 'fs' format: 'sarif' output: 'trivy-fs-results.sarif' severity: 'CRITICAL,HIGH' - name: Upload Code Scan Results - uses: github/codeql-action/upload-sarif@v4 + uses: github/codeql-action/upload-sarif@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3 if: always() && hashFiles('trivy-fs-results.sarif') != '' with: sarif_file: 'trivy-fs-results.sarif' diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 692861d44d..68ab657213 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -12,33 +12,33 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: fetch-depth: 2 submodules: recursive - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 - name: Login to Docker Hub - uses: docker/login-action@v3 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0 with: images: appwrite/cloud tags: | type=ref,event=tag - name: Build & Publish to DockerHub - uses: docker/build-push-action@v6 + uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0 with: context: . platforms: linux/amd64,linux/arm64 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 84fc4c9fba..ed4e46d811 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,7 +11,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. @@ -20,20 +20,20 @@ jobs: submodules: recursive - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 - name: Login to Docker Hub - uses: docker/login-action@v3 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0 with: images: appwrite/appwrite tags: | @@ -42,7 +42,7 @@ jobs: type=semver,pattern={{major}} - name: Build and push - uses: docker/build-push-action@v6 + uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0 with: context: . platforms: linux/amd64,linux/arm64 diff --git a/.github/workflows/sdk-preview.yml b/.github/workflows/sdk-preview.yml index f81346a7d1..dacc37a64a 100644 --- a/.github/workflows/sdk-preview.yml +++ b/.github/workflows/sdk-preview.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Set SDK type id: set-sdk @@ -49,7 +49,7 @@ jobs: docker compose exec appwrite sdks --platform=${{ steps.set-sdk.outputs.platform }} --sdk=${{ steps.set-sdk.outputs.sdk_type }} --version=latest --git=no sudo chown -R $USER:$USER ./app/sdks/${{ steps.set-sdk.outputs.platform }}-${{ steps.set-sdk.outputs.sdk_type }} - - uses: actions/setup-node@v4 + - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 with: node-version: 20 diff --git a/.github/workflows/specs.yml b/.github/workflows/specs.yml index 6f377354d5..85c76bacd3 100644 --- a/.github/workflows/specs.yml +++ b/.github/workflows/specs.yml @@ -31,7 +31,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: submodules: recursive diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 6e4a8ba73b..73b767aafe 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/stale@v10 + - uses: actions/stale@b5d41d4e1d5dceea10e7104786b73624c18a190f # v10.2.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} stale-issue-message: "This issue has been labeled as a 'question', indicating that it requires additional information from the requestor. It has been inactive for 7 days. If no further activity occurs, this issue will be closed in 14 days." From 21ba13a076a102a2bd2061b0099d32e0438e1f4d Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 7 May 2026 18:40:26 +0530 Subject: [PATCH 192/211] updated --- src/Appwrite/SDK/Specification/Format.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/SDK/Specification/Format.php b/src/Appwrite/SDK/Specification/Format.php index 777479f7e3..4c7fa6f377 100644 --- a/src/Appwrite/SDK/Specification/Format.php +++ b/src/Appwrite/SDK/Specification/Format.php @@ -763,7 +763,7 @@ abstract class Format case 'getPolicy': switch ($param) { case 'policyId': - return 'ProjectPolicyId'; + return 'ProjectPolicy'; } break; case 'getOAuth2Provider': From b2080fb8f9465288b79495dcd66696001b744937 Mon Sep 17 00:00:00 2001 From: Levi van Noort <73097785+levivannoort@users.noreply.github.com> Date: Thu, 7 May 2026 17:07:13 +0200 Subject: [PATCH 193/211] refactor: migrate to different ci runners --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8cc3b3e113..5b80746db1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -445,19 +445,19 @@ jobs: ] include: - service: Databases - runner: blacksmith-4vcpu-ubuntu-2404 + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7 paratest_processes: 3 timeout_minutes: 30 - service: Sites - runner: blacksmith-4vcpu-ubuntu-2404 + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7 - service: Functions - runner: blacksmith-4vcpu-ubuntu-2404 + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7 - service: Avatars - runner: blacksmith-4vcpu-ubuntu-2404 + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7 - service: Realtime - runner: blacksmith-4vcpu-ubuntu-2404 + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7 - service: TablesDB - runner: blacksmith-4vcpu-ubuntu-2404 + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7 paratest_processes: 3 timeout_minutes: 30 - service: Migrations From c3881f9974d391931b71ba7526f2ba82fdafcd1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 7 May 2026 17:13:26 +0200 Subject: [PATCH 194/211] Fix console email policy features --- app/controllers/api/account.php | 36 +++++++++---------- app/controllers/api/users.php | 12 +++---- .../Modules/Teams/Http/Memberships/Create.php | 6 ++-- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 65fd0bfb83..ac07efc72b 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -332,15 +332,15 @@ Http::post('/v1/account') throw new Exception(Exception::GENERAL_INVALID_EMAIL); } - if (($plan['supportsDisposableEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && $emailMetadata['emailIsDisposable']) { + if ((($project->getId() === 'console') || ($plan['supportsDisposableEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && $emailMetadata['emailIsDisposable']) { throw new Exception(Exception::USER_EMAIL_DISPOSABLE); } - if (($plan['supportsCanonicalEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && $emailMetadata['emailIsCanonical'] === false) { + if ((($project->getId() === 'console') || ($plan['supportsCanonicalEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && $emailMetadata['emailIsCanonical'] === false) { throw new Exception(Exception::USER_EMAIL_NOT_CANONICAL); } - if (($plan['supportsFreeEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && $emailMetadata['emailIsFree']) { + if ((($project->getId() === 'console') || ($plan['supportsFreeEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && $emailMetadata['emailIsFree']) { throw new Exception(Exception::USER_EMAIL_FREE); } @@ -1676,15 +1676,15 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') $failureRedirect(Exception::GENERAL_INVALID_EMAIL); } - if (($plan['supportsDisposableEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && $emailMetadata['emailIsDisposable']) { + if ((($project->getId() === 'console') || ($plan['supportsDisposableEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && $emailMetadata['emailIsDisposable']) { $failureRedirect(Exception::USER_EMAIL_DISPOSABLE); } - if (($plan['supportsCanonicalEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && $emailMetadata['emailIsCanonical'] === false) { + if ((($project->getId() === 'console') || ($plan['supportsCanonicalEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && $emailMetadata['emailIsCanonical'] === false) { $failureRedirect(Exception::USER_EMAIL_NOT_CANONICAL); } - if (($plan['supportsFreeEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && $emailMetadata['emailIsFree']) { + if ((($project->getId() === 'console') || ($plan['supportsFreeEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && $emailMetadata['emailIsFree']) { $failureRedirect(Exception::USER_EMAIL_FREE); } @@ -1817,15 +1817,15 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') $failureRedirect(Exception::GENERAL_INVALID_EMAIL); } - if (($plan['supportsDisposableEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && $emailMetadata['emailIsDisposable']) { + if ((($project->getId() === 'console') || ($plan['supportsDisposableEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && $emailMetadata['emailIsDisposable']) { $failureRedirect(Exception::USER_EMAIL_DISPOSABLE); } - if (($plan['supportsCanonicalEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && $emailMetadata['emailIsCanonical'] === false) { + if ((($project->getId() === 'console') || ($plan['supportsCanonicalEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && $emailMetadata['emailIsCanonical'] === false) { $failureRedirect(Exception::USER_EMAIL_NOT_CANONICAL); } - if (($plan['supportsFreeEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && $emailMetadata['emailIsFree']) { + if ((($project->getId() === 'console') || ($plan['supportsFreeEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && $emailMetadata['emailIsFree']) { $failureRedirect(Exception::USER_EMAIL_FREE); } @@ -2175,15 +2175,15 @@ Http::post('/v1/account/tokens/magic-url') throw new Exception(Exception::GENERAL_INVALID_EMAIL); } - if (($plan['supportsDisposableEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && $emailMetadata['emailIsDisposable']) { + if ((($project->getId() === 'console') || ($plan['supportsDisposableEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && $emailMetadata['emailIsDisposable']) { throw new Exception(Exception::USER_EMAIL_DISPOSABLE); } - if (($plan['supportsCanonicalEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && $emailMetadata['emailIsCanonical'] === false) { + if ((($project->getId() === 'console') || ($plan['supportsCanonicalEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && $emailMetadata['emailIsCanonical'] === false) { throw new Exception(Exception::USER_EMAIL_NOT_CANONICAL); } - if (($plan['supportsFreeEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && $emailMetadata['emailIsFree']) { + if ((($project->getId() === 'console') || ($plan['supportsFreeEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && $emailMetadata['emailIsFree']) { throw new Exception(Exception::USER_EMAIL_FREE); } @@ -2496,15 +2496,15 @@ Http::post('/v1/account/tokens/email') throw new Exception(Exception::GENERAL_INVALID_EMAIL); } - if (($plan['supportsDisposableEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && $emailMetadata['emailIsDisposable']) { + if ((($project->getId() === 'console') || ($plan['supportsDisposableEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && $emailMetadata['emailIsDisposable']) { throw new Exception(Exception::USER_EMAIL_DISPOSABLE); } - if (($plan['supportsCanonicalEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && $emailMetadata['emailIsCanonical'] === false) { + if ((($project->getId() === 'console') || ($plan['supportsCanonicalEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && $emailMetadata['emailIsCanonical'] === false) { throw new Exception(Exception::USER_EMAIL_NOT_CANONICAL); } - if (($plan['supportsFreeEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && $emailMetadata['emailIsFree']) { + if ((($project->getId() === 'console') || ($plan['supportsFreeEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && $emailMetadata['emailIsFree']) { throw new Exception(Exception::USER_EMAIL_FREE); } @@ -3417,15 +3417,15 @@ Http::patch('/v1/account/email') throw new Exception(Exception::GENERAL_INVALID_EMAIL); } - if (($plan['supportsDisposableEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && $emailMetadata['emailIsDisposable']) { + if ((($project->getId() === 'console') || ($plan['supportsDisposableEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && $emailMetadata['emailIsDisposable']) { throw new Exception(Exception::USER_EMAIL_DISPOSABLE); } - if (($plan['supportsCanonicalEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && $emailMetadata['emailIsCanonical'] === false) { + if ((($project->getId() === 'console') || ($plan['supportsCanonicalEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && $emailMetadata['emailIsCanonical'] === false) { throw new Exception(Exception::USER_EMAIL_NOT_CANONICAL); } - if (($plan['supportsFreeEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && $emailMetadata['emailIsFree']) { + if ((($project->getId() === 'console') || ($plan['supportsFreeEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && $emailMetadata['emailIsFree']) { throw new Exception(Exception::USER_EMAIL_FREE); } diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index abcecac396..3f52069609 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -131,15 +131,15 @@ function createUser(Hash $hash, string $userId, ?string $email, ?string $passwor } catch (\Throwable) { } - if (($plan['supportsDisposableEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && ($emailMetadata['emailIsDisposable'] ?? false)) { + if ((($project->getId() === 'console') || ($plan['supportsDisposableEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && ($emailMetadata['emailIsDisposable'] ?? false)) { throw new Exception(Exception::USER_EMAIL_DISPOSABLE); } - if (($plan['supportsCanonicalEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && ($emailMetadata['emailIsCanonical'] ?? true) === false) { + if ((($project->getId() === 'console') || ($plan['supportsCanonicalEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && ($emailMetadata['emailIsCanonical'] ?? true) === false) { throw new Exception(Exception::USER_EMAIL_NOT_CANONICAL); } - if (($plan['supportsFreeEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && ($emailMetadata['emailIsFree'] ?? false)) { + if ((($project->getId() === 'console') || ($plan['supportsFreeEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && ($emailMetadata['emailIsFree'] ?? false)) { throw new Exception(Exception::USER_EMAIL_FREE); } @@ -1563,15 +1563,15 @@ Http::patch('/v1/users/:userId/email') } catch (\Throwable) { } - if (($plan['supportsDisposableEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && ($emailMetadata['emailIsDisposable'] ?? false)) { + if ((($project->getId() === 'console') || ($plan['supportsDisposableEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && ($emailMetadata['emailIsDisposable'] ?? false)) { throw new Exception(Exception::USER_EMAIL_DISPOSABLE); } - if (($plan['supportsCanonicalEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && ($emailMetadata['emailIsCanonical'] ?? true) === false) { + if ((($project->getId() === 'console') || ($plan['supportsCanonicalEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && ($emailMetadata['emailIsCanonical'] ?? true) === false) { throw new Exception(Exception::USER_EMAIL_NOT_CANONICAL); } - if (($plan['supportsFreeEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && ($emailMetadata['emailIsFree'] ?? false)) { + if ((($project->getId() === 'console') || ($plan['supportsFreeEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && ($emailMetadata['emailIsFree'] ?? false)) { throw new Exception(Exception::USER_EMAIL_FREE); } diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php index e174029031..51115b7861 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php @@ -189,15 +189,15 @@ class Create extends Action } catch (\Throwable) { } - if (($plan['supportsDisposableEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && ($emailMetadata['emailIsDisposable'] ?? false)) { + if ((($project->getId() === 'console') || ($plan['supportsDisposableEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['disposableEmails'] ?? false) && ($emailMetadata['emailIsDisposable'] ?? false)) { throw new Exception(Exception::USER_EMAIL_DISPOSABLE); } - if (($plan['supportsCanonicalEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && ($emailMetadata['emailIsCanonical'] ?? true) === false) { + if ((($project->getId() === 'console') || ($plan['supportsCanonicalEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) && ($emailMetadata['emailIsCanonical'] ?? true) === false) { throw new Exception(Exception::USER_EMAIL_NOT_CANONICAL); } - if (($plan['supportsFreeEmailValidation'] ?? false) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && ($emailMetadata['emailIsFree'] ?? false)) { + if ((($project->getId() === 'console') || ($plan['supportsFreeEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['freeEmails'] ?? false) && ($emailMetadata['emailIsFree'] ?? false)) { throw new Exception(Exception::USER_EMAIL_FREE); } From 20ab5b026e01913ebd03ae904f821730fcc75491 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 08:32:07 +0530 Subject: [PATCH 195/211] Add cached response cache-control callback --- app/controllers/shared/api.php | 22 +++++++++++++++++-- app/init/resources.php | 4 ++++ .../Http/Buckets/Files/Preview/Get.php | 20 +++++++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 3ca45ea783..3c8f1d4425 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -501,7 +501,8 @@ Http::init() ->inject('telemetry') ->inject('platform') ->inject('authorization') - ->action(function (Http $utopia, Request $request, Response $response, Document $project, User $user, Event $queueForEvents, Messaging $queueForMessaging, AuditContext $auditContext, Delete $queueForDeletes, EventDatabase $queueForDatabase, Context $usage, Func $queueForFunctions, Mail $queueForMails, Database $dbForProject, callable $timelimit, Document $resourceToken, string $mode, ?Key $apiKey, array $plan, Document $devKey, Telemetry $telemetry, array $platform, Authorization $authorization) { + ->inject('cacheControlForResponse') + ->action(function (Http $utopia, Request $request, Response $response, Document $project, User $user, Event $queueForEvents, Messaging $queueForMessaging, AuditContext $auditContext, Delete $queueForDeletes, EventDatabase $queueForDatabase, Context $usage, Func $queueForFunctions, Mail $queueForMails, Database $dbForProject, callable $timelimit, Document $resourceToken, string $mode, ?Key $apiKey, array $plan, Document $devKey, Telemetry $telemetry, array $platform, Authorization $authorization, callable $cacheControlForResponse) { $response->setUser($user); $request->setUser($user); @@ -639,6 +640,9 @@ Http::init() $data = $cache->load($key, $timestamp); if (! empty($data) && ! $cacheLog->isEmpty()) { + $bucket = new Document(); + $file = new Document(); + $fileSecurity = null; $parts = explode('/', $cacheLog->getAttribute('resourceType', '')); $type = $parts[0]; @@ -702,8 +706,22 @@ Http::init() $cache->save($key, $data); } + $cacheControl = $cacheControlForResponse([ + 'route' => $route, + 'source' => 'cache', + 'project' => $project, + 'user' => $user, + 'bucket' => $bucket, + 'file' => $file, + 'fileSecurity' => $fileSecurity, + 'resourceToken' => $resourceToken, + 'cacheLog' => $cacheLog, + 'maxAge' => $timestamp, + 'isImageTransformation' => $isImageTransformation, + ]); + $response - ->addHeader('Cache-Control', sprintf('private, max-age=%d', $timestamp)) + ->addHeader('Cache-Control', $cacheControl ?? sprintf('private, max-age=%d', $timestamp)) ->addHeader('X-Appwrite-Cache', 'hit') ->setContentType($cacheLog->getAttribute('mimeType')); $storageCacheOperationsCounter->add(1, ['result' => 'hit']); diff --git a/app/init/resources.php b/app/init/resources.php index 15f669b2d0..03fe9ce709 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -203,6 +203,10 @@ $container->set('cache', function (Group $pools, Telemetry $telemetry) { return $cache; }, ['pools', 'telemetry']); +$container->set('cacheControlForResponse', fn () => function (array $context): ?string { + return null; +}); + $container->set('redis', function () { $host = System::getEnv('_APP_REDIS_HOST', 'localhost'); $port = System::getEnv('_APP_REDIS_PORT', 6379); diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php index 4fa5006db8..c66c38c982 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php @@ -94,6 +94,7 @@ class Get extends Action ->inject('project') ->inject('authorization') ->inject('user') + ->inject('cacheControlForResponse') ->callback($this->action(...)); } @@ -120,7 +121,8 @@ class Get extends Action Device $deviceForLocal, Document $project, Authorization $authorization, - User $user + User $user, + callable $cacheControlForResponse ) { if (!\extension_loaded('imagick')) { @@ -294,8 +296,22 @@ class Get extends Action } } + $maxAge = 2592000; // 30 days + $cacheControl = $cacheControlForResponse([ + 'route' => $request->getRoute(), + 'source' => 'action', + 'project' => $project, + 'user' => $user, + 'bucket' => $bucket, + 'file' => $file, + 'fileSecurity' => $fileSecurity, + 'resourceToken' => $resourceToken, + 'maxAge' => $maxAge, + 'isImageTransformation' => true, + ]); + $response - ->addHeader('Cache-Control', 'private, max-age=2592000') // 30 days + ->addHeader('Cache-Control', $cacheControl ?? "private, max-age={$maxAge}") ->setContentType($contentType) ->file($data); From 7b5a5b8d197a387393f0e5b52274a097fc168002 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 08:44:35 +0530 Subject: [PATCH 196/211] Rename storage cache control hook --- app/controllers/shared/api.php | 8 ++++---- app/init/resources.php | 6 ++++-- .../Modules/Storage/Http/Buckets/Files/Preview/Get.php | 8 ++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 3c8f1d4425..edbf2a871d 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -501,8 +501,8 @@ Http::init() ->inject('telemetry') ->inject('platform') ->inject('authorization') - ->inject('cacheControlForResponse') - ->action(function (Http $utopia, Request $request, Response $response, Document $project, User $user, Event $queueForEvents, Messaging $queueForMessaging, AuditContext $auditContext, Delete $queueForDeletes, EventDatabase $queueForDatabase, Context $usage, Func $queueForFunctions, Mail $queueForMails, Database $dbForProject, callable $timelimit, Document $resourceToken, string $mode, ?Key $apiKey, array $plan, Document $devKey, Telemetry $telemetry, array $platform, Authorization $authorization, callable $cacheControlForResponse) { + ->inject('cacheControlForStorage') + ->action(function (Http $utopia, Request $request, Response $response, Document $project, User $user, Event $queueForEvents, Messaging $queueForMessaging, AuditContext $auditContext, Delete $queueForDeletes, EventDatabase $queueForDatabase, Context $usage, Func $queueForFunctions, Mail $queueForMails, Database $dbForProject, callable $timelimit, Document $resourceToken, string $mode, ?Key $apiKey, array $plan, Document $devKey, Telemetry $telemetry, array $platform, Authorization $authorization, callable $cacheControlForStorage) { $response->setUser($user); $request->setUser($user); @@ -706,7 +706,7 @@ Http::init() $cache->save($key, $data); } - $cacheControl = $cacheControlForResponse([ + $cacheControl = $cacheControlForStorage([ 'route' => $route, 'source' => 'cache', 'project' => $project, @@ -721,7 +721,7 @@ Http::init() ]); $response - ->addHeader('Cache-Control', $cacheControl ?? sprintf('private, max-age=%d', $timestamp)) + ->addHeader('Cache-Control', $cacheControl) ->addHeader('X-Appwrite-Cache', 'hit') ->setContentType($cacheLog->getAttribute('mimeType')); $storageCacheOperationsCounter->add(1, ['result' => 'hit']); diff --git a/app/init/resources.php b/app/init/resources.php index 03fe9ce709..341d26dd4c 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -203,8 +203,10 @@ $container->set('cache', function (Group $pools, Telemetry $telemetry) { return $cache; }, ['pools', 'telemetry']); -$container->set('cacheControlForResponse', fn () => function (array $context): ?string { - return null; +$container->set('cacheControlForStorage', fn () => function (array $context): string { + $maxAge = $context['maxAge'] ?? 0; + + return \sprintf('private, max-age=%d', \is_int($maxAge) ? $maxAge : 0); }); $container->set('redis', function () { diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php index c66c38c982..e8bb8c381b 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php @@ -94,7 +94,7 @@ class Get extends Action ->inject('project') ->inject('authorization') ->inject('user') - ->inject('cacheControlForResponse') + ->inject('cacheControlForStorage') ->callback($this->action(...)); } @@ -122,7 +122,7 @@ class Get extends Action Document $project, Authorization $authorization, User $user, - callable $cacheControlForResponse + callable $cacheControlForStorage ) { if (!\extension_loaded('imagick')) { @@ -297,7 +297,7 @@ class Get extends Action } $maxAge = 2592000; // 30 days - $cacheControl = $cacheControlForResponse([ + $cacheControl = $cacheControlForStorage([ 'route' => $request->getRoute(), 'source' => 'action', 'project' => $project, @@ -311,7 +311,7 @@ class Get extends Action ]); $response - ->addHeader('Cache-Control', $cacheControl ?? "private, max-age={$maxAge}") + ->addHeader('Cache-Control', $cacheControl) ->setContentType($contentType) ->file($data); From 1208aff569aebe390cff59f7b5ff3034e29a58e5 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 08:52:24 +0530 Subject: [PATCH 197/211] Fix storage cache hook analyze --- .../Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php index e8bb8c381b..7fa10bb636 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php @@ -298,7 +298,6 @@ class Get extends Action $maxAge = 2592000; // 30 days $cacheControl = $cacheControlForStorage([ - 'route' => $request->getRoute(), 'source' => 'action', 'project' => $project, 'user' => $user, From 6abd88b8f13cc99dcc806a477ff5e2c228379f32 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 09:44:00 +0530 Subject: [PATCH 198/211] Type storage cache control config --- app/controllers/shared/api.php | 27 +++++++++--------- app/init/resources.php | 7 ++--- .../Modules/Storage/Config/CacheControl.php | 28 +++++++++++++++++++ .../Http/Buckets/Files/Preview/Get.php | 23 +++++++-------- 4 files changed, 57 insertions(+), 28 deletions(-) create mode 100644 src/Appwrite/Platform/Modules/Storage/Config/CacheControl.php diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index edbf2a871d..4e4ccc4b52 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -19,6 +19,7 @@ use Appwrite\Event\Webhook; use Appwrite\Extend\Exception; use Appwrite\Extend\Exception as AppwriteException; use Appwrite\Functions\EventProcessor; +use Appwrite\Platform\Modules\Storage\Config\CacheControl; use Appwrite\SDK\Method; use Appwrite\Usage\Context; use Appwrite\Utopia\Database\Documents\User; @@ -706,19 +707,19 @@ Http::init() $cache->save($key, $data); } - $cacheControl = $cacheControlForStorage([ - 'route' => $route, - 'source' => 'cache', - 'project' => $project, - 'user' => $user, - 'bucket' => $bucket, - 'file' => $file, - 'fileSecurity' => $fileSecurity, - 'resourceToken' => $resourceToken, - 'cacheLog' => $cacheLog, - 'maxAge' => $timestamp, - 'isImageTransformation' => $isImageTransformation, - ]); + $cacheControl = $cacheControlForStorage(new CacheControl( + source: CacheControl::SOURCE_CACHE, + project: $project, + user: $user, + bucket: $bucket, + file: $file, + resourceToken: $resourceToken, + maxAge: $timestamp, + isImageTransformation: $isImageTransformation, + fileSecurity: $fileSecurity, + cacheLog: $cacheLog, + route: $route, + )); $response ->addHeader('Cache-Control', $cacheControl) diff --git a/app/init/resources.php b/app/init/resources.php index 341d26dd4c..3142483868 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -9,6 +9,7 @@ use Appwrite\Event\Publisher\Migration as MigrationPublisher; use Appwrite\Event\Publisher\Screenshot as ScreenshotPublisher; use Appwrite\Event\Publisher\StatsResources as StatsResourcesPublisher; use Appwrite\Event\Publisher\Usage as UsagePublisher; +use Appwrite\Platform\Modules\Storage\Config\CacheControl; use Appwrite\Utopia\Database\Documents\User; use Executor\Executor; use Utopia\Abuse\Adapters\TimeLimit\Redis as TimeLimitRedis; @@ -203,10 +204,8 @@ $container->set('cache', function (Group $pools, Telemetry $telemetry) { return $cache; }, ['pools', 'telemetry']); -$container->set('cacheControlForStorage', fn () => function (array $context): string { - $maxAge = $context['maxAge'] ?? 0; - - return \sprintf('private, max-age=%d', \is_int($maxAge) ? $maxAge : 0); +$container->set('cacheControlForStorage', fn () => function (CacheControl $config): string { + return \sprintf('private, max-age=%d', $config->maxAge); }); $container->set('redis', function () { diff --git a/src/Appwrite/Platform/Modules/Storage/Config/CacheControl.php b/src/Appwrite/Platform/Modules/Storage/Config/CacheControl.php new file mode 100644 index 0000000000..643d765da5 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Storage/Config/CacheControl.php @@ -0,0 +1,28 @@ + 'action', - 'project' => $project, - 'user' => $user, - 'bucket' => $bucket, - 'file' => $file, - 'fileSecurity' => $fileSecurity, - 'resourceToken' => $resourceToken, - 'maxAge' => $maxAge, - 'isImageTransformation' => true, - ]); + $cacheControl = $cacheControlForStorage(new CacheControl( + source: CacheControl::SOURCE_ACTION, + project: $project, + user: $user, + bucket: $bucket, + file: $file, + resourceToken: $resourceToken, + maxAge: $maxAge, + isImageTransformation: true, + fileSecurity: $fileSecurity, + )); $response ->addHeader('Cache-Control', $cacheControl) From 707e5d231a80af419aaee26ae5bad696dc993810 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 09:55:33 +0530 Subject: [PATCH 199/211] Scope storage cache control to previews --- app/controllers/shared/api.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 4e4ccc4b52..d404ae501a 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -707,19 +707,22 @@ Http::init() $cache->save($key, $data); } - $cacheControl = $cacheControlForStorage(new CacheControl( - source: CacheControl::SOURCE_CACHE, - project: $project, - user: $user, - bucket: $bucket, - file: $file, - resourceToken: $resourceToken, - maxAge: $timestamp, - isImageTransformation: $isImageTransformation, - fileSecurity: $fileSecurity, - cacheLog: $cacheLog, - route: $route, - )); + $cacheControl = \sprintf('private, max-age=%d', $timestamp); + if ($isImageTransformation) { + $cacheControl = $cacheControlForStorage(new CacheControl( + source: CacheControl::SOURCE_CACHE, + project: $project, + user: $user, + bucket: $bucket, + file: $file, + resourceToken: $resourceToken, + maxAge: $timestamp, + isImageTransformation: $isImageTransformation, + fileSecurity: $fileSecurity, + cacheLog: $cacheLog, + route: $route, + )); + } $response ->addHeader('Cache-Control', $cacheControl) From bf767369718cc79f48aea0fc26447d2795ab99e0 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 09:57:33 +0530 Subject: [PATCH 200/211] Split storage cache control context --- app/controllers/shared/api.php | 37 ++++++++++--------- app/init/resources.php | 4 +- .../Modules/Storage/Config/CacheControl.php | 10 +---- .../Storage/Config/StorageCacheControl.php | 31 ++++++++++++++++ .../Http/Buckets/Files/Preview/Get.php | 7 ++-- 5 files changed, 58 insertions(+), 31 deletions(-) create mode 100644 src/Appwrite/Platform/Modules/Storage/Config/StorageCacheControl.php diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index d404ae501a..3ab2d165a3 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -20,6 +20,7 @@ use Appwrite\Extend\Exception; use Appwrite\Extend\Exception as AppwriteException; use Appwrite\Functions\EventProcessor; use Appwrite\Platform\Modules\Storage\Config\CacheControl; +use Appwrite\Platform\Modules\Storage\Config\StorageCacheControl; use Appwrite\SDK\Method; use Appwrite\Usage\Context; use Appwrite\Utopia\Database\Documents\User; @@ -641,9 +642,7 @@ Http::init() $data = $cache->load($key, $timestamp); if (! empty($data) && ! $cacheLog->isEmpty()) { - $bucket = new Document(); - $file = new Document(); - $fileSecurity = null; + $storageCacheControl = null; $parts = explode('/', $cacheLog->getAttribute('resourceType', '')); $type = $parts[0]; @@ -696,6 +695,22 @@ Http::init() ]))); } } + + if ($isImageTransformation) { + $storageCacheControl = new StorageCacheControl( + source: CacheControl::SOURCE_CACHE, + user: $user, + maxAge: $timestamp, + project: $project, + bucket: $bucket, + file: $file, + resourceToken: $resourceToken, + isImageTransformation: $isImageTransformation, + fileSecurity: $fileSecurity, + cacheLog: $cacheLog, + route: $route, + ); + } } $accessedAt = $cacheLog->getAttribute('accessedAt', ''); @@ -708,20 +723,8 @@ Http::init() } $cacheControl = \sprintf('private, max-age=%d', $timestamp); - if ($isImageTransformation) { - $cacheControl = $cacheControlForStorage(new CacheControl( - source: CacheControl::SOURCE_CACHE, - project: $project, - user: $user, - bucket: $bucket, - file: $file, - resourceToken: $resourceToken, - maxAge: $timestamp, - isImageTransformation: $isImageTransformation, - fileSecurity: $fileSecurity, - cacheLog: $cacheLog, - route: $route, - )); + if ($storageCacheControl !== null) { + $cacheControl = $cacheControlForStorage($storageCacheControl); } $response diff --git a/app/init/resources.php b/app/init/resources.php index 3142483868..c5d034a125 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -9,7 +9,7 @@ use Appwrite\Event\Publisher\Migration as MigrationPublisher; use Appwrite\Event\Publisher\Screenshot as ScreenshotPublisher; use Appwrite\Event\Publisher\StatsResources as StatsResourcesPublisher; use Appwrite\Event\Publisher\Usage as UsagePublisher; -use Appwrite\Platform\Modules\Storage\Config\CacheControl; +use Appwrite\Platform\Modules\Storage\Config\StorageCacheControl; use Appwrite\Utopia\Database\Documents\User; use Executor\Executor; use Utopia\Abuse\Adapters\TimeLimit\Redis as TimeLimitRedis; @@ -204,7 +204,7 @@ $container->set('cache', function (Group $pools, Telemetry $telemetry) { return $cache; }, ['pools', 'telemetry']); -$container->set('cacheControlForStorage', fn () => function (CacheControl $config): string { +$container->set('cacheControlForStorage', fn () => function (StorageCacheControl $config): string { return \sprintf('private, max-age=%d', $config->maxAge); }); diff --git a/src/Appwrite/Platform/Modules/Storage/Config/CacheControl.php b/src/Appwrite/Platform/Modules/Storage/Config/CacheControl.php index 643d765da5..ef2ace34ff 100644 --- a/src/Appwrite/Platform/Modules/Storage/Config/CacheControl.php +++ b/src/Appwrite/Platform/Modules/Storage/Config/CacheControl.php @@ -3,25 +3,17 @@ namespace Appwrite\Platform\Modules\Storage\Config; use Appwrite\Utopia\Database\Documents\User; -use Utopia\Database\Document; use Utopia\Http\Route; -final class CacheControl +class CacheControl { public const SOURCE_ACTION = 'action'; public const SOURCE_CACHE = 'cache'; public function __construct( public readonly string $source, - public readonly Document $project, public readonly User $user, - public readonly Document $bucket, - public readonly Document $file, - public readonly Document $resourceToken, public readonly int $maxAge, - public readonly bool $isImageTransformation, - public readonly ?bool $fileSecurity = null, - public readonly ?Document $cacheLog = null, public readonly ?Route $route = null, ) { } diff --git a/src/Appwrite/Platform/Modules/Storage/Config/StorageCacheControl.php b/src/Appwrite/Platform/Modules/Storage/Config/StorageCacheControl.php new file mode 100644 index 0000000000..ea4daddad8 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Storage/Config/StorageCacheControl.php @@ -0,0 +1,31 @@ + Date: Fri, 8 May 2026 09:59:36 +0530 Subject: [PATCH 201/211] Inline storage preview cache control --- app/controllers/shared/api.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 3ab2d165a3..0ef58862e7 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -642,7 +642,7 @@ Http::init() $data = $cache->load($key, $timestamp); if (! empty($data) && ! $cacheLog->isEmpty()) { - $storageCacheControl = null; + $cacheControl = \sprintf('private, max-age=%d', $timestamp); $parts = explode('/', $cacheLog->getAttribute('resourceType', '')); $type = $parts[0]; @@ -697,7 +697,7 @@ Http::init() } if ($isImageTransformation) { - $storageCacheControl = new StorageCacheControl( + $cacheControl = $cacheControlForStorage(new StorageCacheControl( source: CacheControl::SOURCE_CACHE, user: $user, maxAge: $timestamp, @@ -709,7 +709,7 @@ Http::init() fileSecurity: $fileSecurity, cacheLog: $cacheLog, route: $route, - ); + )); } } @@ -722,11 +722,6 @@ Http::init() $cache->save($key, $data); } - $cacheControl = \sprintf('private, max-age=%d', $timestamp); - if ($storageCacheControl !== null) { - $cacheControl = $cacheControlForStorage($storageCacheControl); - } - $response ->addHeader('Cache-Control', $cacheControl) ->addHeader('X-Appwrite-Cache', 'hit') From 48e2ee9acb5b606a2c0de76e94e9ff025454eb0d Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 10:04:40 +0530 Subject: [PATCH 202/211] Test storage preview cache headers --- tests/e2e/Services/Storage/StorageBase.php | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index 29f7d70435..80fe5a9984 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -957,6 +957,64 @@ trait StorageBase $this->assertNotEquals($imageBefore->getImageBlob(), $imageAfter->getImageBlob()); } + public function testFilePreviewCacheControlOnCacheHit(): void + { + $data = $this->setupBucketFile(); + $bucketId = $data['bucketId']; + $file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'fileId' => ID::unique(), + 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'), + 'permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + ]); + $this->assertEquals(201, $file['headers']['status-code']); + $this->assertNotEmpty($file['body']['$id']); + + $fileId = $file['body']['$id']; + $params = [ + 'width' => 123, + 'height' => 45, + 'output' => 'png', + 'quality' => 80, + ]; + $headers = array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()); + + $preview = $this->client->call( + Client::METHOD_GET, + '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', + $headers, + $params + ); + + $this->assertEquals(200, $preview['headers']['status-code']); + $this->assertEquals('image/png', $preview['headers']['content-type']); + $this->assertEquals('private, max-age=2592000', $preview['headers']['cache-control']); + $this->assertArrayNotHasKey('x-appwrite-cache', $preview['headers']); + $this->assertNotEmpty($preview['body']); + + $cachedPreview = $this->client->call( + Client::METHOD_GET, + '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', + $headers, + $params + ); + + $this->assertEquals(200, $cachedPreview['headers']['status-code']); + $this->assertEquals('image/png', $cachedPreview['headers']['content-type']); + $this->assertEquals('hit', $cachedPreview['headers']['x-appwrite-cache']); + $this->assertEquals('private, max-age=15552000', $cachedPreview['headers']['cache-control']); + $this->assertEquals($preview['body'], $cachedPreview['body']); + } + public function testFilePreviewZstdCompression(): void { $data = $this->setupZstdCompressionBucket(); From 96e51936013fcffb1204ce06e78db38a273bd7c9 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 10:18:34 +0530 Subject: [PATCH 203/211] Fix storage preview cache e2e assertion --- tests/e2e/Services/Storage/StorageBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index 80fe5a9984..078a67f55d 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -998,7 +998,7 @@ trait StorageBase $this->assertEquals(200, $preview['headers']['status-code']); $this->assertEquals('image/png', $preview['headers']['content-type']); $this->assertEquals('private, max-age=2592000', $preview['headers']['cache-control']); - $this->assertArrayNotHasKey('x-appwrite-cache', $preview['headers']); + $this->assertEquals('miss', $preview['headers']['x-appwrite-cache']); $this->assertNotEmpty($preview['body']); $cachedPreview = $this->client->call( From 75a30793ac134cc5a0ff305aad6108ff32c6780a Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 10:42:39 +0530 Subject: [PATCH 204/211] Remove preview flag from storage cache config --- app/controllers/shared/api.php | 1 - .../Platform/Modules/Storage/Config/StorageCacheControl.php | 1 - .../Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php | 1 - 3 files changed, 3 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 0ef58862e7..14ffdc059f 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -705,7 +705,6 @@ Http::init() bucket: $bucket, file: $file, resourceToken: $resourceToken, - isImageTransformation: $isImageTransformation, fileSecurity: $fileSecurity, cacheLog: $cacheLog, route: $route, diff --git a/src/Appwrite/Platform/Modules/Storage/Config/StorageCacheControl.php b/src/Appwrite/Platform/Modules/Storage/Config/StorageCacheControl.php index ea4daddad8..2e076fa782 100644 --- a/src/Appwrite/Platform/Modules/Storage/Config/StorageCacheControl.php +++ b/src/Appwrite/Platform/Modules/Storage/Config/StorageCacheControl.php @@ -16,7 +16,6 @@ final class StorageCacheControl extends CacheControl public readonly Document $bucket, public readonly Document $file, public readonly Document $resourceToken, - public readonly bool $isImageTransformation, public readonly bool $fileSecurity, public readonly ?Document $cacheLog = null, ?Route $route = null, diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php index 36f362a825..cb0d8c76ef 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php @@ -307,7 +307,6 @@ class Get extends Action bucket: $bucket, file: $file, resourceToken: $resourceToken, - isImageTransformation: true, fileSecurity: $fileSecurity, )); From 8e274012bd550c5641d94e026ae4660945bf5f04 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 10:48:12 +0530 Subject: [PATCH 205/211] Relax storage preview cache max-age assertion --- tests/e2e/Services/Storage/StorageBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index 078a67f55d..9177108ca6 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -1011,7 +1011,7 @@ trait StorageBase $this->assertEquals(200, $cachedPreview['headers']['status-code']); $this->assertEquals('image/png', $cachedPreview['headers']['content-type']); $this->assertEquals('hit', $cachedPreview['headers']['x-appwrite-cache']); - $this->assertEquals('private, max-age=15552000', $cachedPreview['headers']['cache-control']); + $this->assertStringStartsWith('private, max-age=', $cachedPreview['headers']['cache-control']); $this->assertEquals($preview['body'], $cachedPreview['body']); } From 2207fff44d85fa7fb2a6b35a363470ec982e668b Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 10:52:31 +0530 Subject: [PATCH 206/211] Wait for storage preview cache hit in e2e --- tests/e2e/Services/Storage/StorageBase.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index 9177108ca6..5e09031a9c 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -1001,16 +1001,20 @@ trait StorageBase $this->assertEquals('miss', $preview['headers']['x-appwrite-cache']); $this->assertNotEmpty($preview['body']); - $cachedPreview = $this->client->call( - Client::METHOD_GET, - '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', - $headers, - $params - ); + $cachedPreview = []; + $this->assertEventually(function () use (&$cachedPreview, $bucketId, $fileId, $headers, $params) { + $cachedPreview = $this->client->call( + Client::METHOD_GET, + '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', + $headers, + $params + ); + + $this->assertEquals('hit', $cachedPreview['headers']['x-appwrite-cache']); + }); $this->assertEquals(200, $cachedPreview['headers']['status-code']); $this->assertEquals('image/png', $cachedPreview['headers']['content-type']); - $this->assertEquals('hit', $cachedPreview['headers']['x-appwrite-cache']); $this->assertStringStartsWith('private, max-age=', $cachedPreview['headers']['cache-control']); $this->assertEquals($preview['body'], $cachedPreview['body']); } From 9337daf7ac6dc397bf4595cb16fc8b9d8aeeda42 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 11:15:17 +0530 Subject: [PATCH 207/211] Preserve default storage cache hit max age --- app/init/resources.php | 5 +++++ tests/e2e/Services/Storage/StorageBase.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/init/resources.php b/app/init/resources.php index c5d034a125..edd75e33d4 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -9,6 +9,7 @@ use Appwrite\Event\Publisher\Migration as MigrationPublisher; use Appwrite\Event\Publisher\Screenshot as ScreenshotPublisher; use Appwrite\Event\Publisher\StatsResources as StatsResourcesPublisher; use Appwrite\Event\Publisher\Usage as UsagePublisher; +use Appwrite\Platform\Modules\Storage\Config\CacheControl; use Appwrite\Platform\Modules\Storage\Config\StorageCacheControl; use Appwrite\Utopia\Database\Documents\User; use Executor\Executor; @@ -205,6 +206,10 @@ $container->set('cache', function (Group $pools, Telemetry $telemetry) { }, ['pools', 'telemetry']); $container->set('cacheControlForStorage', fn () => function (StorageCacheControl $config): string { + if ($config->source === CacheControl::SOURCE_CACHE) { + return 'private, max-age=15552000'; + } + return \sprintf('private, max-age=%d', $config->maxAge); }); diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index 5e09031a9c..56112101bf 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -1015,7 +1015,7 @@ trait StorageBase $this->assertEquals(200, $cachedPreview['headers']['status-code']); $this->assertEquals('image/png', $cachedPreview['headers']['content-type']); - $this->assertStringStartsWith('private, max-age=', $cachedPreview['headers']['cache-control']); + $this->assertEquals('private, max-age=15552000', $cachedPreview['headers']['cache-control']); $this->assertEquals($preview['body'], $cachedPreview['body']); } From 8ebf4fee46b28771aec991a67b108bf3340a3b8f Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 11:18:55 +0530 Subject: [PATCH 208/211] Use storage cache callback max age --- app/init/resources.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/init/resources.php b/app/init/resources.php index edd75e33d4..c5d034a125 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -9,7 +9,6 @@ use Appwrite\Event\Publisher\Migration as MigrationPublisher; use Appwrite\Event\Publisher\Screenshot as ScreenshotPublisher; use Appwrite\Event\Publisher\StatsResources as StatsResourcesPublisher; use Appwrite\Event\Publisher\Usage as UsagePublisher; -use Appwrite\Platform\Modules\Storage\Config\CacheControl; use Appwrite\Platform\Modules\Storage\Config\StorageCacheControl; use Appwrite\Utopia\Database\Documents\User; use Executor\Executor; @@ -206,10 +205,6 @@ $container->set('cache', function (Group $pools, Telemetry $telemetry) { }, ['pools', 'telemetry']); $container->set('cacheControlForStorage', fn () => function (StorageCacheControl $config): string { - if ($config->source === CacheControl::SOURCE_CACHE) { - return 'private, max-age=15552000'; - } - return \sprintf('private, max-age=%d', $config->maxAge); }); From 3d35d140d123da68843b6895179aebf874a8d8ac Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 8 May 2026 11:27:35 +0530 Subject: [PATCH 209/211] Relax storage preview cache hit max age --- tests/e2e/Services/Storage/StorageBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index 56112101bf..5e09031a9c 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -1015,7 +1015,7 @@ trait StorageBase $this->assertEquals(200, $cachedPreview['headers']['status-code']); $this->assertEquals('image/png', $cachedPreview['headers']['content-type']); - $this->assertEquals('private, max-age=15552000', $cachedPreview['headers']['cache-control']); + $this->assertStringStartsWith('private, max-age=', $cachedPreview['headers']['cache-control']); $this->assertEquals($preview['body'], $cachedPreview['body']); } From 6a0d2d53148444174e1d0912ab7d0ed34665a4bc Mon Sep 17 00:00:00 2001 From: Levi van Noort <73097785+levivannoort@users.noreply.github.com> Date: Fri, 8 May 2026 09:01:36 +0200 Subject: [PATCH 210/211] chore: add bigger disks to the provisioned setup --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b80746db1..6743c7f5e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -445,19 +445,19 @@ jobs: ] include: - service: Databases - runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7 + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/disk=large paratest_processes: 3 timeout_minutes: 30 - service: Sites - runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7 + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/disk=large - service: Functions - runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7 + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/disk=large - service: Avatars - runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7 + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/disk=large - service: Realtime - runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7 + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/disk=large - service: TablesDB - runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7 + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/disk=large paratest_processes: 3 timeout_minutes: 30 - service: Migrations From bd0e7456a79938b593e0d6e0c1e2e32ed88dc969 Mon Sep 17 00:00:00 2001 From: Levi van Noort <73097785+levivannoort@users.noreply.github.com> Date: Fri, 8 May 2026 09:08:42 +0200 Subject: [PATCH 211/211] refactor: update ci runners to use volume instead of disk --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6743c7f5e7..260a4656cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -445,19 +445,19 @@ jobs: ] include: - service: Databases - runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/disk=large + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/volume=120g paratest_processes: 3 timeout_minutes: 30 - service: Sites - runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/disk=large + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/volume=120g - service: Functions - runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/disk=large + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/volume=120g - service: Avatars - runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/disk=large + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/volume=120g - service: Realtime - runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/disk=large + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/volume=120g - service: TablesDB - runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/disk=large + runner: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/family=c7/volume=120g paratest_processes: 3 timeout_minutes: 30 - service: Migrations