diff --git a/app/config/collections.php b/app/config/collections.php index bc4db6bce6..e2d4d2b12f 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -785,6 +785,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('resourceInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('resourceId'), 'type' => Database::VAR_STRING, @@ -2223,6 +2234,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('deploymentInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('deployment'), 'type' => Database::VAR_STRING, @@ -2256,6 +2278,17 @@ $collections = [ 'array' => true, 'filters' => [], ], + [ + '$id' => ID::custom('scheduleInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('scheduleId'), 'type' => Database::VAR_STRING, @@ -2381,6 +2414,17 @@ $collections = [ '$id' => ID::custom('deployments'), 'name' => 'Deployments', 'attributes' => [ + [ + '$id' => ID::custom('resourceInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('resourceId'), 'type' => Database::VAR_STRING, @@ -2403,6 +2447,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('buildInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('buildId'), 'type' => Database::VAR_STRING, @@ -2583,6 +2638,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => 'deploymentInternalId', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('deploymentId'), 'type' => Database::VAR_STRING, @@ -2699,6 +2765,17 @@ $collections = [ '$id' => ID::custom('executions'), 'name' => 'Executions', 'attributes' => [ + [ + '$id' => ID::custom('functionInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('functionId'), 'type' => Database::VAR_STRING, @@ -2710,6 +2787,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('deploymentInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('deploymentId'), 'type' => Database::VAR_STRING, diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 83bb63dc43..cdd1acf1dd 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -82,6 +82,7 @@ App::post('/v1/functions') 'enabled' => $enabled, 'name' => $name, 'runtime' => $runtime, + 'deploymentInternalId' => '', 'deployment' => '', 'events' => $events, 'schedule' => $schedule, @@ -104,6 +105,7 @@ App::post('/v1/functions') ); $function->setAttribute('scheduleId', $schedule->getId()); + $function->setAttribute('scheduleInternalId', $schedule->getInternalId()); $dbForProject->updateDocument('functions', $function->getId(), $function); $eventsInstance->setParam('functionId', $function->getId()); @@ -536,6 +538,7 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId') } $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ + 'deploymentInternalId' => $deployment->getInternalId(), 'deployment' => $deployment->getId() ]))); @@ -742,6 +745,7 @@ App::post('/v1/functions/:functionId/deployments') Permission::update(Role::any()), Permission::delete(Role::any()), ], + 'resourceInternalId' => $function->getInternalId(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', 'entrypoint' => $entrypoint, @@ -772,6 +776,7 @@ App::post('/v1/functions/:functionId/deployments') Permission::update(Role::any()), Permission::delete(Role::any()), ], + 'resourceInternalId' => $function->getInternalId(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', 'entrypoint' => $entrypoint, @@ -969,6 +974,7 @@ App::delete('/v1/functions/:functionId/deployments/:deploymentId') if ($function->getAttribute('deployment') === $deployment->getId()) { // Reset function deployment $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ 'deployment' => '', + 'deploymentInternalId' => '', ]))); } @@ -1121,7 +1127,9 @@ App::post('/v1/functions/:functionId/executions') $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', new Document([ '$id' => $executionId, '$permissions' => !$user->isEmpty() ? [Permission::read(Role::user($user->getId()))] : [], + 'functionInternalId' => $function->getInternalId(), 'functionId' => $function->getId(), + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), 'trigger' => 'http', // http / schedule / event 'status' => $async ? 'waiting' : 'processing', // waiting / processing / completed / failed diff --git a/app/workers/builds.php b/app/workers/builds.php index e188e33e2c..712ffc5919 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -97,6 +97,7 @@ class BuildsV1 extends Worker '$id' => $buildId, '$permissions' => [], 'startTime' => $startTime, + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), 'status' => 'processing', 'path' => '', @@ -108,7 +109,8 @@ class BuildsV1 extends Worker 'stderr' => '', 'duration' => 0 ])); - $deployment->setAttribute('buildId', $buildId); + $deployment->setAttribute('buildId', $build->getId()); + $deployment->setAttribute('buildInternalId', $build->getInternalId()); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); } else { $build = $dbForProject->getDocument('builds', $buildId); @@ -205,6 +207,7 @@ class BuildsV1 extends Worker /** Set auto deploy */ if ($deployment->getAttribute('activate') === true) { + $function->setAttribute('deploymentInternalId', $deployment->getInternalId()); $function->setAttribute('deployment', $deployment->getId()); $function = $dbForProject->updateDocument('functions', $function->getId(), $function); } diff --git a/app/workers/functions.php b/app/workers/functions.php index 6145c9e31e..b4d94ade9d 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -222,7 +222,8 @@ Server::setResource('execute', function () { $usage ->setParam('projectId', $project->getId()) ->setParam('projectInternalId', $project->getInternalId()) - ->setParam('functionId', $function->getId()) // TODO: We should use functionInternalId in usage stats + ->setParam('functionId', $function->getId()) + ->setParam('functionInternalId', $function->getInternalId()) ->setParam('executions.{scope}.compute', 1) ->setParam('executionStatus', $execution->getAttribute('status', '')) ->setParam('executionTime', $execution->getAttribute('duration')) diff --git a/composer.lock b/composer.lock index dc33c8026a..0ebab0277e 100644 --- a/composer.lock +++ b/composer.lock @@ -5287,16 +5287,16 @@ }, { "name": "twig/twig", - "version": "v3.5.1", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "a6e0510cc793912b451fd40ab983a1d28f611c15" + "reference": "3ffcf4b7d890770466da3b2666f82ac054e7ec72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/a6e0510cc793912b451fd40ab983a1d28f611c15", - "reference": "a6e0510cc793912b451fd40ab983a1d28f611c15", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/3ffcf4b7d890770466da3b2666f82ac054e7ec72", + "reference": "3ffcf4b7d890770466da3b2666f82ac054e7ec72", "shasum": "" }, "require": { @@ -5347,7 +5347,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.5.1" + "source": "https://github.com/twigphp/Twig/tree/v3.5.0" }, "funding": [ { @@ -5359,7 +5359,7 @@ "type": "tidelift" } ], - "time": "2023-02-08T07:49:20+00:00" + "time": "2022-12-27T12:28:18+00:00" } ], "aliases": [], @@ -5388,5 +5388,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/src/Appwrite/Migration/Version/V17.php b/src/Appwrite/Migration/Version/V17.php index e6877e7225..f841fcab52 100644 --- a/src/Appwrite/Migration/Version/V17.php +++ b/src/Appwrite/Migration/Version/V17.php @@ -90,12 +90,90 @@ class V17 extends Migration try { /** - * Create 'size' + * Create 'deploymentInternalId' attribute */ - $this->createAttributeFromCollection($this->projectDB, $id, 'size'); + $this->createAttributeFromCollection($this->projectDB, $id, 'deploymentInternalId'); $this->projectDB->deleteCachedCollection($id); } catch (\Throwable $th) { - Console::warning("'size' from {$id}: {$th->getMessage()}"); + Console::warning("'deploymentInternalId' from {$id}: {$th->getMessage()}"); + } + break; + + case 'schedules': + try { + /** + * Create 'resourceInternalId' attribute + */ + $this->createAttributeFromCollection($this->projectDB, $id, 'resourceInternalId'); + $this->projectDB->deleteCachedCollection($id); + } catch (\Throwable $th) { + Console::warning("'resourceInternalId' from {$id}: {$th->getMessage()}"); + } + break; + + case 'functions': + try { + /** + * Create 'deploymentInternalId' attribute + */ + $this->createAttributeFromCollection($this->projectDB, $id, 'deploymentInternalId'); + $this->projectDB->deleteCachedCollection($id); + } catch (\Throwable $th) { + Console::warning("'deploymentInternalId' from {$id}: {$th->getMessage()}"); + } + + try { + /** + * Create 'scheduleInternalId' attribute + */ + $this->createAttributeFromCollection($this->projectDB, $id, 'scheduleInternalId'); + $this->projectDB->deleteCachedCollection($id); + } catch (\Throwable $th) { + Console::warning("'scheduleInternalId' from {$id}: {$th->getMessage()}"); + } + break; + + case 'deployments': + try { + /** + * Create 'resourceInternalId' attribute + */ + $this->createAttributeFromCollection($this->projectDB, $id, 'resourceInternalId'); + $this->projectDB->deleteCachedCollection($id); + } catch (\Throwable $th) { + Console::warning("'resourceInternalId' from {$id}: {$th->getMessage()}"); + } + + try { + /** + * Create 'buildInternalId' attribute + */ + $this->createAttributeFromCollection($this->projectDB, $id, 'buildInternalId'); + $this->projectDB->deleteCachedCollection($id); + } catch (\Throwable $th) { + Console::warning("'buildInternalId' from {$id}: {$th->getMessage()}"); + } + break; + + case 'executions': + try { + /** + * Create 'functionInternalId' attribute + */ + $this->createAttributeFromCollection($this->projectDB, $id, 'functionInternalId'); + $this->projectDB->deleteCachedCollection($id); + } catch (\Throwable $th) { + Console::warning("'functionInternalId' from {$id}: {$th->getMessage()}"); + } + + try { + /** + * Create 'deploymentInternalId' attribute + */ + $this->createAttributeFromCollection($this->projectDB, $id, 'deploymentInternalId'); + $this->projectDB->deleteCachedCollection($id); + } catch (\Throwable $th) { + Console::warning("'deploymentInternalId' from {$id}: {$th->getMessage()}"); } break; default: