mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Finish recreate repos docs script
This commit is contained in:
parent
fb6455b783
commit
c133bccfa9
3 changed files with 55 additions and 17 deletions
38
.env
38
.env
|
|
@ -90,12 +90,38 @@ _APP_GRAPHQL_MAX_COMPLEXITY=250
|
||||||
_APP_GRAPHQL_MAX_DEPTH=3
|
_APP_GRAPHQL_MAX_DEPTH=3
|
||||||
_APP_DOCKER_HUB_USERNAME=
|
_APP_DOCKER_HUB_USERNAME=
|
||||||
_APP_DOCKER_HUB_PASSWORD=
|
_APP_DOCKER_HUB_PASSWORD=
|
||||||
_APP_VCS_GITHUB_APP_NAME=
|
_APP_VCS_GITHUB_APP_NAME=appwrite-generated-on-22-5-2023
|
||||||
_APP_VCS_GITHUB_PRIVATE_KEY=disabled
|
_APP_VCS_GITHUB_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
|
||||||
_APP_VCS_GITHUB_APP_ID=
|
MIIEowIBAAKCAQEApUP3k7ratjenwOA1AtnmvZbNIm9Mhu181ryrnb7M1z1/OLUo
|
||||||
_APP_VCS_GITHUB_CLIENT_ID=
|
jZ1iS8u1K/GQtoqCNI8RR38rBXW1hzfC34qAL3XrJr4caK+AKzV7B4y9e2Zn+VlF
|
||||||
_APP_VCS_GITHUB_CLIENT_SECRET=
|
ZZ2rknNPlRLCwll6V60M7suqLONUADs6bvEs8GIR926gwNi8SmomtIj8k8UZFW00
|
||||||
_APP_VCS_GITHUB_WEBHOOK_SECRET=
|
9L0OM0pvajJKASPynZ7jXfxic5Yu060BQq+IAtOkOaxyBF1xiGQRBuAt2movTI2X
|
||||||
|
4PwGcSCy7YD6v2DRgHIoYehtdWx0DrbRgCXsmwMin5BR/7ZhBSJE7YVH9vSqWThe
|
||||||
|
V8VmLKPiZZC5ZW2Vf28kM/FlkCgjfd0tNXs8lQIDAQABAoIBAQCWaFYhODSnE93z
|
||||||
|
ttnoH2JVd7J4PW0be3ZbhNh3t1d8KPbpKE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aUEX5rR9EO3pfrkOmx+zd6c09vtR8g4ZntUTnMyqZp0YgEFnI0REIHnk1
|
||||||
|
7sk0EQKBgGTzNU9Ir6cEZh4j+Qf5rA38bejkD8aRAYg5ozQcbNRJnrC7QnpmZPeD
|
||||||
|
X/E9MZ6wj1BVXEn2oNC63n3QB+B8OhrIDAYDbnaCLzVDl/BTuom3uTCYk0beKncz
|
||||||
|
AurSDpc15RFYjqn0DPBSii/DTaQIz0Rg+seZrOp5Ii2LrSlsnDPf
|
||||||
|
-----END RSA PRIVATE KEY-----"
|
||||||
|
_APP_VCS_GITHUB_APP_ID=337303
|
||||||
|
_APP_VCS_GITHUB_CLIENT_ID=Iv1.306ee38582d3f948
|
||||||
|
_APP_VCS_GITHUB_CLIENT_SECRET=eafc638eaeebe95c0db0fdf59a0a99b9e41832eb
|
||||||
|
_APP_VCS_GITHUB_WEBHOOK_SECRET=gzbrfuenqodiefbrg39u
|
||||||
_APP_MIGRATIONS_FIREBASE_CLIENT_ID=
|
_APP_MIGRATIONS_FIREBASE_CLIENT_ID=
|
||||||
_APP_MIGRATIONS_FIREBASE_CLIENT_SECRET=
|
_APP_MIGRATIONS_FIREBASE_CLIENT_SECRET=
|
||||||
_APP_ASSISTANT_OPENAI_API_KEY=
|
_APP_ASSISTANT_OPENAI_API_KEY=
|
||||||
|
|
@ -19,6 +19,7 @@ use Appwrite\Platform\Tasks\VolumeSync;
|
||||||
use Appwrite\Platform\Tasks\CalcTierStats;
|
use Appwrite\Platform\Tasks\CalcTierStats;
|
||||||
use Appwrite\Platform\Tasks\Upgrade;
|
use Appwrite\Platform\Tasks\Upgrade;
|
||||||
use Appwrite\Platform\Tasks\DeleteOrphanedProjects;
|
use Appwrite\Platform\Tasks\DeleteOrphanedProjects;
|
||||||
|
use Appwrite\Platform\Tasks\PatchRecreateRepositoriesDocuments;
|
||||||
|
|
||||||
class Tasks extends Service
|
class Tasks extends Service
|
||||||
{
|
{
|
||||||
|
|
@ -42,6 +43,7 @@ class Tasks extends Service
|
||||||
->addAction(Specs::getName(), new Specs())
|
->addAction(Specs::getName(), new Specs())
|
||||||
->addAction(CalcTierStats::getName(), new CalcTierStats())
|
->addAction(CalcTierStats::getName(), new CalcTierStats())
|
||||||
->addAction(DeleteOrphanedProjects::getName(), new DeleteOrphanedProjects())
|
->addAction(DeleteOrphanedProjects::getName(), new DeleteOrphanedProjects())
|
||||||
|
->addAction(PatchRecreateRepositoriesDocuments::getName(), new PatchRecreateRepositoriesDocuments())
|
||||||
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
namespace Appwrite\Platform\Tasks;
|
namespace Appwrite\Platform\Tasks;
|
||||||
|
|
||||||
use Utopia\Platform\Action;
|
use Utopia\Platform\Action;
|
||||||
use Appwrite\Event\Certificate;
|
|
||||||
use Utopia\App;
|
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
use Utopia\Database\Database;
|
use Utopia\Database\Database;
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
|
|
@ -12,10 +10,9 @@ use Utopia\Database\Helpers\ID;
|
||||||
use Utopia\Database\Helpers\Permission;
|
use Utopia\Database\Helpers\Permission;
|
||||||
use Utopia\Database\Helpers\Role;
|
use Utopia\Database\Helpers\Role;
|
||||||
use Utopia\Database\Query;
|
use Utopia\Database\Query;
|
||||||
use Utopia\Validator\Hostname;
|
|
||||||
use Utopia\Validator\Text;
|
use Utopia\Validator\Text;
|
||||||
|
|
||||||
class patchRecreateRepositoriesDocuments extends Action
|
class PatchRecreateRepositoriesDocuments extends Action
|
||||||
{
|
{
|
||||||
public static function getName(): string
|
public static function getName(): string
|
||||||
{
|
{
|
||||||
|
|
@ -34,25 +31,25 @@ class patchRecreateRepositoriesDocuments extends Action
|
||||||
}
|
}
|
||||||
|
|
||||||
public function action($after, $projectId, Database $dbForConsole, callable $getProjectDB): void
|
public function action($after, $projectId, Database $dbForConsole, callable $getProjectDB): void
|
||||||
{
|
{
|
||||||
Console::info("Starting the patch");
|
Console::info("Starting the patch");
|
||||||
|
|
||||||
$startTime = microtime(true);
|
$startTime = microtime(true);
|
||||||
|
|
||||||
if(!empty($projectId)) {
|
if (!empty($projectId)) {
|
||||||
$project = $dbForConsole->getDocument('projects', $projectId);
|
$project = $dbForConsole->getDocument('projects', $projectId);
|
||||||
$dbForProject = call_user_func($getProjectDB, $project);
|
$dbForProject = call_user_func($getProjectDB, $project);
|
||||||
$this->recreateRepositories($dbForConsole, $dbForProject, $project);
|
$this->recreateRepositories($dbForConsole, $dbForProject, $project);
|
||||||
} else {
|
} else {
|
||||||
$queries = [];
|
$queries = [];
|
||||||
if(!empty($after)) {
|
if (!empty($after)) {
|
||||||
Console::info("Iterating remaining projects after project with ID {$after}");
|
Console::info("Iterating remaining projects after project with ID {$after}");
|
||||||
$project = $dbForConsole->getDocument('projects', $after);
|
$project = $dbForConsole->getDocument('projects', $after);
|
||||||
$queries = [Query::cursorAfter($project)];
|
$queries = [Query::cursorAfter($project)];
|
||||||
} else {
|
} else {
|
||||||
Console::info("Iterating all projects");
|
Console::info("Iterating all projects");
|
||||||
}
|
}
|
||||||
$this->foreachDocument($dbForConsole, 'projects', $queries, function(Document $project) use($getProjectDB, $dbForConsole){
|
$this->foreachDocument($dbForConsole, 'projects', $queries, function (Document $project) use ($getProjectDB, $dbForConsole) {
|
||||||
$dbForProject = call_user_func($getProjectDB, $project);
|
$dbForProject = call_user_func($getProjectDB, $project);
|
||||||
$this->recreateRepositories($dbForConsole, $dbForProject, $project);
|
$this->recreateRepositories($dbForConsole, $dbForProject, $project);
|
||||||
});
|
});
|
||||||
|
|
@ -106,13 +103,13 @@ class patchRecreateRepositoriesDocuments extends Action
|
||||||
$projectId = $project->getId();
|
$projectId = $project->getId();
|
||||||
Console::log("Running patch for project {$projectId}");
|
Console::log("Running patch for project {$projectId}");
|
||||||
|
|
||||||
$this->foreachDocument($dbForProject, 'functions', [], function(Document $function) use ($dbForConsole, $project) {
|
$this->foreachDocument($dbForProject, 'functions', [], function (Document $function) use ($dbForProject, $dbForConsole, $project) {
|
||||||
$isConnected = !empty($function->getAttribute('providerRepositoryId', ''));
|
$isConnected = !empty($function->getAttribute('providerRepositoryId', ''));
|
||||||
|
|
||||||
if($isConnected) {
|
if ($isConnected) {
|
||||||
$repository = $dbForConsole->getDocument('repositories', $function->getAttribute('repositoryId', ''));
|
$repository = $dbForConsole->getDocument('repositories', $function->getAttribute('repositoryId', ''));
|
||||||
|
|
||||||
if($repository->isEmpty()) {
|
if ($repository->isEmpty()) {
|
||||||
$projectId = $project->getId();
|
$projectId = $project->getId();
|
||||||
$functionId = $function->getId();
|
$functionId = $function->getId();
|
||||||
Console::success("Recreating repositories document for project ID {$projectId}, function ID {$functionId}");
|
Console::success("Recreating repositories document for project ID {$projectId}, function ID {$functionId}");
|
||||||
|
|
@ -134,6 +131,19 @@ class patchRecreateRepositoriesDocuments extends Action
|
||||||
'resourceType' => 'function',
|
'resourceType' => 'function',
|
||||||
'providerPullRequestIds' => []
|
'providerPullRequestIds' => []
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
$function = $dbForProject->updateDocument('functions', $function->getId(), $function
|
||||||
|
->setAttribute('repositoryId', $repository->getId())
|
||||||
|
->setAttribute('repositoryInternalId', $repository->getInternalId()));
|
||||||
|
|
||||||
|
$this->foreachDocument($dbForProject, 'deployments', [
|
||||||
|
Query::equal('resourceInternalId', [$function->getInternalId()]),
|
||||||
|
Query::equal('resourceType', ['functions'])
|
||||||
|
], function (Document $deployment) use ($dbForProject, $repository) {
|
||||||
|
$dbForProject->updateDocument('deployments', $deployment->getId(), $deployment
|
||||||
|
->setAttribute('repositoryId', $repository->getId())
|
||||||
|
->setAttribute('repositoryInternalId', $repository->getInternalId()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue