mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Rename Service to Migrations
This commit is contained in:
@@ -3581,10 +3581,10 @@ $collections = [
|
||||
],
|
||||
],
|
||||
|
||||
'imports' => [
|
||||
'migrations' => [
|
||||
'$collection' => ID::custom(Database::METADATA),
|
||||
'$id' => ID::custom('imports'),
|
||||
'name' => 'Imports',
|
||||
'$id' => ID::custom('migrations'),
|
||||
'name' => 'Migrations',
|
||||
'attributes' => [
|
||||
[
|
||||
'$id' => ID::custom('status'),
|
||||
|
||||
@@ -238,7 +238,7 @@ return [
|
||||
]
|
||||
],
|
||||
'imports' => [
|
||||
'$model' => Response::MODEL_IMPORT,
|
||||
'$model' => Response::MODEL_MIGRATION,
|
||||
'$resource' => true,
|
||||
'$description' => 'This event triggers on any imports event.',
|
||||
'create' => [
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
use Appwrite\Event\Delete;
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Event\Import;
|
||||
use Appwrite\Event\Migration;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Appwrite\Utopia\Database\Validator\Queries\Imports;
|
||||
use Appwrite\Utopia\Database\Validator\Queries\Migrations;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\App;
|
||||
use Utopia\Database\Database;
|
||||
@@ -21,18 +23,18 @@ use Utopia\Validator\WhiteList;
|
||||
|
||||
include_once __DIR__ . '/../shared/api.php';
|
||||
|
||||
App::get('/v1/imports')
|
||||
->groups(['api', 'imports'])
|
||||
->desc('List Imports')
|
||||
->label('scope', 'imports.read')
|
||||
App::get('/v1/migrations')
|
||||
->groups(['api', 'migrations'])
|
||||
->desc('List Migrations')
|
||||
->label('scope', 'migrations.read')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'imports')
|
||||
->label('sdk.namespace', 'migrations')
|
||||
->label('sdk.method', 'list')
|
||||
->label('sdk.description', '/docs/references/imports/list-imports.md')
|
||||
->label('sdk.description', '/docs/references/migrations/list-migrations.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_IMPORT_LIST)
|
||||
->param('queries', [], new Imports(), 'Array of query strings generated using the Query class provided by the SDK. [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. You may filter on the following attributes: ' . implode(', ', Imports::ALLOWED_ATTRIBUTES), true)
|
||||
->label('sdk.response.model', Response::MODEL_MIGRATION_LIST)
|
||||
->param('queries', [], new Migrations(), 'Array of query strings generated using the Query class provided by the SDK. [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. You may filter on the following attributes: ' . implode(', ', Migrations::ALLOWED_ATTRIBUTES), true)
|
||||
->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true)
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
@@ -49,11 +51,11 @@ App::get('/v1/imports')
|
||||
$cursor = reset($cursor);
|
||||
if ($cursor) {
|
||||
/** @var Query $cursor */
|
||||
$importId = $cursor->getValue();
|
||||
$cursorDocument = $dbForProject->getDocument('imports', $importId);
|
||||
$migrationId = $cursor->getValue();
|
||||
$cursorDocument = $dbForProject->getDocument('migrations', $migrationId);
|
||||
|
||||
if ($cursorDocument->isEmpty()) {
|
||||
throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Import '{$importId}' for the 'cursor' value not found.");
|
||||
throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Import '{$migrationId}' for the 'cursor' value not found.");
|
||||
}
|
||||
|
||||
$cursor->setValue($cursorDocument);
|
||||
@@ -62,74 +64,74 @@ App::get('/v1/imports')
|
||||
$filterQueries = Query::groupByType($queries)['filters'];
|
||||
|
||||
$response->dynamic(new Document([
|
||||
'imports' => $dbForProject->find('imports', $queries),
|
||||
'total' => $dbForProject->count('imports', $filterQueries, APP_LIMIT_COUNT),
|
||||
]), Response::MODEL_IMPORT_LIST);
|
||||
'migrations' => $dbForProject->find('migrations', $queries),
|
||||
'total' => $dbForProject->count('migrations', $filterQueries, APP_LIMIT_COUNT),
|
||||
]), Response::MODEL_MIGRATION_LIST);
|
||||
});
|
||||
|
||||
App::get('/v1/imports/:importId')
|
||||
->groups(['api', 'imports'])
|
||||
App::get('/v1/migrations/:migrationId')
|
||||
->groups(['api', 'migrations'])
|
||||
->desc('Get Import')
|
||||
->label('scope', 'imports.read')
|
||||
->label('scope', 'migrations.read')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'imports')
|
||||
->label('sdk.namespace', 'migrations')
|
||||
->label('sdk.method', 'get')
|
||||
->label('sdk.description', '/docs/references/imports/get-import.md')
|
||||
->label('sdk.description', '/docs/references/migrations/get-migration.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_IMPORT)
|
||||
->param('importId', '', new UID(), 'Import unique ID.')
|
||||
->label('sdk.response.model', Response::MODEL_MIGRATION)
|
||||
->param('migrationId', '', new UID(), 'Import unique ID.')
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->action(function (string $importId, Response $response, Database $dbForProject) {
|
||||
$import = $dbForProject->getDocument('imports', $importId);
|
||||
->action(function (string $migrationId, Response $response, Database $dbForProject) {
|
||||
$migration = $dbForProject->getDocument('migrations', $migrationId);
|
||||
|
||||
if ($import->isEmpty()) {
|
||||
if ($migration->isEmpty()) {
|
||||
throw new Exception(Exception::IMPORT_NOT_FOUND, 'Import not found', 404);
|
||||
}
|
||||
|
||||
$response->dynamic($import, Response::MODEL_IMPORT);
|
||||
$response->dynamic($migration, Response::MODEL_MIGRATION);
|
||||
});
|
||||
|
||||
App::post('/v1/imports/:importId')
|
||||
->groups(['api', 'imports'])
|
||||
App::post('/v1/migrations/:migrationId')
|
||||
->groups(['api', 'migrations'])
|
||||
->desc('Retry Import')
|
||||
->label('scope', 'imports.write')
|
||||
->label('event', 'imports.[importId].retry')
|
||||
->label('audits.event', 'import.retry')
|
||||
->label('audits.resource', 'imports/{request.importId}')
|
||||
->label('scope', 'migrations.write')
|
||||
->label('event', 'migrations.[migrationId].retry')
|
||||
->label('audits.event', 'migration.retry')
|
||||
->label('audits.resource', 'migrations/{request.migrationId}')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'imports')
|
||||
->label('sdk.namespace', 'migrations')
|
||||
->label('sdk.method', 'retry')
|
||||
->label('sdk.description', '/docs/references/imports/retry-import.md')
|
||||
->label('sdk.description', '/docs/references/migrations/retry-migration.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_IMPORT)
|
||||
->param('importId', '', new UID(), 'Import unique ID.')
|
||||
->label('sdk.response.model', Response::MODEL_MIGRATION)
|
||||
->param('migrationId', '', new UID(), 'Migration unique ID.')
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('project')
|
||||
->inject('user')
|
||||
->inject('events')
|
||||
->action(function (string $importId, Response $response, Database $dbForProject, Document $project, Document $user, Event $eventInstance) {
|
||||
$import = $dbForProject->getDocument('imports', $importId);
|
||||
->action(function (string $migrationId, Response $response, Database $dbForProject, Document $project, Document $user, Event $eventInstance) {
|
||||
$migration = $dbForProject->getDocument('migrations', $migrationId);
|
||||
|
||||
if ($import->isEmpty()) {
|
||||
if ($migration->isEmpty()) {
|
||||
throw new Exception(Exception::IMPORT_NOT_FOUND);
|
||||
}
|
||||
|
||||
// if ($import->getAttribute('status') !== 'failed') {
|
||||
// if ($migration->getAttribute('status') !== 'failed') {
|
||||
// throw new Exception(Exception::IMPORT_IN_PROGRESS, 'Import not failed');
|
||||
// }
|
||||
|
||||
$import
|
||||
$migration
|
||||
->setAttribute('status', 'pending')
|
||||
->setAttribute('dateUpdated', \time());
|
||||
|
||||
// Trigger Import
|
||||
$event = new Import();
|
||||
$event = new Migration();
|
||||
$event
|
||||
->setImport($import)
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
@@ -137,59 +139,59 @@ App::post('/v1/imports/:importId')
|
||||
$response->noContent();
|
||||
});
|
||||
|
||||
App::delete('/v1/imports/:importId')
|
||||
->groups(['api', 'imports'])
|
||||
App::delete('/v1/migrations/:migrationId')
|
||||
->groups(['api', 'migrations'])
|
||||
->desc('Delete Import')
|
||||
->label('scope', 'imports.write')
|
||||
->label('event', 'imports.[importId].delete')
|
||||
->label('audits.event', 'importId.delete')
|
||||
->label('audits.resource', 'imports/{request.importId}')
|
||||
->label('scope', 'migrations.write')
|
||||
->label('event', 'migrations.[migrationId].delete')
|
||||
->label('audits.event', 'migrationId.delete')
|
||||
->label('audits.resource', 'migrations/{request.migrationId}')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'imports')
|
||||
->label('sdk.namespace', 'migrations')
|
||||
->label('sdk.method', 'delete')
|
||||
->label('sdk.description', '/docs/references/functions/delete-import.md')
|
||||
->label('sdk.description', '/docs/references/functions/delete-migration.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT)
|
||||
->label('sdk.response.model', Response::MODEL_NONE)
|
||||
->param('importId', '', new UID(), 'Import ID.')
|
||||
->param('migrationId', '', new UID(), 'Import ID.')
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('deletes')
|
||||
->inject('events')
|
||||
->action(function (string $importId, Response $response, Database $dbForProject, Delete $deletes, Event $events) {
|
||||
->action(function (string $migrationId, Response $response, Database $dbForProject, Delete $deletes, Event $events) {
|
||||
|
||||
$import = $dbForProject->getDocument('imports', $importId);
|
||||
$migration = $dbForProject->getDocument('migrations', $migrationId);
|
||||
|
||||
if ($import->isEmpty()) {
|
||||
if ($migration->isEmpty()) {
|
||||
throw new Exception(Exception::IMPORT_NOT_FOUND, 'Import not found', 404);
|
||||
}
|
||||
|
||||
if (!$dbForProject->deleteDocument('imports', $import->getId())) {
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove import from DB', 500);
|
||||
if (!$dbForProject->deleteDocument('migrations', $migration->getId())) {
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove migration from DB', 500);
|
||||
}
|
||||
|
||||
$deletes
|
||||
->setType(DELETE_TYPE_DOCUMENT)
|
||||
->setDocument($import);
|
||||
->setDocument($migration);
|
||||
|
||||
$events->setParam('importId', $import->getId());
|
||||
$events->setParam('migrationId', $migration->getId());
|
||||
|
||||
$response->noContent();
|
||||
});
|
||||
|
||||
App::post('/v1/imports/appwrite')
|
||||
->groups(['api', 'imports'])
|
||||
App::post('/v1/migrations/appwrite')
|
||||
->groups(['api', 'migrations'])
|
||||
->desc('Import Appwrite Data')
|
||||
->label('scope', 'imports.write')
|
||||
->label('event', 'imports.create')
|
||||
->label('audits.event', 'import.create')
|
||||
->label('scope', 'migrations.write')
|
||||
->label('event', 'migrations.create')
|
||||
->label('audits.event', 'migration.create')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'imports')
|
||||
->label('sdk.method', 'importAppwrite')
|
||||
->label('sdk.description', '/docs/references/imports/import-appwrite.md')
|
||||
->label('sdk.namespace', 'migrations')
|
||||
->label('sdk.method', 'migrationAppwrite')
|
||||
->label('sdk.description', '/docs/references/migrations/migration-appwrite.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_IMPORT)
|
||||
->param('resources', [], new ArrayList(new WhiteList(Transfer::ALL_PUBLIC_RESOURCES)), 'List of resources to import')
|
||||
->label('sdk.response.model', Response::MODEL_MIGRATION)
|
||||
->param('resources', [], new ArrayList(new WhiteList(Transfer::ALL_PUBLIC_RESOURCES)), 'List of resources to migration')
|
||||
->param('endpoint', '', new URL(), "Source's Appwrite Endpoint")
|
||||
->param('projectId', '', new UID(), "Source's Project ID")
|
||||
->param('apiKey', '', new Text(512), "Source's API Key")
|
||||
@@ -199,7 +201,7 @@ App::post('/v1/imports/appwrite')
|
||||
->inject('user')
|
||||
->inject('events')
|
||||
->action(function (array $resources, string $endpoint, string $projectId, string $apiKey, Response $response, Database $dbForProject, Document $project, Document $user, Event $eventsInstance) {
|
||||
$import = $dbForProject->createDocument('imports', new Document([
|
||||
$migration = $dbForProject->createDocument('migrations', new Document([
|
||||
'$id' => ID::unique(),
|
||||
'status' => 'pending',
|
||||
'stage' => 'init',
|
||||
@@ -215,35 +217,35 @@ App::post('/v1/imports/appwrite')
|
||||
'errorData' => ""
|
||||
]));
|
||||
|
||||
$eventsInstance->setParam('importId', $import->getId());
|
||||
$eventsInstance->setParam('migrationId', $migration->getId());
|
||||
|
||||
// Trigger Transfer
|
||||
$event = new Import();
|
||||
$event = new Migration();
|
||||
$event
|
||||
->setImport($import)
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->dynamic($import, Response::MODEL_IMPORT);
|
||||
->dynamic($migration, Response::MODEL_MIGRATION);
|
||||
});
|
||||
|
||||
App::post('/v1/imports/firebase')
|
||||
->groups(['api', 'imports'])
|
||||
App::post('/v1/migrations/firebase')
|
||||
->groups(['api', 'migrations'])
|
||||
->desc('Import Firebase Data')
|
||||
->label('scope', 'imports.write')
|
||||
->label('event', 'imports.create')
|
||||
->label('audits.event', 'import.create')
|
||||
->label('scope', 'migrations.write')
|
||||
->label('event', 'migrations.create')
|
||||
->label('audits.event', 'migration.create')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'imports')
|
||||
->label('sdk.method', 'importFirebase')
|
||||
->label('sdk.description', '/docs/references/imports/import-firebase.md')
|
||||
->label('sdk.namespace', 'migrations')
|
||||
->label('sdk.method', 'migrationFirebase')
|
||||
->label('sdk.description', '/docs/references/migrations/migration-firebase.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_IMPORT)
|
||||
->param('resources', [], new ArrayList(new WhiteList(Transfer::ALL_PUBLIC_RESOURCES)), 'List of resources to import')
|
||||
->label('sdk.response.model', Response::MODEL_MIGRATION)
|
||||
->param('resources', [], new ArrayList(new WhiteList(Transfer::ALL_PUBLIC_RESOURCES)), 'List of resources to migration')
|
||||
->param('serviceAccount', '', new Text(512), "Source's Service Account")
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
@@ -251,7 +253,7 @@ App::post('/v1/imports/firebase')
|
||||
->inject('user')
|
||||
->inject('events')
|
||||
->action(function (array $resources, string $serviceAccount, Response $response, Database $dbForProject, Document $project, Document $user, Event $eventsInstance) {
|
||||
$import = $dbForProject->createDocument('imports', new Document([
|
||||
$migration = $dbForProject->createDocument('migrations', new Document([
|
||||
'$id' => ID::unique(),
|
||||
'status' => 'pending',
|
||||
'stage' => 'init',
|
||||
@@ -265,35 +267,35 @@ App::post('/v1/imports/firebase')
|
||||
'errorData' => ""
|
||||
]));
|
||||
|
||||
$eventsInstance->setParam('importId', $import->getId());
|
||||
$eventsInstance->setParam('migrationId', $migration->getId());
|
||||
|
||||
// Trigger Transfer
|
||||
$event = new Import();
|
||||
$event = new Migration();
|
||||
$event
|
||||
->setImport($import)
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->dynamic($import, Response::MODEL_IMPORT);
|
||||
->dynamic($migration, Response::MODEL_MIGRATION);
|
||||
});
|
||||
|
||||
App::post('/v1/imports/supabase')
|
||||
->groups(['api', 'imports'])
|
||||
App::post('/v1/migrations/supabase')
|
||||
->groups(['api', 'migrations'])
|
||||
->desc('Import Supabase Data')
|
||||
->label('scope', 'imports.write')
|
||||
->label('event', 'imports.create')
|
||||
->label('audits.event', 'import.create')
|
||||
->label('scope', 'migrations.write')
|
||||
->label('event', 'migrations.create')
|
||||
->label('audits.event', 'migration.create')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'imports')
|
||||
->label('sdk.method', 'importSupabase')
|
||||
->label('sdk.description', '/docs/references/imports/import-supabase.md')
|
||||
->label('sdk.namespace', 'migrations')
|
||||
->label('sdk.method', 'migrationSupabase')
|
||||
->label('sdk.description', '/docs/references/migrations/migration-supabase.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_IMPORT)
|
||||
->param('resources', [], new ArrayList(new WhiteList(Transfer::ALL_PUBLIC_RESOURCES)), 'List of resources to import')
|
||||
->label('sdk.response.model', Response::MODEL_MIGRATION)
|
||||
->param('resources', [], new ArrayList(new WhiteList(Transfer::ALL_PUBLIC_RESOURCES)), 'List of resources to migration')
|
||||
->param('endpoint', '', new URL(), "Source's Supabase Endpoint")
|
||||
->param('apiKey', '', new Text(512), "Source's API Key")
|
||||
->param('databaseHost', '', new Text(512), "Source's Database Host")
|
||||
@@ -306,7 +308,7 @@ App::post('/v1/imports/supabase')
|
||||
->inject('user')
|
||||
->inject('events')
|
||||
->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 $eventsInstance) {
|
||||
$import = $dbForProject->createDocument('imports', new Document([
|
||||
$migration = $dbForProject->createDocument('migrations', new Document([
|
||||
'$id' => ID::unique(),
|
||||
'status' => 'pending',
|
||||
'stage' => 'init',
|
||||
@@ -325,35 +327,35 @@ App::post('/v1/imports/supabase')
|
||||
'errorData' => ""
|
||||
]));
|
||||
|
||||
$eventsInstance->setParam('importId', $import->getId());
|
||||
$eventsInstance->setParam('migrationId', $migration->getId());
|
||||
|
||||
// Trigger Transfer
|
||||
$event = new Import();
|
||||
$event = new Migration();
|
||||
$event
|
||||
->setImport($import)
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->dynamic($import, Response::MODEL_IMPORT);
|
||||
->dynamic($migration, Response::MODEL_MIGRATION);
|
||||
});
|
||||
|
||||
App::post('/v1/imports/nhost')
|
||||
->groups(['api', 'imports'])
|
||||
App::post('/v1/migrations/nhost')
|
||||
->groups(['api', 'migrations'])
|
||||
->desc('Import NHost Data')
|
||||
->label('scope', 'imports.write')
|
||||
->label('event', 'imports.create')
|
||||
->label('audits.event', 'import.create')
|
||||
->label('scope', 'migrations.write')
|
||||
->label('event', 'migrations.create')
|
||||
->label('audits.event', 'migration.create')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'imports')
|
||||
->label('sdk.method', 'importNhost')
|
||||
->label('sdk.description', '/docs/references/imports/import-nhost.md')
|
||||
->label('sdk.namespace', 'migrations')
|
||||
->label('sdk.method', 'migrationNhost')
|
||||
->label('sdk.description', '/docs/references/migrations/migration-nhost.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_IMPORT)
|
||||
->param('resources', [], new ArrayList(new WhiteList(Transfer::ALL_PUBLIC_RESOURCES)), 'List of resources to import')
|
||||
->label('sdk.response.model', Response::MODEL_MIGRATION)
|
||||
->param('resources', [], new ArrayList(new WhiteList(Transfer::ALL_PUBLIC_RESOURCES)), 'List of resources to migration')
|
||||
->param('subdomain', '', new URL(), "Source's Subdomain")
|
||||
->param('region', '', new Text(512), "Source's Region")
|
||||
->param('adminSecret', '', new Text(512), "Source's Admin Secret")
|
||||
@@ -367,7 +369,7 @@ App::post('/v1/imports/nhost')
|
||||
->inject('user')
|
||||
->inject('events')
|
||||
->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 $eventsInstance) {
|
||||
$import = $dbForProject->createDocument('imports', new Document([
|
||||
$migration = $dbForProject->createDocument('migrations', new Document([
|
||||
'$id' => ID::unique(),
|
||||
'status' => 'pending',
|
||||
'stage' => 'init',
|
||||
@@ -387,17 +389,17 @@ App::post('/v1/imports/nhost')
|
||||
'errorData' => ""
|
||||
]));
|
||||
|
||||
$eventsInstance->setParam('importId', $import->getId());
|
||||
$eventsInstance->setParam('migrationId', $migration->getId());
|
||||
|
||||
// Trigger Transfer
|
||||
$event = new Import();
|
||||
$event = new Migration();
|
||||
$event
|
||||
->setImport($import)
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->dynamic($import, Response::MODEL_IMPORT);
|
||||
->dynamic($migration, Response::MODEL_MIGRATION);
|
||||
});
|
||||
@@ -7,7 +7,7 @@ use Appwrite\Permission;
|
||||
use Appwrite\Query;
|
||||
use Appwrite\Resque\Worker;
|
||||
use Appwrite\Role;
|
||||
use Appwrite\Utopia\Response\Model\Import;
|
||||
use Appwrite\Utopia\Response\Model\Migration;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
@@ -23,10 +23,10 @@ use Utopia\Transfer\Transfer;
|
||||
|
||||
require_once __DIR__ . '/../init.php';
|
||||
|
||||
Console::title('Imports V1 Worker');
|
||||
Console::success(APP_NAME . ' Imports worker v1 has started');
|
||||
Console::title('Migrations V1 Worker');
|
||||
Console::success(APP_NAME . ' Migrations worker v1 has started');
|
||||
|
||||
class ImportsV1 extends Worker
|
||||
class MigrationsV1 extends Worker
|
||||
{
|
||||
/**
|
||||
* Database connection shared across all methods of this file
|
||||
@@ -37,7 +37,7 @@ class ImportsV1 extends Worker
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return "imports";
|
||||
return "migrations";
|
||||
}
|
||||
|
||||
public function init(): void
|
||||
@@ -49,7 +49,7 @@ class ImportsV1 extends Worker
|
||||
$this->dbForProject = $this->getProjectDB($this->args['project']['$id']);
|
||||
|
||||
// Process
|
||||
$this->processImport();
|
||||
$this->processMigration();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,39 +97,39 @@ class ImportsV1 extends Worker
|
||||
}
|
||||
}
|
||||
|
||||
protected function updateImportDocument(Document $import, Document $project): Document
|
||||
protected function updateMigrationDocument(Document $migration, Document $project): Document
|
||||
{
|
||||
// Trigger Webhook
|
||||
$importModel = new Import();
|
||||
$migrationModel = new Migration();
|
||||
|
||||
$importUpdate = new Event(Event::IMPORTS_QUEUE_NAME, Event::IMPORTS_CLASS_NAME);
|
||||
$importUpdate
|
||||
$migrationUpdate = new Event(Event::MIGRATIONS_QUEUE_NAME, Event::MIGRATIONS_CLASS_NAME);
|
||||
$migrationUpdate
|
||||
->setProject($project)
|
||||
->setEvent('imports.[importId].update')
|
||||
->setParam('importId', $import->getId())
|
||||
->setPayload($import->getArrayCopy(array_keys($importModel->getRules())))
|
||||
->setEvent('migrations.[migrationId].update')
|
||||
->setParam('migrationId', $migration->getId())
|
||||
->setPayload($migration->getArrayCopy(array_keys($migrationModel->getRules())))
|
||||
->trigger();
|
||||
|
||||
/** Trigger Realtime */
|
||||
$allEvents = Event::generateEvents('imports.[importId].update', [
|
||||
'importId' => $import->getId(),
|
||||
$allEvents = Event::generateEvents('migrations.[migrationId].update', [
|
||||
'migrationId' => $migration->getId(),
|
||||
]);
|
||||
|
||||
$target = Realtime::fromPayload(
|
||||
event: $allEvents[0],
|
||||
payload: $import,
|
||||
payload: $migration,
|
||||
project: $project
|
||||
);
|
||||
|
||||
Realtime::send(
|
||||
projectId: 'console',
|
||||
payload: $import->getArrayCopy(),
|
||||
payload: $migration->getArrayCopy(),
|
||||
events: $allEvents,
|
||||
channels: $target['channels'],
|
||||
roles: $target['roles'],
|
||||
);
|
||||
|
||||
return $this->dbForProject->updateDocument('imports', $import->getId(), $import);
|
||||
return $this->dbForProject->updateDocument('migrations', $migration->getId(), $migration);
|
||||
}
|
||||
|
||||
protected function removeAPIKey(Document $apiKey)
|
||||
@@ -191,23 +191,23 @@ class ImportsV1 extends Worker
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processImport(): void
|
||||
protected function processMigration(): void
|
||||
{
|
||||
/**
|
||||
* @var Document $importDocument
|
||||
* @var Document $migrationDocument
|
||||
* @var Transfer $transfer
|
||||
*/
|
||||
$importDocument = null;
|
||||
$migrationDocument = null;
|
||||
$transfer = null;
|
||||
$projectDocument = $this->dbForProject->getDocument('projects', $this->args['project']['$id']);
|
||||
$tempAPIKey = $this->generateAPIKey($projectDocument);
|
||||
|
||||
try {
|
||||
$importDocument = $this->dbForProject->getDocument('imports', $this->args['import']['$id']);
|
||||
$importDocument->setAttribute('status', 'processing');
|
||||
$this->updateImportDocument($importDocument, $projectDocument);
|
||||
$migrationDocument = $this->dbForProject->getDocument('migrations', $this->args['migration']['$id']);
|
||||
$migrationDocument->setAttribute('status', 'processing');
|
||||
$this->updateMigrationDocument($migrationDocument, $projectDocument);
|
||||
|
||||
$source = $this->processSource(json_decode($importDocument->getAttribute('source'), true));
|
||||
$source = $this->processSource(json_decode($migrationDocument->getAttribute('source'), true));
|
||||
|
||||
$destination = new DestinationsAppwrite(
|
||||
$projectDocument->getId(),
|
||||
@@ -220,48 +220,48 @@ class ImportsV1 extends Worker
|
||||
$destination
|
||||
);
|
||||
|
||||
$importDocument->setAttribute('status', 'source-check');
|
||||
$this->updateImportDocument($importDocument, $projectDocument);
|
||||
$migrationDocument->setAttribute('status', 'source-check');
|
||||
$this->updateMigrationDocument($migrationDocument, $projectDocument);
|
||||
$source->report();
|
||||
|
||||
$importDocument->setAttribute('status', 'destination-check');
|
||||
$this->updateImportDocument($importDocument, $projectDocument);
|
||||
$migrationDocument->setAttribute('status', 'destination-check');
|
||||
$this->updateMigrationDocument($migrationDocument, $projectDocument);
|
||||
$destination->report();
|
||||
|
||||
/** Start Transfer */
|
||||
$importDocument->setAttribute('status', 'importing');
|
||||
$this->updateImportDocument($importDocument, $projectDocument);
|
||||
$transfer->run($importDocument->getAttribute('resources'), function () use ($importDocument, $transfer, $projectDocument) {
|
||||
$importDocument->setAttribute('resourceData', json_encode($transfer->getResourceCache()));
|
||||
$importDocument->setAttribute('statusCounters', json_encode($transfer->getStatusCounters()));
|
||||
$migrationDocument->setAttribute('status', 'migrating');
|
||||
$this->updateMigrationDocument($migrationDocument, $projectDocument);
|
||||
$transfer->run($migrationDocument->getAttribute('resources'), function () use ($migrationDocument, $transfer, $projectDocument) {
|
||||
$migrationDocument->setAttribute('resourceData', json_encode($transfer->getResourceCache()));
|
||||
$migrationDocument->setAttribute('statusCounters', json_encode($transfer->getStatusCounters()));
|
||||
|
||||
$this->updateImportDocument($importDocument, $projectDocument);
|
||||
$this->updateMigrationDocument($migrationDocument, $projectDocument);
|
||||
});
|
||||
|
||||
$errors = $transfer->getReport(Resource::STATUS_ERROR);
|
||||
|
||||
if (count($errors) > 0) {
|
||||
$importDocument->setAttribute('status', 'failed');
|
||||
$importDocument->setAttribute('errorData', $errors);
|
||||
$this->updateImportDocument($importDocument, $projectDocument);
|
||||
$migrationDocument->setAttribute('status', 'failed');
|
||||
$migrationDocument->setAttribute('errorData', $errors);
|
||||
$this->updateMigrationDocument($migrationDocument, $projectDocument);
|
||||
return;
|
||||
}
|
||||
|
||||
$importDocument->setAttribute('status', 'completed');
|
||||
$importDocument->setAttribute('stage', 'finished');
|
||||
$migrationDocument->setAttribute('status', 'completed');
|
||||
$migrationDocument->setAttribute('stage', 'finished');
|
||||
} catch (\Throwable $th) {
|
||||
Console::error($th->getMessage());
|
||||
|
||||
if ($importDocument) {
|
||||
if ($migrationDocument) {
|
||||
Console::error($th->getMessage());
|
||||
Console::error($th->getTraceAsString());
|
||||
$importDocument->setAttribute('status', 'failed');
|
||||
$importDocument->setAttribute('errorData', $th->getMessage());
|
||||
$migrationDocument->setAttribute('status', 'failed');
|
||||
$migrationDocument->setAttribute('errorData', $th->getMessage());
|
||||
return;
|
||||
}
|
||||
} finally {
|
||||
if ($importDocument) {
|
||||
$this->updateImportDocument($importDocument, $projectDocument);
|
||||
if ($migrationDocument) {
|
||||
$this->updateMigrationDocument($migrationDocument, $projectDocument);
|
||||
}
|
||||
if ($tempAPIKey) {
|
||||
$this->removeAPIKey($tempAPIKey);
|
||||
@@ -35,8 +35,8 @@ class Event
|
||||
public const MESSAGING_QUEUE_NAME = 'v1-messaging';
|
||||
public const MESSAGING_CLASS_NAME = 'MessagingV1';
|
||||
|
||||
public const IMPORTS_QUEUE_NAME = 'v1-imports';
|
||||
public const IMPORTS_CLASS_NAME = 'ImportsV1';
|
||||
public const MIGRATIONS_QUEUE_NAME = 'v1-migrations';
|
||||
public const MIGRATIONS_CLASS_NAME = 'MigrationsV1';
|
||||
|
||||
protected string $queue = '';
|
||||
protected string $class = '';
|
||||
|
||||
@@ -7,41 +7,41 @@ use Resque;
|
||||
use ResqueScheduler;
|
||||
use Utopia\Database\Document;
|
||||
|
||||
class Import extends Event
|
||||
class Migration extends Event
|
||||
{
|
||||
protected string $type = '';
|
||||
protected ?Document $import = null;
|
||||
protected ?Document $migration = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(Event::IMPORTS_QUEUE_NAME, Event::IMPORTS_CLASS_NAME);
|
||||
parent::__construct(Event::MIGRATIONS_QUEUE_NAME, Event::MIGRATIONS_CLASS_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets import document for the import event.
|
||||
* Sets migration document for the migration event.
|
||||
*
|
||||
* @param Document $import
|
||||
* @param Document $migration
|
||||
* @return self
|
||||
*/
|
||||
public function setImport(Document $import): self
|
||||
public function setMigration(Document $migration): self
|
||||
{
|
||||
$this->import = $import;
|
||||
$this->migration = $migration;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns set import document for the function event.
|
||||
* Returns set migration document for the function event.
|
||||
*
|
||||
* @return null|Document
|
||||
*/
|
||||
public function getImport(): ?Document
|
||||
public function getMigration(): ?Document
|
||||
{
|
||||
return $this->import;
|
||||
return $this->migration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets import type for the import event.
|
||||
* Sets migration type for the migration event.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
@@ -55,7 +55,7 @@ class Import extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns set import type for the import event.
|
||||
* Returns set migration type for the migration event.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -65,7 +65,7 @@ class Import extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the import event and sends it to the imports worker.
|
||||
* Executes the migration event and sends it to the migrations worker.
|
||||
*
|
||||
* @return string|bool
|
||||
* @throws \InvalidArgumentException
|
||||
@@ -75,12 +75,12 @@ class Import extends Event
|
||||
return Resque::enqueue($this->queue, $this->class, [
|
||||
'project' => $this->project,
|
||||
'user' => $this->user,
|
||||
'import' => $this->import
|
||||
'migration' => $this->migration
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the import event and schedules it in the imports worker queue.
|
||||
* Schedules the migration event and schedules it in the migrations worker queue.
|
||||
*
|
||||
* @param \DateTime|int $at
|
||||
* @return void
|
||||
@@ -92,7 +92,7 @@ class Import extends Event
|
||||
ResqueScheduler::enqueueAt($at, $this->queue, $this->class, [
|
||||
'project' => $this->project,
|
||||
'user' => $this->user,
|
||||
'import' => $this->import
|
||||
'migration' => $this->migration
|
||||
]);
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Appwrite\Utopia\Database\Validator\Queries;
|
||||
|
||||
class Imports extends Base
|
||||
class Migrations extends Base
|
||||
{
|
||||
public const ALLOWED_ATTRIBUTES = [
|
||||
'status',
|
||||
@@ -20,6 +20,6 @@ class Imports extends Base
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('imports', self::ALLOWED_ATTRIBUTES);
|
||||
parent::__construct('migrations', self::ALLOWED_ATTRIBUTES);
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,7 @@ use Appwrite\Utopia\Response\Model\UsageUsers;
|
||||
use Appwrite\Utopia\Response\Model\Variable;
|
||||
use Appwrite\Utopia\Response\Model\Import;
|
||||
use Appwrite\Utopia\Response\Model\ImportValidationError;
|
||||
use Appwrite\Utopia\Response\Model\Migration;
|
||||
|
||||
/**
|
||||
* @method int getStatusCode()
|
||||
@@ -221,9 +222,9 @@ class Response extends SwooleResponse
|
||||
// Console
|
||||
public const MODEL_CONSOLE_VARIABLES = 'consoleVariables';
|
||||
|
||||
// Imports
|
||||
public const MODEL_IMPORT = 'import';
|
||||
public const MODEL_IMPORT_LIST = 'importList';
|
||||
// Migrations
|
||||
public const MODEL_MIGRATION = 'migration';
|
||||
public const MODEL_MIGRATION_LIST = 'migrationList';
|
||||
public const MODEL_IMPORT_VALIDATION_ERROR = 'importValidationError';
|
||||
|
||||
// Deprecated
|
||||
@@ -287,7 +288,7 @@ class Response extends SwooleResponse
|
||||
->setModel(new BaseList('Phones List', self::MODEL_PHONE_LIST, 'phones', self::MODEL_PHONE))
|
||||
->setModel(new BaseList('Metric List', self::MODEL_METRIC_LIST, 'metrics', self::MODEL_METRIC, true, false))
|
||||
->setModel(new BaseList('Variables List', self::MODEL_VARIABLE_LIST, 'variables', self::MODEL_VARIABLE))
|
||||
->setModel(new BaseList('Imports List', self::MODEL_IMPORT_LIST, 'imports', self::MODEL_IMPORT))
|
||||
->setModel(new BaseList('Migrations List', self::MODEL_MIGRATION_LIST, 'migrations', self::MODEL_MIGRATION))
|
||||
// Entities
|
||||
->setModel(new Database())
|
||||
->setModel(new Collection())
|
||||
@@ -357,7 +358,7 @@ class Response extends SwooleResponse
|
||||
->setModel(new UsageFunction())
|
||||
->setModel(new UsageProject())
|
||||
->setModel(new ConsoleVariables())
|
||||
->setModel(new Import())
|
||||
->setModel(new Migration())
|
||||
->setModel(new ImportValidationError())
|
||||
// Verification
|
||||
// Recovery
|
||||
|
||||
@@ -23,6 +23,6 @@ class ImportValidationError extends Any
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_IMPORT_VALIDATION_ERROR;
|
||||
return Response::MODEL_MIGRATION_VALIDATION_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ namespace Appwrite\Utopia\Response\Model;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Import extends Model
|
||||
class Migration extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
@@ -91,6 +91,6 @@ class Import extends Model
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_IMPORT;
|
||||
return Response::MODEL_MIGRATION;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user