From 3cfe4dca6a8d1e8b77d0edf45c2d3d244608d178 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 17 Jul 2026 23:31:19 +1200 Subject: [PATCH] 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); + } +}