Merge remote-tracking branch 'origin/refactor-usage-sn' into feat-shared-tables

This commit is contained in:
Jake Barnby 2024-05-02 18:29:05 +12:00
commit 1959e6498b
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
3 changed files with 30 additions and 13 deletions

22
composer.lock generated
View file

@ -2005,16 +2005,16 @@
},
{
"name": "utopia-php/migration",
"version": "0.4.0",
"version": "0.4.1",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/migration.git",
"reference": "a72f27bd3dde68752fb185d306c4820e1b8d9657"
"reference": "ae3cfe93f6d313105d226aeb68806660c806a925"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/a72f27bd3dde68752fb185d306c4820e1b8d9657",
"reference": "a72f27bd3dde68752fb185d306c4820e1b8d9657",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/ae3cfe93f6d313105d226aeb68806660c806a925",
"reference": "ae3cfe93f6d313105d226aeb68806660c806a925",
"shasum": ""
},
"require": {
@ -2047,9 +2047,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/migration/issues",
"source": "https://github.com/utopia-php/migration/tree/0.4.0"
"source": "https://github.com/utopia-php/migration/tree/0.4.1"
},
"time": "2024-02-25T12:35:21+00:00"
"time": "2024-05-01T13:19:18+00:00"
},
{
"name": "utopia-php/mongo",
@ -2991,16 +2991,16 @@
},
{
"name": "laravel/pint",
"version": "v1.15.2",
"version": "v1.15.3",
"source": {
"type": "git",
"url": "https://github.com/laravel/pint.git",
"reference": "2c9f8004899815f3f0ee3cb28ef7281e2b589134"
"reference": "3600b5d17aff52f6100ea4921849deacbbeb8656"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/pint/zipball/2c9f8004899815f3f0ee3cb28ef7281e2b589134",
"reference": "2c9f8004899815f3f0ee3cb28ef7281e2b589134",
"url": "https://api.github.com/repos/laravel/pint/zipball/3600b5d17aff52f6100ea4921849deacbbeb8656",
"reference": "3600b5d17aff52f6100ea4921849deacbbeb8656",
"shasum": ""
},
"require": {
@ -3053,7 +3053,7 @@
"issues": "https://github.com/laravel/pint/issues",
"source": "https://github.com/laravel/pint"
},
"time": "2024-04-23T15:42:34+00:00"
"time": "2024-04-30T15:02:26+00:00"
},
{
"name": "matthiasmullie/minify",

View file

@ -300,11 +300,20 @@ class Exception extends \Exception
protected array $errors = [];
protected bool $publish;
public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, int $code = null, \Throwable $previous = null)
public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, int|string $code = null, \Throwable $previous = null)
{
$this->errors = Config::getParam('errors');
$this->type = $type;
$this->code = $code ?? $this->errors[$type]['code'];
if(\is_string($this->code)) {
if (\is_numeric($this->code)) {
$this->code = (int) $this->code;
} else {
$this->code = 500;
}
}
$this->message = $message ?? $this->errors[$type]['description'];
$this->publish = $this->errors[$type]['publish'] ?? ($this->code >= 500);

View file

@ -16,6 +16,7 @@ use Utopia\Database\Exception\Restricted;
use Utopia\Database\Exception\Structure;
use Utopia\Database\Helpers\ID;
use Utopia\Logger\Log;
use Utopia\Logger\Log\Breadcrumb;
use Utopia\Migration\Destinations\Appwrite as DestinationsAppwrite;
use Utopia\Migration\Exception as MigrationException;
use Utopia\Migration\Source;
@ -85,6 +86,7 @@ class Migrations extends Action
return;
}
$log->addTag('migrationId', $migration->getId());
$log->addTag('projectId', $project->getId());
$this->processMigration($project, $migration, $log);
@ -256,6 +258,7 @@ class Migrations extends Action
$migrationDocument = $this->dbForProject->getDocument('migrations', $migration->getId());
$migrationDocument->setAttribute('stage', 'processing');
$migrationDocument->setAttribute('status', 'processing');
$log->addBreadcrumb(new Breadcrumb("debug", "migration", "Migration hit stage 'processing'", \microtime(true)));
$this->updateMigrationDocument($migrationDocument, $projectDocument);
$log->addTag('type', $migrationDocument->getAttribute('source'));
@ -277,6 +280,7 @@ class Migrations extends Action
/** Start Transfer */
$migrationDocument->setAttribute('stage', 'migrating');
$log->addBreadcrumb(new Breadcrumb("debug", "migration", "Migration hit stage 'migrating'", \microtime(true)));
$this->updateMigrationDocument($migrationDocument, $projectDocument);
$transfer->run($migrationDocument->getAttribute('resources'), function () use ($migrationDocument, $transfer, $projectDocument) {
$migrationDocument->setAttribute('resourceData', json_encode($transfer->getCache()));
@ -291,6 +295,7 @@ class Migrations extends Action
if (!empty($sourceErrors) || !empty($destinationErrors)) {
$migrationDocument->setAttribute('status', 'failed');
$migrationDocument->setAttribute('stage', 'finished');
$log->addBreadcrumb(new Breadcrumb("debug", "migration", "Migration hit stage 'finished' and failed", \microtime(true)));
$errorMessages = [];
foreach ($sourceErrors as $error) {
@ -303,6 +308,7 @@ class Migrations extends Action
}
$migrationDocument->setAttribute('errors', $errorMessages);
$log->addExtra('migrationErrors', json_encode($errorMessages));
$this->updateMigrationDocument($migrationDocument, $projectDocument);
return;
@ -310,6 +316,7 @@ class Migrations extends Action
$migrationDocument->setAttribute('status', 'completed');
$migrationDocument->setAttribute('stage', 'finished');
$log->addBreadcrumb(new Breadcrumb("debug", "migration", "Migration hit stage 'finished' and succeeded", \microtime(true)));
} catch (\Throwable $th) {
Console::error($th->getMessage());
@ -338,6 +345,7 @@ class Migrations extends Action
}
$migrationDocument->setAttribute('errors', $errorMessages);
$log->addTag('migrationErrors', json_encode($errorMessages));
}
} finally {
if ($tempAPIKey) {
@ -347,7 +355,7 @@ class Migrations extends Action
$this->updateMigrationDocument($migrationDocument, $projectDocument);
if ($migrationDocument->getAttribute('status', '') == 'failed') {
throw new Exception(implode("\n", $migrationDocument->getAttribute('errors', [])));
throw new Exception("Migration failed");
}
}
}