diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index c2228f6a4c..f9a44e169c 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -579,6 +579,17 @@ return [ '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 +1014,17 @@ return [ '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..27eded178a 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php @@ -100,6 +100,7 @@ class Delete extends Action $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ 'deploymentId' => '', 'deploymentInternalId' => '', + '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..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,6 +93,7 @@ class Update extends Base $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), + '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..16b2e08be1 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -868,6 +868,7 @@ class Builds extends Action $resource->setAttribute('deploymentId', $deployment->getId()); $resource->setAttribute('deploymentInternalId', $deployment->getInternalId()); + $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); $resource = $dbForProject->updateDocument('functions', $resource->getId(), $resource); $queries = [ @@ -900,6 +901,7 @@ class Builds extends Action $resource->setAttribute('deploymentInternalId', $deployment->getInternalId()); $resource->setAttribute('deploymentScreenshotDark', $deployment->getAttribute('screenshotDark', '')); $resource->setAttribute('deploymentScreenshotLight', $deployment->getAttribute('screenshotLight', '')); + $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..00342a7667 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php @@ -102,6 +102,7 @@ class Delete extends Action 'deploymentInternalId' => '', 'deploymentScreenshotDark' => '', 'deploymentScreenshotLight' => '', + '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..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,6 +92,7 @@ class Update extends Base 'deploymentId' => $deployment->getId(), 'deploymentScreenshotDark' => $deployment->getAttribute('screenshotDark', ''), 'deploymentScreenshotLight' => $deployment->getAttribute('screenshotLight', ''), + 'deploymentCreatedAt' => $deployment->getCreatedAt(), ]))); $queries = [ diff --git a/src/Appwrite/Utopia/Response/Model/Func.php b/src/Appwrite/Utopia/Response/Model/Func.php index bf16f91b59..5d937ab075 100644 --- a/src/Appwrite/Utopia/Response/Model/Func.php +++ b/src/Appwrite/Utopia/Response/Model/Func.php @@ -71,6 +71,12 @@ 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('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..fad4856f3e 100644 --- a/src/Appwrite/Utopia/Response/Model/Site.php +++ b/src/Appwrite/Utopia/Response/Model/Site.php @@ -58,6 +58,12 @@ 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('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..e13e7f9147 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -493,6 +493,13 @@ 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']['deploymentCreatedAt']); + $this->assertEquals($deployment['body']['$id'], $function['body']['deploymentId']); + $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..c1609bfb80 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -367,6 +367,13 @@ 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']['deploymentCreatedAt']); + $this->assertEquals($deployment['body']['$id'], $site['body']['deploymentId']); + $this->assertEquals($deployment['body']['$createdAt'], $site['body']['deploymentCreatedAt']); + $this->cleanupSite($siteId); }