mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Compare commits
24
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
adf52b8d58 | ||
|
|
79b58f23f8 | ||
|
|
b8b0002977 | ||
|
|
ee0ac45d52 | ||
|
|
ae7e307052 | ||
|
|
e45a2c0ef0 | ||
|
|
85bde93517 | ||
|
|
ca06cc72f2 | ||
|
|
6898957e98 | ||
|
|
39537fc270 | ||
|
|
9f82825a89 | ||
|
|
bad5ee65fd | ||
|
|
ddef6ad9ed | ||
|
|
4b26c1756e | ||
|
|
a5d5d72840 | ||
|
|
2bf291f7fd | ||
|
|
47ecb3330e | ||
|
|
6f0a9a8adb | ||
|
|
aa856b6a0a | ||
|
|
d20d3228f5 | ||
|
|
abd4772821 | ||
|
|
fdaf79e80b | ||
|
|
4d76abe510 | ||
|
|
eff09b665d |
+128
-12
@@ -4101,9 +4101,9 @@ $projectCollections = array_merge([
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'default' => 'pending',
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
'filters' => ['subQueryMigrationStatus'],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('stage'),
|
||||
@@ -4166,10 +4166,9 @@ $projectCollections = array_merge([
|
||||
'format' => '',
|
||||
'size' => 3000,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => ['json'],
|
||||
'filters' => ['subQueryStatusCounters'],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('resourceData'),
|
||||
@@ -4177,10 +4176,9 @@ $projectCollections = array_merge([
|
||||
'format' => '',
|
||||
'size' => 131070,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => ['json'],
|
||||
'filters' => ['subQueryResourceData'],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('errors'),
|
||||
@@ -4188,10 +4186,10 @@ $projectCollections = array_merge([
|
||||
'format' => '',
|
||||
'size' => 65535,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'array' => true,
|
||||
'filters' => [],
|
||||
'required' => false,
|
||||
'default' => '',
|
||||
'array' => false,
|
||||
'filters' => ['subQueryMigrationErrors'],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('search'),
|
||||
@@ -4236,6 +4234,124 @@ $projectCollections = array_merge([
|
||||
]
|
||||
],
|
||||
],
|
||||
'migrationsGroup' => [
|
||||
'$collection' => ID::custom(Database::METADATA),
|
||||
'$id' => ID::custom('migrationsGroup'),
|
||||
'name' => 'migrationsGroup',
|
||||
'attributes' => [
|
||||
[
|
||||
'$id' => ID::custom('migrationId'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => []
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('migrationInternalId'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => []
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('status'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => []
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('resources'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'array' => true,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('group'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => []
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('statusCounters'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 3000,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('resourceData'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 131070,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('errors'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 65535,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'array' => true,
|
||||
'filters' => [],
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
[
|
||||
'$id' => '_key_migrationId',
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => ['migrationId'],
|
||||
'lengths' => [Database::LENGTH_KEY],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
[
|
||||
'$id' => '_key_migrationInternalId',
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => ['migrationInternalId'],
|
||||
'lengths' => [Database::LENGTH_KEY],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
[
|
||||
'$id' => '_key_group',
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => ['group'],
|
||||
'lengths' => [Database::LENGTH_KEY],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
]
|
||||
]
|
||||
],
|
||||
], $commonCollections);
|
||||
|
||||
$consoleCollections = array_merge([
|
||||
|
||||
@@ -22,6 +22,7 @@ use Utopia\Migration\Sources\Appwrite;
|
||||
use Utopia\Migration\Sources\Firebase;
|
||||
use Utopia\Migration\Sources\NHost;
|
||||
use Utopia\Migration\Sources\Supabase;
|
||||
use Utopia\Migration\Transfer;
|
||||
use Utopia\System\System;
|
||||
use Utopia\Validator\ArrayList;
|
||||
use Utopia\Validator\Host;
|
||||
@@ -32,6 +33,43 @@ use Utopia\Validator\WhiteList;
|
||||
|
||||
include_once __DIR__ . '/../shared/api.php';
|
||||
|
||||
$triggerMigration = function (Document $migration, array $resources, Migration $queueForMigrations, Database $dbForProject) {
|
||||
$groups = [
|
||||
Transfer::GROUP_AUTH => Transfer::GROUP_AUTH_RESOURCES,
|
||||
Transfer::GROUP_DATABASES => Transfer::GROUP_DATABASES_RESOURCES,
|
||||
Transfer::GROUP_FUNCTIONS => Transfer::GROUP_FUNCTIONS_RESOURCES,
|
||||
Transfer::GROUP_STORAGE => Transfer::GROUP_STORAGE_RESOURCES
|
||||
];
|
||||
|
||||
foreach ($groups as $group => $groupResources) {
|
||||
$filteredResources = array_intersect(
|
||||
$groupResources,
|
||||
$resources
|
||||
);
|
||||
|
||||
if (!empty($filteredResources)) {
|
||||
$groupDocument = new Document([
|
||||
'$id' => ID::unique(),
|
||||
'status' => 'pending',
|
||||
'migrationId' => $migration->getId(),
|
||||
'migrationInternalId' => $migration->getInternalId(),
|
||||
'group' => $group,
|
||||
'resources' => $filteredResources,
|
||||
'statusCounters' => '',
|
||||
'resourceData' => '',
|
||||
'errors' => []
|
||||
]);
|
||||
|
||||
$dbForProject->createDocument('migrationsGroup', $groupDocument);
|
||||
|
||||
$queueForMigrations
|
||||
->setType($group)
|
||||
->setMigration($groupDocument)
|
||||
->trigger();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
App::post('/v1/migrations/appwrite')
|
||||
->groups(['api', 'migrations'])
|
||||
->desc('Migrate Appwrite data')
|
||||
@@ -55,7 +93,7 @@ App::post('/v1/migrations/appwrite')
|
||||
->inject('user')
|
||||
->inject('queueForEvents')
|
||||
->inject('queueForMigrations')
|
||||
->action(function (array $resources, string $endpoint, string $projectId, string $apiKey, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations) {
|
||||
->action(function (array $resources, string $endpoint, string $projectId, string $apiKey, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations) use ($triggerMigration) {
|
||||
$migration = $dbForProject->createDocument('migrations', new Document([
|
||||
'$id' => ID::unique(),
|
||||
'status' => 'pending',
|
||||
@@ -75,12 +113,11 @@ App::post('/v1/migrations/appwrite')
|
||||
|
||||
$queueForEvents->setParam('migrationId', $migration->getId());
|
||||
|
||||
// Trigger Transfer
|
||||
$queueForMigrations
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
->setUser($user);
|
||||
|
||||
$triggerMigration($migration, $resources, $queueForMigrations, $dbForProject);
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_ACCEPTED)
|
||||
@@ -110,7 +147,7 @@ App::post('/v1/migrations/firebase/oauth')
|
||||
->inject('queueForEvents')
|
||||
->inject('queueForMigrations')
|
||||
->inject('request')
|
||||
->action(function (array $resources, string $projectId, Response $response, Database $dbForProject, Database $dbForConsole, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations, Request $request) {
|
||||
->action(function (array $resources, string $projectId, Response $response, Database $dbForProject, Database $dbForConsole, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations, Request $request) use ($triggerMigration) {
|
||||
$firebase = new OAuth2Firebase(
|
||||
System::getEnv('_APP_MIGRATIONS_FIREBASE_CLIENT_ID', ''),
|
||||
System::getEnv('_APP_MIGRATIONS_FIREBASE_CLIENT_SECRET', ''),
|
||||
@@ -180,10 +217,10 @@ App::post('/v1/migrations/firebase/oauth')
|
||||
|
||||
// Trigger Transfer
|
||||
$queueForMigrations
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
->setUser($user);
|
||||
|
||||
$triggerMigration($migration, $resources, $queueForMigrations, $dbForProject);
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_ACCEPTED)
|
||||
@@ -211,7 +248,7 @@ App::post('/v1/migrations/firebase')
|
||||
->inject('user')
|
||||
->inject('queueForEvents')
|
||||
->inject('queueForMigrations')
|
||||
->action(function (array $resources, string $serviceAccount, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations) {
|
||||
->action(function (array $resources, string $serviceAccount, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations) use ($triggerMigration) {
|
||||
$serviceAccountData = json_decode($serviceAccount, true);
|
||||
|
||||
if (empty($serviceAccountData)) {
|
||||
@@ -231,7 +268,6 @@ App::post('/v1/migrations/firebase')
|
||||
'credentials' => [
|
||||
'serviceAccount' => $serviceAccount,
|
||||
],
|
||||
'resources' => $resources,
|
||||
'statusCounters' => '{}',
|
||||
'resourceData' => '{}',
|
||||
'errors' => [],
|
||||
@@ -241,10 +277,10 @@ App::post('/v1/migrations/firebase')
|
||||
|
||||
// Trigger Transfer
|
||||
$queueForMigrations
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
->setUser($user);
|
||||
|
||||
$triggerMigration($migration, $resources, $queueForMigrations, $dbForProject);
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_ACCEPTED)
|
||||
@@ -277,7 +313,7 @@ App::post('/v1/migrations/supabase')
|
||||
->inject('user')
|
||||
->inject('queueForEvents')
|
||||
->inject('queueForMigrations')
|
||||
->action(function (array $resources, string $endpoint, string $apiKey, string $databaseHost, string $username, string $password, int $port, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations) {
|
||||
->action(function (array $resources, string $endpoint, string $apiKey, string $databaseHost, string $username, string $password, int $port, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations) use ($triggerMigration) {
|
||||
$migration = $dbForProject->createDocument('migrations', new Document([
|
||||
'$id' => ID::unique(),
|
||||
'status' => 'pending',
|
||||
@@ -302,10 +338,10 @@ App::post('/v1/migrations/supabase')
|
||||
|
||||
// Trigger Transfer
|
||||
$queueForMigrations
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
->setUser($user);
|
||||
|
||||
$triggerMigration($migration, $resources, $queueForMigrations, $dbForProject);
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_ACCEPTED)
|
||||
@@ -339,7 +375,7 @@ App::post('/v1/migrations/nhost')
|
||||
->inject('user')
|
||||
->inject('queueForEvents')
|
||||
->inject('queueForMigrations')
|
||||
->action(function (array $resources, string $subdomain, string $region, string $adminSecret, string $database, string $username, string $password, int $port, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations) {
|
||||
->action(function (array $resources, string $subdomain, string $region, string $adminSecret, string $database, string $username, string $password, int $port, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations) use ($triggerMigration) {
|
||||
$migration = $dbForProject->createDocument('migrations', new Document([
|
||||
'$id' => ID::unique(),
|
||||
'status' => 'pending',
|
||||
@@ -365,10 +401,10 @@ App::post('/v1/migrations/nhost')
|
||||
|
||||
// Trigger Transfer
|
||||
$queueForMigrations
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
->setUser($user);
|
||||
|
||||
$triggerMigration($migration, $resources, $queueForMigrations, $dbForProject);
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_ACCEPTED)
|
||||
|
||||
@@ -735,6 +735,104 @@ Database::addFilter(
|
||||
}
|
||||
);
|
||||
|
||||
Database::addFilter(
|
||||
'subQueryMigrationStatus',
|
||||
function (mixed $value) {
|
||||
return $value;
|
||||
},
|
||||
function (mixed $value, Document $document, Database $database) {
|
||||
$groups = $database->find('migrationsGroup', [
|
||||
Query::equal('migrationInternalId', [$document->getInternalId()]),
|
||||
]);
|
||||
|
||||
$status = 'pending';
|
||||
|
||||
foreach ($groups as $document) {
|
||||
if ($document->getAttribute('status') === 'processing') {
|
||||
$status = 'processing';
|
||||
break;
|
||||
}
|
||||
|
||||
if ($document->getAttribute('status') === 'failed') {
|
||||
$status = 'failed';
|
||||
break;
|
||||
}
|
||||
|
||||
if ($document->getAttribute('status') === 'completed') {
|
||||
$status = 'completed';
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
);
|
||||
|
||||
Database::addFilter(
|
||||
'subQueryStatusCounters',
|
||||
function (mixed $value) {
|
||||
return;
|
||||
},
|
||||
function (mixed $value, Document $document, Database $database) {
|
||||
$groups = $database->find('migrationsGroup', [
|
||||
Query::equal('migrationInternalId', [$document->getInternalId()]),
|
||||
]);
|
||||
|
||||
$statusCounter = [];
|
||||
|
||||
foreach ($groups as $document) {
|
||||
$data = $document->getAttribute('statusCounters');
|
||||
|
||||
$statusCounter = array_merge($statusCounter, $data);
|
||||
}
|
||||
|
||||
return $statusCounter;
|
||||
}
|
||||
);
|
||||
|
||||
Database::addFilter(
|
||||
'subQueryResourceData',
|
||||
function (mixed $value) {
|
||||
return;
|
||||
},
|
||||
function (mixed $value, Document $document, Database $database) {
|
||||
$groups = $database->find('migrationsGroup', [
|
||||
Query::equal('migrationInternalId', [$document->getInternalId()]),
|
||||
]);
|
||||
|
||||
$resourceData = [];
|
||||
|
||||
foreach ($groups as $document) {
|
||||
$data = $document->getAttribute('resourceData');
|
||||
|
||||
$resourceData = array_merge($resourceData, $data);
|
||||
}
|
||||
|
||||
return $resourceData;
|
||||
}
|
||||
);
|
||||
|
||||
Database::addFilter(
|
||||
'subQueryMigrationErrors',
|
||||
function (mixed $value) {
|
||||
return;
|
||||
},
|
||||
function (mixed $value, Document $document, Database $database) {
|
||||
$groups = $database->find('migrationsGroup', [
|
||||
Query::equal('migrationInternalId', [$document->getInternalId()]),
|
||||
]);
|
||||
|
||||
$errors = [];
|
||||
|
||||
foreach ($groups as $document) {
|
||||
$data = $document->getAttribute('errors');
|
||||
|
||||
$errors = array_merge($errors, $data);
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* DB Formats
|
||||
*/
|
||||
|
||||
Generated
+7
-7
@@ -4068,23 +4068,23 @@
|
||||
},
|
||||
{
|
||||
"name": "phpdocumentor/type-resolver",
|
||||
"version": "1.8.2",
|
||||
"version": "1.9.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpDocumentor/TypeResolver.git",
|
||||
"reference": "153ae662783729388a584b4361f2545e4d841e3c"
|
||||
"reference": "1fb5ba8d045f5dd984ebded5b1cc66f29459422d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/153ae662783729388a584b4361f2545e4d841e3c",
|
||||
"reference": "153ae662783729388a584b4361f2545e4d841e3c",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/1fb5ba8d045f5dd984ebded5b1cc66f29459422d",
|
||||
"reference": "1fb5ba8d045f5dd984ebded5b1cc66f29459422d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"doctrine/deprecations": "^1.0",
|
||||
"php": "^7.3 || ^8.0",
|
||||
"phpdocumentor/reflection-common": "^2.0",
|
||||
"phpstan/phpdoc-parser": "^1.13"
|
||||
"phpstan/phpdoc-parser": "^1.18"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-tokenizer": "*",
|
||||
@@ -4120,9 +4120,9 @@
|
||||
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
|
||||
"support": {
|
||||
"issues": "https://github.com/phpDocumentor/TypeResolver/issues",
|
||||
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.2"
|
||||
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.9.0"
|
||||
},
|
||||
"time": "2024-02-23T11:10:43+00:00"
|
||||
"time": "2024-11-03T20:11:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpspec/prophecy",
|
||||
|
||||
+1
-2
@@ -660,6 +660,7 @@ services:
|
||||
environment:
|
||||
- _APP_ENV
|
||||
- _APP_WORKER_PER_CORE
|
||||
- _APP_WORKERS_NUM=8
|
||||
- _APP_OPENSSL_KEY_V1
|
||||
- _APP_DOMAIN
|
||||
- _APP_DOMAIN_TARGET
|
||||
@@ -674,8 +675,6 @@ services:
|
||||
- _APP_DB_USER
|
||||
- _APP_DB_PASS
|
||||
- _APP_LOGGING_CONFIG
|
||||
- _APP_MIGRATIONS_FIREBASE_CLIENT_ID
|
||||
- _APP_MIGRATIONS_FIREBASE_CLIENT_SECRET
|
||||
- _APP_DATABASE_SHARED_TABLES
|
||||
|
||||
appwrite-task-maintenance:
|
||||
|
||||
@@ -11,6 +11,11 @@ class Migration extends Event
|
||||
protected string $type = '';
|
||||
protected ?Document $migration = null;
|
||||
|
||||
public const TYPE_AUTH = 'Auth';
|
||||
public const TYPE_DATABASES = 'Databases';
|
||||
public const TYPE_STORAGE = 'Storage';
|
||||
public const TYPE_FUNCTIONS = 'Functions';
|
||||
|
||||
public function __construct(protected Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
|
||||
@@ -157,17 +157,27 @@ class Migrations extends Action
|
||||
* @throws \Utopia\Database\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function updateMigrationDocument(Document $migration, Document $project): Document
|
||||
protected function updateDocument(Document $document): Document
|
||||
{
|
||||
$migrationId = $document->getId();
|
||||
|
||||
if ($document->getCollection() === 'migrationsGroup') {
|
||||
$migrationId = $document->getAttribute('migrationId');
|
||||
}
|
||||
|
||||
$document = $this->dbForProject->updateDocument($document->getCollection(), $document->getId(), $document);
|
||||
|
||||
$migration = $this->dbForProject->getDocument('migrations', $migrationId);
|
||||
|
||||
/** Trigger Realtime */
|
||||
$allEvents = Event::generateEvents('migrations.[migrationId].update', [
|
||||
'migrationId' => $migration->getId(),
|
||||
'migrationId' => $migrationId,
|
||||
]);
|
||||
|
||||
$target = Realtime::fromPayload(
|
||||
event: $allEvents[0],
|
||||
payload: $migration,
|
||||
project: $project
|
||||
project: $this->project
|
||||
);
|
||||
|
||||
Realtime::send(
|
||||
@@ -179,14 +189,14 @@ class Migrations extends Action
|
||||
);
|
||||
|
||||
Realtime::send(
|
||||
projectId: $project->getId(),
|
||||
projectId: $this->project->getId(),
|
||||
payload: $migration->getArrayCopy(),
|
||||
events: $allEvents,
|
||||
channels: $target['channels'],
|
||||
roles: $target['roles'],
|
||||
);
|
||||
|
||||
return $this->dbForProject->updateDocument('migrations', $migration->getId(), $migration);
|
||||
return $document;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,7 +269,7 @@ class Migrations extends Action
|
||||
* @throws \Utopia\Database\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function processMigration(Document $migration, Log $log): void
|
||||
protected function processMigration(Document $group, Log $log): void
|
||||
{
|
||||
$project = $this->project;
|
||||
$projectDocument = $this->dbForConsole->getDocument('projects', $project->getId());
|
||||
@@ -268,7 +278,8 @@ class Migrations extends Action
|
||||
$transfer = $source = $destination = null;
|
||||
|
||||
try {
|
||||
$migration = $this->dbForProject->getDocument('migrations', $migration->getId());
|
||||
$group = $this->dbForProject->getDocument('migrationsGroup', $group->getId());
|
||||
$migration = $this->dbForProject->getDocument('migrations', $group->getAttribute('migrationId', ''));
|
||||
|
||||
if (
|
||||
$migration->getAttribute('source') === SourceAppwrite::getName() &&
|
||||
@@ -283,9 +294,10 @@ class Migrations extends Action
|
||||
$migration->setAttribute('credentials', $credentials);
|
||||
}
|
||||
|
||||
$migration->setAttribute('stage', 'processing');
|
||||
$group->setAttribute('status', 'processing');
|
||||
$migration->setAttribute('status', 'processing');
|
||||
$this->updateMigrationDocument($migration, $projectDocument);
|
||||
$this->updateDocument($migration);
|
||||
$this->updateDocument($group);
|
||||
|
||||
$log->addTag('type', $migration->getAttribute('source'));
|
||||
|
||||
@@ -300,15 +312,12 @@ class Migrations extends Action
|
||||
);
|
||||
|
||||
/** Start Transfer */
|
||||
$migration->setAttribute('stage', 'migrating');
|
||||
$this->updateMigrationDocument($migration, $projectDocument);
|
||||
|
||||
$transfer->run(
|
||||
$migration->getAttribute('resources'),
|
||||
function () use ($migration, $transfer, $projectDocument) {
|
||||
$migration->setAttribute('resourceData', json_encode($transfer->getCache()));
|
||||
$migration->setAttribute('statusCounters', json_encode($transfer->getStatusCounters()));
|
||||
$this->updateMigrationDocument($migration, $projectDocument);
|
||||
$group->getAttribute('resources'),
|
||||
function () use ($group, $transfer) {
|
||||
$group->setAttribute('resourceData', json_encode($transfer->getCache()));
|
||||
$group->setAttribute('statusCounters', json_encode($transfer->getStatusCounters()));
|
||||
$this->updateDocument($group);
|
||||
},
|
||||
$migration->getAttribute('resourceId'),
|
||||
$migration->getAttribute('resourceType')
|
||||
@@ -321,12 +330,11 @@ class Migrations extends Action
|
||||
$destinationErrors = $destination->getErrors();
|
||||
|
||||
if (! empty($sourceErrors) || ! empty($destinationErrors)) {
|
||||
$migration->setAttribute('status', 'failed');
|
||||
$migration->setAttribute('stage', 'finished');
|
||||
$group->setAttribute('status', 'failed');
|
||||
|
||||
$errorMessages = [];
|
||||
foreach ($sourceErrors as $error) {
|
||||
/** @var $sourceErrors $error */
|
||||
/** @var MigrationException $error */
|
||||
$message = "Error occurred while fetching '{$error->getResourceName()}:{$error->getResourceId()}' from source with message: '{$error->getMessage()}'";
|
||||
if ($error->getPrevious()) {
|
||||
$message .= " Message: ".$error->getPrevious()->getMessage() . " File: ".$error->getPrevious()->getFile() . " Line: ".$error->getPrevious()->getLine();
|
||||
@@ -345,23 +353,21 @@ class Migrations extends Action
|
||||
$errorMessages[] = $message;
|
||||
}
|
||||
|
||||
$migration->setAttribute('errors', $errorMessages);
|
||||
$group->setAttribute('errors', $errorMessages);
|
||||
$log->addExtra('migrationErrors', json_encode($errorMessages));
|
||||
$this->updateMigrationDocument($migration, $projectDocument);
|
||||
$this->updateDocument($group);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$migration->setAttribute('status', 'completed');
|
||||
$migration->setAttribute('stage', 'finished');
|
||||
$group->setAttribute('status', 'completed');
|
||||
} catch (\Throwable $th) {
|
||||
Console::error($th->getMessage());
|
||||
Console::error($th->getTraceAsString());
|
||||
|
||||
if (! $migration->isEmpty()) {
|
||||
$migration->setAttribute('status', 'failed');
|
||||
$migration->setAttribute('stage', 'finished');
|
||||
$migration->setAttribute('errors', [$th->getMessage()]);
|
||||
$group->setAttribute('status', 'failed');
|
||||
$group->setAttribute('errors', [$th->getMessage()]);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -380,7 +386,7 @@ class Migrations extends Action
|
||||
$errorMessages[] = "Error occurred while pushing '{$error->getResourceName()}:{$error->getResourceId()}' to destination with message '{$error->getMessage()}'";
|
||||
}
|
||||
|
||||
$migration->setAttribute('errors', $errorMessages);
|
||||
$group->setAttribute('errors', $errorMessages);
|
||||
$log->addTag('migrationErrors', json_encode($errorMessages));
|
||||
}
|
||||
} finally {
|
||||
@@ -388,9 +394,10 @@ class Migrations extends Action
|
||||
$this->removeAPIKey($tempAPIKey);
|
||||
}
|
||||
|
||||
$this->updateMigrationDocument($migration, $projectDocument);
|
||||
$this->updateDocument($migration);
|
||||
$this->updateDocument($group);
|
||||
|
||||
if ($migration->getAttribute('status', '') === 'failed') {
|
||||
if ($group->getAttribute('status', '') === 'failed') {
|
||||
Console::error('Migration('.$migration->getInternalId().':'.$migration->getId().') failed, Project('.$this->project->getInternalId().':'.$this->project->getId().')');
|
||||
|
||||
$destination->error();
|
||||
@@ -399,10 +406,10 @@ class Migrations extends Action
|
||||
throw new Exception('Migration failed');
|
||||
}
|
||||
|
||||
if ($migration->getAttribute('status', '') === 'completed') {
|
||||
if ($group->getAttribute('status', '') === 'completed') {
|
||||
$destination->success();
|
||||
$source->success();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ class Migrations extends Base
|
||||
{
|
||||
public const ALLOWED_ATTRIBUTES = [
|
||||
'status',
|
||||
'stage',
|
||||
'source',
|
||||
'destination',
|
||||
'resources',
|
||||
|
||||
@@ -34,12 +34,6 @@ class Migration extends Model
|
||||
'default' => '',
|
||||
'example' => 'pending',
|
||||
])
|
||||
->addRule('stage', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Migration stage ( init, processing, source-check, destination-check, migrating, finished )',
|
||||
'default' => '',
|
||||
'example' => 'init',
|
||||
])
|
||||
->addRule('source', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'A string containing the type of source of the migration.',
|
||||
|
||||
Reference in New Issue
Block a user