Merge pull request #7652 from appwrite/feat-migrations-service-fixes

Use new migration error handling
This commit is contained in:
Eldad A. Fux 2024-02-25 16:30:56 +01:00 committed by GitHub
commit 5bc6018c7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 51 additions and 34 deletions

View file

@ -58,7 +58,7 @@
"utopia-php/locale": "0.4.*", "utopia-php/locale": "0.4.*",
"utopia-php/logger": "0.3.*", "utopia-php/logger": "0.3.*",
"utopia-php/messaging": "0.10.*", "utopia-php/messaging": "0.10.*",
"utopia-php/migration": "0.3.*", "utopia-php/migration": "0.4.*",
"utopia-php/orchestration": "0.9.*", "utopia-php/orchestration": "0.9.*",
"utopia-php/platform": "0.5.*", "utopia-php/platform": "0.5.*",
"utopia-php/pools": "0.4.*", "utopia-php/pools": "0.4.*",

40
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "f19c09e7e233fe0f767bf5255fb46b86", "content-hash": "ed4d8b871471fe6a259742c4abe88184",
"packages": [ "packages": [
{ {
"name": "adhocore/jwt", "name": "adhocore/jwt",
@ -65,16 +65,16 @@
}, },
{ {
"name": "appwrite/appwrite", "name": "appwrite/appwrite",
"version": "10.0.0", "version": "10.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/appwrite/sdk-for-php.git", "url": "https://github.com/appwrite/sdk-for-php.git",
"reference": "461eedf4efd502dc905c3055f36f0e3583f67390" "reference": "da579af70723cfc117b5af84375bdef117e27312"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/461eedf4efd502dc905c3055f36f0e3583f67390", "url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/da579af70723cfc117b5af84375bdef117e27312",
"reference": "461eedf4efd502dc905c3055f36f0e3583f67390", "reference": "da579af70723cfc117b5af84375bdef117e27312",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -99,10 +99,10 @@
"support": { "support": {
"email": "team@appwrite.io", "email": "team@appwrite.io",
"issues": "https://github.com/appwrite/sdk-for-php/issues", "issues": "https://github.com/appwrite/sdk-for-php/issues",
"source": "https://github.com/appwrite/sdk-for-php/tree/10.0.0", "source": "https://github.com/appwrite/sdk-for-php/tree/10.1.0",
"url": "https://appwrite.io/support" "url": "https://appwrite.io/support"
}, },
"time": "2023-09-07T23:28:31+00:00" "time": "2023-11-20T09:56:12+00:00"
}, },
{ {
"name": "appwrite/php-clamav", "name": "appwrite/php-clamav",
@ -1962,20 +1962,20 @@
}, },
{ {
"name": "utopia-php/migration", "name": "utopia-php/migration",
"version": "0.3.6", "version": "0.4.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/utopia-php/migration.git", "url": "https://github.com/utopia-php/migration.git",
"reference": "f78273b38bade23db5866e5c7cb5f55427ba82af" "reference": "a72f27bd3dde68752fb185d306c4820e1b8d9657"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/f78273b38bade23db5866e5c7cb5f55427ba82af", "url": "https://api.github.com/repos/utopia-php/migration/zipball/a72f27bd3dde68752fb185d306c4820e1b8d9657",
"reference": "f78273b38bade23db5866e5c7cb5f55427ba82af", "reference": "a72f27bd3dde68752fb185d306c4820e1b8d9657",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"appwrite/appwrite": "10.0.*", "appwrite/appwrite": "10.1.0",
"php": "8.*", "php": "8.*",
"utopia-php/cli": "0.*" "utopia-php/cli": "0.*"
}, },
@ -2004,9 +2004,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/utopia-php/migration/issues", "issues": "https://github.com/utopia-php/migration/issues",
"source": "https://github.com/utopia-php/migration/tree/0.3.6" "source": "https://github.com/utopia-php/migration/tree/0.4.0"
}, },
"time": "2023-11-02T15:13:03+00:00" "time": "2024-02-25T12:35:21+00:00"
}, },
{ {
"name": "utopia-php/mongo", "name": "utopia-php/mongo",
@ -3484,16 +3484,16 @@
}, },
{ {
"name": "phpstan/phpdoc-parser", "name": "phpstan/phpdoc-parser",
"version": "1.25.0", "version": "1.26.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git", "url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240" "reference": "231e3186624c03d7e7c890ec662b81e6b0405227"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bd84b629c8de41aa2ae82c067c955e06f1b00240", "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/231e3186624c03d7e7c890ec662b81e6b0405227",
"reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240", "reference": "231e3186624c03d7e7c890ec662b81e6b0405227",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3525,9 +3525,9 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types", "description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": { "support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues", "issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.25.0" "source": "https://github.com/phpstan/phpdoc-parser/tree/1.26.0"
}, },
"time": "2024-01-04T17:06:16+00:00" "time": "2024-02-23T16:05:55+00:00"
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",

