From 3cfe4dca6a8d1e8b77d0edf45c2d3d244608d178 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 17 Jul 2026 23:31:19 +1200 Subject: [PATCH 01/14] refactor(migrations): separate root and child resources --- app/config/collections/projects.php | 79 ++ app/controllers/general.php | 8 + composer.json | 26 +- composer.lock | 754 +++++++++--------- src/Appwrite/Migration/Version/V25.php | 193 +++-- .../Http/Migrations/CSV/Exports/Create.php | 26 +- .../Http/Migrations/CSV/Imports/Create.php | 28 +- .../Http/Migrations/JSON/Exports/Create.php | 26 +- .../Http/Migrations/JSON/Imports/Create.php | 24 +- src/Appwrite/Platform/Workers/Migrations.php | 75 +- .../Database/Validator/Queries/Migrations.php | 4 +- src/Appwrite/Utopia/Request/Filters/V27.php | 38 + src/Appwrite/Utopia/Response/Filters/V27.php | 41 + .../Utopia/Response/Model/Migration.php | 39 +- .../Services/Migrations/MigrationsBase.php | 87 +- tests/unit/Migration/Version/V25Test.php | 103 +++ tests/unit/Utopia/Request/Filters/V27Test.php | 49 ++ .../unit/Utopia/Response/Filters/V27Test.php | 79 ++ 18 files changed, 1104 insertions(+), 575 deletions(-) create mode 100644 src/Appwrite/Utopia/Request/Filters/V27.php create mode 100644 src/Appwrite/Utopia/Response/Filters/V27.php create mode 100644 tests/unit/Migration/Version/V25Test.php create mode 100644 tests/unit/Utopia/Request/Filters/V27Test.php create mode 100644 tests/unit/Utopia/Response/Filters/V27Test.php diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index 9b1f5bc74d..c4aa686b72 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -2267,6 +2267,17 @@ return [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('resourceInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('resourceType'), 'type' => Database::VAR_STRING, @@ -2278,6 +2289,39 @@ return [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('parentResourceId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => ID::custom('parentResourceInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => ID::custom('parentResourceType'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], ], 'indexes' => [ [ @@ -2308,6 +2352,41 @@ return [ 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_DESC], ], + [ + '$id' => '_key_resourceType', + 'type' => Database::INDEX_KEY, + 'attributes' => ['resourceType'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], + [ + '$id' => '_key_resourceInternalId', + 'type' => Database::INDEX_KEY, + 'attributes' => ['resourceInternalId'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], + [ + '$id' => '_key_parentResourceId', + 'type' => Database::INDEX_KEY, + 'attributes' => ['parentResourceId'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], + [ + '$id' => '_key_parentResourceType', + 'type' => Database::INDEX_KEY, + 'attributes' => ['parentResourceType'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], + [ + '$id' => '_key_parentResourceInternalId', + 'type' => Database::INDEX_KEY, + 'attributes' => ['parentResourceInternalId'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], [ '$id' => ID::custom('_fulltext_search'), 'type' => Database::INDEX_FULLTEXT, diff --git a/app/controllers/general.php b/app/controllers/general.php index fd622a4784..47b4ecd097 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -34,6 +34,7 @@ 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\Request\Filters\V26 as RequestV26; +use Appwrite\Utopia\Request\Filters\V27 as RequestV27; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Filters\V16 as ResponseV16; use Appwrite\Utopia\Response\Filters\V17 as ResponseV17; @@ -46,6 +47,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\Response\Filters\V26 as ResponseV26; +use Appwrite\Utopia\Response\Filters\V27 as ResponseV27; use Appwrite\Utopia\View; use Executor\Exception\Timeout as ExecutorTimeout; use Executor\Executor; @@ -917,6 +919,9 @@ Http::init() if (version_compare($requestFormat, '1.9.5', '<')) { $request->addFilter(new RequestV26()); } + if (version_compare($requestFormat, '1.9.6', '<')) { + $request->addFilter(new RequestV27()); + } } $localeParam = (string) $request->getParam('locale', $request->getHeaderLine('x-appwrite-locale', '')); @@ -941,6 +946,9 @@ Http::init() */ $responseFormat = $request->getHeaderLine('x-appwrite-response-format', System::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '')); if ($responseFormat) { + if (version_compare($responseFormat, '1.9.6', '<')) { + $response->addFilter(new ResponseV27()); + } if (version_compare($responseFormat, '1.9.5', '<')) { $response->addFilter(new ResponseV26()); } diff --git a/composer.json b/composer.json index 8aa00f578d..3178893a90 100644 --- a/composer.json +++ b/composer.json @@ -40,11 +40,11 @@ "repositories": [ { "type": "vcs", - "url": "https://github.com/utopia-php/auth" + "url": "https://github.com/utopia-php/migration" } ], "require": { - "php": ">=8.5.0", + "php": ">=8.3.0", "ext-curl": "*", "ext-imagick": "*", "ext-mbstring": "*", @@ -62,14 +62,14 @@ "utopia-php/abuse": "1.4.*", "utopia-php/agents": "2.*", "utopia-php/analytics": "0.15.*", - "utopia-php/audit": "2.9.*", - "utopia-php/auth": "^0.10", - "utopia-php/cache": "^3.0.0", + "utopia-php/audit": "2.6.*", + "utopia-php/auth": "^0.7", + "utopia-php/cache": "^3.0", "utopia-php/cli": "^0.24", "utopia-php/compression": "0.1.*", "utopia-php/config": "1.*", "utopia-php/console": "0.1.*", - "utopia-php/database": "^6.0.0", + "utopia-php/database": "6.0.*", "utopia-php/detector": "0.2.*", "utopia-php/domains": "^2.2", "utopia-php/emails": "0.7.*", @@ -77,24 +77,24 @@ "utopia-php/dsn": "0.2.1", "utopia-php/http": "^2.0@RC", "utopia-php/fetch": "^1.1", - "utopia-php/validators": "0.3.*", + "utopia-php/validators": "0.2.*", "utopia-php/image": "0.8.*", "utopia-php/locale": "0.8.*", "utopia-php/lock": "0.2.*", "utopia-php/logger": "0.8.*", - "utopia-php/messaging": "^2.0", - "utopia-php/migration": "1.17.*", + "utopia-php/messaging": "^1.2", + "utopia-php/migration": "dev-feat/drop-compound-resource-id#a7e94c86a96fc7cdfff3eae9845270d91f83e7f8 as 1.17.3", "utopia-php/platform": "^1.0@RC", "utopia-php/pools": "1.*", "utopia-php/span": "3.0.*", "utopia-php/preloader": "0.2.*", - "utopia-php/queue": "^0.22", + "utopia-php/queue": "^0.21", "utopia-php/servers": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/storage": "2.*", "utopia-php/system": "0.10.*", "utopia-php/telemetry": "^0.4", - "utopia-php/vcs": "^4.4.2", + "utopia-php/vcs": "4.*", "utopia-php/websocket": "1.0.*", "matomo/device-detector": "6.4.*", "dragonmantank/cron-expression": "3.4.*", @@ -104,9 +104,7 @@ "spomky-labs/otphp": "11.*", "webonyx/graphql-php": "15.32.*", "league/csv": "9.14.*", - "enshrined/svg-sanitize": "0.22.*", - "utopia-php/client": "^0.2.2", - "open-runtimes/sdk-for-php": "^0.4.0" + "enshrined/svg-sanitize": "0.22.*" }, "require-dev": { "ext-fileinfo": "*", diff --git a/composer.lock b/composer.lock index c37a91b918..e73fdc4039 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": "5748e1f0a2a6b943979fd57679d8842c", + "content-hash": "4d8282e455d647d1132ef9c0340924a1", "packages": [ { "name": "adhocore/jwt", @@ -216,22 +216,23 @@ }, { "name": "brick/math", - "version": "0.18.0", + "version": "0.14.8", "source": { "type": "git", "url": "https://github.com/brick/math.git", - "reference": "82944324d1c1bdb2c2618e89978d4e2ad78d69ad" + "reference": "63422359a44b7f06cae63c3b429b59e8efcc0629" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/brick/math/zipball/82944324d1c1bdb2c2618e89978d4e2ad78d69ad", - "reference": "82944324d1c1bdb2c2618e89978d4e2ad78d69ad", + "url": "https://api.github.com/repos/brick/math/zipball/63422359a44b7f06cae63c3b429b59e8efcc0629", + "reference": "63422359a44b7f06cae63c3b429b59e8efcc0629", "shasum": "" }, "require": { "php": "^8.2" }, "require-dev": { + "php-coveralls/php-coveralls": "^2.2", "phpstan/phpstan": "2.1.22", "phpunit/phpunit": "^11.5" }, @@ -263,7 +264,7 @@ ], "support": { "issues": "https://github.com/brick/math/issues", - "source": "https://github.com/brick/math/tree/0.18.0" + "source": "https://github.com/brick/math/tree/0.14.8" }, "funding": [ { @@ -271,7 +272,7 @@ "type": "github" } ], - "time": "2026-06-14T18:21:03+00:00" + "time": "2026-02-10T14:33:43+00:00" }, { "name": "chillerlan/php-qrcode", @@ -605,6 +606,84 @@ }, "time": "2025-08-12T10:13:48+00:00" }, + { + "name": "giggsey/libphonenumber-for-php-lite", + "version": "9.0.23", + "source": { + "type": "git", + "url": "https://github.com/giggsey/libphonenumber-for-php-lite.git", + "reference": "e8f6f896c1bef398136849934a934904bd9bf072" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/giggsey/libphonenumber-for-php-lite/zipball/e8f6f896c1bef398136849934a934904bd9bf072", + "reference": "e8f6f896c1bef398136849934a934904bd9bf072", + "shasum": "" + }, + "require": { + "php": "^8.1", + "symfony/polyfill-mbstring": "^1.17" + }, + "conflict": { + "giggsey/libphonenumber-for-php": "*" + }, + "require-dev": { + "ext-dom": "*", + "friendsofphp/php-cs-fixer": "^3.71", + "infection/infection": "^0.29|^0.31.0", + "nette/php-generator": "^4.1", + "php-coveralls/php-coveralls": "^2.7", + "phpstan/extension-installer": "^1.4.3", + "phpstan/phpstan": "^2.1.7", + "phpstan/phpstan-deprecation-rules": "^2.0.1", + "phpstan/phpstan-phpunit": "^2.0.4", + "phpstan/phpstan-strict-rules": "^2.0.3", + "phpunit/phpunit": "^10.5.45", + "symfony/console": "^6.4", + "symfony/filesystem": "^6.4", + "symfony/process": "^6.4" + }, + "suggest": { + "giggsey/libphonenumber-for-php": "Use libphonenumber-for-php for geocoding, carriers, timezones and matching" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.x-dev" + } + }, + "autoload": { + "psr-4": { + "libphonenumber\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Joshua Gigg", + "email": "giggsey@gmail.com", + "homepage": "https://giggsey.com/" + } + ], + "description": "A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber", + "homepage": "https://github.com/giggsey/libphonenumber-for-php-lite", + "keywords": [ + "geocoding", + "geolocation", + "libphonenumber", + "mobile", + "phonenumber", + "validation" + ], + "support": { + "issues": "https://github.com/giggsey/libphonenumber-for-php-lite/issues", + "source": "https://github.com/giggsey/libphonenumber-for-php-lite" + }, + "time": "2026-01-30T12:33:03+00:00" + }, { "name": "google/protobuf", "version": "v4.33.6", @@ -1145,49 +1224,6 @@ ], "time": "2023-11-08T09:30:43+00:00" }, - { - "name": "open-runtimes/sdk-for-php", - "version": "0.4.0", - "source": { - "type": "git", - "url": "https://github.com/open-runtimes/sdk-for-php.git", - "reference": "02c01ec6c807f43602d93534252e96c9451ecd80" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/open-runtimes/sdk-for-php/zipball/02c01ec6c807f43602d93534252e96c9451ecd80", - "reference": "02c01ec6c807f43602d93534252e96c9451ecd80", - "shasum": "" - }, - "require": { - "ext-curl": "*", - "ext-json": "*", - "php": ">=8.4", - "utopia-php/client": "^0.2.2" - }, - "require-dev": { - "laravel/pint": "^1.22", - "phpstan/phpstan": "^2.1", - "phpunit/phpunit": "^13.1", - "rector/rector": "^2.4" - }, - "type": "library", - "autoload": { - "psr-4": { - "OpenRuntimes\\Orchestrator\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "PHP SDK for the Open Runtimes orchestrator Jobs API.", - "support": { - "issues": "https://github.com/open-runtimes/sdk-for-php/issues", - "source": "https://github.com/open-runtimes/sdk-for-php/tree/0.4.0" - }, - "time": "2026-07-13T21:55:56+00:00" - }, { "name": "open-telemetry/api", "version": "1.9.0", @@ -2216,20 +2252,20 @@ }, { "name": "ramsey/uuid", - "version": "4.9.3", + "version": "4.9.2", "source": { "type": "git", "url": "https://github.com/ramsey/uuid.git", - "reference": "1df15849d00943a67d677dc9cfd80795f038c9f8" + "reference": "8429c78ca35a09f27565311b98101e2826affde0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/uuid/zipball/1df15849d00943a67d677dc9cfd80795f038c9f8", - "reference": "1df15849d00943a67d677dc9cfd80795f038c9f8", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/8429c78ca35a09f27565311b98101e2826affde0", + "reference": "8429c78ca35a09f27565311b98101e2826affde0", "shasum": "" }, "require": { - "brick/math": ">=0.8.16 <=0.18", + "brick/math": "^0.8.16 || ^0.9 || ^0.10 || ^0.11 || ^0.12 || ^0.13 || ^0.14", "php": "^8.0", "ramsey/collection": "^1.2 || ^2.0" }, @@ -2288,9 +2324,9 @@ ], "support": { "issues": "https://github.com/ramsey/uuid/issues", - "source": "https://github.com/ramsey/uuid/tree/4.9.3" + "source": "https://github.com/ramsey/uuid/tree/4.9.2" }, - "time": "2026-06-18T03:57:49+00:00" + "time": "2025-12-14T04:43:48+00:00" }, { "name": "spomky-labs/otphp", @@ -2364,16 +2400,16 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.7.1", + "version": "v3.7.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "f3202fa1b5097b0af062dc978b32ecf63404e31d" + "reference": "50f59d1f3ca46d41ac911f97a78626b6756af35b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/f3202fa1b5097b0af062dc978b32ecf63404e31d", - "reference": "f3202fa1b5097b0af062dc978b32ecf63404e31d", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/50f59d1f3ca46d41ac911f97a78626b6756af35b", + "reference": "50f59d1f3ca46d41ac911f97a78626b6756af35b", "shasum": "" }, "require": { @@ -2411,7 +2447,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.7.1" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.7.0" }, "funding": [ { @@ -2431,20 +2467,20 @@ "type": "tidelift" } ], - "time": "2026-06-05T06:23:12+00:00" + "time": "2026-04-13T15:52:40+00:00" }, { "name": "symfony/http-client", - "version": "v7.4.14", + "version": "v7.4.13", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "f6bc6b5a54ff5afac4725cacec9bf2f52eb15920" + "reference": "e8a112b8415707265a7e614278136a9d92989a6a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/f6bc6b5a54ff5afac4725cacec9bf2f52eb15920", - "reference": "f6bc6b5a54ff5afac4725cacec9bf2f52eb15920", + "url": "https://api.github.com/repos/symfony/http-client/zipball/e8a112b8415707265a7e614278136a9d92989a6a", + "reference": "e8a112b8415707265a7e614278136a9d92989a6a", "shasum": "" }, "require": { @@ -2512,7 +2548,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.4.14" + "source": "https://github.com/symfony/http-client/tree/v7.4.13" }, "funding": [ { @@ -2532,20 +2568,20 @@ "type": "tidelift" } ], - "time": "2026-06-16T11:50:14+00:00" + "time": "2026-05-24T09:57:54+00:00" }, { "name": "symfony/http-client-contracts", - "version": "v3.7.1", + "version": "v3.7.0", "source": { "type": "git", "url": "https://github.com/symfony/http-client-contracts.git", - "reference": "41fc42d276aeff21192465331ebbab7d83a743c0" + "reference": "4a2d00c37651c0bdc2b9e1c773487a8bf4edb12d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/41fc42d276aeff21192465331ebbab7d83a743c0", - "reference": "41fc42d276aeff21192465331ebbab7d83a743c0", + "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/4a2d00c37651c0bdc2b9e1c773487a8bf4edb12d", + "reference": "4a2d00c37651c0bdc2b9e1c773487a8bf4edb12d", "shasum": "" }, "require": { @@ -2594,7 +2630,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/http-client-contracts/tree/v3.7.1" + "source": "https://github.com/symfony/http-client-contracts/tree/v3.7.0" }, "funding": [ { @@ -2614,7 +2650,7 @@ "type": "tidelift" } ], - "time": "2026-06-05T06:23:12+00:00" + "time": "2026-03-06T13:17:50+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -2943,16 +2979,16 @@ }, { "name": "symfony/service-contracts", - "version": "v3.7.1", + "version": "v3.7.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "c0a284bab1ed8aa0417e3d69250ab437739563a0" + "reference": "d25d82433a80eba6aa0e6c24b61d7370d99e444a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/c0a284bab1ed8aa0417e3d69250ab437739563a0", - "reference": "c0a284bab1ed8aa0417e3d69250ab437739563a0", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/d25d82433a80eba6aa0e6c24b61d7370d99e444a", + "reference": "d25d82433a80eba6aa0e6c24b61d7370d99e444a", "shasum": "" }, "require": { @@ -3006,7 +3042,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.7.1" + "source": "https://github.com/symfony/service-contracts/tree/v3.7.0" }, "funding": [ { @@ -3026,7 +3062,7 @@ "type": "tidelift" } ], - "time": "2026-06-16T09:55:08+00:00" + "time": "2026-03-28T09:44:51+00:00" }, { "name": "tbachert/spi", @@ -3082,16 +3118,16 @@ }, { "name": "utopia-php/abuse", - "version": "1.4.2", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "3b527181546d6191ac2d028a2fd1e500ca90f999" + "reference": "8f5df0274869cf9022eea7d8030ca1a0d458b3b2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/3b527181546d6191ac2d028a2fd1e500ca90f999", - "reference": "3b527181546d6191ac2d028a2fd1e500ca90f999", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/8f5df0274869cf9022eea7d8030ca1a0d458b3b2", + "reference": "8f5df0274869cf9022eea7d8030ca1a0d458b3b2", "shasum": "" }, "require": { @@ -3099,9 +3135,8 @@ "ext-curl": "*", "ext-pdo": "*", "ext-redis": "*", - "php": ">=8.4.1", - "utopia-php/database": "^6.0.0", - "utopia-php/pools": "1.*" + "php": ">=8.2", + "utopia-php/database": "^6.0.0" }, "require-dev": { "laravel/pint": "1.*", @@ -3129,9 +3164,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/1.4.2" + "source": "https://github.com/utopia-php/abuse/tree/1.4.1" }, - "time": "2026-06-19T07:18:23+00:00" + "time": "2026-06-18T11:18:52+00:00" }, { "name": "utopia-php/agents", @@ -3234,24 +3269,29 @@ }, { "name": "utopia-php/audit", - "version": "2.9.0", + "version": "2.6.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "322fd475836be6aa20f8e7ec017299ac55b3c8f4" + "reference": "f5bb07841e335e9ea7d4bd5860da1f580447014a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/322fd475836be6aa20f8e7ec017299ac55b3c8f4", - "reference": "322fd475836be6aa20f8e7ec017299ac55b3c8f4", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/f5bb07841e335e9ea7d4bd5860da1f580447014a", + "reference": "f5bb07841e335e9ea7d4bd5860da1f580447014a", "shasum": "" }, "require": { - "php": ">=8.5", + "php": ">=8.4", "utopia-php/database": "^6.0.0", "utopia-php/fetch": "^1.1", "utopia-php/query": "0.1.*", - "utopia-php/validators": "0.3.*" + "utopia-php/validators": "0.2.*" + }, + "require-dev": { + "laravel/pint": "1.*", + "phpstan/phpstan": "1.*", + "phpunit/phpunit": "9.*" }, "type": "library", "autoload": { @@ -3273,22 +3313,22 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/2.9.0" + "source": "https://github.com/utopia-php/audit/tree/2.6.0" }, - "time": "2026-07-15T10:27:51+00:00" + "time": "2026-06-22T03:33:28+00:00" }, { "name": "utopia-php/auth", - "version": "0.10.0", + "version": "0.7.0", "source": { "type": "git", "url": "https://github.com/utopia-php/auth.git", - "reference": "fc6e7861a0428415a7454ba808a511cc01bf8db4" + "reference": "22a2cf6ca604e5cc6bf10f0f8240195f0baa063a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/auth/zipball/fc6e7861a0428415a7454ba808a511cc01bf8db4", - "reference": "fc6e7861a0428415a7454ba808a511cc01bf8db4", + "url": "https://api.github.com/repos/utopia-php/auth/zipball/22a2cf6ca604e5cc6bf10f0f8240195f0baa063a", + "reference": "22a2cf6ca604e5cc6bf10f0f8240195f0baa063a", "shasum": "" }, "require": { @@ -3296,7 +3336,7 @@ "ext-openssl": "*", "ext-scrypt": "*", "ext-sodium": "*", - "php": ">=8.3" + "php": ">=8.1" }, "type": "library", "autoload": { @@ -3304,16 +3344,7 @@ "Utopia\\Auth\\": "src/Auth" } }, - "autoload-dev": { - "psr-4": { - "Utopia\\Tests\\Auth\\": "tests/Auth" - } - }, - "scripts": { - "test": [ - "phpunit --configuration phpunit.xml" - ] - }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -3325,29 +3356,29 @@ ], "description": "A simple PHP authentication library", "keywords": [ + "Authentication", "auth", - "authentication", "php", "security" ], "support": { - "source": "https://github.com/utopia-php/auth/tree/0.10.0", - "issues": "https://github.com/utopia-php/auth/issues" + "issues": "https://github.com/utopia-php/auth/issues", + "source": "https://github.com/utopia-php/auth/tree/0.7.0" }, - "time": "2026-07-15T15:52:58+00:00" + "time": "2026-06-22T11:58:24+00:00" }, { "name": "utopia-php/cache", - "version": "3.4.0", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/utopia-php/cache.git", - "reference": "5c292d4df156f8b008f29fa6b033834b906bf328" + "reference": "086687d7ae23dd1dae67b943161e8cef143539e1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cache/zipball/5c292d4df156f8b008f29fa6b033834b906bf328", - "reference": "5c292d4df156f8b008f29fa6b033834b906bf328", + "url": "https://api.github.com/repos/utopia-php/cache/zipball/086687d7ae23dd1dae67b943161e8cef143539e1", + "reference": "086687d7ae23dd1dae67b943161e8cef143539e1", "shasum": "" }, "require": { @@ -3386,9 +3417,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cache/issues", - "source": "https://github.com/utopia-php/cache/tree/3.4.0" + "source": "https://github.com/utopia-php/cache/tree/3.0.2" }, - "time": "2026-07-01T15:44:35+00:00" + "time": "2026-05-19T22:38:16+00:00" }, { "name": "utopia-php/circuit-breaker", @@ -3454,16 +3485,16 @@ }, { "name": "utopia-php/cli", - "version": "0.24.3", + "version": "0.24.1", "source": { "type": "git", "url": "https://github.com/utopia-php/cli.git", - "reference": "d6a27f2902e777c2985e834ffb3e662130fd7ecc" + "reference": "ba1eabbbfa56f0936de7455a26dcd1afc3246636" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cli/zipball/d6a27f2902e777c2985e834ffb3e662130fd7ecc", - "reference": "d6a27f2902e777c2985e834ffb3e662130fd7ecc", + "url": "https://api.github.com/repos/utopia-php/cli/zipball/ba1eabbbfa56f0936de7455a26dcd1afc3246636", + "reference": "ba1eabbbfa56f0936de7455a26dcd1afc3246636", "shasum": "" }, "require": { @@ -3495,79 +3526,22 @@ ], "support": { "issues": "https://github.com/utopia-php/cli/issues", - "source": "https://github.com/utopia-php/cli/tree/0.24.3" + "source": "https://github.com/utopia-php/cli/tree/0.24.1" }, - "time": "2026-06-26T10:48:18+00:00" - }, - { - "name": "utopia-php/client", - "version": "0.2.3", - "source": { - "type": "git", - "url": "https://github.com/utopia-php/client.git", - "reference": "377dc1f79441ac1584f25dba57904ee1cf0f626b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/utopia-php/client/zipball/377dc1f79441ac1584f25dba57904ee1cf0f626b", - "reference": "377dc1f79441ac1584f25dba57904ee1cf0f626b", - "shasum": "" - }, - "require": { - "php": ">=8.5", - "psr/http-client": "^1.0", - "psr/http-factory": "^1.0", - "psr/http-message": "^1.1 || ^2.0", - "utopia-php/pools": "^1.0", - "utopia-php/psr7": "^0.2", - "utopia-php/span": "^1.1 || ^3.0 || ^4.0" - }, - "require-dev": { - "swoole/ide-helper": "^6.0" - }, - "suggest": { - "ext-curl": "Required to use the cURL HTTP client adapter.", - "ext-simplexml": "Required to decode XML responses with Response::xml().", - "ext-swoole": "Required to use the Swoole coroutine HTTP client adapter." - }, - "type": "library", - "autoload": { - "psr-4": { - "Utopia\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "A lightweight PSR-18 HTTP client with cURL and Swoole coroutine backends", - "keywords": [ - "client", - "curl", - "http", - "php", - "psr-18", - "swoole", - "utopia" - ], - "support": { - "issues": "https://github.com/utopia-php/client/issues", - "source": "https://github.com/utopia-php/client/tree/0.2.3" - }, - "time": "2026-07-13T15:29:09+00:00" + "time": "2026-06-10T16:25:51+00:00" }, { "name": "utopia-php/compression", - "version": "0.1.7", + "version": "0.1.5", "source": { "type": "git", "url": "https://github.com/utopia-php/compression.git", - "reference": "655adbd2e42ba28f3148e0aaaf03a68dd6a1bd44" + "reference": "d39208e3f0f3ad0a793e8023046eb2e69b57bae3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/compression/zipball/655adbd2e42ba28f3148e0aaaf03a68dd6a1bd44", - "reference": "655adbd2e42ba28f3148e0aaaf03a68dd6a1bd44", + "url": "https://api.github.com/repos/utopia-php/compression/zipball/d39208e3f0f3ad0a793e8023046eb2e69b57bae3", + "reference": "d39208e3f0f3ad0a793e8023046eb2e69b57bae3", "shasum": "" }, "require": { @@ -3601,9 +3575,9 @@ ], "support": { "issues": "https://github.com/utopia-php/compression/issues", - "source": "https://github.com/utopia-php/compression/tree/0.1.7" + "source": "https://github.com/utopia-php/compression/tree/0.1.5" }, - "time": "2026-06-26T10:48:18+00:00" + "time": "2026-06-10T15:38:47+00:00" }, { "name": "utopia-php/config", @@ -3702,16 +3676,16 @@ }, { "name": "utopia-php/database", - "version": "6.4.3", + "version": "6.0.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "d5ebecc2f4518329e3e1c5ded3769638908c78ba" + "reference": "fff9f0effbd40359ff925741ff9424856d8b4fde" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/d5ebecc2f4518329e3e1c5ded3769638908c78ba", - "reference": "d5ebecc2f4518329e3e1c5ded3769638908c78ba", + "url": "https://api.github.com/repos/utopia-php/database/zipball/fff9f0effbd40359ff925741ff9424856d8b4fde", + "reference": "fff9f0effbd40359ff925741ff9424856d8b4fde", "shasum": "" }, "require": { @@ -3719,12 +3693,12 @@ "ext-mongodb": "*", "ext-pdo": "*", "ext-redis": "*", - "php": ">=8.5", - "utopia-php/cache": "^3.1.0", + "php": ">=8.4", + "utopia-php/cache": "^3.0", "utopia-php/console": "0.1.*", "utopia-php/mongo": "1.*", "utopia-php/pools": "1.*", - "utopia-php/validators": "0.3.*" + "utopia-php/validators": "0.2.*" }, "require-dev": { "fakerphp/faker": "1.23.*", @@ -3756,22 +3730,22 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/6.4.3" + "source": "https://github.com/utopia-php/database/tree/6.0.0" }, - "time": "2026-07-13T13:24:23+00:00" + "time": "2026-06-18T10:37:40+00:00" }, { "name": "utopia-php/detector", - "version": "0.2.6", + "version": "0.2.4", "source": { "type": "git", "url": "https://github.com/utopia-php/detector.git", - "reference": "2b2744be7ea028307dc9352eeec109cd1f9ab2d3" + "reference": "a564381108518ce6d18b6ab441f1448bd8355afd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/detector/zipball/2b2744be7ea028307dc9352eeec109cd1f9ab2d3", - "reference": "2b2744be7ea028307dc9352eeec109cd1f9ab2d3", + "url": "https://api.github.com/repos/utopia-php/detector/zipball/a564381108518ce6d18b6ab441f1448bd8355afd", + "reference": "a564381108518ce6d18b6ab441f1448bd8355afd", "shasum": "" }, "require": { @@ -3801,22 +3775,22 @@ ], "support": { "issues": "https://github.com/utopia-php/detector/issues", - "source": "https://github.com/utopia-php/detector/tree/0.2.6" + "source": "https://github.com/utopia-php/detector/tree/0.2.4" }, - "time": "2026-07-01T14:00:11+00:00" + "time": "2026-02-17T11:26:34+00:00" }, { "name": "utopia-php/di", - "version": "0.3.5", + "version": "0.3.3", "source": { "type": "git", "url": "https://github.com/utopia-php/di.git", - "reference": "053ebd097963190c5b279d66c5b530acb584d8c0" + "reference": "a0cee7ff9976bb6b596619aeac524948a8ee3dfb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/di/zipball/053ebd097963190c5b279d66c5b530acb584d8c0", - "reference": "053ebd097963190c5b279d66c5b530acb584d8c0", + "url": "https://api.github.com/repos/utopia-php/di/zipball/a0cee7ff9976bb6b596619aeac524948a8ee3dfb", + "reference": "a0cee7ff9976bb6b596619aeac524948a8ee3dfb", "shasum": "" }, "require": { @@ -3849,9 +3823,9 @@ ], "support": { "issues": "https://github.com/utopia-php/di/issues", - "source": "https://github.com/utopia-php/di/tree/0.3.5" + "source": "https://github.com/utopia-php/di/tree/0.3.3" }, - "time": "2026-06-26T10:48:18+00:00" + "time": "2026-06-10T14:22:41+00:00" }, { "name": "utopia-php/dns", @@ -3912,16 +3886,16 @@ }, { "name": "utopia-php/domains", - "version": "2.3.0", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/utopia-php/domains.git", - "reference": "73bb46ec7c7522c8a0a1e7311144bdea1a7480cd" + "reference": "77fcf4b63e33b2c1ddf8c67cfc1a57eef2dbec8f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/domains/zipball/73bb46ec7c7522c8a0a1e7311144bdea1a7480cd", - "reference": "73bb46ec7c7522c8a0a1e7311144bdea1a7480cd", + "url": "https://api.github.com/repos/utopia-php/domains/zipball/77fcf4b63e33b2c1ddf8c67cfc1a57eef2dbec8f", + "reference": "77fcf4b63e33b2c1ddf8c67cfc1a57eef2dbec8f", "shasum": "" }, "require": { @@ -3968,9 +3942,9 @@ ], "support": { "issues": "https://github.com/utopia-php/domains/issues", - "source": "https://github.com/utopia-php/domains/tree/2.3.0" + "source": "https://github.com/utopia-php/domains/tree/2.2.0" }, - "time": "2026-07-06T03:50:24+00:00" + "time": "2026-05-28T15:16:46+00:00" }, { "name": "utopia-php/dsn", @@ -4122,27 +4096,25 @@ }, { "name": "utopia-php/http", - "version": "2.0.0-rc18", + "version": "2.0.0-rc9", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "3bfc500c6a53ffb87d4dcb95b4712b6a91b24439" + "reference": "e4fdbc57ac6dc7cad1604eb904d3c95a31226ba9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/3bfc500c6a53ffb87d4dcb95b4712b6a91b24439", - "reference": "3bfc500c6a53ffb87d4dcb95b4712b6a91b24439", + "url": "https://api.github.com/repos/utopia-php/http/zipball/e4fdbc57ac6dc7cad1604eb904d3c95a31226ba9", + "reference": "e4fdbc57ac6dc7cad1604eb904d3c95a31226ba9", "shasum": "" }, "require": { - "php": ">=8.5", + "php": ">=8.3", "utopia-php/compression": "^0.1", "utopia-php/di": "^0.3", - "utopia-php/psr7": "^0.2.0", "utopia-php/servers": "^0.4", - "utopia-php/system": "^0.10", "utopia-php/telemetry": "^0.4", - "utopia-php/validators": "0.3.*" + "utopia-php/validators": "^0.2" }, "require-dev": { "swoole/ide-helper": "4.8.3" @@ -4169,22 +4141,22 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/2.0.0-rc18" + "source": "https://github.com/utopia-php/http/tree/2.0.0-rc9" }, - "time": "2026-07-13T16:18:22+00:00" + "time": "2026-06-10T16:25:51+00:00" }, { "name": "utopia-php/image", - "version": "0.8.7", + "version": "0.8.6", "source": { "type": "git", "url": "https://github.com/utopia-php/image.git", - "reference": "ed06c72998869f5d66026c7e4b7e1bcc1bbf45c7" + "reference": "85ab7027873e11bc901110d8f7830252247ba724" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/image/zipball/ed06c72998869f5d66026c7e4b7e1bcc1bbf45c7", - "reference": "ed06c72998869f5d66026c7e4b7e1bcc1bbf45c7", + "url": "https://api.github.com/repos/utopia-php/image/zipball/85ab7027873e11bc901110d8f7830252247ba724", + "reference": "85ab7027873e11bc901110d8f7830252247ba724", "shasum": "" }, "require": { @@ -4220,9 +4192,9 @@ ], "support": { "issues": "https://github.com/utopia-php/image/issues", - "source": "https://github.com/utopia-php/image/tree/0.8.7" + "source": "https://github.com/utopia-php/image/tree/0.8.6" }, - "time": "2026-07-13T12:12:06+00:00" + "time": "2026-04-19T12:52:59+00:00" }, { "name": "utopia-php/locale", @@ -4273,16 +4245,16 @@ }, { "name": "utopia-php/lock", - "version": "0.2.3", + "version": "0.2.1", "source": { "type": "git", "url": "https://github.com/utopia-php/lock.git", - "reference": "4eca3784d4c112655faf77adcf0fdbb186650487" + "reference": "9ef48d7094f5c68d1736f664f6e9b4b1ec656f21" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/lock/zipball/4eca3784d4c112655faf77adcf0fdbb186650487", - "reference": "4eca3784d4c112655faf77adcf0fdbb186650487", + "url": "https://api.github.com/repos/utopia-php/lock/zipball/9ef48d7094f5c68d1736f664f6e9b4b1ec656f21", + "reference": "9ef48d7094f5c68d1736f664f6e9b4b1ec656f21", "shasum": "" }, "require": { @@ -4315,9 +4287,9 @@ "description": "A simple lock library to coordinate access to shared resources across coroutines, processes and hosts", "support": { "issues": "https://github.com/utopia-php/lock/issues", - "source": "https://github.com/utopia-php/lock/tree/0.2.3" + "source": "https://github.com/utopia-php/lock/tree/0.2.1" }, - "time": "2026-06-26T10:48:18+00:00" + "time": "2026-06-10T15:55:36+00:00" }, { "name": "utopia-php/logger", @@ -4376,34 +4348,30 @@ }, { "name": "utopia-php/messaging", - "version": "2.0.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/utopia-php/messaging.git", - "reference": "8890c3b2e94bdf832c17fd3d7832cdf01b933eb7" + "reference": "3419ffbbeb242b3232b588430bd465024959720c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/messaging/zipball/8890c3b2e94bdf832c17fd3d7832cdf01b933eb7", - "reference": "8890c3b2e94bdf832c17fd3d7832cdf01b933eb7", + "url": "https://api.github.com/repos/utopia-php/messaging/zipball/3419ffbbeb242b3232b588430bd465024959720c", + "reference": "3419ffbbeb242b3232b588430bd465024959720c", "shasum": "" }, "require": { "ext-curl": "*", "ext-openssl": "*", - "ext-swoole": "*", - "php": ">=8.5.0", - "phpmailer/phpmailer": "^6.9", - "psr/http-client": "^1.0", - "psr/http-message": "^1.1 || ^2.0", - "utopia-php/client": "^0.2", + "giggsey/libphonenumber-for-php-lite": "9.0.23", + "php": ">=8.1.0", + "phpmailer/phpmailer": "6.9.1", "utopia-php/telemetry": "^0.4" }, "require-dev": { - "laravel/pint": "^1.0", - "phpstan/phpstan": "^2.0", - "phpunit/phpunit": "^11.0", - "swoole/ide-helper": "^6.0" + "laravel/pint": "1.*", + "phpstan/phpstan": "1.*", + "phpunit/phpunit": "11.*" }, "type": "library", "autoload": { @@ -4426,22 +4394,22 @@ ], "support": { "issues": "https://github.com/utopia-php/messaging/issues", - "source": "https://github.com/utopia-php/messaging/tree/2.0.0" + "source": "https://github.com/utopia-php/messaging/tree/1.2.0" }, - "time": "2026-07-14T10:22:03+00:00" + "time": "2026-06-23T04:24:43+00:00" }, { "name": "utopia-php/migration", - "version": "1.17.3", + "version": "dev-feat/drop-compound-resource-id", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "daf1008800633416a186c18069e3a5784de88d1c" + "reference": "a7e94c86a96fc7cdfff3eae9845270d91f83e7f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/daf1008800633416a186c18069e3a5784de88d1c", - "reference": "daf1008800633416a186c18069e3a5784de88d1c", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/a7e94c86a96fc7cdfff3eae9845270d91f83e7f8", + "reference": "a7e94c86a96fc7cdfff3eae9845270d91f83e7f8", "shasum": "" }, "require": { @@ -4467,7 +4435,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" ], @@ -4480,23 +4466,23 @@ "utopia" ], "support": { - "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.17.3" + "source": "https://github.com/utopia-php/migration/tree/feat/drop-compound-resource-id", + "issues": "https://github.com/utopia-php/migration/issues" }, - "time": "2026-07-14T14:04:00+00:00" + "time": "2026-07-17T12:11:07+00:00" }, { "name": "utopia-php/mongo", - "version": "1.3.1", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/utopia-php/mongo.git", - "reference": "f6ef5f1cecf80fb0378eda13250d6c14096d7620" + "reference": "73593682deee4696525a04e26524c1c1226e1530" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/mongo/zipball/f6ef5f1cecf80fb0378eda13250d6c14096d7620", - "reference": "f6ef5f1cecf80fb0378eda13250d6c14096d7620", + "url": "https://api.github.com/repos/utopia-php/mongo/zipball/73593682deee4696525a04e26524c1c1226e1530", + "reference": "73593682deee4696525a04e26524c1c1226e1530", "shasum": "" }, "require": { @@ -4542,31 +4528,31 @@ ], "support": { "issues": "https://github.com/utopia-php/mongo/issues", - "source": "https://github.com/utopia-php/mongo/tree/1.3.1" + "source": "https://github.com/utopia-php/mongo/tree/1.1.0" }, - "time": "2026-07-14T15:22:52+00:00" + "time": "2026-04-24T06:15:10+00:00" }, { "name": "utopia-php/platform", - "version": "1.0.0-rc14", + "version": "1.0.0-rc9", "source": { "type": "git", "url": "https://github.com/utopia-php/platform.git", - "reference": "bf3f1266de7da2e9ce00d923df054057c1b2fbb4" + "reference": "5ae1fba6d797ba617816a1a582d9c1b1d188a1bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/platform/zipball/bf3f1266de7da2e9ce00d923df054057c1b2fbb4", - "reference": "bf3f1266de7da2e9ce00d923df054057c1b2fbb4", + "url": "https://api.github.com/repos/utopia-php/platform/zipball/5ae1fba6d797ba617816a1a582d9c1b1d188a1bc", + "reference": "5ae1fba6d797ba617816a1a582d9c1b1d188a1bc", "shasum": "" }, "require": { "ext-json": "*", "ext-redis": "*", - "php": ">=8.5", + "php": ">=8.3", "utopia-php/cli": "^0.24", "utopia-php/http": "^2.0@RC", - "utopia-php/queue": "^0.22", + "utopia-php/queue": "^0.21", "utopia-php/servers": "^0.4" }, "type": "library", @@ -4589,22 +4575,22 @@ ], "support": { "issues": "https://github.com/utopia-php/platform/issues", - "source": "https://github.com/utopia-php/platform/tree/1.0.0-rc14" + "source": "https://github.com/utopia-php/platform/tree/1.0.0-rc9" }, - "time": "2026-07-13T15:07:08+00:00" + "time": "2026-06-11T10:36:26+00:00" }, { "name": "utopia-php/pools", - "version": "1.1.0", + "version": "1.0.5", "source": { "type": "git", "url": "https://github.com/utopia-php/pools.git", - "reference": "fd5aa7e89685ffc74f9dff3d23c270ef30c7bbf3" + "reference": "e66e498d59cf3ac48c1f4c70be46f7eb6df7a63b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/pools/zipball/fd5aa7e89685ffc74f9dff3d23c270ef30c7bbf3", - "reference": "fd5aa7e89685ffc74f9dff3d23c270ef30c7bbf3", + "url": "https://api.github.com/repos/utopia-php/pools/zipball/e66e498d59cf3ac48c1f4c70be46f7eb6df7a63b", + "reference": "e66e498d59cf3ac48c1f4c70be46f7eb6df7a63b", "shasum": "" }, "require": { @@ -4615,10 +4601,7 @@ "swoole/ide-helper": "6.*" }, "suggest": { - "ext-mongodb": "Needed to support MongoDB database pools", - "ext-pdo": "Needed to support MariaDB, MySQL or SQLite database pools", - "ext-redis": "Needed to support Redis cache pools", - "ext-swoole": "Needed to support Swoole based pool adapter" + "ext-swoole": "Required to use the Swoole pool adapter" }, "type": "library", "autoload": { @@ -4645,9 +4628,9 @@ ], "support": { "issues": "https://github.com/utopia-php/pools/issues", - "source": "https://github.com/utopia-php/pools/tree/1.1.0" + "source": "https://github.com/utopia-php/pools/tree/1.0.5" }, - "time": "2026-07-17T10:19:09+00:00" + "time": "2026-06-10T15:14:31+00:00" }, { "name": "utopia-php/preloader", @@ -4702,52 +4685,6 @@ }, "time": "2020-10-24T07:04:59+00:00" }, - { - "name": "utopia-php/psr7", - "version": "0.2.0", - "source": { - "type": "git", - "url": "https://github.com/utopia-php/psr7.git", - "reference": "115753c36194d53abe5587d383810724ac3a782d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/utopia-php/psr7/zipball/115753c36194d53abe5587d383810724ac3a782d", - "reference": "115753c36194d53abe5587d383810724ac3a782d", - "shasum": "" - }, - "require": { - "php": ">=8.4", - "psr/http-factory": "^1.0", - "psr/http-message": "^1.1 || ^2.0" - }, - "suggest": { - "ext-simplexml": "Required to decode XML responses with Response::xml()." - }, - "type": "library", - "autoload": { - "psr-4": { - "Utopia\\Psr7\\": "src/Psr7/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "PSR-7 HTTP message implementations and PSR-17 factories for Utopia", - "keywords": [ - "http", - "php", - "psr-17", - "psr-7", - "utopia" - ], - "support": { - "issues": "https://github.com/utopia-php/psr7/issues", - "source": "https://github.com/utopia-php/psr7/tree/0.2.0" - }, - "time": "2026-07-06T12:40:23+00:00" - }, { "name": "utopia-php/query", "version": "0.1.1", @@ -4796,26 +4733,26 @@ }, { "name": "utopia-php/queue", - "version": "0.22.2", + "version": "0.21.1", "source": { "type": "git", "url": "https://github.com/utopia-php/queue.git", - "reference": "3081a1cd464e9bc92443e91e08d653bfdf45b54d" + "reference": "abc5173ff7079118ebf5a22cb8008e8cf0a150e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/queue/zipball/3081a1cd464e9bc92443e91e08d653bfdf45b54d", - "reference": "3081a1cd464e9bc92443e91e08d653bfdf45b54d", + "url": "https://api.github.com/repos/utopia-php/queue/zipball/abc5173ff7079118ebf5a22cb8008e8cf0a150e4", + "reference": "abc5173ff7079118ebf5a22cb8008e8cf0a150e4", "shasum": "" }, "require": { - "php": ">=8.5", + "php": ">=8.4", "utopia-php/di": "^0.3", "utopia-php/lock": "^0.2", "utopia-php/pools": "^1.0", "utopia-php/servers": "^0.4", "utopia-php/telemetry": "^0.4", - "utopia-php/validators": "0.3.*" + "utopia-php/validators": "^0.2" }, "require-dev": { "ext-redis": "*", @@ -4853,9 +4790,9 @@ ], "support": { "issues": "https://github.com/utopia-php/queue/issues", - "source": "https://github.com/utopia-php/queue/tree/0.22.2" + "source": "https://github.com/utopia-php/queue/tree/0.21.1" }, - "time": "2026-07-13T11:15:40+00:00" + "time": "2026-06-10T16:25:51+00:00" }, { "name": "utopia-php/registry", @@ -4911,22 +4848,22 @@ }, { "name": "utopia-php/servers", - "version": "0.4.6", + "version": "0.4.3", "source": { "type": "git", "url": "https://github.com/utopia-php/servers.git", - "reference": "036c4da1c8b9a5bba1a973270158ba745a5944c9" + "reference": "a160268a804ae1a6d8a6ee41aed8dda1d2553da8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/036c4da1c8b9a5bba1a973270158ba745a5944c9", - "reference": "036c4da1c8b9a5bba1a973270158ba745a5944c9", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/a160268a804ae1a6d8a6ee41aed8dda1d2553da8", + "reference": "a160268a804ae1a6d8a6ee41aed8dda1d2553da8", "shasum": "" }, "require": { - "php": ">=8.5", + "php": ">=8.2", "utopia-php/di": "^0.3", - "utopia-php/validators": "0.3.*" + "utopia-php/validators": "^0.2" }, "type": "library", "autoload": { @@ -4954,28 +4891,32 @@ ], "support": { "issues": "https://github.com/utopia-php/servers/issues", - "source": "https://github.com/utopia-php/servers/tree/0.4.6" + "source": "https://github.com/utopia-php/servers/tree/0.4.3" }, - "time": "2026-07-13T11:15:40+00:00" + "time": "2026-06-10T16:25:51+00:00" }, { "name": "utopia-php/span", - "version": "3.0.2", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/utopia-php/span.git", - "reference": "6f9042c1ae1fa5a3e890b5c9a92cbf1388422945" + "reference": "97f0ab6e9125c000262f8b5b007423d11fd1a9b3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/span/zipball/6f9042c1ae1fa5a3e890b5c9a92cbf1388422945", - "reference": "6f9042c1ae1fa5a3e890b5c9a92cbf1388422945", + "url": "https://api.github.com/repos/utopia-php/span/zipball/97f0ab6e9125c000262f8b5b007423d11fd1a9b3", + "reference": "97f0ab6e9125c000262f8b5b007423d11fd1a9b3", "shasum": "" }, "require": { "php": ">=8.2" }, "require-dev": { + "laravel/pint": "^1.0", + "phpstan/phpstan": "^2.0", + "phpunit/phpunit": "^10.0", + "rector/rector": "^2.3", "swoole/ide-helper": "^5.0" }, "suggest": { @@ -4994,22 +4935,22 @@ "description": "Simple span tracing library for PHP with coroutine support", "support": { "issues": "https://github.com/utopia-php/span/issues", - "source": "https://github.com/utopia-php/span/tree/3.0.2" + "source": "https://github.com/utopia-php/span/tree/3.0.1" }, - "time": "2026-06-10T14:42:53+00:00" + "time": "2026-05-13T11:53:06+00:00" }, { "name": "utopia-php/storage", - "version": "2.0.6", + "version": "2.0.5", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "00503ebecdae5e4c694889acf7777b1b4ca5d3d6" + "reference": "b8af52e8ae1f9e670b32255a8936bbb46634b711" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/00503ebecdae5e4c694889acf7777b1b4ca5d3d6", - "reference": "00503ebecdae5e4c694889acf7777b1b4ca5d3d6", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/b8af52e8ae1f9e670b32255a8936bbb46634b711", + "reference": "b8af52e8ae1f9e670b32255a8936bbb46634b711", "shasum": "" }, "require": { @@ -5017,10 +4958,10 @@ "ext-fileinfo": "*", "ext-simplexml": "*", "ext-zlib": "*", - "php": ">=8.5", + "php": ">=8.1", "utopia-php/system": "0.*.*", "utopia-php/telemetry": "^0.4", - "utopia-php/validators": "0.3.*" + "utopia-php/validators": "0.2.*" }, "require-dev": { "laravel/pint": "^1.21", @@ -5046,27 +4987,32 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/2.0.6" + "source": "https://github.com/utopia-php/storage/tree/2.0.5" }, - "time": "2026-07-13T13:40:39+00:00" + "time": "2026-06-03T05:21:46+00:00" }, { "name": "utopia-php/system", - "version": "0.10.5", + "version": "0.10.2", "source": { "type": "git", "url": "https://github.com/utopia-php/system.git", - "reference": "57a2ab17f5346f171c796e29a6c2202bfaa21303" + "reference": "04229a822b147c1abaf1a92fb42c2d7aad4625df" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/system/zipball/57a2ab17f5346f171c796e29a6c2202bfaa21303", - "reference": "57a2ab17f5346f171c796e29a6c2202bfaa21303", + "url": "https://api.github.com/repos/utopia-php/system/zipball/04229a822b147c1abaf1a92fb42c2d7aad4625df", + "reference": "04229a822b147c1abaf1a92fb42c2d7aad4625df", "shasum": "" }, "require": { "php": ">=8.0.0" }, + "require-dev": { + "laravel/pint": "1.13.*", + "phpstan/phpstan": "1.12.*", + "phpunit/phpunit": "9.6.*" + }, "type": "library", "autoload": { "psr-4": { @@ -5097,25 +5043,26 @@ ], "support": { "issues": "https://github.com/utopia-php/system/issues", - "source": "https://github.com/utopia-php/system/tree/0.10.5" + "source": "https://github.com/utopia-php/system/tree/0.10.2" }, - "time": "2026-06-26T10:48:18+00:00" + "time": "2026-05-05T14:33:41+00:00" }, { "name": "utopia-php/telemetry", - "version": "0.4.5", + "version": "0.4.1", "source": { "type": "git", "url": "https://github.com/utopia-php/telemetry.git", - "reference": "139943bffcd4f6dd8fb9ed247f946a1d151b006a" + "reference": "028f3a85bb987b1e9357fb1632aa40f020d1b86e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/telemetry/zipball/139943bffcd4f6dd8fb9ed247f946a1d151b006a", - "reference": "139943bffcd4f6dd8fb9ed247f946a1d151b006a", + "url": "https://api.github.com/repos/utopia-php/telemetry/zipball/028f3a85bb987b1e9357fb1632aa40f020d1b86e", + "reference": "028f3a85bb987b1e9357fb1632aa40f020d1b86e", "shasum": "" }, "require": { + "ext-opentelemetry": "*", "ext-protobuf": "*", "nyholm/psr7": "1.*", "open-telemetry/exporter-otlp": "1.*", @@ -5124,6 +5071,7 @@ "symfony/http-client": "7.*" }, "require-dev": { + "phpbench/phpbench": "1.*", "swoole/ide-helper": "6.*" }, "suggest": { @@ -5148,26 +5096,26 @@ ], "support": { "issues": "https://github.com/utopia-php/telemetry/issues", - "source": "https://github.com/utopia-php/telemetry/tree/0.4.5" + "source": "https://github.com/utopia-php/telemetry/tree/0.4.1" }, - "time": "2026-07-08T11:07:25+00:00" + "time": "2026-06-10T15:48:26+00:00" }, { "name": "utopia-php/validators", - "version": "0.3.0", + "version": "0.2.6", "source": { "type": "git", "url": "https://github.com/utopia-php/validators.git", - "reference": "5a3ef67ce17c2e148da7895e8de699614f0afdfa" + "reference": "f1ac4f08d6876daf117a1d9af53a4c7b752c2c0b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/validators/zipball/5a3ef67ce17c2e148da7895e8de699614f0afdfa", - "reference": "5a3ef67ce17c2e148da7895e8de699614f0afdfa", + "url": "https://api.github.com/repos/utopia-php/validators/zipball/f1ac4f08d6876daf117a1d9af53a4c7b752c2c0b", + "reference": "f1ac4f08d6876daf117a1d9af53a4c7b752c2c0b", "shasum": "" }, "require": { - "php": ">=8.5" + "php": ">=8.0" }, "type": "library", "autoload": { @@ -5188,22 +5136,22 @@ ], "support": { "issues": "https://github.com/utopia-php/validators/issues", - "source": "https://github.com/utopia-php/validators/tree/0.3.0" + "source": "https://github.com/utopia-php/validators/tree/0.2.6" }, - "time": "2026-07-13T09:46:33+00:00" + "time": "2026-06-10T14:45:13+00:00" }, { "name": "utopia-php/vcs", - "version": "4.4.2", + "version": "4.2.3", "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "ea623171caeaad2ef600b6c6bd52fd5f76b38486" + "reference": "598cbd2793a5a6394493f1046743e75ec6544a57" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/vcs/zipball/ea623171caeaad2ef600b6c6bd52fd5f76b38486", - "reference": "ea623171caeaad2ef600b6c6bd52fd5f76b38486", + "url": "https://api.github.com/repos/utopia-php/vcs/zipball/598cbd2793a5a6394493f1046743e75ec6544a57", + "reference": "598cbd2793a5a6394493f1046743e75ec6544a57", "shasum": "" }, "require": { @@ -5237,9 +5185,9 @@ ], "support": { "issues": "https://github.com/utopia-php/vcs/issues", - "source": "https://github.com/utopia-php/vcs/tree/4.4.2" + "source": "https://github.com/utopia-php/vcs/tree/4.2.3" }, - "time": "2026-07-14T06:22:41+00:00" + "time": "2026-06-16T12:14:08+00:00" }, { "name": "utopia-php/websocket", @@ -5432,16 +5380,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "2.4.5", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "ebdb3af8bee5669879644c262e704d83dbeb438a" + "reference": "60a2e804c1464494d763e5ff6bfff9b188502253" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/ebdb3af8bee5669879644c262e704d83dbeb438a", - "reference": "ebdb3af8bee5669879644c262e704d83dbeb438a", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/60a2e804c1464494d763e5ff6bfff9b188502253", + "reference": "60a2e804c1464494d763e5ff6bfff9b188502253", "shasum": "" }, "require": { @@ -5456,7 +5404,7 @@ "brianium/paratest": "7.*", "phpunit/phpunit": "11.*", "rector/rector": "^2.4", - "squizlabs/php_codesniffer": "4.*" + "squizlabs/php_codesniffer": "3.*" }, "type": "library", "autoload": { @@ -5478,9 +5426,9 @@ "description": "SDK generator for Appwrite APIs across multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/2.4.5" + "source": "https://github.com/appwrite/sdk-generator/tree/2.0.0" }, - "time": "2026-07-09T15:23:08+00:00" + "time": "2026-06-11T05:54:24+00:00" }, { "name": "brianium/paratest", @@ -8424,16 +8372,24 @@ "time": "2026-05-30T17:09:26+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/migration", + "version": "dev-feat/drop-compound-resource-id", + "alias": "1.17.3", + "alias_normalized": "1.17.3.0" + } + ], "minimum-stability": "dev", "stability-flags": { "utopia-php/http": 5, + "utopia-php/migration": 20, "utopia-php/platform": 5 }, "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": ">=8.5.0", + "php": ">=8.3.0", "ext-curl": "*", "ext-imagick": "*", "ext-mbstring": "*", diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index 4aa05673c1..cf8eeb6ba9 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -3,12 +3,11 @@ namespace Appwrite\Migration\Version; use Appwrite\Migration\Migration; -use Exception; use Throwable; use Utopia\Console; use Utopia\Database\Database; use Utopia\Database\Document; -use Utopia\Database\Query; +use Utopia\Migration\Resource; class V25 extends Migration { @@ -19,92 +18,134 @@ class V25 extends Migration { Console::info('Migrating collections'); $this->migrateCollections(); + + Console::info('Migrating documents'); + $this->forEachDocument($this->migrateDocument(...)); } /** - * Migrate Collections. - * - * @return void - * @throws Exception|Throwable + * @throws Throwable */ private function migrateCollections(): void { - $projectInternalId = $this->project->getSequence(); - - if (empty($projectInternalId)) { - throw new Exception('Project ID is null'); + if ($this->project->getSequence() === 'console') { + return; } - $collectionType = match ($projectInternalId) { - 'console' => 'console', - default => 'projects', - }; + $id = 'migrations'; - $collections = $this->collections[$collectionType]; + $this->dbForProject->purgeCachedCollection($id); + $this->dbForProject->purgeCachedDocument(Database::METADATA, $id); - foreach ($collections as $collection) { - $id = $collection['$id']; + $attributes = [ + 'resourceInternalId', + 'parentResourceId', + 'parentResourceInternalId', + 'parentResourceType', + ]; + try { + $this->createAttributesFromCollection($this->dbForProject, $id, $attributes); + } catch (Throwable $th) { + Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}"); + } - if (empty($id)) { - continue; - } - - Console::log("Migrating collection \"{$id}\""); - - $this->dbForProject->purgeCachedCollection($id); - $this->dbForProject->purgeCachedDocument(Database::METADATA, $id); - - switch ($id) { - case 'projects': - if ($collectionType === 'console') { - try { - $this->createIndexFromCollection($this->dbForProject, $id, '_key_accessedAt'); - } catch (Throwable $th) { - Console::warning("Failed to create index \"_key_accessedAt\" from {$id}: {$th->getMessage()}"); - } - } - $this->dbForProject->purgeCachedCollection($id); - break; - - case 'installations': - if ($collectionType === 'console') { - foreach (['personalAccessToken', 'personalRefreshToken'] as $attribute) { - try { - $this->dbForProject->updateAttribute($id, $attribute, size: 2048); - } catch (Throwable $th) { - Console::warning("Failed to resize attribute \"{$attribute}\" in collection {$id}: {$th->getMessage()}"); - } - } - } - $this->dbForProject->purgeCachedCollection($id); - break; - - case 'databases': - if ($collectionType === 'projects') { - try { - $this->createAttributeFromCollection($this->dbForProject, $id, 'status'); - } catch (Throwable $th) { - Console::warning("Failed to create attribute \"status\" in collection {$id}: {$th->getMessage()}"); - } - $this->dbForProject->purgeCachedCollection($id); - - // Backfill existing databases so the stored value matches the intended default. - // Materialize the matched documents before updating any of them: updating - // "status" removes rows from the isNull() set, and the offset-based iterator - // would otherwise skip un-processed rows as the filtered set shrinks mid-scan. - $databases = \iterator_to_array($this->documentsIterator($id, [Query::isNull('status')])); - foreach ($databases as $database) { - try { - $this->dbForProject->updateDocument($id, $database->getId(), new Document([ - 'status' => 'ready', - ])); - } catch (Throwable $th) { - Console::warning("Failed to backfill \"status\" for database {$database->getId()}: {$th->getMessage()}"); - } - } - } - break; + $indexes = [ + '_key_resourceType', + '_key_resourceInternalId', + '_key_parentResourceId', + '_key_parentResourceType', + '_key_parentResourceInternalId', + ]; + foreach ($indexes as $index) { + try { + $this->createIndexFromCollection($this->dbForProject, $id, $index); + } catch (Throwable $th) { + Console::warning("Failed to create index \"{$index}\" from {$id}: {$th->getMessage()}"); } } + + $this->dbForProject->purgeCachedCollection($id); + } + + protected function migrateDocument(Document $document): Document + { + if ($document->getCollection() !== 'migrations') { + return $document; + } + + $resourceId = (string) $document->getAttribute('resourceId', ''); + $parentResourceId = (string) $document->getAttribute('parentResourceId', ''); + + if ($parentResourceId === '') { + if (!\str_contains($resourceId, ':')) { + return $document; + } + + [$parentResourceId, $resourceId] = \explode(':', $resourceId, 2); + if ($parentResourceId === '' || $resourceId === '') { + return $document; + } + + $parentResourceType = (string) $document->getAttribute('resourceType', ''); + $document + ->setAttribute('resourceId', $resourceId) + ->setAttribute('resourceType', Resource::TYPE_COLLECTION) + ->setAttribute('parentResourceId', $parentResourceId); + + if ($parentResourceType !== '') { + $document->setAttribute('parentResourceType', $parentResourceType); + } + } + + if ($resourceId === '') { + return $document; + } + + $internalIds = $this->resolveInternalIds($parentResourceId, $resourceId, $document->getId()); + if ( + $document->getAttribute('parentResourceInternalId', '') === '' + && isset($internalIds['parentResourceInternalId']) + ) { + $document->setAttribute('parentResourceInternalId', $internalIds['parentResourceInternalId']); + } + if ( + $document->getAttribute('resourceInternalId', '') === '' + && isset($internalIds['resourceInternalId']) + ) { + $document->setAttribute('resourceInternalId', $internalIds['resourceInternalId']); + } + + return $document; + } + + /** + * @return array{parentResourceInternalId?: string, resourceInternalId?: string} + */ + protected function resolveInternalIds(string $parentResourceId, string $resourceId, string $migrationId): array + { + try { + $database = $this->dbForProject->getDocument('databases', $parentResourceId); + if ($database->isEmpty() || $database->getSequence() === '') { + return []; + } + } catch (Throwable $th) { + Console::warning("Failed to resolve parent internal ID for migration {$migrationId}: {$th->getMessage()}"); + return []; + } + + $internalIds = [ + 'parentResourceInternalId' => (string) $database->getSequence(), + ]; + + try { + $resource = $this->dbForProject->getDocument('database_' . $database->getSequence(), $resourceId); + if (!$resource->isEmpty() && $resource->getSequence() !== '') { + $internalIds['resourceInternalId'] = (string) $resource->getSequence(); + } + } catch (Throwable $th) { + Console::warning("Failed to resolve resource internal ID for migration {$migrationId}: {$th->getMessage()}"); + } + + return $internalIds; } } diff --git a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Exports/Create.php b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Exports/Create.php index 0ab3cecf1a..bab990bee8 100644 --- a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Exports/Create.php +++ b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Exports/Create.php @@ -9,7 +9,6 @@ use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; -use Appwrite\Utopia\Database\Validator\CompoundUID; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; @@ -18,6 +17,7 @@ use Utopia\Database\Helpers\ID; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Queries\Documents; +use Utopia\Database\Validator\UID; use Utopia\Migration\Resource; use Utopia\Migration\Sources\Appwrite as AppwriteSource; use Utopia\Migration\Sources\CSV; @@ -60,7 +60,8 @@ class Create extends Action ) ] )) - ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database to export.') + ->param('databaseId', '', new UID(), 'Database ID containing the source collection.') + ->param('collectionId', '', new UID(), 'Collection ID to export documents from.') ->param('filename', '', new Text(255), 'The name of the file to be created for the export, excluding the .csv extension.') ->param('columns', [], new ArrayList(new Text(Database::LENGTH_KEY)), 'List of attributes to export. If empty, all attributes will be exported. You can use the `*` wildcard to export all attributes from the collection.', true) ->param('queries', [], new ArrayList(new Text(0)), 'Array of query strings generated using the Query class provided by the SDK to filter documents to export. [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.', true) @@ -82,7 +83,8 @@ class Create extends Action } public function action( - string $resourceId, + string $databaseId, + string $collectionId, string $filename, array $columns, array $queries, @@ -112,14 +114,6 @@ class Create extends Action throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - [$databaseId, $collectionId] = \explode(':', $resourceId, 2); - if (empty($databaseId)) { - throw new Exception(Exception::DATABASE_NOT_FOUND); - } - if (empty($collectionId)) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); - } - $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { throw new Exception(Exception::DATABASE_NOT_FOUND); @@ -150,7 +144,7 @@ class Create extends Action } $resources = Transfer::extractServices([self::transferGroupForDatabaseType($databaseType)]); - $resourceType = self::resourceTypeForDatabaseType($databaseType); + $parentResourceType = self::resourceTypeForDatabaseType($databaseType); $migration = $dbForProject->createDocument('migrations', new Document([ '$id' => ID::unique(), @@ -159,8 +153,12 @@ class Create extends Action 'source' => AppwriteSource::getName(), 'destination' => CSV::getName(), 'resources' => $resources, - 'resourceId' => $resourceId, - 'resourceType' => $resourceType, + 'resourceId' => $collection->getId(), + 'resourceInternalId' => $collection->getSequence(), + 'resourceType' => Resource::TYPE_COLLECTION, + 'parentResourceId' => $database->getId(), + 'parentResourceInternalId' => $database->getSequence(), + 'parentResourceType' => $parentResourceType, 'statusCounters' => '{}', 'resourceData' => '{}', 'errors' => [], 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 66c1b96ae5..bae41c756d 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 @@ -10,7 +10,6 @@ use Appwrite\OpenSSL\OpenSSL; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; -use Appwrite\Utopia\Database\Validator\CompoundUID; use Appwrite\Utopia\Response; use Utopia\Compression\Algorithms\GZIP; use Utopia\Compression\Algorithms\Zstd; @@ -68,7 +67,8 @@ class Create extends Action )) ->param('bucketId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).', false, ['dbForProject']) ->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('databaseId', '', new UID(), 'Database ID containing the target collection.') + ->param('collectionId', '', new UID(), 'Collection ID to import documents into.') ->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, enum: new Enum(name: 'OnDuplicate')) ->inject('response') @@ -87,7 +87,8 @@ class Create extends Action public function action( string $bucketId, string $fileId, - string $resourceId, + string $databaseId, + string $collectionId, bool $internalFile, string $onDuplicate, Response $response, @@ -163,15 +164,24 @@ class Create extends Action throw new \Exception('Unable to copy file'); } - [$databaseId] = \explode(':', $resourceId, 2); $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); + if ($database->isEmpty()) { + throw new Exception(Exception::DATABASE_NOT_FOUND); + } + $databaseType = $database->getAttribute('type'); if (!\in_array($databaseType, CSV_ALLOWED_DATABASE_TYPES)) { throw new Exception(Exception::MIGRATION_DATABASE_TYPE_UNSUPPORTED, 'Database type not supported for csv'); } + + $collection = $authorization->skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); + if ($collection->isEmpty()) { + throw new Exception(Exception::COLLECTION_NOT_FOUND); + } + $fileSize = $deviceForMigrations->getFileSize($newPath); $resources = Transfer::extractServices([self::transferGroupForDatabaseType($databaseType)]); - $resourceType = self::resourceTypeForDatabaseType($databaseType); + $parentResourceType = self::resourceTypeForDatabaseType($databaseType); $migration = $dbForProject->createDocument('migrations', new Document([ '$id' => $migrationId, @@ -180,8 +190,12 @@ class Create extends Action 'source' => CSV::getName(), 'destination' => AppwriteSource::getName(), 'resources' => $resources, - 'resourceId' => $resourceId, - 'resourceType' => $resourceType, + 'resourceId' => $collection->getId(), + 'resourceInternalId' => $collection->getSequence(), + 'resourceType' => Resource::TYPE_COLLECTION, + 'parentResourceId' => $database->getId(), + 'parentResourceInternalId' => $database->getSequence(), + 'parentResourceType' => $parentResourceType, 'statusCounters' => '{}', 'resourceData' => '{}', 'errors' => [], diff --git a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/JSON/Exports/Create.php b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/JSON/Exports/Create.php index d968bd91f6..2196128e5c 100644 --- a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/JSON/Exports/Create.php +++ b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/JSON/Exports/Create.php @@ -9,7 +9,6 @@ use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; -use Appwrite\Utopia\Database\Validator\CompoundUID; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; @@ -18,6 +17,7 @@ use Utopia\Database\Helpers\ID; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Queries\Documents; +use Utopia\Database\Validator\UID; use Utopia\Migration\Resource; use Utopia\Migration\Sources\Appwrite as AppwriteSource; use Utopia\Migration\Sources\JSON as JSONSource; @@ -60,7 +60,8 @@ class Create extends Action ) ] )) - ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database to export.') + ->param('databaseId', '', new UID(), 'Database ID containing the source collection.') + ->param('collectionId', '', new UID(), 'Collection ID to export documents from.') ->param('filename', '', new Text(255), 'The name of the file to be created for the export, excluding the .json extension.') ->param('columns', [], new ArrayList(new Text(Database::LENGTH_KEY)), 'List of attributes to export. If empty, all attributes will be exported. You can use the `*` wildcard to export all attributes from the collection.', true) ->param('queries', [], new ArrayList(new Text(0)), 'Array of query strings generated using the Query class provided by the SDK to filter documents to export. [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.', true) @@ -78,7 +79,8 @@ class Create extends Action } public function action( - string $resourceId, + string $databaseId, + string $collectionId, string $filename, array $columns, array $queries, @@ -104,14 +106,6 @@ class Create extends Action throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - [$databaseId, $collectionId] = \explode(':', $resourceId, 2); - if (empty($databaseId)) { - throw new Exception(Exception::DATABASE_NOT_FOUND); - } - if (empty($collectionId)) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); - } - $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { throw new Exception(Exception::DATABASE_NOT_FOUND); @@ -139,7 +133,7 @@ class Create extends Action } $resources = Transfer::extractServices([self::transferGroupForDatabaseType($databaseType)]); - $resourceType = self::resourceTypeForDatabaseType($databaseType); + $parentResourceType = self::resourceTypeForDatabaseType($databaseType); $migration = $dbForProject->createDocument('migrations', new Document([ '$id' => ID::unique(), @@ -148,8 +142,12 @@ class Create extends Action 'source' => AppwriteSource::getName(), 'destination' => JSONSource::getName(), 'resources' => $resources, - 'resourceId' => $resourceId, - 'resourceType' => $resourceType, + 'resourceId' => $collection->getId(), + 'resourceInternalId' => $collection->getSequence(), + 'resourceType' => Resource::TYPE_COLLECTION, + 'parentResourceId' => $database->getId(), + 'parentResourceInternalId' => $database->getSequence(), + 'parentResourceType' => $parentResourceType, 'statusCounters' => '{}', 'resourceData' => '{}', 'errors' => [], 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 c1f2e25c8e..365f8c213b 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 @@ -10,7 +10,6 @@ use Appwrite\OpenSSL\OpenSSL; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; -use Appwrite\Utopia\Database\Validator\CompoundUID; use Appwrite\Utopia\Response; use Utopia\Compression\Algorithms\GZIP; use Utopia\Compression\Algorithms\Zstd; @@ -67,7 +66,8 @@ class Create extends Action )) ->param('bucketId', '', new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).') ->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('databaseId', '', new UID(), 'Database ID containing the target collection.') + ->param('collectionId', '', new UID(), 'Collection ID to import documents into.') ->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, enum: new Enum(name: 'OnDuplicate')) ->inject('response') @@ -86,7 +86,8 @@ class Create extends Action public function action( string $bucketId, string $fileId, - string $resourceId, + string $databaseId, + string $collectionId, bool $internalFile, string $onDuplicate, Response $response, @@ -164,14 +165,19 @@ class Create extends Action $fileSize = $deviceForMigrations->getFileSize($newPath); - [$databaseId] = \explode(':', $resourceId, 2); $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { throw new Exception(Exception::DATABASE_NOT_FOUND); } + + $collection = $authorization->skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); + if ($collection->isEmpty()) { + throw new Exception(Exception::COLLECTION_NOT_FOUND); + } + $databaseType = $database->getAttribute('type'); $resources = Transfer::extractServices([self::transferGroupForDatabaseType($databaseType)]); - $resourceType = self::resourceTypeForDatabaseType($databaseType); + $parentResourceType = self::resourceTypeForDatabaseType($databaseType); $migration = $dbForProject->createDocument('migrations', new Document([ '$id' => $migrationId, @@ -180,8 +186,12 @@ class Create extends Action 'source' => JSONSource::getName(), 'destination' => AppwriteSource::getName(), 'resources' => $resources, - 'resourceId' => $resourceId, - 'resourceType' => $resourceType, + 'resourceId' => $collection->getId(), + 'resourceInternalId' => $collection->getSequence(), + 'resourceType' => Resource::TYPE_COLLECTION, + 'parentResourceId' => $database->getId(), + 'parentResourceInternalId' => $database->getSequence(), + 'parentResourceType' => $parentResourceType, 'statusCounters' => '{}', 'resourceData' => '{}', 'errors' => [], diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 1184bfb40b..31d57198e4 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -192,7 +192,7 @@ class Migrations extends Action { $source = $migration->getAttribute('source'); $destination = $migration->getAttribute('destination'); - $resourceId = $migration->getAttribute('resourceId'); + [$databaseId, $tableId] = $this->resolveResourceIds($migration); $credentials = $migration->getAttribute('credentials'); $migrationOptions = $migration->getAttribute('options'); /** @var Database|null $projectDB */ @@ -291,14 +291,16 @@ class Migrations extends Action $queries ), CSV::getName() => new CSV( - $resourceId, + $databaseId, + $tableId, $migrationOptions['path'], $this->deviceForMigrations, $this->dbForProject, $getDatabasesDB ), JSON::getName() => new JSON( - $resourceId, + $databaseId, + $tableId, $migrationOptions['path'], $this->deviceForMigrations, $this->dbForProject, @@ -320,6 +322,7 @@ class Migrations extends Action $destination = $migration->getAttribute('destination'); $options = $migration->getAttribute('options', []); $credentials = $migration->getAttribute('credentials'); + [$databaseId, $tableId] = $this->resolveResourceIds($migration); return match ($destination) { DestinationAppwrite::getName() => new DestinationAppwrite( @@ -336,7 +339,8 @@ class Migrations extends Action ), DestinationCSV::getName() => new DestinationCSV( $this->deviceForFiles, - $migration->getAttribute('resourceId'), + $databaseId, + $tableId, $options['bucketId'], $migration->getId(), $options['columns'], @@ -347,7 +351,8 @@ class Migrations extends Action ), DestinationJSON::getName() => new DestinationJSON( $this->deviceForFiles, - $migration->getAttribute('resourceId'), + $databaseId, + $tableId, $options['bucketId'] ?? 'default', $migration->getId(), $options['columns'] ?? [], @@ -573,8 +578,9 @@ class Migrations extends Action } $this->updateMigrationDocument($migration, $project, $queueForRealtime); }, - $migration->getAttribute('resourceId'), - $migration->getAttribute('resourceType') + $this->resolveResourceIds($migration)[0], + $migration->getAttribute('parentResourceType') ?: $migration->getAttribute('resourceType'), + $this->resolveResourceIds($migration)[1], ); $destination->shutdown(); @@ -692,7 +698,7 @@ class Migrations extends Action $publisherForUsage, $migration->getAttribute('source'), $authorization, - $migration->getAttribute('resourceId') + ...$this->resolveResourceIds($migration), ); } $destination?->success(); @@ -718,6 +724,40 @@ class Migrations extends Action return ($this->getDatabasesDB)($database); } + /** + * Resolve [rootResourceId, rootResourceChildId] from a migration document. + * + * Returns the root resource ID (e.g. databaseId for CSV/JSON or backup + * migrations) and an optional child filter under that root (the + * collection/table ID for CSV/JSON migrations). Three input shapes: + * + * - 1.9.4 CSV/JSON migration: parentResourceId is set to the root, + * resourceId is the leaf. Returns [parent, leaf]. + * - Pre-1.9.4 CSV/JSON migration (V25 not yet run, queue drain after + * upgrade, restored backup): resourceId is the composite + * "{databaseId}:{tableId}", parentResourceId is empty. Split it. + * - Single-root migration (Backup, full Appwrite/Supabase/Firebase/ + * NHost imports): resourceId is the root resource ID with no leaf. + * Returns [root, '']. + * + * @return array{0: string, 1: string} + */ + protected function resolveResourceIds(Document $migration): array + { + $parent = (string) $migration->getAttribute('parentResourceId', ''); + $resource = (string) $migration->getAttribute('resourceId', ''); + + if ($parent !== '') { + return [$parent, $resource]; + } + + if (\str_contains($resource, ':')) { + return \explode(':', $resource, 2); + } + + return [$resource, '']; + } + /** * Handle actions to be performed when a CSV export migration is successfully completed * @@ -1074,7 +1114,7 @@ class Migrations extends Action return $errors; } - private function processMigrationResourceStats(array $resources, Context $usage, Document $projectDocument, UsagePublisher $publisherForUsage, string $source, Authorization $authorization, ?string $resourceId) + private function processMigrationResourceStats(array $resources, Context $usage, Document $projectDocument, UsagePublisher $publisherForUsage, string $source, Authorization $authorization, ?string $parentResourceId, ?string $resourceId) { $resourceName = $resources['name']; $count = $resources['count']; @@ -1082,9 +1122,20 @@ class Migrations extends Action $tableInternalId = $resources['tableId']; if ($source === CSV::getName()) { - [$databaseId, $tableId] = explode(':', $resourceId); - $database = $authorization->skip(fn () => $this->dbForProject->getDocument('databases', $databaseId)); - $table = $authorization->skip(fn () => $this->dbForProject->getDocument('database_' . $database->getSequence(), $tableId)); + if (empty($parentResourceId) || empty($resourceId)) { + Console::warning("Skipping CSV migration usage stats: missing parent/leaf resource ID (parent: '{$parentResourceId}', leaf: '{$resourceId}')"); + return; + } + $database = $authorization->skip(fn () => $this->dbForProject->getDocument('databases', $parentResourceId)); + if ($database->isEmpty()) { + Console::warning("Skipping CSV migration usage stats: database '{$parentResourceId}' not found"); + return; + } + $table = $authorization->skip(fn () => $this->dbForProject->getDocument('database_' . $database->getSequence(), $resourceId)); + if ($table->isEmpty()) { + Console::warning("Skipping CSV migration usage stats: collection '{$resourceId}' not found in database '{$parentResourceId}'"); + return; + } $databaseInternalId = (int) $database->getSequence(); $tableInternalId = (int) $table->getSequence(); } diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Migrations.php b/src/Appwrite/Utopia/Database/Validator/Queries/Migrations.php index c49788872e..c1c2cea344 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Migrations.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Migrations.php @@ -12,9 +12,11 @@ class Migrations extends Base 'resources', 'resourceId', 'resourceType', + 'parentResourceId', + 'parentResourceType', 'statusCounters', 'resourceData', - 'errors' + 'errors', ]; /** diff --git a/src/Appwrite/Utopia/Request/Filters/V27.php b/src/Appwrite/Utopia/Request/Filters/V27.php new file mode 100644 index 0000000000..58baf8a1a5 --- /dev/null +++ b/src/Appwrite/Utopia/Request/Filters/V27.php @@ -0,0 +1,38 @@ + $this->parseMigrationResource($content), + default => $content, + }; + } + + protected function parseMigrationResource(array $content): array + { + if (!isset($content['resourceId']) || !\is_string($content['resourceId'])) { + return $content; + } + + if (!\str_contains($content['resourceId'], ':')) { + return $content; + } + + [$databaseId, $collectionId] = \explode(':', $content['resourceId'], 2); + $content['databaseId'] = $content['databaseId'] ?? $databaseId; + $content['collectionId'] = $content['collectionId'] ?? $collectionId; + unset($content['resourceId']); + + return $content; + } +} diff --git a/src/Appwrite/Utopia/Response/Filters/V27.php b/src/Appwrite/Utopia/Response/Filters/V27.php new file mode 100644 index 0000000000..1cf518f14d --- /dev/null +++ b/src/Appwrite/Utopia/Response/Filters/V27.php @@ -0,0 +1,41 @@ + $this->parseMigration($content), + Response::MODEL_MIGRATION_LIST => $this->handleList($content, 'migrations', fn ($item) => $this->parseMigration($item)), + default => $content, + }; + } + + protected function parseMigration(array $content): array + { + $parentResourceId = $content['parentResourceId'] ?? ''; + $resourceId = $content['resourceId'] ?? ''; + + if ($parentResourceId !== '' && $resourceId !== '') { + $content['resourceId'] = $parentResourceId . ':' . $resourceId; + } + + $parentResourceType = $content['parentResourceType'] ?? ''; + if ($parentResourceType !== '') { + $content['resourceType'] = $parentResourceType; + } + + unset($content['resourceInternalId']); + unset($content['parentResourceId']); + unset($content['parentResourceInternalId']); + unset($content['parentResourceType']); + + return $content; + } +} diff --git a/src/Appwrite/Utopia/Response/Model/Migration.php b/src/Appwrite/Utopia/Response/Model/Migration.php index df8b2d79ec..0fbf7362b7 100644 --- a/src/Appwrite/Utopia/Response/Model/Migration.php +++ b/src/Appwrite/Utopia/Response/Model/Migration.php @@ -62,9 +62,44 @@ class Migration extends Model ]) ->addRule('resourceId', [ 'type' => self::TYPE_STRING, - 'description' => 'Id of the resource to migrate.', + 'description' => 'ID of the resource being migrated.', 'default' => '', - 'example' => 'databaseId:collectionId', + 'example' => 'collectionId', + 'array' => false + ]) + ->addRule('resourceInternalId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Internal ID of the resource being migrated.', + 'default' => '', + 'example' => '1', + 'array' => false + ]) + ->addRule('resourceType', [ + 'type' => self::TYPE_STRING, + 'description' => 'Type of the resource being migrated.', + 'default' => '', + 'example' => 'collection', + 'array' => false + ]) + ->addRule('parentResourceId', [ + 'type' => self::TYPE_STRING, + 'description' => 'ID of the parent resource that contains the migrated resource.', + 'default' => '', + 'example' => 'databaseId', + 'array' => false + ]) + ->addRule('parentResourceInternalId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Internal ID of the parent resource that contains the migrated resource.', + 'default' => '', + 'example' => '1', + 'array' => false + ]) + ->addRule('parentResourceType', [ + 'type' => self::TYPE_STRING, + 'description' => 'Type of the parent resource that contains the migrated resource.', + 'default' => '', + 'example' => 'database', 'array' => false ]) ->addRule('statusCounters', [ diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 3e5a06ad26..1f131cb07b 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -3641,7 +3641,8 @@ trait MigrationsBase [ 'fileId' => $fileIds['missing-column'], 'bucketId' => $bucketIds['missing-column'], - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ] ); @@ -3673,7 +3674,8 @@ trait MigrationsBase [ 'fileId' => $fileIds['missing-row'], 'bucketId' => $bucketIds['missing-row'], - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ] ); @@ -3705,7 +3707,8 @@ trait MigrationsBase [ 'fileId' => $fileIds['irrelevant-column'], 'bucketId' => $bucketIds['irrelevant-column'], - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ] ); @@ -3732,7 +3735,8 @@ trait MigrationsBase 'endpoint' => $this->webEndpoint, 'fileId' => $fileIds['default'], 'bucketId' => $bucketIds['default'], - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ] ); @@ -3774,7 +3778,8 @@ trait MigrationsBase 'endpoint' => $this->webEndpoint, 'fileId' => $fileIds['documents-internals'], 'bucketId' => $bucketIds['documents-internals'], - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ] ); @@ -3888,7 +3893,8 @@ trait MigrationsBase $first = $this->performCsvMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ]); $this->assertEventually(function () use ($first) { $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $first['body']['$id'], array_merge([ @@ -3914,7 +3920,8 @@ trait MigrationsBase $second = $this->performCsvMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, 'onDuplicate' => 'skip', ]); $this->assertEventually(function () use ($second) { @@ -3955,7 +3962,8 @@ trait MigrationsBase $first = $this->performCsvMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ]); $this->assertEventually(function () use ($first) { $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $first['body']['$id'], array_merge([ @@ -3981,7 +3989,8 @@ trait MigrationsBase $second = $this->performCsvMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, 'onDuplicate' => 'overwrite', ]); $this->assertEventually(function () use ($second) { @@ -4023,7 +4032,8 @@ trait MigrationsBase $first = $this->performCsvMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ]); $this->assertEventually(function () use ($first) { $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $first['body']['$id'], array_merge([ @@ -4037,7 +4047,8 @@ trait MigrationsBase $second = $this->performCsvMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ]); $this->assertEventually(function () use ($second) { $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $second['body']['$id'], array_merge([ @@ -4148,7 +4159,8 @@ trait MigrationsBase $first = $this->performJsonMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ]); $this->assertEventually(function () use ($first) { $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $first['body']['$id'], array_merge([ @@ -4173,7 +4185,8 @@ trait MigrationsBase $second = $this->performJsonMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, 'onDuplicate' => 'skip', ]); $this->assertEventually(function () use ($second) { @@ -4211,7 +4224,8 @@ trait MigrationsBase $first = $this->performJsonMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ]); $this->assertEventually(function () use ($first) { $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $first['body']['$id'], array_merge([ @@ -4235,7 +4249,8 @@ trait MigrationsBase $second = $this->performJsonMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, 'onDuplicate' => 'overwrite', ]); $this->assertEventually(function () use ($second) { @@ -4273,7 +4288,8 @@ trait MigrationsBase $first = $this->performJsonMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ]); $this->assertEventually(function () use ($first) { $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $first['body']['$id'], array_merge([ @@ -4286,7 +4302,8 @@ trait MigrationsBase $second = $this->performJsonMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ]); $this->assertEventually(function () use ($second) { $migration = $this->client->call(Client::METHOD_GET, '/migrations/' . $second['body']['$id'], array_merge([ @@ -4465,7 +4482,8 @@ trait MigrationsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'] ], $this->getHeaders()), [ - 'resourceId' => $databaseId . ':' . $collectionId, + 'databaseId' => $databaseId, + 'collectionId' => $collectionId, 'filename' => 'test-export', 'columns' => [], 'delimiter' => ',', @@ -5445,7 +5463,8 @@ trait MigrationsBase $migration = $this->performCsvMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $collectionId, + 'databaseId' => $databaseId, + 'collectionId' => $collectionId, ]); $this->assertEquals(202, $migration['headers']['status-code']); @@ -5573,7 +5592,8 @@ trait MigrationsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'resourceId' => $databaseId . ':' . $collectionId, + 'databaseId' => $databaseId, + 'collectionId' => $collectionId, 'filename' => $filename, 'columns' => [], 'queries' => [], @@ -6787,7 +6807,8 @@ trait MigrationsBase [ 'fileId' => $fileIds['missing-column'], 'bucketId' => $bucketIds['missing-column'], - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ] ); @@ -6824,7 +6845,8 @@ trait MigrationsBase [ 'fileId' => $fileIds['irrelevant-column'], 'bucketId' => $bucketIds['irrelevant-column'], - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ] ); @@ -6851,7 +6873,8 @@ trait MigrationsBase 'endpoint' => $this->endpoint, 'fileId' => $fileIds['default'], 'bucketId' => $bucketIds['default'], - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ] ); @@ -6893,7 +6916,8 @@ trait MigrationsBase 'endpoint' => $this->endpoint, 'fileId' => $fileIds['documents-internals'], 'bucketId' => $bucketIds['documents-internals'], - 'resourceId' => $databaseId . ':' . $tableId, + 'databaseId' => $databaseId, + 'collectionId' => $tableId, ] ); @@ -7016,7 +7040,8 @@ trait MigrationsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'] ], $this->getHeaders()), [ - 'resourceId' => $databaseId . ':' . $collectionId, + 'databaseId' => $databaseId, + 'collectionId' => $collectionId, 'filename' => 'test-json-export', 'columns' => [], 'queries' => [], @@ -7127,7 +7152,8 @@ trait MigrationsBase // Trigger JSON export $migration = $this->client->call(Client::METHOD_POST, '/migrations/json/exports', $headers, [ - 'resourceId' => $databaseId . ':' . $collectionId, + 'databaseId' => $databaseId, + 'collectionId' => $collectionId, 'filename' => 'vectorsdb-export-test', 'columns' => [], 'queries' => [], @@ -7200,7 +7226,8 @@ trait MigrationsBase $migration = $this->performJsonMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $collectionId, + 'databaseId' => $databaseId, + 'collectionId' => $collectionId, ]); $this->assertEquals(202, $migration['headers']['status-code']); @@ -7271,7 +7298,8 @@ trait MigrationsBase // Trigger JSON export $migration = $this->client->call(Client::METHOD_POST, '/migrations/json/exports', $headers, [ - 'resourceId' => $databaseId . ':' . $collectionId, + 'databaseId' => $databaseId, + 'collectionId' => $collectionId, 'filename' => 'documentsdb-export-test', 'columns' => [], 'queries' => [], @@ -7343,7 +7371,8 @@ trait MigrationsBase $migration = $this->performJsonMigration([ 'fileId' => $fileId, 'bucketId' => $bucketId, - 'resourceId' => $databaseId . ':' . $collectionId, + 'databaseId' => $databaseId, + 'collectionId' => $collectionId, ]); $this->assertEquals(202, $migration['headers']['status-code']); diff --git a/tests/unit/Migration/Version/V25Test.php b/tests/unit/Migration/Version/V25Test.php new file mode 100644 index 0000000000..aee039880b --- /dev/null +++ b/tests/unit/Migration/Version/V25Test.php @@ -0,0 +1,103 @@ +migrateDocument($document); + } + + #[\Override] + protected function resolveInternalIds(string $parentResourceId, string $resourceId, string $migrationId): array + { + return []; + } + }; + $document = new Document([ + '$id' => 'migration', + '$collection' => 'migrations', + 'resourceId' => 'database:collection', + 'resourceType' => Resource::TYPE_DATABASE, + ]); + + $result = $migration->migrate($document); + + $this->assertSame('collection', $result->getAttribute('resourceId')); + $this->assertSame(Resource::TYPE_COLLECTION, $result->getAttribute('resourceType')); + $this->assertSame('database', $result->getAttribute('parentResourceId')); + $this->assertSame(Resource::TYPE_DATABASE, $result->getAttribute('parentResourceType')); + $this->assertNull($result->getAttribute('resourceInternalId')); + $this->assertNull($result->getAttribute('parentResourceInternalId')); + } + + public function testRerunResolvesMissingInternalIdsIdempotently(): void + { + $migration = new class () extends V25 { + /** + * @var array{parentResourceInternalId?: string, resourceInternalId?: string} + */ + private array $internalIds = []; + + public function __construct() + { + } + + public function migrate(Document $document): Document + { + return $this->migrateDocument($document); + } + + /** + * @param array{parentResourceInternalId?: string, resourceInternalId?: string} $internalIds + */ + public function setInternalIds(array $internalIds): void + { + $this->internalIds = $internalIds; + } + + /** + * @return array{parentResourceInternalId?: string, resourceInternalId?: string} + */ + #[\Override] + protected function resolveInternalIds(string $parentResourceId, string $resourceId, string $migrationId): array + { + return $this->internalIds; + } + }; + $document = new Document([ + '$id' => 'migration', + '$collection' => 'migrations', + 'resourceId' => 'database:collection', + 'resourceType' => Resource::TYPE_DATABASE, + ]); + + $migration->migrate($document); + $migration->setInternalIds([ + 'parentResourceInternalId' => '10', + 'resourceInternalId' => '20', + ]); + $migration->migrate($document); + $afterResolution = $document->getArrayCopy(); + $migration->migrate($document); + + $this->assertSame('10', $document->getAttribute('parentResourceInternalId')); + $this->assertSame('20', $document->getAttribute('resourceInternalId')); + $this->assertSame($afterResolution, $document->getArrayCopy()); + } +} diff --git a/tests/unit/Utopia/Request/Filters/V27Test.php b/tests/unit/Utopia/Request/Filters/V27Test.php new file mode 100644 index 0000000000..37686f8e97 --- /dev/null +++ b/tests/unit/Utopia/Request/Filters/V27Test.php @@ -0,0 +1,49 @@ +parse([ + 'resourceId' => 'database:collection', + ], 'migrations.createCSVImport'); + + $this->assertSame([ + 'databaseId' => 'database', + 'collectionId' => 'collection', + ], $result); + } + + public function testExplicitResourceIdsTakePrecedence(): void + { + $filter = new V27(); + + $result = $filter->parse([ + 'resourceId' => 'legacyDatabase:legacyCollection', + 'databaseId' => 'database', + 'collectionId' => 'collection', + ], 'migrations.createJSONExport'); + + $this->assertSame([ + 'databaseId' => 'database', + 'collectionId' => 'collection', + ], $result); + } + + public function testLeavesMalformedResourceForValidation(): void + { + $filter = new V27(); + $content = ['resourceId' => 'database']; + + $this->assertSame($content, $filter->parse($content, 'migrations.createCSVExport')); + } +} diff --git a/tests/unit/Utopia/Response/Filters/V27Test.php b/tests/unit/Utopia/Response/Filters/V27Test.php new file mode 100644 index 0000000000..ca18768a90 --- /dev/null +++ b/tests/unit/Utopia/Response/Filters/V27Test.php @@ -0,0 +1,79 @@ +parse([ + '$id' => 'migration', + 'resourceId' => 'collection', + 'resourceInternalId' => '20', + 'resourceType' => 'collection', + 'parentResourceId' => 'database', + 'parentResourceInternalId' => '10', + 'parentResourceType' => 'database', + ], Response::MODEL_MIGRATION); + + $this->assertSame([ + '$id' => 'migration', + 'resourceId' => 'database:collection', + 'resourceType' => 'database', + ], $result); + } + + public function testPreservesSingleRootMigration(): void + { + $filter = new V27(); + + $result = $filter->parse([ + '$id' => 'migration', + 'resourceId' => 'database', + 'resourceInternalId' => '10', + 'resourceType' => 'database', + 'parentResourceId' => '', + 'parentResourceInternalId' => '', + 'parentResourceType' => '', + ], Response::MODEL_MIGRATION); + + $this->assertSame([ + '$id' => 'migration', + 'resourceId' => 'database', + 'resourceType' => 'database', + ], $result); + } + + public function testTransformsMigrationList(): void + { + $filter = new V27(); + + $result = $filter->parse([ + 'total' => 1, + 'migrations' => [[ + '$id' => 'migration', + 'resourceId' => 'collection', + 'resourceType' => 'collection', + 'parentResourceId' => 'database', + 'parentResourceType' => 'database', + ]], + ], Response::MODEL_MIGRATION_LIST); + + $this->assertSame([ + 'total' => 1, + 'migrations' => [[ + '$id' => 'migration', + 'resourceId' => 'database:collection', + 'resourceType' => 'database', + ]], + ], $result); + } +} From a15da42790286252b51405135ef2b8b83ea7d99f Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 17 Jul 2026 23:34:27 +1200 Subject: [PATCH 02/14] feat(migrations): expose destination resource links --- app/config/collections/projects.php | 36 +++++++++ src/Appwrite/Migration/Version/V25.php | 4 + .../Http/Migrations/CSV/Imports/Create.php | 2 + .../Http/Migrations/JSON/Imports/Create.php | 2 + .../Database/Validator/Queries/Migrations.php | 2 + src/Appwrite/Utopia/Response/Filters/V27.php | 2 + .../Utopia/Response/Model/Migration.php | 14 ++++ .../Services/Migrations/MigrationsBase.php | 74 ++++++++++++++++++- .../unit/Utopia/Response/Filters/V27Test.php | 6 ++ 9 files changed, 141 insertions(+), 1 deletion(-) diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index c4aa686b72..052103c9ac 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -2322,6 +2322,28 @@ return [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('destinationResourceId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => ID::custom('destinationResourceType'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], ], 'indexes' => [ [ @@ -2387,6 +2409,20 @@ return [ 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], + [ + '$id' => '_key_destinationResourceId', + 'type' => Database::INDEX_KEY, + 'attributes' => ['destinationResourceId'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], + [ + '$id' => '_key_destinationResourceType', + 'type' => Database::INDEX_KEY, + 'attributes' => ['destinationResourceType'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], [ '$id' => ID::custom('_fulltext_search'), 'type' => Database::INDEX_FULLTEXT, diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index cf8eeb6ba9..7d57715128 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -42,6 +42,8 @@ class V25 extends Migration 'parentResourceId', 'parentResourceInternalId', 'parentResourceType', + 'destinationResourceId', + 'destinationResourceType', ]; try { $this->createAttributesFromCollection($this->dbForProject, $id, $attributes); @@ -55,6 +57,8 @@ class V25 extends Migration '_key_parentResourceId', '_key_parentResourceType', '_key_parentResourceInternalId', + '_key_destinationResourceId', + '_key_destinationResourceType', ]; foreach ($indexes as $index) { try { 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 bae41c756d..7dddb7b575 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 @@ -196,6 +196,8 @@ class Create extends Action 'parentResourceId' => $database->getId(), 'parentResourceInternalId' => $database->getSequence(), 'parentResourceType' => $parentResourceType, + 'destinationResourceId' => $database->getId(), + 'destinationResourceType' => $parentResourceType, 'statusCounters' => '{}', 'resourceData' => '{}', 'errors' => [], 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 365f8c213b..06101e8565 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 @@ -192,6 +192,8 @@ class Create extends Action 'parentResourceId' => $database->getId(), 'parentResourceInternalId' => $database->getSequence(), 'parentResourceType' => $parentResourceType, + 'destinationResourceId' => $database->getId(), + 'destinationResourceType' => $parentResourceType, 'statusCounters' => '{}', 'resourceData' => '{}', 'errors' => [], diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Migrations.php b/src/Appwrite/Utopia/Database/Validator/Queries/Migrations.php index c1c2cea344..a146c39d10 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Migrations.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Migrations.php @@ -14,6 +14,8 @@ class Migrations extends Base 'resourceType', 'parentResourceId', 'parentResourceType', + 'destinationResourceId', + 'destinationResourceType', 'statusCounters', 'resourceData', 'errors', diff --git a/src/Appwrite/Utopia/Response/Filters/V27.php b/src/Appwrite/Utopia/Response/Filters/V27.php index 1cf518f14d..57bad7171e 100644 --- a/src/Appwrite/Utopia/Response/Filters/V27.php +++ b/src/Appwrite/Utopia/Response/Filters/V27.php @@ -35,6 +35,8 @@ class V27 extends Filter unset($content['parentResourceId']); unset($content['parentResourceInternalId']); unset($content['parentResourceType']); + unset($content['destinationResourceId']); + unset($content['destinationResourceType']); return $content; } diff --git a/src/Appwrite/Utopia/Response/Model/Migration.php b/src/Appwrite/Utopia/Response/Model/Migration.php index 0fbf7362b7..49463b0c9a 100644 --- a/src/Appwrite/Utopia/Response/Model/Migration.php +++ b/src/Appwrite/Utopia/Response/Model/Migration.php @@ -102,6 +102,20 @@ class Migration extends Model 'example' => 'database', 'array' => false ]) + ->addRule('destinationResourceId', [ + 'type' => self::TYPE_STRING, + 'description' => 'ID of the destination resource created or overwritten by the migration.', + 'default' => '', + 'example' => 'databaseId', + 'array' => false + ]) + ->addRule('destinationResourceType', [ + 'type' => self::TYPE_STRING, + 'description' => 'Type of the destination resource created or overwritten by the migration.', + 'default' => '', + 'example' => 'database', + 'array' => false + ]) ->addRule('statusCounters', [ 'type' => self::TYPE_JSON, 'description' => 'A group of counters that represent the total progress of the migration.', diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 1f131cb07b..c440fa32ce 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -3496,8 +3496,10 @@ trait MigrationsBase /** * Import documents from a CSV file. + * + * @return array{databaseId: string, tableId: string, migrationId: string} */ - public function testCreateCSVImport(): void + public function testCreateCSVImport(): array { // Make a database $response = $this->client->call(Client::METHOD_POST, '/databases', [ @@ -3799,6 +3801,76 @@ trait MigrationsBase $this->assertArrayHasKey(Resource::TYPE_ROW, $migration['body']['statusCounters']); $this->assertEquals(25, $migration['body']['statusCounters'][Resource::TYPE_ROW]['success']); }, 10_000, 500); + + return [ + 'databaseId' => $databaseId, + 'tableId' => $tableId, + 'migrationId' => $migration['body']['$id'], + ]; + } + + /** + * @param array{databaseId: string, tableId: string, migrationId: string} $data + */ + #[Depends('testCreateCSVImport')] + public function testListMigrationsByDatabaseResource(array $data): void + { + $databaseId = $data['databaseId']; + $query = Query::or([ + Query::and([ + Query::equal('resourceId', [$databaseId]), + Query::equal('resourceType', [Resource::TYPE_DATABASE]), + ]), + Query::and([ + Query::equal('parentResourceId', [$databaseId]), + Query::equal('parentResourceType', [Resource::TYPE_DATABASE]), + ]), + Query::and([ + Query::equal('destinationResourceId', [$databaseId]), + Query::equal('destinationResourceType', [Resource::TYPE_DATABASE]), + ]), + ]); + + $response = $this->client->call(Client::METHOD_GET, '/migrations', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + $query->toString(), + Query::limit(100)->toString(), + ], + ]); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertContains($data['migrationId'], array_column($response['body']['migrations'], '$id')); + + $migration = null; + foreach ($response['body']['migrations'] as $candidate) { + if ($candidate['$id'] === $data['migrationId']) { + $migration = $candidate; + break; + } + } + + $this->assertNotNull($migration); + $this->assertSame($data['tableId'], $migration['resourceId']); + $this->assertSame($databaseId, $migration['parentResourceId']); + $this->assertSame(Resource::TYPE_DATABASE, $migration['parentResourceType']); + $this->assertSame($databaseId, $migration['destinationResourceId']); + $this->assertSame(Resource::TYPE_DATABASE, $migration['destinationResourceType']); + + $response = $this->client->call(Client::METHOD_GET, '/migrations', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + Query::equal('destinationResourceId', [$databaseId])->toString(), + Query::equal('destinationResourceType', [Resource::TYPE_DATABASE])->toString(), + ], + ]); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertContains($data['migrationId'], array_column($response['body']['migrations'], '$id')); } /** diff --git a/tests/unit/Utopia/Response/Filters/V27Test.php b/tests/unit/Utopia/Response/Filters/V27Test.php index ca18768a90..e2420ae332 100644 --- a/tests/unit/Utopia/Response/Filters/V27Test.php +++ b/tests/unit/Utopia/Response/Filters/V27Test.php @@ -22,6 +22,8 @@ final class V27Test extends TestCase 'parentResourceId' => 'database', 'parentResourceInternalId' => '10', 'parentResourceType' => 'database', + 'destinationResourceId' => 'destination', + 'destinationResourceType' => 'database', ], Response::MODEL_MIGRATION); $this->assertSame([ @@ -43,6 +45,8 @@ final class V27Test extends TestCase 'parentResourceId' => '', 'parentResourceInternalId' => '', 'parentResourceType' => '', + 'destinationResourceId' => '', + 'destinationResourceType' => '', ], Response::MODEL_MIGRATION); $this->assertSame([ @@ -64,6 +68,8 @@ final class V27Test extends TestCase 'resourceType' => 'collection', 'parentResourceId' => 'database', 'parentResourceType' => 'database', + 'destinationResourceId' => 'destination', + 'destinationResourceType' => 'database', ]], ], Response::MODEL_MIGRATION_LIST); From bc426845d69bfaa084029348b19507a2464ac868 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Sat, 18 Jul 2026 08:02:35 +1200 Subject: [PATCH 03/14] fix(migrations): fail when finalization hooks throw --- src/Appwrite/Platform/Workers/Migrations.php | 5 +- .../unit/Platform/Workers/MigrationsTest.php | 248 ++++++++++++++++++ 2 files changed, 251 insertions(+), 2 deletions(-) create mode 100644 tests/unit/Platform/Workers/MigrationsTest.php diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 31d57198e4..7a208dfb14 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -596,6 +596,9 @@ class Migrations extends Action return; } + $destination->success(); + $source->success(); + $destinationType = $migration->getAttribute('destination'); if ($destinationType === DestinationCSV::getName() || $destinationType === DestinationJSON::getName()) { $this->handleDataExportComplete($project, $migration, $publisherForMails, $queueForRealtime, $platform, $authorization); @@ -701,8 +704,6 @@ class Migrations extends Action ...$this->resolveResourceIds($migration), ); } - $destination?->success(); - $source?->success(); } } finally { $source?->cleanup(); diff --git a/tests/unit/Platform/Workers/MigrationsTest.php b/tests/unit/Platform/Workers/MigrationsTest.php new file mode 100644 index 0000000000..c42144add3 --- /dev/null +++ b/tests/unit/Platform/Workers/MigrationsTest.php @@ -0,0 +1,248 @@ +createSourceMock(); + $destination = $this->createDestinationMock(); + + $destination + ->expects($this->once()) + ->method('success') + ->willReturnCallback(static function () use (&$events): void { + $events[] = 'destination:success'; + }); + $source + ->expects($this->once()) + ->method('success') + ->willReturnCallback(static function () use (&$events): void { + $events[] = 'source:success'; + }); + $source->expects($this->never())->method('error'); + $destination->expects($this->never())->method('error'); + + $migration = $this->createMigration(); + $processor = $this->createProcessor($source, $destination, $events); + + $this->process($processor, $migration); + + $this->assertSame('completed', $migration->getAttribute('status')); + $this->assertSame('finished', $migration->getAttribute('stage')); + $this->assertSame([ + 'persist:processing:processing', + 'persist:processing:migrating', + 'destination:success', + 'source:success', + 'persist:completed:finished', + ], $events); + } + + public function testThrowingSourceSuccessHookPersistsFailedMigrationWithoutRerunningHooks(): void + { + $events = []; + $source = $this->createSourceMock(); + $destination = $this->createDestinationMock(); + + $destination + ->expects($this->once()) + ->method('success') + ->willReturnCallback(static function () use (&$events): void { + $events[] = 'destination:success'; + }); + $source + ->expects($this->once()) + ->method('success') + ->willReturnCallback(static function () use (&$events): void { + $events[] = 'source:success'; + throw new \RuntimeException('Finalization failed'); + }); + $source + ->expects($this->once()) + ->method('error') + ->willReturnCallback(static function () use (&$events): void { + $events[] = 'source:error'; + }); + $destination + ->expects($this->once()) + ->method('error') + ->willReturnCallback(static function () use (&$events): void { + $events[] = 'destination:error'; + }); + + $migration = $this->createMigration(); + $processor = $this->createProcessor($source, $destination, $events); + + $this->process($processor, $migration); + + $this->assertSame('failed', $migration->getAttribute('status')); + $this->assertSame('finished', $migration->getAttribute('stage')); + $this->assertSame([ + 'persist:processing:processing', + 'persist:processing:migrating', + 'destination:success', + 'source:success', + 'persist:failed:finished', + 'source:error', + 'destination:error', + ], $events); + $this->assertNotContains('persist:completed:finished', $events); + } + + private function createSourceMock(): Source&MockObject + { + $target = $this->createMock(Source::class); + $target->method('getErrors')->willReturn([]); + $target->expects($this->once())->method('shutdown'); + $target->expects($this->once())->method('cleanUp'); + + return $target; + } + + private function createDestinationMock(): Destination&MockObject + { + $target = $this->createMock(Destination::class); + $target->method('getErrors')->willReturn([]); + $target->expects($this->once())->method('shutdown'); + $target->expects($this->once())->method('cleanUp'); + + return $target; + } + + private function createMigration(): Document + { + return new Document([ + '$id' => 'migration', + '$sequence' => 1, + 'credentials' => [], + 'destination' => 'TestDestination', + 'options' => [], + 'resourceId' => '', + 'resourceType' => '', + 'resources' => [], + 'source' => 'TestSource', + 'stage' => 'pending', + 'status' => 'pending', + ]); + } + + /** + * @param array $events + */ + private function createProcessor(Source $source, Destination $destination, array &$events): \Closure + { + $record = static function (string $event) use (&$events): void { + $events[] = $event; + }; + $worker = new class ($source, $destination, $record) extends Migrations { + public function __construct( + private readonly Source $migrationSource, + private readonly Destination $migrationDestination, + private readonly \Closure $record, + ) { + } + + public function process( + Document $migration, + Document $project, + Realtime $queueForRealtime, + MailPublisher $publisherForMails, + Context $usage, + UsagePublisher $publisherForUsage, + Authorization $authorization, + ): void { + $this->project = $project; + $this->logError = static function (): void { + }; + + $this->processMigration( + $migration, + $queueForRealtime, + $publisherForMails, + $usage, + $publisherForUsage, + [], + $authorization, + ); + } + + #[\Override] + protected function generateAPIKey(Document $project): string + { + return 'key'; + } + + #[\Override] + protected function processSource(Document $migration): Source + { + return $this->migrationSource; + } + + #[\Override] + protected function processDestination(Document $migration): Destination + { + return $this->migrationDestination; + } + + #[\Override] + protected function updateMigrationDocument( + Document $migration, + Document $project, + Realtime $queueForRealtime, + ): Document { + ($this->record)('persist:' + . $migration->getAttribute('status') + . ':' + . $migration->getAttribute('stage')); + + return $migration; + } + }; + + return $worker->process(...); + } + + private function process(\Closure $processor, Document $migration): void + { + $publisher = $this->createStub(Publisher::class); + $queue = new Queue('test'); + $host = \getenv('_APP_MIGRATION_HOST'); + \putenv('_APP_MIGRATION_HOST=localhost'); + + try { + $processor( + $migration, + new Document([ + '$id' => 'project', + '$sequence' => 1, + ]), + new Realtime(), + new MailPublisher($publisher, $queue), + new Context(), + new UsagePublisher($publisher, $queue), + new Authorization(), + ); + } finally { + \putenv($host === false ? '_APP_MIGRATION_HOST' : '_APP_MIGRATION_HOST=' . $host); + } + } +} From 700a4c32f4dd60b72ea57cbcc78505a43b0f6f6c Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Sat, 18 Jul 2026 09:00:37 +1200 Subject: [PATCH 04/14] fix(migrations): use compatible resource selectors --- composer.json | 2 +- composer.lock | 10 +-- src/Appwrite/Platform/Workers/Migrations.php | 69 ++++++++++---------- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/composer.json b/composer.json index 3178893a90..639cae1ffe 100644 --- a/composer.json +++ b/composer.json @@ -83,7 +83,7 @@ "utopia-php/lock": "0.2.*", "utopia-php/logger": "0.8.*", "utopia-php/messaging": "^1.2", - "utopia-php/migration": "dev-feat/drop-compound-resource-id#a7e94c86a96fc7cdfff3eae9845270d91f83e7f8 as 1.17.3", + "utopia-php/migration": "dev-feat/drop-compound-resource-id#7ed62ca2e2279bf30fa2018655e045c59bb5bc3d as 1.17.3", "utopia-php/platform": "^1.0@RC", "utopia-php/pools": "1.*", "utopia-php/span": "3.0.*", diff --git a/composer.lock b/composer.lock index e73fdc4039..673731619d 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": "4d8282e455d647d1132ef9c0340924a1", + "content-hash": "de9b7927d2e0c923329b782e737ab716", "packages": [ { "name": "adhocore/jwt", @@ -4404,12 +4404,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "a7e94c86a96fc7cdfff3eae9845270d91f83e7f8" + "reference": "7ed62ca2e2279bf30fa2018655e045c59bb5bc3d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/a7e94c86a96fc7cdfff3eae9845270d91f83e7f8", - "reference": "a7e94c86a96fc7cdfff3eae9845270d91f83e7f8", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/7ed62ca2e2279bf30fa2018655e045c59bb5bc3d", + "reference": "7ed62ca2e2279bf30fa2018655e045c59bb5bc3d", "shasum": "" }, "require": { @@ -4469,7 +4469,7 @@ "source": "https://github.com/utopia-php/migration/tree/feat/drop-compound-resource-id", "issues": "https://github.com/utopia-php/migration/issues" }, - "time": "2026-07-17T12:11:07+00:00" + "time": "2026-07-17T20:50:27+00:00" }, { "name": "utopia-php/mongo", diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 7a208dfb14..0d186fbeb3 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -290,20 +290,20 @@ class Migrations extends Action $projectDB, $queries ), - CSV::getName() => new CSV( - $databaseId, - $tableId, - $migrationOptions['path'], - $this->deviceForMigrations, - $this->dbForProject, - $getDatabasesDB + CSV::getName() => CSV::fromResourceIds( + databaseId: $databaseId, + tableId: $tableId, + filePath: $migrationOptions['path'], + device: $this->deviceForMigrations, + dbForProject: $this->dbForProject, + getDatabasesDB: $getDatabasesDB, ), - JSON::getName() => new JSON( - $databaseId, - $tableId, - $migrationOptions['path'], - $this->deviceForMigrations, - $this->dbForProject, + JSON::getName() => JSON::fromResourceIds( + databaseId: $databaseId, + tableId: $tableId, + filePath: $migrationOptions['path'], + device: $this->deviceForMigrations, + dbForProject: $this->dbForProject, ), default => throw new Exception(Exception::MIGRATION_SOURCE_TYPE_INVALID), }; @@ -337,25 +337,25 @@ class Migrations extends Action OnDuplicate::tryFrom($options['onDuplicate'] ?? '') ?? OnDuplicate::Fail, $this->resolveDestinationDatabaseDsn(...), ), - DestinationCSV::getName() => new DestinationCSV( - $this->deviceForFiles, - $databaseId, - $tableId, - $options['bucketId'], - $migration->getId(), - $options['columns'], - $options['delimiter'], - $options['enclosure'], - $options['escape'], - $options['header'], + DestinationCSV::getName() => DestinationCSV::fromResourceIds( + deviceForFiles: $this->deviceForFiles, + databaseId: $databaseId, + tableId: $tableId, + directory: $options['bucketId'], + filename: $options['filename'], + allowedColumns: $options['columns'], + delimiter: $options['delimiter'], + enclosure: $options['enclosure'], + escape: $options['escape'], + includeHeaders: $options['header'], ), - DestinationJSON::getName() => new DestinationJSON( - $this->deviceForFiles, - $databaseId, - $tableId, - $options['bucketId'] ?? 'default', - $migration->getId(), - $options['columns'] ?? [], + DestinationJSON::getName() => DestinationJSON::fromResourceIds( + deviceForFiles: $this->deviceForFiles, + databaseId: $databaseId, + tableId: $tableId, + directory: $options['bucketId'] ?? 'default', + filename: $options['filename'], + allowedColumns: $options['columns'] ?? [], ), default => throw new Exception(Exception::MIGRATION_DESTINATION_TYPE_INVALID), }; @@ -540,7 +540,8 @@ class Migrations extends Action $migration->setAttribute('stage', 'migrating'); $this->updateMigrationDocument($migration, $project, $queueForRealtime); - $transfer->run( + [$rootResourceId, $rootResourceChildId] = $this->resolveResourceIds($migration); + $transfer->runWithResourceSelector( $migration->getAttribute('resources'), function ($resources) use ($migration, $transfer, $project, $queueForRealtime, &$aggregatedResources) { $migration->setAttribute('resourceData', json_encode($transfer->getCache())); @@ -578,9 +579,9 @@ class Migrations extends Action } $this->updateMigrationDocument($migration, $project, $queueForRealtime); }, - $this->resolveResourceIds($migration)[0], + $rootResourceId, $migration->getAttribute('parentResourceType') ?: $migration->getAttribute('resourceType'), - $this->resolveResourceIds($migration)[1], + $rootResourceChildId, ); $destination->shutdown(); From be8dea9d8ba2c1aea2267e2d43654b2d18207f62 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Sat, 18 Jul 2026 09:24:23 +1200 Subject: [PATCH 05/14] fix(migrations): preserve unresolved legacy resources --- src/Appwrite/Migration/Version/V25.php | 23 ++++++++++++++++----- tests/unit/Migration/Version/V25Test.php | 26 +++++++++++++++++++----- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index 7d57715128..01a98d71c0 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -79,6 +79,8 @@ class V25 extends Migration $resourceId = (string) $document->getAttribute('resourceId', ''); $parentResourceId = (string) $document->getAttribute('parentResourceId', ''); + $parentResourceType = ''; + $split = false; if ($parentResourceId === '') { if (!\str_contains($resourceId, ':')) { @@ -91,6 +93,22 @@ class V25 extends Migration } $parentResourceType = (string) $document->getAttribute('resourceType', ''); + $split = true; + } + + if ($resourceId === '') { + return $document; + } + + $internalIds = $this->resolveInternalIds($parentResourceId, $resourceId, $document->getId()); + if ( + $split + && (!isset($internalIds['parentResourceInternalId']) || !isset($internalIds['resourceInternalId'])) + ) { + return $document; + } + + if ($split) { $document ->setAttribute('resourceId', $resourceId) ->setAttribute('resourceType', Resource::TYPE_COLLECTION) @@ -101,11 +119,6 @@ class V25 extends Migration } } - if ($resourceId === '') { - return $document; - } - - $internalIds = $this->resolveInternalIds($parentResourceId, $resourceId, $document->getId()); if ( $document->getAttribute('parentResourceInternalId', '') === '' && isset($internalIds['parentResourceInternalId']) diff --git a/tests/unit/Migration/Version/V25Test.php b/tests/unit/Migration/Version/V25Test.php index aee039880b..f09736e87f 100644 --- a/tests/unit/Migration/Version/V25Test.php +++ b/tests/unit/Migration/Version/V25Test.php @@ -11,7 +11,7 @@ use Utopia\Migration\Resource; final class V25Test extends TestCase { - public function testSplitsDeletedResourceWithoutWritingEmptyInternalIds(): void + public function testPreservesLegacyResourceWhenInternalIdsCannotBeResolved(): void { $migration = new class () extends V25 { public function __construct() @@ -38,10 +38,10 @@ final class V25Test extends TestCase $result = $migration->migrate($document); - $this->assertSame('collection', $result->getAttribute('resourceId')); - $this->assertSame(Resource::TYPE_COLLECTION, $result->getAttribute('resourceType')); - $this->assertSame('database', $result->getAttribute('parentResourceId')); - $this->assertSame(Resource::TYPE_DATABASE, $result->getAttribute('parentResourceType')); + $this->assertSame('database:collection', $result->getAttribute('resourceId')); + $this->assertSame(Resource::TYPE_DATABASE, $result->getAttribute('resourceType')); + $this->assertNull($result->getAttribute('parentResourceId')); + $this->assertNull($result->getAttribute('parentResourceType')); $this->assertNull($result->getAttribute('resourceInternalId')); $this->assertNull($result->getAttribute('parentResourceInternalId')); } @@ -88,6 +88,18 @@ final class V25Test extends TestCase ]); $migration->migrate($document); + $this->assertSame('database:collection', $document->getAttribute('resourceId')); + $this->assertSame(Resource::TYPE_DATABASE, $document->getAttribute('resourceType')); + $this->assertNull($document->getAttribute('parentResourceId')); + + $migration->setInternalIds([ + 'parentResourceInternalId' => '10', + ]); + $migration->migrate($document); + $this->assertSame('database:collection', $document->getAttribute('resourceId')); + $this->assertSame(Resource::TYPE_DATABASE, $document->getAttribute('resourceType')); + $this->assertNull($document->getAttribute('parentResourceId')); + $migration->setInternalIds([ 'parentResourceInternalId' => '10', 'resourceInternalId' => '20', @@ -98,6 +110,10 @@ final class V25Test extends TestCase $this->assertSame('10', $document->getAttribute('parentResourceInternalId')); $this->assertSame('20', $document->getAttribute('resourceInternalId')); + $this->assertSame('collection', $document->getAttribute('resourceId')); + $this->assertSame(Resource::TYPE_COLLECTION, $document->getAttribute('resourceType')); + $this->assertSame('database', $document->getAttribute('parentResourceId')); + $this->assertSame(Resource::TYPE_DATABASE, $document->getAttribute('parentResourceType')); $this->assertSame($afterResolution, $document->getArrayCopy()); } } From 68299a5a6153fb0dbb3c75be17e9072317b86fee Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Sat, 18 Jul 2026 09:25:49 +1200 Subject: [PATCH 06/14] fix(migrations): normalize empty resource selectors --- src/Appwrite/Platform/Workers/Migrations.php | 6 ++- .../unit/Platform/Workers/MigrationsTest.php | 40 ++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 0d186fbeb3..3be60e67b7 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -541,6 +541,10 @@ class Migrations extends Action $this->updateMigrationDocument($migration, $project, $queueForRealtime); [$rootResourceId, $rootResourceChildId] = $this->resolveResourceIds($migration); + $rootResourceType = (string) ( + $migration->getAttribute('parentResourceType') + ?: $migration->getAttribute('resourceType') + ); $transfer->runWithResourceSelector( $migration->getAttribute('resources'), function ($resources) use ($migration, $transfer, $project, $queueForRealtime, &$aggregatedResources) { @@ -580,7 +584,7 @@ class Migrations extends Action $this->updateMigrationDocument($migration, $project, $queueForRealtime); }, $rootResourceId, - $migration->getAttribute('parentResourceType') ?: $migration->getAttribute('resourceType'), + $rootResourceType, $rootResourceChildId, ); diff --git a/tests/unit/Platform/Workers/MigrationsTest.php b/tests/unit/Platform/Workers/MigrationsTest.php index c42144add3..af75e2922b 100644 --- a/tests/unit/Platform/Workers/MigrationsTest.php +++ b/tests/unit/Platform/Workers/MigrationsTest.php @@ -108,6 +108,42 @@ final class MigrationsTest extends TestCase $this->assertNotContains('persist:completed:finished', $events); } + public function testNullResourceTypeUsesEmptyResourceSelector(): void + { + $events = []; + $source = $this->createSourceMock(); + $destination = $this->createDestinationMock(); + + $destination + ->expects($this->once()) + ->method('success') + ->willReturnCallback(static function () use (&$events): void { + $events[] = 'destination:success'; + }); + $source + ->expects($this->once()) + ->method('success') + ->willReturnCallback(static function () use (&$events): void { + $events[] = 'source:success'; + }); + $source->expects($this->never())->method('error'); + $destination->expects($this->never())->method('error'); + + $migration = $this->createMigration(null); + $processor = $this->createProcessor($source, $destination, $events); + + $this->process($processor, $migration); + + $this->assertSame('completed', $migration->getAttribute('status')); + $this->assertSame([ + 'persist:processing:processing', + 'persist:processing:migrating', + 'destination:success', + 'source:success', + 'persist:completed:finished', + ], $events); + } + private function createSourceMock(): Source&MockObject { $target = $this->createMock(Source::class); @@ -128,7 +164,7 @@ final class MigrationsTest extends TestCase return $target; } - private function createMigration(): Document + private function createMigration(?string $resourceType = ''): Document { return new Document([ '$id' => 'migration', @@ -137,7 +173,7 @@ final class MigrationsTest extends TestCase 'destination' => 'TestDestination', 'options' => [], 'resourceId' => '', - 'resourceType' => '', + 'resourceType' => $resourceType, 'resources' => [], 'source' => 'TestSource', 'stage' => 'pending', From 221e9727dadc8c349874b3d30c53d3da4bb3b28e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 20 Jul 2026 21:30:51 +1200 Subject: [PATCH 07/14] refactor(migrations): adapt migration and deps to main Fold the migration-resource-link schema provisioning and document backfill into main's V25 migration instead of a standalone V25: only the class mapped to the release version (2.0.0 => V25) is executed, so a separate migration would never run. Main's existing V25 collection work is preserved and the migrations-collection attributes/indexes plus the resource-link document backfill are layered on top. Gate the V27 request/response filters on < 2.0.0 (the release the fields ship in) instead of the branch's 1.9.6, keeping the API version aligned with the folded migration. Restore main's utopia-php/auth VCS repository alongside the utopia-php/migration one, keep utopia-php/messaging ^2.0, and regenerate the lock so only utopia-php/migration moves to the resource-selector branch. APP_VERSION_STABLE and the migration version map stay at main's values. Co-Authored-By: Claude Fable 5 --- app/controllers/general.php | 4 +- composer.json | 26 +- composer.lock | 714 ++++++++++--------- src/Appwrite/Migration/Version/V25.php | 148 +++- src/Appwrite/Utopia/Request/Filters/V27.php | 2 +- src/Appwrite/Utopia/Response/Filters/V27.php | 2 +- 6 files changed, 525 insertions(+), 371 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 47b4ecd097..18f252458e 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -919,7 +919,7 @@ Http::init() if (version_compare($requestFormat, '1.9.5', '<')) { $request->addFilter(new RequestV26()); } - if (version_compare($requestFormat, '1.9.6', '<')) { + if (version_compare($requestFormat, '2.0.0', '<')) { $request->addFilter(new RequestV27()); } } @@ -946,7 +946,7 @@ Http::init() */ $responseFormat = $request->getHeaderLine('x-appwrite-response-format', System::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '')); if ($responseFormat) { - if (version_compare($responseFormat, '1.9.6', '<')) { + if (version_compare($responseFormat, '2.0.0', '<')) { $response->addFilter(new ResponseV27()); } if (version_compare($responseFormat, '1.9.5', '<')) { diff --git a/composer.json b/composer.json index 639cae1ffe..228d754f57 100644 --- a/composer.json +++ b/composer.json @@ -38,13 +38,17 @@ "minimum-stability": "dev", "prefer-stable": true, "repositories": [ + { + "type": "vcs", + "url": "https://github.com/utopia-php/auth" + }, { "type": "vcs", "url": "https://github.com/utopia-php/migration" } ], "require": { - "php": ">=8.3.0", + "php": ">=8.5.0", "ext-curl": "*", "ext-imagick": "*", "ext-mbstring": "*", @@ -62,14 +66,14 @@ "utopia-php/abuse": "1.4.*", "utopia-php/agents": "2.*", "utopia-php/analytics": "0.15.*", - "utopia-php/audit": "2.6.*", - "utopia-php/auth": "^0.7", - "utopia-php/cache": "^3.0", + "utopia-php/audit": "2.9.*", + "utopia-php/auth": "^0.10", + "utopia-php/cache": "^3.0.0", "utopia-php/cli": "^0.24", "utopia-php/compression": "0.1.*", "utopia-php/config": "1.*", "utopia-php/console": "0.1.*", - "utopia-php/database": "6.0.*", + "utopia-php/database": "^6.0.0", "utopia-php/detector": "0.2.*", "utopia-php/domains": "^2.2", "utopia-php/emails": "0.7.*", @@ -77,24 +81,24 @@ "utopia-php/dsn": "0.2.1", "utopia-php/http": "^2.0@RC", "utopia-php/fetch": "^1.1", - "utopia-php/validators": "0.2.*", + "utopia-php/validators": "0.3.*", "utopia-php/image": "0.8.*", "utopia-php/locale": "0.8.*", "utopia-php/lock": "0.2.*", "utopia-php/logger": "0.8.*", - "utopia-php/messaging": "^1.2", + "utopia-php/messaging": "^2.0", "utopia-php/migration": "dev-feat/drop-compound-resource-id#7ed62ca2e2279bf30fa2018655e045c59bb5bc3d as 1.17.3", "utopia-php/platform": "^1.0@RC", "utopia-php/pools": "1.*", "utopia-php/span": "3.0.*", "utopia-php/preloader": "0.2.*", - "utopia-php/queue": "^0.21", + "utopia-php/queue": "^0.22", "utopia-php/servers": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/storage": "2.*", "utopia-php/system": "0.10.*", "utopia-php/telemetry": "^0.4", - "utopia-php/vcs": "4.*", + "utopia-php/vcs": "^4.4.2", "utopia-php/websocket": "1.0.*", "matomo/device-detector": "6.4.*", "dragonmantank/cron-expression": "3.4.*", @@ -104,7 +108,9 @@ "spomky-labs/otphp": "11.*", "webonyx/graphql-php": "15.32.*", "league/csv": "9.14.*", - "enshrined/svg-sanitize": "0.22.*" + "enshrined/svg-sanitize": "0.22.*", + "utopia-php/client": "^0.2.2", + "open-runtimes/sdk-for-php": "^0.4.0" }, "require-dev": { "ext-fileinfo": "*", diff --git a/composer.lock b/composer.lock index 673731619d..c3b90792c9 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": "de9b7927d2e0c923329b782e737ab716", + "content-hash": "de6d55bb252b6063fe98964392cbc80a", "packages": [ { "name": "adhocore/jwt", @@ -216,23 +216,22 @@ }, { "name": "brick/math", - "version": "0.14.8", + "version": "0.18.0", "source": { "type": "git", "url": "https://github.com/brick/math.git", - "reference": "63422359a44b7f06cae63c3b429b59e8efcc0629" + "reference": "82944324d1c1bdb2c2618e89978d4e2ad78d69ad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/brick/math/zipball/63422359a44b7f06cae63c3b429b59e8efcc0629", - "reference": "63422359a44b7f06cae63c3b429b59e8efcc0629", + "url": "https://api.github.com/repos/brick/math/zipball/82944324d1c1bdb2c2618e89978d4e2ad78d69ad", + "reference": "82944324d1c1bdb2c2618e89978d4e2ad78d69ad", "shasum": "" }, "require": { "php": "^8.2" }, "require-dev": { - "php-coveralls/php-coveralls": "^2.2", "phpstan/phpstan": "2.1.22", "phpunit/phpunit": "^11.5" }, @@ -264,7 +263,7 @@ ], "support": { "issues": "https://github.com/brick/math/issues", - "source": "https://github.com/brick/math/tree/0.14.8" + "source": "https://github.com/brick/math/tree/0.18.0" }, "funding": [ { @@ -272,7 +271,7 @@ "type": "github" } ], - "time": "2026-02-10T14:33:43+00:00" + "time": "2026-06-14T18:21:03+00:00" }, { "name": "chillerlan/php-qrcode", @@ -606,84 +605,6 @@ }, "time": "2025-08-12T10:13:48+00:00" }, - { - "name": "giggsey/libphonenumber-for-php-lite", - "version": "9.0.23", - "source": { - "type": "git", - "url": "https://github.com/giggsey/libphonenumber-for-php-lite.git", - "reference": "e8f6f896c1bef398136849934a934904bd9bf072" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/giggsey/libphonenumber-for-php-lite/zipball/e8f6f896c1bef398136849934a934904bd9bf072", - "reference": "e8f6f896c1bef398136849934a934904bd9bf072", - "shasum": "" - }, - "require": { - "php": "^8.1", - "symfony/polyfill-mbstring": "^1.17" - }, - "conflict": { - "giggsey/libphonenumber-for-php": "*" - }, - "require-dev": { - "ext-dom": "*", - "friendsofphp/php-cs-fixer": "^3.71", - "infection/infection": "^0.29|^0.31.0", - "nette/php-generator": "^4.1", - "php-coveralls/php-coveralls": "^2.7", - "phpstan/extension-installer": "^1.4.3", - "phpstan/phpstan": "^2.1.7", - "phpstan/phpstan-deprecation-rules": "^2.0.1", - "phpstan/phpstan-phpunit": "^2.0.4", - "phpstan/phpstan-strict-rules": "^2.0.3", - "phpunit/phpunit": "^10.5.45", - "symfony/console": "^6.4", - "symfony/filesystem": "^6.4", - "symfony/process": "^6.4" - }, - "suggest": { - "giggsey/libphonenumber-for-php": "Use libphonenumber-for-php for geocoding, carriers, timezones and matching" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "9.x-dev" - } - }, - "autoload": { - "psr-4": { - "libphonenumber\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Joshua Gigg", - "email": "giggsey@gmail.com", - "homepage": "https://giggsey.com/" - } - ], - "description": "A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber", - "homepage": "https://github.com/giggsey/libphonenumber-for-php-lite", - "keywords": [ - "geocoding", - "geolocation", - "libphonenumber", - "mobile", - "phonenumber", - "validation" - ], - "support": { - "issues": "https://github.com/giggsey/libphonenumber-for-php-lite/issues", - "source": "https://github.com/giggsey/libphonenumber-for-php-lite" - }, - "time": "2026-01-30T12:33:03+00:00" - }, { "name": "google/protobuf", "version": "v4.33.6", @@ -1224,6 +1145,49 @@ ], "time": "2023-11-08T09:30:43+00:00" }, + { + "name": "open-runtimes/sdk-for-php", + "version": "0.4.0", + "source": { + "type": "git", + "url": "https://github.com/open-runtimes/sdk-for-php.git", + "reference": "02c01ec6c807f43602d93534252e96c9451ecd80" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/open-runtimes/sdk-for-php/zipball/02c01ec6c807f43602d93534252e96c9451ecd80", + "reference": "02c01ec6c807f43602d93534252e96c9451ecd80", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "php": ">=8.4", + "utopia-php/client": "^0.2.2" + }, + "require-dev": { + "laravel/pint": "^1.22", + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^13.1", + "rector/rector": "^2.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "OpenRuntimes\\Orchestrator\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHP SDK for the Open Runtimes orchestrator Jobs API.", + "support": { + "issues": "https://github.com/open-runtimes/sdk-for-php/issues", + "source": "https://github.com/open-runtimes/sdk-for-php/tree/0.4.0" + }, + "time": "2026-07-13T21:55:56+00:00" + }, { "name": "open-telemetry/api", "version": "1.9.0", @@ -2252,20 +2216,20 @@ }, { "name": "ramsey/uuid", - "version": "4.9.2", + "version": "4.9.3", "source": { "type": "git", "url": "https://github.com/ramsey/uuid.git", - "reference": "8429c78ca35a09f27565311b98101e2826affde0" + "reference": "1df15849d00943a67d677dc9cfd80795f038c9f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/uuid/zipball/8429c78ca35a09f27565311b98101e2826affde0", - "reference": "8429c78ca35a09f27565311b98101e2826affde0", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/1df15849d00943a67d677dc9cfd80795f038c9f8", + "reference": "1df15849d00943a67d677dc9cfd80795f038c9f8", "shasum": "" }, "require": { - "brick/math": "^0.8.16 || ^0.9 || ^0.10 || ^0.11 || ^0.12 || ^0.13 || ^0.14", + "brick/math": ">=0.8.16 <=0.18", "php": "^8.0", "ramsey/collection": "^1.2 || ^2.0" }, @@ -2324,9 +2288,9 @@ ], "support": { "issues": "https://github.com/ramsey/uuid/issues", - "source": "https://github.com/ramsey/uuid/tree/4.9.2" + "source": "https://github.com/ramsey/uuid/tree/4.9.3" }, - "time": "2025-12-14T04:43:48+00:00" + "time": "2026-06-18T03:57:49+00:00" }, { "name": "spomky-labs/otphp", @@ -2400,16 +2364,16 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.7.0", + "version": "v3.7.1", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "50f59d1f3ca46d41ac911f97a78626b6756af35b" + "reference": "f3202fa1b5097b0af062dc978b32ecf63404e31d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/50f59d1f3ca46d41ac911f97a78626b6756af35b", - "reference": "50f59d1f3ca46d41ac911f97a78626b6756af35b", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/f3202fa1b5097b0af062dc978b32ecf63404e31d", + "reference": "f3202fa1b5097b0af062dc978b32ecf63404e31d", "shasum": "" }, "require": { @@ -2447,7 +2411,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.7.0" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.7.1" }, "funding": [ { @@ -2467,20 +2431,20 @@ "type": "tidelift" } ], - "time": "2026-04-13T15:52:40+00:00" + "time": "2026-06-05T06:23:12+00:00" }, { "name": "symfony/http-client", - "version": "v7.4.13", + "version": "v7.4.14", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "e8a112b8415707265a7e614278136a9d92989a6a" + "reference": "f6bc6b5a54ff5afac4725cacec9bf2f52eb15920" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/e8a112b8415707265a7e614278136a9d92989a6a", - "reference": "e8a112b8415707265a7e614278136a9d92989a6a", + "url": "https://api.github.com/repos/symfony/http-client/zipball/f6bc6b5a54ff5afac4725cacec9bf2f52eb15920", + "reference": "f6bc6b5a54ff5afac4725cacec9bf2f52eb15920", "shasum": "" }, "require": { @@ -2548,7 +2512,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.4.13" + "source": "https://github.com/symfony/http-client/tree/v7.4.14" }, "funding": [ { @@ -2568,20 +2532,20 @@ "type": "tidelift" } ], - "time": "2026-05-24T09:57:54+00:00" + "time": "2026-06-16T11:50:14+00:00" }, { "name": "symfony/http-client-contracts", - "version": "v3.7.0", + "version": "v3.7.1", "source": { "type": "git", "url": "https://github.com/symfony/http-client-contracts.git", - "reference": "4a2d00c37651c0bdc2b9e1c773487a8bf4edb12d" + "reference": "41fc42d276aeff21192465331ebbab7d83a743c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/4a2d00c37651c0bdc2b9e1c773487a8bf4edb12d", - "reference": "4a2d00c37651c0bdc2b9e1c773487a8bf4edb12d", + "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/41fc42d276aeff21192465331ebbab7d83a743c0", + "reference": "41fc42d276aeff21192465331ebbab7d83a743c0", "shasum": "" }, "require": { @@ -2630,7 +2594,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/http-client-contracts/tree/v3.7.0" + "source": "https://github.com/symfony/http-client-contracts/tree/v3.7.1" }, "funding": [ { @@ -2650,7 +2614,7 @@ "type": "tidelift" } ], - "time": "2026-03-06T13:17:50+00:00" + "time": "2026-06-05T06:23:12+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -2979,16 +2943,16 @@ }, { "name": "symfony/service-contracts", - "version": "v3.7.0", + "version": "v3.7.1", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "d25d82433a80eba6aa0e6c24b61d7370d99e444a" + "reference": "c0a284bab1ed8aa0417e3d69250ab437739563a0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/d25d82433a80eba6aa0e6c24b61d7370d99e444a", - "reference": "d25d82433a80eba6aa0e6c24b61d7370d99e444a", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/c0a284bab1ed8aa0417e3d69250ab437739563a0", + "reference": "c0a284bab1ed8aa0417e3d69250ab437739563a0", "shasum": "" }, "require": { @@ -3042,7 +3006,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.7.0" + "source": "https://github.com/symfony/service-contracts/tree/v3.7.1" }, "funding": [ { @@ -3062,7 +3026,7 @@ "type": "tidelift" } ], - "time": "2026-03-28T09:44:51+00:00" + "time": "2026-06-16T09:55:08+00:00" }, { "name": "tbachert/spi", @@ -3118,16 +3082,16 @@ }, { "name": "utopia-php/abuse", - "version": "1.4.1", + "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "8f5df0274869cf9022eea7d8030ca1a0d458b3b2" + "reference": "3b527181546d6191ac2d028a2fd1e500ca90f999" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/8f5df0274869cf9022eea7d8030ca1a0d458b3b2", - "reference": "8f5df0274869cf9022eea7d8030ca1a0d458b3b2", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/3b527181546d6191ac2d028a2fd1e500ca90f999", + "reference": "3b527181546d6191ac2d028a2fd1e500ca90f999", "shasum": "" }, "require": { @@ -3135,8 +3099,9 @@ "ext-curl": "*", "ext-pdo": "*", "ext-redis": "*", - "php": ">=8.2", - "utopia-php/database": "^6.0.0" + "php": ">=8.4.1", + "utopia-php/database": "^6.0.0", + "utopia-php/pools": "1.*" }, "require-dev": { "laravel/pint": "1.*", @@ -3164,9 +3129,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/1.4.1" + "source": "https://github.com/utopia-php/abuse/tree/1.4.2" }, - "time": "2026-06-18T11:18:52+00:00" + "time": "2026-06-19T07:18:23+00:00" }, { "name": "utopia-php/agents", @@ -3269,29 +3234,24 @@ }, { "name": "utopia-php/audit", - "version": "2.6.0", + "version": "2.9.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "f5bb07841e335e9ea7d4bd5860da1f580447014a" + "reference": "322fd475836be6aa20f8e7ec017299ac55b3c8f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/f5bb07841e335e9ea7d4bd5860da1f580447014a", - "reference": "f5bb07841e335e9ea7d4bd5860da1f580447014a", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/322fd475836be6aa20f8e7ec017299ac55b3c8f4", + "reference": "322fd475836be6aa20f8e7ec017299ac55b3c8f4", "shasum": "" }, "require": { - "php": ">=8.4", + "php": ">=8.5", "utopia-php/database": "^6.0.0", "utopia-php/fetch": "^1.1", "utopia-php/query": "0.1.*", - "utopia-php/validators": "0.2.*" - }, - "require-dev": { - "laravel/pint": "1.*", - "phpstan/phpstan": "1.*", - "phpunit/phpunit": "9.*" + "utopia-php/validators": "0.3.*" }, "type": "library", "autoload": { @@ -3313,22 +3273,22 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/2.6.0" + "source": "https://github.com/utopia-php/audit/tree/2.9.0" }, - "time": "2026-06-22T03:33:28+00:00" + "time": "2026-07-15T10:27:51+00:00" }, { "name": "utopia-php/auth", - "version": "0.7.0", + "version": "0.10.0", "source": { "type": "git", "url": "https://github.com/utopia-php/auth.git", - "reference": "22a2cf6ca604e5cc6bf10f0f8240195f0baa063a" + "reference": "fc6e7861a0428415a7454ba808a511cc01bf8db4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/auth/zipball/22a2cf6ca604e5cc6bf10f0f8240195f0baa063a", - "reference": "22a2cf6ca604e5cc6bf10f0f8240195f0baa063a", + "url": "https://api.github.com/repos/utopia-php/auth/zipball/fc6e7861a0428415a7454ba808a511cc01bf8db4", + "reference": "fc6e7861a0428415a7454ba808a511cc01bf8db4", "shasum": "" }, "require": { @@ -3336,7 +3296,7 @@ "ext-openssl": "*", "ext-scrypt": "*", "ext-sodium": "*", - "php": ">=8.1" + "php": ">=8.3" }, "type": "library", "autoload": { @@ -3344,7 +3304,16 @@ "Utopia\\Auth\\": "src/Auth" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "Utopia\\Tests\\Auth\\": "tests/Auth" + } + }, + "scripts": { + "test": [ + "phpunit --configuration phpunit.xml" + ] + }, "license": [ "MIT" ], @@ -3356,29 +3325,29 @@ ], "description": "A simple PHP authentication library", "keywords": [ - "Authentication", "auth", + "authentication", "php", "security" ], "support": { - "issues": "https://github.com/utopia-php/auth/issues", - "source": "https://github.com/utopia-php/auth/tree/0.7.0" + "source": "https://github.com/utopia-php/auth/tree/0.10.0", + "issues": "https://github.com/utopia-php/auth/issues" }, - "time": "2026-06-22T11:58:24+00:00" + "time": "2026-07-15T15:52:58+00:00" }, { "name": "utopia-php/cache", - "version": "3.0.2", + "version": "3.4.0", "source": { "type": "git", "url": "https://github.com/utopia-php/cache.git", - "reference": "086687d7ae23dd1dae67b943161e8cef143539e1" + "reference": "5c292d4df156f8b008f29fa6b033834b906bf328" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cache/zipball/086687d7ae23dd1dae67b943161e8cef143539e1", - "reference": "086687d7ae23dd1dae67b943161e8cef143539e1", + "url": "https://api.github.com/repos/utopia-php/cache/zipball/5c292d4df156f8b008f29fa6b033834b906bf328", + "reference": "5c292d4df156f8b008f29fa6b033834b906bf328", "shasum": "" }, "require": { @@ -3417,9 +3386,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cache/issues", - "source": "https://github.com/utopia-php/cache/tree/3.0.2" + "source": "https://github.com/utopia-php/cache/tree/3.4.0" }, - "time": "2026-05-19T22:38:16+00:00" + "time": "2026-07-01T15:44:35+00:00" }, { "name": "utopia-php/circuit-breaker", @@ -3485,16 +3454,16 @@ }, { "name": "utopia-php/cli", - "version": "0.24.1", + "version": "0.24.3", "source": { "type": "git", "url": "https://github.com/utopia-php/cli.git", - "reference": "ba1eabbbfa56f0936de7455a26dcd1afc3246636" + "reference": "d6a27f2902e777c2985e834ffb3e662130fd7ecc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cli/zipball/ba1eabbbfa56f0936de7455a26dcd1afc3246636", - "reference": "ba1eabbbfa56f0936de7455a26dcd1afc3246636", + "url": "https://api.github.com/repos/utopia-php/cli/zipball/d6a27f2902e777c2985e834ffb3e662130fd7ecc", + "reference": "d6a27f2902e777c2985e834ffb3e662130fd7ecc", "shasum": "" }, "require": { @@ -3526,22 +3495,79 @@ ], "support": { "issues": "https://github.com/utopia-php/cli/issues", - "source": "https://github.com/utopia-php/cli/tree/0.24.1" + "source": "https://github.com/utopia-php/cli/tree/0.24.3" }, - "time": "2026-06-10T16:25:51+00:00" + "time": "2026-06-26T10:48:18+00:00" }, { - "name": "utopia-php/compression", - "version": "0.1.5", + "name": "utopia-php/client", + "version": "0.2.3", "source": { "type": "git", - "url": "https://github.com/utopia-php/compression.git", - "reference": "d39208e3f0f3ad0a793e8023046eb2e69b57bae3" + "url": "https://github.com/utopia-php/client.git", + "reference": "377dc1f79441ac1584f25dba57904ee1cf0f626b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/compression/zipball/d39208e3f0f3ad0a793e8023046eb2e69b57bae3", - "reference": "d39208e3f0f3ad0a793e8023046eb2e69b57bae3", + "url": "https://api.github.com/repos/utopia-php/client/zipball/377dc1f79441ac1584f25dba57904ee1cf0f626b", + "reference": "377dc1f79441ac1584f25dba57904ee1cf0f626b", + "shasum": "" + }, + "require": { + "php": ">=8.5", + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.1 || ^2.0", + "utopia-php/pools": "^1.0", + "utopia-php/psr7": "^0.2", + "utopia-php/span": "^1.1 || ^3.0 || ^4.0" + }, + "require-dev": { + "swoole/ide-helper": "^6.0" + }, + "suggest": { + "ext-curl": "Required to use the cURL HTTP client adapter.", + "ext-simplexml": "Required to decode XML responses with Response::xml().", + "ext-swoole": "Required to use the Swoole coroutine HTTP client adapter." + }, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A lightweight PSR-18 HTTP client with cURL and Swoole coroutine backends", + "keywords": [ + "client", + "curl", + "http", + "php", + "psr-18", + "swoole", + "utopia" + ], + "support": { + "issues": "https://github.com/utopia-php/client/issues", + "source": "https://github.com/utopia-php/client/tree/0.2.3" + }, + "time": "2026-07-13T15:29:09+00:00" + }, + { + "name": "utopia-php/compression", + "version": "0.1.7", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/compression.git", + "reference": "655adbd2e42ba28f3148e0aaaf03a68dd6a1bd44" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/compression/zipball/655adbd2e42ba28f3148e0aaaf03a68dd6a1bd44", + "reference": "655adbd2e42ba28f3148e0aaaf03a68dd6a1bd44", "shasum": "" }, "require": { @@ -3575,9 +3601,9 @@ ], "support": { "issues": "https://github.com/utopia-php/compression/issues", - "source": "https://github.com/utopia-php/compression/tree/0.1.5" + "source": "https://github.com/utopia-php/compression/tree/0.1.7" }, - "time": "2026-06-10T15:38:47+00:00" + "time": "2026-06-26T10:48:18+00:00" }, { "name": "utopia-php/config", @@ -3676,16 +3702,16 @@ }, { "name": "utopia-php/database", - "version": "6.0.0", + "version": "6.4.3", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "fff9f0effbd40359ff925741ff9424856d8b4fde" + "reference": "d5ebecc2f4518329e3e1c5ded3769638908c78ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/fff9f0effbd40359ff925741ff9424856d8b4fde", - "reference": "fff9f0effbd40359ff925741ff9424856d8b4fde", + "url": "https://api.github.com/repos/utopia-php/database/zipball/d5ebecc2f4518329e3e1c5ded3769638908c78ba", + "reference": "d5ebecc2f4518329e3e1c5ded3769638908c78ba", "shasum": "" }, "require": { @@ -3693,12 +3719,12 @@ "ext-mongodb": "*", "ext-pdo": "*", "ext-redis": "*", - "php": ">=8.4", - "utopia-php/cache": "^3.0", + "php": ">=8.5", + "utopia-php/cache": "^3.1.0", "utopia-php/console": "0.1.*", "utopia-php/mongo": "1.*", "utopia-php/pools": "1.*", - "utopia-php/validators": "0.2.*" + "utopia-php/validators": "0.3.*" }, "require-dev": { "fakerphp/faker": "1.23.*", @@ -3730,22 +3756,22 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/6.0.0" + "source": "https://github.com/utopia-php/database/tree/6.4.3" }, - "time": "2026-06-18T10:37:40+00:00" + "time": "2026-07-13T13:24:23+00:00" }, { "name": "utopia-php/detector", - "version": "0.2.4", + "version": "0.2.6", "source": { "type": "git", "url": "https://github.com/utopia-php/detector.git", - "reference": "a564381108518ce6d18b6ab441f1448bd8355afd" + "reference": "2b2744be7ea028307dc9352eeec109cd1f9ab2d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/detector/zipball/a564381108518ce6d18b6ab441f1448bd8355afd", - "reference": "a564381108518ce6d18b6ab441f1448bd8355afd", + "url": "https://api.github.com/repos/utopia-php/detector/zipball/2b2744be7ea028307dc9352eeec109cd1f9ab2d3", + "reference": "2b2744be7ea028307dc9352eeec109cd1f9ab2d3", "shasum": "" }, "require": { @@ -3775,22 +3801,22 @@ ], "support": { "issues": "https://github.com/utopia-php/detector/issues", - "source": "https://github.com/utopia-php/detector/tree/0.2.4" + "source": "https://github.com/utopia-php/detector/tree/0.2.6" }, - "time": "2026-02-17T11:26:34+00:00" + "time": "2026-07-01T14:00:11+00:00" }, { "name": "utopia-php/di", - "version": "0.3.3", + "version": "0.3.5", "source": { "type": "git", "url": "https://github.com/utopia-php/di.git", - "reference": "a0cee7ff9976bb6b596619aeac524948a8ee3dfb" + "reference": "053ebd097963190c5b279d66c5b530acb584d8c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/di/zipball/a0cee7ff9976bb6b596619aeac524948a8ee3dfb", - "reference": "a0cee7ff9976bb6b596619aeac524948a8ee3dfb", + "url": "https://api.github.com/repos/utopia-php/di/zipball/053ebd097963190c5b279d66c5b530acb584d8c0", + "reference": "053ebd097963190c5b279d66c5b530acb584d8c0", "shasum": "" }, "require": { @@ -3823,9 +3849,9 @@ ], "support": { "issues": "https://github.com/utopia-php/di/issues", - "source": "https://github.com/utopia-php/di/tree/0.3.3" + "source": "https://github.com/utopia-php/di/tree/0.3.5" }, - "time": "2026-06-10T14:22:41+00:00" + "time": "2026-06-26T10:48:18+00:00" }, { "name": "utopia-php/dns", @@ -3886,16 +3912,16 @@ }, { "name": "utopia-php/domains", - "version": "2.2.0", + "version": "2.3.0", "source": { "type": "git", "url": "https://github.com/utopia-php/domains.git", - "reference": "77fcf4b63e33b2c1ddf8c67cfc1a57eef2dbec8f" + "reference": "73bb46ec7c7522c8a0a1e7311144bdea1a7480cd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/domains/zipball/77fcf4b63e33b2c1ddf8c67cfc1a57eef2dbec8f", - "reference": "77fcf4b63e33b2c1ddf8c67cfc1a57eef2dbec8f", + "url": "https://api.github.com/repos/utopia-php/domains/zipball/73bb46ec7c7522c8a0a1e7311144bdea1a7480cd", + "reference": "73bb46ec7c7522c8a0a1e7311144bdea1a7480cd", "shasum": "" }, "require": { @@ -3942,9 +3968,9 @@ ], "support": { "issues": "https://github.com/utopia-php/domains/issues", - "source": "https://github.com/utopia-php/domains/tree/2.2.0" + "source": "https://github.com/utopia-php/domains/tree/2.3.0" }, - "time": "2026-05-28T15:16:46+00:00" + "time": "2026-07-06T03:50:24+00:00" }, { "name": "utopia-php/dsn", @@ -4096,25 +4122,27 @@ }, { "name": "utopia-php/http", - "version": "2.0.0-rc9", + "version": "2.0.0-rc18", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "e4fdbc57ac6dc7cad1604eb904d3c95a31226ba9" + "reference": "3bfc500c6a53ffb87d4dcb95b4712b6a91b24439" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/e4fdbc57ac6dc7cad1604eb904d3c95a31226ba9", - "reference": "e4fdbc57ac6dc7cad1604eb904d3c95a31226ba9", + "url": "https://api.github.com/repos/utopia-php/http/zipball/3bfc500c6a53ffb87d4dcb95b4712b6a91b24439", + "reference": "3bfc500c6a53ffb87d4dcb95b4712b6a91b24439", "shasum": "" }, "require": { - "php": ">=8.3", + "php": ">=8.5", "utopia-php/compression": "^0.1", "utopia-php/di": "^0.3", + "utopia-php/psr7": "^0.2.0", "utopia-php/servers": "^0.4", + "utopia-php/system": "^0.10", "utopia-php/telemetry": "^0.4", - "utopia-php/validators": "^0.2" + "utopia-php/validators": "0.3.*" }, "require-dev": { "swoole/ide-helper": "4.8.3" @@ -4141,22 +4169,22 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/2.0.0-rc9" + "source": "https://github.com/utopia-php/http/tree/2.0.0-rc18" }, - "time": "2026-06-10T16:25:51+00:00" + "time": "2026-07-13T16:18:22+00:00" }, { "name": "utopia-php/image", - "version": "0.8.6", + "version": "0.8.7", "source": { "type": "git", "url": "https://github.com/utopia-php/image.git", - "reference": "85ab7027873e11bc901110d8f7830252247ba724" + "reference": "ed06c72998869f5d66026c7e4b7e1bcc1bbf45c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/image/zipball/85ab7027873e11bc901110d8f7830252247ba724", - "reference": "85ab7027873e11bc901110d8f7830252247ba724", + "url": "https://api.github.com/repos/utopia-php/image/zipball/ed06c72998869f5d66026c7e4b7e1bcc1bbf45c7", + "reference": "ed06c72998869f5d66026c7e4b7e1bcc1bbf45c7", "shasum": "" }, "require": { @@ -4192,9 +4220,9 @@ ], "support": { "issues": "https://github.com/utopia-php/image/issues", - "source": "https://github.com/utopia-php/image/tree/0.8.6" + "source": "https://github.com/utopia-php/image/tree/0.8.7" }, - "time": "2026-04-19T12:52:59+00:00" + "time": "2026-07-13T12:12:06+00:00" }, { "name": "utopia-php/locale", @@ -4245,16 +4273,16 @@ }, { "name": "utopia-php/lock", - "version": "0.2.1", + "version": "0.2.3", "source": { "type": "git", "url": "https://github.com/utopia-php/lock.git", - "reference": "9ef48d7094f5c68d1736f664f6e9b4b1ec656f21" + "reference": "4eca3784d4c112655faf77adcf0fdbb186650487" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/lock/zipball/9ef48d7094f5c68d1736f664f6e9b4b1ec656f21", - "reference": "9ef48d7094f5c68d1736f664f6e9b4b1ec656f21", + "url": "https://api.github.com/repos/utopia-php/lock/zipball/4eca3784d4c112655faf77adcf0fdbb186650487", + "reference": "4eca3784d4c112655faf77adcf0fdbb186650487", "shasum": "" }, "require": { @@ -4287,9 +4315,9 @@ "description": "A simple lock library to coordinate access to shared resources across coroutines, processes and hosts", "support": { "issues": "https://github.com/utopia-php/lock/issues", - "source": "https://github.com/utopia-php/lock/tree/0.2.1" + "source": "https://github.com/utopia-php/lock/tree/0.2.3" }, - "time": "2026-06-10T15:55:36+00:00" + "time": "2026-06-26T10:48:18+00:00" }, { "name": "utopia-php/logger", @@ -4348,30 +4376,34 @@ }, { "name": "utopia-php/messaging", - "version": "1.2.0", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/utopia-php/messaging.git", - "reference": "3419ffbbeb242b3232b588430bd465024959720c" + "reference": "8890c3b2e94bdf832c17fd3d7832cdf01b933eb7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/messaging/zipball/3419ffbbeb242b3232b588430bd465024959720c", - "reference": "3419ffbbeb242b3232b588430bd465024959720c", + "url": "https://api.github.com/repos/utopia-php/messaging/zipball/8890c3b2e94bdf832c17fd3d7832cdf01b933eb7", + "reference": "8890c3b2e94bdf832c17fd3d7832cdf01b933eb7", "shasum": "" }, "require": { "ext-curl": "*", "ext-openssl": "*", - "giggsey/libphonenumber-for-php-lite": "9.0.23", - "php": ">=8.1.0", - "phpmailer/phpmailer": "6.9.1", + "ext-swoole": "*", + "php": ">=8.5.0", + "phpmailer/phpmailer": "^6.9", + "psr/http-client": "^1.0", + "psr/http-message": "^1.1 || ^2.0", + "utopia-php/client": "^0.2", "utopia-php/telemetry": "^0.4" }, "require-dev": { - "laravel/pint": "1.*", - "phpstan/phpstan": "1.*", - "phpunit/phpunit": "11.*" + "laravel/pint": "^1.0", + "phpstan/phpstan": "^2.0", + "phpunit/phpunit": "^11.0", + "swoole/ide-helper": "^6.0" }, "type": "library", "autoload": { @@ -4394,9 +4426,9 @@ ], "support": { "issues": "https://github.com/utopia-php/messaging/issues", - "source": "https://github.com/utopia-php/messaging/tree/1.2.0" + "source": "https://github.com/utopia-php/messaging/tree/2.0.0" }, - "time": "2026-06-23T04:24:43+00:00" + "time": "2026-07-14T10:22:03+00:00" }, { "name": "utopia-php/migration", @@ -4473,16 +4505,16 @@ }, { "name": "utopia-php/mongo", - "version": "1.1.0", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/utopia-php/mongo.git", - "reference": "73593682deee4696525a04e26524c1c1226e1530" + "reference": "f6ef5f1cecf80fb0378eda13250d6c14096d7620" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/mongo/zipball/73593682deee4696525a04e26524c1c1226e1530", - "reference": "73593682deee4696525a04e26524c1c1226e1530", + "url": "https://api.github.com/repos/utopia-php/mongo/zipball/f6ef5f1cecf80fb0378eda13250d6c14096d7620", + "reference": "f6ef5f1cecf80fb0378eda13250d6c14096d7620", "shasum": "" }, "require": { @@ -4528,31 +4560,31 @@ ], "support": { "issues": "https://github.com/utopia-php/mongo/issues", - "source": "https://github.com/utopia-php/mongo/tree/1.1.0" + "source": "https://github.com/utopia-php/mongo/tree/1.3.1" }, - "time": "2026-04-24T06:15:10+00:00" + "time": "2026-07-14T15:22:52+00:00" }, { "name": "utopia-php/platform", - "version": "1.0.0-rc9", + "version": "1.0.0-rc14", "source": { "type": "git", "url": "https://github.com/utopia-php/platform.git", - "reference": "5ae1fba6d797ba617816a1a582d9c1b1d188a1bc" + "reference": "bf3f1266de7da2e9ce00d923df054057c1b2fbb4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/platform/zipball/5ae1fba6d797ba617816a1a582d9c1b1d188a1bc", - "reference": "5ae1fba6d797ba617816a1a582d9c1b1d188a1bc", + "url": "https://api.github.com/repos/utopia-php/platform/zipball/bf3f1266de7da2e9ce00d923df054057c1b2fbb4", + "reference": "bf3f1266de7da2e9ce00d923df054057c1b2fbb4", "shasum": "" }, "require": { "ext-json": "*", "ext-redis": "*", - "php": ">=8.3", + "php": ">=8.5", "utopia-php/cli": "^0.24", "utopia-php/http": "^2.0@RC", - "utopia-php/queue": "^0.21", + "utopia-php/queue": "^0.22", "utopia-php/servers": "^0.4" }, "type": "library", @@ -4575,22 +4607,22 @@ ], "support": { "issues": "https://github.com/utopia-php/platform/issues", - "source": "https://github.com/utopia-php/platform/tree/1.0.0-rc9" + "source": "https://github.com/utopia-php/platform/tree/1.0.0-rc14" }, - "time": "2026-06-11T10:36:26+00:00" + "time": "2026-07-13T15:07:08+00:00" }, { "name": "utopia-php/pools", - "version": "1.0.5", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/utopia-php/pools.git", - "reference": "e66e498d59cf3ac48c1f4c70be46f7eb6df7a63b" + "reference": "fd5aa7e89685ffc74f9dff3d23c270ef30c7bbf3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/pools/zipball/e66e498d59cf3ac48c1f4c70be46f7eb6df7a63b", - "reference": "e66e498d59cf3ac48c1f4c70be46f7eb6df7a63b", + "url": "https://api.github.com/repos/utopia-php/pools/zipball/fd5aa7e89685ffc74f9dff3d23c270ef30c7bbf3", + "reference": "fd5aa7e89685ffc74f9dff3d23c270ef30c7bbf3", "shasum": "" }, "require": { @@ -4601,7 +4633,10 @@ "swoole/ide-helper": "6.*" }, "suggest": { - "ext-swoole": "Required to use the Swoole pool adapter" + "ext-mongodb": "Needed to support MongoDB database pools", + "ext-pdo": "Needed to support MariaDB, MySQL or SQLite database pools", + "ext-redis": "Needed to support Redis cache pools", + "ext-swoole": "Needed to support Swoole based pool adapter" }, "type": "library", "autoload": { @@ -4628,9 +4663,9 @@ ], "support": { "issues": "https://github.com/utopia-php/pools/issues", - "source": "https://github.com/utopia-php/pools/tree/1.0.5" + "source": "https://github.com/utopia-php/pools/tree/1.1.0" }, - "time": "2026-06-10T15:14:31+00:00" + "time": "2026-07-17T10:19:09+00:00" }, { "name": "utopia-php/preloader", @@ -4685,6 +4720,52 @@ }, "time": "2020-10-24T07:04:59+00:00" }, + { + "name": "utopia-php/psr7", + "version": "0.2.0", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/psr7.git", + "reference": "115753c36194d53abe5587d383810724ac3a782d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/psr7/zipball/115753c36194d53abe5587d383810724ac3a782d", + "reference": "115753c36194d53abe5587d383810724ac3a782d", + "shasum": "" + }, + "require": { + "php": ">=8.4", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.1 || ^2.0" + }, + "suggest": { + "ext-simplexml": "Required to decode XML responses with Response::xml()." + }, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\Psr7\\": "src/Psr7/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PSR-7 HTTP message implementations and PSR-17 factories for Utopia", + "keywords": [ + "http", + "php", + "psr-17", + "psr-7", + "utopia" + ], + "support": { + "issues": "https://github.com/utopia-php/psr7/issues", + "source": "https://github.com/utopia-php/psr7/tree/0.2.0" + }, + "time": "2026-07-06T12:40:23+00:00" + }, { "name": "utopia-php/query", "version": "0.1.1", @@ -4733,26 +4814,26 @@ }, { "name": "utopia-php/queue", - "version": "0.21.1", + "version": "0.22.2", "source": { "type": "git", "url": "https://github.com/utopia-php/queue.git", - "reference": "abc5173ff7079118ebf5a22cb8008e8cf0a150e4" + "reference": "3081a1cd464e9bc92443e91e08d653bfdf45b54d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/queue/zipball/abc5173ff7079118ebf5a22cb8008e8cf0a150e4", - "reference": "abc5173ff7079118ebf5a22cb8008e8cf0a150e4", + "url": "https://api.github.com/repos/utopia-php/queue/zipball/3081a1cd464e9bc92443e91e08d653bfdf45b54d", + "reference": "3081a1cd464e9bc92443e91e08d653bfdf45b54d", "shasum": "" }, "require": { - "php": ">=8.4", + "php": ">=8.5", "utopia-php/di": "^0.3", "utopia-php/lock": "^0.2", "utopia-php/pools": "^1.0", "utopia-php/servers": "^0.4", "utopia-php/telemetry": "^0.4", - "utopia-php/validators": "^0.2" + "utopia-php/validators": "0.3.*" }, "require-dev": { "ext-redis": "*", @@ -4790,9 +4871,9 @@ ], "support": { "issues": "https://github.com/utopia-php/queue/issues", - "source": "https://github.com/utopia-php/queue/tree/0.21.1" + "source": "https://github.com/utopia-php/queue/tree/0.22.2" }, - "time": "2026-06-10T16:25:51+00:00" + "time": "2026-07-13T11:15:40+00:00" }, { "name": "utopia-php/registry", @@ -4848,22 +4929,22 @@ }, { "name": "utopia-php/servers", - "version": "0.4.3", + "version": "0.4.6", "source": { "type": "git", "url": "https://github.com/utopia-php/servers.git", - "reference": "a160268a804ae1a6d8a6ee41aed8dda1d2553da8" + "reference": "036c4da1c8b9a5bba1a973270158ba745a5944c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/a160268a804ae1a6d8a6ee41aed8dda1d2553da8", - "reference": "a160268a804ae1a6d8a6ee41aed8dda1d2553da8", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/036c4da1c8b9a5bba1a973270158ba745a5944c9", + "reference": "036c4da1c8b9a5bba1a973270158ba745a5944c9", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.5", "utopia-php/di": "^0.3", - "utopia-php/validators": "^0.2" + "utopia-php/validators": "0.3.*" }, "type": "library", "autoload": { @@ -4891,32 +4972,28 @@ ], "support": { "issues": "https://github.com/utopia-php/servers/issues", - "source": "https://github.com/utopia-php/servers/tree/0.4.3" + "source": "https://github.com/utopia-php/servers/tree/0.4.6" }, - "time": "2026-06-10T16:25:51+00:00" + "time": "2026-07-13T11:15:40+00:00" }, { "name": "utopia-php/span", - "version": "3.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/utopia-php/span.git", - "reference": "97f0ab6e9125c000262f8b5b007423d11fd1a9b3" + "reference": "6f9042c1ae1fa5a3e890b5c9a92cbf1388422945" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/span/zipball/97f0ab6e9125c000262f8b5b007423d11fd1a9b3", - "reference": "97f0ab6e9125c000262f8b5b007423d11fd1a9b3", + "url": "https://api.github.com/repos/utopia-php/span/zipball/6f9042c1ae1fa5a3e890b5c9a92cbf1388422945", + "reference": "6f9042c1ae1fa5a3e890b5c9a92cbf1388422945", "shasum": "" }, "require": { "php": ">=8.2" }, "require-dev": { - "laravel/pint": "^1.0", - "phpstan/phpstan": "^2.0", - "phpunit/phpunit": "^10.0", - "rector/rector": "^2.3", "swoole/ide-helper": "^5.0" }, "suggest": { @@ -4935,22 +5012,22 @@ "description": "Simple span tracing library for PHP with coroutine support", "support": { "issues": "https://github.com/utopia-php/span/issues", - "source": "https://github.com/utopia-php/span/tree/3.0.1" + "source": "https://github.com/utopia-php/span/tree/3.0.2" }, - "time": "2026-05-13T11:53:06+00:00" + "time": "2026-06-10T14:42:53+00:00" }, { "name": "utopia-php/storage", - "version": "2.0.5", + "version": "2.0.6", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "b8af52e8ae1f9e670b32255a8936bbb46634b711" + "reference": "00503ebecdae5e4c694889acf7777b1b4ca5d3d6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/b8af52e8ae1f9e670b32255a8936bbb46634b711", - "reference": "b8af52e8ae1f9e670b32255a8936bbb46634b711", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/00503ebecdae5e4c694889acf7777b1b4ca5d3d6", + "reference": "00503ebecdae5e4c694889acf7777b1b4ca5d3d6", "shasum": "" }, "require": { @@ -4958,10 +5035,10 @@ "ext-fileinfo": "*", "ext-simplexml": "*", "ext-zlib": "*", - "php": ">=8.1", + "php": ">=8.5", "utopia-php/system": "0.*.*", "utopia-php/telemetry": "^0.4", - "utopia-php/validators": "0.2.*" + "utopia-php/validators": "0.3.*" }, "require-dev": { "laravel/pint": "^1.21", @@ -4987,32 +5064,27 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/2.0.5" + "source": "https://github.com/utopia-php/storage/tree/2.0.6" }, - "time": "2026-06-03T05:21:46+00:00" + "time": "2026-07-13T13:40:39+00:00" }, { "name": "utopia-php/system", - "version": "0.10.2", + "version": "0.10.5", "source": { "type": "git", "url": "https://github.com/utopia-php/system.git", - "reference": "04229a822b147c1abaf1a92fb42c2d7aad4625df" + "reference": "57a2ab17f5346f171c796e29a6c2202bfaa21303" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/system/zipball/04229a822b147c1abaf1a92fb42c2d7aad4625df", - "reference": "04229a822b147c1abaf1a92fb42c2d7aad4625df", + "url": "https://api.github.com/repos/utopia-php/system/zipball/57a2ab17f5346f171c796e29a6c2202bfaa21303", + "reference": "57a2ab17f5346f171c796e29a6c2202bfaa21303", "shasum": "" }, "require": { "php": ">=8.0.0" }, - "require-dev": { - "laravel/pint": "1.13.*", - "phpstan/phpstan": "1.12.*", - "phpunit/phpunit": "9.6.*" - }, "type": "library", "autoload": { "psr-4": { @@ -5043,26 +5115,25 @@ ], "support": { "issues": "https://github.com/utopia-php/system/issues", - "source": "https://github.com/utopia-php/system/tree/0.10.2" + "source": "https://github.com/utopia-php/system/tree/0.10.5" }, - "time": "2026-05-05T14:33:41+00:00" + "time": "2026-06-26T10:48:18+00:00" }, { "name": "utopia-php/telemetry", - "version": "0.4.1", + "version": "0.4.5", "source": { "type": "git", "url": "https://github.com/utopia-php/telemetry.git", - "reference": "028f3a85bb987b1e9357fb1632aa40f020d1b86e" + "reference": "139943bffcd4f6dd8fb9ed247f946a1d151b006a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/telemetry/zipball/028f3a85bb987b1e9357fb1632aa40f020d1b86e", - "reference": "028f3a85bb987b1e9357fb1632aa40f020d1b86e", + "url": "https://api.github.com/repos/utopia-php/telemetry/zipball/139943bffcd4f6dd8fb9ed247f946a1d151b006a", + "reference": "139943bffcd4f6dd8fb9ed247f946a1d151b006a", "shasum": "" }, "require": { - "ext-opentelemetry": "*", "ext-protobuf": "*", "nyholm/psr7": "1.*", "open-telemetry/exporter-otlp": "1.*", @@ -5071,7 +5142,6 @@ "symfony/http-client": "7.*" }, "require-dev": { - "phpbench/phpbench": "1.*", "swoole/ide-helper": "6.*" }, "suggest": { @@ -5096,26 +5166,26 @@ ], "support": { "issues": "https://github.com/utopia-php/telemetry/issues", - "source": "https://github.com/utopia-php/telemetry/tree/0.4.1" + "source": "https://github.com/utopia-php/telemetry/tree/0.4.5" }, - "time": "2026-06-10T15:48:26+00:00" + "time": "2026-07-08T11:07:25+00:00" }, { "name": "utopia-php/validators", - "version": "0.2.6", + "version": "0.3.0", "source": { "type": "git", "url": "https://github.com/utopia-php/validators.git", - "reference": "f1ac4f08d6876daf117a1d9af53a4c7b752c2c0b" + "reference": "5a3ef67ce17c2e148da7895e8de699614f0afdfa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/validators/zipball/f1ac4f08d6876daf117a1d9af53a4c7b752c2c0b", - "reference": "f1ac4f08d6876daf117a1d9af53a4c7b752c2c0b", + "url": "https://api.github.com/repos/utopia-php/validators/zipball/5a3ef67ce17c2e148da7895e8de699614f0afdfa", + "reference": "5a3ef67ce17c2e148da7895e8de699614f0afdfa", "shasum": "" }, "require": { - "php": ">=8.0" + "php": ">=8.5" }, "type": "library", "autoload": { @@ -5136,22 +5206,22 @@ ], "support": { "issues": "https://github.com/utopia-php/validators/issues", - "source": "https://github.com/utopia-php/validators/tree/0.2.6" + "source": "https://github.com/utopia-php/validators/tree/0.3.0" }, - "time": "2026-06-10T14:45:13+00:00" + "time": "2026-07-13T09:46:33+00:00" }, { "name": "utopia-php/vcs", - "version": "4.2.3", + "version": "4.4.2", "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "598cbd2793a5a6394493f1046743e75ec6544a57" + "reference": "ea623171caeaad2ef600b6c6bd52fd5f76b38486" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/vcs/zipball/598cbd2793a5a6394493f1046743e75ec6544a57", - "reference": "598cbd2793a5a6394493f1046743e75ec6544a57", + "url": "https://api.github.com/repos/utopia-php/vcs/zipball/ea623171caeaad2ef600b6c6bd52fd5f76b38486", + "reference": "ea623171caeaad2ef600b6c6bd52fd5f76b38486", "shasum": "" }, "require": { @@ -5185,9 +5255,9 @@ ], "support": { "issues": "https://github.com/utopia-php/vcs/issues", - "source": "https://github.com/utopia-php/vcs/tree/4.2.3" + "source": "https://github.com/utopia-php/vcs/tree/4.4.2" }, - "time": "2026-06-16T12:14:08+00:00" + "time": "2026-07-14T06:22:41+00:00" }, { "name": "utopia-php/websocket", @@ -5380,16 +5450,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "2.0.0", + "version": "2.4.5", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "60a2e804c1464494d763e5ff6bfff9b188502253" + "reference": "ebdb3af8bee5669879644c262e704d83dbeb438a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/60a2e804c1464494d763e5ff6bfff9b188502253", - "reference": "60a2e804c1464494d763e5ff6bfff9b188502253", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/ebdb3af8bee5669879644c262e704d83dbeb438a", + "reference": "ebdb3af8bee5669879644c262e704d83dbeb438a", "shasum": "" }, "require": { @@ -5404,7 +5474,7 @@ "brianium/paratest": "7.*", "phpunit/phpunit": "11.*", "rector/rector": "^2.4", - "squizlabs/php_codesniffer": "3.*" + "squizlabs/php_codesniffer": "4.*" }, "type": "library", "autoload": { @@ -5426,9 +5496,9 @@ "description": "SDK generator for Appwrite APIs across multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/2.0.0" + "source": "https://github.com/appwrite/sdk-generator/tree/2.4.5" }, - "time": "2026-06-11T05:54:24+00:00" + "time": "2026-07-09T15:23:08+00:00" }, { "name": "brianium/paratest", @@ -8389,7 +8459,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": ">=8.3.0", + "php": ">=8.5.0", "ext-curl": "*", "ext-imagick": "*", "ext-mbstring": "*", diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index 01a98d71c0..62d734af9e 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -3,10 +3,12 @@ namespace Appwrite\Migration\Version; use Appwrite\Migration\Migration; +use Exception; use Throwable; use Utopia\Console; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Query; use Utopia\Migration\Resource; class V25 extends Migration @@ -24,51 +26,127 @@ class V25 extends Migration } /** - * @throws Throwable + * Migrate Collections. + * + * @return void + * @throws Exception|Throwable */ private function migrateCollections(): void { - if ($this->project->getSequence() === 'console') { - return; + $projectInternalId = $this->project->getSequence(); + + if (empty($projectInternalId)) { + throw new Exception('Project ID is null'); } - $id = 'migrations'; + $collectionType = match ($projectInternalId) { + 'console' => 'console', + default => 'projects', + }; - $this->dbForProject->purgeCachedCollection($id); - $this->dbForProject->purgeCachedDocument(Database::METADATA, $id); + $collections = $this->collections[$collectionType]; - $attributes = [ - 'resourceInternalId', - 'parentResourceId', - 'parentResourceInternalId', - 'parentResourceType', - 'destinationResourceId', - 'destinationResourceType', - ]; - try { - $this->createAttributesFromCollection($this->dbForProject, $id, $attributes); - } catch (Throwable $th) { - Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}"); - } + foreach ($collections as $collection) { + $id = $collection['$id']; - $indexes = [ - '_key_resourceType', - '_key_resourceInternalId', - '_key_parentResourceId', - '_key_parentResourceType', - '_key_parentResourceInternalId', - '_key_destinationResourceId', - '_key_destinationResourceType', - ]; - foreach ($indexes as $index) { - try { - $this->createIndexFromCollection($this->dbForProject, $id, $index); - } catch (Throwable $th) { - Console::warning("Failed to create index \"{$index}\" from {$id}: {$th->getMessage()}"); + if (empty($id)) { + continue; + } + + Console::log("Migrating collection \"{$id}\""); + + $this->dbForProject->purgeCachedCollection($id); + $this->dbForProject->purgeCachedDocument(Database::METADATA, $id); + + switch ($id) { + case 'projects': + if ($collectionType === 'console') { + try { + $this->createIndexFromCollection($this->dbForProject, $id, '_key_accessedAt'); + } catch (Throwable $th) { + Console::warning("Failed to create index \"_key_accessedAt\" from {$id}: {$th->getMessage()}"); + } + } + $this->dbForProject->purgeCachedCollection($id); + break; + + case 'installations': + if ($collectionType === 'console') { + foreach (['personalAccessToken', 'personalRefreshToken'] as $attribute) { + try { + $this->dbForProject->updateAttribute($id, $attribute, size: 2048); + } catch (Throwable $th) { + Console::warning("Failed to resize attribute \"{$attribute}\" in collection {$id}: {$th->getMessage()}"); + } + } + } + $this->dbForProject->purgeCachedCollection($id); + break; + + case 'databases': + if ($collectionType === 'projects') { + try { + $this->createAttributeFromCollection($this->dbForProject, $id, 'status'); + } catch (Throwable $th) { + Console::warning("Failed to create attribute \"status\" in collection {$id}: {$th->getMessage()}"); + } + $this->dbForProject->purgeCachedCollection($id); + + // Backfill existing databases so the stored value matches the intended default. + // Materialize the matched documents before updating any of them: updating + // "status" removes rows from the isNull() set, and the offset-based iterator + // would otherwise skip un-processed rows as the filtered set shrinks mid-scan. + $databases = \iterator_to_array($this->documentsIterator($id, [Query::isNull('status')])); + foreach ($databases as $database) { + try { + $this->dbForProject->updateDocument($id, $database->getId(), new Document([ + 'status' => 'ready', + ])); + } catch (Throwable $th) { + Console::warning("Failed to backfill \"status\" for database {$database->getId()}: {$th->getMessage()}"); + } + } + } + break; + + case 'migrations': + if ($collectionType === 'projects') { + $attributes = [ + 'resourceInternalId', + 'parentResourceId', + 'parentResourceInternalId', + 'parentResourceType', + 'destinationResourceId', + 'destinationResourceType', + ]; + try { + $this->createAttributesFromCollection($this->dbForProject, $id, $attributes); + } catch (Throwable $th) { + Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}"); + } + + $indexes = [ + '_key_resourceType', + '_key_resourceInternalId', + '_key_parentResourceId', + '_key_parentResourceType', + '_key_parentResourceInternalId', + '_key_destinationResourceId', + '_key_destinationResourceType', + ]; + foreach ($indexes as $index) { + try { + $this->createIndexFromCollection($this->dbForProject, $id, $index); + } catch (Throwable $th) { + Console::warning("Failed to create index \"{$index}\" from {$id}: {$th->getMessage()}"); + } + } + + $this->dbForProject->purgeCachedCollection($id); + } + break; } } - - $this->dbForProject->purgeCachedCollection($id); } protected function migrateDocument(Document $document): Document diff --git a/src/Appwrite/Utopia/Request/Filters/V27.php b/src/Appwrite/Utopia/Request/Filters/V27.php index 58baf8a1a5..3b4c427732 100644 --- a/src/Appwrite/Utopia/Request/Filters/V27.php +++ b/src/Appwrite/Utopia/Request/Filters/V27.php @@ -6,7 +6,7 @@ use Appwrite\Utopia\Request\Filter; class V27 extends Filter { - // Convert 1.9.5 params to 1.9.6 + // Convert 1.9.5 params to 2.0.0 public function parse(array $content, string $model): array { return match ($model) { diff --git a/src/Appwrite/Utopia/Response/Filters/V27.php b/src/Appwrite/Utopia/Response/Filters/V27.php index 57bad7171e..258dd56ffc 100644 --- a/src/Appwrite/Utopia/Response/Filters/V27.php +++ b/src/Appwrite/Utopia/Response/Filters/V27.php @@ -5,7 +5,7 @@ namespace Appwrite\Utopia\Response\Filters; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Filter; -// Convert 1.9.6 data format to 1.9.5 format +// Convert 2.0.0 Data format to 1.9.5 format class V27 extends Filter { public function parse(array $content, string $model): array From 065c5b02c1bf446e6830c2178739f838ce0956c9 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 20 Jul 2026 22:01:14 +1200 Subject: [PATCH 08/14] chore(deps): consume utopia-php/migration 1.18.0 release Replaces the dev-branch VCS pin now that feat/drop-compound-resource-id shipped in the 1.18.0 tag. Co-Authored-By: Claude Fable 5 --- composer.json | 11 +++-------- composer.lock | 46 ++++++++++------------------------------------ 2 files changed, 13 insertions(+), 44 deletions(-) diff --git a/composer.json b/composer.json index 228d754f57..cc575b2408 100644 --- a/composer.json +++ b/composer.json @@ -41,10 +41,6 @@ { "type": "vcs", "url": "https://github.com/utopia-php/auth" - }, - { - "type": "vcs", - "url": "https://github.com/utopia-php/migration" } ], "require": { @@ -87,7 +83,7 @@ "utopia-php/lock": "0.2.*", "utopia-php/logger": "0.8.*", "utopia-php/messaging": "^2.0", - "utopia-php/migration": "dev-feat/drop-compound-resource-id#7ed62ca2e2279bf30fa2018655e045c59bb5bc3d as 1.17.3", + "utopia-php/migration": "^1.18.0", "utopia-php/platform": "^1.0@RC", "utopia-php/pools": "1.*", "utopia-php/span": "3.0.*", @@ -128,11 +124,10 @@ "ext-phpiredis": "*" }, "config": { - "platform": { - }, + "platform": {}, "allow-plugins": { "php-http/discovery": true, "tbachert/spi": true } } -} +} \ No newline at end of file diff --git a/composer.lock b/composer.lock index c3b90792c9..7febf8d75b 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": "de6d55bb252b6063fe98964392cbc80a", + "content-hash": "56ff11d19729a2d94b5936e8b942a610", "packages": [ { "name": "adhocore/jwt", @@ -4432,16 +4432,16 @@ }, { "name": "utopia-php/migration", - "version": "dev-feat/drop-compound-resource-id", + "version": "1.18.0", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "7ed62ca2e2279bf30fa2018655e045c59bb5bc3d" + "reference": "b531ea43293fde5ceb72c29d312489aa0ded0c83" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/7ed62ca2e2279bf30fa2018655e045c59bb5bc3d", - "reference": "7ed62ca2e2279bf30fa2018655e045c59bb5bc3d", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/b531ea43293fde5ceb72c29d312489aa0ded0c83", + "reference": "b531ea43293fde5ceb72c29d312489aa0ded0c83", "shasum": "" }, "require": { @@ -4467,25 +4467,7 @@ "Utopia\\Migration\\": "src/Migration" } }, - "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" - ] - }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -4498,10 +4480,10 @@ "utopia" ], "support": { - "source": "https://github.com/utopia-php/migration/tree/feat/drop-compound-resource-id", - "issues": "https://github.com/utopia-php/migration/issues" + "issues": "https://github.com/utopia-php/migration/issues", + "source": "https://github.com/utopia-php/migration/tree/1.18.0" }, - "time": "2026-07-17T20:50:27+00:00" + "time": "2026-07-20T10:00:12+00:00" }, { "name": "utopia-php/mongo", @@ -8442,18 +8424,10 @@ "time": "2026-05-30T17:09:26+00:00" } ], - "aliases": [ - { - "package": "utopia-php/migration", - "version": "dev-feat/drop-compound-resource-id", - "alias": "1.17.3", - "alias_normalized": "1.17.3.0" - } - ], + "aliases": [], "minimum-stability": "dev", "stability-flags": { "utopia-php/http": 5, - "utopia-php/migration": 20, "utopia-php/platform": 5 }, "prefer-stable": true, From aa9be97ca41aab7199b9c4fa08d582f327b204d9 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 20 Jul 2026 21:47:56 +1200 Subject: [PATCH 09/14] (refactor): pass canonical migration resource context --- src/Appwrite/Platform/Workers/Migrations.php | 74 ++++++++++--------- .../unit/Platform/Workers/MigrationsTest.php | 42 +++++++++++ 2 files changed, 81 insertions(+), 35 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 3be60e67b7..40d0843bd4 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -342,7 +342,7 @@ class Migrations extends Action databaseId: $databaseId, tableId: $tableId, directory: $options['bucketId'], - filename: $options['filename'], + filename: $migration->getId(), allowedColumns: $options['columns'], delimiter: $options['delimiter'], enclosure: $options['enclosure'], @@ -354,7 +354,7 @@ class Migrations extends Action databaseId: $databaseId, tableId: $tableId, directory: $options['bucketId'] ?? 'default', - filename: $options['filename'], + filename: $migration->getId(), allowedColumns: $options['columns'] ?? [], ), default => throw new Exception(Exception::MIGRATION_DESTINATION_TYPE_INVALID), @@ -540,11 +540,7 @@ class Migrations extends Action $migration->setAttribute('stage', 'migrating'); $this->updateMigrationDocument($migration, $project, $queueForRealtime); - [$rootResourceId, $rootResourceChildId] = $this->resolveResourceIds($migration); - $rootResourceType = (string) ( - $migration->getAttribute('parentResourceType') - ?: $migration->getAttribute('resourceType') - ); + $context = $this->resolveResourceContext($migration); $transfer->runWithResourceSelector( $migration->getAttribute('resources'), function ($resources) use ($migration, $transfer, $project, $queueForRealtime, &$aggregatedResources) { @@ -583,9 +579,12 @@ class Migrations extends Action } $this->updateMigrationDocument($migration, $project, $queueForRealtime); }, - $rootResourceId, - $rootResourceType, - $rootResourceChildId, + resourceId: $context['resourceId'], + resourceInternalId: $context['resourceInternalId'], + resourceType: $context['resourceType'], + parentResourceId: $context['parentResourceId'], + parentResourceInternalId: $context['parentResourceInternalId'], + parentResourceType: $context['parentResourceType'], ); $destination->shutdown(); @@ -730,38 +729,43 @@ class Migrations extends Action return ($this->getDatabasesDB)($database); } - /** - * Resolve [rootResourceId, rootResourceChildId] from a migration document. - * - * Returns the root resource ID (e.g. databaseId for CSV/JSON or backup - * migrations) and an optional child filter under that root (the - * collection/table ID for CSV/JSON migrations). Three input shapes: - * - * - 1.9.4 CSV/JSON migration: parentResourceId is set to the root, - * resourceId is the leaf. Returns [parent, leaf]. - * - Pre-1.9.4 CSV/JSON migration (V25 not yet run, queue drain after - * upgrade, restored backup): resourceId is the composite - * "{databaseId}:{tableId}", parentResourceId is empty. Split it. - * - Single-root migration (Backup, full Appwrite/Supabase/Firebase/ - * NHost imports): resourceId is the root resource ID with no leaf. - * Returns [root, '']. - * - * @return array{0: string, 1: string} - */ + /** @return array{0: string, 1: string} */ protected function resolveResourceIds(Document $migration): array { - $parent = (string) $migration->getAttribute('parentResourceId', ''); - $resource = (string) $migration->getAttribute('resourceId', ''); + $context = $this->resolveResourceContext($migration); - if ($parent !== '') { - return [$parent, $resource]; + if ($context['parentResourceId'] !== '') { + return [$context['parentResourceId'], $context['resourceId']]; } - if (\str_contains($resource, ':')) { - return \explode(':', $resource, 2); + return [$context['resourceId'], '']; + } + + /** + * @return array{resourceId: string, resourceInternalId: string, resourceType: string, parentResourceId: string, parentResourceInternalId: string, parentResourceType: string} + */ + protected function resolveResourceContext(Document $migration): array + { + $context = [ + 'resourceId' => (string) $migration->getAttribute('resourceId', ''), + 'resourceInternalId' => (string) $migration->getAttribute('resourceInternalId', ''), + 'resourceType' => (string) $migration->getAttribute('resourceType', ''), + 'parentResourceId' => (string) $migration->getAttribute('parentResourceId', ''), + 'parentResourceInternalId' => (string) $migration->getAttribute('parentResourceInternalId', ''), + 'parentResourceType' => (string) $migration->getAttribute('parentResourceType', ''), + ]; + + if ( + $context['parentResourceId'] === '' + && \array_key_exists($context['resourceType'], Resource::DATABASE_TYPE_RESOURCE_MAP) + && \str_contains($context['resourceId'], ':') + ) { + [$context['parentResourceId'], $context['resourceId']] = \explode(':', $context['resourceId'], 2); + $context['parentResourceType'] = $context['resourceType']; + $context['resourceType'] = Resource::TYPE_COLLECTION; } - return [$resource, '']; + return $context; } /** diff --git a/tests/unit/Platform/Workers/MigrationsTest.php b/tests/unit/Platform/Workers/MigrationsTest.php index af75e2922b..b4431a49a8 100644 --- a/tests/unit/Platform/Workers/MigrationsTest.php +++ b/tests/unit/Platform/Workers/MigrationsTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Utopia\Database\Document; use Utopia\Database\Validator\Authorization; use Utopia\Migration\Destination; +use Utopia\Migration\Resource; use Utopia\Migration\Source; use Utopia\Queue\Publisher; use Utopia\Queue\Queue; @@ -144,6 +145,47 @@ final class MigrationsTest extends TestCase ], $events); } + public function testResourceContextUsesCanonicalRelationFields(): void + { + $worker = new class () extends Migrations { + /** + * @return array{resourceId: string, resourceInternalId: string, resourceType: string, parentResourceId: string, parentResourceInternalId: string, parentResourceType: string} + */ + public function context(Document $migration): array + { + return $this->resolveResourceContext($migration); + } + }; + + $this->assertSame([ + 'resourceId' => 'table-a', + 'resourceInternalId' => '201', + 'resourceType' => Resource::TYPE_COLLECTION, + 'parentResourceId' => 'database-a', + 'parentResourceInternalId' => '101', + 'parentResourceType' => Resource::TYPE_DATABASE, + ], $worker->context(new Document([ + 'resourceId' => 'table-a', + 'resourceInternalId' => '201', + 'resourceType' => Resource::TYPE_COLLECTION, + 'parentResourceId' => 'database-a', + 'parentResourceInternalId' => '101', + 'parentResourceType' => Resource::TYPE_DATABASE, + ]))); + + $this->assertSame([ + 'resourceId' => 'table-a', + 'resourceInternalId' => '', + 'resourceType' => Resource::TYPE_COLLECTION, + 'parentResourceId' => 'database-a', + 'parentResourceInternalId' => '', + 'parentResourceType' => Resource::TYPE_DATABASE, + ], $worker->context(new Document([ + 'resourceId' => 'database-a:table-a', + 'resourceType' => Resource::TYPE_DATABASE, + ]))); + } + private function createSourceMock(): Source&MockObject { $target = $this->createMock(Source::class); From 22800b14d91714d5d8f3a2a91a36e30f1b34f809 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 20 Jul 2026 22:38:30 +1200 Subject: [PATCH 10/14] (feat): expose migration destination generations --- app/config/collections/projects.php | 18 +++++++++ src/Appwrite/Migration/Version/V25.php | 38 ++++++++++++++++--- .../Http/Migrations/CSV/Imports/Create.php | 1 + .../Http/Migrations/JSON/Imports/Create.php | 1 + .../Database/Validator/Queries/Migrations.php | 3 ++ src/Appwrite/Utopia/Response/Filters/V27.php | 1 + .../Utopia/Response/Model/Migration.php | 7 ++++ .../Services/Migrations/MigrationsBase.php | 4 +- tests/unit/Migration/Version/V25Test.php | 29 +++++++++++++- .../Validator/Queries/MigrationsTest.php | 33 ++++++++++++++++ .../unit/Utopia/Response/Filters/V27Test.php | 3 ++ 11 files changed, 129 insertions(+), 9 deletions(-) create mode 100644 tests/unit/Utopia/Database/Validator/Queries/MigrationsTest.php diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index 052103c9ac..9c806696cb 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -2333,6 +2333,17 @@ return [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('destinationResourceInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('destinationResourceType'), 'type' => Database::VAR_STRING, @@ -2416,6 +2427,13 @@ return [ 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], + [ + '$id' => '_key_destinationResourceInternalId', + 'type' => Database::INDEX_KEY, + 'attributes' => ['destinationResourceInternalId'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], [ '$id' => '_key_destinationResourceType', 'type' => Database::INDEX_KEY, diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index 62d734af9e..759a3d0794 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -117,6 +117,7 @@ class V25 extends Migration 'parentResourceInternalId', 'parentResourceType', 'destinationResourceId', + 'destinationResourceInternalId', 'destinationResourceType', ]; try { @@ -132,6 +133,7 @@ class V25 extends Migration '_key_parentResourceType', '_key_parentResourceInternalId', '_key_destinationResourceId', + '_key_destinationResourceInternalId', '_key_destinationResourceType', ]; foreach ($indexes as $index) { @@ -178,7 +180,7 @@ class V25 extends Migration return $document; } - $internalIds = $this->resolveInternalIds($parentResourceId, $resourceId, $document->getId()); + $internalIds = $this->resolveInternalIds($parentResourceId, $resourceId, $document); if ( $split && (!isset($internalIds['parentResourceInternalId']) || !isset($internalIds['resourceInternalId'])) @@ -216,15 +218,19 @@ class V25 extends Migration /** * @return array{parentResourceInternalId?: string, resourceInternalId?: string} */ - protected function resolveInternalIds(string $parentResourceId, string $resourceId, string $migrationId): array + protected function resolveInternalIds(string $parentResourceId, string $resourceId, Document $migration): array { try { $database = $this->dbForProject->getDocument('databases', $parentResourceId); - if ($database->isEmpty() || $database->getSequence() === '') { + if ( + $database->isEmpty() + || $database->getSequence() === '' + || !$this->predatesMigration($database, $migration) + ) { return []; } } catch (Throwable $th) { - Console::warning("Failed to resolve parent internal ID for migration {$migrationId}: {$th->getMessage()}"); + Console::warning("Failed to resolve parent internal ID for migration {$migration->getId()}: {$th->getMessage()}"); return []; } @@ -234,13 +240,33 @@ class V25 extends Migration try { $resource = $this->dbForProject->getDocument('database_' . $database->getSequence(), $resourceId); - if (!$resource->isEmpty() && $resource->getSequence() !== '') { + if ( + !$resource->isEmpty() + && $resource->getSequence() !== '' + && $this->predatesMigration($resource, $migration) + ) { $internalIds['resourceInternalId'] = (string) $resource->getSequence(); } } catch (Throwable $th) { - Console::warning("Failed to resolve resource internal ID for migration {$migrationId}: {$th->getMessage()}"); + Console::warning("Failed to resolve resource internal ID for migration {$migration->getId()}: {$th->getMessage()}"); } return $internalIds; } + + /** + * A resource created after the migration is a reused public ID, not the + * generation the historical migration operated on. + */ + protected function predatesMigration(Document $resource, Document $migration): bool + { + $resourceCreatedAt = \strtotime($resource->getCreatedAt()); + $migrationCreatedAt = \strtotime($migration->getCreatedAt()); + + if ($resourceCreatedAt === false || $migrationCreatedAt === false) { + return false; + } + + return $resourceCreatedAt <= $migrationCreatedAt; + } } 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 7dddb7b575..61b1298fd9 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 @@ -197,6 +197,7 @@ class Create extends Action 'parentResourceInternalId' => $database->getSequence(), 'parentResourceType' => $parentResourceType, 'destinationResourceId' => $database->getId(), + 'destinationResourceInternalId' => $database->getSequence(), 'destinationResourceType' => $parentResourceType, 'statusCounters' => '{}', 'resourceData' => '{}', 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 06101e8565..4bcba3edb3 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 @@ -193,6 +193,7 @@ class Create extends Action 'parentResourceInternalId' => $database->getSequence(), 'parentResourceType' => $parentResourceType, 'destinationResourceId' => $database->getId(), + 'destinationResourceInternalId' => $database->getSequence(), 'destinationResourceType' => $parentResourceType, 'statusCounters' => '{}', 'resourceData' => '{}', diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Migrations.php b/src/Appwrite/Utopia/Database/Validator/Queries/Migrations.php index a146c39d10..0d5e2f28ca 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Migrations.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Migrations.php @@ -11,10 +11,13 @@ class Migrations extends Base 'destination', 'resources', 'resourceId', + 'resourceInternalId', 'resourceType', 'parentResourceId', + 'parentResourceInternalId', 'parentResourceType', 'destinationResourceId', + 'destinationResourceInternalId', 'destinationResourceType', 'statusCounters', 'resourceData', diff --git a/src/Appwrite/Utopia/Response/Filters/V27.php b/src/Appwrite/Utopia/Response/Filters/V27.php index 258dd56ffc..e0cf53ea3f 100644 --- a/src/Appwrite/Utopia/Response/Filters/V27.php +++ b/src/Appwrite/Utopia/Response/Filters/V27.php @@ -36,6 +36,7 @@ class V27 extends Filter unset($content['parentResourceInternalId']); unset($content['parentResourceType']); unset($content['destinationResourceId']); + unset($content['destinationResourceInternalId']); unset($content['destinationResourceType']); return $content; diff --git a/src/Appwrite/Utopia/Response/Model/Migration.php b/src/Appwrite/Utopia/Response/Model/Migration.php index 49463b0c9a..e6a15cff37 100644 --- a/src/Appwrite/Utopia/Response/Model/Migration.php +++ b/src/Appwrite/Utopia/Response/Model/Migration.php @@ -109,6 +109,13 @@ class Migration extends Model 'example' => 'databaseId', 'array' => false ]) + ->addRule('destinationResourceInternalId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Internal ID of the destination resource created or overwritten by the migration.', + 'default' => '', + 'example' => '1', + 'array' => false + ]) ->addRule('destinationResourceType', [ 'type' => self::TYPE_STRING, 'description' => 'Type of the destination resource created or overwritten by the migration.', diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index c440fa32ce..65a96694f0 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -3855,8 +3855,10 @@ trait MigrationsBase $this->assertNotNull($migration); $this->assertSame($data['tableId'], $migration['resourceId']); $this->assertSame($databaseId, $migration['parentResourceId']); + $this->assertNotSame('', $migration['parentResourceInternalId']); $this->assertSame(Resource::TYPE_DATABASE, $migration['parentResourceType']); $this->assertSame($databaseId, $migration['destinationResourceId']); + $this->assertSame($migration['parentResourceInternalId'], $migration['destinationResourceInternalId']); $this->assertSame(Resource::TYPE_DATABASE, $migration['destinationResourceType']); $response = $this->client->call(Client::METHOD_GET, '/migrations', array_merge([ @@ -3864,7 +3866,7 @@ trait MigrationsBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::equal('destinationResourceId', [$databaseId])->toString(), + Query::equal('destinationResourceInternalId', [$migration['destinationResourceInternalId']])->toString(), Query::equal('destinationResourceType', [Resource::TYPE_DATABASE])->toString(), ], ]); diff --git a/tests/unit/Migration/Version/V25Test.php b/tests/unit/Migration/Version/V25Test.php index f09736e87f..d95805a13c 100644 --- a/tests/unit/Migration/Version/V25Test.php +++ b/tests/unit/Migration/Version/V25Test.php @@ -24,7 +24,7 @@ final class V25Test extends TestCase } #[\Override] - protected function resolveInternalIds(string $parentResourceId, string $resourceId, string $migrationId): array + protected function resolveInternalIds(string $parentResourceId, string $resourceId, Document $migration): array { return []; } @@ -75,7 +75,7 @@ final class V25Test extends TestCase * @return array{parentResourceInternalId?: string, resourceInternalId?: string} */ #[\Override] - protected function resolveInternalIds(string $parentResourceId, string $resourceId, string $migrationId): array + protected function resolveInternalIds(string $parentResourceId, string $resourceId, Document $migration): array { return $this->internalIds; } @@ -116,4 +116,29 @@ final class V25Test extends TestCase $this->assertSame(Resource::TYPE_DATABASE, $document->getAttribute('parentResourceType')); $this->assertSame($afterResolution, $document->getArrayCopy()); } + + public function testRejectsResourcesCreatedAfterMigration(): void + { + $migration = new class () extends V25 { + public function __construct() + { + } + + public function isCandidate(Document $resource, Document $migration): bool + { + return $this->predatesMigration($resource, $migration); + } + }; + $document = new Document([ + '$createdAt' => '2026-01-02T00:00:00.000+00:00', + ]); + + $this->assertTrue($migration->isCandidate(new Document([ + '$createdAt' => '2026-01-01T00:00:00.000+00:00', + ]), $document)); + $this->assertFalse($migration->isCandidate(new Document([ + '$createdAt' => '2026-01-03T00:00:00.000+00:00', + ]), $document)); + $this->assertFalse($migration->isCandidate(new Document(), $document)); + } } diff --git a/tests/unit/Utopia/Database/Validator/Queries/MigrationsTest.php b/tests/unit/Utopia/Database/Validator/Queries/MigrationsTest.php new file mode 100644 index 0000000000..80c8c41f1e --- /dev/null +++ b/tests/unit/Utopia/Database/Validator/Queries/MigrationsTest.php @@ -0,0 +1,33 @@ +assertTrue($validator->isValid([$query]), $validator->getDescription()); + } + } +} diff --git a/tests/unit/Utopia/Response/Filters/V27Test.php b/tests/unit/Utopia/Response/Filters/V27Test.php index e2420ae332..fe03dac7d9 100644 --- a/tests/unit/Utopia/Response/Filters/V27Test.php +++ b/tests/unit/Utopia/Response/Filters/V27Test.php @@ -23,6 +23,7 @@ final class V27Test extends TestCase 'parentResourceInternalId' => '10', 'parentResourceType' => 'database', 'destinationResourceId' => 'destination', + 'destinationResourceInternalId' => '30', 'destinationResourceType' => 'database', ], Response::MODEL_MIGRATION); @@ -46,6 +47,7 @@ final class V27Test extends TestCase 'parentResourceInternalId' => '', 'parentResourceType' => '', 'destinationResourceId' => '', + 'destinationResourceInternalId' => '', 'destinationResourceType' => '', ], Response::MODEL_MIGRATION); @@ -69,6 +71,7 @@ final class V27Test extends TestCase 'parentResourceId' => 'database', 'parentResourceType' => 'database', 'destinationResourceId' => 'destination', + 'destinationResourceInternalId' => '30', 'destinationResourceType' => 'database', ]], ], Response::MODEL_MIGRATION_LIST); From 1d94059ce3ea03667daf0b7a2def4c4aa3156b8d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 20 Jul 2026 22:46:48 +1200 Subject: [PATCH 11/14] (fix): backfill null migration generation IDs --- src/Appwrite/Migration/Version/V25.php | 4 ++-- tests/unit/Migration/Version/V25Test.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index 759a3d0794..05b1142be2 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -200,13 +200,13 @@ class V25 extends Migration } if ( - $document->getAttribute('parentResourceInternalId', '') === '' + (string) $document->getAttribute('parentResourceInternalId', '') === '' && isset($internalIds['parentResourceInternalId']) ) { $document->setAttribute('parentResourceInternalId', $internalIds['parentResourceInternalId']); } if ( - $document->getAttribute('resourceInternalId', '') === '' + (string) $document->getAttribute('resourceInternalId', '') === '' && isset($internalIds['resourceInternalId']) ) { $document->setAttribute('resourceInternalId', $internalIds['resourceInternalId']); diff --git a/tests/unit/Migration/Version/V25Test.php b/tests/unit/Migration/Version/V25Test.php index d95805a13c..fadb5609e0 100644 --- a/tests/unit/Migration/Version/V25Test.php +++ b/tests/unit/Migration/Version/V25Test.php @@ -33,7 +33,9 @@ final class V25Test extends TestCase '$id' => 'migration', '$collection' => 'migrations', 'resourceId' => 'database:collection', + 'resourceInternalId' => null, 'resourceType' => Resource::TYPE_DATABASE, + 'parentResourceInternalId' => null, ]); $result = $migration->migrate($document); @@ -84,7 +86,9 @@ final class V25Test extends TestCase '$id' => 'migration', '$collection' => 'migrations', 'resourceId' => 'database:collection', + 'resourceInternalId' => null, 'resourceType' => Resource::TYPE_DATABASE, + 'parentResourceInternalId' => null, ]); $migration->migrate($document); From 1544ad5bcc3a6030d6b26822a08fb3f4fd75c617 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 21 Jul 2026 01:29:14 +1200 Subject: [PATCH 12/14] fix(migrations): ship resource links under 1.9.6, not 2.0.0 The release carrying this feature is 1.9.6, so the backfill moves out of 2.0.0's V25 into its own V26 migration keyed to 1.9.6, the V27 request/response filters gate at 1.9.6, and APP_VERSION_STABLE bumps to match. V25 returns to main's contents. Co-Authored-By: Claude Fable 5 --- app/controllers/general.php | 4 +- app/init/constants.php | 2 +- src/Appwrite/Migration/Migration.php | 1 + src/Appwrite/Migration/Version/V25.php | 162 ------------- src/Appwrite/Migration/Version/V26.php | 221 ++++++++++++++++++ src/Appwrite/Utopia/Request/Filters/V27.php | 2 +- src/Appwrite/Utopia/Response/Filters/V27.php | 2 +- .../Version/{V25Test.php => V26Test.php} | 10 +- 8 files changed, 232 insertions(+), 172 deletions(-) create mode 100644 src/Appwrite/Migration/Version/V26.php rename tests/unit/Migration/Version/{V25Test.php => V26Test.php} (96%) diff --git a/app/controllers/general.php b/app/controllers/general.php index 18f252458e..47b4ecd097 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -919,7 +919,7 @@ Http::init() if (version_compare($requestFormat, '1.9.5', '<')) { $request->addFilter(new RequestV26()); } - if (version_compare($requestFormat, '2.0.0', '<')) { + if (version_compare($requestFormat, '1.9.6', '<')) { $request->addFilter(new RequestV27()); } } @@ -946,7 +946,7 @@ Http::init() */ $responseFormat = $request->getHeaderLine('x-appwrite-response-format', System::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '')); if ($responseFormat) { - if (version_compare($responseFormat, '2.0.0', '<')) { + if (version_compare($responseFormat, '1.9.6', '<')) { $response->addFilter(new ResponseV27()); } if (version_compare($responseFormat, '1.9.5', '<')) { diff --git a/app/init/constants.php b/app/init/constants.php index f5eaa3a4ab..88da25bcbc 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -52,7 +52,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 = 4326; -const APP_VERSION_STABLE = '1.9.5'; +const APP_VERSION_STABLE = '1.9.6'; 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 b37846b642..73a5a2522d 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -98,6 +98,7 @@ abstract class Migration '1.9.3' => 'V24', '1.9.4' => 'V24', '1.9.5' => 'V24', + '1.9.6' => 'V26', '2.0.0' => 'V25', ]; diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index 05b1142be2..4aa05673c1 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -9,7 +9,6 @@ use Utopia\Console; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Query; -use Utopia\Migration\Resource; class V25 extends Migration { @@ -20,9 +19,6 @@ class V25 extends Migration { Console::info('Migrating collections'); $this->migrateCollections(); - - Console::info('Migrating documents'); - $this->forEachDocument($this->migrateDocument(...)); } /** @@ -108,165 +104,7 @@ class V25 extends Migration } } break; - - case 'migrations': - if ($collectionType === 'projects') { - $attributes = [ - 'resourceInternalId', - 'parentResourceId', - 'parentResourceInternalId', - 'parentResourceType', - 'destinationResourceId', - 'destinationResourceInternalId', - 'destinationResourceType', - ]; - try { - $this->createAttributesFromCollection($this->dbForProject, $id, $attributes); - } catch (Throwable $th) { - Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}"); - } - - $indexes = [ - '_key_resourceType', - '_key_resourceInternalId', - '_key_parentResourceId', - '_key_parentResourceType', - '_key_parentResourceInternalId', - '_key_destinationResourceId', - '_key_destinationResourceInternalId', - '_key_destinationResourceType', - ]; - foreach ($indexes as $index) { - try { - $this->createIndexFromCollection($this->dbForProject, $id, $index); - } catch (Throwable $th) { - Console::warning("Failed to create index \"{$index}\" from {$id}: {$th->getMessage()}"); - } - } - - $this->dbForProject->purgeCachedCollection($id); - } - break; } } } - - protected function migrateDocument(Document $document): Document - { - if ($document->getCollection() !== 'migrations') { - return $document; - } - - $resourceId = (string) $document->getAttribute('resourceId', ''); - $parentResourceId = (string) $document->getAttribute('parentResourceId', ''); - $parentResourceType = ''; - $split = false; - - if ($parentResourceId === '') { - if (!\str_contains($resourceId, ':')) { - return $document; - } - - [$parentResourceId, $resourceId] = \explode(':', $resourceId, 2); - if ($parentResourceId === '' || $resourceId === '') { - return $document; - } - - $parentResourceType = (string) $document->getAttribute('resourceType', ''); - $split = true; - } - - if ($resourceId === '') { - return $document; - } - - $internalIds = $this->resolveInternalIds($parentResourceId, $resourceId, $document); - if ( - $split - && (!isset($internalIds['parentResourceInternalId']) || !isset($internalIds['resourceInternalId'])) - ) { - return $document; - } - - if ($split) { - $document - ->setAttribute('resourceId', $resourceId) - ->setAttribute('resourceType', Resource::TYPE_COLLECTION) - ->setAttribute('parentResourceId', $parentResourceId); - - if ($parentResourceType !== '') { - $document->setAttribute('parentResourceType', $parentResourceType); - } - } - - if ( - (string) $document->getAttribute('parentResourceInternalId', '') === '' - && isset($internalIds['parentResourceInternalId']) - ) { - $document->setAttribute('parentResourceInternalId', $internalIds['parentResourceInternalId']); - } - if ( - (string) $document->getAttribute('resourceInternalId', '') === '' - && isset($internalIds['resourceInternalId']) - ) { - $document->setAttribute('resourceInternalId', $internalIds['resourceInternalId']); - } - - return $document; - } - - /** - * @return array{parentResourceInternalId?: string, resourceInternalId?: string} - */ - protected function resolveInternalIds(string $parentResourceId, string $resourceId, Document $migration): array - { - try { - $database = $this->dbForProject->getDocument('databases', $parentResourceId); - if ( - $database->isEmpty() - || $database->getSequence() === '' - || !$this->predatesMigration($database, $migration) - ) { - return []; - } - } catch (Throwable $th) { - Console::warning("Failed to resolve parent internal ID for migration {$migration->getId()}: {$th->getMessage()}"); - return []; - } - - $internalIds = [ - 'parentResourceInternalId' => (string) $database->getSequence(), - ]; - - try { - $resource = $this->dbForProject->getDocument('database_' . $database->getSequence(), $resourceId); - if ( - !$resource->isEmpty() - && $resource->getSequence() !== '' - && $this->predatesMigration($resource, $migration) - ) { - $internalIds['resourceInternalId'] = (string) $resource->getSequence(); - } - } catch (Throwable $th) { - Console::warning("Failed to resolve resource internal ID for migration {$migration->getId()}: {$th->getMessage()}"); - } - - return $internalIds; - } - - /** - * A resource created after the migration is a reused public ID, not the - * generation the historical migration operated on. - */ - protected function predatesMigration(Document $resource, Document $migration): bool - { - $resourceCreatedAt = \strtotime($resource->getCreatedAt()); - $migrationCreatedAt = \strtotime($migration->getCreatedAt()); - - if ($resourceCreatedAt === false || $migrationCreatedAt === false) { - return false; - } - - return $resourceCreatedAt <= $migrationCreatedAt; - } } diff --git a/src/Appwrite/Migration/Version/V26.php b/src/Appwrite/Migration/Version/V26.php new file mode 100644 index 0000000000..3f5b155453 --- /dev/null +++ b/src/Appwrite/Migration/Version/V26.php @@ -0,0 +1,221 @@ +migrateCollections(); + + Console::info('Migrating documents'); + $this->forEachDocument($this->migrateDocument(...)); + } + + /** + * Migrate Collections. + * + * @return void + * @throws Exception|Throwable + */ + private function migrateCollections(): void + { + $projectInternalId = $this->project->getSequence(); + + if (empty($projectInternalId)) { + throw new Exception('Project ID is null'); + } + + $collectionType = match ($projectInternalId) { + 'console' => 'console', + default => 'projects', + }; + + $collections = $this->collections[$collectionType]; + + foreach ($collections as $collection) { + $id = $collection['$id']; + + if (empty($id)) { + continue; + } + + Console::log("Migrating collection \"{$id}\""); + + $this->dbForProject->purgeCachedCollection($id); + $this->dbForProject->purgeCachedDocument(Database::METADATA, $id); + + switch ($id) { + case 'migrations': + if ($collectionType === 'projects') { + $attributes = [ + 'resourceInternalId', + 'parentResourceId', + 'parentResourceInternalId', + 'parentResourceType', + 'destinationResourceId', + 'destinationResourceInternalId', + 'destinationResourceType', + ]; + try { + $this->createAttributesFromCollection($this->dbForProject, $id, $attributes); + } catch (Throwable $th) { + Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}"); + } + + $indexes = [ + '_key_resourceType', + '_key_resourceInternalId', + '_key_parentResourceId', + '_key_parentResourceType', + '_key_parentResourceInternalId', + '_key_destinationResourceId', + '_key_destinationResourceInternalId', + '_key_destinationResourceType', + ]; + foreach ($indexes as $index) { + try { + $this->createIndexFromCollection($this->dbForProject, $id, $index); + } catch (Throwable $th) { + Console::warning("Failed to create index \"{$index}\" from {$id}: {$th->getMessage()}"); + } + } + + $this->dbForProject->purgeCachedCollection($id); + } + break; + } + } + } + + protected function migrateDocument(Document $document): Document + { + if ($document->getCollection() !== 'migrations') { + return $document; + } + + $resourceId = (string) $document->getAttribute('resourceId', ''); + $parentResourceId = (string) $document->getAttribute('parentResourceId', ''); + $parentResourceType = ''; + $split = false; + + if ($parentResourceId === '') { + if (!\str_contains($resourceId, ':')) { + return $document; + } + + [$parentResourceId, $resourceId] = \explode(':', $resourceId, 2); + if ($parentResourceId === '' || $resourceId === '') { + return $document; + } + + $parentResourceType = (string) $document->getAttribute('resourceType', ''); + $split = true; + } + + if ($resourceId === '') { + return $document; + } + + $internalIds = $this->resolveInternalIds($parentResourceId, $resourceId, $document); + if ( + $split + && (!isset($internalIds['parentResourceInternalId']) || !isset($internalIds['resourceInternalId'])) + ) { + return $document; + } + + if ($split) { + $document + ->setAttribute('resourceId', $resourceId) + ->setAttribute('resourceType', Resource::TYPE_COLLECTION) + ->setAttribute('parentResourceId', $parentResourceId); + + if ($parentResourceType !== '') { + $document->setAttribute('parentResourceType', $parentResourceType); + } + } + + if ( + (string) $document->getAttribute('parentResourceInternalId', '') === '' + && isset($internalIds['parentResourceInternalId']) + ) { + $document->setAttribute('parentResourceInternalId', $internalIds['parentResourceInternalId']); + } + if ( + (string) $document->getAttribute('resourceInternalId', '') === '' + && isset($internalIds['resourceInternalId']) + ) { + $document->setAttribute('resourceInternalId', $internalIds['resourceInternalId']); + } + + return $document; + } + + /** + * @return array{parentResourceInternalId?: string, resourceInternalId?: string} + */ + protected function resolveInternalIds(string $parentResourceId, string $resourceId, Document $migration): array + { + try { + $database = $this->dbForProject->getDocument('databases', $parentResourceId); + if ( + $database->isEmpty() + || $database->getSequence() === '' + || !$this->predatesMigration($database, $migration) + ) { + return []; + } + } catch (Throwable $th) { + Console::warning("Failed to resolve parent internal ID for migration {$migration->getId()}: {$th->getMessage()}"); + return []; + } + + $internalIds = [ + 'parentResourceInternalId' => (string) $database->getSequence(), + ]; + + try { + $resource = $this->dbForProject->getDocument('database_' . $database->getSequence(), $resourceId); + if ( + !$resource->isEmpty() + && $resource->getSequence() !== '' + && $this->predatesMigration($resource, $migration) + ) { + $internalIds['resourceInternalId'] = (string) $resource->getSequence(); + } + } catch (Throwable $th) { + Console::warning("Failed to resolve resource internal ID for migration {$migration->getId()}: {$th->getMessage()}"); + } + + return $internalIds; + } + + /** + * A resource created after the migration is a reused public ID, not the + * generation the historical migration operated on. + */ + protected function predatesMigration(Document $resource, Document $migration): bool + { + $resourceCreatedAt = \strtotime($resource->getCreatedAt()); + $migrationCreatedAt = \strtotime($migration->getCreatedAt()); + + if ($resourceCreatedAt === false || $migrationCreatedAt === false) { + return false; + } + + return $resourceCreatedAt <= $migrationCreatedAt; + } +} diff --git a/src/Appwrite/Utopia/Request/Filters/V27.php b/src/Appwrite/Utopia/Request/Filters/V27.php index 3b4c427732..58baf8a1a5 100644 --- a/src/Appwrite/Utopia/Request/Filters/V27.php +++ b/src/Appwrite/Utopia/Request/Filters/V27.php @@ -6,7 +6,7 @@ use Appwrite\Utopia\Request\Filter; class V27 extends Filter { - // Convert 1.9.5 params to 2.0.0 + // Convert 1.9.5 params to 1.9.6 public function parse(array $content, string $model): array { return match ($model) { diff --git a/src/Appwrite/Utopia/Response/Filters/V27.php b/src/Appwrite/Utopia/Response/Filters/V27.php index e0cf53ea3f..d377536488 100644 --- a/src/Appwrite/Utopia/Response/Filters/V27.php +++ b/src/Appwrite/Utopia/Response/Filters/V27.php @@ -5,7 +5,7 @@ namespace Appwrite\Utopia\Response\Filters; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Filter; -// Convert 2.0.0 Data format to 1.9.5 format +// Convert 1.9.6 Data format to 1.9.5 format class V27 extends Filter { public function parse(array $content, string $model): array diff --git a/tests/unit/Migration/Version/V25Test.php b/tests/unit/Migration/Version/V26Test.php similarity index 96% rename from tests/unit/Migration/Version/V25Test.php rename to tests/unit/Migration/Version/V26Test.php index fadb5609e0..4b8059e41a 100644 --- a/tests/unit/Migration/Version/V25Test.php +++ b/tests/unit/Migration/Version/V26Test.php @@ -4,16 +4,16 @@ declare(strict_types=1); namespace Tests\Unit\Migration\Version; -use Appwrite\Migration\Version\V25; +use Appwrite\Migration\Version\V26; use PHPUnit\Framework\TestCase; use Utopia\Database\Document; use Utopia\Migration\Resource; -final class V25Test extends TestCase +final class V26Test extends TestCase { public function testPreservesLegacyResourceWhenInternalIdsCannotBeResolved(): void { - $migration = new class () extends V25 { + $migration = new class () extends V26 { public function __construct() { } @@ -50,7 +50,7 @@ final class V25Test extends TestCase public function testRerunResolvesMissingInternalIdsIdempotently(): void { - $migration = new class () extends V25 { + $migration = new class () extends V26 { /** * @var array{parentResourceInternalId?: string, resourceInternalId?: string} */ @@ -123,7 +123,7 @@ final class V25Test extends TestCase public function testRejectsResourcesCreatedAfterMigration(): void { - $migration = new class () extends V25 { + $migration = new class () extends V26 { public function __construct() { } From 2d775cd4638b1f706641f93b2dc02c12f63ab801 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 21 Jul 2026 01:45:12 +1200 Subject: [PATCH 13/14] Revert "fix(migrations): ship resource links under 1.9.6, not 2.0.0" CE main deliberately renamed the next release from 1.9.6 to 2.0.0 (923e413358, 2026-07-02), so 1.9.6 will never ship. The feature stays folded in V25 keyed to 2.0.0 with the V27 filters gated at 2.0.0. Co-Authored-By: Claude Fable 5 --- app/controllers/general.php | 4 +- app/init/constants.php | 2 +- src/Appwrite/Migration/Migration.php | 1 - src/Appwrite/Migration/Version/V25.php | 162 +++++++++++++ src/Appwrite/Migration/Version/V26.php | 221 ------------------ src/Appwrite/Utopia/Request/Filters/V27.php | 2 +- src/Appwrite/Utopia/Response/Filters/V27.php | 2 +- .../Version/{V26Test.php => V25Test.php} | 10 +- 8 files changed, 172 insertions(+), 232 deletions(-) delete mode 100644 src/Appwrite/Migration/Version/V26.php rename tests/unit/Migration/Version/{V26Test.php => V25Test.php} (96%) diff --git a/app/controllers/general.php b/app/controllers/general.php index 47b4ecd097..18f252458e 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -919,7 +919,7 @@ Http::init() if (version_compare($requestFormat, '1.9.5', '<')) { $request->addFilter(new RequestV26()); } - if (version_compare($requestFormat, '1.9.6', '<')) { + if (version_compare($requestFormat, '2.0.0', '<')) { $request->addFilter(new RequestV27()); } } @@ -946,7 +946,7 @@ Http::init() */ $responseFormat = $request->getHeaderLine('x-appwrite-response-format', System::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '')); if ($responseFormat) { - if (version_compare($responseFormat, '1.9.6', '<')) { + if (version_compare($responseFormat, '2.0.0', '<')) { $response->addFilter(new ResponseV27()); } if (version_compare($responseFormat, '1.9.5', '<')) { diff --git a/app/init/constants.php b/app/init/constants.php index 88da25bcbc..f5eaa3a4ab 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -52,7 +52,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 = 4326; -const APP_VERSION_STABLE = '1.9.6'; +const APP_VERSION_STABLE = '1.9.5'; 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 73a5a2522d..b37846b642 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -98,7 +98,6 @@ abstract class Migration '1.9.3' => 'V24', '1.9.4' => 'V24', '1.9.5' => 'V24', - '1.9.6' => 'V26', '2.0.0' => 'V25', ]; diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index 4aa05673c1..05b1142be2 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -9,6 +9,7 @@ use Utopia\Console; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Query; +use Utopia\Migration\Resource; class V25 extends Migration { @@ -19,6 +20,9 @@ class V25 extends Migration { Console::info('Migrating collections'); $this->migrateCollections(); + + Console::info('Migrating documents'); + $this->forEachDocument($this->migrateDocument(...)); } /** @@ -104,7 +108,165 @@ class V25 extends Migration } } break; + + case 'migrations': + if ($collectionType === 'projects') { + $attributes = [ + 'resourceInternalId', + 'parentResourceId', + 'parentResourceInternalId', + 'parentResourceType', + 'destinationResourceId', + 'destinationResourceInternalId', + 'destinationResourceType', + ]; + try { + $this->createAttributesFromCollection($this->dbForProject, $id, $attributes); + } catch (Throwable $th) { + Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}"); + } + + $indexes = [ + '_key_resourceType', + '_key_resourceInternalId', + '_key_parentResourceId', + '_key_parentResourceType', + '_key_parentResourceInternalId', + '_key_destinationResourceId', + '_key_destinationResourceInternalId', + '_key_destinationResourceType', + ]; + foreach ($indexes as $index) { + try { + $this->createIndexFromCollection($this->dbForProject, $id, $index); + } catch (Throwable $th) { + Console::warning("Failed to create index \"{$index}\" from {$id}: {$th->getMessage()}"); + } + } + + $this->dbForProject->purgeCachedCollection($id); + } + break; } } } + + protected function migrateDocument(Document $document): Document + { + if ($document->getCollection() !== 'migrations') { + return $document; + } + + $resourceId = (string) $document->getAttribute('resourceId', ''); + $parentResourceId = (string) $document->getAttribute('parentResourceId', ''); + $parentResourceType = ''; + $split = false; + + if ($parentResourceId === '') { + if (!\str_contains($resourceId, ':')) { + return $document; + } + + [$parentResourceId, $resourceId] = \explode(':', $resourceId, 2); + if ($parentResourceId === '' || $resourceId === '') { + return $document; + } + + $parentResourceType = (string) $document->getAttribute('resourceType', ''); + $split = true; + } + + if ($resourceId === '') { + return $document; + } + + $internalIds = $this->resolveInternalIds($parentResourceId, $resourceId, $document); + if ( + $split + && (!isset($internalIds['parentResourceInternalId']) || !isset($internalIds['resourceInternalId'])) + ) { + return $document; + } + + if ($split) { + $document + ->setAttribute('resourceId', $resourceId) + ->setAttribute('resourceType', Resource::TYPE_COLLECTION) + ->setAttribute('parentResourceId', $parentResourceId); + + if ($parentResourceType !== '') { + $document->setAttribute('parentResourceType', $parentResourceType); + } + } + + if ( + (string) $document->getAttribute('parentResourceInternalId', '') === '' + && isset($internalIds['parentResourceInternalId']) + ) { + $document->setAttribute('parentResourceInternalId', $internalIds['parentResourceInternalId']); + } + if ( + (string) $document->getAttribute('resourceInternalId', '') === '' + && isset($internalIds['resourceInternalId']) + ) { + $document->setAttribute('resourceInternalId', $internalIds['resourceInternalId']); + } + + return $document; + } + + /** + * @return array{parentResourceInternalId?: string, resourceInternalId?: string} + */ + protected function resolveInternalIds(string $parentResourceId, string $resourceId, Document $migration): array + { + try { + $database = $this->dbForProject->getDocument('databases', $parentResourceId); + if ( + $database->isEmpty() + || $database->getSequence() === '' + || !$this->predatesMigration($database, $migration) + ) { + return []; + } + } catch (Throwable $th) { + Console::warning("Failed to resolve parent internal ID for migration {$migration->getId()}: {$th->getMessage()}"); + return []; + } + + $internalIds = [ + 'parentResourceInternalId' => (string) $database->getSequence(), + ]; + + try { + $resource = $this->dbForProject->getDocument('database_' . $database->getSequence(), $resourceId); + if ( + !$resource->isEmpty() + && $resource->getSequence() !== '' + && $this->predatesMigration($resource, $migration) + ) { + $internalIds['resourceInternalId'] = (string) $resource->getSequence(); + } + } catch (Throwable $th) { + Console::warning("Failed to resolve resource internal ID for migration {$migration->getId()}: {$th->getMessage()}"); + } + + return $internalIds; + } + + /** + * A resource created after the migration is a reused public ID, not the + * generation the historical migration operated on. + */ + protected function predatesMigration(Document $resource, Document $migration): bool + { + $resourceCreatedAt = \strtotime($resource->getCreatedAt()); + $migrationCreatedAt = \strtotime($migration->getCreatedAt()); + + if ($resourceCreatedAt === false || $migrationCreatedAt === false) { + return false; + } + + return $resourceCreatedAt <= $migrationCreatedAt; + } } diff --git a/src/Appwrite/Migration/Version/V26.php b/src/Appwrite/Migration/Version/V26.php deleted file mode 100644 index 3f5b155453..0000000000 --- a/src/Appwrite/Migration/Version/V26.php +++ /dev/null @@ -1,221 +0,0 @@ -migrateCollections(); - - Console::info('Migrating documents'); - $this->forEachDocument($this->migrateDocument(...)); - } - - /** - * Migrate Collections. - * - * @return void - * @throws Exception|Throwable - */ - private function migrateCollections(): void - { - $projectInternalId = $this->project->getSequence(); - - if (empty($projectInternalId)) { - throw new Exception('Project ID is null'); - } - - $collectionType = match ($projectInternalId) { - 'console' => 'console', - default => 'projects', - }; - - $collections = $this->collections[$collectionType]; - - foreach ($collections as $collection) { - $id = $collection['$id']; - - if (empty($id)) { - continue; - } - - Console::log("Migrating collection \"{$id}\""); - - $this->dbForProject->purgeCachedCollection($id); - $this->dbForProject->purgeCachedDocument(Database::METADATA, $id); - - switch ($id) { - case 'migrations': - if ($collectionType === 'projects') { - $attributes = [ - 'resourceInternalId', - 'parentResourceId', - 'parentResourceInternalId', - 'parentResourceType', - 'destinationResourceId', - 'destinationResourceInternalId', - 'destinationResourceType', - ]; - try { - $this->createAttributesFromCollection($this->dbForProject, $id, $attributes); - } catch (Throwable $th) { - Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}"); - } - - $indexes = [ - '_key_resourceType', - '_key_resourceInternalId', - '_key_parentResourceId', - '_key_parentResourceType', - '_key_parentResourceInternalId', - '_key_destinationResourceId', - '_key_destinationResourceInternalId', - '_key_destinationResourceType', - ]; - foreach ($indexes as $index) { - try { - $this->createIndexFromCollection($this->dbForProject, $id, $index); - } catch (Throwable $th) { - Console::warning("Failed to create index \"{$index}\" from {$id}: {$th->getMessage()}"); - } - } - - $this->dbForProject->purgeCachedCollection($id); - } - break; - } - } - } - - protected function migrateDocument(Document $document): Document - { - if ($document->getCollection() !== 'migrations') { - return $document; - } - - $resourceId = (string) $document->getAttribute('resourceId', ''); - $parentResourceId = (string) $document->getAttribute('parentResourceId', ''); - $parentResourceType = ''; - $split = false; - - if ($parentResourceId === '') { - if (!\str_contains($resourceId, ':')) { - return $document; - } - - [$parentResourceId, $resourceId] = \explode(':', $resourceId, 2); - if ($parentResourceId === '' || $resourceId === '') { - return $document; - } - - $parentResourceType = (string) $document->getAttribute('resourceType', ''); - $split = true; - } - - if ($resourceId === '') { - return $document; - } - - $internalIds = $this->resolveInternalIds($parentResourceId, $resourceId, $document); - if ( - $split - && (!isset($internalIds['parentResourceInternalId']) || !isset($internalIds['resourceInternalId'])) - ) { - return $document; - } - - if ($split) { - $document - ->setAttribute('resourceId', $resourceId) - ->setAttribute('resourceType', Resource::TYPE_COLLECTION) - ->setAttribute('parentResourceId', $parentResourceId); - - if ($parentResourceType !== '') { - $document->setAttribute('parentResourceType', $parentResourceType); - } - } - - if ( - (string) $document->getAttribute('parentResourceInternalId', '') === '' - && isset($internalIds['parentResourceInternalId']) - ) { - $document->setAttribute('parentResourceInternalId', $internalIds['parentResourceInternalId']); - } - if ( - (string) $document->getAttribute('resourceInternalId', '') === '' - && isset($internalIds['resourceInternalId']) - ) { - $document->setAttribute('resourceInternalId', $internalIds['resourceInternalId']); - } - - return $document; - } - - /** - * @return array{parentResourceInternalId?: string, resourceInternalId?: string} - */ - protected function resolveInternalIds(string $parentResourceId, string $resourceId, Document $migration): array - { - try { - $database = $this->dbForProject->getDocument('databases', $parentResourceId); - if ( - $database->isEmpty() - || $database->getSequence() === '' - || !$this->predatesMigration($database, $migration) - ) { - return []; - } - } catch (Throwable $th) { - Console::warning("Failed to resolve parent internal ID for migration {$migration->getId()}: {$th->getMessage()}"); - return []; - } - - $internalIds = [ - 'parentResourceInternalId' => (string) $database->getSequence(), - ]; - - try { - $resource = $this->dbForProject->getDocument('database_' . $database->getSequence(), $resourceId); - if ( - !$resource->isEmpty() - && $resource->getSequence() !== '' - && $this->predatesMigration($resource, $migration) - ) { - $internalIds['resourceInternalId'] = (string) $resource->getSequence(); - } - } catch (Throwable $th) { - Console::warning("Failed to resolve resource internal ID for migration {$migration->getId()}: {$th->getMessage()}"); - } - - return $internalIds; - } - - /** - * A resource created after the migration is a reused public ID, not the - * generation the historical migration operated on. - */ - protected function predatesMigration(Document $resource, Document $migration): bool - { - $resourceCreatedAt = \strtotime($resource->getCreatedAt()); - $migrationCreatedAt = \strtotime($migration->getCreatedAt()); - - if ($resourceCreatedAt === false || $migrationCreatedAt === false) { - return false; - } - - return $resourceCreatedAt <= $migrationCreatedAt; - } -} diff --git a/src/Appwrite/Utopia/Request/Filters/V27.php b/src/Appwrite/Utopia/Request/Filters/V27.php index 58baf8a1a5..3b4c427732 100644 --- a/src/Appwrite/Utopia/Request/Filters/V27.php +++ b/src/Appwrite/Utopia/Request/Filters/V27.php @@ -6,7 +6,7 @@ use Appwrite\Utopia\Request\Filter; class V27 extends Filter { - // Convert 1.9.5 params to 1.9.6 + // Convert 1.9.5 params to 2.0.0 public function parse(array $content, string $model): array { return match ($model) { diff --git a/src/Appwrite/Utopia/Response/Filters/V27.php b/src/Appwrite/Utopia/Response/Filters/V27.php index d377536488..e0cf53ea3f 100644 --- a/src/Appwrite/Utopia/Response/Filters/V27.php +++ b/src/Appwrite/Utopia/Response/Filters/V27.php @@ -5,7 +5,7 @@ namespace Appwrite\Utopia\Response\Filters; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Filter; -// Convert 1.9.6 Data format to 1.9.5 format +// Convert 2.0.0 Data format to 1.9.5 format class V27 extends Filter { public function parse(array $content, string $model): array diff --git a/tests/unit/Migration/Version/V26Test.php b/tests/unit/Migration/Version/V25Test.php similarity index 96% rename from tests/unit/Migration/Version/V26Test.php rename to tests/unit/Migration/Version/V25Test.php index 4b8059e41a..fadb5609e0 100644 --- a/tests/unit/Migration/Version/V26Test.php +++ b/tests/unit/Migration/Version/V25Test.php @@ -4,16 +4,16 @@ declare(strict_types=1); namespace Tests\Unit\Migration\Version; -use Appwrite\Migration\Version\V26; +use Appwrite\Migration\Version\V25; use PHPUnit\Framework\TestCase; use Utopia\Database\Document; use Utopia\Migration\Resource; -final class V26Test extends TestCase +final class V25Test extends TestCase { public function testPreservesLegacyResourceWhenInternalIdsCannotBeResolved(): void { - $migration = new class () extends V26 { + $migration = new class () extends V25 { public function __construct() { } @@ -50,7 +50,7 @@ final class V26Test extends TestCase public function testRerunResolvesMissingInternalIdsIdempotently(): void { - $migration = new class () extends V26 { + $migration = new class () extends V25 { /** * @var array{parentResourceInternalId?: string, resourceInternalId?: string} */ @@ -123,7 +123,7 @@ final class V26Test extends TestCase public function testRejectsResourcesCreatedAfterMigration(): void { - $migration = new class () extends V26 { + $migration = new class () extends V25 { public function __construct() { } From 6d8e59e37b8e660a7fbc81fa59a68aa6d3d1c729 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 21 Jul 2026 01:51:52 +1200 Subject: [PATCH 14/14] chore: trigger CI on revert tip Co-Authored-By: Claude Fable 5