From 3b38b6bb57c1580e82ba715bcd5a70af20a4e412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 May 2025 16:52:13 +0200 Subject: [PATCH 1/2] Migration review fixes --- app/config/collections/platform.php | 18 ------- app/config/collections/projects.php | 53 +++++++++---------- app/http.php | 2 +- .../Functions/Http/Deployments/Create.php | 2 - .../Http/Deployments/Duplicate/Create.php | 4 +- .../Http/Deployments/Status/Update.php | 4 +- .../Modules/Functions/Workers/Builds.php | 8 +-- .../Modules/Projects/Http/DevKeys/Create.php | 1 - .../Modules/Projects/Http/DevKeys/Update.php | 3 +- .../Modules/Projects/Http/DevKeys/XList.php | 8 +-- .../Modules/Sites/Http/Deployments/Create.php | 2 - .../Http/Deployments/Duplicate/Create.php | 4 +- .../Sites/Http/Deployments/Status/Update.php | 4 +- .../Realtime/RealtimeConsoleClientTest.php | 6 +-- 14 files changed, 43 insertions(+), 76 deletions(-) diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index e53194c513..3fba6a46f6 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -782,17 +782,6 @@ return [ 'array' => true, 'filters' => [], ], - [ - '$id' => ID::custom('search'), - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => 16384, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], ], 'indexes' => [ [ @@ -809,13 +798,6 @@ return [ 'lengths' => [], 'orders' => [], ], - [ - '$id' => ID::custom('_key_search'), - 'type' => Database::INDEX_FULLTEXT, - 'attributes' => ['search'], - 'lengths' => [], - 'orders' => [], - ], ], ], diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index 8da1688fc4..4c23146b0b 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -1554,8 +1554,8 @@ return [ '$id' => ID::custom('sourceSize'), 'type' => Database::VAR_INTEGER, 'format' => '', - 'size' => 0, - 'signed' => true, + 'size' => 8, + 'signed' => false, 'required' => false, 'default' => null, 'array' => false, @@ -1594,17 +1594,6 @@ return [ 'array' => false, 'filters' => [], ], - [ - '$id' => ID::custom('search'), - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => 16384, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], [ '$id' => ID::custom('activate'), 'type' => Database::VAR_BOOLEAN, @@ -1639,7 +1628,7 @@ return [ 'filters' => [], ], [ - '$id' => ID::custom('buildStartAt'), + '$id' => ID::custom('buildStartedAt'), 'type' => Database::VAR_DATETIME, 'format' => '', 'size' => 0, @@ -1650,7 +1639,7 @@ return [ 'filters' => ['datetime'], ], [ - '$id' => ID::custom('buildEndAt'), + '$id' => ID::custom('buildEndedAt'), 'type' => Database::VAR_DATETIME, 'format' => '', 'size' => 0, @@ -1665,7 +1654,7 @@ return [ 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, - 'signed' => true, + 'signed' => false, 'required' => false, 'default' => null, 'array' => false, @@ -1675,8 +1664,8 @@ return [ '$id' => ID::custom('buildSize'), 'type' => Database::VAR_INTEGER, 'format' => '', - 'size' => 0, - 'signed' => true, + 'size' => 8, + 'signed' => false, 'required' => false, 'default' => null, 'array' => false, @@ -1686,8 +1675,8 @@ return [ '$id' => ID::custom('totalSize'), 'type' => Database::VAR_INTEGER, 'format' => '', - 'size' => 0, - 'signed' => true, + 'size' => 8, + 'signed' => false, 'required' => false, 'default' => null, 'array' => false, @@ -1764,13 +1753,6 @@ return [ 'lengths' => [], 'orders' => [Database::ORDER_ASC], ], - [ - '$id' => ID::custom('_key_search'), - 'type' => Database::INDEX_FULLTEXT, - 'attributes' => ['search'], - 'lengths' => [], - 'orders' => [], - ], [ '$id' => ID::custom('_key_sourceSize'), 'type' => Database::INDEX_KEY, @@ -1812,13 +1794,21 @@ return [ 'attributes' => ['type'], 'lengths' => [32], 'orders' => [Database::ORDER_ASC], - ], [ + ], + [ '$id' => ID::custom('_key_status'), 'type' => Database::INDEX_KEY, 'attributes' => ['status'], 'lengths' => [16], 'orders' => [Database::ORDER_ASC], ], + [ + '$id' => ID::custom('_key_resourceId_resourceType__id'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['resourceId', 'resourceType', '_id'], + 'lengths' => [], + 'orders' => [], + ], ], ], @@ -2490,6 +2480,13 @@ return [ 'lengths' => [], 'orders' => [], ], + [ + '$id' => '_key_resourceInternalId_resourceType', + 'type' => Database::INDEX_KEY, + 'attributes' => ['resourceInternalId', 'resourceType'], + 'lengths' => [], + 'orders' => [], + ], ], ], ]; diff --git a/app/http.php b/app/http.php index e4276a4dec..6dede19a06 100644 --- a/app/http.php +++ b/app/http.php @@ -311,7 +311,7 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg '$id' => ID::custom('screenshots'), '$collection' => ID::custom('buckets'), 'name' => 'Screenshots', - 'maximumFileSize' => 5000000, // ~5MB + 'maximumFileSize' => 20000000, // ~20MB 'allowedFileExtensions' => [ 'png' ], 'enabled' => true, 'compression' => Compression::GZIP, diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php index 2d49f1ce34..869d494d9f 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php @@ -236,7 +236,6 @@ class Create extends Action 'sourcePath' => $path, 'sourceSize' => $fileSize, 'totalSize' => $fileSize, - 'search' => implode(' ', [$deploymentId, $entrypoint]), 'activate' => $activate, 'sourceMetadata' => $metadata, 'type' => $type @@ -276,7 +275,6 @@ class Create extends Action 'totalSize' => $fileSize, 'sourceChunksTotal' => $chunks, 'sourceChunksUploaded' => $chunksUploaded, - 'search' => implode(' ', [$deploymentId, $entrypoint]), 'activate' => $activate, 'sourceMetadata' => $metadata, 'type' => $type diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php index 0bb4a3b9fb..642e88ecc2 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php @@ -105,8 +105,8 @@ class Create extends Action 'entrypoint' => $function->getAttribute('entrypoint'), 'buildCommands' => $function->getAttribute('commands', ''), 'search' => implode(' ', [$deploymentId, $function->getAttribute('entrypoint')]), - 'buildStartAt' => null, - 'buildEndAt' => null, + 'buildStartedAt' => null, + 'buildEndedAt' => null, 'buildDuration' => null, 'buildSize' => null, 'status' => 'waiting', diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php index dd2e08fe54..c5436d1d05 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php @@ -87,12 +87,12 @@ class Update extends Action throw new Exception(Exception::BUILD_ALREADY_COMPLETED); } - $startTime = new \DateTime($deployment->getAttribute('buildStartAt', 'now')); + $startTime = new \DateTime($deployment->getAttribute('buildStartedAt', 'now')); $endTime = new \DateTime('now'); $duration = $endTime->getTimestamp() - $startTime->getTimestamp(); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment->setAttributes([ - 'buildEndAt' => DateTime::now(), + 'buildEndedAt' => DateTime::now(), 'buildDuration' => $duration, 'status' => 'canceled' ])); diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 5356a746e6..da6f006265 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -263,7 +263,7 @@ class Builds extends Action $deploymentId = $deployment->getId(); - $deployment->setAttribute('buildStartAt', $startTime); + $deployment->setAttribute('buildStartedAt', $startTime); $deployment->setAttribute('status', 'processing'); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); @@ -794,8 +794,8 @@ class Builds extends Action $executor->deleteRuntime($project->getId(), $deployment->getId(), '-build'); /** Update the build document */ - $deployment->setAttribute('buildStartAt', DateTime::format((new \DateTime())->setTimestamp(floor($response['startTime'])))); - $deployment->setAttribute('buildEndAt', $endTime); + $deployment->setAttribute('buildStartedAt', DateTime::format((new \DateTime())->setTimestamp(floor($response['startTime'])))); + $deployment->setAttribute('buildEndedAt', $endTime); $deployment->setAttribute('buildDuration', \intval(\ceil($durationEnd - $durationStart))); $deployment->setAttribute('buildPath', $response['path']); $deployment->setAttribute('buildSize', $response['size']); @@ -1163,7 +1163,7 @@ class Builds extends Action $endTime = DateTime::now(); $durationEnd = \microtime(true); - $deployment->setAttribute('buildEndAt', $endTime); + $deployment->setAttribute('buildEndedAt', $endTime); $deployment->setAttribute('buildDuration', \intval(\ceil($durationEnd - $durationStart))); $deployment->setAttribute('status', 'failed'); $deployment->setAttribute('buildLogs', $message); diff --git a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Create.php index 9758b8da93..43f7d4ac02 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Create.php @@ -81,7 +81,6 @@ class Create extends Action 'name' => $name, 'expire' => $expire, 'sdks' => [], - 'search' => implode('', [$name, $project->getId(), $devKeyId]), 'accessedAt' => null, 'secret' => \bin2hex(\random_bytes(128)), ]); diff --git a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Update.php b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Update.php index 8f66318376..d5e6839174 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Update.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Update.php @@ -71,8 +71,7 @@ class Update extends Action $key ->setAttribute('name', $name) - ->setAttribute('expire', $expire) - ->setAttribute('search', implode('', [$name, $project->getId(), $key->getId()])); + ->setAttribute('expire', $expire); $dbForPlatform->updateDocument('devKeys', $key->getId(), $key); diff --git a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/XList.php b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/XList.php index b1aeecdcde..864531d32d 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/XList.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/XList.php @@ -16,7 +16,6 @@ use Utopia\Database\Query; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; -use Utopia\Validator\Text; class XList extends Action { @@ -52,13 +51,12 @@ class XList extends Action )) ->param('projectId', '', new UID(), 'Project unique ID.') ->param('queries', [], new DevKeys(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). 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(', ', DevKeys::ALLOWED_ATTRIBUTES), true) - ->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true) ->inject('response') ->inject('dbForPlatform') ->callback([$this, 'action']); } - public function action(string $projectId, ?array $queries, ?string $search, Response $response, Database $dbForPlatform) + public function action(string $projectId, ?array $queries, Response $response, Database $dbForPlatform) { $project = $dbForPlatform->getDocument('projects', $projectId); @@ -73,10 +71,6 @@ class XList extends Action throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); } - if (!empty($search)) { - $queries[] = Query::search('search', $search); - } - $queries[] = Query::equal('projectInternalId', [$project->getInternalId()]); $keys = $dbForPlatform->find('devKeys', $queries); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php index 0f1e8d7d4a..50759d2a59 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php @@ -247,7 +247,6 @@ class Create extends Action 'sourcePath' => $path, 'sourceSize' => $fileSize, 'totalSize' => $fileSize, - 'search' => implode(' ', [$deploymentId]), 'activate' => $activate, 'sourceMetadata' => $metadata, 'type' => $type, @@ -316,7 +315,6 @@ class Create extends Action 'totalSize' => $fileSize, 'sourceChunksTotal' => $chunks, 'sourceChunksUploaded' => $chunksUploaded, - 'search' => implode(' ', [$deploymentId]), 'activate' => $activate, 'sourceMetadata' => $metadata, 'type' => $type, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php index f9d73ee4fc..fe4fd79e6b 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php @@ -123,8 +123,8 @@ class Create extends Action 'search' => implode(' ', [$deploymentId]), 'screenshotLight' => '', 'screenshotDark' => '', - 'buildStartAt' => null, - 'buildEndAt' => null, + 'buildStartedAt' => null, + 'buildEndedAt' => null, 'buildDuration' => 0, 'buildSize' => 0, 'status' => 'waiting', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php index 64a9b0426a..2c6da43893 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php @@ -85,12 +85,12 @@ class Update extends Action throw new Exception(Exception::BUILD_ALREADY_COMPLETED); } - $startTime = new \DateTime($deployment->getAttribute('buildStartAt', 'now')); + $startTime = new \DateTime($deployment->getAttribute('buildStartedAt', 'now')); $endTime = new \DateTime('now'); $duration = $endTime->getTimestamp() - $startTime->getTimestamp(); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment->setAttributes([ - 'buildEndAt' => DateTime::now(), + 'buildEndedAt' => DateTime::now(), 'buildDuration' => $duration, 'status' => 'canceled' ])); diff --git a/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php b/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php index 4e27457b05..01de2782a5 100644 --- a/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php @@ -616,9 +616,9 @@ class RealtimeConsoleClientTest extends Scope $this->assertEquals('building', $response['data']['payload']['status']); - if (!empty($response['data']['payload']['buildEndAt'])) { - $this->assertNotEmpty($response['data']['payload']['buildEndAt']); - $this->assertNotEmpty($response['data']['payload']['buildStartAt']); + if (!empty($response['data']['payload']['buildEndedAt'])) { + $this->assertNotEmpty($response['data']['payload']['buildEndedAt']); + $this->assertNotEmpty($response['data']['payload']['buildStartedAt']); $this->assertNotEmpty($response['data']['payload']['buildDuration']); $this->assertNotEmpty($response['data']['payload']['buildPath']); $this->assertNotEmpty($response['data']['payload']['buildSize']); From 06bf26682e79fefc005f44af6fd95d19e5af9801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 May 2025 17:33:21 +0200 Subject: [PATCH 2/2] Fix index --- app/config/collections/projects.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index 4c23146b0b..fb090099f5 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -1803,9 +1803,9 @@ return [ 'orders' => [Database::ORDER_ASC], ], [ - '$id' => ID::custom('_key_resourceId_resourceType__id'), + '$id' => ID::custom('_key_resourceId_resourceType'), 'type' => Database::INDEX_KEY, - 'attributes' => ['resourceId', 'resourceType', '_id'], + 'attributes' => ['resourceId', 'resourceType'], 'lengths' => [], 'orders' => [], ],