View file

@ -19,13 +19,13 @@ use Utopia\Database\Database;
use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\ID;
use Utopia\Logger\Log; use Utopia\Logger\Log;
use Utopia\Migration\Destinations\Appwrite as DestinationsAppwrite; use Utopia\Migration\Destinations\Appwrite as DestinationsAppwrite;
use Utopia\Migration\Resource;
use Utopia\Migration\Source; use Utopia\Migration\Source;
use Utopia\Migration\Sources\Appwrite; use Utopia\Migration\Sources\Appwrite;
use Utopia\Migration\Sources\Firebase; use Utopia\Migration\Sources\Firebase;
use Utopia\Migration\Sources\NHost; use Utopia\Migration\Sources\NHost;
use Utopia\Migration\Sources\Supabase; use Utopia\Migration\Sources\Supabase;
use Utopia\Migration\Transfer; use Utopia\Migration\Transfer;
use Utopia\Migration\Exception as MigrationException;
class Migrations extends Action class Migrations extends Action
{ {
@ -285,15 +285,21 @@ class Migrations extends Action
$this->updateMigrationDocument($migrationDocument, $projectDocument); $this->updateMigrationDocument($migrationDocument, $projectDocument);
}); });
$errors = $transfer->getReport(Resource::STATUS_ERROR); $sourceErrors = $source->getErrors();
$destinationErrors = $destination->getErrors();
if (count($errors) > 0) { if (!empty($sourceErrors) || !empty($destinationErrors)) {
$migrationDocument->setAttribute('status', 'failed'); $migrationDocument->setAttribute('status', 'failed');
$migrationDocument->setAttribute('stage', 'finished'); $migrationDocument->setAttribute('stage', 'finished');
$errorMessages = []; $errorMessages = [];
foreach ($errors as $error) { foreach ($sourceErrors as $error) {
$errorMessages[] = "Failed to transfer resource '{$error['id']}:{$error['resource']}' with message '{$error['message']}'"; /** @var MigrationException $error */
$errorMessages[] = "Error occurred while fetching '{$error->getResourceType()}:{$error->getResourceId()}' from source with message: '{$error->getMessage()}'";
}
foreach ($destinationErrors as $error) {
/** @var MigrationException $error */
$errorMessages[] = "Error occurred while pushing '{$error->getResourceType()}:{$error->getResourceId()}' to destination with message: '{$error->getMessage()}'";
} }
$migrationDocument->setAttribute('errors', $errorMessages); $migrationDocument->setAttribute('errors', $errorMessages);
@ -318,21 +324,32 @@ class Migrations extends Action
} }
if ($transfer) { if ($transfer) {
$errors = $transfer->getReport(Resource::STATUS_ERROR); $sourceErrors = $source->getErrors();
$destinationErrors = $destination->getErrors();
if (count($errors) > 0) { $errorMessages = [];
$migrationDocument->setAttribute('status', 'failed'); foreach ($sourceErrors as $error) {
$migrationDocument->setAttribute('stage', 'finished'); /** @var MigrationException $error */
$migrationDocument->setAttribute('errors', $errors); $errorMessages[] = "Error occurred while fetching '{$error->getResourceType()}:{$error->getResourceId()}' from source with message '{$error->getMessage()}'";
} }
foreach ($destinationErrors as $error) {
/** @var MigrationException $error */
$errorMessages[] = "Error occurred while pushing '{$error->getResourceType()}:{$error->getResourceId()}' to destination with message '{$error->getMessage()}'";
}
$migrationDocument->setAttribute('errors', $errorMessages);
} }
} finally { } finally {
if ($migrationDocument) {
$this->updateMigrationDocument($migrationDocument, $projectDocument);
}
if ($tempAPIKey) { if ($tempAPIKey) {
$this->removeAPIKey($tempAPIKey); $this->removeAPIKey($tempAPIKey);
} }
if ($migrationDocument) {
$this->updateMigrationDocument($migrationDocument, $projectDocument);
if ($migrationDocument->getAttribute('status', '') == 'failed') {
throw new Exception(implode("\n", $migrationDocument->getAttribute('errors', [])));
}
}
} }
} }
} }