From 7cade1a27df4a7d686d5d423caf9bb389b57da9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 18 Mar 2025 12:44:21 +0100 Subject: [PATCH 1/2] Add active deployment status and creation date --- app/config/collections/projects.php | 45 ++++++++++++++++++- .../Functions/Http/Deployments/Delete.php | 2 + .../Http/Functions/Deployment/Update.php | 2 + .../Modules/Functions/Workers/Builds.php | 4 ++ .../Modules/Sites/Http/Deployments/Delete.php | 2 + .../Sites/Http/Sites/Deployment/Update.php | 2 + src/Appwrite/Utopia/Response/Model/Func.php | 12 +++++ src/Appwrite/Utopia/Response/Model/Site.php | 12 +++++ .../Functions/FunctionsCustomServerTest.php | 9 ++++ .../Services/Sites/SitesCustomServerTest.php | 9 ++++ 10 files changed, 98 insertions(+), 1 deletion(-) diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index c2228f6a4c..a8a1d34e14 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -579,6 +579,28 @@ return [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('deploymentStatus'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 16, + 'signed' => true, + 'required' => false, + 'default' => '', + 'array' => false, + 'filters' => [], + ], + [ + '$id' => ID::custom('deploymentCreatedAt'), + 'type' => Database::VAR_DATETIME, + 'format' => '', + 'size' => 0, + 'signed' => false, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => ['datetime'], + ], [ '$id' => ID::custom('vars'), 'type' => Database::VAR_STRING, @@ -1003,7 +1025,28 @@ return [ 'array' => false, 'filters' => [], ], - + [ + '$id' => ID::custom('deploymentStatus'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 16, + 'signed' => true, + 'required' => false, + 'default' => '', + 'array' => false, + 'filters' => [], + ], + [ + '$id' => ID::custom('deploymentCreatedAt'), + 'type' => Database::VAR_DATETIME, + 'format' => '', + 'size' => 0, + 'signed' => false, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => ['datetime'], + ], [ '$id' => ID::custom('deploymentScreenshotLight'), // File ID from 'screenshots' Console bucket 'type' => Database::VAR_STRING, diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php index ec4a90f426..eb1ac6ae50 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php @@ -100,6 +100,8 @@ class Delete extends Action $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ 'deploymentId' => '', 'deploymentInternalId' => '', + 'deploymentStatus' => '', + 'deploymentCreatedAt' => '', ]))); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php index 42608ab47e..088237d58c 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php @@ -93,6 +93,8 @@ class Update extends Base $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), + 'deploymentStatus' => $deployment->getAttribute('status', ''), + 'deploymentCreatedAt' => $deployment->getCreatedAt(), ]))); // Inform scheduler if function is still active diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 1af57fd4e3..cbc41c5df7 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -868,6 +868,8 @@ class Builds extends Action $resource->setAttribute('deploymentId', $deployment->getId()); $resource->setAttribute('deploymentInternalId', $deployment->getInternalId()); + $resource->setAttribute('deploymentStatus', $deployment->getAttribute('status', '')); + $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); $resource = $dbForProject->updateDocument('functions', $resource->getId(), $resource); $queries = [ @@ -900,6 +902,8 @@ class Builds extends Action $resource->setAttribute('deploymentInternalId', $deployment->getInternalId()); $resource->setAttribute('deploymentScreenshotDark', $deployment->getAttribute('screenshotDark', '')); $resource->setAttribute('deploymentScreenshotLight', $deployment->getAttribute('screenshotLight', '')); + $resource->setAttribute('deploymentStatus', $deployment->getAttribute('status', '')); + $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); $resource = $dbForProject->updateDocument('sites', $resource->getId(), $resource); $queries = [ Query::equal("projectInternalId", [$project->getInternalId()]), diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php index 56b601d302..fac61616d0 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php @@ -102,6 +102,8 @@ class Delete extends Action 'deploymentInternalId' => '', 'deploymentScreenshotDark' => '', 'deploymentScreenshotLight' => '', + 'deploymentStatus' => '', + 'deploymentCreatedAt' => '', ]))); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php index 403579d8fd..5cd7f6fbd8 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php @@ -92,6 +92,8 @@ class Update extends Base 'deploymentId' => $deployment->getId(), 'deploymentScreenshotDark' => $deployment->getAttribute('screenshotDark', ''), 'deploymentScreenshotLight' => $deployment->getAttribute('screenshotLight', ''), + 'deploymentStatus' => $deployment->getAttribute('status', ''), + 'deploymentCreatedAt' => $deployment->getCreatedAt(), ]))); $queries = [ diff --git a/src/Appwrite/Utopia/Response/Model/Func.php b/src/Appwrite/Utopia/Response/Model/Func.php index bf16f91b59..40a9b77c2b 100644 --- a/src/Appwrite/Utopia/Response/Model/Func.php +++ b/src/Appwrite/Utopia/Response/Model/Func.php @@ -71,6 +71,18 @@ class Func extends Model 'default' => '', 'example' => '5e5ea5c16897e', ]) + ->addRule('deploymentCreatedAt', [ + 'type' => self::TYPE_DATETIME, + 'description' => 'Active deployment creation date in ISO 8601 format.', + 'default' => '', + 'example' => self::TYPE_DATETIME_EXAMPLE, + ]) + ->addRule('deploymentStatus', [ + 'type' => self::TYPE_STRING, + 'description' => 'Active deployment status. Possible values are "waiting", "processing", "building", "waiting", "ready", and "failed".', + 'default' => '', + 'example' => 'ready', + ]) ->addRule('scopes', [ 'type' => self::TYPE_STRING, 'description' => 'Allowed permission scopes.', diff --git a/src/Appwrite/Utopia/Response/Model/Site.php b/src/Appwrite/Utopia/Response/Model/Site.php index b756e5f1eb..c5caf4e76e 100644 --- a/src/Appwrite/Utopia/Response/Model/Site.php +++ b/src/Appwrite/Utopia/Response/Model/Site.php @@ -58,6 +58,18 @@ class Site extends Model 'default' => '', 'example' => '5e5ea5c16897e', ]) + ->addRule('deploymentCreatedAt', [ + 'type' => self::TYPE_DATETIME, + 'description' => 'Active deployment creation date in ISO 8601 format.', + 'default' => '', + 'example' => self::TYPE_DATETIME_EXAMPLE, + ]) + ->addRule('deploymentStatus', [ + 'type' => self::TYPE_STRING, + 'description' => 'Active deployment status. Possible values are "waiting", "processing", "building", "waiting", "ready", and "failed".', + 'default' => '', + 'example' => 'ready', + ]) ->addRule('deploymentScreenshotLight', [ 'type' => self::TYPE_STRING, 'description' => 'Screenshot of active deployment with light theme preference file ID.', diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index b238ba2768..3d2cfbd597 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -493,6 +493,15 @@ class FunctionsCustomServerTest extends Scope $totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize']; $this->assertEquals($totalSize, $deployment['body']['totalSize']); + $function = $this->getFunction($functionId); + $this->assertEquals(200, $function['headers']['status-code']); + $this->assertNotEmpty($function['body']['deploymentId']); + $this->assertNotEmpty($function['body']['deploymentStatus']); + $this->assertNotEmpty($function['body']['deploymentCreatedAt']); + $this->assertEquals($deployment['body']['$id'], $function['body']['deploymentId']); + $this->assertEquals($deployment['body']['status'], $function['body']['deploymentStatus']); + $this->assertEquals($deployment['body']['$createdAt'], $function['body']['deploymentCreatedAt']); + $function = $this->cleanupFunction($functionId); } diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 36a688ed4d..d09bc42d4b 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -367,6 +367,15 @@ class SitesCustomServerTest extends Scope $totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize']; $this->assertEquals($totalSize, $deployment['body']['totalSize']); + $site = $this->getSite($siteId); + $this->assertEquals(200, $site['headers']['status-code']); + $this->assertNotEmpty($site['body']['deploymentId']); + $this->assertNotEmpty($site['body']['deploymentStatus']); + $this->assertNotEmpty($site['body']['deploymentCreatedAt']); + $this->assertEquals($deployment['body']['$id'], $site['body']['deploymentId']); + $this->assertEquals($deployment['body']['status'], $site['body']['deploymentStatus']); + $this->assertEquals($deployment['body']['$createdAt'], $site['body']['deploymentCreatedAt']); + $this->cleanupSite($siteId); } From 362520ff4ac5571e2c2ea5a13aaa6ac5a774c22e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 18 Mar 2025 12:56:44 +0100 Subject: [PATCH 2/2] Remove active depoyment status (not relevant, always ready) --- app/config/collections/projects.php | 22 ------------------- .../Functions/Http/Deployments/Delete.php | 1 - .../Http/Functions/Deployment/Update.php | 1 - .../Modules/Functions/Workers/Builds.php | 2 -- .../Modules/Sites/Http/Deployments/Delete.php | 1 - .../Sites/Http/Sites/Deployment/Update.php | 1 - src/Appwrite/Utopia/Response/Model/Func.php | 6 ----- src/Appwrite/Utopia/Response/Model/Site.php | 6 ----- .../Functions/FunctionsCustomServerTest.php | 2 -- .../Services/Sites/SitesCustomServerTest.php | 2 -- 10 files changed, 44 deletions(-) diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index a8a1d34e14..f9a44e169c 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -579,17 +579,6 @@ return [ 'array' => false, 'filters' => [], ], - [ - '$id' => ID::custom('deploymentStatus'), - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => 16, - 'signed' => true, - 'required' => false, - 'default' => '', - 'array' => false, - 'filters' => [], - ], [ '$id' => ID::custom('deploymentCreatedAt'), 'type' => Database::VAR_DATETIME, @@ -1025,17 +1014,6 @@ return [ 'array' => false, 'filters' => [], ], - [ - '$id' => ID::custom('deploymentStatus'), - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => 16, - 'signed' => true, - 'required' => false, - 'default' => '', - 'array' => false, - 'filters' => [], - ], [ '$id' => ID::custom('deploymentCreatedAt'), 'type' => Database::VAR_DATETIME, diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php index eb1ac6ae50..27eded178a 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php @@ -100,7 +100,6 @@ class Delete extends Action $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ 'deploymentId' => '', 'deploymentInternalId' => '', - 'deploymentStatus' => '', 'deploymentCreatedAt' => '', ]))); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php index 088237d58c..c957a688e2 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php @@ -93,7 +93,6 @@ class Update extends Base $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), - 'deploymentStatus' => $deployment->getAttribute('status', ''), 'deploymentCreatedAt' => $deployment->getCreatedAt(), ]))); diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index cbc41c5df7..16b2e08be1 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -868,7 +868,6 @@ class Builds extends Action $resource->setAttribute('deploymentId', $deployment->getId()); $resource->setAttribute('deploymentInternalId', $deployment->getInternalId()); - $resource->setAttribute('deploymentStatus', $deployment->getAttribute('status', '')); $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); $resource = $dbForProject->updateDocument('functions', $resource->getId(), $resource); @@ -902,7 +901,6 @@ class Builds extends Action $resource->setAttribute('deploymentInternalId', $deployment->getInternalId()); $resource->setAttribute('deploymentScreenshotDark', $deployment->getAttribute('screenshotDark', '')); $resource->setAttribute('deploymentScreenshotLight', $deployment->getAttribute('screenshotLight', '')); - $resource->setAttribute('deploymentStatus', $deployment->getAttribute('status', '')); $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); $resource = $dbForProject->updateDocument('sites', $resource->getId(), $resource); $queries = [ diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php index fac61616d0..00342a7667 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php @@ -102,7 +102,6 @@ class Delete extends Action 'deploymentInternalId' => '', 'deploymentScreenshotDark' => '', 'deploymentScreenshotLight' => '', - 'deploymentStatus' => '', 'deploymentCreatedAt' => '', ]))); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php index 5cd7f6fbd8..7cfe1a50a2 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php @@ -92,7 +92,6 @@ class Update extends Base 'deploymentId' => $deployment->getId(), 'deploymentScreenshotDark' => $deployment->getAttribute('screenshotDark', ''), 'deploymentScreenshotLight' => $deployment->getAttribute('screenshotLight', ''), - 'deploymentStatus' => $deployment->getAttribute('status', ''), 'deploymentCreatedAt' => $deployment->getCreatedAt(), ]))); diff --git a/src/Appwrite/Utopia/Response/Model/Func.php b/src/Appwrite/Utopia/Response/Model/Func.php index 40a9b77c2b..5d937ab075 100644 --- a/src/Appwrite/Utopia/Response/Model/Func.php +++ b/src/Appwrite/Utopia/Response/Model/Func.php @@ -77,12 +77,6 @@ class Func extends Model 'default' => '', 'example' => self::TYPE_DATETIME_EXAMPLE, ]) - ->addRule('deploymentStatus', [ - 'type' => self::TYPE_STRING, - 'description' => 'Active deployment status. Possible values are "waiting", "processing", "building", "waiting", "ready", and "failed".', - 'default' => '', - 'example' => 'ready', - ]) ->addRule('scopes', [ 'type' => self::TYPE_STRING, 'description' => 'Allowed permission scopes.', diff --git a/src/Appwrite/Utopia/Response/Model/Site.php b/src/Appwrite/Utopia/Response/Model/Site.php index c5caf4e76e..fad4856f3e 100644 --- a/src/Appwrite/Utopia/Response/Model/Site.php +++ b/src/Appwrite/Utopia/Response/Model/Site.php @@ -64,12 +64,6 @@ class Site extends Model 'default' => '', 'example' => self::TYPE_DATETIME_EXAMPLE, ]) - ->addRule('deploymentStatus', [ - 'type' => self::TYPE_STRING, - 'description' => 'Active deployment status. Possible values are "waiting", "processing", "building", "waiting", "ready", and "failed".', - 'default' => '', - 'example' => 'ready', - ]) ->addRule('deploymentScreenshotLight', [ 'type' => self::TYPE_STRING, 'description' => 'Screenshot of active deployment with light theme preference file ID.', diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 3d2cfbd597..e13e7f9147 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -496,10 +496,8 @@ class FunctionsCustomServerTest extends Scope $function = $this->getFunction($functionId); $this->assertEquals(200, $function['headers']['status-code']); $this->assertNotEmpty($function['body']['deploymentId']); - $this->assertNotEmpty($function['body']['deploymentStatus']); $this->assertNotEmpty($function['body']['deploymentCreatedAt']); $this->assertEquals($deployment['body']['$id'], $function['body']['deploymentId']); - $this->assertEquals($deployment['body']['status'], $function['body']['deploymentStatus']); $this->assertEquals($deployment['body']['$createdAt'], $function['body']['deploymentCreatedAt']); $function = $this->cleanupFunction($functionId); diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index d09bc42d4b..c1609bfb80 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -370,10 +370,8 @@ class SitesCustomServerTest extends Scope $site = $this->getSite($siteId); $this->assertEquals(200, $site['headers']['status-code']); $this->assertNotEmpty($site['body']['deploymentId']); - $this->assertNotEmpty($site['body']['deploymentStatus']); $this->assertNotEmpty($site['body']['deploymentCreatedAt']); $this->assertEquals($deployment['body']['$id'], $site['body']['deploymentId']); - $this->assertEquals($deployment['body']['status'], $site['body']['deploymentStatus']); $this->assertEquals($deployment['body']['$createdAt'], $site['body']['deploymentCreatedAt']); $this->cleanupSite($siteId);