From fe5419401a3ca08d4eb614a3a720dc0427cdf30c Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 21 May 2025 07:28:25 +0000 Subject: [PATCH 01/31] chore: use unique filename for health check --- app/controllers/api/health.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 11fc4cc244..825244e776 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -852,15 +852,18 @@ App::get('/v1/health/storage') $checkStart = \microtime(true); foreach ($devices as $device) { - if (!$device->write($device->getPath('health.txt'), 'test', 'text/plain')) { + $uniqueFileName = \uniqid('health', true); + $filePath = $device->getPath($uniqueFileName); + + if (!$device->write($filePath, 'test', 'text/plain')) { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed writing test file to ' . $device->getRoot()); } - if ($device->read($device->getPath('health.txt')) !== 'test') { + if ($device->read($filePath) !== 'test') { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed reading test file from ' . $device->getRoot()); } - if (!$device->delete($device->getPath('health.txt'))) { + if (!$device->delete($filePath)) { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed deleting test file from ' . $device->getRoot()); } } From c5f7a724090fee6cf763d8cf2dbda82b2495ea4e Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 22 May 2025 06:03:35 +0000 Subject: [PATCH 02/31] chore: update flutter_web_auth_2 docs to match 4.x --- docs/sdks/flutter/GETTING_STARTED.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/sdks/flutter/GETTING_STARTED.md b/docs/sdks/flutter/GETTING_STARTED.md index 8d239402b3..c3a1a8d33d 100644 --- a/docs/sdks/flutter/GETTING_STARTED.md +++ b/docs/sdks/flutter/GETTING_STARTED.md @@ -56,13 +56,25 @@ For web in order to capture the OAuth2 callback URL and send it to the applicati ```html Authentication complete -

Authentication is complete. If this does not happen automatically, please -close the window. +

Authentication is complete. If this does not happen automatically, please close the window.

``` From 86526fa1df15f1cb94981bdf656e64861d01b6bb Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 22 May 2025 06:11:28 +0000 Subject: [PATCH 03/31] chore: update changelog --- docs/sdks/flutter/CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/sdks/flutter/CHANGELOG.md b/docs/sdks/flutter/CHANGELOG.md index be03d0fa2a..f707c645e6 100644 --- a/docs/sdks/flutter/CHANGELOG.md +++ b/docs/sdks/flutter/CHANGELOG.md @@ -1,6 +1,11 @@ # Change Log -## 16.0.1 +## 16.1.1 + +* Update `flutter_web_auth_2` dependency to version 4.1.0 +* Update `auth.html` example in README.md to align with `flutter_web_auth_2` documentation + +## 16.1.0 * Add `setDevKey` method to Client service * Add `upsertDocument` method to Databases service From b727b8c100b67965c6bbdcae7bc26e03a9fa241d Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Thu, 22 May 2025 18:01:34 +0530 Subject: [PATCH 04/31] Add configurable deployment and build size --- app/worker.php | 4 ++++ .../Functions/Http/Deployments/Create.php | 12 ++++++++-- .../Modules/Functions/Workers/Builds.php | 23 +++++++++++++++---- .../Modules/Sites/Http/Deployments/Create.php | 12 ++++++++-- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/app/worker.php b/app/worker.php index 79cfffc8bb..1277162bfa 100644 --- a/app/worker.php +++ b/app/worker.php @@ -240,6 +240,10 @@ Server::setResource('timelimit', function (\Redis $redis) { Server::setResource('log', fn () => new Log()); +Server::setResource('plan', function (array $plan = []) { + return []; +}); + Server::setResource('publisher', function (Group $pools) { return new BrokerPool(publisher: $pools->get('publisher')); }, ['pools']); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php index 54894f2caa..cda6dc38bf 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php @@ -86,6 +86,7 @@ class Create extends Action ->inject('deviceForFunctions') ->inject('deviceForLocal') ->inject('queueForBuilds') + ->inject('plan') ->callback([$this, 'action']); } @@ -102,7 +103,8 @@ class Create extends Action Document $project, Device $deviceForFunctions, Device $deviceForLocal, - Build $queueForBuilds + Build $queueForBuilds, + array $plan ) { $activate = \strval($activate) === 'true' || \strval($activate) === '1'; @@ -135,8 +137,14 @@ class Create extends Action throw new Exception(Exception::STORAGE_FILE_EMPTY, 'No file sent'); } + $functionSizeLimit = (int) System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000'); + + if (isset($plan['deploymentSize'])) { + $functionSizeLimit = $plan['deploymentSize'] * 1000 * 1000; + } + $fileExt = new FileExt([FileExt::TYPE_GZIP]); - $fileSizeValidator = new FileSize(System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000')); + $fileSizeValidator = new FileSize($functionSizeLimit); $upload = new Upload(); // Make sure we handle a single file and multiple files the same way diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 163623241c..6ff2161c1a 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -73,6 +73,7 @@ class Builds extends Action ->inject('deviceForFiles') ->inject('log') ->inject('executor') + ->inject('plan') ->callback([$this, 'action']); } @@ -92,6 +93,7 @@ class Builds extends Action * @param Device $deviceForFiles * @param Log $log * @param Executor $executor + * @param array $plan * @return void * @throws \Utopia\Database\Exception */ @@ -111,7 +113,8 @@ class Builds extends Action callable $isResourceBlocked, Device $deviceForFiles, Log $log, - Executor $executor + Executor $executor, + array $plan ): void { $payload = $message->getPayload() ?? []; @@ -150,7 +153,8 @@ class Builds extends Action $template, $isResourceBlocked, $log, - $executor + $executor, + $plan ); break; @@ -177,6 +181,7 @@ class Builds extends Action * @param Document $template * @param Log $log * @param Executor $executor + * @param array $plan * @return void * @throws \Utopia\Database\Exception * @@ -200,7 +205,8 @@ class Builds extends Action Document $template, callable $isResourceBlocked, Log $log, - Executor $executor + Executor $executor, + array $plan ): void { $resourceKey = match ($resource->getCollection()) { 'functions' => 'functionId', @@ -476,8 +482,12 @@ class Builds extends Action $directorySize = $localDevice->getDirectorySize($tmpDirectory); $sizeLimit = (int)System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000'); + if (isset($plan['deploymentSize'])) { + $sizeLimit = (int) $plan['deploymentSize'] * 1000 * 1000; + } + if ($directorySize > $sizeLimit) { - throw new \Exception('Repository directory size should be less than ' . number_format($sizeLimit / 1048576, 2) . ' MBs.'); + throw new \Exception('Repository directory size should be less than ' . number_format($sizeLimit / (1000 * 1000), 2) . ' MBs.'); } Console::execute('find ' . \escapeshellarg($tmpDirectory) . ' -type d -name ".git" -exec rm -rf {} +', '', $stdout, $stderr); @@ -803,8 +813,11 @@ class Builds extends Action $durationEnd = \microtime(true); $buildSizeLimit = (int)System::getEnv('_APP_COMPUTE_BUILD_SIZE_LIMIT', '2000000000'); + if (isset($plan['buildSize'])) { + $buildSizeLimit = $plan['buildSize'] * 1000 * 1000; + } if ($response['size'] > $buildSizeLimit) { - throw new \Exception('Build size should be less than ' . number_format($buildSizeLimit / 1048576, 2) . ' MBs.'); + throw new \Exception('Build size should be less than ' . number_format($buildSizeLimit / (1000 * 1000), 2) . ' MBs.'); } /** Update the build document */ diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php index 7400d86e74..afa1dba7d8 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php @@ -85,6 +85,7 @@ class Create extends Action ->inject('deviceForSites') ->inject('deviceForLocal') ->inject('queueForBuilds') + ->inject('plan') ->callback([$this, 'action']); } @@ -103,7 +104,8 @@ class Create extends Action Event $queueForEvents, Device $deviceForSites, Device $deviceForLocal, - Build $queueForBuilds + Build $queueForBuilds, + array $plan ) { $activate = \strval($activate) === 'true' || \strval($activate) === '1'; @@ -136,8 +138,14 @@ class Create extends Action throw new Exception(Exception::STORAGE_FILE_EMPTY, 'No file sent'); } + $siteSizeLimit = (int) System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000'); + + if (isset($plan['deploymentSize'])) { + $siteSizeLimit = $plan['deploymentSize'] * 1000 * 1000; + } + $fileExt = new FileExt([FileExt::TYPE_GZIP]); - $fileSizeValidator = new FileSize(System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000')); + $fileSizeValidator = new FileSize($siteSizeLimit); $upload = new Upload(); // Make sure we handle a single file and multiple files the same way From d2d9032ede2395e0cd79f5272901579789378b38 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 23 May 2025 00:49:26 +1200 Subject: [PATCH 05/31] Fix bucket not included in path --- app/init/resources.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/init/resources.php b/app/init/resources.php index 910e8369db..14961ea44b 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -487,10 +487,9 @@ App::setResource('timelimit', function (\Redis $redis) { }; }, ['redis']); -App::setResource('deviceForLocal', function (Telemetry $telemetry) { +App::setResource('deviceForLocal', function () { return new Local(); -}, ['telemetry']); - +}); App::setResource('deviceForFiles', function ($project) { return getDevice(APP_STORAGE_UPLOADS . '/app-' . $project->getId()); }, ['project']); @@ -534,7 +533,8 @@ function getDevice(string $root, string $connection = ''): Device switch ($device) { case Storage::DEVICE_S3: if (!empty($url)) { - return new S3($root, $accessKey, $accessSecret, $url, $region, $acl); + $bucketRoot = (!empty($bucket) ? $bucket . '/' : '') . \ltrim($root, '/'); + return new S3($bucketRoot, $accessKey, $accessSecret, $url, $region, $acl); } else { return new AWS($root, $accessKey, $accessSecret, $bucket, $region, $acl); } @@ -566,7 +566,8 @@ function getDevice(string $root, string $connection = ''): Device $s3Acl = 'private'; $s3EndpointUrl = System::getEnv('_APP_STORAGE_S3_ENDPOINT', ''); if (!empty($s3EndpointUrl)) { - return new S3($root, $s3AccessKey, $s3SecretKey, $s3EndpointUrl, $s3Region, $s3Acl); + $bucketRoot = (!empty($s3Bucket) ? $s3Bucket . '/' : '') . \ltrim($root, '/'); + return new S3($bucketRoot, $s3AccessKey, $s3SecretKey, $s3EndpointUrl, $s3Region, $s3Acl); } else { return new AWS($root, $s3AccessKey, $s3SecretKey, $s3Bucket, $s3Region, $s3Acl); } From bd01d12db57f64ab4faf18be3ada1c8758ca618b Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 23 May 2025 00:51:31 +1200 Subject: [PATCH 06/31] Format --- app/init/resources.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/init/resources.php b/app/init/resources.php index 14961ea44b..c75df2a362 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -52,7 +52,6 @@ use Utopia\Storage\Device\S3; use Utopia\Storage\Device\Wasabi; use Utopia\Storage\Storage; use Utopia\System\System; -use Utopia\Telemetry\Adapter as Telemetry; use Utopia\Telemetry\Adapter\None as NoTelemetry; use Utopia\Validator\Hostname; use Utopia\Validator\WhiteList; From 9321f585f5d67e23944a3c979fd27629957e3439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 22 May 2025 15:22:40 +0200 Subject: [PATCH 07/31] Update app/worker.php --- app/worker.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/worker.php b/app/worker.php index 1277162bfa..597e8a9943 100644 --- a/app/worker.php +++ b/app/worker.php @@ -240,9 +240,6 @@ Server::setResource('timelimit', function (\Redis $redis) { Server::setResource('log', fn () => new Log()); -Server::setResource('plan', function (array $plan = []) { - return []; -}); Server::setResource('publisher', function (Group $pools) { return new BrokerPool(publisher: $pools->get('publisher')); From 71e34464988503e4613ee1f8793956f118ad1a4b Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 23 May 2025 02:55:29 +1200 Subject: [PATCH 08/31] Change internal ID to sequence --- CHANGES.md | 2 +- CONTRIBUTING.md | 10 +- app/cli.php | 12 +- app/config/console.php | 2 +- app/controllers/api/account.php | 70 ++--- app/controllers/api/avatars.php | 12 +- app/controllers/api/databases.php | 260 +++++++++--------- app/controllers/api/messaging.php | 28 +- app/controllers/api/migrations.php | 2 +- app/controllers/api/project.php | 18 +- app/controllers/api/projects.php | 46 ++-- app/controllers/api/proxy.php | 8 +- app/controllers/api/storage.php | 80 +++--- app/controllers/api/teams.php | 24 +- app/controllers/api/users.php | 30 +- app/controllers/api/vcs.php | 32 +-- app/controllers/general.php | 20 +- app/controllers/mock.php | 4 +- app/controllers/shared/api.php | 8 +- app/http.php | 4 +- app/init/database/filters.php | 32 +-- app/init/resources.php | 22 +- app/realtime.php | 10 +- app/worker.php | 16 +- src/Appwrite/Deletes/Targets.php | 4 +- src/Appwrite/Event/Event.php | 2 +- src/Appwrite/Migration/Migration.php | 12 +- src/Appwrite/Migration/Version/V15.php | 30 +- src/Appwrite/Migration/Version/V16.php | 2 +- src/Appwrite/Migration/Version/V17.php | 4 +- src/Appwrite/Migration/Version/V18.php | 16 +- src/Appwrite/Migration/Version/V19.php | 24 +- src/Appwrite/Migration/Version/V20.php | 24 +- src/Appwrite/Migration/Version/V21.php | 8 +- src/Appwrite/Migration/Version/V22.php | 8 +- .../Platform/Modules/Compute/Base.php | 20 +- .../Functions/Http/Deployments/Create.php | 8 +- .../Functions/Http/Deployments/Delete.php | 4 +- .../Http/Deployments/Duplicate/Create.php | 6 +- .../Http/Deployments/Status/Update.php | 2 +- .../Http/Deployments/Template/Create.php | 4 +- .../Functions/Http/Deployments/XList.php | 2 +- .../Functions/Http/Executions/Create.php | 14 +- .../Functions/Http/Executions/Delete.php | 2 +- .../Modules/Functions/Http/Executions/Get.php | 2 +- .../Functions/Http/Executions/XList.php | 2 +- .../Functions/Http/Functions/Create.php | 26 +- .../Http/Functions/Deployment/Update.php | 6 +- .../Functions/Http/Functions/Update.php | 14 +- .../Modules/Functions/Http/Usage/Get.php | 22 +- .../Functions/Http/Variables/Create.php | 2 +- .../Functions/Http/Variables/Delete.php | 2 +- .../Modules/Functions/Http/Variables/Get.php | 2 +- .../Functions/Http/Variables/Update.php | 2 +- .../Modules/Functions/Workers/Builds.php | 74 ++--- .../Modules/Projects/Http/DevKeys/Create.php | 2 +- .../Modules/Projects/Http/DevKeys/Delete.php | 2 +- .../Modules/Projects/Http/DevKeys/Get.php | 2 +- .../Modules/Projects/Http/DevKeys/Update.php | 2 +- .../Modules/Projects/Http/DevKeys/XList.php | 2 +- .../Modules/Proxy/Http/Rules/API/Create.php | 2 +- .../Proxy/Http/Rules/Function/Create.php | 6 +- .../Proxy/Http/Rules/Redirect/Create.php | 2 +- .../Modules/Proxy/Http/Rules/Site/Create.php | 6 +- .../Modules/Sites/Http/Deployments/Create.php | 16 +- .../Modules/Sites/Http/Deployments/Delete.php | 4 +- .../Http/Deployments/Duplicate/Create.php | 12 +- .../Sites/Http/Deployments/Status/Update.php | 2 +- .../Http/Deployments/Template/Create.php | 10 +- .../Modules/Sites/Http/Deployments/XList.php | 2 +- .../Modules/Sites/Http/Logs/Delete.php | 2 +- .../Platform/Modules/Sites/Http/Logs/Get.php | 2 +- .../Modules/Sites/Http/Logs/XList.php | 2 +- .../Modules/Sites/Http/Sites/Create.php | 10 +- .../Sites/Http/Sites/Deployment/Update.php | 6 +- .../Modules/Sites/Http/Sites/Update.php | 14 +- .../Platform/Modules/Sites/Http/Usage/Get.php | 28 +- .../Modules/Sites/Http/Variables/Create.php | 2 +- .../Modules/Sites/Http/Variables/Delete.php | 2 +- .../Modules/Sites/Http/Variables/Get.php | 2 +- .../Modules/Sites/Http/Variables/Update.php | 2 +- .../Http/Tokens/Buckets/Files/Action.php | 4 +- .../Http/Tokens/Buckets/Files/Create.php | 2 +- .../Http/Tokens/Buckets/Files/XList.php | 2 +- src/Appwrite/Platform/Tasks/ScheduleBase.php | 10 +- .../Platform/Tasks/ScheduleExecutions.php | 4 +- .../Platform/Tasks/ScheduleMessages.php | 2 +- .../Platform/Tasks/StatsResources.php | 2 +- src/Appwrite/Platform/Workers/Audits.php | 14 +- .../Platform/Workers/Certificates.php | 2 +- src/Appwrite/Platform/Workers/Databases.php | 44 +-- src/Appwrite/Platform/Workers/Deletes.php | 42 +-- src/Appwrite/Platform/Workers/Functions.php | 12 +- src/Appwrite/Platform/Workers/Messaging.php | 4 +- src/Appwrite/Platform/Workers/Migrations.php | 2 +- .../Platform/Workers/StatsResources.php | 70 ++--- src/Appwrite/Platform/Workers/StatsUsage.php | 46 ++-- .../Platform/Workers/StatsUsageDump.php | 4 +- src/Appwrite/Platform/Workers/Webhooks.php | 4 +- .../Database/Validator/Queries/Base.php | 6 +- .../Utopia/Response/Model/Document.php | 2 +- .../e2e/Services/Databases/DatabasesBase.php | 12 +- 102 files changed, 768 insertions(+), 768 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bc903e4b31..fa4db4acc5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -607,7 +607,7 @@ ### Fixes * Fix database exception wrapping by @abnegate in https://github.com/appwrite/appwrite/pull/7787 * Fix exception wrap order by @abnegate in https://github.com/appwrite/appwrite/pull/7818 -* Fix membership query to use internalId by @lohanidamodar in https://github.com/appwrite/appwrite/pull/7834 +* Fix membership query to use sequence by @lohanidamodar in https://github.com/appwrite/appwrite/pull/7834 * Fix vcs silent mode by @vermakhushboo in https://github.com/appwrite/appwrite/pull/7683 * Fix function domain permissions by @stnguyen90 in https://github.com/appwrite/appwrite/pull/7852 * Fix tests required for Cloud by @lohanidamodar in https://github.com/appwrite/appwrite/pull/7777 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7746ef99af..277a509447 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -415,8 +415,8 @@ In addition, you will also need to add some logic to the `reduce()` method of th ```php case $document->getCollection() === 'buckets': - $files = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getInternalId(), METRIC_BUCKET_ID_FILES))); - $storage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getInternalId(), METRIC_BUCKET_ID_FILES_STORAGE))); + $files = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getSequence(), METRIC_BUCKET_ID_FILES))); + $storage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getSequence(), METRIC_BUCKET_ID_FILES_STORAGE))); if (!empty($files['value'])) { $metrics[] = [ @@ -463,9 +463,9 @@ $queueForStatsUsage ->addMetric(METRIC_BUILDS, 1) ->addMetric(METRIC_BUILDS_STORAGE, $build->getAttribute('size', 0)) ->addMetric(METRIC_BUILDS_COMPUTE, (int)$build->getAttribute('duration', 0) * 1000) - ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS), 1) - ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_STORAGE), $build->getAttribute('size', 0)) - ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_COMPUTE), (int)$build->getAttribute('duration', 0) * 1000) + ->addMetric(str_replace('{functionInternalId}', $function->getSequence(), METRIC_FUNCTION_ID_BUILDS), 1) + ->addMetric(str_replace('{functionInternalId}', $function->getSequence(), METRIC_FUNCTION_ID_BUILDS_STORAGE), $build->getAttribute('size', 0)) + ->addMetric(str_replace('{functionInternalId}', $function->getSequence(), METRIC_FUNCTION_ID_BUILDS_COMPUTE), (int)$build->getAttribute('duration', 0) * 1000) ->setProject($project) ->trigger(); ``` diff --git a/app/cli.php b/app/cli.php index 9517347420..224f150a58 100644 --- a/app/cli.php +++ b/app/cli.php @@ -125,13 +125,13 @@ CLI::setResource('getProjectDB', function (Group $pools, Database $dbForPlatform if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getInternalId()) + ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getInternalId()); + ->setNamespace('_' . $project->getSequence()); } return $database; @@ -145,13 +145,13 @@ CLI::setResource('getProjectDB', function (Group $pools, Database $dbForPlatform if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getInternalId()) + ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getInternalId()); + ->setNamespace('_' . $project->getSequence()); } $database @@ -167,7 +167,7 @@ CLI::setResource('getLogsDB', function (Group $pools, Cache $cache) { return function (?Document $project = null) use ($pools, $cache, $database) { if ($database !== null && $project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getInternalId()); + $database->setTenant($project->getSequence()); return $database; } @@ -182,7 +182,7 @@ CLI::setResource('getLogsDB', function (Group $pools, Cache $cache) { // set tenant if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getInternalId()); + $database->setTenant($project->getSequence()); } return $database; diff --git a/app/config/console.php b/app/config/console.php index e37c9b7836..1de3a99370 100644 --- a/app/config/console.php +++ b/app/config/console.php @@ -11,7 +11,7 @@ use Utopia\System\System; $console = [ '$id' => ID::custom('console'), - '$internalId' => ID::custom('console'), + '$sequence' => ID::custom('console'), 'name' => 'Appwrite', '$collection' => ID::custom('projects'), 'description' => 'Appwrite core engine', diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index ac01476314..0c53423325 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -190,7 +190,7 @@ $createSession = function (string $userId, string $secret, Request $request, Res [ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'provider' => Auth::getSessionProviderByTokenType($verifiedToken->getAttribute('type')), 'secret' => Auth::hash($sessionSecret), // One way hash encryption to protect DB leak 'userAgent' => $request->getUserAgent('UNKNOWN'), @@ -387,7 +387,7 @@ App::post('/v1/account') 'search' => implode(' ', [$userId, $email, $name]), 'accessedAt' => DateTime::now(), ]); - $user->removeAttribute('$internalId'); + $user->removeAttribute('$sequence'); $user = Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); try { $target = Authorization::skip(fn () => $dbForProject->createDocument('targets', new Document([ @@ -397,7 +397,7 @@ App::post('/v1/account') Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'providerType' => MESSAGE_TYPE_EMAIL, 'identifier' => $email, ]))); @@ -907,7 +907,7 @@ App::post('/v1/account/sessions/email') [ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => $email, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak @@ -1056,7 +1056,7 @@ App::post('/v1/account/sessions/anonymous') 'search' => $userId, 'accessedAt' => DateTime::now(), ]); - $user->removeAttribute('$internalId'); + $user->removeAttribute('$sequence'); Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); // Create session token @@ -1069,7 +1069,7 @@ App::post('/v1/account/sessions/anonymous') [ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'provider' => Auth::SESSION_PROVIDER_ANONYMOUS, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak 'userAgent' => $request->getUserAgent('UNKNOWN'), @@ -1440,7 +1440,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $identityWithMatchingEmail = $dbForProject->findOne('identities', [ Query::equal('providerEmail', [$email]), - Query::notEqual('userInternalId', $user->getInternalId()), + Query::notEqual('userInternalId', $user->getSequence()), ]); if (!$identityWithMatchingEmail->isEmpty()) { $failureRedirect(Exception::USER_ALREADY_EXISTS); @@ -1554,7 +1554,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') 'search' => implode(' ', [$userId, $email, $name]), 'accessedAt' => DateTime::now(), ]); - $user->removeAttribute('$internalId'); + $user->removeAttribute('$sequence'); $userDoc = Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); $dbForProject->createDocument('targets', new Document([ '$permissions' => [ @@ -1563,7 +1563,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') Permission::delete(Role::user($user->getId())), ], 'userId' => $userDoc->getId(), - 'userInternalId' => $userDoc->getInternalId(), + 'userInternalId' => $userDoc->getSequence(), 'providerType' => MESSAGE_TYPE_EMAIL, 'identifier' => $email, ])); @@ -1582,7 +1582,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') } $identity = $dbForProject->findOne('identities', [ - Query::equal('userInternalId', [$user->getInternalId()]), + Query::equal('userInternalId', [$user->getSequence()]), Query::equal('provider', [$provider]), Query::equal('providerUid', [$oauth2ID]), ]); @@ -1592,7 +1592,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $identitiesWithMatchingEmail = $dbForProject->find('identities', [ Query::equal('providerEmail', [$email]), - Query::notEqual('userInternalId', $user->getInternalId()), + Query::notEqual('userInternalId', $user->getSequence()), ]); if (!empty($identitiesWithMatchingEmail)) { $failureRedirect(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */ @@ -1605,7 +1605,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') Permission::update(Role::user($userId)), Permission::delete(Role::user($userId)), ], - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'userId' => $userId, 'provider' => $provider, 'providerUid' => $oauth2ID, @@ -1648,7 +1648,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $token = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'type' => Auth::TOKEN_TYPE_OAUTH2, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak 'expire' => $expire, @@ -1683,7 +1683,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $session = new Document(array_merge([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'provider' => $provider, 'providerUid' => $oauth2ID, 'providerAccessToken' => $accessToken, @@ -1736,7 +1736,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $target ->setAttribute('sessionId', $session->getId()) - ->setAttribute('sessionInternalId', $session->getInternalId()); + ->setAttribute('sessionInternalId', $session->getSequence()); $dbForProject->updateDocument('targets', $target->getId(), $target); } @@ -1931,7 +1931,7 @@ App::post('/v1/account/tokens/magic-url') 'accessedAt' => DateTime::now(), ]); - $user->removeAttribute('$internalId'); + $user->removeAttribute('$sequence'); Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); } @@ -1941,7 +1941,7 @@ App::post('/v1/account/tokens/magic-url') $token = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'type' => Auth::TOKEN_TYPE_MAGIC_URL, 'secret' => Auth::hash($tokenSecret), // One way hash encryption to protect DB leak 'expire' => $expire, @@ -2168,7 +2168,7 @@ App::post('/v1/account/tokens/email') 'accessedAt' => DateTime::now(), ]); - $user->removeAttribute('$internalId'); + $user->removeAttribute('$sequence'); Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); } @@ -2178,7 +2178,7 @@ App::post('/v1/account/tokens/email') $token = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'type' => Auth::TOKEN_TYPE_EMAIL, 'secret' => Auth::hash($tokenSecret), // One way hash encryption to protect DB leak 'expire' => $expire, @@ -2460,7 +2460,7 @@ App::post('/v1/account/tokens/phone') 'accessedAt' => DateTime::now(), ]); - $user->removeAttribute('$internalId'); + $user->removeAttribute('$sequence'); Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); try { $target = Authorization::skip(fn () => $dbForProject->createDocument('targets', new Document([ @@ -2470,7 +2470,7 @@ App::post('/v1/account/tokens/phone') Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'providerType' => MESSAGE_TYPE_SMS, 'identifier' => $phone, ]))); @@ -2501,7 +2501,7 @@ App::post('/v1/account/tokens/phone') $token = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'type' => Auth::TOKEN_TYPE_PHONE, 'secret' => Auth::hash($secret), 'expire' => $expire, @@ -2703,7 +2703,7 @@ App::get('/v1/account/logs') $audit = new EventAudit($dbForProject); - $logs = $audit->getLogsByUser($user->getInternalId(), $queries); + $logs = $audit->getLogsByUser($user->getSequence(), $queries); $output = []; @@ -2732,7 +2732,7 @@ App::get('/v1/account/logs') } $response->dynamic(new Document([ - 'total' => $audit->countLogsByUser($user->getInternalId(), $queries), + 'total' => $audit->countLogsByUser($user->getSequence(), $queries), 'logs' => $output, ]), Response::MODEL_LOG_LIST); }); @@ -2900,7 +2900,7 @@ App::patch('/v1/account/email') // Makes sure this email is not already used in another identity $identityWithMatchingEmail = $dbForProject->findOne('identities', [ Query::equal('providerEmail', [$email]), - Query::notEqual('userInternalId', $user->getInternalId()), + Query::notEqual('userInternalId', $user->getSequence()), ]); if (!$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */ @@ -3183,7 +3183,7 @@ App::post('/v1/account/recovery') $recovery = new Document([ '$id' => ID::unique(), 'userId' => $profile->getId(), - 'userInternalId' => $profile->getInternalId(), + 'userInternalId' => $profile->getSequence(), 'type' => Auth::TOKEN_TYPE_RECOVERY, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak 'expire' => $expire, @@ -3438,7 +3438,7 @@ App::post('/v1/account/verification') $verification = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'type' => Auth::TOKEN_TYPE_VERIFICATION, 'secret' => Auth::hash($verificationSecret), // One way hash encryption to protect DB leak 'expire' => $expire, @@ -3685,7 +3685,7 @@ App::post('/v1/account/verification/phone') $verification = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'type' => Auth::TOKEN_TYPE_PHONE, 'secret' => Auth::hash($secret), 'expire' => $expire, @@ -3979,7 +3979,7 @@ App::post('/v1/account/mfa/authenticators/:type') $authenticator = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'type' => Type::TOTP, 'verified' => false, 'data' => [ @@ -4292,7 +4292,7 @@ App::post('/v1/account/mfa/challenge') $code = Auth::codeGenerator(); $challenge = new Document([ 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'type' => $factor, 'token' => Auth::tokenGenerator(), 'code' => $code, @@ -4621,12 +4621,12 @@ App::post('/v1/account/targets/push') Permission::delete(Role::user($user->getId())), ], 'providerId' => !empty($providerId) ? $providerId : null, - 'providerInternalId' => !empty($providerId) ? $provider->getInternalId() : null, + 'providerInternalId' => !empty($providerId) ? $provider->getSequence() : null, 'providerType' => MESSAGE_TYPE_PUSH, 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'sessionId' => $session->getId(), - 'sessionInternalId' => $session->getInternalId(), + 'sessionInternalId' => $session->getSequence(), 'identifier' => $identifier, 'name' => "{$device['deviceBrand']} {$device['deviceModel']}" ])); @@ -4745,7 +4745,7 @@ App::delete('/v1/account/targets/:targetId/push') throw new Exception(Exception::USER_TARGET_NOT_FOUND); } - if ($user->getInternalId() !== $target->getAttribute('userInternalId')) { + if ($user->getSequence() !== $target->getAttribute('userInternalId')) { throw new Exception(Exception::USER_TARGET_NOT_FOUND); } @@ -4794,7 +4794,7 @@ App::get('/v1/account/identities') throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); } - $queries[] = Query::equal('userInternalId', [$user->getInternalId()]); + $queries[] = Query::equal('userInternalId', [$user->getSequence()]); /** * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index 779a188089..3a7b4aa582 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -669,7 +669,7 @@ App::get('/v1/cards/cloud') } } - $isPlatinum = $user->getInternalId() % 100 === 0; + $isPlatinum = $user->getSequence() % 100 === 0; } else { $name = $mock === 'normal-long' ? 'Sir First Walter O\'Brian Junior' : 'Walter O\'Brian'; $createdAt = new \DateTime('now'); @@ -859,7 +859,7 @@ App::get('/v1/cards/cloud-back') $isEmployee = \array_key_exists($email, $employees); $isGolden = $isEmployee || $isHero || $isContributor; - $isPlatinum = $user->getInternalId() % 100 === 0; + $isPlatinum = $user->getSequence() % 100 === 0; } else { $userId = '63e0bcf3c3eb803ba530'; @@ -926,9 +926,9 @@ App::get('/v1/cards/cloud-og') } if (!$mock) { - $internalId = $user->getInternalId(); - $bgVariation = $internalId % 3 === 0 ? '1' : ($internalId % 3 === 1 ? '2' : '3'); - $cardVariation = $internalId % 3 === 0 ? '1' : ($internalId % 3 === 1 ? '2' : '3'); + $sequence = $user->getSequence(); + $bgVariation = $sequence % 3 === 0 ? '1' : ($sequence % 3 === 1 ? '2' : '3'); + $cardVariation = $sequence % 3 === 0 ? '1' : ($sequence % 3 === 1 ? '2' : '3'); $name = $user->getAttribute('name', 'Anonymous'); $email = $user->getAttribute('email', ''); @@ -958,7 +958,7 @@ App::get('/v1/cards/cloud-og') } } - $isPlatinum = $user->getInternalId() % 100 === 0; + $isPlatinum = $user->getSequence() % 100 === 0; } else { $bgVariation = \str_ends_with($mock, '-bg2') ? '2' : (\str_ends_with($mock, '-bg3') ? '3' : '1'); $cardVariation = \str_ends_with($mock, '-right') ? '2' : (\str_ends_with($mock, '-middle') ? '3' : '1'); diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 352503b730..9ea5b2a197 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -107,7 +107,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -130,7 +130,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att if ($type === Database::VAR_RELATIONSHIP) { $options['side'] = Database::RELATION_SIDE_PARENT; - $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection'] ?? ''); + $relatedCollection = $dbForProject->getDocument('database_' . $database->getSequence(), $options['relatedCollection'] ?? ''); if ($relatedCollection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND, 'The related collection was not found.'); } @@ -138,11 +138,11 @@ function createAttribute(string $databaseId, string $collectionId, Document $att try { $attribute = new Document([ - '$id' => ID::custom($database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key), + '$id' => ID::custom($database->getSequence() . '_' . $collection->getSequence() . '_' . $key), 'key' => $key, - 'databaseInternalId' => $database->getInternalId(), + 'databaseInternalId' => $database->getSequence(), 'databaseId' => $database->getId(), - 'collectionInternalId' => $collection->getInternalId(), + 'collectionInternalId' => $collection->getSequence(), 'collectionId' => $collectionId, 'type' => $type, 'status' => 'processing', // processing, available, failed, deleting, stuck @@ -164,13 +164,13 @@ function createAttribute(string $databaseId, string $collectionId, Document $att } catch (LimitException) { throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED); } catch (\Throwable $e) { - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); - $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); + $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); throw $e; } - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); - $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); + $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); if ($type === Database::VAR_RELATIONSHIP && $options['twoWay']) { $twoWayKey = $options['twoWayKey']; @@ -181,11 +181,11 @@ function createAttribute(string $databaseId, string $collectionId, Document $att try { try { $twoWayAttribute = new Document([ - '$id' => ID::custom($database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $twoWayKey), + '$id' => ID::custom($database->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $twoWayKey), 'key' => $twoWayKey, - 'databaseInternalId' => $database->getInternalId(), + 'databaseInternalId' => $database->getSequence(), 'databaseId' => $database->getId(), - 'collectionInternalId' => $relatedCollection->getInternalId(), + 'collectionInternalId' => $relatedCollection->getSequence(), 'collectionId' => $relatedCollection->getId(), 'type' => $type, 'status' => 'processing', // processing, available, failed, deleting, stuck @@ -213,13 +213,13 @@ function createAttribute(string $databaseId, string $collectionId, Document $att $dbForProject->deleteDocument('attributes', $attribute->getId()); throw $e; } finally { - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); - $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); + $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); } // If operation succeeded, purge the cache for the related collection too - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); - $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $relatedCollection->getId()); + $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence()); } $queueForDatabase @@ -262,12 +262,12 @@ function updateAttribute( throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $attribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key); + $attribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key); if ($attribute->isEmpty()) { throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); } @@ -292,7 +292,7 @@ function updateAttribute( throw new Exception(Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED, 'Cannot set default value for array attributes'); } - $collectionId = 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(); + $collectionId = 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(); $attribute ->setAttribute('default', $default) @@ -378,8 +378,8 @@ function updateAttribute( } if ($primaryDocumentOptions['twoWay']) { - $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $primaryDocumentOptions['relatedCollection']); - $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $primaryDocumentOptions['twoWayKey']); + $relatedCollection = $dbForProject->getDocument('database_' . $database->getSequence(), $primaryDocumentOptions['relatedCollection']); + $relatedAttribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $primaryDocumentOptions['twoWayKey']); if (!empty($newKey) && $newKey !== $key) { $options['twoWayKey'] = $newKey; @@ -389,8 +389,8 @@ function updateAttribute( $relatedAttribute->setAttribute('options', $relatedOptions); - $dbForProject->updateDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $primaryDocumentOptions['twoWayKey'], $relatedAttribute); - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); + $dbForProject->updateDocument('attributes', $database->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $primaryDocumentOptions['twoWayKey'], $relatedAttribute); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $relatedCollection->getId()); } } else { try { @@ -418,7 +418,7 @@ function updateAttribute( $originalUid = $attribute->getId(); $attribute - ->setAttribute('$id', ID::custom($database->getInternalId() . '_' . $collection->getInternalId() . '_' . $newKey)) + ->setAttribute('$id', ID::custom($database->getSequence() . '_' . $collection->getSequence() . '_' . $newKey)) ->setAttribute('key', $newKey); try { @@ -444,10 +444,10 @@ function updateAttribute( } } } else { - $attribute = $dbForProject->updateDocument('attributes', $database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key, $attribute); + $attribute = $dbForProject->updateDocument('attributes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key, $attribute); } - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collection->getId()); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collection->getId()); $queueForEvents ->setContext('collection', $collection) @@ -536,7 +536,7 @@ App::post('/v1/databases') } try { - $dbForProject->createCollection('database_' . $database->getInternalId(), $attributes, $indexes); + $dbForProject->createCollection('database_' . $database->getSequence(), $attributes, $indexes); } catch (DuplicateException) { throw new Exception(Exception::DATABASE_ALREADY_EXISTS); } catch (IndexException) { @@ -839,7 +839,7 @@ App::delete('/v1/databases/:databaseId') } $dbForProject->purgeCachedDocument('databases', $database->getId()); - $dbForProject->purgeCachedCollection('databases_' . $database->getInternalId()); + $dbForProject->purgeCachedCollection('databases_' . $database->getSequence()); $queueForDatabase ->setType(DATABASE_TYPE_DELETE_DATABASE) @@ -899,9 +899,9 @@ App::post('/v1/databases/:databaseId/collections') $permissions = Permission::aggregate($permissions) ?? []; try { - $collection = $dbForProject->createDocument('database_' . $database->getInternalId(), new Document([ + $collection = $dbForProject->createDocument('database_' . $database->getSequence(), new Document([ '$id' => $collectionId, - 'databaseInternalId' => $database->getInternalId(), + 'databaseInternalId' => $database->getSequence(), 'databaseId' => $databaseId, '$permissions' => $permissions, 'documentSecurity' => $documentSecurity, @@ -919,7 +919,7 @@ App::post('/v1/databases/:databaseId/collections') try { $dbForProject->createCollection( - id: 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), + id: 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), permissions: $permissions, documentSecurity: $documentSecurity ); @@ -1000,7 +1000,7 @@ App::get('/v1/databases/:databaseId/collections') $collectionId = $cursor->getValue(); - $cursorDocument = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $cursorDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($cursorDocument->isEmpty()) { throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Collection '{$collectionId}' for the 'cursor' value not found."); @@ -1009,7 +1009,7 @@ App::get('/v1/databases/:databaseId/collections') $cursor->setValue($cursorDocument); } - $collectionId = 'database_' . $database->getInternalId(); + $collectionId = 'database_' . $database->getSequence(); try { $collections = $dbForProject->find($collectionId, $queries); @@ -1057,7 +1057,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -1100,8 +1100,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/logs') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collectionDocument = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); - $collection = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $collectionDocument->getInternalId()); + $collectionDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collectionDocument->getSequence()); if ($collectionDocument->isEmpty() || $collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -1215,7 +1215,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -1236,12 +1236,12 @@ App::put('/v1/databases/:databaseId/collections/:collectionId') ->setAttribute('search', \implode(' ', [$collectionId, $name])); $collection = $dbForProject->updateDocument( - 'database_' . $database->getInternalId(), + 'database_' . $database->getSequence(), $collectionId, $collection ); - $dbForProject->updateCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $permissions, $documentSecurity); + $dbForProject->updateCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $permissions, $documentSecurity); $queueForEvents ->setContext('database', $database) @@ -1287,17 +1287,17 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - if (!$dbForProject->deleteDocument('database_' . $database->getInternalId(), $collectionId)) { + if (!$dbForProject->deleteDocument('database_' . $database->getSequence(), $collectionId)) { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove collection from DB'); } - $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); + $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); $queueForDatabase ->setType(DATABASE_TYPE_DELETE_COLLECTION) @@ -1882,15 +1882,15 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/relati throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); - $collection = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $relatedCollectionDocument = $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId); - $relatedCollection = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $relatedCollectionDocument->getInternalId()); + $relatedCollectionDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId); + $relatedCollection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $relatedCollectionDocument->getSequence()); if ($relatedCollection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -1991,7 +1991,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -2004,8 +2004,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') \array_push( $queries, - Query::equal('databaseInternalId', [$database->getInternalId()]), - Query::equal('collectionInternalId', [$collection->getInternalId()]), + Query::equal('databaseInternalId', [$database->getSequence()]), + Query::equal('collectionInternalId', [$collection->getSequence()]), ); /** @@ -2027,8 +2027,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') try { $cursorDocument = $dbForProject->findOne('attributes', [ - Query::equal('databaseInternalId', [$database->getInternalId()]), - Query::equal('collectionInternalId', [$collection->getInternalId()]), + Query::equal('databaseInternalId', [$database->getSequence()]), + Query::equal('collectionInternalId', [$collection->getSequence()]), Query::equal('key', [$attributeId]), ]); } catch (QueryException $e) { @@ -2099,13 +2099,13 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes/:key') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $attribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key); + $attribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key); if ($attribute->isEmpty()) { throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); @@ -2712,13 +2712,13 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/attributes/:key throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $attribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key); + $attribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key); if ($attribute->isEmpty()) { throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); @@ -2741,19 +2741,19 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/attributes/:key $attribute = $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'deleting')); } - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); - $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); + $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); if ($attribute->getAttribute('type') === Database::VAR_RELATIONSHIP) { $options = $attribute->getAttribute('options'); if ($options['twoWay']) { - $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); + $relatedCollection = $dbForProject->getDocument('database_' . $database->getSequence(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); + $relatedAttribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $options['twoWayKey']); if ($relatedAttribute->isEmpty()) { throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); @@ -2763,8 +2763,8 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/attributes/:key $dbForProject->updateDocument('attributes', $relatedAttribute->getId(), $relatedAttribute->setAttribute('status', 'deleting')); } - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $options['relatedCollection']); - $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $options['relatedCollection']); + $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence()); } } @@ -2846,7 +2846,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -2855,8 +2855,8 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') $limit = $dbForProject->getLimitForIndexes(); $count = $dbForProject->count('indexes', [ - Query::equal('collectionInternalId', [$collection->getInternalId()]), - Query::equal('databaseInternalId', [$database->getInternalId()]) + Query::equal('collectionInternalId', [$collection->getSequence()]), + Query::equal('databaseInternalId', [$database->getSequence()]) ], max: $limit); @@ -2926,12 +2926,12 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') } $index = new Document([ - '$id' => ID::custom($database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key), + '$id' => ID::custom($database->getSequence() . '_' . $collection->getSequence() . '_' . $key), 'key' => $key, 'status' => 'processing', // processing, available, failed, deleting, stuck - 'databaseInternalId' => $database->getInternalId(), + 'databaseInternalId' => $database->getSequence(), 'databaseId' => $databaseId, - 'collectionInternalId' => $collection->getInternalId(), + 'collectionInternalId' => $collection->getSequence(), 'collectionId' => $collectionId, 'type' => $type, 'attributes' => $attributes, @@ -2955,7 +2955,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') throw new Exception(Exception::INDEX_ALREADY_EXISTS); } - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); $queueForDatabase ->setType(DATABASE_TYPE_CREATE_INDEX) @@ -3007,7 +3007,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -3038,8 +3038,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes') $indexId = $cursor->getValue(); $cursorDocument = Authorization::skip(fn () => $dbForProject->find('indexes', [ - Query::equal('collectionInternalId', [$collection->getInternalId()]), - Query::equal('databaseInternalId', [$database->getInternalId()]), + Query::equal('collectionInternalId', [$collection->getSequence()]), + Query::equal('databaseInternalId', [$database->getSequence()]), Query::equal('key', [$indexId]), Query::limit(1) ])); @@ -3098,7 +3098,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes/:key') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -3151,13 +3151,13 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/indexes/:key') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $index = $dbForProject->getDocument('indexes', $database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key); + $index = $dbForProject->getDocument('indexes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key); if ($index->isEmpty()) { throw new Exception(Exception::INDEX_NOT_FOUND); @@ -3168,7 +3168,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/indexes/:key') $index = $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'deleting')); } - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); $queueForDatabase ->setType(DATABASE_TYPE_DELETE_INDEX) @@ -3304,7 +3304,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); + $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -3413,7 +3413,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) ); foreach ($relations as &$relation) { @@ -3427,7 +3427,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') } if ($relation instanceof Document) { $current = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), $relation->getId()) + fn () => $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence(), $relation->getId()) ); if ($current->isEmpty()) { @@ -3482,7 +3482,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') try { $dbForProject->createDocuments( - 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), + 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documents ); } catch (DuplicateException) { @@ -3524,7 +3524,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) ); foreach ($related as $relation) { @@ -3541,7 +3541,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $operations)) - ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); // per collection + ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); // per collection $response->setStatusCode(Response::STATUS_CODE_CREATED); @@ -3599,7 +3599,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); + $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -3627,7 +3627,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $documentId = $cursor->getValue(); - $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId)); + $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId)); if ($cursorDocument->isEmpty()) { throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Document '{$documentId}' for the 'cursor' value not found."); @@ -3636,8 +3636,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $cursor->setValue($cursorDocument); } try { - $documents = $dbForProject->find('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $queries); - $total = $dbForProject->count('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $queries, APP_LIMIT_COUNT); + $documents = $dbForProject->find('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $queries); + $total = $dbForProject->count('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $queries, APP_LIMIT_COUNT); } catch (OrderException $e) { throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } catch (QueryException $e) { @@ -3681,7 +3681,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $relatedCollectionId = $relationship->getAttribute('relatedCollection'); // todo: Use local cache for this getDocument - $relatedCollection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId)); + $relatedCollection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId)); foreach ($relations as $index => $doc) { if ($doc instanceof Document) { @@ -3707,7 +3707,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_READS, \max(1, $operations)) - ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_READS), \max(1, $operations)); + ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_READS), \max(1, $operations)); $select = \array_reduce($queries, function ($result, $query) { return $result || ($query->getMethod() === Query::TYPE_SELECT); @@ -3778,7 +3778,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); + $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -3790,7 +3790,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen } try { - $document = $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId, $queries); + $document = $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId, $queries); } catch (QueryException $e) { throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); } @@ -3834,7 +3834,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) ); foreach ($related as $relation) { @@ -3849,7 +3849,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_READS, \max(1, $operations)) - ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_READS), \max(1, $operations)); + ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_READS), \max(1, $operations)); $response->dynamic($document, Response::MODEL_DOCUMENT); }); @@ -3888,12 +3888,12 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $document = $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId); + $document = $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId); if ($document->isEmpty()) { throw new Exception(Exception::DOCUMENT_NOT_FOUND); @@ -4017,13 +4017,13 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); + $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } // Read permission should not be required for update - $document = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId)); + $document = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId)); if ($document->isEmpty()) { throw new Exception(Exception::DOCUMENT_NOT_FOUND); } @@ -4092,7 +4092,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) ); foreach ($relations as &$relation) { @@ -4107,7 +4107,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum } if ($relation instanceof Document) { $oldDocument = Authorization::skip(fn () => $dbForProject->getDocument( - 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), + 'database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence(), $relation->getId() )); $relation->removeAttribute('$collectionId'); @@ -4115,7 +4115,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum // Attribute $collection is required for Utopia. $relation->setAttribute( '$collection', - 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId() + 'database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence() ); if ($oldDocument->isEmpty()) { @@ -4139,11 +4139,11 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $operations)) - ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); + ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); try { $document = $dbForProject->updateDocument( - 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), + 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $document->getId(), $newDocument ); @@ -4179,7 +4179,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) ); foreach ($related as $relation) { @@ -4261,7 +4261,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); + $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -4326,7 +4326,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) ); foreach ($relations as &$relation) { @@ -4341,7 +4341,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen } if ($relation instanceof Document) { $oldDocument = Authorization::skip(fn () => $dbForProject->getDocument( - 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), + 'database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence(), $relation->getId() )); $relation->removeAttribute('$collectionId'); @@ -4349,7 +4349,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen // Attribute $collection is required for Utopia. $relation->setAttribute( '$collection', - 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId() + 'database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence() ); if ($oldDocument->isEmpty()) { @@ -4373,12 +4373,12 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $operations)) - ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); + ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); $upserted = []; try { $modified = $dbForProject->createOrUpdateDocuments( - 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), + 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), [$newDocument], onNext: function (Document $document) use (&$upserted) { $upserted[] = $document; @@ -4417,7 +4417,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) ); foreach ($related as $relation) { @@ -4496,7 +4496,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -4527,7 +4527,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents') try { $modified = $dbForProject->updateDocuments( - 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), + 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), new Document($data), $queries, onNext: function (Document $document) use ($plan, &$documents) { @@ -4551,7 +4551,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents') $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $modified)) - ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $modified)); + ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $modified)); $response->dynamic(new Document([ 'total' => $modified, @@ -4596,7 +4596,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -4618,7 +4618,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents') try { $modified = $dbForProject->createOrUpdateDocuments( - 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), + 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documents, onNext: function (Document $document) use ($plan, &$upserted) { if (\count($upserted) < ($plan['databasesBatchSize'] ?? APP_LIMIT_DATABASE_BATCH)) { @@ -4643,7 +4643,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents') $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $modified)) - ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $modified)); + ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $modified)); $response->dynamic(new Document([ 'total' => $modified, @@ -4694,20 +4694,20 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents/:docu throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); + $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } // Read permission should not be required for delete - $document = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId)); + $document = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId)); if ($document->isEmpty()) { throw new Exception(Exception::DOCUMENT_NOT_FOUND); } try { $dbForProject->deleteDocument( - 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), + 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId ); } catch (ConflictException) { @@ -4742,7 +4742,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents/:docu $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) ); foreach ($related as $relation) { @@ -4757,7 +4757,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents/:docu $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $operations)) - ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); + ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); $relationships = \array_map( fn ($document) => $document->getAttribute('key'), @@ -4816,7 +4816,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -4840,7 +4840,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents') try { $modified = $dbForProject->deleteDocuments( - 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), + 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $queries, onNext: function (Document $document) use ($plan, &$documents) { if (\count($documents) < ($plan['databasesBatchSize'] ?? APP_LIMIT_DATABASE_BATCH)) { @@ -4861,7 +4861,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents') $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $modified)) - ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $modified)); + ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $modified)); $response->dynamic(new Document([ 'total' => $modified, @@ -4997,11 +4997,11 @@ App::get('/v1/databases/:databaseId/usage') $stats = $usage = []; $days = $periods[$range]; $metrics = [ - str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_COLLECTIONS), - str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_DOCUMENTS), - str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_STORAGE), - str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_READS), - str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES) + str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_COLLECTIONS), + str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_DOCUMENTS), + str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_STORAGE), + str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_READS), + str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES) ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { @@ -5090,8 +5090,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/usage') ->inject('dbForProject') ->action(function (string $databaseId, string $range, string $collectionId, Response $response, Database $dbForProject) { $database = $dbForProject->getDocument('databases', $databaseId); - $collectionDocument = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); - $collection = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $collectionDocument->getInternalId()); + $collectionDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collectionDocument->getSequence()); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -5101,7 +5101,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/usage') $stats = $usage = []; $days = $periods[$range]; $metrics = [ - str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$database->getInternalId(), $collectionDocument->getInternalId()], METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS), + str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$database->getSequence(), $collectionDocument->getSequence()], METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS), ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 1d11e6c392..c74314e905 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -2511,11 +2511,11 @@ App::post('/v1/messaging/topics/:topicId/subscribers') Permission::delete(Role::user($user->getId())), ], 'topicId' => $topicId, - 'topicInternalId' => $topic->getInternalId(), + 'topicInternalId' => $topic->getSequence(), 'targetId' => $targetId, - 'targetInternalId' => $target->getInternalId(), + 'targetSequence' => $target->getSequence(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'providerType' => $target->getAttribute('providerType'), 'search' => implode(' ', [ $subscriberId, @@ -2597,7 +2597,7 @@ App::get('/v1/messaging/topics/:topicId/subscribers') throw new Exception(Exception::TOPIC_NOT_FOUND); } - $queries[] = Query::equal('topicInternalId', [$topic->getInternalId()]); + $queries[] = Query::equal('topicInternalId', [$topic->getSequence()]); /** * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries @@ -2947,7 +2947,7 @@ App::post('/v1/messaging/messages/email') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); @@ -2989,7 +2989,7 @@ App::post('/v1/messaging/messages/email') 'region' => $project->getAttribute('region'), 'resourceType' => 'message', 'resourceId' => $message->getId(), - 'resourceInternalId' => $message->getInternalId(), + 'resourceInternalId' => $message->getSequence(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -3112,7 +3112,7 @@ App::post('/v1/messaging/messages/sms') 'region' => $project->getAttribute('region'), 'resourceType' => 'message', 'resourceId' => $message->getId(), - 'resourceInternalId' => $message->getInternalId(), + 'resourceInternalId' => $message->getSequence(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -3232,7 +3232,7 @@ App::post('/v1/messaging/messages/push') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } @@ -3330,7 +3330,7 @@ App::post('/v1/messaging/messages/push') 'region' => $project->getAttribute('region'), 'resourceType' => 'message', 'resourceId' => $message->getId(), - 'resourceInternalId' => $message->getInternalId(), + 'resourceInternalId' => $message->getSequence(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -3731,7 +3731,7 @@ App::patch('/v1/messaging/messages/email/:messageId') 'region' => $project->getAttribute('region'), 'resourceType' => 'message', 'resourceId' => $message->getId(), - 'resourceInternalId' => $message->getInternalId(), + 'resourceInternalId' => $message->getSequence(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -3796,7 +3796,7 @@ App::patch('/v1/messaging/messages/email/:messageId') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); @@ -3933,7 +3933,7 @@ App::patch('/v1/messaging/messages/sms/:messageId') 'region' => $project->getAttribute('region'), 'resourceType' => 'message', 'resourceId' => $message->getId(), - 'resourceInternalId' => $message->getInternalId(), + 'resourceInternalId' => $message->getSequence(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -4107,7 +4107,7 @@ App::patch('/v1/messaging/messages/push/:messageId') 'region' => $project->getAttribute('region'), 'resourceType' => 'message', 'resourceId' => $message->getId(), - 'resourceInternalId' => $message->getInternalId(), + 'resourceInternalId' => $message->getSequence(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -4210,7 +4210,7 @@ App::patch('/v1/messaging/messages/push/:messageId') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index 494ccfcaac..92fca88744 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -345,7 +345,7 @@ App::post('/v1/migrations/csv') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); } diff --git a/app/controllers/api/project.php b/app/controllers/api/project.php index 047179b888..d09470ff39 100644 --- a/app/controllers/api/project.php +++ b/app/controllers/api/project.php @@ -150,7 +150,7 @@ App::get('/v1/project/usage') $executionsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -166,7 +166,7 @@ App::get('/v1/project/usage') $executionsMbSecondsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -182,7 +182,7 @@ App::get('/v1/project/usage') $buildsMbSecondsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -198,7 +198,7 @@ App::get('/v1/project/usage') $bucketsBreakdown = array_map(function ($bucket) use ($dbForProject) { $id = $bucket->getId(); $name = $bucket->getAttribute('name'); - $metric = str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES_STORAGE); + $metric = str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES_STORAGE); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -214,7 +214,7 @@ App::get('/v1/project/usage') $databasesStorageBreakdown = array_map(function ($database) use ($dbForProject) { $id = $database->getId(); $name = $database->getAttribute('name'); - $metric = str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_STORAGE); + $metric = str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_STORAGE); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), @@ -231,13 +231,13 @@ App::get('/v1/project/usage') $functionsStorageBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $deploymentMetric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE); + $deploymentMetric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE); $deploymentValue = $dbForProject->findOne('stats', [ Query::equal('metric', [$deploymentMetric]), Query::equal('period', ['inf']) ]); - $buildMetric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE); + $buildMetric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE); $buildValue = $dbForProject->findOne('stats', [ Query::equal('metric', [$buildMetric]), Query::equal('period', ['inf']) @@ -255,7 +255,7 @@ App::get('/v1/project/usage') $executionsMbSecondsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -271,7 +271,7 @@ App::get('/v1/project/usage') $buildsMbSecondsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 5eda8e9a0e..51cbc097f5 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -182,7 +182,7 @@ App::post('/v1/projects') Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], 'name' => $name, - 'teamInternalId' => $team->getInternalId(), + 'teamInternalId' => $team->getSequence(), 'teamId' => $team->getId(), 'region' => $region, 'description' => $description, @@ -230,13 +230,13 @@ App::post('/v1/projects') if ($sharedTables) { $dbForProject ->setSharedTables(true) - ->setTenant($sharedTablesV1 ? $project->getInternalId() : null) + ->setTenant($sharedTablesV1 ? $project->getSequence() : null) ->setNamespace($dsn->getParam('namespace')); } else { $dbForProject ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getInternalId()); + ->setNamespace('_' . $project->getSequence()); } $create = true; @@ -504,12 +504,12 @@ App::patch('/v1/projects/:projectId/team') $project ->setAttribute('teamId', $teamId) - ->setAttribute('teamInternalId', $team->getInternalId()) + ->setAttribute('teamInternalId', $team->getSequence()) ->setAttribute('$permissions', $permissions); $project = $dbForPlatform->updateDocument('projects', $project->getId(), $project); $installations = $dbForPlatform->find('installations', [ - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), ]); foreach ($installations as $installation) { $installation->getAttribute('$permissions', $permissions); @@ -517,7 +517,7 @@ App::patch('/v1/projects/:projectId/team') } $repositories = $dbForPlatform->find('repositories', [ - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), ]); foreach ($repositories as $repository) { $repository->getAttribute('$permissions', $permissions); @@ -525,7 +525,7 @@ App::patch('/v1/projects/:projectId/team') } $vcsComments = $dbForPlatform->find('vcsComments', [ - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), ]); foreach ($vcsComments as $vcsComment) { $vcsComment->getAttribute('$permissions', $permissions); @@ -1229,7 +1229,7 @@ App::post('/v1/projects/:projectId/webhooks') Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'projectId' => $project->getId(), 'name' => $name, 'events' => $events, @@ -1279,7 +1279,7 @@ App::get('/v1/projects/:projectId/webhooks') } $webhooks = $dbForPlatform->find('webhooks', [ - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), Query::limit(5000), ]); @@ -1320,7 +1320,7 @@ App::get('/v1/projects/:projectId/webhooks/:webhookId') $webhook = $dbForPlatform->findOne('webhooks', [ Query::equal('$id', [$webhookId]), - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), ]); if ($webhook->isEmpty()) { @@ -1370,7 +1370,7 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId') $webhook = $dbForPlatform->findOne('webhooks', [ Query::equal('$id', [$webhookId]), - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), ]); if ($webhook->isEmpty()) { @@ -1427,7 +1427,7 @@ App::patch('/v1/projects/:projectId/webhooks/:webhookId/signature') $webhook = $dbForPlatform->findOne('webhooks', [ Query::equal('$id', [$webhookId]), - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), ]); if ($webhook->isEmpty()) { @@ -1474,7 +1474,7 @@ App::delete('/v1/projects/:projectId/webhooks/:webhookId') $webhook = $dbForPlatform->findOne('webhooks', [ Query::equal('$id', [$webhookId]), - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), ]); if ($webhook->isEmpty()) { @@ -1528,7 +1528,7 @@ App::post('/v1/projects/:projectId/keys') Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'projectId' => $project->getId(), 'name' => $name, 'scopes' => $scopes, @@ -1576,7 +1576,7 @@ App::get('/v1/projects/:projectId/keys') } $keys = $dbForPlatform->find('keys', [ - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), Query::limit(5000), ]); @@ -1617,7 +1617,7 @@ App::get('/v1/projects/:projectId/keys/:keyId') $key = $dbForPlatform->findOne('keys', [ Query::equal('$id', [$keyId]), - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), ]); if ($key->isEmpty()) { @@ -1661,7 +1661,7 @@ App::put('/v1/projects/:projectId/keys/:keyId') $key = $dbForPlatform->findOne('keys', [ Query::equal('$id', [$keyId]), - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), ]); if ($key->isEmpty()) { @@ -1712,7 +1712,7 @@ App::delete('/v1/projects/:projectId/keys/:keyId') $key = $dbForPlatform->findOne('keys', [ Query::equal('$id', [$keyId]), - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), ]); if ($key->isEmpty()) { @@ -1811,7 +1811,7 @@ App::post('/v1/projects/:projectId/platforms') Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'projectId' => $project->getId(), 'type' => $type, 'name' => $name, @@ -1858,7 +1858,7 @@ App::get('/v1/projects/:projectId/platforms') } $platforms = $dbForPlatform->find('platforms', [ - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), Query::limit(5000), ]); @@ -1899,7 +1899,7 @@ App::get('/v1/projects/:projectId/platforms/:platformId') $platform = $dbForPlatform->findOne('platforms', [ Query::equal('$id', [$platformId]), - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), ]); if ($platform->isEmpty()) { @@ -1943,7 +1943,7 @@ App::put('/v1/projects/:projectId/platforms/:platformId') $platform = $dbForPlatform->findOne('platforms', [ Query::equal('$id', [$platformId]), - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), ]); if ($platform->isEmpty()) { @@ -1997,7 +1997,7 @@ App::delete('/v1/projects/:projectId/platforms/:platformId') $platform = $dbForPlatform->findOne('platforms', [ Query::equal('$id', [$platformId]), - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), ]); if ($platform->isEmpty()) { diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index c1c8d8e4a0..417ea602ba 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -58,7 +58,7 @@ App::get('/v1/proxy/rules') $queries[] = Query::search('search', $search); } - $queries[] = Query::equal('projectInternalId', [$project->getInternalId()]); + $queries[] = Query::equal('projectInternalId', [$project->getSequence()]); /** * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries @@ -124,7 +124,7 @@ App::get('/v1/proxy/rules/:ruleId') ->action(function (string $ruleId, Response $response, Document $project, Database $dbForPlatform) { $rule = $dbForPlatform->getDocument('rules', $ruleId); - if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getInternalId()) { + if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) { throw new Exception(Exception::RULE_NOT_FOUND); } @@ -165,7 +165,7 @@ App::delete('/v1/proxy/rules/:ruleId') ->action(function (string $ruleId, Response $response, Document $project, Database $dbForPlatform, Delete $queueForDeletes, Event $queueForEvents) { $rule = $dbForPlatform->getDocument('rules', $ruleId); - if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getInternalId()) { + if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) { throw new Exception(Exception::RULE_NOT_FOUND); } @@ -210,7 +210,7 @@ App::patch('/v1/proxy/rules/:ruleId/verification') ->action(function (string $ruleId, Response $response, Certificate $queueForCertificates, Event $queueForEvents, Document $project, Database $dbForPlatform, Log $log) { $rule = $dbForPlatform->getDocument('rules', $ruleId); - if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getInternalId()) { + if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) { throw new Exception(Exception::RULE_NOT_FOUND); } diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index b3b8fb906a..a25241ec4b 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -145,7 +145,7 @@ App::post('/v1/storage/buckets') $bucket = $dbForProject->getDocument('buckets', $bucketId); - $dbForProject->createCollection('bucket_' . $bucket->getInternalId(), $attributes, $indexes, permissions: $permissions ?? [], documentSecurity: $fileSecurity); + $dbForProject->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes, permissions: $permissions ?? [], documentSecurity: $fileSecurity); } catch (DuplicateException) { throw new Exception(Exception::STORAGE_BUCKET_ALREADY_EXISTS); } @@ -326,7 +326,7 @@ App::put('/v1/storage/buckets/:bucketId') ->setAttribute('compression', $compression) ->setAttribute('antivirus', $antivirus)); - $dbForProject->updateCollection('bucket_' . $bucket->getInternalId(), $permissions, $fileSecurity); + $dbForProject->updateCollection('bucket_' . $bucket->getSequence(), $permissions, $fileSecurity); $queueForEvents ->setParam('bucketId', $bucket->getId()); @@ -558,7 +558,7 @@ App::post('/v1/storage/buckets/:bucketId/files') $path = $deviceForFiles->getPath($fileId . '.' . \pathinfo($fileName, PATHINFO_EXTENSION)); $path = str_ireplace($deviceForFiles->getRoot(), $deviceForFiles->getRoot() . DIRECTORY_SEPARATOR . $bucket->getId(), $path); // Add bucket id to path after root - $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); $metadata = ['content_type' => $deviceForLocal->getFileMimeType($fileTmpName)]; if (!$file->isEmpty()) { @@ -652,7 +652,7 @@ App::post('/v1/storage/buckets/:bucketId/files') '$id' => $fileId, '$permissions' => $permissions, 'bucketId' => $bucket->getId(), - 'bucketInternalId' => $bucket->getInternalId(), + 'bucketInternalId' => $bucket->getSequence(), 'name' => $fileName, 'path' => $path, 'signature' => $fileHash, @@ -671,7 +671,7 @@ App::post('/v1/storage/buckets/:bucketId/files') 'metadata' => $metadata, ]); - $file = $dbForProject->createDocument('bucket_' . $bucket->getInternalId(), $doc); + $file = $dbForProject->createDocument('bucket_' . $bucket->getSequence(), $doc); } else { $file = $file ->setAttribute('$permissions', $permissions) @@ -696,7 +696,7 @@ App::post('/v1/storage/buckets/:bucketId/files') if (!$validator->isValid($bucket->getCreate())) { throw new Exception(Exception::USER_UNAUTHORIZED); } - $file = Authorization::skip(fn () => $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file)); + $file = Authorization::skip(fn () => $dbForProject->updateDocument('bucket_' . $bucket->getSequence(), $fileId, $file)); } } else { if ($file->isEmpty()) { @@ -704,7 +704,7 @@ App::post('/v1/storage/buckets/:bucketId/files') '$id' => ID::custom($fileId), '$permissions' => $permissions, 'bucketId' => $bucket->getId(), - 'bucketInternalId' => $bucket->getInternalId(), + 'bucketInternalId' => $bucket->getSequence(), 'name' => $fileName, 'path' => $path, 'signature' => '', @@ -720,7 +720,7 @@ App::post('/v1/storage/buckets/:bucketId/files') ]); try { - $file = $dbForProject->createDocument('bucket_' . $bucket->getInternalId(), $doc); + $file = $dbForProject->createDocument('bucket_' . $bucket->getSequence(), $doc); } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } @@ -741,7 +741,7 @@ App::post('/v1/storage/buckets/:bucketId/files') } try { - $file = Authorization::skip(fn () => $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file)); + $file = Authorization::skip(fn () => $dbForProject->updateDocument('bucket_' . $bucket->getSequence(), $fileId, $file)); } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } @@ -826,9 +826,9 @@ App::get('/v1/storage/buckets/:bucketId/files') $fileId = $cursor->getValue(); if ($fileSecurity && !$valid) { - $cursorDocument = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $cursorDocument = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); } else { - $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); + $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); } if ($cursorDocument->isEmpty()) { @@ -842,11 +842,11 @@ App::get('/v1/storage/buckets/:bucketId/files') try { if ($fileSecurity && !$valid) { - $files = $dbForProject->find('bucket_' . $bucket->getInternalId(), $queries); - $total = $dbForProject->count('bucket_' . $bucket->getInternalId(), $filterQueries, APP_LIMIT_COUNT); + $files = $dbForProject->find('bucket_' . $bucket->getSequence(), $queries); + $total = $dbForProject->count('bucket_' . $bucket->getSequence(), $filterQueries, APP_LIMIT_COUNT); } else { - $files = Authorization::skip(fn () => $dbForProject->find('bucket_' . $bucket->getInternalId(), $queries)); - $total = Authorization::skip(fn () => $dbForProject->count('bucket_' . $bucket->getInternalId(), $filterQueries, APP_LIMIT_COUNT)); + $files = Authorization::skip(fn () => $dbForProject->find('bucket_' . $bucket->getSequence(), $queries)); + $total = Authorization::skip(fn () => $dbForProject->count('bucket_' . $bucket->getSequence(), $filterQueries, APP_LIMIT_COUNT)); } } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); @@ -902,9 +902,9 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId') } if ($fileSecurity && !$valid) { - $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); } else { - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); } if ($file->isEmpty()) { @@ -973,7 +973,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getInternalId(); + $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getSequence(); $fileSecurity = $bucket->getAttribute('fileSecurity', false); $validator = new Authorization(Database::PERMISSION_READ); $valid = $validator->isValid($bucket->getRead()); @@ -982,12 +982,12 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview') } if ($fileSecurity && !$valid && !$isToken) { - $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); } else { - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); } - if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getInternalId()) { + if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getSequence()) { throw new Exception(Exception::USER_UNAUTHORIZED); } @@ -1150,7 +1150,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/download') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getInternalId(); + $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getSequence(); $fileSecurity = $bucket->getAttribute('fileSecurity', false); $validator = new Authorization(Database::PERMISSION_READ); $valid = $validator->isValid($bucket->getRead()); @@ -1159,12 +1159,12 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/download') } if ($fileSecurity && !$valid) { - $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); } else { - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); } - if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getInternalId()) { + if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getSequence()) { throw new Exception(Exception::USER_UNAUTHORIZED); } @@ -1309,7 +1309,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/view') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getInternalId(); + $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getSequence(); $fileSecurity = $bucket->getAttribute('fileSecurity', false); $validator = new Authorization(Database::PERMISSION_READ); $valid = $validator->isValid($bucket->getRead()); @@ -1318,12 +1318,12 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/view') } if ($fileSecurity && !$valid) { - $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); } else { - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); } - if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getInternalId()) { + if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getSequence()) { throw new Exception(Exception::USER_UNAUTHORIZED); } @@ -1478,7 +1478,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/push') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); @@ -1643,7 +1643,7 @@ App::put('/v1/storage/buckets/:bucketId/files/:fileId') } // Read permission should not be required for update - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); @@ -1689,9 +1689,9 @@ App::put('/v1/storage/buckets/:bucketId/files/:fileId') try { if ($fileSecurity && !$valid) { - $file = $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file); + $file = $dbForProject->updateDocument('bucket_' . $bucket->getSequence(), $fileId, $file); } else { - $file = Authorization::skip(fn () => $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file)); + $file = Authorization::skip(fn () => $dbForProject->updateDocument('bucket_' . $bucket->getSequence(), $fileId, $file)); } } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); @@ -1757,7 +1757,7 @@ App::delete('/v1/storage/buckets/:bucketId/files/:fileId') } // Read permission should not be required for delete - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); @@ -1787,9 +1787,9 @@ App::delete('/v1/storage/buckets/:bucketId/files/:fileId') try { if ($fileSecurity && !$valid) { - $deleted = $dbForProject->deleteDocument('bucket_' . $bucket->getInternalId(), $fileId); + $deleted = $dbForProject->deleteDocument('bucket_' . $bucket->getSequence(), $fileId); } else { - $deleted = Authorization::skip(fn () => $dbForProject->deleteDocument('bucket_' . $bucket->getInternalId(), $fileId)); + $deleted = Authorization::skip(fn () => $dbForProject->deleteDocument('bucket_' . $bucket->getSequence(), $fileId)); } } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); @@ -1937,14 +1937,14 @@ App::get('/v1/storage/:bucketId/usage') $stats = $usage = []; $days = $periods[$range]; $metrics = [ - str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES), - str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES_STORAGE), - str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES_IMAGES_TRANSFORMED), + str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES), + str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES_STORAGE), + str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES_IMAGES_TRANSFORMED), ]; Authorization::skip(function () use ($dbForProject, $dbForLogs, $bucket, $days, $metrics, &$stats) { foreach ($metrics as $metric) { - $db = ($metric === str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES_IMAGES_TRANSFORMED)) + $db = ($metric === str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES_IMAGES_TRANSFORMED)) ? $dbForLogs : $dbForProject; diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 49d9005c54..c83cad7eb1 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -123,9 +123,9 @@ App::post('/v1/teams') Permission::delete(Role::team($team->getId(), 'owner')), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'teamId' => $team->getId(), - 'teamInternalId' => $team->getInternalId(), + 'teamInternalId' => $team->getSequence(), 'roles' => $roles, 'invited' => DateTime::now(), 'joined' => DateTime::now(), @@ -595,8 +595,8 @@ App::post('/v1/teams/:teamId/memberships') } $membership = $dbForProject->findOne('memberships', [ - Query::equal('userInternalId', [$invitee->getInternalId()]), - Query::equal('teamInternalId', [$team->getInternalId()]), + Query::equal('userInternalId', [$invitee->getSequence()]), + Query::equal('teamInternalId', [$team->getSequence()]), ]); $secret = Auth::tokenGenerator(); @@ -612,9 +612,9 @@ App::post('/v1/teams/:teamId/memberships') Permission::delete(Role::team($team->getId(), 'owner')), ], 'userId' => $invitee->getId(), - 'userInternalId' => $invitee->getInternalId(), + 'userInternalId' => $invitee->getSequence(), 'teamId' => $team->getId(), - 'teamInternalId' => $team->getInternalId(), + 'teamInternalId' => $team->getSequence(), 'roles' => $roles, 'invited' => DateTime::now(), 'joined' => ($isPrivilegedUser || $isAppUser) ? DateTime::now() : null, @@ -842,7 +842,7 @@ App::get('/v1/teams/:teamId/memberships') } // Set internal queries - $queries[] = Query::equal('teamInternalId', [$team->getInternalId()]); + $queries[] = Query::equal('teamInternalId', [$team->getSequence()]); /** * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries @@ -1092,7 +1092,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId') collection: 'memberships', queries: [ Query::contains('roles', ['owner']), - Query::equal('teamInternalId', [$team->getInternalId()]) + Query::equal('teamInternalId', [$team->getSequence()]) ], max: 2 ); @@ -1180,7 +1180,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') throw new Exception(Exception::TEAM_NOT_FOUND); } - if ($membership->getAttribute('teamInternalId') !== $team->getInternalId()) { + if ($membership->getAttribute('teamInternalId') !== $team->getSequence()) { throw new Exception(Exception::TEAM_MEMBERSHIP_MISMATCH); } @@ -1197,7 +1197,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') $user->setAttributes($dbForProject->getDocument('users', $userId)->getArrayCopy()); // Get user } - if ($membership->getAttribute('userInternalId') !== $user->getInternalId()) { + if ($membership->getAttribute('userInternalId') !== $user->getSequence()) { throw new Exception(Exception::TEAM_INVITE_MISMATCH, 'Invite does not belong to current user (' . $user->getAttribute('email') . ')'); } @@ -1229,7 +1229,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => $user->getAttribute('email'), 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak @@ -1338,7 +1338,7 @@ App::delete('/v1/teams/:teamId/memberships/:membershipId') throw new Exception(Exception::TEAM_NOT_FOUND); } - if ($membership->getAttribute('teamInternalId') !== $team->getInternalId()) { + if ($membership->getAttribute('teamInternalId') !== $team->getSequence()) { throw new Exception(Exception::TEAM_MEMBERSHIP_MISMATCH); } diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index bc9de0fd42..4b6e5abe6b 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -140,7 +140,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'providerType' => 'email', 'identifier' => $email, ])); @@ -164,7 +164,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'providerType' => 'sms', 'identifier' => $phone, ])); @@ -564,10 +564,10 @@ App::post('/v1/users/:userId/targets') Permission::delete(Role::user($user->getId())), ], 'providerId' => empty($provider->getId()) ? null : $provider->getId(), - 'providerInternalId' => $provider->isEmpty() ? null : $provider->getInternalId(), + 'providerInternalId' => $provider->isEmpty() ? null : $provider->getSequence(), 'providerType' => $providerType, 'userId' => $userId, - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'identifier' => $identifier, 'name' => ($name !== '') ? $name : null, ])); @@ -846,7 +846,7 @@ App::get('/v1/users/:userId/memberships') } // Set internal queries - $queries[] = Query::equal('userInternalId', [$user->getInternalId()]); + $queries[] = Query::equal('userInternalId', [$user->getSequence()]); $memberships = array_map(function ($membership) use ($dbForProject, $user) { $team = $dbForProject->getDocument('teams', $membership->getAttribute('teamId')); @@ -910,7 +910,7 @@ App::get('/v1/users/:userId/logs') $audit = new Audit($dbForProject); - $logs = $audit->getLogsByUser($user->getInternalId(), $queries); + $logs = $audit->getLogsByUser($user->getSequence(), $queries); $output = []; @@ -957,7 +957,7 @@ App::get('/v1/users/:userId/logs') } $response->dynamic(new Document([ - 'total' => $audit->countLogsByUser($user->getInternalId(), $queries), + 'total' => $audit->countLogsByUser($user->getSequence(), $queries), 'logs' => $output, ]), Response::MODEL_LOG_LIST); }); @@ -1396,7 +1396,7 @@ App::patch('/v1/users/:userId/email') // Makes sure this email is not already used in another identity $identityWithMatchingEmail = $dbForProject->findOne('identities', [ Query::equal('providerEmail', [$email]), - Query::notEqual('userInternalId', $user->getInternalId()), + Query::notEqual('userInternalId', $user->getSequence()), ]); if (!$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); @@ -1440,7 +1440,7 @@ App::patch('/v1/users/:userId/email') Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'providerType' => 'email', 'identifier' => $email, ])); @@ -1529,7 +1529,7 @@ App::patch('/v1/users/:userId/phone') Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'providerType' => 'sms', 'identifier' => $number, ])); @@ -1711,7 +1711,7 @@ App::patch('/v1/users/:userId/targets/:targetId') $target ->setAttribute('providerId', $provider->getId()) - ->setAttribute('providerInternalId', $provider->getInternalId()); + ->setAttribute('providerInternalId', $provider->getSequence()); } if ($name) { @@ -2051,7 +2051,7 @@ App::post('/v1/users/:userId/sessions') [ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'provider' => Auth::SESSION_PROVIDER_SERVER, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak 'userAgent' => $request->getUserAgent('UNKNOWN'), @@ -2131,7 +2131,7 @@ App::post('/v1/users/:userId/tokens') $token = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + 'userInternalId' => $user->getSequence(), 'type' => Auth::TOKEN_TYPE_GENERIC, 'secret' => Auth::hash($secret), 'expire' => $expire, @@ -2293,8 +2293,8 @@ App::delete('/v1/users/:userId') $clone = clone $user; $dbForProject->deleteDocument('users', $userId); - DeleteIdentities::delete($dbForProject, Query::equal('userInternalId', [$user->getInternalId()])); - DeleteTargets::delete($dbForProject, Query::equal('userInternalId', [$user->getInternalId()])); + DeleteIdentities::delete($dbForProject, Query::equal('userInternalId', [$user->getSequence()])); + DeleteTargets::delete($dbForProject, Query::equal('userInternalId', [$user->getSequence()])); $queueForDeletes ->setType(DELETE_TYPE_DOCUMENT) diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 571c7ddca7..746f61c59c 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -78,11 +78,11 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId $resourceCollection = $resourceType === "function" ? 'functions' : 'sites'; $resourceId = $repository->getAttribute('resourceId'); $resource = Authorization::skip(fn () => $dbForProject->getDocument($resourceCollection, $resourceId)); - $resourceInternalId = $resource->getInternalId(); + $resourceInternalId = $resource->getSequence(); $deploymentId = ID::unique(); $repositoryId = $repository->getId(); - $repositoryInternalId = $repository->getInternalId(); + $repositoryInternalId = $repository->getSequence(); $providerRepositoryId = $repository->getAttribute('providerRepositoryId'); $installationId = $repository->getAttribute('installationId'); $installationInternalId = $repository->getAttribute('installationInternalId'); @@ -157,7 +157,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId ], 'installationInternalId' => $installationInternalId, 'installationId' => $installationId, - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'projectId' => $project->getId(), 'providerRepositoryId' => $providerRepositoryId, 'providerBranch' => $providerBranch, @@ -257,7 +257,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId $resource = $resource ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); Authorization::skip(fn () => $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource)); @@ -273,12 +273,12 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->getId(), - 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->getSequence(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $resourceId, 'deploymentResourceInternalId' => $resourceInternalId, @@ -300,12 +300,12 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->getId(), - 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->getSequence(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $resourceId, 'deploymentResourceInternalId' => $resourceInternalId, @@ -331,12 +331,12 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->getId(), - 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->getSequence(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $resourceId, 'deploymentResourceInternalId' => $resourceInternalId, @@ -503,7 +503,7 @@ App::get('/v1/vcs/github/callback') $github->initializeVariables($providerInstallationId, $privateKey, $githubAppId); $owner = $github->getOwnerName($providerInstallationId) ?? ''; - $projectInternalId = $project->getInternalId(); + $projectInternalId = $project->getSequence(); $installation = $dbForPlatform->findOne('installations', [ Query::equal('providerInstallationId', [$providerInstallationId]), @@ -999,7 +999,7 @@ App::post('/v1/vcs/github/installations/:installationId/providerRepositories') if (empty($accessToken) || empty($refreshToken) || empty($accessTokenExpiry)) { $identity = $dbForPlatform->findOne('identities', [ Query::equal('provider', ['github']), - Query::equal('userInternalId', [$user->getInternalId()]), + Query::equal('userInternalId', [$user->getSequence()]), ]); if ($identity->isEmpty()) { throw new Exception(Exception::USER_IDENTITY_NOT_FOUND); @@ -1246,7 +1246,7 @@ App::post('/v1/vcs/github/events') foreach ($installations as $installation) { $repositories = Authorization::skip(fn () => $dbForPlatform->find('repositories', [ - Query::equal('installationInternalId', [$installation->getInternalId()]), + Query::equal('installationInternalId', [$installation->getSequence()]), Query::limit(1000) ])); @@ -1349,7 +1349,7 @@ App::get('/v1/vcs/installations') throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); } - $queries[] = Query::equal('projectInternalId', [$project->getInternalId()]); + $queries[] = Query::equal('projectInternalId', [$project->getSequence()]); if (!empty($search)) { $queries[] = Query::search('search', $search); @@ -1422,7 +1422,7 @@ App::get('/v1/vcs/installations/:installationId') throw new Exception(Exception::INSTALLATION_NOT_FOUND); } - if ($installation->getAttribute('projectInternalId') !== $project->getInternalId()) { + if ($installation->getAttribute('projectInternalId') !== $project->getSequence()) { throw new Exception(Exception::INSTALLATION_NOT_FOUND); } @@ -1505,7 +1505,7 @@ App::patch('/v1/vcs/github/installations/:installationId/repositories/:repositor } $repository = Authorization::skip(fn () => $dbForPlatform->getDocument('repositories', $repositoryId, [ - Query::equal('projectInternalId', [$project->getInternalId()]) + Query::equal('projectInternalId', [$project->getSequence()]) ])); if ($repository->isEmpty()) { diff --git a/app/controllers/general.php b/app/controllers/general.php index bff701792e..90a108c7c6 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -391,9 +391,9 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $execution = new Document([ '$id' => $executionId, '$permissions' => [], - 'resourceInternalId' => $resource->getInternalId(), + 'resourceInternalId' => $resource->getSequence(), 'resourceId' => $resource->getId(), - 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->getSequence(), 'deploymentId' => $deployment->getId(), 'responseStatusCode' => 0, 'responseHeaders' => [], @@ -692,11 +692,11 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw } $metricTypeExecutions = str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS); - $metricTypeIdExecutions = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS); + $metricTypeIdExecutions = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS); $metricTypeExecutionsCompute = str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE); - $metricTypeIdExecutionsCompute = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE); + $metricTypeIdExecutionsCompute = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE); $metricTypeExecutionsMbSeconds = str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS); - $metricTypeIdExecutionsMBSeconds = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); + $metricTypeIdExecutionsMBSeconds = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); if ($deployment->getAttribute('resourceType') === 'sites') { $queueForStatsUsage ->disableMetric(METRIC_NETWORK_REQUESTS) @@ -719,9 +719,9 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw ->addMetric(METRIC_SITES_REQUESTS, 1) ->addMetric(METRIC_SITES_INBOUND, $request->getSize() + $fileSize) ->addMetric(METRIC_SITES_OUTBOUND, $response->getSize()) - ->addMetric(str_replace('{siteInternalId}', $resource->getInternalId(), METRIC_SITES_ID_REQUESTS), 1) - ->addMetric(str_replace('{siteInternalId}', $resource->getInternalId(), METRIC_SITES_ID_INBOUND), $request->getSize() + $fileSize) - ->addMetric(str_replace('{siteInternalId}', $resource->getInternalId(), METRIC_SITES_ID_OUTBOUND), $response->getSize()) + ->addMetric(str_replace('{siteInternalId}', $resource->getSequence(), METRIC_SITES_ID_REQUESTS), 1) + ->addMetric(str_replace('{siteInternalId}', $resource->getSequence(), METRIC_SITES_ID_INBOUND), $request->getSize() + $fileSize) + ->addMetric(str_replace('{siteInternalId}', $resource->getSequence(), METRIC_SITES_ID_OUTBOUND), $response->getSize()) ; } @@ -914,7 +914,7 @@ App::init() 'type' => 'api', 'status' => 'verifying', 'projectId' => $console->getId(), - 'projectInternalId' => $console->getInternalId(), + 'projectInternalId' => $console->getSequence(), 'search' => implode(' ', [$ruleId, $domain->get()]), 'owner' => $owner, 'region' => $console->getAttribute('region') @@ -964,7 +964,7 @@ App::init() )[0] ?? new Document(); } - if (!$rule->isEmpty() && $rule->getAttribute('projectInternalId') === $project->getInternalId()) { + if (!$rule->isEmpty() && $rule->getAttribute('projectInternalId') === $project->getSequence()) { $refDomainOrigin = $origin; } } diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 16d8e03841..fd7b9ab495 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -185,7 +185,7 @@ App::post('/v1/mock/api-key-unprefixed') Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'projectId' => $project->getId(), 'name' => 'Outdated key', 'scopes' => $scopes, @@ -235,7 +235,7 @@ App::get('/v1/mock/github/callback') $github->initializeVariables($providerInstallationId, $privateKey, $githubAppId); $owner = $github->getOwnerName($providerInstallationId) ?? ''; - $projectInternalId = $project->getInternalId(); + $projectInternalId = $project->getSequence(); $teamId = $project->getAttribute('teamId', ''); diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 937f245099..f99ebbce07 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -574,7 +574,7 @@ App::init() $bucketId = $parts[1] ?? null; $bucket = Authorization::skip(fn () => $dbForProject->getDocument('buckets', $bucketId)); - $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getInternalId(); + $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getSequence(); $isAPIKey = Auth::isAppUser(Authorization::getRoles()); $isPrivilegedUser = Auth::isPrivilegedUser(Authorization::getRoles()); @@ -593,12 +593,12 @@ App::init() $fileId = $parts[1] ?? null; if ($fileSecurity && !$valid && !$isToken) { - $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); } else { - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); } - if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getInternalId()) { + if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getSequence()) { throw new Exception(Exception::USER_UNAUTHORIZED); } diff --git a/app/http.php b/app/http.php index 6064dfdd4c..30f4013821 100644 --- a/app/http.php +++ b/app/http.php @@ -309,7 +309,7 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg 'orders' => $index['orders'], ]), $files['indexes']); - $dbForPlatform->createCollection('bucket_' . $bucket->getInternalId(), $attributes, $indexes); + $dbForPlatform->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes); } if (Authorization::skip(fn () => $dbForPlatform->getDocument('buckets', 'screenshots')->isEmpty())) { @@ -357,7 +357,7 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg 'orders' => $index['orders'], ]), $files['indexes']); - Authorization::skip(fn () => $dbForPlatform->createCollection('bucket_' . $bucket->getInternalId(), $attributes, $indexes)); + Authorization::skip(fn () => $dbForPlatform->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes)); } }); diff --git a/app/init/database/filters.php b/app/init/database/filters.php index f110fe1554..7f2282747e 100644 --- a/app/init/database/filters.php +++ b/app/init/database/filters.php @@ -71,7 +71,7 @@ Database::addFilter( }, function (mixed $value, Document $document, Database $database) { $attributes = $database->find('attributes', [ - Query::equal('collectionInternalId', [$document->getInternalId()]), + Query::equal('collectionInternalId', [$document->getSequence()]), Query::equal('databaseInternalId', [$document->getAttribute('databaseInternalId')]), Query::limit($database->getLimitForAttributes()), ]); @@ -98,7 +98,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('indexes', [ - Query::equal('collectionInternalId', [$document->getInternalId()]), + Query::equal('collectionInternalId', [$document->getSequence()]), Query::equal('databaseInternalId', [$document->getAttribute('databaseInternalId')]), Query::limit($database->getLimitForIndexes()), ]); @@ -113,7 +113,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('platforms', [ - Query::equal('projectInternalId', [$document->getInternalId()]), + Query::equal('projectInternalId', [$document->getSequence()]), Query::limit(APP_LIMIT_SUBQUERY), ]); } @@ -127,7 +127,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('keys', [ - Query::equal('projectInternalId', [$document->getInternalId()]), + Query::equal('projectInternalId', [$document->getSequence()]), Query::limit(APP_LIMIT_SUBQUERY), ]); } @@ -141,7 +141,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('devKeys', [ - Query::equal('projectInternalId', [$document->getInternalId()]), + Query::equal('projectInternalId', [$document->getSequence()]), Query::limit(APP_LIMIT_SUBQUERY), ]); } @@ -155,7 +155,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('webhooks', [ - Query::equal('projectInternalId', [$document->getInternalId()]), + Query::equal('projectInternalId', [$document->getSequence()]), Query::limit(APP_LIMIT_SUBQUERY), ]); } @@ -168,7 +168,7 @@ Database::addFilter( }, function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn () => $database->find('sessions', [ - Query::equal('userInternalId', [$document->getInternalId()]), + Query::equal('userInternalId', [$document->getSequence()]), Query::limit(APP_LIMIT_SUBQUERY), ])); } @@ -182,7 +182,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn () => $database ->find('tokens', [ - Query::equal('userInternalId', [$document->getInternalId()]), + Query::equal('userInternalId', [$document->getSequence()]), Query::limit(APP_LIMIT_SUBQUERY), ])); } @@ -196,7 +196,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn () => $database ->find('challenges', [ - Query::equal('userInternalId', [$document->getInternalId()]), + Query::equal('userInternalId', [$document->getSequence()]), Query::limit(APP_LIMIT_SUBQUERY), ])); } @@ -210,7 +210,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn () => $database ->find('authenticators', [ - Query::equal('userInternalId', [$document->getInternalId()]), + Query::equal('userInternalId', [$document->getSequence()]), Query::limit(APP_LIMIT_SUBQUERY), ])); } @@ -224,7 +224,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn () => $database ->find('memberships', [ - Query::equal('userInternalId', [$document->getInternalId()]), + Query::equal('userInternalId', [$document->getSequence()]), Query::limit(APP_LIMIT_SUBQUERY), ])); } @@ -238,7 +238,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('variables', [ - Query::equal('resourceInternalId', [$document->getInternalId()]), + Query::equal('resourceInternalId', [$document->getSequence()]), Query::equal('resourceType', ['function', 'site']), Query::limit(APP_LIMIT_SUBQUERY), ]); @@ -316,7 +316,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn () => $database ->find('targets', [ - Query::equal('userInternalId', [$document->getInternalId()]), + Query::equal('userInternalId', [$document->getSequence()]), Query::limit(APP_LIMIT_SUBQUERY) ])); } @@ -329,15 +329,15 @@ Database::addFilter( }, function (mixed $value, Document $document, Database $database) { $targetIds = Authorization::skip(fn () => \array_map( - fn ($document) => $document->getAttribute('targetInternalId'), + fn ($document) => $document->getAttribute('targetSequence'), $database->find('subscribers', [ - Query::equal('topicInternalId', [$document->getInternalId()]), + Query::equal('topicInternalId', [$document->getSequence()]), Query::limit(APP_LIMIT_SUBSCRIBERS_SUBQUERY) ]) )); if (\count($targetIds) > 0) { return $database->skipValidation(fn () => $database->find('targets', [ - Query::equal('$internalId', $targetIds) + Query::equal('$sequence', $targetIds) ])); } return []; diff --git a/app/init/resources.php b/app/init/resources.php index c75df2a362..7c3df681b1 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -347,13 +347,13 @@ App::setResource('dbForProject', function (Group $pools, Database $dbForPlatform if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getInternalId()) + ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getInternalId()); + ->setNamespace('_' . $project->getSequence()); } return $database; @@ -400,13 +400,13 @@ App::setResource('getProjectDB', function (Group $pools, Database $dbForPlatform if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getInternalId()) + ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getInternalId()); + ->setNamespace('_' . $project->getSequence()); } }); @@ -430,7 +430,7 @@ App::setResource('getLogsDB', function (Group $pools, Cache $cache) { return function (?Document $project = null) use ($pools, $cache, &$database) { if ($database !== null && $project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getInternalId()); + $database->setTenant($project->getSequence()); return $database; } @@ -445,7 +445,7 @@ App::setResource('getLogsDB', function (Group $pools, Cache $cache) { // set tenant if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getInternalId()); + $database->setTenant($project->getSequence()); } return $database; @@ -836,7 +836,7 @@ App::setResource('team', function (Document $project, Database $dbForPlatform, A $team = Authorization::skip(function () use ($dbForPlatform, $teamInternalId) { return $dbForPlatform->findOne('teams', [ - Query::equal('$internalId', [$teamInternalId]), + Query::equal('$sequence', [$teamInternalId]), ]); }); @@ -915,10 +915,10 @@ App::setResource('resourceToken', function ($project, $dbForProject, $request) { return match ($token->getAttribute('resourceType')) { TOKENS_RESOURCE_TYPE_FILES => (function () use ($token, $dbForProject) { - $internalIds = explode(':', $token->getAttribute('resourceInternalId')); + $sequences = explode(':', $token->getAttribute('resourceInternalId')); $ids = explode(':', $token->getAttribute('resourceId')); - if (count($internalIds) !== 2 || count($ids) !== 2) { + if (count($sequences) !== 2 || count($ids) !== 2) { return new Document([]); } @@ -931,8 +931,8 @@ App::setResource('resourceToken', function ($project, $dbForProject, $request) { return new Document([ 'bucketId' => $ids[0], 'fileId' => $ids[1], - 'bucketInternalId' => $internalIds[0], - 'fileInternalId' => $internalIds[1], + 'bucketInternalId' => $sequences[0], + 'fileInternalId' => $sequences[1], ]); })(), diff --git a/app/realtime.php b/app/realtime.php index 7e6fc0e311..96484c8a35 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -79,8 +79,8 @@ if (!function_exists('getProjectDB')) { static $databases = []; - if (isset($databases[$project->getInternalId()])) { - return $databases[$project->getInternalId()]; + if (isset($databases[$project->getSequence()])) { + return $databases[$project->getSequence()]; } /** @var Group $pools */ @@ -105,20 +105,20 @@ if (!function_exists('getProjectDB')) { if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getInternalId()) + ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getInternalId()); + ->setNamespace('_' . $project->getSequence()); } $database ->setMetadata('host', \gethostname()) ->setMetadata('project', $project->getId()); - return $databases[$project->getInternalId()] = $database; + return $databases[$project->getSequence()] = $database; } } diff --git a/app/worker.php b/app/worker.php index 597e8a9943..2b6726c855 100644 --- a/app/worker.php +++ b/app/worker.php @@ -90,13 +90,13 @@ Server::setResource('dbForProject', function (Cache $cache, Registry $register, if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getInternalId()) + ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getInternalId()); + ->setNamespace('_' . $project->getSequence()); } $database->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_WORKER); @@ -127,13 +127,13 @@ Server::setResource('getProjectDB', function (Group $pools, Database $dbForPlatf if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getInternalId()) + ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getInternalId()); + ->setNamespace('_' . $project->getSequence()); } return $database; @@ -149,13 +149,13 @@ Server::setResource('getProjectDB', function (Group $pools, Database $dbForPlatf if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getInternalId()) + ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getInternalId()); + ->setNamespace('_' . $project->getSequence()); } $database->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_WORKER); @@ -168,7 +168,7 @@ Server::setResource('getLogsDB', function (Group $pools, Cache $cache) { $database = null; return function (?Document $project = null) use ($pools, $cache, $database) { if ($database !== null && $project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getInternalId()); + $database->setTenant($project->getSequence()); return $database; } @@ -183,7 +183,7 @@ Server::setResource('getLogsDB', function (Group $pools, Cache $cache) { // set tenant if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getInternalId()); + $database->setTenant($project->getSequence()); } return $database; diff --git a/src/Appwrite/Deletes/Targets.php b/src/Appwrite/Deletes/Targets.php index 95e744ddf1..68a9d675b6 100644 --- a/src/Appwrite/Deletes/Targets.php +++ b/src/Appwrite/Deletes/Targets.php @@ -27,7 +27,7 @@ class Targets $database->deleteDocuments( 'subscribers', [ - Query::equal('targetInternalId', [$target->getInternalId()]), + Query::equal('targetSequence', [$target->getSequence()]), Query::orderAsc(), ], Database::DELETE_BATCH_SIZE, @@ -35,7 +35,7 @@ class Targets $topicId = $subscriber->getAttribute('topicId'); $topicInternalId = $subscriber->getAttribute('topicInternalId'); $topic = $database->getDocument('topics', $topicId); - if (!$topic->isEmpty() && $topic->getInternalId() === $topicInternalId) { + if (!$topic->isEmpty() && $topic->getSequence() === $topicInternalId) { $totalAttribute = match ($target->getAttribute('providerType')) { MESSAGE_TYPE_EMAIL => 'emailTotal', MESSAGE_TYPE_SMS => 'smsTotal', diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index 2c735ef2d4..934647f7c3 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -320,7 +320,7 @@ class Event if ($this->project) { $trimmed['project'] = new Document([ '$id' => $this->project->getId(), - '$internalId' => $this->project->getInternalId(), + '$sequence' => $this->project->getSequence(), 'database' => $this->project->getAttribute('database') ]); } diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 81ea1ef263..73d16394c0 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -155,7 +155,7 @@ abstract class Migration */ public function forEachDocument(callable $callback): void { - $projectInternalId = $this->project->getInternalId(); + $projectInternalId = $this->project->getSequence(); $collections = match ($projectInternalId) { 'console' => $this->collections['console'], @@ -208,7 +208,7 @@ abstract class Migration { $name ??= $id; - $collectionType = match ($this->project->getInternalId()) { + $collectionType = match ($this->project->getSequence()) { 'console' => 'console', default => 'projects', }; @@ -259,7 +259,7 @@ abstract class Migration ): void { $from ??= $collectionId; - $collectionType = match ($this->project->getInternalId()) { + $collectionType = match ($this->project->getSequence()) { 'console' => 'console', default => 'projects', }; @@ -324,7 +324,7 @@ abstract class Migration ): void { $from ??= $collectionId; - $collectionType = match ($this->project->getInternalId()) { + $collectionType = match ($this->project->getSequence()) { 'console' => 'console', default => 'projects', }; @@ -382,7 +382,7 @@ abstract class Migration { $from ??= $collectionId; - $collectionType = match ($this->project->getInternalId()) { + $collectionType = match ($this->project->getSequence()) { 'console' => 'console', default => 'projects', }; @@ -428,7 +428,7 @@ abstract class Migration */ protected function changeAttributeInternalType(string $collection, string $attribute, string $type): void { - $stmt = $this->pdo->prepare("ALTER TABLE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$collection}` MODIFY `$attribute` $type;"); + $stmt = $this->pdo->prepare("ALTER TABLE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$collection}` MODIFY `$attribute` $type;"); try { $stmt->execute(); diff --git a/src/Appwrite/Migration/Version/V15.php b/src/Appwrite/Migration/Version/V15.php index 8eab916f19..15331e9a37 100644 --- a/src/Appwrite/Migration/Version/V15.php +++ b/src/Appwrite/Migration/Version/V15.php @@ -95,7 +95,7 @@ class V15 extends Migration $this->migrateStatsMetric('storage.files.delete', 'files.$all.requests.delete'); foreach ($this->documentsIterator('buckets') as $bucket) { - $bucketTable = "bucket_{$bucket->getInternalId()}"; + $bucketTable = "bucket_{$bucket->getSequence()}"; $this->createPermissionsColumn($bucketTable); $this->migrateDateTimeAttribute($bucketTable, '_createdAt'); @@ -178,7 +178,7 @@ class V15 extends Migration * Migrate every Database. */ foreach ($this->documentsIterator('databases') as $database) { - $databaseTable = "database_{$database->getInternalId()}"; + $databaseTable = "database_{$database->getSequence()}"; $this->createPermissionsColumn($databaseTable); $this->migrateDateTimeAttribute($databaseTable, '_createdAt'); $this->migrateDateTimeAttribute($databaseTable, '_updatedAt'); @@ -216,7 +216,7 @@ class V15 extends Migration */ Console::info("Migrating Collections of {$database->getId()} ({$database->getAttribute('name')})"); foreach ($this->documentsIterator($databaseTable) as $collection) { - $collectionTable = "{$databaseTable}_collection_{$collection->getInternalId()}"; + $collectionTable = "{$databaseTable}_collection_{$collection->getSequence()}"; $this->createPermissionsColumn($collectionTable); $this->migrateDateTimeAttribute($collectionTable, '_createdAt'); $this->migrateDateTimeAttribute($collectionTable, '_updatedAt'); @@ -277,7 +277,7 @@ class V15 extends Migration $this->removeWritePermissions($databaseTable); try { - $this->dbForProject->deleteAttribute("database_{$database->getInternalId()}", 'permission'); + $this->dbForProject->deleteAttribute("database_{$database->getSequence()}", 'permission'); } catch (\Throwable $th) { Console::warning("'permission' from {$databaseTable}: {$th->getMessage()}"); } @@ -293,7 +293,7 @@ class V15 extends Migration protected function removeWritePermissions(string $table): void { try { - $this->pdo->prepare("DELETE FROM `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _type = 'write'")->execute(); + $this->pdo->prepare("DELETE FROM `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$table}_perms` WHERE _type = 'write'")->execute(); } catch (\Throwable $th) { Console::warning("Remove 'write' permissions from {$table}: {$th->getMessage()}"); } @@ -309,7 +309,7 @@ class V15 extends Migration */ protected function getSQLColumnTypes(string $table): array { - $query = $this->pdo->prepare("SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '_{$this->project->getInternalId()}_{$table}' AND table_schema = '{$this->dbForProject->getDatabase()}'"); + $query = $this->pdo->prepare("SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '_{$this->project->getSequence()}_{$table}' AND table_schema = '{$this->dbForProject->getDatabase()}'"); $query->execute(); return array_reduce($query->fetchAll(), function (array $carry, array $item) { @@ -331,8 +331,8 @@ class V15 extends Migration if ($columns[$attribute] === 'int') { try { - $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} VARCHAR(64)")->execute(); - $this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` SET {$attribute} = IF({$attribute} = 0, NULL, FROM_UNIXTIME({$attribute}))")->execute(); + $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$table}` MODIFY {$attribute} VARCHAR(64)")->execute(); + $this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$table}` SET {$attribute} = IF({$attribute} = 0, NULL, FROM_UNIXTIME({$attribute}))")->execute(); $columns[$attribute] = 'varchar'; } catch (\Throwable $th) { Console::warning($th->getMessage()); @@ -341,7 +341,7 @@ class V15 extends Migration if ($columns[$attribute] === 'varchar') { try { - $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} DATETIME(3)")->execute(); + $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$table}` MODIFY {$attribute} DATETIME(3)")->execute(); } catch (\Throwable $th) { Console::warning($th->getMessage()); } @@ -387,7 +387,7 @@ class V15 extends Migration if (!array_key_exists('_permissions', $columns)) { try { - $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` ADD `_permissions` MEDIUMTEXT DEFAULT NULL")->execute(); + $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$table}` ADD `_permissions` MEDIUMTEXT DEFAULT NULL")->execute(); } catch (\Throwable $th) { Console::warning("Add '_permissions' column to '{$table}': {$th->getMessage()}"); } @@ -408,7 +408,7 @@ class V15 extends Migration { $table ??= $document->getCollection(); - $query = $this->pdo->prepare("SELECT * FROM `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _document = '{$document->getId()}'"); + $query = $this->pdo->prepare("SELECT * FROM `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$table}_perms` WHERE _document = '{$document->getId()}'"); $query->execute(); $results = $query->fetchAll(); $permissions = []; @@ -466,7 +466,7 @@ class V15 extends Migration Console::log("Migrating Collection \"{$id}\""); - $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); + $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); switch ($id) { case '_metadata': @@ -746,7 +746,7 @@ class V15 extends Migration Permission::delete(Role::any()), ], 'functionId' => $function->getId(), - 'functionInternalId' => $function->getInternalId(), + 'functionInternalId' => $function->getSequence(), 'key' => (string) $key, 'value' => (string) $value, 'search' => implode(' ', [$variableId, $key, $function->getId()]) @@ -1470,9 +1470,9 @@ class V15 extends Migration $from = $this->pdo->quote($from); $to = $this->pdo->quote($to); - $this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_stats` SET metric = {$to} WHERE metric = {$from}")->execute(); + $this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_stats` SET metric = {$to} WHERE metric = {$from}")->execute(); } catch (\Throwable $th) { - Console::warning("Migrating steps from {$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_stats:" . $th->getMessage()); + Console::warning("Migrating steps from {$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_stats:" . $th->getMessage()); } } diff --git a/src/Appwrite/Migration/Version/V16.php b/src/Appwrite/Migration/Version/V16.php index 34407a0471..9d72af9563 100644 --- a/src/Appwrite/Migration/Version/V16.php +++ b/src/Appwrite/Migration/Version/V16.php @@ -45,7 +45,7 @@ class V16 extends Migration Console::log("Migrating Collection \"{$id}\""); - $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); + $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); switch ($id) { case 'sessions': diff --git a/src/Appwrite/Migration/Version/V17.php b/src/Appwrite/Migration/Version/V17.php index f7cb08d6f4..fbbd4bfde0 100644 --- a/src/Appwrite/Migration/Version/V17.php +++ b/src/Appwrite/Migration/Version/V17.php @@ -44,7 +44,7 @@ class V17 extends Migration protected function migrateBuckets(): void { foreach ($this->documentsIterator('buckets') as $bucket) { - $id = "bucket_{$bucket->getInternalId()}"; + $id = "bucket_{$bucket->getSequence()}"; try { $this->dbForProject->updateAttribute($id, 'mimeType', Database::VAR_STRING, 255, true, false); @@ -67,7 +67,7 @@ class V17 extends Migration Console::log("Migrating Collection \"{$id}\""); - $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); + $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); switch ($id) { case 'builds': diff --git a/src/Appwrite/Migration/Version/V18.php b/src/Appwrite/Migration/Version/V18.php index a5fae3789b..aa2ad35cca 100644 --- a/src/Appwrite/Migration/Version/V18.php +++ b/src/Appwrite/Migration/Version/V18.php @@ -26,7 +26,7 @@ class V18 extends Migration } Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')'); - $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); + $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); $this->addDocumentSecurityToProject(); Console::info('Migrating Databases'); @@ -48,12 +48,12 @@ class V18 extends Migration private function migrateDatabases(): void { foreach ($this->documentsIterator('databases') as $database) { - $databaseTable = "database_{$database->getInternalId()}"; + $databaseTable = "database_{$database->getSequence()}"; Console::info("Migrating Collections of {$database->getId()} ({$database->getAttribute('name')})"); foreach ($this->documentsIterator($databaseTable) as $collection) { - $collectionTable = "{$databaseTable}_collection_{$collection->getInternalId()}"; + $collectionTable = "{$databaseTable}_collection_{$collection->getSequence()}"; foreach ($collection['attributes'] ?? [] as $attribute) { if ($attribute['type'] !== Database::VAR_FLOAT) { @@ -197,7 +197,7 @@ class V18 extends Migration * Set the bucket permission in the metadata table */ try { - $internalBucketId = "bucket_{$this->project->getInternalId()}"; + $internalBucketId = "bucket_{$this->project->getSequence()}"; $permissions = $document->getPermissions(); $fileSecurity = $document->getAttribute('fileSecurity', false); $this->dbForProject->updateCollection($internalBucketId, $permissions, $fileSecurity); @@ -224,8 +224,8 @@ class V18 extends Migration // Nonetheless, there's nothing else we can do here. break; } - $internalId = $user->getInternalId(); - $document->setAttribute('userId', $internalId); + $sequence = $user->getSequence(); + $document->setAttribute('userId', $sequence); $data = $document->getAttribute('data', []); $data['userId'] = $user->getId(); $document->setAttribute('data', $data); @@ -244,7 +244,7 @@ class V18 extends Migration /** * Create 'documentSecurity' column */ - $this->pdo->prepare("ALTER TABLE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}__metadata` ADD COLUMN IF NOT EXISTS documentSecurity TINYINT(1);")->execute(); + $this->pdo->prepare("ALTER TABLE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}__metadata` ADD COLUMN IF NOT EXISTS documentSecurity TINYINT(1);")->execute(); } catch (\Throwable $th) { Console::warning($th->getMessage()); } @@ -253,7 +253,7 @@ class V18 extends Migration /** * Set 'documentSecurity' column to 1 if NULL */ - $this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}__metadata` SET documentSecurity = 1 WHERE documentSecurity IS NULL")->execute(); + $this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}__metadata` SET documentSecurity = 1 WHERE documentSecurity IS NULL")->execute(); } catch (\Throwable $th) { Console::warning($th->getMessage()); } diff --git a/src/Appwrite/Migration/Version/V19.php b/src/Appwrite/Migration/Version/V19.php index cae27cc6ed..d4dda02d75 100644 --- a/src/Appwrite/Migration/Version/V19.php +++ b/src/Appwrite/Migration/Version/V19.php @@ -28,7 +28,7 @@ class V19 extends Migration } Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')'); - $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); + $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); Console::info('Migrating Collections'); $this->migrateCollections(); @@ -100,7 +100,7 @@ class V19 extends Migration protected function migrateBuckets(): void { foreach ($this->documentsIterator('buckets') as $bucket) { - $id = "bucket_{$bucket->getInternalId()}"; + $id = "bucket_{$bucket->getSequence()}"; Console::log("Migrating Bucket {$id} {$bucket->getId()} ({$bucket->getAttribute('name')})"); try { @@ -121,7 +121,7 @@ class V19 extends Migration */ private function migrateCollections(): void { - $internalProjectId = $this->project->getInternalId(); + $internalProjectId = $this->project->getSequence(); $collectionType = match ($internalProjectId) { 'console' => 'console', default => 'projects', @@ -680,7 +680,7 @@ class V19 extends Migration case 'builds': $deploymentId = $document->getAttribute('deploymentId'); $deployment = $this->dbForProject->getDocument('deployments', $deploymentId); - $document->setAttribute('deploymentInternalId', $deployment->getInternalId()); + $document->setAttribute('deploymentInternalId', $deployment->getSequence()); $stdout = $document->getAttribute('stdout', ''); $stderr = $document->getAttribute('stderr', ''); @@ -692,12 +692,12 @@ class V19 extends Migration case 'deployments': $resourceId = $document->getAttribute('resourceId'); $function = $this->dbForProject->getDocument('functions', $resourceId); - $document->setAttribute('resourceInternalId', $function->getInternalId()); + $document->setAttribute('resourceInternalId', $function->getSequence()); $buildId = $document->getAttribute('buildId'); if (!empty($buildId)) { $build = $this->dbForProject->getDocument('builds', $buildId); - $document->setAttribute('buildInternalId', $build->getInternalId()); + $document->setAttribute('buildInternalId', $build->getSequence()); } $commands = $this->getFunctionCommands($function); @@ -707,11 +707,11 @@ class V19 extends Migration case 'executions': $functionId = $document->getAttribute('functionId'); $function = $this->dbForProject->getDocument('functions', $functionId); - $document->setAttribute('functionInternalId', $function->getInternalId()); + $document->setAttribute('functionInternalId', $function->getSequence()); $deploymentId = $document->getAttribute('deploymentId'); $deployment = $this->dbForProject->getDocument('deployments', $deploymentId); - $document->setAttribute('deploymentInternalId', $deployment->getInternalId()); + $document->setAttribute('deploymentInternalId', $deployment->getSequence()); break; case 'functions': $document->setAttribute('live', $document->getAttribute('live', true)); @@ -721,7 +721,7 @@ class V19 extends Migration if (!empty($deploymentId)) { $deployment = $this->dbForProject->getDocument('deployments', $deploymentId); - $document->setAttribute('deploymentInternalId', $deployment->getInternalId()); + $document->setAttribute('deploymentInternalId', $deployment->getSequence()); $document->setAttribute('entrypoint', $deployment->getAttribute('entrypoint')); } @@ -733,7 +733,7 @@ class V19 extends Migration 'region' => $project->getAttribute('region'), 'resourceType' => 'function', 'resourceId' => $document->getId(), - 'resourceInternalId' => $document->getInternalId(), + 'resourceInternalId' => $document->getSequence(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $this->project->getId(), 'schedule' => $document->getAttribute('schedule'), @@ -741,7 +741,7 @@ class V19 extends Migration ])); $document->setAttribute('scheduleId', $schedule->getId()); - $document->setAttribute('scheduleInternalId', $schedule->getInternalId()); + $document->setAttribute('scheduleInternalId', $schedule->getSequence()); } break; @@ -799,7 +799,7 @@ class V19 extends Migration */ public function forEachDocument(callable $callback): void { - $internalProjectId = $this->project->getInternalId(); + $internalProjectId = $this->project->getSequence(); $collections = match ($internalProjectId) { 'console' => $this->collections['console'], diff --git a/src/Appwrite/Migration/Version/V20.php b/src/Appwrite/Migration/Version/V20.php index 3a9bba6772..9ff041eb33 100644 --- a/src/Appwrite/Migration/Version/V20.php +++ b/src/Appwrite/Migration/Version/V20.php @@ -36,13 +36,13 @@ class V20 extends Migration } Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')'); - $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); + $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); Console::info('Migrating Collections'); $this->migrateCollections(); // No need to migrate stats for console - if ($this->project->getInternalId() !== 'console') { + if ($this->project->getSequence() !== 'console') { $this->migrateUsageMetrics('project.$all.network.requests', 'network.requests'); $this->migrateUsageMetrics('project.$all.network.outbound', 'network.outbound'); $this->migrateUsageMetrics('project.$all.network.inbound', 'network.inbound'); @@ -71,7 +71,7 @@ class V20 extends Migration */ private function migrateCollections(): void { - $internalProjectId = $this->project->getInternalId(); + $internalProjectId = $this->project->getSequence(); $collectionType = match ($internalProjectId) { 'console' => 'console', default => 'projects', @@ -510,7 +510,7 @@ class V20 extends Migration Console::log("Migrating Functions usage stats of {$function->getId()} ({$function->getAttribute('name')})"); $functionId = $function->getId(); - $functionInternalId = $function->getInternalId(); + $functionInternalId = $function->getSequence(); $this->migrateUsageMetrics("deployment.$functionId.storage.size", "function.$functionInternalId.deployments.storage"); $this->migrateUsageMetrics("builds.$functionId.compute.total", "$functionInternalId.builds"); @@ -536,22 +536,22 @@ class V20 extends Migration foreach ($this->documentsIterator('databases') as $database) { Console::log("Migrating Collections of {$database->getId()} ({$database->getAttribute('name')})"); - $databaseTable = "database_{$database->getInternalId()}"; + $databaseTable = "database_{$database->getSequence()}"; // Database level $databaseId = $database->getId(); - $databaseInternalId = $database->getInternalId(); + $databaseInternalId = $database->getSequence(); $this->migrateUsageMetrics("collections.$databaseId.count.total", "$databaseInternalId.collections"); $this->migrateUsageMetrics("documents.$databaseId.count.total", "$databaseInternalId.documents"); foreach ($this->documentsIterator($databaseTable) as $collection) { - $collectionTable = "{$databaseTable}_collection_{$collection->getInternalId()}"; + $collectionTable = "{$databaseTable}_collection_{$collection->getSequence()}"; Console::log("Migrating Collections of {$collectionTable} {$collection->getId()} ({$collection->getAttribute('name')})"); // Collection level $collectionId = $collection->getId(); - $collectionInternalId = $collection->getInternalId(); + $collectionInternalId = $collection->getSequence(); $this->migrateUsageMetrics("documents.$databaseId/$collectionId.count.total", "$databaseInternalId.$collectionInternalId.documents"); } @@ -573,12 +573,12 @@ class V20 extends Migration $this->migrateUsageMetrics('files.$all.storage.size', 'files.storage'); foreach ($this->documentsIterator('buckets') as $bucket) { - $id = "bucket_{$bucket->getInternalId()}"; + $id = "bucket_{$bucket->getSequence()}"; Console::log("Migrating Bucket {$id} {$bucket->getId()} ({$bucket->getAttribute('name')})"); // Bucket level $bucketId = $bucket->getId(); - $bucketInternalId = $bucket->getInternalId(); + $bucketInternalId = $bucket->getSequence(); $this->migrateUsageMetrics("files.$bucketId.count.total", "$bucketInternalId.files"); $this->migrateUsageMetrics("files.$bucketId.storage.size", "$bucketInternalId.files.storage"); @@ -605,7 +605,7 @@ class V20 extends Migration $target = new Document([ '$id' => ID::unique(), 'userId' => $document->getId(), - 'userInternalId' => $document->getInternalId(), + 'userInternalId' => $document->getSequence(), 'providerType' => MESSAGE_TYPE_EMAIL, 'identifier' => $document->getAttribute('email'), ]); @@ -620,7 +620,7 @@ class V20 extends Migration $target = new Document([ '$id' => ID::unique(), 'userId' => $document->getId(), - 'userInternalId' => $document->getInternalId(), + 'userInternalId' => $document->getSequence(), 'providerType' => MESSAGE_TYPE_SMS, 'identifier' => $document->getAttribute('phone'), ]); diff --git a/src/Appwrite/Migration/Version/V21.php b/src/Appwrite/Migration/Version/V21.php index 38e8a8d513..891d2a92fe 100644 --- a/src/Appwrite/Migration/Version/V21.php +++ b/src/Appwrite/Migration/Version/V21.php @@ -29,12 +29,12 @@ class V21 extends Migration } Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')'); - $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); + $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); Console::info('Migrating Collections'); $this->migrateCollections(); - if ($this->project->getInternalId() !== 'console') { + if ($this->project->getSequence() !== 'console') { Console::info('Migrating Buckets'); $this->migrateBuckets(); } @@ -51,7 +51,7 @@ class V21 extends Migration */ private function migrateCollections(): void { - $internalProjectId = $this->project->getInternalId(); + $internalProjectId = $this->project->getSequence(); $collectionType = match ($internalProjectId) { 'console' => 'console', default => 'projects', @@ -251,7 +251,7 @@ class V21 extends Migration private function migrateBuckets(): void { $this->dbForProject->forEach('buckets', function (Document $bucket) { - $bucketId = 'bucket_' . $bucket['$internalId']; + $bucketId = 'bucket_' . $bucket['$sequence']; Console::log("Migrating Bucket {$bucketId} {$bucket->getId()} ({$bucket->getAttribute('name')})"); diff --git a/src/Appwrite/Migration/Version/V22.php b/src/Appwrite/Migration/Version/V22.php index 50d5bdbb85..a99e07de59 100644 --- a/src/Appwrite/Migration/Version/V22.php +++ b/src/Appwrite/Migration/Version/V22.php @@ -49,7 +49,7 @@ class V22 extends Migration */ private function migrateCollections(): void { - $projectInternalId = $this->project->getInternalId(); + $projectInternalId = $this->project->getSequence(); if (empty($projectInternalId)) { throw new Exception('Project ID is null'); @@ -394,7 +394,7 @@ class V22 extends Migration 2. Fill "deploymentCreatedAt" with deployment's "$createdAt" --- Fetch latestDeployment using find() 3. Fill latestDeploymentId with latestDeployment's "$id" - 4. Fill latestDeploymentInternalId with latestDeployment's "$internalId" + 4. Fill latestDeploymentInternalId with latestDeployment's "$sequence" 5. Fill latestDeploymentCreatedAt with latestDeployment's "$createdAt" 6. Fill latestDeploymentStatus with latestDeployment's build's "status" */ @@ -433,7 +433,7 @@ class V22 extends Migration $document ->setAttribute('latestDeploymentId', $latestDeployment->getId()) - ->setAttribute('latestDeploymentInternalId', $latestDeployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $latestDeployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $latestDeployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $latestBuild->getAttribute('status', $document->getAttribute('latestDeploymentStatus', ''))); break; @@ -497,7 +497,7 @@ class V22 extends Migration private function cleanCollections(): void { - $projectInternalId = $this->project->getInternalId(); + $projectInternalId = $this->project->getSequence(); $collectionType = match ($projectInternalId) { 'console' => 'console', diff --git a/src/Appwrite/Platform/Modules/Compute/Base.php b/src/Appwrite/Platform/Modules/Compute/Base.php index 47529a142b..71c436b0a0 100644 --- a/src/Appwrite/Platform/Modules/Compute/Base.php +++ b/src/Appwrite/Platform/Modules/Compute/Base.php @@ -69,13 +69,13 @@ class Base extends Action Permission::delete(Role::any()), ], 'resourceId' => $function->getId(), - 'resourceInternalId' => $function->getInternalId(), + 'resourceInternalId' => $function->getSequence(), 'resourceType' => 'functions', 'entrypoint' => $entrypoint, 'buildCommands' => $function->getAttribute('commands', ''), 'type' => 'vcs', 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getInternalId(), + 'installationInternalId' => $installation->getSequence(), 'providerRepositoryId' => $providerRepositoryId, 'repositoryId' => $function->getAttribute('repositoryId', ''), 'repositoryInternalId' => $function->getAttribute('repositoryInternalId', ''), @@ -95,7 +95,7 @@ class Base extends Action $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); @@ -166,7 +166,7 @@ class Base extends Action Permission::delete(Role::any()), ], 'resourceId' => $site->getId(), - 'resourceInternalId' => $site->getInternalId(), + 'resourceInternalId' => $site->getSequence(), 'resourceType' => 'sites', 'buildCommands' => implode(' && ', $commands), 'buildOutput' => $site->getAttribute('outputDirectory', ''), @@ -174,7 +174,7 @@ class Base extends Action 'fallbackFile' => $site->getAttribute('fallbackFile', ''), 'type' => 'vcs', 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getInternalId(), + 'installationInternalId' => $installation->getSequence(), 'providerRepositoryId' => $providerRepositoryId, 'repositoryId' => $site->getAttribute('repositoryId', ''), 'repositoryInternalId' => $site->getAttribute('repositoryInternalId', ''), @@ -194,7 +194,7 @@ class Base extends Action $site = $site ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('sites', $site->getId(), $site); @@ -209,15 +209,15 @@ class Base extends Action fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain, 'trigger' => 'deployment', 'type' => 'deployment', 'deploymentId' => $deployment->getId(), - 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->getSequence(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $site->getId(), - 'deploymentResourceInternalId' => $site->getInternalId(), + 'deploymentResourceInternalId' => $site->getSequence(), 'deploymentVcsProviderBranch' => $providerBranch, 'status' => 'verified', 'certificateId' => '', @@ -244,7 +244,7 @@ class Base extends Action do { $queries = \array_merge([ Query::limit($limit), - Query::equal("projectInternalId", [$project->getInternalId()]) + Query::equal("projectInternalId", [$project->getSequence()]) ], $queries); if ($cursor !== null) { diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php index cda6dc38bf..ad3ea18b98 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php @@ -237,7 +237,7 @@ class Create extends Action Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'resourceInternalId' => $function->getInternalId(), + 'resourceInternalId' => $function->getSequence(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', 'entrypoint' => $entrypoint, @@ -252,7 +252,7 @@ class Create extends Action $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); @@ -274,7 +274,7 @@ class Create extends Action Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'resourceInternalId' => $function->getInternalId(), + 'resourceInternalId' => $function->getSequence(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', 'entrypoint' => $entrypoint, @@ -291,7 +291,7 @@ class Create extends Action $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php index 84878055d8..912e12bdc1 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php @@ -101,7 +101,7 @@ class Delete extends Action if ($function->getAttribute('latestDeploymentId') === $deployment->getId()) { $latestDeployment = $dbForProject->findOne('deployments', [ Query::equal('resourceType', ['functions']), - Query::equal('resourceInternalId', [$function->getInternalId()]), + Query::equal('resourceInternalId', [$function->getSequence()]), Query::orderDesc('$createdAt'), ]); $function = $dbForProject->updateDocument( @@ -109,7 +109,7 @@ class Delete extends Action $function->getId(), $function ->setAttribute('latestDeploymentCreatedAt', $latestDeployment->isEmpty() ? '' : $latestDeployment->getCreatedAt()) - ->setAttribute('latestDeploymentInternalId', $latestDeployment->isEmpty() ? '' : $latestDeployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $latestDeployment->isEmpty() ? '' : $latestDeployment->getSequence()) ->setAttribute('latestDeploymentId', $latestDeployment->isEmpty() ? '' : $latestDeployment->getId()) ->setAttribute('latestDeploymentStatus', $latestDeployment->isEmpty() ? '' : $latestDeployment->getAttribute('status', '')) ); 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 8f739dd37f..0a07440dff 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php @@ -96,9 +96,9 @@ class Create extends Action $destination = $deviceForFunctions->getPath($deploymentId . '.' . \pathinfo('code.tar.gz', PATHINFO_EXTENSION)); $deviceForFunctions->transfer($path, $destination, $deviceForFunctions); - $deployment->removeAttribute('$internalId'); + $deployment->removeAttribute('$sequence'); $deployment = $dbForProject->createDocument('deployments', $deployment->setAttributes([ - '$internalId' => '', + '$sequence' => '', '$id' => $deploymentId, 'sourcePath' => $destination, 'totalSize' => $deployment->getAttribute('sourceSize', 0), @@ -115,7 +115,7 @@ class Create extends Action $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); 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 c5436d1d05..4c924a64d1 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php @@ -97,7 +97,7 @@ class Update extends Action 'status' => 'canceled' ])); - if ($deployment->getInternalId() === $function->getAttribute('latestDeploymentInternalId', '')) { + if ($deployment->getSequence() === $function->getAttribute('latestDeploymentInternalId', '')) { $function = $function->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php index 55230bd4a5..f1bd4b71e4 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php @@ -142,7 +142,7 @@ class Create extends Base Permission::delete(Role::any()), ], 'resourceId' => $function->getId(), - 'resourceInternalId' => $function->getInternalId(), + 'resourceInternalId' => $function->getSequence(), 'resourceType' => 'functions', 'entrypoint' => $function->getAttribute('entrypoint', ''), 'buildCommands' => $function->getAttribute('commands', ''), @@ -152,7 +152,7 @@ class Create extends Base $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php index 38f1f38e89..2ffcfc5d11 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php @@ -84,7 +84,7 @@ class XList extends Action } // Set resource queries - $queries[] = Query::equal('resourceInternalId', [$function->getInternalId()]); + $queries[] = Query::equal('resourceInternalId', [$function->getSequence()]); $queries[] = Query::equal('resourceType', ['functions']); /** diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index fd1b2076a8..0aec31e5fd 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -253,10 +253,10 @@ class Create extends Base $execution = new Document([ '$id' => $executionId, '$permissions' => !$user->isEmpty() ? [Permission::read(Role::user($user->getId()))] : [], - 'resourceInternalId' => $function->getInternalId(), + 'resourceInternalId' => $function->getSequence(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', - 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->getSequence(), 'deploymentId' => $deployment->getId(), 'trigger' => (!is_null($scheduledAt)) ? 'schedule' : 'http', 'status' => $status, // waiting / processing / completed / failed / scheduled @@ -305,7 +305,7 @@ class Create extends Base 'region' => $project->getAttribute('region'), 'resourceType' => ScheduleExecutions::getSupportedResource(), 'resourceId' => $execution->getId(), - 'resourceInternalId' => $execution->getInternalId(), + 'resourceInternalId' => $execution->getSequence(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -315,7 +315,7 @@ class Create extends Base $execution = $execution ->setAttribute('scheduleId', $schedule->getId()) - ->setAttribute('scheduleInternalId', $schedule->getInternalId()) + ->setAttribute('scheduleInternalId', $schedule->getSequence()) ->setAttribute('scheduledAt', $scheduledAt); $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution)); @@ -439,13 +439,13 @@ class Create extends Base $queueForStatsUsage ->addMetric(METRIC_EXECUTIONS, 1) ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS), 1) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ; $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution)); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Delete.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Delete.php index cd85b5e534..8a3d5f2a49 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Delete.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Delete.php @@ -84,7 +84,7 @@ class Delete extends Base throw new Exception(Exception::EXECUTION_NOT_FOUND); } - if ($execution->getAttribute('resourceType') !== 'functions' && $execution->getAttribute('resourceInternalId') !== $function->getInternalId()) { + if ($execution->getAttribute('resourceType') !== 'functions' && $execution->getAttribute('resourceInternalId') !== $function->getSequence()) { throw new Exception(Exception::EXECUTION_NOT_FOUND); } $status = $execution->getAttribute('status'); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php index 892ce30f47..659682ab55 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php @@ -72,7 +72,7 @@ class Get extends Base $execution = $dbForProject->getDocument('executions', $executionId); - if ($execution->getAttribute('resourceType') !== 'functions' || $execution->getAttribute('resourceInternalId') !== $function->getInternalId()) { + if ($execution->getAttribute('resourceType') !== 'functions' || $execution->getAttribute('resourceInternalId') !== $function->getSequence()) { throw new Exception(Exception::EXECUTION_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php index a31e95b1c8..91683c915b 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php @@ -83,7 +83,7 @@ class XList extends Base } // Set internal queries - $queries[] = Query::equal('resourceInternalId', [$function->getInternalId()]); + $queries[] = Query::equal('resourceInternalId', [$function->getSequence()]); $queries[] = Query::equal('resourceType', ['functions']); /** diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php index fd8da657eb..c644c681d8 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php @@ -222,7 +222,7 @@ class Create extends Base 'search' => implode(' ', [$functionId, $name, $runtime]), 'version' => 'v5', 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getInternalId(), + 'installationInternalId' => $installation->getSequence(), 'providerRepositoryId' => $providerRepositoryId, 'repositoryId' => '', 'repositoryInternalId' => '', @@ -237,7 +237,7 @@ class Create extends Base 'region' => $project->getAttribute('region'), 'resourceType' => 'function', 'resourceId' => $function->getId(), - 'resourceInternalId' => $function->getInternalId(), + 'resourceInternalId' => $function->getSequence(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $function->getAttribute('schedule'), @@ -246,7 +246,7 @@ class Create extends Base ); $function->setAttribute('scheduleId', $schedule->getId()); - $function->setAttribute('scheduleInternalId', $schedule->getInternalId()); + $function->setAttribute('scheduleInternalId', $schedule->getSequence()); // Git connect logic if (!empty($providerRepositoryId)) { @@ -262,18 +262,18 @@ class Create extends Base Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getInternalId(), + 'installationInternalId' => $installation->getSequence(), 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'providerRepositoryId' => $providerRepositoryId, 'resourceId' => $function->getId(), - 'resourceInternalId' => $function->getInternalId(), + 'resourceInternalId' => $function->getSequence(), 'resourceType' => 'function', 'providerPullRequestIds' => [] ])); $function->setAttribute('repositoryId', $repository->getId()); - $function->setAttribute('repositoryInternalId', $repository->getInternalId()); + $function->setAttribute('repositoryInternalId', $repository->getSequence()); } $function = $dbForProject->updateDocument('functions', $function->getId(), $function); @@ -316,7 +316,7 @@ class Create extends Base $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); @@ -331,7 +331,7 @@ class Create extends Base Permission::delete(Role::any()), ], 'resourceId' => $function->getId(), - 'resourceInternalId' => $function->getInternalId(), + 'resourceInternalId' => $function->getSequence(), 'resourceType' => 'functions', 'entrypoint' => $function->getAttribute('entrypoint', ''), 'buildCommands' => $function->getAttribute('commands', ''), @@ -341,7 +341,7 @@ class Create extends Base $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); @@ -364,16 +364,16 @@ class Create extends Base fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain, 'status' => 'verified', 'type' => 'deployment', 'trigger' => 'manual', 'deploymentId' => !isset($deployment) || $deployment->isEmpty() ? '' : $deployment->getId(), - 'deploymentInternalId' => !isset($deployment) || $deployment->isEmpty() ? '' : $deployment->getInternalId(), + 'deploymentInternalId' => !isset($deployment) || $deployment->isEmpty() ? '' : $deployment->getSequence(), 'deploymentResourceType' => 'function', 'deploymentResourceId' => $function->getId(), - 'deploymentResourceInternalId' => $function->getInternalId(), + 'deploymentResourceInternalId' => $function->getSequence(), 'deploymentVcsProviderBranch' => '', 'certificateId' => '', 'search' => implode(' ', [$ruleId, $domain]), 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 6de71cfae6..1f3e39dee1 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php @@ -92,7 +92,7 @@ class Update extends Base $oldDeploymentInternalId = $function->getAttribute('deploymentInternalId', ''); $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ - 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->getSequence(), 'deploymentId' => $deployment->getId(), 'deploymentCreatedAt' => $deployment->getCreatedAt(), ]))); @@ -109,7 +109,7 @@ class Update extends Base Query::equal('trigger', 'manual'), Query::equal("type", ["deployment"]), Query::equal("deploymentResourceType", ["function"]), - Query::equal("deploymentResourceInternalId", [$function->getInternalId()]), + Query::equal("deploymentResourceInternalId", [$function->getSequence()]), ]; if (empty($oldDeploymentInternalId)) { @@ -121,7 +121,7 @@ class Update extends Base $this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { $rule = $rule ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getInternalId()); + ->setAttribute('deploymentInternalId', $deployment->getSequence()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); }); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index a19ec1e278..2bfe8b1344 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -175,8 +175,8 @@ class Update extends Base // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ - Query::equal('projectInternalId', [$project->getInternalId()]), - Query::equal('resourceInternalId', [$function->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('resourceInternalId', [$function->getSequence()]), Query::equal('resourceType', ['function']), Query::limit(100), ]); @@ -208,18 +208,18 @@ class Update extends Base Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getInternalId(), + 'installationInternalId' => $installation->getSequence(), 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'providerRepositoryId' => $providerRepositoryId, 'resourceId' => $function->getId(), - 'resourceInternalId' => $function->getInternalId(), + 'resourceInternalId' => $function->getSequence(), 'resourceType' => 'function', 'providerPullRequestIds' => [] ])); $repositoryId = $repository->getId(); - $repositoryInternalId = $repository->getInternalId(); + $repositoryInternalId = $repository->getSequence(); } $live = true; @@ -260,7 +260,7 @@ class Update extends Base 'commands' => $commands, 'scopes' => $scopes, 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getInternalId(), + 'installationInternalId' => $installation->getSequence(), 'providerRepositoryId' => $providerRepositoryId, 'repositoryId' => $repositoryId, 'repositoryInternalId' => $repositoryInternalId, diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php index e0d659c9ba..947da4cd37 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php @@ -70,17 +70,17 @@ class Get extends Base $stats = $usage = []; $days = $periods[$range]; $metrics = [ - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php index 9300524c64..ee892fe1ed 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php @@ -96,7 +96,7 @@ class Create extends Base Permission::delete(Role::team(ID::custom($teamId), 'owner')), Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], - 'resourceInternalId' => $function->getInternalId(), + 'resourceInternalId' => $function->getSequence(), 'resourceId' => $function->getId(), 'resourceType' => 'function', 'key' => $key, diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Delete.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Delete.php index 3d6bfebcb9..dda1f97f6b 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Delete.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Delete.php @@ -74,7 +74,7 @@ class Delete extends Base } $variable = $dbForProject->getDocument('variables', $variableId); - if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $function->getInternalId() || $variable->getAttribute('resourceType') !== 'function') { + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $function->getSequence() || $variable->getAttribute('resourceType') !== 'function') { throw new Exception(Exception::VARIABLE_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php index 70cc66219a..98119c4a66 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php @@ -68,7 +68,7 @@ class Get extends Base if ( $variable === false || $variable->isEmpty() || - $variable->getAttribute('resourceInternalId') !== $function->getInternalId() || + $variable->getAttribute('resourceInternalId') !== $function->getSequence() || $variable->getAttribute('resourceType') !== 'function' ) { throw new Exception(Exception::VARIABLE_NOT_FOUND); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Update.php index 4102022267..7a6acf88e3 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Update.php @@ -81,7 +81,7 @@ class Update extends Base } $variable = $dbForProject->getDocument('variables', $variableId); - if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $function->getInternalId() || $variable->getAttribute('resourceType') !== 'function') { + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $function->getSequence() || $variable->getAttribute('resourceType') !== 'function') { throw new Exception(Exception::VARIABLE_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 6ff2161c1a..e43f92a24a 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -273,7 +273,7 @@ class Builds extends Action $deployment->setAttribute('status', 'processing'); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); - if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { + if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); } @@ -523,7 +523,7 @@ class Builds extends Action $deployment->setAttribute('status', 'building'); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); - if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { + if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); } @@ -886,9 +886,9 @@ class Builds extends Action if ($resource->getCollection() === 'sites') { try { $rule = Authorization::skip(fn () => $dbForPlatform->findOne('rules', [ - Query::equal("projectInternalId", [$project->getInternalId()]), + Query::equal("projectInternalId", [$project->getSequence()]), Query::equal("type", ["deployment"]), - Query::equal('deploymentInternalId', [$deployment->getInternalId()]), + Query::equal('deploymentInternalId', [$deployment->getSequence()]), ])); if ($rule->isEmpty()) { @@ -927,9 +927,9 @@ class Builds extends Action str_replace(["{resourceType}"], [RESOURCE_TYPE_SITES], METRIC_RESOURCE_TYPE_EXECUTIONS), str_replace(["{resourceType}"], [RESOURCE_TYPE_SITES], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), str_replace(["{resourceType}"], [RESOURCE_TYPE_SITES], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), - str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), - str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), - str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), + str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), + str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), + str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), ], 'bannerDisabled' => true, 'projectCheckDisabled' => true, @@ -999,7 +999,7 @@ class Builds extends Action Permission::read(Role::team(ID::custom($teamId))), ], 'bucketId' => $bucket->getId(), - 'bucketInternalId' => $bucket->getInternalId(), + 'bucketInternalId' => $bucket->getSequence(), 'name' => $fileName, 'path' => $path, 'signature' => $deviceForFiles->getFileHash($path), @@ -1018,7 +1018,7 @@ class Builds extends Action 'metadata' => ['content_type' => $deviceForFiles->getFileMimeType($path)], ]); - Authorization::skip(fn () => $dbForPlatform->createDocument('bucket_' . $bucket->getInternalId(), $file)); + Authorization::skip(fn () => $dbForPlatform->createDocument('bucket_' . $bucket->getSequence(), $file)); $deployment->setAttribute($key, $fileId); } @@ -1054,7 +1054,7 @@ class Builds extends Action $deployment->setAttribute('status', 'ready'); $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); - if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { + if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); } @@ -1077,14 +1077,14 @@ class Builds extends Action $oldDeploymentInternalId = $resource->getAttribute('deploymentInternalId', ''); $resource->setAttribute('deploymentId', $deployment->getId()); - $resource->setAttribute('deploymentInternalId', $deployment->getInternalId()); + $resource->setAttribute('deploymentInternalId', $deployment->getSequence()); $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); $resource = $dbForProject->updateDocument('functions', $resource->getId(), $resource); $queries = [ - Query::equal("projectInternalId", [$project->getInternalId()]), + Query::equal("projectInternalId", [$project->getSequence()]), Query::equal("type", ["deployment"]), - Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]), + Query::equal("deploymentResourceInternalId", [$resource->getSequence()]), Query::equal('deploymentResourceType', ['function']), Query::equal('trigger', ['manual']), ]; @@ -1100,7 +1100,7 @@ class Builds extends Action $rulesUpdated = true; $rule = $rule ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getInternalId()); + ->setAttribute('deploymentInternalId', $deployment->getSequence()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); }); break; @@ -1108,15 +1108,15 @@ class Builds extends Action $oldDeploymentInternalId = $resource->getAttribute('deploymentInternalId', ''); $resource->setAttribute('deploymentId', $deployment->getId()); - $resource->setAttribute('deploymentInternalId', $deployment->getInternalId()); + $resource->setAttribute('deploymentInternalId', $deployment->getSequence()); $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()]), + Query::equal("projectInternalId", [$project->getSequence()]), Query::equal("type", ["deployment"]), - Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]), + Query::equal("deploymentResourceInternalId", [$resource->getSequence()]), Query::equal('deploymentResourceType', ['site']), Query::equal('trigger', ['manual']), ]; @@ -1130,7 +1130,7 @@ class Builds extends Action $this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { $rule = $rule ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getInternalId()); + ->setAttribute('deploymentInternalId', $deployment->getSequence()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); }); @@ -1150,15 +1150,15 @@ class Builds extends Action $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->getId(), - 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->getSequence(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $deployment->getId(), - 'deploymentResourceInternalId' => $deployment->getInternalId(), + 'deploymentResourceInternalId' => $deployment->getSequence(), 'deploymentVcsProviderBranch' => $branchName, 'status' => 'verified', 'certificateId' => '', @@ -1170,21 +1170,21 @@ class Builds extends Action $rule = $dbForPlatform->getDocument('rules', $ruleId); $rule = $rule ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getInternalId()); + ->setAttribute('deploymentInternalId', $deployment->getSequence()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); } $this->listRules($project, [ - Query::equal("projectInternalId", [$project->getInternalId()]), + Query::equal("projectInternalId", [$project->getSequence()]), Query::equal("type", ["deployment"]), - Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]), + Query::equal("deploymentResourceInternalId", [$resource->getSequence()]), Query::equal('deploymentResourceType', ['site']), Query::equal("deploymentVcsProviderBranch", [$branchName]), Query::equal("trigger", ['manual']), ], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { $rule = $rule ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getInternalId()); + ->setAttribute('deploymentInternalId', $deployment->getSequence()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); }); } @@ -1249,7 +1249,7 @@ class Builds extends Action $deployment->setAttribute('buildLogs', $message); $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); - if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { + if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); } @@ -1284,8 +1284,8 @@ class Builds extends Action ->addMetric(METRIC_BUILDS_COMPUTE_SUCCESS, (int)$deployment->getAttribute('buildDuration', 0) * 1000) ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_SUCCESS), 1) // per function ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_COMPUTE_SUCCESS), (int)$deployment->getAttribute('buildDuration', 0) * 1000) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), 1) // per function - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_SUCCESS), (int)$deployment->getAttribute('buildDuration', 0) * 1000); + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), 1) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_SUCCESS), (int)$deployment->getAttribute('buildDuration', 0) * 1000); break; case 'failed': $queue @@ -1293,8 +1293,8 @@ class Builds extends Action ->addMetric(METRIC_BUILDS_COMPUTE_FAILED, (int)$deployment->getAttribute('buildDuration', 0) * 1000) ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_FAILED), 1) // per function ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_COMPUTE_FAILED), (int)$deployment->getAttribute('buildDuration', 0) * 1000) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), 1) // per function - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_FAILED), (int)$deployment->getAttribute('buildDuration', 0) * 1000); + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), 1) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_FAILED), (int)$deployment->getAttribute('buildDuration', 0) * 1000); break; } @@ -1307,10 +1307,10 @@ class Builds extends Action ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_STORAGE), $deployment->getAttribute('buildSize', 0)) ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_COMPUTE), (int)$deployment->getAttribute('buildDuration', 0) * 1000) ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), 1) // per function - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $deployment->getAttribute('buildSize', 0)) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), (int)$deployment->getAttribute('buildDuration', 0) * 1000) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS), 1) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $deployment->getAttribute('buildSize', 0)) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), (int)$deployment->getAttribute('buildDuration', 0) * 1000) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->setProject($project) ->trigger(); } @@ -1468,9 +1468,9 @@ class Builds extends Action }; $rule = Authorization::skip(fn () => $dbForPlatform->findOne('rules', [ - Query::equal("projectInternalId", [$project->getInternalId()]), + Query::equal("projectInternalId", [$project->getSequence()]), Query::equal("type", ["deployment"]), - Query::equal("deploymentInternalId", [$deployment->getInternalId()]), + Query::equal("deploymentInternalId", [$deployment->getSequence()]), ])); $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; @@ -1498,7 +1498,7 @@ class Builds extends Action do { $queries = \array_merge([ Query::limit($limit), - Query::equal("projectInternalId", [$project->getInternalId()]) + Query::equal("projectInternalId", [$project->getSequence()]) ], $queries); if ($cursor !== null) { diff --git a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Create.php index 43f7d4ac02..54ff189c20 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Create.php @@ -76,7 +76,7 @@ class Create extends Action Permission::update(Role::user($user->getId())), Permission::delete(Role::user($user->getId())), ], - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'projectId' => $project->getId(), 'name' => $name, 'expire' => $expire, diff --git a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Delete.php b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Delete.php index f6cb966f50..eac42be5f0 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Delete.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Delete.php @@ -63,7 +63,7 @@ class Delete extends Action $key = $dbForPlatform->getDocument('devKeys', $keyId); - if ($key === false || $key->isEmpty() || $key->getAttribute('projectInternalId') !== $project->getInternalId()) { + if ($key === false || $key->isEmpty() || $key->getAttribute('projectInternalId') !== $project->getSequence()) { throw new Exception(Exception::KEY_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Get.php b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Get.php index bd472b26e7..6255976de4 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Get.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Get.php @@ -63,7 +63,7 @@ class Get extends Action $key = $dbForPlatform->getDocument('devKeys', $keyId); - if ($key === false || $key->isEmpty() || $key->getAttribute('projectInternalId') !== $project->getInternalId()) { + if ($key === false || $key->isEmpty() || $key->getAttribute('projectInternalId') !== $project->getSequence()) { throw new Exception(Exception::KEY_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Update.php b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Update.php index d5e6839174..33b91eb0b6 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Update.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Update.php @@ -65,7 +65,7 @@ class Update extends Action $key = $dbForPlatform->getDocument('devKeys', $keyId); - if ($key === false || $key->isEmpty() || $key->getAttribute('projectInternalId') !== $project->getInternalId()) { + if ($key === false || $key->isEmpty() || $key->getAttribute('projectInternalId') !== $project->getSequence()) { throw new Exception(Exception::KEY_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/XList.php b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/XList.php index 864531d32d..73e79a783a 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/XList.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/XList.php @@ -71,7 +71,7 @@ class XList extends Action throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); } - $queries[] = Query::equal('projectInternalId', [$project->getInternalId()]); + $queries[] = Query::equal('projectInternalId', [$project->getSequence()]); $keys = $dbForPlatform->find('devKeys', $queries); diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php index e4d0d2899f..33eb5313a0 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -153,7 +153,7 @@ class Create extends Action $rule = new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain->get(), 'status' => $status, 'type' => 'api', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php index 6c5a87a68d..0b68b80aa3 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php @@ -165,16 +165,16 @@ class Create extends Action $rule = new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain->get(), 'status' => $status, 'type' => 'deployment', 'trigger' => 'manual', 'deploymentId' => $deployment->isEmpty() ? '' : $deployment->getId(), - 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getSequence(), 'deploymentResourceType' => 'function', 'deploymentResourceId' => $function->getId(), - 'deploymentResourceInternalId' => $function->getInternalId(), + 'deploymentResourceInternalId' => $function->getSequence(), 'deploymentVcsProviderBranch' => $branch, 'certificateId' => '', 'search' => implode(' ', [$ruleId, $domain->get(), $branch]), diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php index d0c9dbbbe3..ed84b8498b 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php @@ -157,7 +157,7 @@ class Create extends Action $rule = new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain->get(), 'status' => $status, 'type' => 'redirect', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php index 894c954a32..7c2a640cdf 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php @@ -165,16 +165,16 @@ class Create extends Action $rule = new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain->get(), 'status' => $status, 'type' => 'deployment', 'trigger' => 'manual', 'deploymentId' => $deployment->isEmpty() ? '' : $deployment->getId(), - 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getSequence(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $site->getId(), - 'deploymentResourceInternalId' => $site->getInternalId(), + 'deploymentResourceInternalId' => $site->getSequence(), 'deploymentVcsProviderBranch' => $branch, 'certificateId' => '', 'search' => implode(' ', [$ruleId, $domain->get(), $branch]), diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php index afa1dba7d8..68916a716f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php @@ -246,7 +246,7 @@ class Create extends Action Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'resourceInternalId' => $site->getInternalId(), + 'resourceInternalId' => $site->getSequence(), 'resourceId' => $site->getId(), 'resourceType' => 'sites', 'buildCommands' => \implode(' && ', $commands), @@ -263,7 +263,7 @@ class Create extends Action $site = $site ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('sites', $site->getId(), $site); @@ -278,15 +278,15 @@ class Create extends Action fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->isEmpty() ? '' : $deployment->getId(), - 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getSequence(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $site->getId(), - 'deploymentResourceInternalId' => $site->getInternalId(), + 'deploymentResourceInternalId' => $site->getSequence(), 'status' => 'verified', 'certificateId' => '', 'search' => implode(' ', [$ruleId, $domain]), @@ -312,7 +312,7 @@ class Create extends Action Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'resourceInternalId' => $site->getInternalId(), + 'resourceInternalId' => $site->getSequence(), 'resourceId' => $site->getId(), 'resourceType' => 'sites', 'buildCommands' => \implode(' && ', $commands), @@ -331,7 +331,7 @@ class Create extends Action $site = $site ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('sites', $site->getId(), $site); @@ -343,7 +343,7 @@ class Create extends Action fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php index 27db10c484..8717d04fc2 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php @@ -101,7 +101,7 @@ class Delete extends Action if ($site->getAttribute('latestDeploymentId') === $deployment->getId()) { $latestDeployment = $dbForProject->findOne('deployments', [ Query::equal('resourceType', ['sites']), - Query::equal('resourceInternalId', [$site->getInternalId()]), + Query::equal('resourceInternalId', [$site->getSequence()]), Query::orderDesc('$createdAt'), ]); $site = $dbForProject->updateDocument( @@ -109,7 +109,7 @@ class Delete extends Action $site->getId(), $site ->setAttribute('latestDeploymentCreatedAt', $latestDeployment->isEmpty() ? '' : $latestDeployment->getCreatedAt()) - ->setAttribute('latestDeploymentInternalId', $latestDeployment->isEmpty() ? '' : $latestDeployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $latestDeployment->isEmpty() ? '' : $latestDeployment->getSequence()) ->setAttribute('latestDeploymentId', $latestDeployment->isEmpty() ? '' : $latestDeployment->getId()) ->setAttribute('latestDeploymentStatus', $latestDeployment->isEmpty() ? '' : $latestDeployment->getAttribute('status', '')) ); 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 bff0735328..739c701a2e 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php @@ -110,9 +110,9 @@ class Create extends Action $commands[] = $site->getAttribute('buildCommand', ''); } - $deployment->removeAttribute('$internalId'); + $deployment->removeAttribute('$sequence'); $deployment = $dbForProject->createDocument('deployments', $deployment->setAttributes([ - '$internalId' => '', + '$sequence' => '', '$id' => $deploymentId, 'sourcePath' => $destination, 'totalSize' => $deployment->getAttribute('sourceSize', 0), @@ -134,7 +134,7 @@ class Create extends Action $site = $site ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('sites', $site->getId(), $site); @@ -150,15 +150,15 @@ class Create extends Action fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->isEmpty() ? '' : $deployment->getId(), - 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getSequence(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $site->getId(), - 'deploymentResourceInternalId' => $site->getInternalId(), + 'deploymentResourceInternalId' => $site->getSequence(), 'status' => 'verified', 'certificateId' => '', 'owner' => 'Appwrite', 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 2c6da43893..046ddd1ac8 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php @@ -95,7 +95,7 @@ class Update extends Action 'status' => 'canceled' ])); - if ($deployment->getInternalId() === $site->getAttribute('latestDeploymentInternalId', '')) { + if ($deployment->getSequence() === $site->getAttribute('latestDeploymentInternalId', '')) { $site = $site->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('sites', $site->getId(), $site); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php index 5b29521ce5..5de688fbf8 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php @@ -153,7 +153,7 @@ class Create extends Base Permission::delete(Role::any()), ], 'resourceId' => $site->getId(), - 'resourceInternalId' => $site->getInternalId(), + 'resourceInternalId' => $site->getSequence(), 'resourceType' => 'sites', 'buildCommands' => \implode(' && ', $commands), 'buildOutput' => $site->getAttribute('outputDirectory', ''), @@ -165,7 +165,7 @@ class Create extends Base $site = $site ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('sites', $site->getId(), $site); @@ -180,15 +180,15 @@ class Create extends Base fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->isEmpty() ? '' : $deployment->getId(), - 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getSequence(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $site->getId(), - 'deploymentResourceInternalId' => $site->getInternalId(), + 'deploymentResourceInternalId' => $site->getSequence(), 'status' => 'verified', 'certificateId' => '', 'owner' => 'Appwrite', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php index d7cfc1d3ad..306f756d87 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php @@ -79,7 +79,7 @@ class XList extends Action } // Set resource queries - $queries[] = Query::equal('resourceInternalId', [$site->getInternalId()]); + $queries[] = Query::equal('resourceInternalId', [$site->getSequence()]); $queries[] = Query::equal('resourceType', ['sites']); /** diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Logs/Delete.php b/src/Appwrite/Platform/Modules/Sites/Http/Logs/Delete.php index a411cee91f..2d87321086 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Logs/Delete.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Logs/Delete.php @@ -71,7 +71,7 @@ class Delete extends Base throw new Exception(Exception::LOG_NOT_FOUND); } - if ($log->getAttribute('resourceType') !== 'sites' && $log->getAttribute('resourceInternalId') !== $site->getInternalId()) { + if ($log->getAttribute('resourceType') !== 'sites' && $log->getAttribute('resourceInternalId') !== $site->getSequence()) { throw new Exception(Exception::LOG_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php index 3d1ace2d20..2ef7d75539 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php @@ -63,7 +63,7 @@ class Get extends Base $log = $dbForProject->getDocument('executions', $logId); - if ($log->getAttribute('resourceType') !== 'sites' && $log->getAttribute('resourceInternalId') !== $site->getInternalId()) { + if ($log->getAttribute('resourceType') !== 'sites' && $log->getAttribute('resourceInternalId') !== $site->getSequence()) { throw new Exception(Exception::LOG_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php index a873d32603..7e2c587797 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php @@ -75,7 +75,7 @@ class XList extends Base } // Set internal queries - $queries[] = Query::equal('resourceInternalId', [$site->getInternalId()]); + $queries[] = Query::equal('resourceInternalId', [$site->getSequence()]); $queries[] = Query::equal('resourceType', ['sites']); /** diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php index c509799024..6dd1865047 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php @@ -154,7 +154,7 @@ class Create extends Base 'search' => implode(' ', [$siteId, $name, $framework]), 'fallbackFile' => $fallbackFile, 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getInternalId(), + 'installationInternalId' => $installation->getSequence(), 'providerRepositoryId' => $providerRepositoryId, 'repositoryId' => '', 'repositoryInternalId' => '', @@ -180,18 +180,18 @@ class Create extends Base Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getInternalId(), + 'installationInternalId' => $installation->getSequence(), 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'providerRepositoryId' => $providerRepositoryId, 'resourceId' => $site->getId(), - 'resourceInternalId' => $site->getInternalId(), + 'resourceInternalId' => $site->getSequence(), 'resourceType' => 'site', 'providerPullRequestIds' => [] ])); $site->setAttribute('repositoryId', $repository->getId()); - $site->setAttribute('repositoryInternalId', $repository->getInternalId()); + $site->setAttribute('repositoryInternalId', $repository->getSequence()); } $site = $dbForProject->updateDocument('sites', $site->getId(), $site); 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 7f1681c0f1..835068be88 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php @@ -89,7 +89,7 @@ class Update extends Base $oldDeploymentInternalId = $site->getAttribute('deploymentInternalId', ''); $site = $dbForProject->updateDocument('sites', $site->getId(), new Document(array_merge($site->getArrayCopy(), [ - 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->getSequence(), 'deploymentId' => $deployment->getId(), 'deploymentScreenshotDark' => $deployment->getAttribute('screenshotDark', ''), 'deploymentScreenshotLight' => $deployment->getAttribute('screenshotLight', ''), @@ -100,7 +100,7 @@ class Update extends Base Query::equal('trigger', 'manual'), Query::equal("type", ["deployment"]), Query::equal("deploymentResourceType", ["site"]), - Query::equal("deploymentResourceInternalId", [$site->getInternalId()]), + Query::equal("deploymentResourceInternalId", [$site->getSequence()]), ]; if (empty($oldDeploymentInternalId)) { @@ -112,7 +112,7 @@ class Update extends Base $this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { $rule = $rule ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getInternalId()); + ->setAttribute('deploymentInternalId', $deployment->getSequence()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); }); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 212b410178..85f1ee8845 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -173,8 +173,8 @@ class Update extends Base // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ - Query::equal('projectInternalId', [$project->getInternalId()]), - Query::equal('resourceInternalId', [$site->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('resourceInternalId', [$site->getSequence()]), Query::equal('resourceType', ['site']), Query::limit(100), ]); @@ -206,18 +206,18 @@ class Update extends Base Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getInternalId(), + 'installationInternalId' => $installation->getSequence(), 'projectId' => $project->getId(), - 'projectInternalId' => $project->getInternalId(), + 'projectInternalId' => $project->getSequence(), 'providerRepositoryId' => $providerRepositoryId, 'resourceId' => $site->getId(), - 'resourceInternalId' => $site->getInternalId(), + 'resourceInternalId' => $site->getSequence(), 'resourceType' => 'site', 'providerPullRequestIds' => [] ])); $repositoryId = $repository->getId(); - $repositoryInternalId = $repository->getInternalId(); + $repositoryInternalId = $repository->getSequence(); } $live = true; @@ -256,7 +256,7 @@ class Update extends Base 'buildCommand' => $buildCommand, 'outputDirectory' => $outputDirectory, 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getInternalId(), + 'installationInternalId' => $installation->getSequence(), 'providerRepositoryId' => $providerRepositoryId, 'repositoryId' => $repositoryId, 'repositoryInternalId' => $repositoryInternalId, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php index 8bf19a9c28..f8df836085 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php @@ -74,20 +74,20 @@ class Get extends Base $stats = $usage = []; $days = $periods[$range]; $metrics = [ - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), - str_replace(['{siteInternalId}'], [$site->getInternalId()], METRIC_SITES_ID_REQUESTS), - str_replace(['{siteInternalId}'], [$site->getInternalId()], METRIC_SITES_ID_INBOUND), - str_replace(['{siteInternalId}'], [$site->getInternalId()], METRIC_SITES_ID_OUTBOUND), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), + str_replace(['{siteInternalId}'], [$site->getSequence()], METRIC_SITES_ID_REQUESTS), + str_replace(['{siteInternalId}'], [$site->getSequence()], METRIC_SITES_ID_INBOUND), + str_replace(['{siteInternalId}'], [$site->getSequence()], METRIC_SITES_ID_OUTBOUND), ]; diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php index ff1a5c50ec..88da635fe4 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php @@ -85,7 +85,7 @@ class Create extends Base Permission::delete(Role::team(ID::custom($teamId), 'owner')), Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], - 'resourceInternalId' => $site->getInternalId(), + 'resourceInternalId' => $site->getSequence(), 'resourceId' => $site->getId(), 'resourceType' => 'site', 'key' => $key, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Delete.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Delete.php index e4594a7c3d..ea927be367 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Delete.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Delete.php @@ -66,7 +66,7 @@ class Delete extends Base } $variable = $dbForProject->getDocument('variables', $variableId); - if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $site->getInternalId() || $variable->getAttribute('resourceType') !== 'site') { + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $site->getSequence() || $variable->getAttribute('resourceType') !== 'site') { throw new Exception(Exception::VARIABLE_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php index a14129d432..1c25f9e701 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php @@ -68,7 +68,7 @@ class Get extends Base if ( $variable === false || $variable->isEmpty() || - $variable->getAttribute('resourceInternalId') !== $site->getInternalId() || + $variable->getAttribute('resourceInternalId') !== $site->getSequence() || $variable->getAttribute('resourceType') !== 'site' ) { throw new Exception(Exception::VARIABLE_NOT_FOUND); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Update.php index cd438a0ebb..698992f79f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Update.php @@ -77,7 +77,7 @@ class Update extends Base } $variable = $dbForProject->getDocument('variables', $variableId); - if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $site->getInternalId() || $variable->getAttribute('resourceType') !== 'site') { + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $site->getSequence() || $variable->getAttribute('resourceType') !== 'site') { throw new Exception(Exception::VARIABLE_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Action.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Action.php index 565ab7bab7..bcefaf353f 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Action.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Action.php @@ -29,9 +29,9 @@ class Action extends UtopiaAction $fileSecurity = $bucket->getAttribute('fileSecurity', false); if ($fileSecurity) { - $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); } else { - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); } if ($file->isEmpty()) { diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php index fb96849ed2..dc1e5232b6 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php @@ -94,7 +94,7 @@ class Create extends Action '$id' => ID::unique(), 'secret' => Auth::tokenGenerator(128), 'resourceId' => $bucketId . ':' . $fileId, - 'resourceInternalId' => $bucket->getInternalId() . ':' . $file->getInternalId(), + 'resourceInternalId' => $bucket->getSequence() . ':' . $file->getSequence(), 'resourceType' => TOKENS_RESOURCE_TYPE_FILES, 'expire' => $expire, ])); diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php index 38fe10e2d9..628d9b768f 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php @@ -64,7 +64,7 @@ class XList extends Action $queries = Query::parseQueries($queries); $queries[] = Query::equal('resourceType', [TOKENS_RESOURCE_TYPE_FILES]); - $queries[] = Query::equal('resourceInternalId', [$bucket->getInternalId() . ':' . $file->getInternalId()]); + $queries[] = Query::equal('resourceInternalId', [$bucket->getSequence() . ':' . $file->getSequence()]); // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); diff --git a/src/Appwrite/Platform/Tasks/ScheduleBase.php b/src/Appwrite/Platform/Tasks/ScheduleBase.php index 286ffe45cb..6d0968a804 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleBase.php +++ b/src/Appwrite/Platform/Tasks/ScheduleBase.php @@ -124,7 +124,7 @@ abstract class ScheduleBase extends Action ); return [ - '$internalId' => $schedule->getInternalId(), + '$sequence' => $schedule->getSequence(), '$id' => $schedule->getId(), 'resourceId' => $schedule->getAttribute('resourceId'), 'schedule' => $schedule->getAttribute('schedule'), @@ -175,19 +175,19 @@ abstract class ScheduleBase extends Action $total = $total + $sum; foreach ($results as $document) { - $localDocument = $this->schedules[$document->getInternalId()] ?? null; + $localDocument = $this->schedules[$document->getSequence()] ?? null; if ($localDocument !== null) { if (!$document['active']) { Console::info("Removing: {$document['resourceType']}::{$document['resourceId']}"); - unset($this->schedules[$document->getInternalId()]); + unset($this->schedules[$document->getSequence()]); } elseif (strtotime($localDocument['resourceUpdatedAt']) !== strtotime($document['resourceUpdatedAt'])) { Console::info("Updating: {$document['resourceType']}::{$document['resourceId']}"); - $this->schedules[$document->getInternalId()] = $getSchedule($document); + $this->schedules[$document->getSequence()] = $getSchedule($document); } } else { try { - $this->schedules[$document->getInternalId()] = $getSchedule($document); + $this->schedules[$document->getSequence()] = $getSchedule($document); } catch (\Throwable $th) { $collectionId = static::getCollectionId(); Console::error("Failed to load schedule for project {$document['projectId']} {$collectionId} {$document['resourceId']}"); diff --git a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php index 6bf2f93afe..27a7c1dbf1 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php +++ b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php @@ -39,7 +39,7 @@ class ScheduleExecutions extends ScheduleBase $schedule['$id'], ); - unset($this->schedules[$schedule['$internalId']]); + unset($this->schedules[$schedule['$sequence']]); continue; } @@ -81,7 +81,7 @@ class ScheduleExecutions extends ScheduleBase $schedule['$id'], ); - unset($this->schedules[$schedule['$internalId']]); + unset($this->schedules[$schedule['$sequence']]); } } } diff --git a/src/Appwrite/Platform/Tasks/ScheduleMessages.php b/src/Appwrite/Platform/Tasks/ScheduleMessages.php index 5e65f7a8a6..4d971e1b36 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleMessages.php +++ b/src/Appwrite/Platform/Tasks/ScheduleMessages.php @@ -57,7 +57,7 @@ class ScheduleMessages extends ScheduleBase ); $this->recordEnqueueDelay($scheduledAt); - unset($this->schedules[$schedule['$internalId']]); + unset($this->schedules[$schedule['$sequence']]); }); } } diff --git a/src/Appwrite/Platform/Tasks/StatsResources.php b/src/Appwrite/Platform/Tasks/StatsResources.php index ca2a6860ff..a0b5056b0f 100644 --- a/src/Appwrite/Platform/Tasks/StatsResources.php +++ b/src/Appwrite/Platform/Tasks/StatsResources.php @@ -73,7 +73,7 @@ class StatsResources extends Action $queue ->setProject($project) ->trigger(); - Console::success('project: ' . $project->getId() . '(' . $project->getInternalId() . ')' . ' queued'); + Console::success('project: ' . $project->getId() . '(' . $project->getSequence() . ')' . ' queued'); }); }, $interval); diff --git a/src/Appwrite/Platform/Workers/Audits.php b/src/Appwrite/Platform/Workers/Audits.php index 76309145b8..19ca5181ce 100644 --- a/src/Appwrite/Platform/Workers/Audits.php +++ b/src/Appwrite/Platform/Workers/Audits.php @@ -91,7 +91,7 @@ class Audits extends Action // Create event data $eventData = [ - 'userId' => $user->getInternalId(), + 'userId' => $user->getSequence(), 'event' => $event, 'resource' => $resource, 'userAgent' => $userAgent, @@ -108,13 +108,13 @@ class Audits extends Action 'timestamp' => date("Y-m-d H:i:s", $message->getTimestamp()), ]; - if (isset($this->logs[$project->getInternalId()])) { - $this->logs[$project->getInternalId()]['logs'][] = $eventData; + if (isset($this->logs[$project->getSequence()])) { + $this->logs[$project->getSequence()]['logs'][] = $eventData; } else { - $this->logs[$project->getInternalId()] = [ + $this->logs[$project->getSequence()] = [ 'project' => new Document([ '$id' => $project->getId(), - '$internalId' => $project->getInternalId(), + '$sequence' => $project->getSequence(), 'database' => $project->getAttribute('database'), ]), 'logs' => [$eventData] @@ -130,7 +130,7 @@ class Audits extends Action if ($shouldProcessBatch) { try { - foreach ($this->logs as $internalId => $projectLogs) { + foreach ($this->logs as $sequence => $projectLogs) { $dbForProject = $getProjectDB($projectLogs['project']); Console::log('Processing batch with ' . count($projectLogs['logs']) . ' events'); @@ -139,7 +139,7 @@ class Audits extends Action $audit->logBatch($projectLogs['logs']); Console::success('Audit logs processed successfully'); - unset($this->logs[$internalId]); + unset($this->logs[$sequence]); } } catch (Throwable $e) { Console::error('Error processing audit logs: ' . $e->getMessage()); diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 0dce51cb52..a9104e0017 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -255,7 +255,7 @@ class Certificates extends Action $certificate = new Document(\array_merge($certificateDocument->getArrayCopy(), $certificate->getArrayCopy())); $certificate = $dbForPlatform->updateDocument('certificates', $certificate->getId(), $certificate); } else { - $certificate->removeAttribute('$internalId'); + $certificate->removeAttribute('$sequence'); $certificate = $dbForPlatform->createDocument('certificates', $certificate); } diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index b2691b420e..8c6f6f0252 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -147,15 +147,15 @@ class Databases extends Action try { switch ($type) { case Database::VAR_RELATIONSHIP: - $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); + $relatedCollection = $dbForProject->getDocument('database_' . $database->getSequence(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { throw new DatabaseException('Collection not found'); } if ( !$dbForProject->createRelationship( - collection: 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), - relatedCollection: 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), + collection: 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), + relatedCollection: 'database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence(), type: $options['relationType'], twoWay: $options['twoWay'], id: $key, @@ -167,12 +167,12 @@ class Databases extends Action } if ($options['twoWay']) { - $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); + $relatedAttribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $options['twoWayKey']); $dbForProject->updateDocument('attributes', $relatedAttribute->getId(), $relatedAttribute->setAttribute('status', 'available')); } break; default: - if (!$dbForProject->createAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) { + if (!$dbForProject->createAttribute('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) { throw new Exception('Failed to create Attribute'); } } @@ -207,10 +207,10 @@ class Databases extends Action $this->trigger($database, $collection, $project, $event, $queueForRealtime, $attribute); if (! $relatedCollection->isEmpty()) { - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $relatedCollection->getId()); } - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); } } @@ -257,18 +257,18 @@ class Databases extends Action try { if ($type === Database::VAR_RELATIONSHIP) { if ($options['twoWay']) { - $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); + $relatedCollection = $dbForProject->getDocument('database_' . $database->getSequence(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { throw new DatabaseException('Collection not found'); } - $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); + $relatedAttribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $options['twoWayKey']); } - if (!$dbForProject->deleteRelationship('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { + if (!$dbForProject->deleteRelationship('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $key)) { $dbForProject->updateDocument('attributes', $relatedAttribute->getId(), $relatedAttribute->setAttribute('status', 'stuck')); throw new DatabaseException('Failed to delete Relationship'); } - } elseif (!$dbForProject->deleteAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { + } elseif (!$dbForProject->deleteAttribute('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $key)) { throw new DatabaseException('Failed to delete Attribute'); } @@ -365,10 +365,10 @@ class Databases extends Action } } } finally { - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); if (! $relatedCollection->isEmpty()) { - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $relatedCollection->getId()); } } } @@ -408,7 +408,7 @@ class Databases extends Action $project = $dbForPlatform->getDocument('projects', $projectId); try { - if (!$dbForProject->createIndex('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $attributes, $lengths, $orders)) { + if (!$dbForProject->createIndex('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $key, $type, $attributes, $lengths, $orders)) { throw new DatabaseException('Failed to create Index'); } $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); @@ -426,7 +426,7 @@ class Databases extends Action throw $e; } finally { $this->trigger($database, $collection, $project, $event, $queueForRealtime, null, $index); - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); } } @@ -461,7 +461,7 @@ class Databases extends Action $project = $dbForPlatform->getDocument('projects', $projectId); try { - if ($status !== 'failed' && !$dbForProject->deleteIndex('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { + if ($status !== 'failed' && !$dbForProject->deleteIndex('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $key)) { throw new DatabaseException('Failed to delete index'); } $dbForProject->deleteDocument('indexes', $index->getId()); @@ -482,7 +482,7 @@ class Databases extends Action } finally { $this->trigger($database, $collection, $project, $event, $queueForRealtime, null, $index); - $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collection->getId()); + $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collection->getId()); } } @@ -495,11 +495,11 @@ class Databases extends Action */ protected function deleteDatabase(Document $database, Document $project, $dbForProject): void { - $this->deleteByGroup('database_' . $database->getInternalId(), [], $dbForProject, function ($collection) use ($database, $project, $dbForProject) { + $this->deleteByGroup('database_' . $database->getSequence(), [], $dbForProject, function ($collection) use ($database, $project, $dbForProject) { $this->deleteCollection($database, $collection, $project, $dbForProject); }); - $dbForProject->deleteCollection('database_' . $database->getInternalId()); + $dbForProject->deleteCollection('database_' . $database->getSequence()); } /** @@ -522,10 +522,10 @@ class Databases extends Action } $collectionId = $collection->getId(); - $collectionInternalId = $collection->getInternalId(); - $databaseInternalId = $database->getInternalId(); + $collectionInternalId = $collection->getSequence(); + $databaseInternalId = $database->getSequence(); - $dbForProject->deleteCollection('database_' . $databaseInternalId . '_collection_' . $collection->getInternalId()); + $dbForProject->deleteCollection('database_' . $databaseInternalId . '_collection_' . $collection->getSequence()); /** * Related collections relating to current collection diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 43bc55583d..8ed96c76a2 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -34,7 +34,7 @@ use Utopia\System\System; class Deletes extends Action { - protected array $selects = ['$internalId', '$id', '$collection', '$permissions', '$updatedAt']; + protected array $selects = ['$sequence', '$id', '$collection', '$permissions', '$updatedAt']; public static function getName(): string { @@ -277,7 +277,7 @@ class Deletes extends Action $this->deleteByGroup( 'subscribers', [ - Query::equal('topicInternalId', [$topic->getInternalId()]), + Query::equal('topicInternalId', [$topic->getSequence()]), Query::orderAsc(), ], $getProjectDB($project) @@ -298,7 +298,7 @@ class Deletes extends Action private function deleteSessionTargets(Document $project, callable $getProjectDB, Document $session): void { - Targets::delete($getProjectDB($project), Query::equal('sessionInternalId', [$session->getInternalId()])); + Targets::delete($getProjectDB($project), Query::equal('sessionInternalId', [$session->getSequence()])); } /** @@ -434,7 +434,7 @@ class Deletes extends Action public function deleteMemberships(callable $getProjectDB, Document $document, Document $project): void { $dbForProject = $getProjectDB($project); - $teamInternalId = $document->getInternalId(); + $teamInternalId = $document->getSequence(); // Delete Memberships $this->deleteByGroup( @@ -466,7 +466,7 @@ class Deletes extends Action { $projects = $dbForPlatform->find('projects', [ - Query::equal('teamInternalId', [$document->getInternalId()]), + Query::equal('teamInternalId', [$document->getSequence()]), Query::equal('region', [System::getEnv('_APP_REGION', 'default')]) ]); @@ -497,7 +497,7 @@ class Deletes extends Action */ private function deleteProject(Database $dbForPlatform, callable $getProjectDB, Device $deviceForFiles, Device $deviceForSites, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, Document $document): void { - $projectInternalId = $document->getInternalId(); + $projectInternalId = $document->getSequence(); $projectId = $document->getId(); try { @@ -637,7 +637,7 @@ class Deletes extends Action private function deleteUser(callable $getProjectDB, Document $document, Document $project): void { $userId = $document->getId(); - $userInternalId = $document->getInternalId(); + $userInternalId = $document->getSequence(); $dbForProject = $getProjectDB($project); // Delete all sessions of this user from the sessions table and update the sessions field of the user record @@ -769,7 +769,7 @@ class Deletes extends Action { $dbForProject = $getProjectDB($project); $siteId = $document->getId(); - $siteInternalId = $document->getInternalId(); + $siteInternalId = $document->getSequence(); /** * Delete rules for site @@ -779,7 +779,7 @@ class Deletes extends Action Query::equal('type', ['deployment']), Query::equal('deploymentResourceType', ['site']), Query::equal('deploymentResourceInternalId', [$siteInternalId]), - Query::equal('projectInternalId', [$project->getInternalId()]) + Query::equal('projectInternalId', [$project->getSequence()]) ], $dbForPlatform, function (Document $document) use ($dbForPlatform, $certificates) { $this->deleteRule($dbForPlatform, $document, $certificates); }); @@ -804,7 +804,7 @@ class Deletes extends Action Query::equal('resourceType', ['site']), Query::orderAsc() ], $dbForProject, function (Document $document) use ($project, $certificates, $deviceForSites, $deviceForBuilds, $deviceForFiles, $dbForPlatform, &$deploymentInternalIds) { - $deploymentInternalIds[] = $document->getInternalId(); + $deploymentInternalIds[] = $document->getSequence(); $deploymentIds[] = $document->getId(); $this->deleteBuildFiles($deviceForBuilds, $document); $this->deleteDeploymentFiles($deviceForSites, $document); @@ -827,7 +827,7 @@ class Deletes extends Action */ Console::info("Deleting VCS repositories and comments linked to site " . $siteId); $this->deleteByGroup('repositories', [ - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), Query::equal('resourceInternalId', [$siteInternalId]), Query::equal('resourceType', ['site']), ], $dbForPlatform, function (Document $document) use ($dbForPlatform) { @@ -855,7 +855,7 @@ class Deletes extends Action $projectId = $project->getId(); $dbForProject = $getProjectDB($project); $functionId = $document->getId(); - $functionInternalId = $document->getInternalId(); + $functionInternalId = $document->getSequence(); /** * Delete rules @@ -865,7 +865,7 @@ class Deletes extends Action Query::equal('type', ['deployment']), Query::equal('deploymentResourceType', ['function']), Query::equal('deploymentResourceInternalId', [$functionInternalId]), - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), Query::orderAsc() ], $dbForPlatform, function (Document $document) use ($project, $dbForPlatform, $certificates) { $this->deleteRule($dbForPlatform, $document, $certificates); @@ -892,7 +892,7 @@ class Deletes extends Action Query::equal('resourceType', ['function']), Query::orderAsc() ], $dbForProject, function (Document $document) use ($dbForPlatform, $project, $certificates, $deviceForFunctions, $deviceForBuilds, &$deploymentInternalIds) { - $deploymentInternalIds[] = $document->getInternalId(); + $deploymentInternalIds[] = $document->getSequence(); $this->deleteDeploymentFiles($deviceForFunctions, $document); $this->deleteBuildFiles($deviceForBuilds, $document); }); @@ -913,7 +913,7 @@ class Deletes extends Action */ Console::info("Deleting VCS repositories and comments linked to function " . $functionId); $this->deleteByGroup('repositories', [ - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), Query::equal('resourceInternalId', [$functionInternalId]), Query::equal('resourceType', ['function']), Query::orderAsc() @@ -957,7 +957,7 @@ class Deletes extends Action } foreach ($screenshotIds as $id) { - $file = ValidatorAuthorization::skip(fn () => $dbForPlatform->getDocument('bucket_' . $bucket->getInternalId(), $id)); + $file = ValidatorAuthorization::skip(fn () => $dbForPlatform->getDocument('bucket_' . $bucket->getSequence(), $id)); if ($file->isEmpty()) { Console::error('Failed to get deployment screenshot: ' . $id); @@ -1060,7 +1060,7 @@ class Deletes extends Action $projectId = $project->getId(); $dbForProject = $getProjectDB($project); $deploymentId = $document->getId(); - $deploymentInternalId = $document->getInternalId(); + $deploymentInternalId = $document->getSequence(); /** * Delete deployment files @@ -1089,7 +1089,7 @@ class Deletes extends Action Query::equal('trigger', ['deployment']), Query::equal('type', ['deployment']), Query::equal('deploymentInternalId', [$deploymentInternalId]), - Query::equal('projectInternalId', [$project->getInternalId()]) + Query::equal('projectInternalId', [$project->getSequence()]) ], $dbForPlatform, function (Document $document) use ($dbForPlatform, $certificates) { $this->deleteRule($dbForPlatform, $document, $certificates); }); @@ -1211,7 +1211,7 @@ class Deletes extends Action { $dbForProject = $getProjectDB($project); - $dbForProject->deleteCollection('bucket_' . $document->getInternalId()); + $dbForProject->deleteCollection('bucket_' . $document->getSequence()); $deviceForFiles->deletePath($document->getId()); } @@ -1229,7 +1229,7 @@ class Deletes extends Action $dbForProject = $getProjectDB($project); $this->listByGroup('functions', [ - Query::equal('installationInternalId', [$document->getInternalId()]) + Query::equal('installationInternalId', [$document->getSequence()]) ], $dbForProject, function ($function) use ($dbForProject, $dbForPlatform) { $dbForPlatform->deleteDocument('repositories', $function->getAttribute('repositoryId')); @@ -1260,7 +1260,7 @@ class Deletes extends Action $this->listByGroup( 'deployments', [ - Query::equal('resourceInternalId', [$function->getInternalId()]), + Query::equal('resourceInternalId', [$function->getSequence()]), Query::equal('resourceType', ['functions']), ], $getProjectDB($project), diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index c8c68a58ba..a9126583ce 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -280,7 +280,7 @@ class Functions extends Action $execution = new Document([ '$id' => $executionId, '$permissions' => $user->isEmpty() ? [] : [Permission::read(Role::user($user->getId()))], - 'resourceInternalId' => $function->getInternalId(), + 'resourceInternalId' => $function->getSequence(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', 'deploymentInternalId' => '', @@ -420,10 +420,10 @@ class Functions extends Action $execution = new Document([ '$id' => $executionId, '$permissions' => $user->isEmpty() ? [] : [Permission::read(Role::user($user->getId()))], - 'resourceInternalId' => $function->getInternalId(), + 'resourceInternalId' => $function->getSequence(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', - 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentInternalId' => $deployment->getSequence(), 'deploymentId' => $deployment->getId(), 'trigger' => $trigger, 'status' => 'processing', @@ -572,13 +572,13 @@ class Functions extends Action ->setProject($project) ->addMetric(METRIC_EXECUTIONS, 1) ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS), 1) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000))// per project ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->trigger() ; } diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index 8491e91a6c..2ee107a319 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -373,7 +373,7 @@ class Messaging extends Action throw new \Exception('Storage bucket with the requested ID could not be found'); } - $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); if ($file->isEmpty()) { throw new \Exception('Storage file with the requested ID could not be found'); } @@ -558,7 +558,7 @@ class Messaging extends Action throw new \Exception('Storage bucket with the requested ID could not be found'); } - $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); if ($file->isEmpty()) { throw new \Exception('Storage file with the requested ID could not be found'); } diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index b746365f20..395ec1351e 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -368,7 +368,7 @@ class Migrations extends Action $this->updateMigrationDocument($migration, $projectDocument, $queueForRealtime); if ($migration->getAttribute('status', '') === 'failed') { - Console::error('Migration('.$migration->getInternalId().':'.$migration->getId().') failed, Project('.$this->project->getInternalId().':'.$this->project->getId().')'); + Console::error('Migration('.$migration->getSequence().':'.$migration->getId().') failed, Project('.$this->project->getSequence().':'.$this->project->getId().')'); if ($destination) { $destination->error(); diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index 19d1223d95..c68465f8df 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -80,7 +80,7 @@ class StatsResources extends Action $this->countForProject($dbForPlatform, $getLogsDB, $getProjectDB, $project); $endTime = microtime(true); $executionTime = $endTime - $startTime; - Console::info('Project: ' . $project->getId() . '(' . $project->getInternalId() . ') aggregated in ' . $executionTime .' seconds'); + Console::info('Project: ' . $project->getId() . '(' . $project->getSequence() . ') aggregated in ' . $executionTime .' seconds'); } protected function countForProject(Database $dbForPlatform, callable $getLogsDB, callable $getProjectDB, Document $project): void @@ -105,17 +105,17 @@ class StatsResources extends Action $region = $project->getAttribute('region'); $platforms = $dbForPlatform->count('platforms', [ - Query::equal('projectInternalId', [$project->getInternalId()]) + Query::equal('projectInternalId', [$project->getSequence()]) ]); $webhooks = $dbForPlatform->count('webhooks', [ - Query::equal('projectInternalId', [$project->getInternalId()]) + Query::equal('projectInternalId', [$project->getSequence()]) ]); $keys = $dbForPlatform->count('keys', [ - Query::equal('projectInternalId', [$project->getInternalId()]) + Query::equal('projectInternalId', [$project->getSequence()]) ]); $domains = $dbForPlatform->count('rules', [ - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), Query::equal('owner', ['']), ]); @@ -216,13 +216,13 @@ class StatsResources extends Action $totalFiles = 0; $totalStorage = 0; $this->foreachDocument($dbForProject, 'buckets', [], function ($bucket) use ($dbForProject, $dbForLogs, $region, &$totalFiles, &$totalStorage) { - $files = $dbForProject->count('bucket_' . $bucket->getInternalId()); + $files = $dbForProject->count('bucket_' . $bucket->getSequence()); - $metric = str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES); + $metric = str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES); $this->createStatsDocuments($region, $metric, $files); - $storage = $dbForProject->sum('bucket_' . $bucket->getInternalId(), 'sizeActual'); - $metric = str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES_STORAGE); + $storage = $dbForProject->sum('bucket_' . $bucket->getSequence(), 'sizeActual'); + $metric = str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES_STORAGE); $this->createStatsDocuments($region, $metric, $storage); $totalStorage += $storage; @@ -241,10 +241,10 @@ class StatsResources extends Action $totalImageTransformations = 0; $last30Days = (new \DateTime())->sub(\DateInterval::createFromDateString('30 days'))->format('Y-m-d 00:00:00'); $this->foreachDocument($dbForProject, 'buckets', [], function ($bucket) use ($dbForProject, $last30Days, $region, &$totalImageTransformations) { - $imageTransformations = $dbForProject->count('bucket_' . $bucket->getInternalId(), [ + $imageTransformations = $dbForProject->count('bucket_' . $bucket->getSequence(), [ Query::greaterThanEqual('transformedAt', $last30Days), ]); - $metric = str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES_IMAGES_TRANSFORMED); + $metric = str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES_IMAGES_TRANSFORMED); $this->createStatsDocuments($region, $metric, $imageTransformations); $totalImageTransformations += $imageTransformations; }); @@ -260,9 +260,9 @@ class StatsResources extends Action $totalDatabaseStorage = 0; $this->foreachDocument($dbForProject, 'databases', [], function ($database) use ($dbForProject, $region, &$totalCollections, &$totalDocuments, &$totalDatabaseStorage) { - $collections = $dbForProject->count('database_' . $database->getInternalId()); + $collections = $dbForProject->count('database_' . $database->getSequence()); - $metric = str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_COLLECTIONS); + $metric = str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_COLLECTIONS); $this->createStatsDocuments($region, $metric, $collections); [$documents, $storage] = $this->countForCollections($dbForProject, $database, $region); @@ -280,23 +280,23 @@ class StatsResources extends Action { $databaseDocuments = 0; $databaseStorage = 0; - $this->foreachDocument($dbForProject, 'database_' . $database->getInternalId(), [], function ($collection) use ($dbForProject, $database, $region, &$databaseStorage, &$databaseDocuments) { - $documents = $dbForProject->count('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); - $metric = str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$database->getInternalId(), $collection->getInternalId()], METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS); + $this->foreachDocument($dbForProject, 'database_' . $database->getSequence(), [], function ($collection) use ($dbForProject, $database, $region, &$databaseStorage, &$databaseDocuments) { + $documents = $dbForProject->count('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); + $metric = str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$database->getSequence(), $collection->getSequence()], METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS); $this->createStatsDocuments($region, $metric, $documents); $databaseDocuments += $documents; - $collectionStorage = $dbForProject->getSizeOfCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); - $metric = str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$database->getInternalId(), $collection->getInternalId()], METRIC_DATABASE_ID_COLLECTION_ID_STORAGE); + $collectionStorage = $dbForProject->getSizeOfCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); + $metric = str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$database->getSequence(), $collection->getSequence()], METRIC_DATABASE_ID_COLLECTION_ID_STORAGE); $this->createStatsDocuments($region, $metric, $collectionStorage); $databaseStorage += $collectionStorage; }); - $metric = str_replace(['{databaseInternalId}'], [$database->getInternalId()], METRIC_DATABASE_ID_DOCUMENTS); + $metric = str_replace(['{databaseInternalId}'], [$database->getSequence()], METRIC_DATABASE_ID_DOCUMENTS); $this->createStatsDocuments($region, $metric, $databaseDocuments); - $metric = str_replace(['{databaseInternalId}'], [$database->getInternalId()], METRIC_DATABASE_ID_STORAGE); + $metric = str_replace(['{databaseInternalId}'], [$database->getSequence()], METRIC_DATABASE_ID_STORAGE); $this->createStatsDocuments($region, $metric, $databaseStorage); return [$databaseDocuments, $databaseStorage]; @@ -337,33 +337,33 @@ class StatsResources extends Action $this->foreachDocument($dbForProject, 'functions', [], function (Document $function) use ($dbForProject, $region) { $functionDeploymentsStorage = $dbForProject->sum('deployments', 'sourceSize', [ - Query::equal('resourceInternalId', [$function->getInternalId()]), + Query::equal('resourceInternalId', [$function->getSequence()]), Query::equal('resourceType', [RESOURCE_TYPE_FUNCTIONS]), ]); - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), $functionDeploymentsStorage); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), $functionDeploymentsStorage); $functionDeployments = $dbForProject->count('deployments', [ - Query::equal('resourceInternalId', [$function->getInternalId()]), + Query::equal('resourceInternalId', [$function->getSequence()]), Query::equal('resourceType', [RESOURCE_TYPE_FUNCTIONS]), ]); - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), $functionDeployments); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), $functionDeployments); /** * As deployments and builds have 1-1 relationship, * the count for one should match the other */ - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), $functionDeployments); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS), $functionDeployments); $functionBuildsStorage = 0; $this->foreachDocument($dbForProject, 'deployments', [ - Query::equal('resourceInternalId', [$function->getInternalId()]), + Query::equal('resourceInternalId', [$function->getSequence()]), Query::equal('resourceType', [RESOURCE_TYPE_FUNCTIONS]), ], function (Document $deployment) use (&$functionBuildsStorage): void { $functionBuildsStorage += $deployment->getAttribute('buildSize', 0); }); - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $functionBuildsStorage); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $functionBuildsStorage); }); } @@ -387,29 +387,29 @@ class StatsResources extends Action $this->foreachDocument($dbForProject, 'sites', [], function (Document $site) use ($dbForProject, $region) { $siteDeploymentsStorage = $dbForProject->sum('deployments', 'sourceSize', [ - Query::equal('resourceInternalId', [$site->getInternalId()]), + Query::equal('resourceInternalId', [$site->getSequence()]), Query::equal('resourceType', [RESOURCE_TYPE_SITES]), ]); - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), $siteDeploymentsStorage); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), $siteDeploymentsStorage); $siteDeployments = $dbForProject->count('deployments', [ - Query::equal('resourceInternalId', [$site->getInternalId()]), + Query::equal('resourceInternalId', [$site->getSequence()]), Query::equal('resourceType', [RESOURCE_TYPE_SITES]), ]); - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), $siteDeployments); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), $siteDeployments); /** * As deployments and builds have 1-1 relationship, * the count for one should match the other */ - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), $siteDeployments); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS), $siteDeployments); $siteBuildsStorage = $dbForProject->sum('deployments', 'buildSize', [ - Query::equal('resourceInternalId', [$site->getInternalId()]), + Query::equal('resourceInternalId', [$site->getSequence()]), Query::equal('resourceType', [RESOURCE_TYPE_SITES]), ]); - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $siteBuildsStorage); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $siteBuildsStorage); }); } @@ -437,6 +437,6 @@ class StatsResources extends Action $this->documents ); $this->documents = []; - Console::success('Stats written to logs db for project: ' . $project->getId() . '(' . $project->getInternalId() . ')'); + Console::success('Stats written to logs db for project: ' . $project->getId() . '(' . $project->getSequence() . ')'); } } diff --git a/src/Appwrite/Platform/Workers/StatsUsage.php b/src/Appwrite/Platform/Workers/StatsUsage.php index 25c80fabdc..59b5a15ada 100644 --- a/src/Appwrite/Platform/Workers/StatsUsage.php +++ b/src/Appwrite/Platform/Workers/StatsUsage.php @@ -145,7 +145,7 @@ class StatsUsage extends Action $aggregationInterval = (int) System::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', '20'); $project = new Document($payload['project'] ?? []); - $projectId = $project->getInternalId(); + $projectId = $project->getSequence(); foreach ($payload['reduce'] ?? [] as $document) { if (empty($document)) { continue; @@ -211,8 +211,8 @@ class StatsUsage extends Action } break; case $document->getCollection() === 'databases': // databases - $collections = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{databaseInternalId}', $document->getInternalId(), METRIC_DATABASE_ID_COLLECTIONS))); - $documents = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{databaseInternalId}', $document->getInternalId(), METRIC_DATABASE_ID_DOCUMENTS))); + $collections = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{databaseInternalId}', $document->getSequence(), METRIC_DATABASE_ID_COLLECTIONS))); + $documents = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{databaseInternalId}', $document->getSequence(), METRIC_DATABASE_ID_DOCUMENTS))); if (!empty($collections['value'])) { $metrics[] = [ 'key' => METRIC_COLLECTIONS, @@ -232,7 +232,7 @@ class StatsUsage extends Action $databaseInternalId = $parts[1] ?? 0; $documents = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace( ['{databaseInternalId}', '{collectionInternalId}'], - [$databaseInternalId, $document->getInternalId()], + [$databaseInternalId, $document->getSequence()], METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS ))); @@ -249,8 +249,8 @@ class StatsUsage extends Action break; case $document->getCollection() === 'buckets': - $files = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getInternalId(), METRIC_BUCKET_ID_FILES))); - $storage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getInternalId(), METRIC_BUCKET_ID_FILES_STORAGE))); + $files = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getSequence(), METRIC_BUCKET_ID_FILES))); + $storage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getSequence(), METRIC_BUCKET_ID_FILES_STORAGE))); if (!empty($files['value'])) { $metrics[] = [ @@ -268,13 +268,13 @@ class StatsUsage extends Action break; case $document->getCollection() === 'functions' || $document->getCollection() === 'sites': - $deployments = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS))); - $deploymentsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE))); - $builds = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS))); - $buildsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE))); - $buildsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE))); - $executions = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS))); - $executionsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE))); + $deployments = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS))); + $deploymentsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE))); + $builds = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS))); + $buildsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE))); + $buildsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE))); + $executions = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS))); + $executionsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE))); if (!empty($deployments['value'])) { $metrics[] = [ @@ -357,7 +357,7 @@ class StatsUsage extends Action break; } } catch (Throwable $e) { - Console::error("[reducer] " . " {DateTime::now()} " . " {$project->getInternalId()} " . " {$e->getMessage()}"); + Console::error("[reducer] " . " {DateTime::now()} " . " {$project->getSequence()} " . " {$e->getMessage()}"); } } @@ -376,7 +376,7 @@ class StatsUsage extends Action continue; } - Console::log('['.DateTime::now().'] Id: '.$project->getId(). ' InternalId: '.$project->getInternalId(). ' Db: '.$project->getAttribute('database').' ReceivedAt: '.$receivedAt. ' Keys: '.$numberOfKeys); + Console::log('['.DateTime::now().'] Id: '.$project->getId(). ' InternalId: '.$project->getSequence(). ' Db: '.$project->getAttribute('database').' ReceivedAt: '.$receivedAt. ' Keys: '.$numberOfKeys); try { foreach ($stats['keys'] ?? [] as $key => $value) { @@ -402,23 +402,23 @@ class StatsUsage extends Action ]); - $this->projects[$project->getInternalId()]['project'] = new Document([ + $this->projects[$project->getSequence()]['project'] = new Document([ '$id' => $project->getId(), - '$internalId' => $project->getInternalId(), + '$sequence' => $project->getSequence(), 'database' => $project->getAttribute('database'), ]); - $this->projects[$project->getInternalId()]['stats'][] = $document; + $this->projects[$project->getSequence()]['stats'][] = $document; $this->prepareForLogsDB($project, $document); } } } catch (Exception $e) { - Console::error('[' . DateTime::now() . '] project [' . $project->getInternalId() . '] database [' . $project['database'] . '] ' . ' ' . $e->getMessage()); + Console::error('[' . DateTime::now() . '] project [' . $project->getSequence() . '] database [' . $project['database'] . '] ' . ' ' . $e->getMessage()); } } - foreach ($this->projects as $internalId => $projectStats) { - if (empty($internalId)) { + foreach ($this->projects as $sequence => $projectStats) { + if (empty($sequence)) { continue; } try { @@ -427,7 +427,7 @@ class StatsUsage extends Action $dbForProject->createOrUpdateDocumentsWithIncrease('stats', 'value', $projectStats['stats']); Console::success('Batch successfully written to DB'); - unset($this->projects[$internalId]); + unset($this->projects[$sequence]); } catch (Throwable $e) { Console::error('Error processing stats: ' . $e->getMessage()); } @@ -451,7 +451,7 @@ class StatsUsage extends Action } } $documentClone = clone $stat; - $documentClone->setAttribute('$tenant', (int) $project->getInternalId()); + $documentClone->setAttribute('$tenant', (int) $project->getSequence()); $this->statDocuments[] = $documentClone; } diff --git a/src/Appwrite/Platform/Workers/StatsUsageDump.php b/src/Appwrite/Platform/Workers/StatsUsageDump.php index 77ec3f13e6..7c2da8fd4d 100644 --- a/src/Appwrite/Platform/Workers/StatsUsageDump.php +++ b/src/Appwrite/Platform/Workers/StatsUsageDump.php @@ -126,7 +126,7 @@ class StatsUsageDump extends Action continue; } - Console::log('['.DateTime::now().'] Id: '.$project->getId(). ' InternalId: '.$project->getInternalId(). ' Db: '.$project->getAttribute('database').' ReceivedAt: '.$receivedAt. ' Keys: '.$numberOfKeys); + Console::log('['.DateTime::now().'] Id: '.$project->getId(). ' InternalId: '.$project->getSequence(). ' Db: '.$project->getAttribute('database').' ReceivedAt: '.$receivedAt. ' Keys: '.$numberOfKeys); try { /** @var Database $dbForProject */ @@ -169,7 +169,7 @@ class StatsUsageDump extends Action } } } catch (\Exception $e) { - Console::error('[' . DateTime::now() . '] project [' . $project->getInternalId() . '] database [' . $project['database'] . '] ' . ' ' . $e->getMessage()); + Console::error('[' . DateTime::now() . '] project [' . $project->getSequence() . '] database [' . $project['database'] . '] ' . ' ' . $e->getMessage()); } } } diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index ada4d6faaa..4c081aaa13 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -176,7 +176,7 @@ class Webhooks extends Action $this->errors[] = $logs; $queueForStatsUsage ->addMetric(METRIC_WEBHOOKS_FAILED, 1) - ->addMetric(str_replace('{webhookInternalId}', $webhook->getInternalId(), METRIC_WEBHOOK_ID_FAILED), 1) + ->addMetric(str_replace('{webhookInternalId}', $webhook->getSequence(), METRIC_WEBHOOK_ID_FAILED), 1) ; @@ -186,7 +186,7 @@ class Webhooks extends Action $dbForPlatform->purgeCachedDocument('projects', $project->getId()); $queueForStatsUsage ->addMetric(METRIC_WEBHOOKS_SENT, 1) - ->addMetric(str_replace('{webhookInternalId}', $webhook->getInternalId(), METRIC_WEBHOOK_ID_SENT), 1) + ->addMetric(str_replace('{webhookInternalId}', $webhook->getSequence(), METRIC_WEBHOOK_ID_SENT), 1) ; } diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php index e8eafba5a0..20e7d5cb93 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php @@ -71,8 +71,8 @@ class Base extends Queries 'array' => false, ]); - $internalId = new Document([ - 'key' => '$internalId', + $sequence = new Document([ + 'key' => '$sequence', 'type' => Database::VAR_STRING, 'array' => false, ]); @@ -82,7 +82,7 @@ class Base extends Queries new Offset(), new Cursor(), new Filter($attributes, APP_DATABASE_QUERY_MAX_VALUES), - new Order([...$attributes, $internalId]), + new Order([...$attributes, $sequence]), ]; parent::__construct($validators); diff --git a/src/Appwrite/Utopia/Response/Model/Document.php b/src/Appwrite/Utopia/Response/Model/Document.php index 41a10cee89..c4f7eb3044 100644 --- a/src/Appwrite/Utopia/Response/Model/Document.php +++ b/src/Appwrite/Utopia/Response/Model/Document.php @@ -71,7 +71,7 @@ class Document extends Any public function filter(DatabaseDocument $document): DatabaseDocument { - $document->removeAttribute('$internalId'); + $document->removeAttribute('$sequence'); $document->removeAttribute('$collection'); $document->removeAttribute('$tenant'); diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 7c0060ecaa..8f59575f79 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -2003,9 +2003,9 @@ trait DatabasesBase $this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']); $this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']); $this->assertEquals(2019, $documents['body']['documents'][2]['releaseYear']); - $this->assertFalse(array_key_exists('$internalId', $documents['body']['documents'][0])); - $this->assertFalse(array_key_exists('$internalId', $documents['body']['documents'][1])); - $this->assertFalse(array_key_exists('$internalId', $documents['body']['documents'][2])); + $this->assertFalse(array_key_exists('$sequence', $documents['body']['documents'][0])); + $this->assertFalse(array_key_exists('$sequence', $documents['body']['documents'][1])); + $this->assertFalse(array_key_exists('$sequence', $documents['body']['documents'][2])); $this->assertCount(3, $documents['body']['documents']); foreach ($documents['body']['documents'] as $document) { @@ -2098,7 +2098,7 @@ trait DatabasesBase $this->assertEquals($response['body']['releaseYear'], $document['releaseYear']); $this->assertEquals($response['body']['$permissions'], $document['$permissions']); $this->assertEquals($response['body']['birthDay'], $document['birthDay']); - $this->assertFalse(array_key_exists('$internalId', $response['body'])); + $this->assertFalse(array_key_exists('$sequence', $response['body'])); $this->assertFalse(array_key_exists('$tenant', $response['body'])); } } @@ -4361,8 +4361,8 @@ trait DatabasesBase $this->assertArrayNotHasKey('$collection', $person1['body']); $this->assertArrayNotHasKey('$collection', $person1['body']['library']); - $this->assertArrayNotHasKey('$internalId', $person1['body']); - $this->assertArrayNotHasKey('$internalId', $person1['body']['library']); + $this->assertArrayNotHasKey('$sequence', $person1['body']); + $this->assertArrayNotHasKey('$sequence', $person1['body']['library']); $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $person['body']['$id'] . '/documents', array_merge([ 'content-type' => 'application/json', From f6bf7791199364b6ae38494706ccf186e7bc09bc Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 23 May 2025 02:57:11 +1200 Subject: [PATCH 09/31] Update database --- composer.json | 2 +- composer.lock | 61 +++++++++++++++++++++++++++++---------------------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/composer.json b/composer.json index 7e445cd36b..9a3c9e8319 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,7 @@ "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", "utopia-php/detector": "0.1.*", - "utopia-php/database": "0.69.*", + "utopia-php/database": "dev-feat-internal-to-sequence as 0.69.5", "utopia-php/domains": "0.8.0", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index f36b815777..1d84acbb43 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9f5de64d73e2ef73d796fa64f2baf232", + "content-hash": "cb47e05e104d978efba67c3ccc7bf959", "packages": [ { "name": "adhocore/jwt", @@ -1238,16 +1238,16 @@ }, { "name": "open-telemetry/exporter-otlp", - "version": "1.3.0", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/opentelemetry-php/exporter-otlp.git", - "reference": "19adf03d2b0f91f9e9b1c7f93db6c755c737cf6c" + "reference": "8b3ca1f86d01429c73b407bf1a2075d9c187001e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opentelemetry-php/exporter-otlp/zipball/19adf03d2b0f91f9e9b1c7f93db6c755c737cf6c", - "reference": "19adf03d2b0f91f9e9b1c7f93db6c755c737cf6c", + "url": "https://api.github.com/repos/opentelemetry-php/exporter-otlp/zipball/8b3ca1f86d01429c73b407bf1a2075d9c187001e", + "reference": "8b3ca1f86d01429c73b407bf1a2075d9c187001e", "shasum": "" }, "require": { @@ -1298,7 +1298,7 @@ "issues": "https://github.com/open-telemetry/opentelemetry-php/issues", "source": "https://github.com/open-telemetry/opentelemetry-php" }, - "time": "2025-05-12T00:36:35+00:00" + "time": "2025-05-21T12:02:20+00:00" }, { "name": "open-telemetry/gen-otlp-protobuf", @@ -1365,16 +1365,16 @@ }, { "name": "open-telemetry/sdk", - "version": "1.4.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/opentelemetry-php/sdk.git", - "reference": "939d3a28395c249a763676458140dad44b3a8011" + "reference": "cd0d7367599717fc29e04eb8838ec061e6c2c657" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opentelemetry-php/sdk/zipball/939d3a28395c249a763676458140dad44b3a8011", - "reference": "939d3a28395c249a763676458140dad44b3a8011", + "url": "https://api.github.com/repos/opentelemetry-php/sdk/zipball/cd0d7367599717fc29e04eb8838ec061e6c2c657", + "reference": "cd0d7367599717fc29e04eb8838ec061e6c2c657", "shasum": "" }, "require": { @@ -1451,7 +1451,7 @@ "issues": "https://github.com/open-telemetry/opentelemetry-php/issues", "source": "https://github.com/open-telemetry/opentelemetry-php" }, - "time": "2025-05-07T12:32:21+00:00" + "time": "2025-05-22T02:33:34+00:00" }, { "name": "open-telemetry/sem-conv", @@ -3499,16 +3499,16 @@ }, { "name": "utopia-php/database", - "version": "0.69.5", + "version": "dev-feat-internal-to-sequence", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "4abe53609dfc23b2ea82884d12b149df6a8af2f5" + "reference": "0f3617e23bef7c6f260d7f8f194031c2f096a154" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/4abe53609dfc23b2ea82884d12b149df6a8af2f5", - "reference": "4abe53609dfc23b2ea82884d12b149df6a8af2f5", + "url": "https://api.github.com/repos/utopia-php/database/zipball/0f3617e23bef7c6f260d7f8f194031c2f096a154", + "reference": "0f3617e23bef7c6f260d7f8f194031c2f096a154", "shasum": "" }, "require": { @@ -3549,9 +3549,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.69.5" + "source": "https://github.com/utopia-php/database/tree/feat-internal-to-sequence" }, - "time": "2025-05-17T08:01:51+00:00" + "time": "2025-05-22T13:09:40+00:00" }, { "name": "utopia-php/detector", @@ -4816,16 +4816,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.40.17", + "version": "0.40.18", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "7e333c1003bfd4763e4d6f3a0a799fde5e7bc4de" + "reference": "38de4b9c58112d7e83eb75955994c8412a401093" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/7e333c1003bfd4763e4d6f3a0a799fde5e7bc4de", - "reference": "7e333c1003bfd4763e4d6f3a0a799fde5e7bc4de", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/38de4b9c58112d7e83eb75955994c8412a401093", + "reference": "38de4b9c58112d7e83eb75955994c8412a401093", "shasum": "" }, "require": { @@ -4861,9 +4861,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.40.17" + "source": "https://github.com/appwrite/sdk-generator/tree/0.40.18" }, - "time": "2025-05-16T15:10:54+00:00" + "time": "2025-05-21T14:14:47+00:00" }, { "name": "doctrine/annotations", @@ -8240,9 +8240,18 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-feat-internal-to-sequence", + "alias": "0.69.5", + "alias_normalized": "0.69.5.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -8266,5 +8275,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } From b4f5af8461f447fe3b544e72b02b3eba56f92dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 22 May 2025 17:25:47 +0200 Subject: [PATCH 10/31] Fix: unlimited deployment size --- .../Platform/Modules/Functions/Http/Deployments/Create.php | 2 +- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 4 ++-- .../Platform/Modules/Sites/Http/Deployments/Create.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php index cda6dc38bf..1f3febbfef 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php @@ -182,7 +182,7 @@ class Create extends Action } } - if (!$fileSizeValidator->isValid($fileSize)) { // Check if file size is exceeding allowed limit + if (!$fileSizeValidator->isValid($fileSize) && $functionSizeLimit !== 0) { // Check if file size is exceeding allowed limit throw new Exception(Exception::STORAGE_INVALID_FILE_SIZE); } diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 6ff2161c1a..87481e91ea 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -486,7 +486,7 @@ class Builds extends Action $sizeLimit = (int) $plan['deploymentSize'] * 1000 * 1000; } - if ($directorySize > $sizeLimit) { + if ($directorySize > $sizeLimit && $sizeLimit !== 0) { throw new \Exception('Repository directory size should be less than ' . number_format($sizeLimit / (1000 * 1000), 2) . ' MBs.'); } @@ -816,7 +816,7 @@ class Builds extends Action if (isset($plan['buildSize'])) { $buildSizeLimit = $plan['buildSize'] * 1000 * 1000; } - if ($response['size'] > $buildSizeLimit) { + if ($response['size'] > $buildSizeLimit && $buildSizeLimit !== 0) { throw new \Exception('Build size should be less than ' . number_format($buildSizeLimit / (1000 * 1000), 2) . ' MBs.'); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php index afa1dba7d8..13b1e0c830 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php @@ -183,7 +183,7 @@ class Create extends Action } } - if (!$fileSizeValidator->isValid($fileSize)) { // Check if file size is exceeding allowed limit + if (!$fileSizeValidator->isValid($fileSize) && $siteSizeLimit !== 0) { // Check if file size is exceeding allowed limit throw new Exception(Exception::STORAGE_INVALID_FILE_SIZE); } From 04a9b0be348857dd001162d8ab0afa5060943799 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 23 May 2025 03:29:44 +1200 Subject: [PATCH 11/31] Fix replace --- CHANGES.md | 2 +- app/controllers/api/messaging.php | 2 +- app/init/database/filters.php | 2 +- composer.json | 2 +- composer.lock | 25 ++++++++++++++++--------- src/Appwrite/Deletes/Targets.php | 2 +- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index fa4db4acc5..bc903e4b31 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -607,7 +607,7 @@ ### Fixes * Fix database exception wrapping by @abnegate in https://github.com/appwrite/appwrite/pull/7787 * Fix exception wrap order by @abnegate in https://github.com/appwrite/appwrite/pull/7818 -* Fix membership query to use sequence by @lohanidamodar in https://github.com/appwrite/appwrite/pull/7834 +* Fix membership query to use internalId by @lohanidamodar in https://github.com/appwrite/appwrite/pull/7834 * Fix vcs silent mode by @vermakhushboo in https://github.com/appwrite/appwrite/pull/7683 * Fix function domain permissions by @stnguyen90 in https://github.com/appwrite/appwrite/pull/7852 * Fix tests required for Cloud by @lohanidamodar in https://github.com/appwrite/appwrite/pull/7777 diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index c74314e905..0bc6f93787 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -2513,7 +2513,7 @@ App::post('/v1/messaging/topics/:topicId/subscribers') 'topicId' => $topicId, 'topicInternalId' => $topic->getSequence(), 'targetId' => $targetId, - 'targetSequence' => $target->getSequence(), + 'targetInternalId' => $target->getSequence(), 'userId' => $user->getId(), 'userInternalId' => $user->getSequence(), 'providerType' => $target->getAttribute('providerType'), diff --git a/app/init/database/filters.php b/app/init/database/filters.php index 7f2282747e..73ff7dc221 100644 --- a/app/init/database/filters.php +++ b/app/init/database/filters.php @@ -329,7 +329,7 @@ Database::addFilter( }, function (mixed $value, Document $document, Database $database) { $targetIds = Authorization::skip(fn () => \array_map( - fn ($document) => $document->getAttribute('targetSequence'), + fn ($document) => $document->getAttribute('targetInternalId'), $database->find('subscribers', [ Query::equal('topicInternalId', [$document->getSequence()]), Query::limit(APP_LIMIT_SUBSCRIBERS_SUBQUERY) diff --git a/composer.json b/composer.json index 9a3c9e8319..7f3c4a574e 100644 --- a/composer.json +++ b/composer.json @@ -62,7 +62,7 @@ "utopia-php/locale": "0.4.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.17.*", - "utopia-php/migration": "0.9.*", + "utopia-php/migration": "dev-feat-sequence as 0.9.3", "utopia-php/orchestration": "0.9.*", "utopia-php/platform": "0.7.*", "utopia-php/pools": "0.8.*", diff --git a/composer.lock b/composer.lock index 1d84acbb43..58b7d9d387 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cb47e05e104d978efba67c3ccc7bf959", + "content-hash": "92b3f5ad47dd7b23394f27c18713c7e8", "packages": [ { "name": "adhocore/jwt", @@ -3999,16 +3999,16 @@ }, { "name": "utopia-php/migration", - "version": "0.9.3", + "version": "dev-feat-sequence", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "e518d39eb550fde36bc5cf06c9bd7b2faf5dbedd" + "reference": "bef2ad136a86a7747675e0e877f38a8ffe44c39f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/e518d39eb550fde36bc5cf06c9bd7b2faf5dbedd", - "reference": "e518d39eb550fde36bc5cf06c9bd7b2faf5dbedd", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/bef2ad136a86a7747675e0e877f38a8ffe44c39f", + "reference": "bef2ad136a86a7747675e0e877f38a8ffe44c39f", "shasum": "" }, "require": { @@ -4016,7 +4016,7 @@ "ext-curl": "*", "ext-openssl": "*", "php": ">=8.1", - "utopia-php/database": "0.*.*", + "utopia-php/database": "dev-feat-internal-to-sequence as 0.65.5", "utopia-php/dsn": "0.2.*", "utopia-php/framework": "0.33.*", "utopia-php/storage": "0.18.*" @@ -4049,9 +4049,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/0.9.3" + "source": "https://github.com/utopia-php/migration/tree/feat-sequence" }, - "time": "2025-05-01T05:41:26+00:00" + "time": "2025-05-22T15:27:01+00:00" }, { "name": "utopia-php/orchestration", @@ -8246,11 +8246,18 @@ "version": "dev-feat-internal-to-sequence", "alias": "0.69.5", "alias_normalized": "0.69.5.0" + }, + { + "package": "utopia-php/migration", + "version": "dev-feat-sequence", + "alias": "0.9.3", + "alias_normalized": "0.9.3.0" } ], "minimum-stability": "stable", "stability-flags": { - "utopia-php/database": 20 + "utopia-php/database": 20, + "utopia-php/migration": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/src/Appwrite/Deletes/Targets.php b/src/Appwrite/Deletes/Targets.php index 68a9d675b6..794ab0b87a 100644 --- a/src/Appwrite/Deletes/Targets.php +++ b/src/Appwrite/Deletes/Targets.php @@ -27,7 +27,7 @@ class Targets $database->deleteDocuments( 'subscribers', [ - Query::equal('targetSequence', [$target->getSequence()]), + Query::equal('targetInternalId', [$target->getSequence()]), Query::orderAsc(), ], Database::DELETE_BATCH_SIZE, From 0cccb7527351e3bc48a0fd01ac9fe437c1bea4ce Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 12:05:42 +0530 Subject: [PATCH 12/31] added encrypt property in the attribute string response model --- app/controllers/api/databases.php | 6 ++++-- src/Appwrite/Utopia/Response/Model/AttributeString.php | 7 +++++++ tests/e2e/Services/Databases/DatabasesBase.php | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index d495a1d924..786b498adf 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1372,10 +1372,12 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string 'array' => $array, 'filters' => $filters, ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); - + $stringAttribute = $attribute->getArrayCopy(); + $stringAttribute['encrypt'] = $encrypt; + $stringAttribute = new Document($stringAttribute); $response ->setStatusCode(Response::STATUS_CODE_ACCEPTED) - ->dynamic($attribute, Response::MODEL_ATTRIBUTE_STRING); + ->dynamic($stringAttribute, Response::MODEL_ATTRIBUTE_STRING); }); App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/email') diff --git a/src/Appwrite/Utopia/Response/Model/AttributeString.php b/src/Appwrite/Utopia/Response/Model/AttributeString.php index 12bb42009d..f5559f2206 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeString.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeString.php @@ -24,6 +24,13 @@ class AttributeString extends Attribute 'required' => false, 'example' => 'default', ]) + ->addRule('encrypt', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Encryption status for the string attribute. Encryption enhances security by not storing any plain text values in the database. However, encrypted attributes cannot be queried.', + 'default' => false, + 'required' => false, + 'example' => false, + ]) ; } diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 7c0060ecaa..9aed3684de 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -298,7 +298,7 @@ trait DatabasesBase $this->assertEquals($title['body']['type'], 'string'); $this->assertEquals($title['body']['size'], 256); $this->assertEquals($title['body']['required'], true); - + $this->assertFalse($title['body']['encrypt']); $this->assertEquals(202, $description['headers']['status-code']); $this->assertEquals($description['body']['key'], 'description'); $this->assertEquals($description['body']['type'], 'string'); From 1a4a10400b2b956a919cf2080fc43a0e7a1fdca3 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 12:12:23 +0530 Subject: [PATCH 13/31] added test for the encrypted string in the server --- tests/e2e/Services/Databases/DatabasesCustomServerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 67f7a07a9b..57dbd3d378 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -697,6 +697,7 @@ class DatabasesCustomServerTest extends Scope 'required' => true, 'encrypt' => true ]); + $this->assertTrue($lastName['body']['encrypt']); /** From 1d0577b07ded92cfca8336d48de8e6db1d2c1621 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 12:51:59 +0530 Subject: [PATCH 14/31] added encrypt to the get and list atttributes --- app/controllers/api/databases.php | 18 +++++++++++++++--- .../Utopia/Response/Model/AttributeString.php | 2 +- .../Databases/DatabasesCustomServerTest.php | 13 ++++++++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 786b498adf..8ed169baff 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2053,8 +2053,18 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') throw new Exception(Exception::GENERAL_QUERY_INVALID); } + $updatedAttributes = []; + + foreach ($attributes as $attribute) { + $filters = $attribute->getAttribute('filters', []); + $attributeArray = $attribute->getArrayCopy(); + $attributeArray['encrypt'] = in_array('encrypt', $filters); + $updatedAttribute = new Document($attributeArray); + $updatedAttributes[] = $updatedAttribute; + } + $response->dynamic(new Document([ - 'attributes' => $attributes, + 'attributes' => $updatedAttributes, 'total' => $total, ]), Response::MODEL_ATTRIBUTE_LIST); }); @@ -2117,7 +2127,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes/:key') $type = $attribute->getAttribute('type'); $format = $attribute->getAttribute('format'); $options = $attribute->getAttribute('options', []); - + $filters = $attribute->getAttribute('filters', []); foreach ($options as $key => $option) { $attribute->setAttribute($key, $option); } @@ -2137,7 +2147,9 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes/:key') }, default => Response::MODEL_ATTRIBUTE, }; - + $attribute = $attribute->getArrayCopy(); + $attribute['encrypt'] = in_array('encrypt', $filters); + $attribute = new Document($attribute); $response->dynamic($attribute, $model); }); diff --git a/src/Appwrite/Utopia/Response/Model/AttributeString.php b/src/Appwrite/Utopia/Response/Model/AttributeString.php index f5559f2206..fded48fddc 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeString.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeString.php @@ -26,7 +26,7 @@ class AttributeString extends Attribute ]) ->addRule('encrypt', [ 'type' => self::TYPE_BOOLEAN, - 'description' => 'Encryption status for the string attribute. Encryption enhances security by not storing any plain text values in the database. However, encrypted attributes cannot be queried.', + 'description' => 'Defines whether this attribute is encrypted or not.', 'default' => false, 'required' => false, 'example' => false, diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 57dbd3d378..d9cbc04250 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -698,8 +698,19 @@ class DatabasesCustomServerTest extends Scope 'encrypt' => true ]); $this->assertTrue($lastName['body']['encrypt']); + sleep(1); + $response = $this->client->call(Client::METHOD_GET, $attributesPath . '/lastName', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ])); + $this->assertTrue($response['body']['encrypt']); - + $response = $this->client->call(Client::METHOD_GET, $attributesPath, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ])); /** * Check status of every attribute */ From 02426df1cab7e0bf0a55f15e9097244c1e68799c Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 12:53:10 +0530 Subject: [PATCH 15/31] linting --- tests/e2e/Services/Databases/DatabasesCustomServerTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index d9cbc04250..33e597dd87 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -706,11 +706,6 @@ class DatabasesCustomServerTest extends Scope ])); $this->assertTrue($response['body']['encrypt']); - $response = $this->client->call(Client::METHOD_GET, $attributesPath, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ])); /** * Check status of every attribute */ From 14274d96aadb36a34b2318fd5b5a8b8e5bfa651c Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 23 May 2025 19:42:43 +1200 Subject: [PATCH 16/31] Update libs --- composer.json | 4 ++-- composer.lock | 48 ++++++++++++++++-------------------------------- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/composer.json b/composer.json index 7f3c4a574e..9b61351956 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,7 @@ "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", "utopia-php/detector": "0.1.*", - "utopia-php/database": "dev-feat-internal-to-sequence as 0.69.5", + "utopia-php/database": "0.71.*", "utopia-php/domains": "0.8.0", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", @@ -62,7 +62,7 @@ "utopia-php/locale": "0.4.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.17.*", - "utopia-php/migration": "dev-feat-sequence as 0.9.3", + "utopia-php/migration": "0.10.*", "utopia-php/orchestration": "0.9.*", "utopia-php/platform": "0.7.*", "utopia-php/pools": "0.8.*", diff --git a/composer.lock b/composer.lock index 58b7d9d387..dc8661f3bb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "92b3f5ad47dd7b23394f27c18713c7e8", + "content-hash": "5027a541e6377eb2c87357b69f11daea", "packages": [ { "name": "adhocore/jwt", @@ -3499,16 +3499,16 @@ }, { "name": "utopia-php/database", - "version": "dev-feat-internal-to-sequence", + "version": "0.71.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "0f3617e23bef7c6f260d7f8f194031c2f096a154" + "reference": "cf463c0a5c64a4168fe56266ace4ae835d61c920" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/0f3617e23bef7c6f260d7f8f194031c2f096a154", - "reference": "0f3617e23bef7c6f260d7f8f194031c2f096a154", + "url": "https://api.github.com/repos/utopia-php/database/zipball/cf463c0a5c64a4168fe56266ace4ae835d61c920", + "reference": "cf463c0a5c64a4168fe56266ace4ae835d61c920", "shasum": "" }, "require": { @@ -3549,9 +3549,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/feat-internal-to-sequence" + "source": "https://github.com/utopia-php/database/tree/0.71.0" }, - "time": "2025-05-22T13:09:40+00:00" + "time": "2025-05-23T07:32:59+00:00" }, { "name": "utopia-php/detector", @@ -3999,16 +3999,16 @@ }, { "name": "utopia-php/migration", - "version": "dev-feat-sequence", + "version": "0.10.0", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "bef2ad136a86a7747675e0e877f38a8ffe44c39f" + "reference": "0b0e94c4b5243c5566b9634b07ba2ec5f7990914" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/bef2ad136a86a7747675e0e877f38a8ffe44c39f", - "reference": "bef2ad136a86a7747675e0e877f38a8ffe44c39f", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/0b0e94c4b5243c5566b9634b07ba2ec5f7990914", + "reference": "0b0e94c4b5243c5566b9634b07ba2ec5f7990914", "shasum": "" }, "require": { @@ -4016,7 +4016,7 @@ "ext-curl": "*", "ext-openssl": "*", "php": ">=8.1", - "utopia-php/database": "dev-feat-internal-to-sequence as 0.65.5", + "utopia-php/database": "0.*.*", "utopia-php/dsn": "0.2.*", "utopia-php/framework": "0.33.*", "utopia-php/storage": "0.18.*" @@ -4049,9 +4049,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/feat-sequence" + "source": "https://github.com/utopia-php/migration/tree/0.10.0" }, - "time": "2025-05-22T15:27:01+00:00" + "time": "2025-05-23T07:40:24+00:00" }, { "name": "utopia-php/orchestration", @@ -8240,25 +8240,9 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [ - { - "package": "utopia-php/database", - "version": "dev-feat-internal-to-sequence", - "alias": "0.69.5", - "alias_normalized": "0.69.5.0" - }, - { - "package": "utopia-php/migration", - "version": "dev-feat-sequence", - "alias": "0.9.3", - "alias_normalized": "0.9.3.0" - } - ], + "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "utopia-php/database": 20, - "utopia-php/migration": 20 - }, + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { From 73764941b6bdcd3fc5ccd664e22977e92439a458 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 13:23:33 +0530 Subject: [PATCH 17/31] updated tests and collection method --- app/controllers/api/databases.php | 31 ++++++++++--------- .../Databases/DatabasesCustomServerTest.php | 22 +++++++++++++ 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 8ed169baff..186ba4b08d 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1063,6 +1063,14 @@ App::get('/v1/databases/:databaseId/collections/:collectionId') throw new Exception(Exception::COLLECTION_NOT_FOUND); } + $attributes = $collection->getAttribute('attributes'); + foreach ($attributes as $attribute) { + if ($attribute->getAttribute('type') === Database::VAR_STRING) { + $filters = $attribute->getAttribute('filters', []); + $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); + } + } + $response->dynamic($collection, Response::MODEL_COLLECTION); }); @@ -1372,12 +1380,10 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string 'array' => $array, 'filters' => $filters, ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); - $stringAttribute = $attribute->getArrayCopy(); - $stringAttribute['encrypt'] = $encrypt; - $stringAttribute = new Document($stringAttribute); + $attribute->setAttribute('encrypt', $encrypt); $response ->setStatusCode(Response::STATUS_CODE_ACCEPTED) - ->dynamic($stringAttribute, Response::MODEL_ATTRIBUTE_STRING); + ->dynamic($attribute, Response::MODEL_ATTRIBUTE_STRING); }); App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/email') @@ -2053,18 +2059,17 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') throw new Exception(Exception::GENERAL_QUERY_INVALID); } - $updatedAttributes = []; + foreach ($attributes as $attribute) { - $filters = $attribute->getAttribute('filters', []); - $attributeArray = $attribute->getArrayCopy(); - $attributeArray['encrypt'] = in_array('encrypt', $filters); - $updatedAttribute = new Document($attributeArray); - $updatedAttributes[] = $updatedAttribute; + if ($attribute->getAttribute('type') === Database::VAR_STRING) { + $filters = $attribute->getAttribute('filters', []); + $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); + } } $response->dynamic(new Document([ - 'attributes' => $updatedAttributes, + 'attributes' => $attributes, 'total' => $total, ]), Response::MODEL_ATTRIBUTE_LIST); }); @@ -2147,9 +2152,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes/:key') }, default => Response::MODEL_ATTRIBUTE, }; - $attribute = $attribute->getArrayCopy(); - $attribute['encrypt'] = in_array('encrypt', $filters); - $attribute = new Document($attribute); + $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); $response->dynamic($attribute, $model); }); diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 33e597dd87..3d5ba61585 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -748,6 +748,28 @@ class DatabasesCustomServerTest extends Scope $this->assertEquals(200, $document['headers']['status-code']); $this->assertEquals('Jonah', $document['body']['firstName']); $this->assertEquals('Jameson', $document['body']['lastName']); + + + $actors = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $actors['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), []); + $attributes = $actors['body']['attributes']; + $firstNameAttribute = null; + $lastNameAttribute = null; + foreach ($attributes as $attribute) { + $this->assertArrayHasKey('encrypt', $attribute); + if ($attribute['key'] === 'firstName') { + $firstNameAttribute = $attribute['encrypt']; + } + if ($attribute['key'] === 'lastName') { + $lastNameAttribute = $attribute['encrypt']; + } + } + $this->assertTrue($lastNameAttribute); + $this->assertFalse($firstNameAttribute); + } public function testDeleteAttribute(): array From 6ea35939217cca37e40fb9292ad6cfadb22974ee Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 13:40:56 +0530 Subject: [PATCH 18/31] updated collection filter --- app/controllers/api/databases.php | 7 ------- app/init/database/filters.php | 7 ++++++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 186ba4b08d..5cc1369f00 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1063,13 +1063,6 @@ App::get('/v1/databases/:databaseId/collections/:collectionId') throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $attributes = $collection->getAttribute('attributes'); - foreach ($attributes as $attribute) { - if ($attribute->getAttribute('type') === Database::VAR_STRING) { - $filters = $attribute->getAttribute('filters', []); - $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); - } - } $response->dynamic($collection, Response::MODEL_COLLECTION); }); diff --git a/app/init/database/filters.php b/app/init/database/filters.php index f110fe1554..44fd748758 100644 --- a/app/init/database/filters.php +++ b/app/init/database/filters.php @@ -77,13 +77,18 @@ Database::addFilter( ]); foreach ($attributes as $attribute) { - if ($attribute->getAttribute('type') === Database::VAR_RELATIONSHIP) { + $attributeType = $attribute->getAttribute('type'); + if ($attributeType === Database::VAR_RELATIONSHIP) { $options = $attribute->getAttribute('options'); foreach ($options as $key => $value) { $attribute->setAttribute($key, $value); } $attribute->removeAttribute('options'); } + if ($attributeType === Database::VAR_STRING) { + $filters = $attribute->getAttribute('filters', []); + $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); + } } return $attributes; From e586afceb74eca90d800323b10056b97db5a18c6 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 14:11:57 +0530 Subject: [PATCH 19/31] updates --- app/controllers/api/databases.php | 1 - app/init/database/filters.php | 24 +++++++++++-------- .../Databases/DatabasesCustomServerTest.php | 8 ++----- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 5cc1369f00..0d4e535b1b 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2053,7 +2053,6 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') } - foreach ($attributes as $attribute) { if ($attribute->getAttribute('type') === Database::VAR_STRING) { $filters = $attribute->getAttribute('filters', []); diff --git a/app/init/database/filters.php b/app/init/database/filters.php index 44fd748758..c470329706 100644 --- a/app/init/database/filters.php +++ b/app/init/database/filters.php @@ -78,16 +78,20 @@ Database::addFilter( foreach ($attributes as $attribute) { $attributeType = $attribute->getAttribute('type'); - if ($attributeType === Database::VAR_RELATIONSHIP) { - $options = $attribute->getAttribute('options'); - foreach ($options as $key => $value) { - $attribute->setAttribute($key, $value); - } - $attribute->removeAttribute('options'); - } - if ($attributeType === Database::VAR_STRING) { - $filters = $attribute->getAttribute('filters', []); - $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); + + switch ($attributeType) { + case Database::VAR_RELATIONSHIP: + $options = $attribute->getAttribute('options'); + foreach ($options as $key => $value) { + $attribute->setAttribute($key, $value); + } + $attribute->removeAttribute('options'); + break; + + case Database::VAR_STRING: + $filters = $attribute->getAttribute('filters', []); + $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); + break; } } diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 3d5ba61585..c0d8763aa7 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -756,19 +756,15 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'] ]), []); $attributes = $actors['body']['attributes']; - $firstNameAttribute = null; - $lastNameAttribute = null; foreach ($attributes as $attribute) { $this->assertArrayHasKey('encrypt', $attribute); if ($attribute['key'] === 'firstName') { - $firstNameAttribute = $attribute['encrypt']; + $this->assertFalse($attribute['encrypt']); } if ($attribute['key'] === 'lastName') { - $lastNameAttribute = $attribute['encrypt']; + $this->assertTrue($attribute['encrypt']); } } - $this->assertTrue($lastNameAttribute); - $this->assertFalse($firstNameAttribute); } From 7c760e4b07979fa94cdbbb13054928832704239c Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 14:16:35 +0530 Subject: [PATCH 20/31] linting --- app/controllers/api/databases.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 0d4e535b1b..fba985fded 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1063,7 +1063,6 @@ App::get('/v1/databases/:databaseId/collections/:collectionId') throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $response->dynamic($collection, Response::MODEL_COLLECTION); }); From b8cb6f281d467bd41a5d7adde86b82134752877f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 14:19:00 +0530 Subject: [PATCH 21/31] linting --- app/controllers/api/databases.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index fba985fded..75f89d5733 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2051,7 +2051,6 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') throw new Exception(Exception::GENERAL_QUERY_INVALID); } - foreach ($attributes as $attribute) { if ($attribute->getAttribute('type') === Database::VAR_STRING) { $filters = $attribute->getAttribute('filters', []); From 18335ebf892e23f20587f0c2376cccd8dbe9e63b Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 23 May 2025 14:29:31 +0100 Subject: [PATCH 22/31] feat: add builds worker group --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 980e49fcad..a01250c05a 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -57,6 +57,7 @@ class Builds extends Action { $this ->desc('Builds worker') + ->groups(['builds']) ->inject('message') ->inject('project') ->inject('dbForPlatform') From 65a220b70274a1405727b074fb547e648e3fc430 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Fri, 23 May 2025 20:11:27 +0530 Subject: [PATCH 23/31] Fix URL for view logs in github comment --- src/Appwrite/Vcs/Comment.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Vcs/Comment.php b/src/Appwrite/Vcs/Comment.php index 62f6ef61d0..7c550ad528 100644 --- a/src/Appwrite/Vcs/Comment.php +++ b/src/Appwrite/Vcs/Comment.php @@ -36,6 +36,7 @@ class Comment $this->builds[$id] = [ 'projectName' => $project->getAttribute('name'), 'projectId' => $project->getId(), + 'region' => $project->getAttribute('region', 'default'), 'resourceName' => $resource->getAttribute('name'), 'resourceId' => $resource->getId(), 'resourceType' => $resourceType, @@ -66,6 +67,7 @@ class Comment if ($build['resourceType'] === 'site') { $projects[$build['projectId']]['site'][$build['resourceId']] = [ 'name' => $build['resourceName'], + 'region' => $build['region'], 'status' => $build['buildStatus'], 'deploymentId' => $build['deploymentId'], 'action' => $build['action'], @@ -74,6 +76,7 @@ class Comment } elseif ($build['resourceType'] === 'function') { $projects[$build['projectId']]['function'][$build['resourceId']] = [ 'name' => $build['resourceName'], + 'region' => $build['region'], 'status' => $build['buildStatus'], 'deploymentId' => $build['deploymentId'], 'action' => $build['action'], @@ -114,7 +117,7 @@ class Comment }; if ($site['action']['type'] === 'logs') { - $action = '[View Logs](' . $protocol . '://' . $hostname . '/console/project-' . $projectId . '/sites/site-' . $siteId . '/deployments/deployment-' . $site['deploymentId'] . ')'; + $action = '[View Logs](' . $protocol . '://' . $hostname . '/console/project-' . $site['region'] . '-' . $projectId . '/sites/site-' . $siteId . '/deployments/deployment-' . $site['deploymentId'] . ')'; } else { $action = '[Authorize](' . $site['action']['url'] . ')'; } @@ -146,12 +149,12 @@ class Comment $text .= "| :- | :- | :- | :- |\n"; foreach ($project['function'] as $functionId => $function) { - $extension = $site['status'] === 'building' ? 'gif' : 'png'; + $extension = $function['status'] === 'building' ? 'gif' : 'png'; - $pathLight = '/images/vcs/status-' . $site['status'] . '-light.' . $extension; - $pathDark = '/images/vcs/status-' . $site['status'] . '-dark.' . $extension; + $pathLight = '/images/vcs/status-' . $function['status'] . '-light.' . $extension; + $pathDark = '/images/vcs/status-' . $function['status'] . '-dark.' . $extension; - $status = match ($site['status']) { + $status = match ($function['status']) { 'waiting' => $this->generatImage($pathLight, $pathDark, 'Queued', 85) . ' _Queued_', 'processing' => $this->generatImage($pathLight, $pathDark, 'Processing', 85) . ' _Processing_', 'building' => $this->generatImage($pathLight, $pathDark, 'Building', 85) . ' _Building_', @@ -160,7 +163,7 @@ class Comment }; if ($function['action']['type'] === 'logs') { - $action = '[View Logs](' . $protocol . '://' . $hostname . '/console/project-' . $projectId . '/functions/function-' . $functionId . '/deployment-' . $function['deploymentId'] . ')'; + $action = '[View Logs](' . $protocol . '://' . $hostname . '/console/project-' . $function['region'] . '-' . $projectId . '/functions/function-' . $functionId . '/deployment-' . $function['deploymentId'] . ')'; } else { $action = '[Authorize](' . $function['action']['url'] . ')'; } From 14fe7a32939a3f5140cb847d86da477efc02dae5 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 20:35:59 +0530 Subject: [PATCH 24/31] updated errro for the string encryption --- app/controllers/api/databases.php | 3 +++ .../Services/Databases/DatabasesCustomServerTest.php | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 75f89d5733..c57c29d9a2 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1352,6 +1352,9 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string if ($encrypt && !empty($plan) && !($plan['databasesAllowEncrypt'] ?? false)) { throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Encrypted string attributes are not available on your plan. Please upgrade to create encrypted string attributes.'); } + if ($encrypt && $size < 150) { + throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Size too small. Encrypted strings require a minimum size of 150 characters.'); + } // Ensure attribute default is within required size $validator = new Text($size, 0); if (!is_null($default) && !$validator->isValid($default)) { diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index c0d8763aa7..25c7e30a4f 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -686,6 +686,18 @@ class DatabasesCustomServerTest extends Scope 'size' => 256, 'required' => true, ]); + // checking size test + $lastName = $this->client->call(Client::METHOD_POST, $attributesPath . '/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'lastName', + 'size' => 149, + 'required' => true, + 'encrypt' => true + ]); + $this->assertEquals('Size too small. Encrypted strings require a minimum size of 150 characters.', $lastName['body']['message']); $lastName = $this->client->call(Client::METHOD_POST, $attributesPath . '/string', array_merge([ 'content-type' => 'application/json', From 6af9d1206d63b50d2970d59445b86c8b5d8b4328 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 20:41:08 +0530 Subject: [PATCH 25/31] added a constant --- app/controllers/api/databases.php | 2 +- app/init/constants.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index c57c29d9a2..b38596239c 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1352,7 +1352,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string if ($encrypt && !empty($plan) && !($plan['databasesAllowEncrypt'] ?? false)) { throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Encrypted string attributes are not available on your plan. Please upgrade to create encrypted string attributes.'); } - if ($encrypt && $size < 150) { + if ($encrypt && $size < APP_DATABASE_ENCRYPT_SIZE_MIN) { throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Size too small. Encrypted strings require a minimum size of 150 characters.'); } // Ensure attribute default is within required size diff --git a/app/init/constants.php b/app/init/constants.php index 7686759719..4699014925 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -51,6 +51,7 @@ const APP_DATABASE_TIMEOUT_MILLISECONDS_API = 15 * 1000; // 15 seconds const APP_DATABASE_TIMEOUT_MILLISECONDS_WORKER = 300 * 1000; // 5 minutes const APP_DATABASE_TIMEOUT_MILLISECONDS_TASK = 300 * 1000; // 5 minutes const APP_DATABASE_QUERY_MAX_VALUES = 500; +const APP_DATABASE_ENCRYPT_SIZE_MIN = 150; const APP_STORAGE_UPLOADS = '/storage/uploads'; const APP_STORAGE_SITES = '/storage/sites'; const APP_STORAGE_FUNCTIONS = '/storage/functions'; From 49f8369fdd3ecb02337a36f8127fed4865a4090f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 20:45:36 +0530 Subject: [PATCH 26/31] updated the message --- app/controllers/api/databases.php | 5 ++++- tests/e2e/Services/Databases/DatabasesCustomServerTest.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index b38596239c..7eb3273c38 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1353,7 +1353,10 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Encrypted string attributes are not available on your plan. Please upgrade to create encrypted string attributes.'); } if ($encrypt && $size < APP_DATABASE_ENCRYPT_SIZE_MIN) { - throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Size too small. Encrypted strings require a minimum size of 150 characters.'); + throw new Exception( + Exception::GENERAL_BAD_REQUEST, + "Size too small. Encrypted strings require a minimum size of " . APP_DATABASE_ENCRYPT_SIZE_MIN . " characters." + ); } // Ensure attribute default is within required size $validator = new Text($size, 0); diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 25c7e30a4f..e66207b215 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -697,7 +697,7 @@ class DatabasesCustomServerTest extends Scope 'required' => true, 'encrypt' => true ]); - $this->assertEquals('Size too small. Encrypted strings require a minimum size of 150 characters.', $lastName['body']['message']); + $this->assertEquals("Size too small. Encrypted strings require a minimum size of " . APP_DATABASE_ENCRYPT_SIZE_MIN . " characters.", $lastName['body']['message']); $lastName = $this->client->call(Client::METHOD_POST, $attributesPath . '/string', array_merge([ 'content-type' => 'application/json', From 28d2ed1baa69499c2377240617588b2ced2611e5 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 23 May 2025 21:39:56 +0400 Subject: [PATCH 27/31] Revert "Feat sequence" --- CONTRIBUTING.md | 10 +- app/cli.php | 12 +- app/config/console.php | 2 +- app/controllers/api/account.php | 70 ++--- app/controllers/api/avatars.php | 12 +- app/controllers/api/databases.php | 260 +++++++++--------- app/controllers/api/health.php | 9 +- app/controllers/api/messaging.php | 28 +- app/controllers/api/migrations.php | 2 +- app/controllers/api/project.php | 18 +- app/controllers/api/projects.php | 46 ++-- app/controllers/api/proxy.php | 8 +- app/controllers/api/storage.php | 80 +++--- app/controllers/api/teams.php | 24 +- app/controllers/api/users.php | 30 +- app/controllers/api/vcs.php | 32 +-- app/controllers/general.php | 20 +- app/controllers/mock.php | 4 +- app/controllers/shared/api.php | 8 +- app/http.php | 4 +- app/init/database/filters.php | 30 +- app/init/resources.php | 22 +- app/realtime.php | 10 +- app/worker.php | 16 +- composer.json | 4 +- composer.lock | 62 ++--- src/Appwrite/Deletes/Targets.php | 4 +- src/Appwrite/Event/Event.php | 2 +- src/Appwrite/Migration/Migration.php | 12 +- src/Appwrite/Migration/Version/V15.php | 30 +- src/Appwrite/Migration/Version/V16.php | 2 +- src/Appwrite/Migration/Version/V17.php | 4 +- src/Appwrite/Migration/Version/V18.php | 16 +- src/Appwrite/Migration/Version/V19.php | 24 +- src/Appwrite/Migration/Version/V20.php | 24 +- src/Appwrite/Migration/Version/V21.php | 8 +- src/Appwrite/Migration/Version/V22.php | 8 +- .../Platform/Modules/Compute/Base.php | 20 +- .../Functions/Http/Deployments/Create.php | 8 +- .../Functions/Http/Deployments/Delete.php | 4 +- .../Http/Deployments/Duplicate/Create.php | 6 +- .../Http/Deployments/Status/Update.php | 2 +- .../Http/Deployments/Template/Create.php | 4 +- .../Functions/Http/Deployments/XList.php | 2 +- .../Functions/Http/Executions/Create.php | 14 +- .../Functions/Http/Executions/Delete.php | 2 +- .../Modules/Functions/Http/Executions/Get.php | 2 +- .../Functions/Http/Executions/XList.php | 2 +- .../Functions/Http/Functions/Create.php | 26 +- .../Http/Functions/Deployment/Update.php | 6 +- .../Functions/Http/Functions/Update.php | 14 +- .../Modules/Functions/Http/Usage/Get.php | 22 +- .../Functions/Http/Variables/Create.php | 2 +- .../Functions/Http/Variables/Delete.php | 2 +- .../Modules/Functions/Http/Variables/Get.php | 2 +- .../Functions/Http/Variables/Update.php | 2 +- .../Modules/Functions/Workers/Builds.php | 74 ++--- .../Modules/Projects/Http/DevKeys/Create.php | 2 +- .../Modules/Projects/Http/DevKeys/Delete.php | 2 +- .../Modules/Projects/Http/DevKeys/Get.php | 2 +- .../Modules/Projects/Http/DevKeys/Update.php | 2 +- .../Modules/Projects/Http/DevKeys/XList.php | 2 +- .../Modules/Proxy/Http/Rules/API/Create.php | 2 +- .../Proxy/Http/Rules/Function/Create.php | 6 +- .../Proxy/Http/Rules/Redirect/Create.php | 2 +- .../Modules/Proxy/Http/Rules/Site/Create.php | 6 +- .../Modules/Sites/Http/Deployments/Create.php | 16 +- .../Modules/Sites/Http/Deployments/Delete.php | 4 +- .../Http/Deployments/Duplicate/Create.php | 12 +- .../Sites/Http/Deployments/Status/Update.php | 2 +- .../Http/Deployments/Template/Create.php | 10 +- .../Modules/Sites/Http/Deployments/XList.php | 2 +- .../Modules/Sites/Http/Logs/Delete.php | 2 +- .../Platform/Modules/Sites/Http/Logs/Get.php | 2 +- .../Modules/Sites/Http/Logs/XList.php | 2 +- .../Modules/Sites/Http/Sites/Create.php | 10 +- .../Sites/Http/Sites/Deployment/Update.php | 6 +- .../Modules/Sites/Http/Sites/Update.php | 14 +- .../Platform/Modules/Sites/Http/Usage/Get.php | 28 +- .../Modules/Sites/Http/Variables/Create.php | 2 +- .../Modules/Sites/Http/Variables/Delete.php | 2 +- .../Modules/Sites/Http/Variables/Get.php | 2 +- .../Modules/Sites/Http/Variables/Update.php | 2 +- .../Http/Tokens/Buckets/Files/Action.php | 4 +- .../Http/Tokens/Buckets/Files/Create.php | 2 +- .../Http/Tokens/Buckets/Files/XList.php | 2 +- src/Appwrite/Platform/Tasks/ScheduleBase.php | 10 +- .../Platform/Tasks/ScheduleExecutions.php | 4 +- .../Platform/Tasks/ScheduleMessages.php | 2 +- .../Platform/Tasks/StatsResources.php | 2 +- src/Appwrite/Platform/Workers/Audits.php | 14 +- .../Platform/Workers/Certificates.php | 2 +- src/Appwrite/Platform/Workers/Databases.php | 44 +-- src/Appwrite/Platform/Workers/Deletes.php | 42 +-- src/Appwrite/Platform/Workers/Functions.php | 12 +- src/Appwrite/Platform/Workers/Messaging.php | 4 +- src/Appwrite/Platform/Workers/Migrations.php | 2 +- .../Platform/Workers/StatsResources.php | 70 ++--- src/Appwrite/Platform/Workers/StatsUsage.php | 46 ++-- .../Platform/Workers/StatsUsageDump.php | 4 +- src/Appwrite/Platform/Workers/Webhooks.php | 4 +- .../Database/Validator/Queries/Base.php | 6 +- .../Utopia/Response/Model/Document.php | 2 +- .../e2e/Services/Databases/DatabasesBase.php | 12 +- 104 files changed, 802 insertions(+), 805 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 277a509447..7746ef99af 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -415,8 +415,8 @@ In addition, you will also need to add some logic to the `reduce()` method of th ```php case $document->getCollection() === 'buckets': - $files = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getSequence(), METRIC_BUCKET_ID_FILES))); - $storage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getSequence(), METRIC_BUCKET_ID_FILES_STORAGE))); + $files = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getInternalId(), METRIC_BUCKET_ID_FILES))); + $storage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getInternalId(), METRIC_BUCKET_ID_FILES_STORAGE))); if (!empty($files['value'])) { $metrics[] = [ @@ -463,9 +463,9 @@ $queueForStatsUsage ->addMetric(METRIC_BUILDS, 1) ->addMetric(METRIC_BUILDS_STORAGE, $build->getAttribute('size', 0)) ->addMetric(METRIC_BUILDS_COMPUTE, (int)$build->getAttribute('duration', 0) * 1000) - ->addMetric(str_replace('{functionInternalId}', $function->getSequence(), METRIC_FUNCTION_ID_BUILDS), 1) - ->addMetric(str_replace('{functionInternalId}', $function->getSequence(), METRIC_FUNCTION_ID_BUILDS_STORAGE), $build->getAttribute('size', 0)) - ->addMetric(str_replace('{functionInternalId}', $function->getSequence(), METRIC_FUNCTION_ID_BUILDS_COMPUTE), (int)$build->getAttribute('duration', 0) * 1000) + ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS), 1) + ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_STORAGE), $build->getAttribute('size', 0)) + ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_COMPUTE), (int)$build->getAttribute('duration', 0) * 1000) ->setProject($project) ->trigger(); ``` diff --git a/app/cli.php b/app/cli.php index 224f150a58..9517347420 100644 --- a/app/cli.php +++ b/app/cli.php @@ -125,13 +125,13 @@ CLI::setResource('getProjectDB', function (Group $pools, Database $dbForPlatform if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getSequence()) + ->setTenant($project->getInternalId()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getSequence()); + ->setNamespace('_' . $project->getInternalId()); } return $database; @@ -145,13 +145,13 @@ CLI::setResource('getProjectDB', function (Group $pools, Database $dbForPlatform if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getSequence()) + ->setTenant($project->getInternalId()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getSequence()); + ->setNamespace('_' . $project->getInternalId()); } $database @@ -167,7 +167,7 @@ CLI::setResource('getLogsDB', function (Group $pools, Cache $cache) { return function (?Document $project = null) use ($pools, $cache, $database) { if ($database !== null && $project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getSequence()); + $database->setTenant($project->getInternalId()); return $database; } @@ -182,7 +182,7 @@ CLI::setResource('getLogsDB', function (Group $pools, Cache $cache) { // set tenant if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getSequence()); + $database->setTenant($project->getInternalId()); } return $database; diff --git a/app/config/console.php b/app/config/console.php index 1de3a99370..e37c9b7836 100644 --- a/app/config/console.php +++ b/app/config/console.php @@ -11,7 +11,7 @@ use Utopia\System\System; $console = [ '$id' => ID::custom('console'), - '$sequence' => ID::custom('console'), + '$internalId' => ID::custom('console'), 'name' => 'Appwrite', '$collection' => ID::custom('projects'), 'description' => 'Appwrite core engine', diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 0c53423325..ac01476314 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -190,7 +190,7 @@ $createSession = function (string $userId, string $secret, Request $request, Res [ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'provider' => Auth::getSessionProviderByTokenType($verifiedToken->getAttribute('type')), 'secret' => Auth::hash($sessionSecret), // One way hash encryption to protect DB leak 'userAgent' => $request->getUserAgent('UNKNOWN'), @@ -387,7 +387,7 @@ App::post('/v1/account') 'search' => implode(' ', [$userId, $email, $name]), 'accessedAt' => DateTime::now(), ]); - $user->removeAttribute('$sequence'); + $user->removeAttribute('$internalId'); $user = Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); try { $target = Authorization::skip(fn () => $dbForProject->createDocument('targets', new Document([ @@ -397,7 +397,7 @@ App::post('/v1/account') Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'providerType' => MESSAGE_TYPE_EMAIL, 'identifier' => $email, ]))); @@ -907,7 +907,7 @@ App::post('/v1/account/sessions/email') [ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => $email, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak @@ -1056,7 +1056,7 @@ App::post('/v1/account/sessions/anonymous') 'search' => $userId, 'accessedAt' => DateTime::now(), ]); - $user->removeAttribute('$sequence'); + $user->removeAttribute('$internalId'); Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); // Create session token @@ -1069,7 +1069,7 @@ App::post('/v1/account/sessions/anonymous') [ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'provider' => Auth::SESSION_PROVIDER_ANONYMOUS, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak 'userAgent' => $request->getUserAgent('UNKNOWN'), @@ -1440,7 +1440,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $identityWithMatchingEmail = $dbForProject->findOne('identities', [ Query::equal('providerEmail', [$email]), - Query::notEqual('userInternalId', $user->getSequence()), + Query::notEqual('userInternalId', $user->getInternalId()), ]); if (!$identityWithMatchingEmail->isEmpty()) { $failureRedirect(Exception::USER_ALREADY_EXISTS); @@ -1554,7 +1554,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') 'search' => implode(' ', [$userId, $email, $name]), 'accessedAt' => DateTime::now(), ]); - $user->removeAttribute('$sequence'); + $user->removeAttribute('$internalId'); $userDoc = Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); $dbForProject->createDocument('targets', new Document([ '$permissions' => [ @@ -1563,7 +1563,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') Permission::delete(Role::user($user->getId())), ], 'userId' => $userDoc->getId(), - 'userInternalId' => $userDoc->getSequence(), + 'userInternalId' => $userDoc->getInternalId(), 'providerType' => MESSAGE_TYPE_EMAIL, 'identifier' => $email, ])); @@ -1582,7 +1582,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') } $identity = $dbForProject->findOne('identities', [ - Query::equal('userInternalId', [$user->getSequence()]), + Query::equal('userInternalId', [$user->getInternalId()]), Query::equal('provider', [$provider]), Query::equal('providerUid', [$oauth2ID]), ]); @@ -1592,7 +1592,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $identitiesWithMatchingEmail = $dbForProject->find('identities', [ Query::equal('providerEmail', [$email]), - Query::notEqual('userInternalId', $user->getSequence()), + Query::notEqual('userInternalId', $user->getInternalId()), ]); if (!empty($identitiesWithMatchingEmail)) { $failureRedirect(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */ @@ -1605,7 +1605,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') Permission::update(Role::user($userId)), Permission::delete(Role::user($userId)), ], - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'userId' => $userId, 'provider' => $provider, 'providerUid' => $oauth2ID, @@ -1648,7 +1648,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $token = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'type' => Auth::TOKEN_TYPE_OAUTH2, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak 'expire' => $expire, @@ -1683,7 +1683,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $session = new Document(array_merge([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'provider' => $provider, 'providerUid' => $oauth2ID, 'providerAccessToken' => $accessToken, @@ -1736,7 +1736,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $target ->setAttribute('sessionId', $session->getId()) - ->setAttribute('sessionInternalId', $session->getSequence()); + ->setAttribute('sessionInternalId', $session->getInternalId()); $dbForProject->updateDocument('targets', $target->getId(), $target); } @@ -1931,7 +1931,7 @@ App::post('/v1/account/tokens/magic-url') 'accessedAt' => DateTime::now(), ]); - $user->removeAttribute('$sequence'); + $user->removeAttribute('$internalId'); Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); } @@ -1941,7 +1941,7 @@ App::post('/v1/account/tokens/magic-url') $token = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'type' => Auth::TOKEN_TYPE_MAGIC_URL, 'secret' => Auth::hash($tokenSecret), // One way hash encryption to protect DB leak 'expire' => $expire, @@ -2168,7 +2168,7 @@ App::post('/v1/account/tokens/email') 'accessedAt' => DateTime::now(), ]); - $user->removeAttribute('$sequence'); + $user->removeAttribute('$internalId'); Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); } @@ -2178,7 +2178,7 @@ App::post('/v1/account/tokens/email') $token = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'type' => Auth::TOKEN_TYPE_EMAIL, 'secret' => Auth::hash($tokenSecret), // One way hash encryption to protect DB leak 'expire' => $expire, @@ -2460,7 +2460,7 @@ App::post('/v1/account/tokens/phone') 'accessedAt' => DateTime::now(), ]); - $user->removeAttribute('$sequence'); + $user->removeAttribute('$internalId'); Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); try { $target = Authorization::skip(fn () => $dbForProject->createDocument('targets', new Document([ @@ -2470,7 +2470,7 @@ App::post('/v1/account/tokens/phone') Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'providerType' => MESSAGE_TYPE_SMS, 'identifier' => $phone, ]))); @@ -2501,7 +2501,7 @@ App::post('/v1/account/tokens/phone') $token = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'type' => Auth::TOKEN_TYPE_PHONE, 'secret' => Auth::hash($secret), 'expire' => $expire, @@ -2703,7 +2703,7 @@ App::get('/v1/account/logs') $audit = new EventAudit($dbForProject); - $logs = $audit->getLogsByUser($user->getSequence(), $queries); + $logs = $audit->getLogsByUser($user->getInternalId(), $queries); $output = []; @@ -2732,7 +2732,7 @@ App::get('/v1/account/logs') } $response->dynamic(new Document([ - 'total' => $audit->countLogsByUser($user->getSequence(), $queries), + 'total' => $audit->countLogsByUser($user->getInternalId(), $queries), 'logs' => $output, ]), Response::MODEL_LOG_LIST); }); @@ -2900,7 +2900,7 @@ App::patch('/v1/account/email') // Makes sure this email is not already used in another identity $identityWithMatchingEmail = $dbForProject->findOne('identities', [ Query::equal('providerEmail', [$email]), - Query::notEqual('userInternalId', $user->getSequence()), + Query::notEqual('userInternalId', $user->getInternalId()), ]); if (!$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */ @@ -3183,7 +3183,7 @@ App::post('/v1/account/recovery') $recovery = new Document([ '$id' => ID::unique(), 'userId' => $profile->getId(), - 'userInternalId' => $profile->getSequence(), + 'userInternalId' => $profile->getInternalId(), 'type' => Auth::TOKEN_TYPE_RECOVERY, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak 'expire' => $expire, @@ -3438,7 +3438,7 @@ App::post('/v1/account/verification') $verification = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'type' => Auth::TOKEN_TYPE_VERIFICATION, 'secret' => Auth::hash($verificationSecret), // One way hash encryption to protect DB leak 'expire' => $expire, @@ -3685,7 +3685,7 @@ App::post('/v1/account/verification/phone') $verification = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'type' => Auth::TOKEN_TYPE_PHONE, 'secret' => Auth::hash($secret), 'expire' => $expire, @@ -3979,7 +3979,7 @@ App::post('/v1/account/mfa/authenticators/:type') $authenticator = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'type' => Type::TOTP, 'verified' => false, 'data' => [ @@ -4292,7 +4292,7 @@ App::post('/v1/account/mfa/challenge') $code = Auth::codeGenerator(); $challenge = new Document([ 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'type' => $factor, 'token' => Auth::tokenGenerator(), 'code' => $code, @@ -4621,12 +4621,12 @@ App::post('/v1/account/targets/push') Permission::delete(Role::user($user->getId())), ], 'providerId' => !empty($providerId) ? $providerId : null, - 'providerInternalId' => !empty($providerId) ? $provider->getSequence() : null, + 'providerInternalId' => !empty($providerId) ? $provider->getInternalId() : null, 'providerType' => MESSAGE_TYPE_PUSH, 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'sessionId' => $session->getId(), - 'sessionInternalId' => $session->getSequence(), + 'sessionInternalId' => $session->getInternalId(), 'identifier' => $identifier, 'name' => "{$device['deviceBrand']} {$device['deviceModel']}" ])); @@ -4745,7 +4745,7 @@ App::delete('/v1/account/targets/:targetId/push') throw new Exception(Exception::USER_TARGET_NOT_FOUND); } - if ($user->getSequence() !== $target->getAttribute('userInternalId')) { + if ($user->getInternalId() !== $target->getAttribute('userInternalId')) { throw new Exception(Exception::USER_TARGET_NOT_FOUND); } @@ -4794,7 +4794,7 @@ App::get('/v1/account/identities') throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); } - $queries[] = Query::equal('userInternalId', [$user->getSequence()]); + $queries[] = Query::equal('userInternalId', [$user->getInternalId()]); /** * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index 3a7b4aa582..779a188089 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -669,7 +669,7 @@ App::get('/v1/cards/cloud') } } - $isPlatinum = $user->getSequence() % 100 === 0; + $isPlatinum = $user->getInternalId() % 100 === 0; } else { $name = $mock === 'normal-long' ? 'Sir First Walter O\'Brian Junior' : 'Walter O\'Brian'; $createdAt = new \DateTime('now'); @@ -859,7 +859,7 @@ App::get('/v1/cards/cloud-back') $isEmployee = \array_key_exists($email, $employees); $isGolden = $isEmployee || $isHero || $isContributor; - $isPlatinum = $user->getSequence() % 100 === 0; + $isPlatinum = $user->getInternalId() % 100 === 0; } else { $userId = '63e0bcf3c3eb803ba530'; @@ -926,9 +926,9 @@ App::get('/v1/cards/cloud-og') } if (!$mock) { - $sequence = $user->getSequence(); - $bgVariation = $sequence % 3 === 0 ? '1' : ($sequence % 3 === 1 ? '2' : '3'); - $cardVariation = $sequence % 3 === 0 ? '1' : ($sequence % 3 === 1 ? '2' : '3'); + $internalId = $user->getInternalId(); + $bgVariation = $internalId % 3 === 0 ? '1' : ($internalId % 3 === 1 ? '2' : '3'); + $cardVariation = $internalId % 3 === 0 ? '1' : ($internalId % 3 === 1 ? '2' : '3'); $name = $user->getAttribute('name', 'Anonymous'); $email = $user->getAttribute('email', ''); @@ -958,7 +958,7 @@ App::get('/v1/cards/cloud-og') } } - $isPlatinum = $user->getSequence() % 100 === 0; + $isPlatinum = $user->getInternalId() % 100 === 0; } else { $bgVariation = \str_ends_with($mock, '-bg2') ? '2' : (\str_ends_with($mock, '-bg3') ? '3' : '1'); $cardVariation = \str_ends_with($mock, '-right') ? '2' : (\str_ends_with($mock, '-middle') ? '3' : '1'); diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 4ff1c55fb3..4860f7a967 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -107,7 +107,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -130,7 +130,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att if ($type === Database::VAR_RELATIONSHIP) { $options['side'] = Database::RELATION_SIDE_PARENT; - $relatedCollection = $dbForProject->getDocument('database_' . $database->getSequence(), $options['relatedCollection'] ?? ''); + $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection'] ?? ''); if ($relatedCollection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND, 'The related collection was not found.'); } @@ -138,11 +138,11 @@ function createAttribute(string $databaseId, string $collectionId, Document $att try { $attribute = new Document([ - '$id' => ID::custom($database->getSequence() . '_' . $collection->getSequence() . '_' . $key), + '$id' => ID::custom($database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key), 'key' => $key, - 'databaseInternalId' => $database->getSequence(), + 'databaseInternalId' => $database->getInternalId(), 'databaseId' => $database->getId(), - 'collectionInternalId' => $collection->getSequence(), + 'collectionInternalId' => $collection->getInternalId(), 'collectionId' => $collectionId, 'type' => $type, 'status' => 'processing', // processing, available, failed, deleting, stuck @@ -164,13 +164,13 @@ function createAttribute(string $databaseId, string $collectionId, Document $att } catch (LimitException) { throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED); } catch (\Throwable $e) { - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); - $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); + $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); throw $e; } - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); - $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); + $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); if ($type === Database::VAR_RELATIONSHIP && $options['twoWay']) { $twoWayKey = $options['twoWayKey']; @@ -181,11 +181,11 @@ function createAttribute(string $databaseId, string $collectionId, Document $att try { try { $twoWayAttribute = new Document([ - '$id' => ID::custom($database->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $twoWayKey), + '$id' => ID::custom($database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $twoWayKey), 'key' => $twoWayKey, - 'databaseInternalId' => $database->getSequence(), + 'databaseInternalId' => $database->getInternalId(), 'databaseId' => $database->getId(), - 'collectionInternalId' => $relatedCollection->getSequence(), + 'collectionInternalId' => $relatedCollection->getInternalId(), 'collectionId' => $relatedCollection->getId(), 'type' => $type, 'status' => 'processing', // processing, available, failed, deleting, stuck @@ -213,13 +213,13 @@ function createAttribute(string $databaseId, string $collectionId, Document $att $dbForProject->deleteDocument('attributes', $attribute->getId()); throw $e; } finally { - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); - $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); + $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); } // If operation succeeded, purge the cache for the related collection too - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $relatedCollection->getId()); - $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); + $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); } $queueForDatabase @@ -262,12 +262,12 @@ function updateAttribute( throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $attribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key); + $attribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key); if ($attribute->isEmpty()) { throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); } @@ -292,7 +292,7 @@ function updateAttribute( throw new Exception(Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED, 'Cannot set default value for array attributes'); } - $collectionId = 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(); + $collectionId = 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(); $attribute ->setAttribute('default', $default) @@ -378,8 +378,8 @@ function updateAttribute( } if ($primaryDocumentOptions['twoWay']) { - $relatedCollection = $dbForProject->getDocument('database_' . $database->getSequence(), $primaryDocumentOptions['relatedCollection']); - $relatedAttribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $primaryDocumentOptions['twoWayKey']); + $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $primaryDocumentOptions['relatedCollection']); + $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $primaryDocumentOptions['twoWayKey']); if (!empty($newKey) && $newKey !== $key) { $options['twoWayKey'] = $newKey; @@ -389,8 +389,8 @@ function updateAttribute( $relatedAttribute->setAttribute('options', $relatedOptions); - $dbForProject->updateDocument('attributes', $database->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $primaryDocumentOptions['twoWayKey'], $relatedAttribute); - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $relatedCollection->getId()); + $dbForProject->updateDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $primaryDocumentOptions['twoWayKey'], $relatedAttribute); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); } } else { try { @@ -418,7 +418,7 @@ function updateAttribute( $originalUid = $attribute->getId(); $attribute - ->setAttribute('$id', ID::custom($database->getSequence() . '_' . $collection->getSequence() . '_' . $newKey)) + ->setAttribute('$id', ID::custom($database->getInternalId() . '_' . $collection->getInternalId() . '_' . $newKey)) ->setAttribute('key', $newKey); try { @@ -444,10 +444,10 @@ function updateAttribute( } } } else { - $attribute = $dbForProject->updateDocument('attributes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key, $attribute); + $attribute = $dbForProject->updateDocument('attributes', $database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key, $attribute); } - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collection->getId()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collection->getId()); $queueForEvents ->setContext('collection', $collection) @@ -536,7 +536,7 @@ App::post('/v1/databases') } try { - $dbForProject->createCollection('database_' . $database->getSequence(), $attributes, $indexes); + $dbForProject->createCollection('database_' . $database->getInternalId(), $attributes, $indexes); } catch (DuplicateException) { throw new Exception(Exception::DATABASE_ALREADY_EXISTS); } catch (IndexException) { @@ -839,7 +839,7 @@ App::delete('/v1/databases/:databaseId') } $dbForProject->purgeCachedDocument('databases', $database->getId()); - $dbForProject->purgeCachedCollection('databases_' . $database->getSequence()); + $dbForProject->purgeCachedCollection('databases_' . $database->getInternalId()); $queueForDatabase ->setType(DATABASE_TYPE_DELETE_DATABASE) @@ -899,9 +899,9 @@ App::post('/v1/databases/:databaseId/collections') $permissions = Permission::aggregate($permissions) ?? []; try { - $collection = $dbForProject->createDocument('database_' . $database->getSequence(), new Document([ + $collection = $dbForProject->createDocument('database_' . $database->getInternalId(), new Document([ '$id' => $collectionId, - 'databaseInternalId' => $database->getSequence(), + 'databaseInternalId' => $database->getInternalId(), 'databaseId' => $databaseId, '$permissions' => $permissions, 'documentSecurity' => $documentSecurity, @@ -919,7 +919,7 @@ App::post('/v1/databases/:databaseId/collections') try { $dbForProject->createCollection( - id: 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), + id: 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), permissions: $permissions, documentSecurity: $documentSecurity ); @@ -1000,7 +1000,7 @@ App::get('/v1/databases/:databaseId/collections') $collectionId = $cursor->getValue(); - $cursorDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $cursorDocument = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($cursorDocument->isEmpty()) { throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Collection '{$collectionId}' for the 'cursor' value not found."); @@ -1009,7 +1009,7 @@ App::get('/v1/databases/:databaseId/collections') $cursor->setValue($cursorDocument); } - $collectionId = 'database_' . $database->getSequence(); + $collectionId = 'database_' . $database->getInternalId(); try { $collections = $dbForProject->find($collectionId, $queries); @@ -1057,7 +1057,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -1100,8 +1100,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/logs') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collectionDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); - $collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collectionDocument->getSequence()); + $collectionDocument = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $collectionDocument->getInternalId()); if ($collectionDocument->isEmpty() || $collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -1215,7 +1215,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -1236,12 +1236,12 @@ App::put('/v1/databases/:databaseId/collections/:collectionId') ->setAttribute('search', \implode(' ', [$collectionId, $name])); $collection = $dbForProject->updateDocument( - 'database_' . $database->getSequence(), + 'database_' . $database->getInternalId(), $collectionId, $collection ); - $dbForProject->updateCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $permissions, $documentSecurity); + $dbForProject->updateCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $permissions, $documentSecurity); $queueForEvents ->setContext('database', $database) @@ -1287,17 +1287,17 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - if (!$dbForProject->deleteDocument('database_' . $database->getSequence(), $collectionId)) { + if (!$dbForProject->deleteDocument('database_' . $database->getInternalId(), $collectionId)) { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove collection from DB'); } - $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); + $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); $queueForDatabase ->setType(DATABASE_TYPE_DELETE_COLLECTION) @@ -1888,15 +1888,15 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/relati throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); - $collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $relatedCollectionDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId); - $relatedCollection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $relatedCollectionDocument->getSequence()); + $relatedCollectionDocument = $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId); + $relatedCollection = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $relatedCollectionDocument->getInternalId()); if ($relatedCollection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -1997,7 +1997,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -2010,8 +2010,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') \array_push( $queries, - Query::equal('databaseInternalId', [$database->getSequence()]), - Query::equal('collectionInternalId', [$collection->getSequence()]), + Query::equal('databaseInternalId', [$database->getInternalId()]), + Query::equal('collectionInternalId', [$collection->getInternalId()]), ); /** @@ -2033,8 +2033,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') try { $cursorDocument = $dbForProject->findOne('attributes', [ - Query::equal('databaseInternalId', [$database->getSequence()]), - Query::equal('collectionInternalId', [$collection->getSequence()]), + Query::equal('databaseInternalId', [$database->getInternalId()]), + Query::equal('collectionInternalId', [$collection->getInternalId()]), Query::equal('key', [$attributeId]), ]); } catch (QueryException $e) { @@ -2112,13 +2112,13 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes/:key') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $attribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key); + $attribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key); if ($attribute->isEmpty()) { throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); @@ -2725,13 +2725,13 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/attributes/:key throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $attribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key); + $attribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key); if ($attribute->isEmpty()) { throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); @@ -2754,19 +2754,19 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/attributes/:key $attribute = $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'deleting')); } - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); - $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); + $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); if ($attribute->getAttribute('type') === Database::VAR_RELATIONSHIP) { $options = $attribute->getAttribute('options'); if ($options['twoWay']) { - $relatedCollection = $dbForProject->getDocument('database_' . $database->getSequence(), $options['relatedCollection']); + $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $relatedAttribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $options['twoWayKey']); + $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); if ($relatedAttribute->isEmpty()) { throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); @@ -2776,8 +2776,8 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/attributes/:key $dbForProject->updateDocument('attributes', $relatedAttribute->getId(), $relatedAttribute->setAttribute('status', 'deleting')); } - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $options['relatedCollection']); - $dbForProject->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $options['relatedCollection']); + $dbForProject->purgeCachedCollection('database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); } } @@ -2859,7 +2859,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -2868,8 +2868,8 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') $limit = $dbForProject->getLimitForIndexes(); $count = $dbForProject->count('indexes', [ - Query::equal('collectionInternalId', [$collection->getSequence()]), - Query::equal('databaseInternalId', [$database->getSequence()]) + Query::equal('collectionInternalId', [$collection->getInternalId()]), + Query::equal('databaseInternalId', [$database->getInternalId()]) ], max: $limit); @@ -2939,12 +2939,12 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') } $index = new Document([ - '$id' => ID::custom($database->getSequence() . '_' . $collection->getSequence() . '_' . $key), + '$id' => ID::custom($database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key), 'key' => $key, 'status' => 'processing', // processing, available, failed, deleting, stuck - 'databaseInternalId' => $database->getSequence(), + 'databaseInternalId' => $database->getInternalId(), 'databaseId' => $databaseId, - 'collectionInternalId' => $collection->getSequence(), + 'collectionInternalId' => $collection->getInternalId(), 'collectionId' => $collectionId, 'type' => $type, 'attributes' => $attributes, @@ -2968,7 +2968,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') throw new Exception(Exception::INDEX_ALREADY_EXISTS); } - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); $queueForDatabase ->setType(DATABASE_TYPE_CREATE_INDEX) @@ -3020,7 +3020,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -3051,8 +3051,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes') $indexId = $cursor->getValue(); $cursorDocument = Authorization::skip(fn () => $dbForProject->find('indexes', [ - Query::equal('collectionInternalId', [$collection->getSequence()]), - Query::equal('databaseInternalId', [$database->getSequence()]), + Query::equal('collectionInternalId', [$collection->getInternalId()]), + Query::equal('databaseInternalId', [$database->getInternalId()]), Query::equal('key', [$indexId]), Query::limit(1) ])); @@ -3111,7 +3111,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes/:key') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -3164,13 +3164,13 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/indexes/:key') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $index = $dbForProject->getDocument('indexes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key); + $index = $dbForProject->getDocument('indexes', $database->getInternalId() . '_' . $collection->getInternalId() . '_' . $key); if ($index->isEmpty()) { throw new Exception(Exception::INDEX_NOT_FOUND); @@ -3181,7 +3181,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/indexes/:key') $index = $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'deleting')); } - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); $queueForDatabase ->setType(DATABASE_TYPE_DELETE_INDEX) @@ -3317,7 +3317,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); + $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -3426,7 +3426,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) ); foreach ($relations as &$relation) { @@ -3440,7 +3440,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') } if ($relation instanceof Document) { $current = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence(), $relation->getId()) + fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), $relation->getId()) ); if ($current->isEmpty()) { @@ -3495,7 +3495,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') try { $dbForProject->createDocuments( - 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), + 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documents ); } catch (DuplicateException) { @@ -3537,7 +3537,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) ); foreach ($related as $relation) { @@ -3554,7 +3554,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $operations)) - ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); // per collection + ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); // per collection $response->setStatusCode(Response::STATUS_CODE_CREATED); @@ -3612,7 +3612,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); + $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -3640,7 +3640,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $documentId = $cursor->getValue(); - $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId)); + $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId)); if ($cursorDocument->isEmpty()) { throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Document '{$documentId}' for the 'cursor' value not found."); @@ -3649,8 +3649,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $cursor->setValue($cursorDocument); } try { - $documents = $dbForProject->find('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $queries); - $total = $dbForProject->count('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $queries, APP_LIMIT_COUNT); + $documents = $dbForProject->find('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $queries); + $total = $dbForProject->count('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $queries, APP_LIMIT_COUNT); } catch (OrderException $e) { throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } catch (QueryException $e) { @@ -3694,7 +3694,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $relatedCollectionId = $relationship->getAttribute('relatedCollection'); // todo: Use local cache for this getDocument - $relatedCollection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId)); + $relatedCollection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId)); foreach ($relations as $index => $doc) { if ($doc instanceof Document) { @@ -3720,7 +3720,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_READS, \max(1, $operations)) - ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_READS), \max(1, $operations)); + ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_READS), \max(1, $operations)); $select = \array_reduce($queries, function ($result, $query) { return $result || ($query->getMethod() === Query::TYPE_SELECT); @@ -3791,7 +3791,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); + $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -3803,7 +3803,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen } try { - $document = $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId, $queries); + $document = $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId, $queries); } catch (QueryException $e) { throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); } @@ -3847,7 +3847,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) ); foreach ($related as $relation) { @@ -3862,7 +3862,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_READS, \max(1, $operations)) - ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_READS), \max(1, $operations)); + ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_READS), \max(1, $operations)); $response->dynamic($document, Response::MODEL_DOCUMENT); }); @@ -3901,12 +3901,12 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } - $document = $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId); + $document = $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId); if ($document->isEmpty()) { throw new Exception(Exception::DOCUMENT_NOT_FOUND); @@ -4030,13 +4030,13 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); + $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } // Read permission should not be required for update - $document = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId)); + $document = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId)); if ($document->isEmpty()) { throw new Exception(Exception::DOCUMENT_NOT_FOUND); } @@ -4105,7 +4105,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) ); foreach ($relations as &$relation) { @@ -4120,7 +4120,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum } if ($relation instanceof Document) { $oldDocument = Authorization::skip(fn () => $dbForProject->getDocument( - 'database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence(), + 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), $relation->getId() )); $relation->removeAttribute('$collectionId'); @@ -4128,7 +4128,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum // Attribute $collection is required for Utopia. $relation->setAttribute( '$collection', - 'database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence() + 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId() ); if ($oldDocument->isEmpty()) { @@ -4152,11 +4152,11 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $operations)) - ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); + ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); try { $document = $dbForProject->updateDocument( - 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), + 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $document->getId(), $newDocument ); @@ -4192,7 +4192,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) ); foreach ($related as $relation) { @@ -4274,7 +4274,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); + $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -4339,7 +4339,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) ); foreach ($relations as &$relation) { @@ -4354,7 +4354,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen } if ($relation instanceof Document) { $oldDocument = Authorization::skip(fn () => $dbForProject->getDocument( - 'database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence(), + 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), $relation->getId() )); $relation->removeAttribute('$collectionId'); @@ -4362,7 +4362,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen // Attribute $collection is required for Utopia. $relation->setAttribute( '$collection', - 'database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence() + 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId() ); if ($oldDocument->isEmpty()) { @@ -4386,12 +4386,12 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $operations)) - ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); + ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); $upserted = []; try { $modified = $dbForProject->createOrUpdateDocuments( - 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), + 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), [$newDocument], onNext: function (Document $document) use (&$upserted) { $upserted[] = $document; @@ -4430,7 +4430,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) ); foreach ($related as $relation) { @@ -4509,7 +4509,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -4540,7 +4540,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents') try { $modified = $dbForProject->updateDocuments( - 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), + 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), new Document($data), $queries, onNext: function (Document $document) use ($plan, &$documents) { @@ -4564,7 +4564,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents') $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $modified)) - ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $modified)); + ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $modified)); $response->dynamic(new Document([ 'total' => $modified, @@ -4609,7 +4609,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -4631,7 +4631,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents') try { $modified = $dbForProject->createOrUpdateDocuments( - 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), + 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documents, onNext: function (Document $document) use ($plan, &$upserted) { if (\count($upserted) < ($plan['databasesBatchSize'] ?? APP_LIMIT_DATABASE_BATCH)) { @@ -4656,7 +4656,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents') $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $modified)) - ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $modified)); + ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $modified)); $response->dynamic(new Document([ 'total' => $modified, @@ -4707,20 +4707,20 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents/:docu throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); + $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } // Read permission should not be required for delete - $document = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId)); + $document = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId)); if ($document->isEmpty()) { throw new Exception(Exception::DOCUMENT_NOT_FOUND); } try { $dbForProject->deleteDocument( - 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), + 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId ); } catch (ConflictException) { @@ -4755,7 +4755,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents/:docu $relatedCollectionId = $relationship->getAttribute('relatedCollection'); $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) + fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId) ); foreach ($related as $relation) { @@ -4770,7 +4770,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents/:docu $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $operations)) - ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); + ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); $relationships = \array_map( fn ($document) => $document->getAttribute('key'), @@ -4829,7 +4829,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception(Exception::DATABASE_NOT_FOUND); } - $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -4853,7 +4853,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents') try { $modified = $dbForProject->deleteDocuments( - 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), + 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $queries, onNext: function (Document $document) use ($plan, &$documents) { if (\count($documents) < ($plan['databasesBatchSize'] ?? APP_LIMIT_DATABASE_BATCH)) { @@ -4874,7 +4874,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents') $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, \max(1, $modified)) - ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $modified)); + ->addMetric(str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $modified)); $response->dynamic(new Document([ 'total' => $modified, @@ -5010,11 +5010,11 @@ App::get('/v1/databases/:databaseId/usage') $stats = $usage = []; $days = $periods[$range]; $metrics = [ - str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_COLLECTIONS), - str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_DOCUMENTS), - str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_STORAGE), - str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_READS), - str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES) + str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_COLLECTIONS), + str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_DOCUMENTS), + str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_STORAGE), + str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_READS), + str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_OPERATIONS_WRITES) ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { @@ -5103,8 +5103,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/usage') ->inject('dbForProject') ->action(function (string $databaseId, string $range, string $collectionId, Response $response, Database $dbForProject) { $database = $dbForProject->getDocument('databases', $databaseId); - $collectionDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); - $collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collectionDocument->getSequence()); + $collectionDocument = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + $collection = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $collectionDocument->getInternalId()); if ($collection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -5114,7 +5114,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/usage') $stats = $usage = []; $days = $periods[$range]; $metrics = [ - str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$database->getSequence(), $collectionDocument->getSequence()], METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS), + str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$database->getInternalId(), $collectionDocument->getInternalId()], METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS), ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 2bdaea3c2c..b95eb432a1 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -845,18 +845,15 @@ App::get('/v1/health/storage') $checkStart = \microtime(true); foreach ($devices as $device) { - $uniqueFileName = \uniqid('health', true); - $filePath = $device->getPath($uniqueFileName); - - if (!$device->write($filePath, 'test', 'text/plain')) { + if (!$device->write($device->getPath('health.txt'), 'test', 'text/plain')) { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed writing test file to ' . $device->getRoot()); } - if ($device->read($filePath) !== 'test') { + if ($device->read($device->getPath('health.txt')) !== 'test') { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed reading test file from ' . $device->getRoot()); } - if (!$device->delete($filePath)) { + if (!$device->delete($device->getPath('health.txt'))) { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed deleting test file from ' . $device->getRoot()); } } diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 0bc6f93787..1d11e6c392 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -2511,11 +2511,11 @@ App::post('/v1/messaging/topics/:topicId/subscribers') Permission::delete(Role::user($user->getId())), ], 'topicId' => $topicId, - 'topicInternalId' => $topic->getSequence(), + 'topicInternalId' => $topic->getInternalId(), 'targetId' => $targetId, - 'targetInternalId' => $target->getSequence(), + 'targetInternalId' => $target->getInternalId(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'providerType' => $target->getAttribute('providerType'), 'search' => implode(' ', [ $subscriberId, @@ -2597,7 +2597,7 @@ App::get('/v1/messaging/topics/:topicId/subscribers') throw new Exception(Exception::TOPIC_NOT_FOUND); } - $queries[] = Query::equal('topicInternalId', [$topic->getSequence()]); + $queries[] = Query::equal('topicInternalId', [$topic->getInternalId()]); /** * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries @@ -2947,7 +2947,7 @@ App::post('/v1/messaging/messages/email') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); @@ -2989,7 +2989,7 @@ App::post('/v1/messaging/messages/email') 'region' => $project->getAttribute('region'), 'resourceType' => 'message', 'resourceId' => $message->getId(), - 'resourceInternalId' => $message->getSequence(), + 'resourceInternalId' => $message->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -3112,7 +3112,7 @@ App::post('/v1/messaging/messages/sms') 'region' => $project->getAttribute('region'), 'resourceType' => 'message', 'resourceId' => $message->getId(), - 'resourceInternalId' => $message->getSequence(), + 'resourceInternalId' => $message->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -3232,7 +3232,7 @@ App::post('/v1/messaging/messages/push') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } @@ -3330,7 +3330,7 @@ App::post('/v1/messaging/messages/push') 'region' => $project->getAttribute('region'), 'resourceType' => 'message', 'resourceId' => $message->getId(), - 'resourceInternalId' => $message->getSequence(), + 'resourceInternalId' => $message->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -3731,7 +3731,7 @@ App::patch('/v1/messaging/messages/email/:messageId') 'region' => $project->getAttribute('region'), 'resourceType' => 'message', 'resourceId' => $message->getId(), - 'resourceInternalId' => $message->getSequence(), + 'resourceInternalId' => $message->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -3796,7 +3796,7 @@ App::patch('/v1/messaging/messages/email/:messageId') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); @@ -3933,7 +3933,7 @@ App::patch('/v1/messaging/messages/sms/:messageId') 'region' => $project->getAttribute('region'), 'resourceType' => 'message', 'resourceId' => $message->getId(), - 'resourceInternalId' => $message->getSequence(), + 'resourceInternalId' => $message->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -4107,7 +4107,7 @@ App::patch('/v1/messaging/messages/push/:messageId') 'region' => $project->getAttribute('region'), 'resourceType' => 'message', 'resourceId' => $message->getId(), - 'resourceInternalId' => $message->getSequence(), + 'resourceInternalId' => $message->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -4210,7 +4210,7 @@ App::patch('/v1/messaging/messages/push/:messageId') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index 92fca88744..494ccfcaac 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -345,7 +345,7 @@ App::post('/v1/migrations/csv') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); } diff --git a/app/controllers/api/project.php b/app/controllers/api/project.php index d09470ff39..047179b888 100644 --- a/app/controllers/api/project.php +++ b/app/controllers/api/project.php @@ -150,7 +150,7 @@ App::get('/v1/project/usage') $executionsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -166,7 +166,7 @@ App::get('/v1/project/usage') $executionsMbSecondsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -182,7 +182,7 @@ App::get('/v1/project/usage') $buildsMbSecondsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -198,7 +198,7 @@ App::get('/v1/project/usage') $bucketsBreakdown = array_map(function ($bucket) use ($dbForProject) { $id = $bucket->getId(); $name = $bucket->getAttribute('name'); - $metric = str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES_STORAGE); + $metric = str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES_STORAGE); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -214,7 +214,7 @@ App::get('/v1/project/usage') $databasesStorageBreakdown = array_map(function ($database) use ($dbForProject) { $id = $database->getId(); $name = $database->getAttribute('name'); - $metric = str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_STORAGE); + $metric = str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_STORAGE); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), @@ -231,13 +231,13 @@ App::get('/v1/project/usage') $functionsStorageBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $deploymentMetric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE); + $deploymentMetric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE); $deploymentValue = $dbForProject->findOne('stats', [ Query::equal('metric', [$deploymentMetric]), Query::equal('period', ['inf']) ]); - $buildMetric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE); + $buildMetric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE); $buildValue = $dbForProject->findOne('stats', [ Query::equal('metric', [$buildMetric]), Query::equal('period', ['inf']) @@ -255,7 +255,7 @@ App::get('/v1/project/usage') $executionsMbSecondsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) @@ -271,7 +271,7 @@ App::get('/v1/project/usage') $buildsMbSecondsBreakdown = array_map(function ($function) use ($dbForProject) { $id = $function->getId(); $name = $function->getAttribute('name'); - $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS); + $metric = str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS); $value = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), Query::equal('period', ['inf']) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 51cbc097f5..5eda8e9a0e 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -182,7 +182,7 @@ App::post('/v1/projects') Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], 'name' => $name, - 'teamInternalId' => $team->getSequence(), + 'teamInternalId' => $team->getInternalId(), 'teamId' => $team->getId(), 'region' => $region, 'description' => $description, @@ -230,13 +230,13 @@ App::post('/v1/projects') if ($sharedTables) { $dbForProject ->setSharedTables(true) - ->setTenant($sharedTablesV1 ? $project->getSequence() : null) + ->setTenant($sharedTablesV1 ? $project->getInternalId() : null) ->setNamespace($dsn->getParam('namespace')); } else { $dbForProject ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getSequence()); + ->setNamespace('_' . $project->getInternalId()); } $create = true; @@ -504,12 +504,12 @@ App::patch('/v1/projects/:projectId/team') $project ->setAttribute('teamId', $teamId) - ->setAttribute('teamInternalId', $team->getSequence()) + ->setAttribute('teamInternalId', $team->getInternalId()) ->setAttribute('$permissions', $permissions); $project = $dbForPlatform->updateDocument('projects', $project->getId(), $project); $installations = $dbForPlatform->find('installations', [ - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), ]); foreach ($installations as $installation) { $installation->getAttribute('$permissions', $permissions); @@ -517,7 +517,7 @@ App::patch('/v1/projects/:projectId/team') } $repositories = $dbForPlatform->find('repositories', [ - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), ]); foreach ($repositories as $repository) { $repository->getAttribute('$permissions', $permissions); @@ -525,7 +525,7 @@ App::patch('/v1/projects/:projectId/team') } $vcsComments = $dbForPlatform->find('vcsComments', [ - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), ]); foreach ($vcsComments as $vcsComment) { $vcsComment->getAttribute('$permissions', $permissions); @@ -1229,7 +1229,7 @@ App::post('/v1/projects/:projectId/webhooks') Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'projectId' => $project->getId(), 'name' => $name, 'events' => $events, @@ -1279,7 +1279,7 @@ App::get('/v1/projects/:projectId/webhooks') } $webhooks = $dbForPlatform->find('webhooks', [ - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), Query::limit(5000), ]); @@ -1320,7 +1320,7 @@ App::get('/v1/projects/:projectId/webhooks/:webhookId') $webhook = $dbForPlatform->findOne('webhooks', [ Query::equal('$id', [$webhookId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), ]); if ($webhook->isEmpty()) { @@ -1370,7 +1370,7 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId') $webhook = $dbForPlatform->findOne('webhooks', [ Query::equal('$id', [$webhookId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), ]); if ($webhook->isEmpty()) { @@ -1427,7 +1427,7 @@ App::patch('/v1/projects/:projectId/webhooks/:webhookId/signature') $webhook = $dbForPlatform->findOne('webhooks', [ Query::equal('$id', [$webhookId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), ]); if ($webhook->isEmpty()) { @@ -1474,7 +1474,7 @@ App::delete('/v1/projects/:projectId/webhooks/:webhookId') $webhook = $dbForPlatform->findOne('webhooks', [ Query::equal('$id', [$webhookId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), ]); if ($webhook->isEmpty()) { @@ -1528,7 +1528,7 @@ App::post('/v1/projects/:projectId/keys') Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'projectId' => $project->getId(), 'name' => $name, 'scopes' => $scopes, @@ -1576,7 +1576,7 @@ App::get('/v1/projects/:projectId/keys') } $keys = $dbForPlatform->find('keys', [ - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), Query::limit(5000), ]); @@ -1617,7 +1617,7 @@ App::get('/v1/projects/:projectId/keys/:keyId') $key = $dbForPlatform->findOne('keys', [ Query::equal('$id', [$keyId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), ]); if ($key->isEmpty()) { @@ -1661,7 +1661,7 @@ App::put('/v1/projects/:projectId/keys/:keyId') $key = $dbForPlatform->findOne('keys', [ Query::equal('$id', [$keyId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), ]); if ($key->isEmpty()) { @@ -1712,7 +1712,7 @@ App::delete('/v1/projects/:projectId/keys/:keyId') $key = $dbForPlatform->findOne('keys', [ Query::equal('$id', [$keyId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), ]); if ($key->isEmpty()) { @@ -1811,7 +1811,7 @@ App::post('/v1/projects/:projectId/platforms') Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'projectId' => $project->getId(), 'type' => $type, 'name' => $name, @@ -1858,7 +1858,7 @@ App::get('/v1/projects/:projectId/platforms') } $platforms = $dbForPlatform->find('platforms', [ - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), Query::limit(5000), ]); @@ -1899,7 +1899,7 @@ App::get('/v1/projects/:projectId/platforms/:platformId') $platform = $dbForPlatform->findOne('platforms', [ Query::equal('$id', [$platformId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), ]); if ($platform->isEmpty()) { @@ -1943,7 +1943,7 @@ App::put('/v1/projects/:projectId/platforms/:platformId') $platform = $dbForPlatform->findOne('platforms', [ Query::equal('$id', [$platformId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), ]); if ($platform->isEmpty()) { @@ -1997,7 +1997,7 @@ App::delete('/v1/projects/:projectId/platforms/:platformId') $platform = $dbForPlatform->findOne('platforms', [ Query::equal('$id', [$platformId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), ]); if ($platform->isEmpty()) { diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 417ea602ba..c1c8d8e4a0 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -58,7 +58,7 @@ App::get('/v1/proxy/rules') $queries[] = Query::search('search', $search); } - $queries[] = Query::equal('projectInternalId', [$project->getSequence()]); + $queries[] = Query::equal('projectInternalId', [$project->getInternalId()]); /** * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries @@ -124,7 +124,7 @@ App::get('/v1/proxy/rules/:ruleId') ->action(function (string $ruleId, Response $response, Document $project, Database $dbForPlatform) { $rule = $dbForPlatform->getDocument('rules', $ruleId); - if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) { + if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getInternalId()) { throw new Exception(Exception::RULE_NOT_FOUND); } @@ -165,7 +165,7 @@ App::delete('/v1/proxy/rules/:ruleId') ->action(function (string $ruleId, Response $response, Document $project, Database $dbForPlatform, Delete $queueForDeletes, Event $queueForEvents) { $rule = $dbForPlatform->getDocument('rules', $ruleId); - if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) { + if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getInternalId()) { throw new Exception(Exception::RULE_NOT_FOUND); } @@ -210,7 +210,7 @@ App::patch('/v1/proxy/rules/:ruleId/verification') ->action(function (string $ruleId, Response $response, Certificate $queueForCertificates, Event $queueForEvents, Document $project, Database $dbForPlatform, Log $log) { $rule = $dbForPlatform->getDocument('rules', $ruleId); - if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) { + if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getInternalId()) { throw new Exception(Exception::RULE_NOT_FOUND); } diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index a25241ec4b..b3b8fb906a 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -145,7 +145,7 @@ App::post('/v1/storage/buckets') $bucket = $dbForProject->getDocument('buckets', $bucketId); - $dbForProject->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes, permissions: $permissions ?? [], documentSecurity: $fileSecurity); + $dbForProject->createCollection('bucket_' . $bucket->getInternalId(), $attributes, $indexes, permissions: $permissions ?? [], documentSecurity: $fileSecurity); } catch (DuplicateException) { throw new Exception(Exception::STORAGE_BUCKET_ALREADY_EXISTS); } @@ -326,7 +326,7 @@ App::put('/v1/storage/buckets/:bucketId') ->setAttribute('compression', $compression) ->setAttribute('antivirus', $antivirus)); - $dbForProject->updateCollection('bucket_' . $bucket->getSequence(), $permissions, $fileSecurity); + $dbForProject->updateCollection('bucket_' . $bucket->getInternalId(), $permissions, $fileSecurity); $queueForEvents ->setParam('bucketId', $bucket->getId()); @@ -558,7 +558,7 @@ App::post('/v1/storage/buckets/:bucketId/files') $path = $deviceForFiles->getPath($fileId . '.' . \pathinfo($fileName, PATHINFO_EXTENSION)); $path = str_ireplace($deviceForFiles->getRoot(), $deviceForFiles->getRoot() . DIRECTORY_SEPARATOR . $bucket->getId(), $path); // Add bucket id to path after root - $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); $metadata = ['content_type' => $deviceForLocal->getFileMimeType($fileTmpName)]; if (!$file->isEmpty()) { @@ -652,7 +652,7 @@ App::post('/v1/storage/buckets/:bucketId/files') '$id' => $fileId, '$permissions' => $permissions, 'bucketId' => $bucket->getId(), - 'bucketInternalId' => $bucket->getSequence(), + 'bucketInternalId' => $bucket->getInternalId(), 'name' => $fileName, 'path' => $path, 'signature' => $fileHash, @@ -671,7 +671,7 @@ App::post('/v1/storage/buckets/:bucketId/files') 'metadata' => $metadata, ]); - $file = $dbForProject->createDocument('bucket_' . $bucket->getSequence(), $doc); + $file = $dbForProject->createDocument('bucket_' . $bucket->getInternalId(), $doc); } else { $file = $file ->setAttribute('$permissions', $permissions) @@ -696,7 +696,7 @@ App::post('/v1/storage/buckets/:bucketId/files') if (!$validator->isValid($bucket->getCreate())) { throw new Exception(Exception::USER_UNAUTHORIZED); } - $file = Authorization::skip(fn () => $dbForProject->updateDocument('bucket_' . $bucket->getSequence(), $fileId, $file)); + $file = Authorization::skip(fn () => $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file)); } } else { if ($file->isEmpty()) { @@ -704,7 +704,7 @@ App::post('/v1/storage/buckets/:bucketId/files') '$id' => ID::custom($fileId), '$permissions' => $permissions, 'bucketId' => $bucket->getId(), - 'bucketInternalId' => $bucket->getSequence(), + 'bucketInternalId' => $bucket->getInternalId(), 'name' => $fileName, 'path' => $path, 'signature' => '', @@ -720,7 +720,7 @@ App::post('/v1/storage/buckets/:bucketId/files') ]); try { - $file = $dbForProject->createDocument('bucket_' . $bucket->getSequence(), $doc); + $file = $dbForProject->createDocument('bucket_' . $bucket->getInternalId(), $doc); } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } @@ -741,7 +741,7 @@ App::post('/v1/storage/buckets/:bucketId/files') } try { - $file = Authorization::skip(fn () => $dbForProject->updateDocument('bucket_' . $bucket->getSequence(), $fileId, $file)); + $file = Authorization::skip(fn () => $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file)); } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } @@ -826,9 +826,9 @@ App::get('/v1/storage/buckets/:bucketId/files') $fileId = $cursor->getValue(); if ($fileSecurity && !$valid) { - $cursorDocument = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $cursorDocument = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); } else { - $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); + $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); } if ($cursorDocument->isEmpty()) { @@ -842,11 +842,11 @@ App::get('/v1/storage/buckets/:bucketId/files') try { if ($fileSecurity && !$valid) { - $files = $dbForProject->find('bucket_' . $bucket->getSequence(), $queries); - $total = $dbForProject->count('bucket_' . $bucket->getSequence(), $filterQueries, APP_LIMIT_COUNT); + $files = $dbForProject->find('bucket_' . $bucket->getInternalId(), $queries); + $total = $dbForProject->count('bucket_' . $bucket->getInternalId(), $filterQueries, APP_LIMIT_COUNT); } else { - $files = Authorization::skip(fn () => $dbForProject->find('bucket_' . $bucket->getSequence(), $queries)); - $total = Authorization::skip(fn () => $dbForProject->count('bucket_' . $bucket->getSequence(), $filterQueries, APP_LIMIT_COUNT)); + $files = Authorization::skip(fn () => $dbForProject->find('bucket_' . $bucket->getInternalId(), $queries)); + $total = Authorization::skip(fn () => $dbForProject->count('bucket_' . $bucket->getInternalId(), $filterQueries, APP_LIMIT_COUNT)); } } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); @@ -902,9 +902,9 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId') } if ($fileSecurity && !$valid) { - $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); } else { - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); } if ($file->isEmpty()) { @@ -973,7 +973,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getSequence(); + $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getInternalId(); $fileSecurity = $bucket->getAttribute('fileSecurity', false); $validator = new Authorization(Database::PERMISSION_READ); $valid = $validator->isValid($bucket->getRead()); @@ -982,12 +982,12 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview') } if ($fileSecurity && !$valid && !$isToken) { - $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); } else { - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); } - if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getSequence()) { + if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getInternalId()) { throw new Exception(Exception::USER_UNAUTHORIZED); } @@ -1150,7 +1150,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/download') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getSequence(); + $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getInternalId(); $fileSecurity = $bucket->getAttribute('fileSecurity', false); $validator = new Authorization(Database::PERMISSION_READ); $valid = $validator->isValid($bucket->getRead()); @@ -1159,12 +1159,12 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/download') } if ($fileSecurity && !$valid) { - $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); } else { - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); } - if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getSequence()) { + if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getInternalId()) { throw new Exception(Exception::USER_UNAUTHORIZED); } @@ -1309,7 +1309,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/view') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getSequence(); + $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getInternalId(); $fileSecurity = $bucket->getAttribute('fileSecurity', false); $validator = new Authorization(Database::PERMISSION_READ); $valid = $validator->isValid($bucket->getRead()); @@ -1318,12 +1318,12 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/view') } if ($fileSecurity && !$valid) { - $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); } else { - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); } - if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getSequence()) { + if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getInternalId()) { throw new Exception(Exception::USER_UNAUTHORIZED); } @@ -1478,7 +1478,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/push') throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); } - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); @@ -1643,7 +1643,7 @@ App::put('/v1/storage/buckets/:bucketId/files/:fileId') } // Read permission should not be required for update - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); @@ -1689,9 +1689,9 @@ App::put('/v1/storage/buckets/:bucketId/files/:fileId') try { if ($fileSecurity && !$valid) { - $file = $dbForProject->updateDocument('bucket_' . $bucket->getSequence(), $fileId, $file); + $file = $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file); } else { - $file = Authorization::skip(fn () => $dbForProject->updateDocument('bucket_' . $bucket->getSequence(), $fileId, $file)); + $file = Authorization::skip(fn () => $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file)); } } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); @@ -1757,7 +1757,7 @@ App::delete('/v1/storage/buckets/:bucketId/files/:fileId') } // Read permission should not be required for delete - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); @@ -1787,9 +1787,9 @@ App::delete('/v1/storage/buckets/:bucketId/files/:fileId') try { if ($fileSecurity && !$valid) { - $deleted = $dbForProject->deleteDocument('bucket_' . $bucket->getSequence(), $fileId); + $deleted = $dbForProject->deleteDocument('bucket_' . $bucket->getInternalId(), $fileId); } else { - $deleted = Authorization::skip(fn () => $dbForProject->deleteDocument('bucket_' . $bucket->getSequence(), $fileId)); + $deleted = Authorization::skip(fn () => $dbForProject->deleteDocument('bucket_' . $bucket->getInternalId(), $fileId)); } } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); @@ -1937,14 +1937,14 @@ App::get('/v1/storage/:bucketId/usage') $stats = $usage = []; $days = $periods[$range]; $metrics = [ - str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES), - str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES_STORAGE), - str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES_IMAGES_TRANSFORMED), + str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES), + str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES_STORAGE), + str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES_IMAGES_TRANSFORMED), ]; Authorization::skip(function () use ($dbForProject, $dbForLogs, $bucket, $days, $metrics, &$stats) { foreach ($metrics as $metric) { - $db = ($metric === str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES_IMAGES_TRANSFORMED)) + $db = ($metric === str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES_IMAGES_TRANSFORMED)) ? $dbForLogs : $dbForProject; diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index c83cad7eb1..49d9005c54 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -123,9 +123,9 @@ App::post('/v1/teams') Permission::delete(Role::team($team->getId(), 'owner')), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'teamId' => $team->getId(), - 'teamInternalId' => $team->getSequence(), + 'teamInternalId' => $team->getInternalId(), 'roles' => $roles, 'invited' => DateTime::now(), 'joined' => DateTime::now(), @@ -595,8 +595,8 @@ App::post('/v1/teams/:teamId/memberships') } $membership = $dbForProject->findOne('memberships', [ - Query::equal('userInternalId', [$invitee->getSequence()]), - Query::equal('teamInternalId', [$team->getSequence()]), + Query::equal('userInternalId', [$invitee->getInternalId()]), + Query::equal('teamInternalId', [$team->getInternalId()]), ]); $secret = Auth::tokenGenerator(); @@ -612,9 +612,9 @@ App::post('/v1/teams/:teamId/memberships') Permission::delete(Role::team($team->getId(), 'owner')), ], 'userId' => $invitee->getId(), - 'userInternalId' => $invitee->getSequence(), + 'userInternalId' => $invitee->getInternalId(), 'teamId' => $team->getId(), - 'teamInternalId' => $team->getSequence(), + 'teamInternalId' => $team->getInternalId(), 'roles' => $roles, 'invited' => DateTime::now(), 'joined' => ($isPrivilegedUser || $isAppUser) ? DateTime::now() : null, @@ -842,7 +842,7 @@ App::get('/v1/teams/:teamId/memberships') } // Set internal queries - $queries[] = Query::equal('teamInternalId', [$team->getSequence()]); + $queries[] = Query::equal('teamInternalId', [$team->getInternalId()]); /** * Get cursor document if there was a cursor query, we use array_filter and reset for reference $cursor to $queries @@ -1092,7 +1092,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId') collection: 'memberships', queries: [ Query::contains('roles', ['owner']), - Query::equal('teamInternalId', [$team->getSequence()]) + Query::equal('teamInternalId', [$team->getInternalId()]) ], max: 2 ); @@ -1180,7 +1180,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') throw new Exception(Exception::TEAM_NOT_FOUND); } - if ($membership->getAttribute('teamInternalId') !== $team->getSequence()) { + if ($membership->getAttribute('teamInternalId') !== $team->getInternalId()) { throw new Exception(Exception::TEAM_MEMBERSHIP_MISMATCH); } @@ -1197,7 +1197,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') $user->setAttributes($dbForProject->getDocument('users', $userId)->getArrayCopy()); // Get user } - if ($membership->getAttribute('userInternalId') !== $user->getSequence()) { + if ($membership->getAttribute('userInternalId') !== $user->getInternalId()) { throw new Exception(Exception::TEAM_INVITE_MISMATCH, 'Invite does not belong to current user (' . $user->getAttribute('email') . ')'); } @@ -1229,7 +1229,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => $user->getAttribute('email'), 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak @@ -1338,7 +1338,7 @@ App::delete('/v1/teams/:teamId/memberships/:membershipId') throw new Exception(Exception::TEAM_NOT_FOUND); } - if ($membership->getAttribute('teamInternalId') !== $team->getSequence()) { + if ($membership->getAttribute('teamInternalId') !== $team->getInternalId()) { throw new Exception(Exception::TEAM_MEMBERSHIP_MISMATCH); } diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 4b6e5abe6b..bc9de0fd42 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -140,7 +140,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'providerType' => 'email', 'identifier' => $email, ])); @@ -164,7 +164,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'providerType' => 'sms', 'identifier' => $phone, ])); @@ -564,10 +564,10 @@ App::post('/v1/users/:userId/targets') Permission::delete(Role::user($user->getId())), ], 'providerId' => empty($provider->getId()) ? null : $provider->getId(), - 'providerInternalId' => $provider->isEmpty() ? null : $provider->getSequence(), + 'providerInternalId' => $provider->isEmpty() ? null : $provider->getInternalId(), 'providerType' => $providerType, 'userId' => $userId, - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'identifier' => $identifier, 'name' => ($name !== '') ? $name : null, ])); @@ -846,7 +846,7 @@ App::get('/v1/users/:userId/memberships') } // Set internal queries - $queries[] = Query::equal('userInternalId', [$user->getSequence()]); + $queries[] = Query::equal('userInternalId', [$user->getInternalId()]); $memberships = array_map(function ($membership) use ($dbForProject, $user) { $team = $dbForProject->getDocument('teams', $membership->getAttribute('teamId')); @@ -910,7 +910,7 @@ App::get('/v1/users/:userId/logs') $audit = new Audit($dbForProject); - $logs = $audit->getLogsByUser($user->getSequence(), $queries); + $logs = $audit->getLogsByUser($user->getInternalId(), $queries); $output = []; @@ -957,7 +957,7 @@ App::get('/v1/users/:userId/logs') } $response->dynamic(new Document([ - 'total' => $audit->countLogsByUser($user->getSequence(), $queries), + 'total' => $audit->countLogsByUser($user->getInternalId(), $queries), 'logs' => $output, ]), Response::MODEL_LOG_LIST); }); @@ -1396,7 +1396,7 @@ App::patch('/v1/users/:userId/email') // Makes sure this email is not already used in another identity $identityWithMatchingEmail = $dbForProject->findOne('identities', [ Query::equal('providerEmail', [$email]), - Query::notEqual('userInternalId', $user->getSequence()), + Query::notEqual('userInternalId', $user->getInternalId()), ]); if (!$identityWithMatchingEmail->isEmpty()) { throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); @@ -1440,7 +1440,7 @@ App::patch('/v1/users/:userId/email') Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'providerType' => 'email', 'identifier' => $email, ])); @@ -1529,7 +1529,7 @@ App::patch('/v1/users/:userId/phone') Permission::delete(Role::user($user->getId())), ], 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'providerType' => 'sms', 'identifier' => $number, ])); @@ -1711,7 +1711,7 @@ App::patch('/v1/users/:userId/targets/:targetId') $target ->setAttribute('providerId', $provider->getId()) - ->setAttribute('providerInternalId', $provider->getSequence()); + ->setAttribute('providerInternalId', $provider->getInternalId()); } if ($name) { @@ -2051,7 +2051,7 @@ App::post('/v1/users/:userId/sessions') [ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'provider' => Auth::SESSION_PROVIDER_SERVER, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak 'userAgent' => $request->getUserAgent('UNKNOWN'), @@ -2131,7 +2131,7 @@ App::post('/v1/users/:userId/tokens') $token = new Document([ '$id' => ID::unique(), 'userId' => $user->getId(), - 'userInternalId' => $user->getSequence(), + 'userInternalId' => $user->getInternalId(), 'type' => Auth::TOKEN_TYPE_GENERIC, 'secret' => Auth::hash($secret), 'expire' => $expire, @@ -2293,8 +2293,8 @@ App::delete('/v1/users/:userId') $clone = clone $user; $dbForProject->deleteDocument('users', $userId); - DeleteIdentities::delete($dbForProject, Query::equal('userInternalId', [$user->getSequence()])); - DeleteTargets::delete($dbForProject, Query::equal('userInternalId', [$user->getSequence()])); + DeleteIdentities::delete($dbForProject, Query::equal('userInternalId', [$user->getInternalId()])); + DeleteTargets::delete($dbForProject, Query::equal('userInternalId', [$user->getInternalId()])); $queueForDeletes ->setType(DELETE_TYPE_DOCUMENT) diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 746f61c59c..571c7ddca7 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -78,11 +78,11 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId $resourceCollection = $resourceType === "function" ? 'functions' : 'sites'; $resourceId = $repository->getAttribute('resourceId'); $resource = Authorization::skip(fn () => $dbForProject->getDocument($resourceCollection, $resourceId)); - $resourceInternalId = $resource->getSequence(); + $resourceInternalId = $resource->getInternalId(); $deploymentId = ID::unique(); $repositoryId = $repository->getId(); - $repositoryInternalId = $repository->getSequence(); + $repositoryInternalId = $repository->getInternalId(); $providerRepositoryId = $repository->getAttribute('providerRepositoryId'); $installationId = $repository->getAttribute('installationId'); $installationInternalId = $repository->getAttribute('installationInternalId'); @@ -157,7 +157,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId ], 'installationInternalId' => $installationInternalId, 'installationId' => $installationId, - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'projectId' => $project->getId(), 'providerRepositoryId' => $providerRepositoryId, 'providerBranch' => $providerBranch, @@ -257,7 +257,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId $resource = $resource ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); Authorization::skip(fn () => $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource)); @@ -273,12 +273,12 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->getId(), - 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $resourceId, 'deploymentResourceInternalId' => $resourceInternalId, @@ -300,12 +300,12 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->getId(), - 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $resourceId, 'deploymentResourceInternalId' => $resourceInternalId, @@ -331,12 +331,12 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->getId(), - 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $resourceId, 'deploymentResourceInternalId' => $resourceInternalId, @@ -503,7 +503,7 @@ App::get('/v1/vcs/github/callback') $github->initializeVariables($providerInstallationId, $privateKey, $githubAppId); $owner = $github->getOwnerName($providerInstallationId) ?? ''; - $projectInternalId = $project->getSequence(); + $projectInternalId = $project->getInternalId(); $installation = $dbForPlatform->findOne('installations', [ Query::equal('providerInstallationId', [$providerInstallationId]), @@ -999,7 +999,7 @@ App::post('/v1/vcs/github/installations/:installationId/providerRepositories') if (empty($accessToken) || empty($refreshToken) || empty($accessTokenExpiry)) { $identity = $dbForPlatform->findOne('identities', [ Query::equal('provider', ['github']), - Query::equal('userInternalId', [$user->getSequence()]), + Query::equal('userInternalId', [$user->getInternalId()]), ]); if ($identity->isEmpty()) { throw new Exception(Exception::USER_IDENTITY_NOT_FOUND); @@ -1246,7 +1246,7 @@ App::post('/v1/vcs/github/events') foreach ($installations as $installation) { $repositories = Authorization::skip(fn () => $dbForPlatform->find('repositories', [ - Query::equal('installationInternalId', [$installation->getSequence()]), + Query::equal('installationInternalId', [$installation->getInternalId()]), Query::limit(1000) ])); @@ -1349,7 +1349,7 @@ App::get('/v1/vcs/installations') throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); } - $queries[] = Query::equal('projectInternalId', [$project->getSequence()]); + $queries[] = Query::equal('projectInternalId', [$project->getInternalId()]); if (!empty($search)) { $queries[] = Query::search('search', $search); @@ -1422,7 +1422,7 @@ App::get('/v1/vcs/installations/:installationId') throw new Exception(Exception::INSTALLATION_NOT_FOUND); } - if ($installation->getAttribute('projectInternalId') !== $project->getSequence()) { + if ($installation->getAttribute('projectInternalId') !== $project->getInternalId()) { throw new Exception(Exception::INSTALLATION_NOT_FOUND); } @@ -1505,7 +1505,7 @@ App::patch('/v1/vcs/github/installations/:installationId/repositories/:repositor } $repository = Authorization::skip(fn () => $dbForPlatform->getDocument('repositories', $repositoryId, [ - Query::equal('projectInternalId', [$project->getSequence()]) + Query::equal('projectInternalId', [$project->getInternalId()]) ])); if ($repository->isEmpty()) { diff --git a/app/controllers/general.php b/app/controllers/general.php index 90a108c7c6..bff701792e 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -391,9 +391,9 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $execution = new Document([ '$id' => $executionId, '$permissions' => [], - 'resourceInternalId' => $resource->getSequence(), + 'resourceInternalId' => $resource->getInternalId(), 'resourceId' => $resource->getId(), - 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), 'responseStatusCode' => 0, 'responseHeaders' => [], @@ -692,11 +692,11 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw } $metricTypeExecutions = str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS); - $metricTypeIdExecutions = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS); + $metricTypeIdExecutions = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS); $metricTypeExecutionsCompute = str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE); - $metricTypeIdExecutionsCompute = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE); + $metricTypeIdExecutionsCompute = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE); $metricTypeExecutionsMbSeconds = str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS); - $metricTypeIdExecutionsMBSeconds = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); + $metricTypeIdExecutionsMBSeconds = str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS); if ($deployment->getAttribute('resourceType') === 'sites') { $queueForStatsUsage ->disableMetric(METRIC_NETWORK_REQUESTS) @@ -719,9 +719,9 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw ->addMetric(METRIC_SITES_REQUESTS, 1) ->addMetric(METRIC_SITES_INBOUND, $request->getSize() + $fileSize) ->addMetric(METRIC_SITES_OUTBOUND, $response->getSize()) - ->addMetric(str_replace('{siteInternalId}', $resource->getSequence(), METRIC_SITES_ID_REQUESTS), 1) - ->addMetric(str_replace('{siteInternalId}', $resource->getSequence(), METRIC_SITES_ID_INBOUND), $request->getSize() + $fileSize) - ->addMetric(str_replace('{siteInternalId}', $resource->getSequence(), METRIC_SITES_ID_OUTBOUND), $response->getSize()) + ->addMetric(str_replace('{siteInternalId}', $resource->getInternalId(), METRIC_SITES_ID_REQUESTS), 1) + ->addMetric(str_replace('{siteInternalId}', $resource->getInternalId(), METRIC_SITES_ID_INBOUND), $request->getSize() + $fileSize) + ->addMetric(str_replace('{siteInternalId}', $resource->getInternalId(), METRIC_SITES_ID_OUTBOUND), $response->getSize()) ; } @@ -914,7 +914,7 @@ App::init() 'type' => 'api', 'status' => 'verifying', 'projectId' => $console->getId(), - 'projectInternalId' => $console->getSequence(), + 'projectInternalId' => $console->getInternalId(), 'search' => implode(' ', [$ruleId, $domain->get()]), 'owner' => $owner, 'region' => $console->getAttribute('region') @@ -964,7 +964,7 @@ App::init() )[0] ?? new Document(); } - if (!$rule->isEmpty() && $rule->getAttribute('projectInternalId') === $project->getSequence()) { + if (!$rule->isEmpty() && $rule->getAttribute('projectInternalId') === $project->getInternalId()) { $refDomainOrigin = $origin; } } diff --git a/app/controllers/mock.php b/app/controllers/mock.php index fd7b9ab495..16d8e03841 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -185,7 +185,7 @@ App::post('/v1/mock/api-key-unprefixed') Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'projectId' => $project->getId(), 'name' => 'Outdated key', 'scopes' => $scopes, @@ -235,7 +235,7 @@ App::get('/v1/mock/github/callback') $github->initializeVariables($providerInstallationId, $privateKey, $githubAppId); $owner = $github->getOwnerName($providerInstallationId) ?? ''; - $projectInternalId = $project->getSequence(); + $projectInternalId = $project->getInternalId(); $teamId = $project->getAttribute('teamId', ''); diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index f99ebbce07..937f245099 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -574,7 +574,7 @@ App::init() $bucketId = $parts[1] ?? null; $bucket = Authorization::skip(fn () => $dbForProject->getDocument('buckets', $bucketId)); - $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getSequence(); + $isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getInternalId(); $isAPIKey = Auth::isAppUser(Authorization::getRoles()); $isPrivilegedUser = Auth::isPrivilegedUser(Authorization::getRoles()); @@ -593,12 +593,12 @@ App::init() $fileId = $parts[1] ?? null; if ($fileSecurity && !$valid && !$isToken) { - $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); } else { - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); } - if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getSequence()) { + if (!$resourceToken->isEmpty() && $resourceToken->getAttribute('fileInternalId') !== $file->getInternalId()) { throw new Exception(Exception::USER_UNAUTHORIZED); } diff --git a/app/http.php b/app/http.php index 30f4013821..6064dfdd4c 100644 --- a/app/http.php +++ b/app/http.php @@ -309,7 +309,7 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg 'orders' => $index['orders'], ]), $files['indexes']); - $dbForPlatform->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes); + $dbForPlatform->createCollection('bucket_' . $bucket->getInternalId(), $attributes, $indexes); } if (Authorization::skip(fn () => $dbForPlatform->getDocument('buckets', 'screenshots')->isEmpty())) { @@ -357,7 +357,7 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg 'orders' => $index['orders'], ]), $files['indexes']); - Authorization::skip(fn () => $dbForPlatform->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes)); + Authorization::skip(fn () => $dbForPlatform->createCollection('bucket_' . $bucket->getInternalId(), $attributes, $indexes)); } }); diff --git a/app/init/database/filters.php b/app/init/database/filters.php index 98a37ec4ad..c470329706 100644 --- a/app/init/database/filters.php +++ b/app/init/database/filters.php @@ -71,7 +71,7 @@ Database::addFilter( }, function (mixed $value, Document $document, Database $database) { $attributes = $database->find('attributes', [ - Query::equal('collectionInternalId', [$document->getSequence()]), + Query::equal('collectionInternalId', [$document->getInternalId()]), Query::equal('databaseInternalId', [$document->getAttribute('databaseInternalId')]), Query::limit($database->getLimitForAttributes()), ]); @@ -107,7 +107,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('indexes', [ - Query::equal('collectionInternalId', [$document->getSequence()]), + Query::equal('collectionInternalId', [$document->getInternalId()]), Query::equal('databaseInternalId', [$document->getAttribute('databaseInternalId')]), Query::limit($database->getLimitForIndexes()), ]); @@ -122,7 +122,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('platforms', [ - Query::equal('projectInternalId', [$document->getSequence()]), + Query::equal('projectInternalId', [$document->getInternalId()]), Query::limit(APP_LIMIT_SUBQUERY), ]); } @@ -136,7 +136,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('keys', [ - Query::equal('projectInternalId', [$document->getSequence()]), + Query::equal('projectInternalId', [$document->getInternalId()]), Query::limit(APP_LIMIT_SUBQUERY), ]); } @@ -150,7 +150,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('devKeys', [ - Query::equal('projectInternalId', [$document->getSequence()]), + Query::equal('projectInternalId', [$document->getInternalId()]), Query::limit(APP_LIMIT_SUBQUERY), ]); } @@ -164,7 +164,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('webhooks', [ - Query::equal('projectInternalId', [$document->getSequence()]), + Query::equal('projectInternalId', [$document->getInternalId()]), Query::limit(APP_LIMIT_SUBQUERY), ]); } @@ -177,7 +177,7 @@ Database::addFilter( }, function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn () => $database->find('sessions', [ - Query::equal('userInternalId', [$document->getSequence()]), + Query::equal('userInternalId', [$document->getInternalId()]), Query::limit(APP_LIMIT_SUBQUERY), ])); } @@ -191,7 +191,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn () => $database ->find('tokens', [ - Query::equal('userInternalId', [$document->getSequence()]), + Query::equal('userInternalId', [$document->getInternalId()]), Query::limit(APP_LIMIT_SUBQUERY), ])); } @@ -205,7 +205,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn () => $database ->find('challenges', [ - Query::equal('userInternalId', [$document->getSequence()]), + Query::equal('userInternalId', [$document->getInternalId()]), Query::limit(APP_LIMIT_SUBQUERY), ])); } @@ -219,7 +219,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn () => $database ->find('authenticators', [ - Query::equal('userInternalId', [$document->getSequence()]), + Query::equal('userInternalId', [$document->getInternalId()]), Query::limit(APP_LIMIT_SUBQUERY), ])); } @@ -233,7 +233,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn () => $database ->find('memberships', [ - Query::equal('userInternalId', [$document->getSequence()]), + Query::equal('userInternalId', [$document->getInternalId()]), Query::limit(APP_LIMIT_SUBQUERY), ])); } @@ -247,7 +247,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database ->find('variables', [ - Query::equal('resourceInternalId', [$document->getSequence()]), + Query::equal('resourceInternalId', [$document->getInternalId()]), Query::equal('resourceType', ['function', 'site']), Query::limit(APP_LIMIT_SUBQUERY), ]); @@ -325,7 +325,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn () => $database ->find('targets', [ - Query::equal('userInternalId', [$document->getSequence()]), + Query::equal('userInternalId', [$document->getInternalId()]), Query::limit(APP_LIMIT_SUBQUERY) ])); } @@ -340,13 +340,13 @@ Database::addFilter( $targetIds = Authorization::skip(fn () => \array_map( fn ($document) => $document->getAttribute('targetInternalId'), $database->find('subscribers', [ - Query::equal('topicInternalId', [$document->getSequence()]), + Query::equal('topicInternalId', [$document->getInternalId()]), Query::limit(APP_LIMIT_SUBSCRIBERS_SUBQUERY) ]) )); if (\count($targetIds) > 0) { return $database->skipValidation(fn () => $database->find('targets', [ - Query::equal('$sequence', $targetIds) + Query::equal('$internalId', $targetIds) ])); } return []; diff --git a/app/init/resources.php b/app/init/resources.php index 7c3df681b1..c75df2a362 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -347,13 +347,13 @@ App::setResource('dbForProject', function (Group $pools, Database $dbForPlatform if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getSequence()) + ->setTenant($project->getInternalId()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getSequence()); + ->setNamespace('_' . $project->getInternalId()); } return $database; @@ -400,13 +400,13 @@ App::setResource('getProjectDB', function (Group $pools, Database $dbForPlatform if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getSequence()) + ->setTenant($project->getInternalId()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getSequence()); + ->setNamespace('_' . $project->getInternalId()); } }); @@ -430,7 +430,7 @@ App::setResource('getLogsDB', function (Group $pools, Cache $cache) { return function (?Document $project = null) use ($pools, $cache, &$database) { if ($database !== null && $project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getSequence()); + $database->setTenant($project->getInternalId()); return $database; } @@ -445,7 +445,7 @@ App::setResource('getLogsDB', function (Group $pools, Cache $cache) { // set tenant if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getSequence()); + $database->setTenant($project->getInternalId()); } return $database; @@ -836,7 +836,7 @@ App::setResource('team', function (Document $project, Database $dbForPlatform, A $team = Authorization::skip(function () use ($dbForPlatform, $teamInternalId) { return $dbForPlatform->findOne('teams', [ - Query::equal('$sequence', [$teamInternalId]), + Query::equal('$internalId', [$teamInternalId]), ]); }); @@ -915,10 +915,10 @@ App::setResource('resourceToken', function ($project, $dbForProject, $request) { return match ($token->getAttribute('resourceType')) { TOKENS_RESOURCE_TYPE_FILES => (function () use ($token, $dbForProject) { - $sequences = explode(':', $token->getAttribute('resourceInternalId')); + $internalIds = explode(':', $token->getAttribute('resourceInternalId')); $ids = explode(':', $token->getAttribute('resourceId')); - if (count($sequences) !== 2 || count($ids) !== 2) { + if (count($internalIds) !== 2 || count($ids) !== 2) { return new Document([]); } @@ -931,8 +931,8 @@ App::setResource('resourceToken', function ($project, $dbForProject, $request) { return new Document([ 'bucketId' => $ids[0], 'fileId' => $ids[1], - 'bucketInternalId' => $sequences[0], - 'fileInternalId' => $sequences[1], + 'bucketInternalId' => $internalIds[0], + 'fileInternalId' => $internalIds[1], ]); })(), diff --git a/app/realtime.php b/app/realtime.php index 96484c8a35..7e6fc0e311 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -79,8 +79,8 @@ if (!function_exists('getProjectDB')) { static $databases = []; - if (isset($databases[$project->getSequence()])) { - return $databases[$project->getSequence()]; + if (isset($databases[$project->getInternalId()])) { + return $databases[$project->getInternalId()]; } /** @var Group $pools */ @@ -105,20 +105,20 @@ if (!function_exists('getProjectDB')) { if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getSequence()) + ->setTenant($project->getInternalId()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getSequence()); + ->setNamespace('_' . $project->getInternalId()); } $database ->setMetadata('host', \gethostname()) ->setMetadata('project', $project->getId()); - return $databases[$project->getSequence()] = $database; + return $databases[$project->getInternalId()] = $database; } } diff --git a/app/worker.php b/app/worker.php index 2b6726c855..597e8a9943 100644 --- a/app/worker.php +++ b/app/worker.php @@ -90,13 +90,13 @@ Server::setResource('dbForProject', function (Cache $cache, Registry $register, if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getSequence()) + ->setTenant($project->getInternalId()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getSequence()); + ->setNamespace('_' . $project->getInternalId()); } $database->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_WORKER); @@ -127,13 +127,13 @@ Server::setResource('getProjectDB', function (Group $pools, Database $dbForPlatf if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getSequence()) + ->setTenant($project->getInternalId()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getSequence()); + ->setNamespace('_' . $project->getInternalId()); } return $database; @@ -149,13 +149,13 @@ Server::setResource('getProjectDB', function (Group $pools, Database $dbForPlatf if (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) - ->setTenant($project->getSequence()) + ->setTenant($project->getInternalId()) ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) - ->setNamespace('_' . $project->getSequence()); + ->setNamespace('_' . $project->getInternalId()); } $database->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_WORKER); @@ -168,7 +168,7 @@ Server::setResource('getLogsDB', function (Group $pools, Cache $cache) { $database = null; return function (?Document $project = null) use ($pools, $cache, $database) { if ($database !== null && $project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getSequence()); + $database->setTenant($project->getInternalId()); return $database; } @@ -183,7 +183,7 @@ Server::setResource('getLogsDB', function (Group $pools, Cache $cache) { // set tenant if ($project !== null && !$project->isEmpty() && $project->getId() !== 'console') { - $database->setTenant($project->getSequence()); + $database->setTenant($project->getInternalId()); } return $database; diff --git a/composer.json b/composer.json index 9b61351956..7e445cd36b 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,7 @@ "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", "utopia-php/detector": "0.1.*", - "utopia-php/database": "0.71.*", + "utopia-php/database": "0.69.*", "utopia-php/domains": "0.8.0", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", @@ -62,7 +62,7 @@ "utopia-php/locale": "0.4.*", "utopia-php/logger": "0.6.*", "utopia-php/messaging": "0.17.*", - "utopia-php/migration": "0.10.*", + "utopia-php/migration": "0.9.*", "utopia-php/orchestration": "0.9.*", "utopia-php/platform": "0.7.*", "utopia-php/pools": "0.8.*", diff --git a/composer.lock b/composer.lock index dc8661f3bb..f36b815777 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5027a541e6377eb2c87357b69f11daea", + "content-hash": "9f5de64d73e2ef73d796fa64f2baf232", "packages": [ { "name": "adhocore/jwt", @@ -1238,16 +1238,16 @@ }, { "name": "open-telemetry/exporter-otlp", - "version": "1.3.1", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/opentelemetry-php/exporter-otlp.git", - "reference": "8b3ca1f86d01429c73b407bf1a2075d9c187001e" + "reference": "19adf03d2b0f91f9e9b1c7f93db6c755c737cf6c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opentelemetry-php/exporter-otlp/zipball/8b3ca1f86d01429c73b407bf1a2075d9c187001e", - "reference": "8b3ca1f86d01429c73b407bf1a2075d9c187001e", + "url": "https://api.github.com/repos/opentelemetry-php/exporter-otlp/zipball/19adf03d2b0f91f9e9b1c7f93db6c755c737cf6c", + "reference": "19adf03d2b0f91f9e9b1c7f93db6c755c737cf6c", "shasum": "" }, "require": { @@ -1298,7 +1298,7 @@ "issues": "https://github.com/open-telemetry/opentelemetry-php/issues", "source": "https://github.com/open-telemetry/opentelemetry-php" }, - "time": "2025-05-21T12:02:20+00:00" + "time": "2025-05-12T00:36:35+00:00" }, { "name": "open-telemetry/gen-otlp-protobuf", @@ -1365,16 +1365,16 @@ }, { "name": "open-telemetry/sdk", - "version": "1.5.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/opentelemetry-php/sdk.git", - "reference": "cd0d7367599717fc29e04eb8838ec061e6c2c657" + "reference": "939d3a28395c249a763676458140dad44b3a8011" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opentelemetry-php/sdk/zipball/cd0d7367599717fc29e04eb8838ec061e6c2c657", - "reference": "cd0d7367599717fc29e04eb8838ec061e6c2c657", + "url": "https://api.github.com/repos/opentelemetry-php/sdk/zipball/939d3a28395c249a763676458140dad44b3a8011", + "reference": "939d3a28395c249a763676458140dad44b3a8011", "shasum": "" }, "require": { @@ -1451,7 +1451,7 @@ "issues": "https://github.com/open-telemetry/opentelemetry-php/issues", "source": "https://github.com/open-telemetry/opentelemetry-php" }, - "time": "2025-05-22T02:33:34+00:00" + "time": "2025-05-07T12:32:21+00:00" }, { "name": "open-telemetry/sem-conv", @@ -3499,16 +3499,16 @@ }, { "name": "utopia-php/database", - "version": "0.71.0", + "version": "0.69.5", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "cf463c0a5c64a4168fe56266ace4ae835d61c920" + "reference": "4abe53609dfc23b2ea82884d12b149df6a8af2f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/cf463c0a5c64a4168fe56266ace4ae835d61c920", - "reference": "cf463c0a5c64a4168fe56266ace4ae835d61c920", + "url": "https://api.github.com/repos/utopia-php/database/zipball/4abe53609dfc23b2ea82884d12b149df6a8af2f5", + "reference": "4abe53609dfc23b2ea82884d12b149df6a8af2f5", "shasum": "" }, "require": { @@ -3549,9 +3549,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.71.0" + "source": "https://github.com/utopia-php/database/tree/0.69.5" }, - "time": "2025-05-23T07:32:59+00:00" + "time": "2025-05-17T08:01:51+00:00" }, { "name": "utopia-php/detector", @@ -3999,16 +3999,16 @@ }, { "name": "utopia-php/migration", - "version": "0.10.0", + "version": "0.9.3", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "0b0e94c4b5243c5566b9634b07ba2ec5f7990914" + "reference": "e518d39eb550fde36bc5cf06c9bd7b2faf5dbedd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/0b0e94c4b5243c5566b9634b07ba2ec5f7990914", - "reference": "0b0e94c4b5243c5566b9634b07ba2ec5f7990914", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/e518d39eb550fde36bc5cf06c9bd7b2faf5dbedd", + "reference": "e518d39eb550fde36bc5cf06c9bd7b2faf5dbedd", "shasum": "" }, "require": { @@ -4049,9 +4049,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/0.10.0" + "source": "https://github.com/utopia-php/migration/tree/0.9.3" }, - "time": "2025-05-23T07:40:24+00:00" + "time": "2025-05-01T05:41:26+00:00" }, { "name": "utopia-php/orchestration", @@ -4816,16 +4816,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.40.18", + "version": "0.40.17", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "38de4b9c58112d7e83eb75955994c8412a401093" + "reference": "7e333c1003bfd4763e4d6f3a0a799fde5e7bc4de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/38de4b9c58112d7e83eb75955994c8412a401093", - "reference": "38de4b9c58112d7e83eb75955994c8412a401093", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/7e333c1003bfd4763e4d6f3a0a799fde5e7bc4de", + "reference": "7e333c1003bfd4763e4d6f3a0a799fde5e7bc4de", "shasum": "" }, "require": { @@ -4861,9 +4861,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.40.18" + "source": "https://github.com/appwrite/sdk-generator/tree/0.40.17" }, - "time": "2025-05-21T14:14:47+00:00" + "time": "2025-05-16T15:10:54+00:00" }, { "name": "doctrine/annotations", @@ -8242,7 +8242,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -8266,5 +8266,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/src/Appwrite/Deletes/Targets.php b/src/Appwrite/Deletes/Targets.php index 794ab0b87a..95e744ddf1 100644 --- a/src/Appwrite/Deletes/Targets.php +++ b/src/Appwrite/Deletes/Targets.php @@ -27,7 +27,7 @@ class Targets $database->deleteDocuments( 'subscribers', [ - Query::equal('targetInternalId', [$target->getSequence()]), + Query::equal('targetInternalId', [$target->getInternalId()]), Query::orderAsc(), ], Database::DELETE_BATCH_SIZE, @@ -35,7 +35,7 @@ class Targets $topicId = $subscriber->getAttribute('topicId'); $topicInternalId = $subscriber->getAttribute('topicInternalId'); $topic = $database->getDocument('topics', $topicId); - if (!$topic->isEmpty() && $topic->getSequence() === $topicInternalId) { + if (!$topic->isEmpty() && $topic->getInternalId() === $topicInternalId) { $totalAttribute = match ($target->getAttribute('providerType')) { MESSAGE_TYPE_EMAIL => 'emailTotal', MESSAGE_TYPE_SMS => 'smsTotal', diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index 934647f7c3..2c735ef2d4 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -320,7 +320,7 @@ class Event if ($this->project) { $trimmed['project'] = new Document([ '$id' => $this->project->getId(), - '$sequence' => $this->project->getSequence(), + '$internalId' => $this->project->getInternalId(), 'database' => $this->project->getAttribute('database') ]); } diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 73d16394c0..81ea1ef263 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -155,7 +155,7 @@ abstract class Migration */ public function forEachDocument(callable $callback): void { - $projectInternalId = $this->project->getSequence(); + $projectInternalId = $this->project->getInternalId(); $collections = match ($projectInternalId) { 'console' => $this->collections['console'], @@ -208,7 +208,7 @@ abstract class Migration { $name ??= $id; - $collectionType = match ($this->project->getSequence()) { + $collectionType = match ($this->project->getInternalId()) { 'console' => 'console', default => 'projects', }; @@ -259,7 +259,7 @@ abstract class Migration ): void { $from ??= $collectionId; - $collectionType = match ($this->project->getSequence()) { + $collectionType = match ($this->project->getInternalId()) { 'console' => 'console', default => 'projects', }; @@ -324,7 +324,7 @@ abstract class Migration ): void { $from ??= $collectionId; - $collectionType = match ($this->project->getSequence()) { + $collectionType = match ($this->project->getInternalId()) { 'console' => 'console', default => 'projects', }; @@ -382,7 +382,7 @@ abstract class Migration { $from ??= $collectionId; - $collectionType = match ($this->project->getSequence()) { + $collectionType = match ($this->project->getInternalId()) { 'console' => 'console', default => 'projects', }; @@ -428,7 +428,7 @@ abstract class Migration */ protected function changeAttributeInternalType(string $collection, string $attribute, string $type): void { - $stmt = $this->pdo->prepare("ALTER TABLE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$collection}` MODIFY `$attribute` $type;"); + $stmt = $this->pdo->prepare("ALTER TABLE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$collection}` MODIFY `$attribute` $type;"); try { $stmt->execute(); diff --git a/src/Appwrite/Migration/Version/V15.php b/src/Appwrite/Migration/Version/V15.php index 15331e9a37..8eab916f19 100644 --- a/src/Appwrite/Migration/Version/V15.php +++ b/src/Appwrite/Migration/Version/V15.php @@ -95,7 +95,7 @@ class V15 extends Migration $this->migrateStatsMetric('storage.files.delete', 'files.$all.requests.delete'); foreach ($this->documentsIterator('buckets') as $bucket) { - $bucketTable = "bucket_{$bucket->getSequence()}"; + $bucketTable = "bucket_{$bucket->getInternalId()}"; $this->createPermissionsColumn($bucketTable); $this->migrateDateTimeAttribute($bucketTable, '_createdAt'); @@ -178,7 +178,7 @@ class V15 extends Migration * Migrate every Database. */ foreach ($this->documentsIterator('databases') as $database) { - $databaseTable = "database_{$database->getSequence()}"; + $databaseTable = "database_{$database->getInternalId()}"; $this->createPermissionsColumn($databaseTable); $this->migrateDateTimeAttribute($databaseTable, '_createdAt'); $this->migrateDateTimeAttribute($databaseTable, '_updatedAt'); @@ -216,7 +216,7 @@ class V15 extends Migration */ Console::info("Migrating Collections of {$database->getId()} ({$database->getAttribute('name')})"); foreach ($this->documentsIterator($databaseTable) as $collection) { - $collectionTable = "{$databaseTable}_collection_{$collection->getSequence()}"; + $collectionTable = "{$databaseTable}_collection_{$collection->getInternalId()}"; $this->createPermissionsColumn($collectionTable); $this->migrateDateTimeAttribute($collectionTable, '_createdAt'); $this->migrateDateTimeAttribute($collectionTable, '_updatedAt'); @@ -277,7 +277,7 @@ class V15 extends Migration $this->removeWritePermissions($databaseTable); try { - $this->dbForProject->deleteAttribute("database_{$database->getSequence()}", 'permission'); + $this->dbForProject->deleteAttribute("database_{$database->getInternalId()}", 'permission'); } catch (\Throwable $th) { Console::warning("'permission' from {$databaseTable}: {$th->getMessage()}"); } @@ -293,7 +293,7 @@ class V15 extends Migration protected function removeWritePermissions(string $table): void { try { - $this->pdo->prepare("DELETE FROM `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$table}_perms` WHERE _type = 'write'")->execute(); + $this->pdo->prepare("DELETE FROM `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _type = 'write'")->execute(); } catch (\Throwable $th) { Console::warning("Remove 'write' permissions from {$table}: {$th->getMessage()}"); } @@ -309,7 +309,7 @@ class V15 extends Migration */ protected function getSQLColumnTypes(string $table): array { - $query = $this->pdo->prepare("SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '_{$this->project->getSequence()}_{$table}' AND table_schema = '{$this->dbForProject->getDatabase()}'"); + $query = $this->pdo->prepare("SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '_{$this->project->getInternalId()}_{$table}' AND table_schema = '{$this->dbForProject->getDatabase()}'"); $query->execute(); return array_reduce($query->fetchAll(), function (array $carry, array $item) { @@ -331,8 +331,8 @@ class V15 extends Migration if ($columns[$attribute] === 'int') { try { - $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$table}` MODIFY {$attribute} VARCHAR(64)")->execute(); - $this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$table}` SET {$attribute} = IF({$attribute} = 0, NULL, FROM_UNIXTIME({$attribute}))")->execute(); + $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} VARCHAR(64)")->execute(); + $this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` SET {$attribute} = IF({$attribute} = 0, NULL, FROM_UNIXTIME({$attribute}))")->execute(); $columns[$attribute] = 'varchar'; } catch (\Throwable $th) { Console::warning($th->getMessage()); @@ -341,7 +341,7 @@ class V15 extends Migration if ($columns[$attribute] === 'varchar') { try { - $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$table}` MODIFY {$attribute} DATETIME(3)")->execute(); + $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} DATETIME(3)")->execute(); } catch (\Throwable $th) { Console::warning($th->getMessage()); } @@ -387,7 +387,7 @@ class V15 extends Migration if (!array_key_exists('_permissions', $columns)) { try { - $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$table}` ADD `_permissions` MEDIUMTEXT DEFAULT NULL")->execute(); + $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` ADD `_permissions` MEDIUMTEXT DEFAULT NULL")->execute(); } catch (\Throwable $th) { Console::warning("Add '_permissions' column to '{$table}': {$th->getMessage()}"); } @@ -408,7 +408,7 @@ class V15 extends Migration { $table ??= $document->getCollection(); - $query = $this->pdo->prepare("SELECT * FROM `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_{$table}_perms` WHERE _document = '{$document->getId()}'"); + $query = $this->pdo->prepare("SELECT * FROM `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _document = '{$document->getId()}'"); $query->execute(); $results = $query->fetchAll(); $permissions = []; @@ -466,7 +466,7 @@ class V15 extends Migration Console::log("Migrating Collection \"{$id}\""); - $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); + $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); switch ($id) { case '_metadata': @@ -746,7 +746,7 @@ class V15 extends Migration Permission::delete(Role::any()), ], 'functionId' => $function->getId(), - 'functionInternalId' => $function->getSequence(), + 'functionInternalId' => $function->getInternalId(), 'key' => (string) $key, 'value' => (string) $value, 'search' => implode(' ', [$variableId, $key, $function->getId()]) @@ -1470,9 +1470,9 @@ class V15 extends Migration $from = $this->pdo->quote($from); $to = $this->pdo->quote($to); - $this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_stats` SET metric = {$to} WHERE metric = {$from}")->execute(); + $this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_stats` SET metric = {$to} WHERE metric = {$from}")->execute(); } catch (\Throwable $th) { - Console::warning("Migrating steps from {$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}_stats:" . $th->getMessage()); + Console::warning("Migrating steps from {$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_stats:" . $th->getMessage()); } } diff --git a/src/Appwrite/Migration/Version/V16.php b/src/Appwrite/Migration/Version/V16.php index 9d72af9563..34407a0471 100644 --- a/src/Appwrite/Migration/Version/V16.php +++ b/src/Appwrite/Migration/Version/V16.php @@ -45,7 +45,7 @@ class V16 extends Migration Console::log("Migrating Collection \"{$id}\""); - $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); + $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); switch ($id) { case 'sessions': diff --git a/src/Appwrite/Migration/Version/V17.php b/src/Appwrite/Migration/Version/V17.php index fbbd4bfde0..f7cb08d6f4 100644 --- a/src/Appwrite/Migration/Version/V17.php +++ b/src/Appwrite/Migration/Version/V17.php @@ -44,7 +44,7 @@ class V17 extends Migration protected function migrateBuckets(): void { foreach ($this->documentsIterator('buckets') as $bucket) { - $id = "bucket_{$bucket->getSequence()}"; + $id = "bucket_{$bucket->getInternalId()}"; try { $this->dbForProject->updateAttribute($id, 'mimeType', Database::VAR_STRING, 255, true, false); @@ -67,7 +67,7 @@ class V17 extends Migration Console::log("Migrating Collection \"{$id}\""); - $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); + $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); switch ($id) { case 'builds': diff --git a/src/Appwrite/Migration/Version/V18.php b/src/Appwrite/Migration/Version/V18.php index aa2ad35cca..a5fae3789b 100644 --- a/src/Appwrite/Migration/Version/V18.php +++ b/src/Appwrite/Migration/Version/V18.php @@ -26,7 +26,7 @@ class V18 extends Migration } Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')'); - $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); + $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); $this->addDocumentSecurityToProject(); Console::info('Migrating Databases'); @@ -48,12 +48,12 @@ class V18 extends Migration private function migrateDatabases(): void { foreach ($this->documentsIterator('databases') as $database) { - $databaseTable = "database_{$database->getSequence()}"; + $databaseTable = "database_{$database->getInternalId()}"; Console::info("Migrating Collections of {$database->getId()} ({$database->getAttribute('name')})"); foreach ($this->documentsIterator($databaseTable) as $collection) { - $collectionTable = "{$databaseTable}_collection_{$collection->getSequence()}"; + $collectionTable = "{$databaseTable}_collection_{$collection->getInternalId()}"; foreach ($collection['attributes'] ?? [] as $attribute) { if ($attribute['type'] !== Database::VAR_FLOAT) { @@ -197,7 +197,7 @@ class V18 extends Migration * Set the bucket permission in the metadata table */ try { - $internalBucketId = "bucket_{$this->project->getSequence()}"; + $internalBucketId = "bucket_{$this->project->getInternalId()}"; $permissions = $document->getPermissions(); $fileSecurity = $document->getAttribute('fileSecurity', false); $this->dbForProject->updateCollection($internalBucketId, $permissions, $fileSecurity); @@ -224,8 +224,8 @@ class V18 extends Migration // Nonetheless, there's nothing else we can do here. break; } - $sequence = $user->getSequence(); - $document->setAttribute('userId', $sequence); + $internalId = $user->getInternalId(); + $document->setAttribute('userId', $internalId); $data = $document->getAttribute('data', []); $data['userId'] = $user->getId(); $document->setAttribute('data', $data); @@ -244,7 +244,7 @@ class V18 extends Migration /** * Create 'documentSecurity' column */ - $this->pdo->prepare("ALTER TABLE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}__metadata` ADD COLUMN IF NOT EXISTS documentSecurity TINYINT(1);")->execute(); + $this->pdo->prepare("ALTER TABLE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}__metadata` ADD COLUMN IF NOT EXISTS documentSecurity TINYINT(1);")->execute(); } catch (\Throwable $th) { Console::warning($th->getMessage()); } @@ -253,7 +253,7 @@ class V18 extends Migration /** * Set 'documentSecurity' column to 1 if NULL */ - $this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getSequence()}__metadata` SET documentSecurity = 1 WHERE documentSecurity IS NULL")->execute(); + $this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}__metadata` SET documentSecurity = 1 WHERE documentSecurity IS NULL")->execute(); } catch (\Throwable $th) { Console::warning($th->getMessage()); } diff --git a/src/Appwrite/Migration/Version/V19.php b/src/Appwrite/Migration/Version/V19.php index d4dda02d75..cae27cc6ed 100644 --- a/src/Appwrite/Migration/Version/V19.php +++ b/src/Appwrite/Migration/Version/V19.php @@ -28,7 +28,7 @@ class V19 extends Migration } Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')'); - $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); + $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); Console::info('Migrating Collections'); $this->migrateCollections(); @@ -100,7 +100,7 @@ class V19 extends Migration protected function migrateBuckets(): void { foreach ($this->documentsIterator('buckets') as $bucket) { - $id = "bucket_{$bucket->getSequence()}"; + $id = "bucket_{$bucket->getInternalId()}"; Console::log("Migrating Bucket {$id} {$bucket->getId()} ({$bucket->getAttribute('name')})"); try { @@ -121,7 +121,7 @@ class V19 extends Migration */ private function migrateCollections(): void { - $internalProjectId = $this->project->getSequence(); + $internalProjectId = $this->project->getInternalId(); $collectionType = match ($internalProjectId) { 'console' => 'console', default => 'projects', @@ -680,7 +680,7 @@ class V19 extends Migration case 'builds': $deploymentId = $document->getAttribute('deploymentId'); $deployment = $this->dbForProject->getDocument('deployments', $deploymentId); - $document->setAttribute('deploymentInternalId', $deployment->getSequence()); + $document->setAttribute('deploymentInternalId', $deployment->getInternalId()); $stdout = $document->getAttribute('stdout', ''); $stderr = $document->getAttribute('stderr', ''); @@ -692,12 +692,12 @@ class V19 extends Migration case 'deployments': $resourceId = $document->getAttribute('resourceId'); $function = $this->dbForProject->getDocument('functions', $resourceId); - $document->setAttribute('resourceInternalId', $function->getSequence()); + $document->setAttribute('resourceInternalId', $function->getInternalId()); $buildId = $document->getAttribute('buildId'); if (!empty($buildId)) { $build = $this->dbForProject->getDocument('builds', $buildId); - $document->setAttribute('buildInternalId', $build->getSequence()); + $document->setAttribute('buildInternalId', $build->getInternalId()); } $commands = $this->getFunctionCommands($function); @@ -707,11 +707,11 @@ class V19 extends Migration case 'executions': $functionId = $document->getAttribute('functionId'); $function = $this->dbForProject->getDocument('functions', $functionId); - $document->setAttribute('functionInternalId', $function->getSequence()); + $document->setAttribute('functionInternalId', $function->getInternalId()); $deploymentId = $document->getAttribute('deploymentId'); $deployment = $this->dbForProject->getDocument('deployments', $deploymentId); - $document->setAttribute('deploymentInternalId', $deployment->getSequence()); + $document->setAttribute('deploymentInternalId', $deployment->getInternalId()); break; case 'functions': $document->setAttribute('live', $document->getAttribute('live', true)); @@ -721,7 +721,7 @@ class V19 extends Migration if (!empty($deploymentId)) { $deployment = $this->dbForProject->getDocument('deployments', $deploymentId); - $document->setAttribute('deploymentInternalId', $deployment->getSequence()); + $document->setAttribute('deploymentInternalId', $deployment->getInternalId()); $document->setAttribute('entrypoint', $deployment->getAttribute('entrypoint')); } @@ -733,7 +733,7 @@ class V19 extends Migration 'region' => $project->getAttribute('region'), 'resourceType' => 'function', 'resourceId' => $document->getId(), - 'resourceInternalId' => $document->getSequence(), + 'resourceInternalId' => $document->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $this->project->getId(), 'schedule' => $document->getAttribute('schedule'), @@ -741,7 +741,7 @@ class V19 extends Migration ])); $document->setAttribute('scheduleId', $schedule->getId()); - $document->setAttribute('scheduleInternalId', $schedule->getSequence()); + $document->setAttribute('scheduleInternalId', $schedule->getInternalId()); } break; @@ -799,7 +799,7 @@ class V19 extends Migration */ public function forEachDocument(callable $callback): void { - $internalProjectId = $this->project->getSequence(); + $internalProjectId = $this->project->getInternalId(); $collections = match ($internalProjectId) { 'console' => $this->collections['console'], diff --git a/src/Appwrite/Migration/Version/V20.php b/src/Appwrite/Migration/Version/V20.php index 9ff041eb33..3a9bba6772 100644 --- a/src/Appwrite/Migration/Version/V20.php +++ b/src/Appwrite/Migration/Version/V20.php @@ -36,13 +36,13 @@ class V20 extends Migration } Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')'); - $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); + $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); Console::info('Migrating Collections'); $this->migrateCollections(); // No need to migrate stats for console - if ($this->project->getSequence() !== 'console') { + if ($this->project->getInternalId() !== 'console') { $this->migrateUsageMetrics('project.$all.network.requests', 'network.requests'); $this->migrateUsageMetrics('project.$all.network.outbound', 'network.outbound'); $this->migrateUsageMetrics('project.$all.network.inbound', 'network.inbound'); @@ -71,7 +71,7 @@ class V20 extends Migration */ private function migrateCollections(): void { - $internalProjectId = $this->project->getSequence(); + $internalProjectId = $this->project->getInternalId(); $collectionType = match ($internalProjectId) { 'console' => 'console', default => 'projects', @@ -510,7 +510,7 @@ class V20 extends Migration Console::log("Migrating Functions usage stats of {$function->getId()} ({$function->getAttribute('name')})"); $functionId = $function->getId(); - $functionInternalId = $function->getSequence(); + $functionInternalId = $function->getInternalId(); $this->migrateUsageMetrics("deployment.$functionId.storage.size", "function.$functionInternalId.deployments.storage"); $this->migrateUsageMetrics("builds.$functionId.compute.total", "$functionInternalId.builds"); @@ -536,22 +536,22 @@ class V20 extends Migration foreach ($this->documentsIterator('databases') as $database) { Console::log("Migrating Collections of {$database->getId()} ({$database->getAttribute('name')})"); - $databaseTable = "database_{$database->getSequence()}"; + $databaseTable = "database_{$database->getInternalId()}"; // Database level $databaseId = $database->getId(); - $databaseInternalId = $database->getSequence(); + $databaseInternalId = $database->getInternalId(); $this->migrateUsageMetrics("collections.$databaseId.count.total", "$databaseInternalId.collections"); $this->migrateUsageMetrics("documents.$databaseId.count.total", "$databaseInternalId.documents"); foreach ($this->documentsIterator($databaseTable) as $collection) { - $collectionTable = "{$databaseTable}_collection_{$collection->getSequence()}"; + $collectionTable = "{$databaseTable}_collection_{$collection->getInternalId()}"; Console::log("Migrating Collections of {$collectionTable} {$collection->getId()} ({$collection->getAttribute('name')})"); // Collection level $collectionId = $collection->getId(); - $collectionInternalId = $collection->getSequence(); + $collectionInternalId = $collection->getInternalId(); $this->migrateUsageMetrics("documents.$databaseId/$collectionId.count.total", "$databaseInternalId.$collectionInternalId.documents"); } @@ -573,12 +573,12 @@ class V20 extends Migration $this->migrateUsageMetrics('files.$all.storage.size', 'files.storage'); foreach ($this->documentsIterator('buckets') as $bucket) { - $id = "bucket_{$bucket->getSequence()}"; + $id = "bucket_{$bucket->getInternalId()}"; Console::log("Migrating Bucket {$id} {$bucket->getId()} ({$bucket->getAttribute('name')})"); // Bucket level $bucketId = $bucket->getId(); - $bucketInternalId = $bucket->getSequence(); + $bucketInternalId = $bucket->getInternalId(); $this->migrateUsageMetrics("files.$bucketId.count.total", "$bucketInternalId.files"); $this->migrateUsageMetrics("files.$bucketId.storage.size", "$bucketInternalId.files.storage"); @@ -605,7 +605,7 @@ class V20 extends Migration $target = new Document([ '$id' => ID::unique(), 'userId' => $document->getId(), - 'userInternalId' => $document->getSequence(), + 'userInternalId' => $document->getInternalId(), 'providerType' => MESSAGE_TYPE_EMAIL, 'identifier' => $document->getAttribute('email'), ]); @@ -620,7 +620,7 @@ class V20 extends Migration $target = new Document([ '$id' => ID::unique(), 'userId' => $document->getId(), - 'userInternalId' => $document->getSequence(), + 'userInternalId' => $document->getInternalId(), 'providerType' => MESSAGE_TYPE_SMS, 'identifier' => $document->getAttribute('phone'), ]); diff --git a/src/Appwrite/Migration/Version/V21.php b/src/Appwrite/Migration/Version/V21.php index 891d2a92fe..38e8a8d513 100644 --- a/src/Appwrite/Migration/Version/V21.php +++ b/src/Appwrite/Migration/Version/V21.php @@ -29,12 +29,12 @@ class V21 extends Migration } Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')'); - $this->dbForProject->setNamespace("_{$this->project->getSequence()}"); + $this->dbForProject->setNamespace("_{$this->project->getInternalId()}"); Console::info('Migrating Collections'); $this->migrateCollections(); - if ($this->project->getSequence() !== 'console') { + if ($this->project->getInternalId() !== 'console') { Console::info('Migrating Buckets'); $this->migrateBuckets(); } @@ -51,7 +51,7 @@ class V21 extends Migration */ private function migrateCollections(): void { - $internalProjectId = $this->project->getSequence(); + $internalProjectId = $this->project->getInternalId(); $collectionType = match ($internalProjectId) { 'console' => 'console', default => 'projects', @@ -251,7 +251,7 @@ class V21 extends Migration private function migrateBuckets(): void { $this->dbForProject->forEach('buckets', function (Document $bucket) { - $bucketId = 'bucket_' . $bucket['$sequence']; + $bucketId = 'bucket_' . $bucket['$internalId']; Console::log("Migrating Bucket {$bucketId} {$bucket->getId()} ({$bucket->getAttribute('name')})"); diff --git a/src/Appwrite/Migration/Version/V22.php b/src/Appwrite/Migration/Version/V22.php index a99e07de59..50d5bdbb85 100644 --- a/src/Appwrite/Migration/Version/V22.php +++ b/src/Appwrite/Migration/Version/V22.php @@ -49,7 +49,7 @@ class V22 extends Migration */ private function migrateCollections(): void { - $projectInternalId = $this->project->getSequence(); + $projectInternalId = $this->project->getInternalId(); if (empty($projectInternalId)) { throw new Exception('Project ID is null'); @@ -394,7 +394,7 @@ class V22 extends Migration 2. Fill "deploymentCreatedAt" with deployment's "$createdAt" --- Fetch latestDeployment using find() 3. Fill latestDeploymentId with latestDeployment's "$id" - 4. Fill latestDeploymentInternalId with latestDeployment's "$sequence" + 4. Fill latestDeploymentInternalId with latestDeployment's "$internalId" 5. Fill latestDeploymentCreatedAt with latestDeployment's "$createdAt" 6. Fill latestDeploymentStatus with latestDeployment's build's "status" */ @@ -433,7 +433,7 @@ class V22 extends Migration $document ->setAttribute('latestDeploymentId', $latestDeployment->getId()) - ->setAttribute('latestDeploymentInternalId', $latestDeployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $latestDeployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $latestDeployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $latestBuild->getAttribute('status', $document->getAttribute('latestDeploymentStatus', ''))); break; @@ -497,7 +497,7 @@ class V22 extends Migration private function cleanCollections(): void { - $projectInternalId = $this->project->getSequence(); + $projectInternalId = $this->project->getInternalId(); $collectionType = match ($projectInternalId) { 'console' => 'console', diff --git a/src/Appwrite/Platform/Modules/Compute/Base.php b/src/Appwrite/Platform/Modules/Compute/Base.php index 71c436b0a0..47529a142b 100644 --- a/src/Appwrite/Platform/Modules/Compute/Base.php +++ b/src/Appwrite/Platform/Modules/Compute/Base.php @@ -69,13 +69,13 @@ class Base extends Action Permission::delete(Role::any()), ], 'resourceId' => $function->getId(), - 'resourceInternalId' => $function->getSequence(), + 'resourceInternalId' => $function->getInternalId(), 'resourceType' => 'functions', 'entrypoint' => $entrypoint, 'buildCommands' => $function->getAttribute('commands', ''), 'type' => 'vcs', 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getSequence(), + 'installationInternalId' => $installation->getInternalId(), 'providerRepositoryId' => $providerRepositoryId, 'repositoryId' => $function->getAttribute('repositoryId', ''), 'repositoryInternalId' => $function->getAttribute('repositoryInternalId', ''), @@ -95,7 +95,7 @@ class Base extends Action $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); @@ -166,7 +166,7 @@ class Base extends Action Permission::delete(Role::any()), ], 'resourceId' => $site->getId(), - 'resourceInternalId' => $site->getSequence(), + 'resourceInternalId' => $site->getInternalId(), 'resourceType' => 'sites', 'buildCommands' => implode(' && ', $commands), 'buildOutput' => $site->getAttribute('outputDirectory', ''), @@ -174,7 +174,7 @@ class Base extends Action 'fallbackFile' => $site->getAttribute('fallbackFile', ''), 'type' => 'vcs', 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getSequence(), + 'installationInternalId' => $installation->getInternalId(), 'providerRepositoryId' => $providerRepositoryId, 'repositoryId' => $site->getAttribute('repositoryId', ''), 'repositoryInternalId' => $site->getAttribute('repositoryInternalId', ''), @@ -194,7 +194,7 @@ class Base extends Action $site = $site ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('sites', $site->getId(), $site); @@ -209,15 +209,15 @@ class Base extends Action fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain, 'trigger' => 'deployment', 'type' => 'deployment', 'deploymentId' => $deployment->getId(), - 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $site->getId(), - 'deploymentResourceInternalId' => $site->getSequence(), + 'deploymentResourceInternalId' => $site->getInternalId(), 'deploymentVcsProviderBranch' => $providerBranch, 'status' => 'verified', 'certificateId' => '', @@ -244,7 +244,7 @@ class Base extends Action do { $queries = \array_merge([ Query::limit($limit), - Query::equal("projectInternalId", [$project->getSequence()]) + Query::equal("projectInternalId", [$project->getInternalId()]) ], $queries); if ($cursor !== null) { diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php index 007cea0252..1f3febbfef 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php @@ -237,7 +237,7 @@ class Create extends Action Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'resourceInternalId' => $function->getSequence(), + 'resourceInternalId' => $function->getInternalId(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', 'entrypoint' => $entrypoint, @@ -252,7 +252,7 @@ class Create extends Action $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); @@ -274,7 +274,7 @@ class Create extends Action Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'resourceInternalId' => $function->getSequence(), + 'resourceInternalId' => $function->getInternalId(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', 'entrypoint' => $entrypoint, @@ -291,7 +291,7 @@ class Create extends Action $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php index 912e12bdc1..84878055d8 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php @@ -101,7 +101,7 @@ class Delete extends Action if ($function->getAttribute('latestDeploymentId') === $deployment->getId()) { $latestDeployment = $dbForProject->findOne('deployments', [ Query::equal('resourceType', ['functions']), - Query::equal('resourceInternalId', [$function->getSequence()]), + Query::equal('resourceInternalId', [$function->getInternalId()]), Query::orderDesc('$createdAt'), ]); $function = $dbForProject->updateDocument( @@ -109,7 +109,7 @@ class Delete extends Action $function->getId(), $function ->setAttribute('latestDeploymentCreatedAt', $latestDeployment->isEmpty() ? '' : $latestDeployment->getCreatedAt()) - ->setAttribute('latestDeploymentInternalId', $latestDeployment->isEmpty() ? '' : $latestDeployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $latestDeployment->isEmpty() ? '' : $latestDeployment->getInternalId()) ->setAttribute('latestDeploymentId', $latestDeployment->isEmpty() ? '' : $latestDeployment->getId()) ->setAttribute('latestDeploymentStatus', $latestDeployment->isEmpty() ? '' : $latestDeployment->getAttribute('status', '')) ); 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 0a07440dff..8f739dd37f 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php @@ -96,9 +96,9 @@ class Create extends Action $destination = $deviceForFunctions->getPath($deploymentId . '.' . \pathinfo('code.tar.gz', PATHINFO_EXTENSION)); $deviceForFunctions->transfer($path, $destination, $deviceForFunctions); - $deployment->removeAttribute('$sequence'); + $deployment->removeAttribute('$internalId'); $deployment = $dbForProject->createDocument('deployments', $deployment->setAttributes([ - '$sequence' => '', + '$internalId' => '', '$id' => $deploymentId, 'sourcePath' => $destination, 'totalSize' => $deployment->getAttribute('sourceSize', 0), @@ -115,7 +115,7 @@ class Create extends Action $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); 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 4c924a64d1..c5436d1d05 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php @@ -97,7 +97,7 @@ class Update extends Action 'status' => 'canceled' ])); - if ($deployment->getSequence() === $function->getAttribute('latestDeploymentInternalId', '')) { + if ($deployment->getInternalId() === $function->getAttribute('latestDeploymentInternalId', '')) { $function = $function->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php index f1bd4b71e4..55230bd4a5 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php @@ -142,7 +142,7 @@ class Create extends Base Permission::delete(Role::any()), ], 'resourceId' => $function->getId(), - 'resourceInternalId' => $function->getSequence(), + 'resourceInternalId' => $function->getInternalId(), 'resourceType' => 'functions', 'entrypoint' => $function->getAttribute('entrypoint', ''), 'buildCommands' => $function->getAttribute('commands', ''), @@ -152,7 +152,7 @@ class Create extends Base $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php index 2ffcfc5d11..38f1f38e89 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php @@ -84,7 +84,7 @@ class XList extends Action } // Set resource queries - $queries[] = Query::equal('resourceInternalId', [$function->getSequence()]); + $queries[] = Query::equal('resourceInternalId', [$function->getInternalId()]); $queries[] = Query::equal('resourceType', ['functions']); /** diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index 0aec31e5fd..fd1b2076a8 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -253,10 +253,10 @@ class Create extends Base $execution = new Document([ '$id' => $executionId, '$permissions' => !$user->isEmpty() ? [Permission::read(Role::user($user->getId()))] : [], - 'resourceInternalId' => $function->getSequence(), + 'resourceInternalId' => $function->getInternalId(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', - 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), 'trigger' => (!is_null($scheduledAt)) ? 'schedule' : 'http', 'status' => $status, // waiting / processing / completed / failed / scheduled @@ -305,7 +305,7 @@ class Create extends Base 'region' => $project->getAttribute('region'), 'resourceType' => ScheduleExecutions::getSupportedResource(), 'resourceId' => $execution->getId(), - 'resourceInternalId' => $execution->getSequence(), + 'resourceInternalId' => $execution->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $scheduledAt, @@ -315,7 +315,7 @@ class Create extends Base $execution = $execution ->setAttribute('scheduleId', $schedule->getId()) - ->setAttribute('scheduleInternalId', $schedule->getSequence()) + ->setAttribute('scheduleInternalId', $schedule->getInternalId()) ->setAttribute('scheduledAt', $scheduledAt); $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution)); @@ -439,13 +439,13 @@ class Create extends Base $queueForStatsUsage ->addMetric(METRIC_EXECUTIONS, 1) ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS), 1) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ; $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution)); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Delete.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Delete.php index 8a3d5f2a49..cd85b5e534 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Delete.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Delete.php @@ -84,7 +84,7 @@ class Delete extends Base throw new Exception(Exception::EXECUTION_NOT_FOUND); } - if ($execution->getAttribute('resourceType') !== 'functions' && $execution->getAttribute('resourceInternalId') !== $function->getSequence()) { + if ($execution->getAttribute('resourceType') !== 'functions' && $execution->getAttribute('resourceInternalId') !== $function->getInternalId()) { throw new Exception(Exception::EXECUTION_NOT_FOUND); } $status = $execution->getAttribute('status'); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php index 659682ab55..892ce30f47 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Get.php @@ -72,7 +72,7 @@ class Get extends Base $execution = $dbForProject->getDocument('executions', $executionId); - if ($execution->getAttribute('resourceType') !== 'functions' || $execution->getAttribute('resourceInternalId') !== $function->getSequence()) { + if ($execution->getAttribute('resourceType') !== 'functions' || $execution->getAttribute('resourceInternalId') !== $function->getInternalId()) { throw new Exception(Exception::EXECUTION_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php index 91683c915b..a31e95b1c8 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php @@ -83,7 +83,7 @@ class XList extends Base } // Set internal queries - $queries[] = Query::equal('resourceInternalId', [$function->getSequence()]); + $queries[] = Query::equal('resourceInternalId', [$function->getInternalId()]); $queries[] = Query::equal('resourceType', ['functions']); /** diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php index c644c681d8..fd8da657eb 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php @@ -222,7 +222,7 @@ class Create extends Base 'search' => implode(' ', [$functionId, $name, $runtime]), 'version' => 'v5', 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getSequence(), + 'installationInternalId' => $installation->getInternalId(), 'providerRepositoryId' => $providerRepositoryId, 'repositoryId' => '', 'repositoryInternalId' => '', @@ -237,7 +237,7 @@ class Create extends Base 'region' => $project->getAttribute('region'), 'resourceType' => 'function', 'resourceId' => $function->getId(), - 'resourceInternalId' => $function->getSequence(), + 'resourceInternalId' => $function->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), 'projectId' => $project->getId(), 'schedule' => $function->getAttribute('schedule'), @@ -246,7 +246,7 @@ class Create extends Base ); $function->setAttribute('scheduleId', $schedule->getId()); - $function->setAttribute('scheduleInternalId', $schedule->getSequence()); + $function->setAttribute('scheduleInternalId', $schedule->getInternalId()); // Git connect logic if (!empty($providerRepositoryId)) { @@ -262,18 +262,18 @@ class Create extends Base Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getSequence(), + 'installationInternalId' => $installation->getInternalId(), 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'providerRepositoryId' => $providerRepositoryId, 'resourceId' => $function->getId(), - 'resourceInternalId' => $function->getSequence(), + 'resourceInternalId' => $function->getInternalId(), 'resourceType' => 'function', 'providerPullRequestIds' => [] ])); $function->setAttribute('repositoryId', $repository->getId()); - $function->setAttribute('repositoryInternalId', $repository->getSequence()); + $function->setAttribute('repositoryInternalId', $repository->getInternalId()); } $function = $dbForProject->updateDocument('functions', $function->getId(), $function); @@ -316,7 +316,7 @@ class Create extends Base $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); @@ -331,7 +331,7 @@ class Create extends Base Permission::delete(Role::any()), ], 'resourceId' => $function->getId(), - 'resourceInternalId' => $function->getSequence(), + 'resourceInternalId' => $function->getInternalId(), 'resourceType' => 'functions', 'entrypoint' => $function->getAttribute('entrypoint', ''), 'buildCommands' => $function->getAttribute('commands', ''), @@ -341,7 +341,7 @@ class Create extends Base $function = $function ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('functions', $function->getId(), $function); @@ -364,16 +364,16 @@ class Create extends Base fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain, 'status' => 'verified', 'type' => 'deployment', 'trigger' => 'manual', 'deploymentId' => !isset($deployment) || $deployment->isEmpty() ? '' : $deployment->getId(), - 'deploymentInternalId' => !isset($deployment) || $deployment->isEmpty() ? '' : $deployment->getSequence(), + 'deploymentInternalId' => !isset($deployment) || $deployment->isEmpty() ? '' : $deployment->getInternalId(), 'deploymentResourceType' => 'function', 'deploymentResourceId' => $function->getId(), - 'deploymentResourceInternalId' => $function->getSequence(), + 'deploymentResourceInternalId' => $function->getInternalId(), 'deploymentVcsProviderBranch' => '', 'certificateId' => '', 'search' => implode(' ', [$ruleId, $domain]), 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 1f3e39dee1..6de71cfae6 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php @@ -92,7 +92,7 @@ class Update extends Base $oldDeploymentInternalId = $function->getAttribute('deploymentInternalId', ''); $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ - 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), 'deploymentCreatedAt' => $deployment->getCreatedAt(), ]))); @@ -109,7 +109,7 @@ class Update extends Base Query::equal('trigger', 'manual'), Query::equal("type", ["deployment"]), Query::equal("deploymentResourceType", ["function"]), - Query::equal("deploymentResourceInternalId", [$function->getSequence()]), + Query::equal("deploymentResourceInternalId", [$function->getInternalId()]), ]; if (empty($oldDeploymentInternalId)) { @@ -121,7 +121,7 @@ class Update extends Base $this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { $rule = $rule ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); + ->setAttribute('deploymentInternalId', $deployment->getInternalId()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); }); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index 2bfe8b1344..a19ec1e278 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -175,8 +175,8 @@ class Update extends Base // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ - Query::equal('projectInternalId', [$project->getSequence()]), - Query::equal('resourceInternalId', [$function->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('resourceInternalId', [$function->getInternalId()]), Query::equal('resourceType', ['function']), Query::limit(100), ]); @@ -208,18 +208,18 @@ class Update extends Base Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getSequence(), + 'installationInternalId' => $installation->getInternalId(), 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'providerRepositoryId' => $providerRepositoryId, 'resourceId' => $function->getId(), - 'resourceInternalId' => $function->getSequence(), + 'resourceInternalId' => $function->getInternalId(), 'resourceType' => 'function', 'providerPullRequestIds' => [] ])); $repositoryId = $repository->getId(); - $repositoryInternalId = $repository->getSequence(); + $repositoryInternalId = $repository->getInternalId(); } $live = true; @@ -260,7 +260,7 @@ class Update extends Base 'commands' => $commands, 'scopes' => $scopes, 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getSequence(), + 'installationInternalId' => $installation->getInternalId(), 'providerRepositoryId' => $providerRepositoryId, 'repositoryId' => $repositoryId, 'repositoryInternalId' => $repositoryInternalId, diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php index 947da4cd37..e0d659c9ba 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Usage/Get.php @@ -70,17 +70,17 @@ class Get extends Base $stats = $usage = []; $days = $periods[$range]; $metrics = [ - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), ]; Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php index ee892fe1ed..9300524c64 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Create.php @@ -96,7 +96,7 @@ class Create extends Base Permission::delete(Role::team(ID::custom($teamId), 'owner')), Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], - 'resourceInternalId' => $function->getSequence(), + 'resourceInternalId' => $function->getInternalId(), 'resourceId' => $function->getId(), 'resourceType' => 'function', 'key' => $key, diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Delete.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Delete.php index dda1f97f6b..3d6bfebcb9 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Delete.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Delete.php @@ -74,7 +74,7 @@ class Delete extends Base } $variable = $dbForProject->getDocument('variables', $variableId); - if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $function->getSequence() || $variable->getAttribute('resourceType') !== 'function') { + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $function->getInternalId() || $variable->getAttribute('resourceType') !== 'function') { throw new Exception(Exception::VARIABLE_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php index 98119c4a66..70cc66219a 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Get.php @@ -68,7 +68,7 @@ class Get extends Base if ( $variable === false || $variable->isEmpty() || - $variable->getAttribute('resourceInternalId') !== $function->getSequence() || + $variable->getAttribute('resourceInternalId') !== $function->getInternalId() || $variable->getAttribute('resourceType') !== 'function' ) { throw new Exception(Exception::VARIABLE_NOT_FOUND); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Update.php index 7a6acf88e3..4102022267 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Variables/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Variables/Update.php @@ -81,7 +81,7 @@ class Update extends Base } $variable = $dbForProject->getDocument('variables', $variableId); - if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $function->getSequence() || $variable->getAttribute('resourceType') !== 'function') { + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $function->getInternalId() || $variable->getAttribute('resourceType') !== 'function') { throw new Exception(Exception::VARIABLE_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index a01250c05a..0ecf1d3f73 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -274,7 +274,7 @@ class Builds extends Action $deployment->setAttribute('status', 'processing'); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); - if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { + if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); } @@ -524,7 +524,7 @@ class Builds extends Action $deployment->setAttribute('status', 'building'); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); - if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { + if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); } @@ -887,9 +887,9 @@ class Builds extends Action if ($resource->getCollection() === 'sites') { try { $rule = Authorization::skip(fn () => $dbForPlatform->findOne('rules', [ - Query::equal("projectInternalId", [$project->getSequence()]), + Query::equal("projectInternalId", [$project->getInternalId()]), Query::equal("type", ["deployment"]), - Query::equal('deploymentInternalId', [$deployment->getSequence()]), + Query::equal('deploymentInternalId', [$deployment->getInternalId()]), ])); if ($rule->isEmpty()) { @@ -928,9 +928,9 @@ class Builds extends Action str_replace(["{resourceType}"], [RESOURCE_TYPE_SITES], METRIC_RESOURCE_TYPE_EXECUTIONS), str_replace(["{resourceType}"], [RESOURCE_TYPE_SITES], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), str_replace(["{resourceType}"], [RESOURCE_TYPE_SITES], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), - str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), - str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), - str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), + str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), + str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), + str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), ], 'bannerDisabled' => true, 'projectCheckDisabled' => true, @@ -1000,7 +1000,7 @@ class Builds extends Action Permission::read(Role::team(ID::custom($teamId))), ], 'bucketId' => $bucket->getId(), - 'bucketInternalId' => $bucket->getSequence(), + 'bucketInternalId' => $bucket->getInternalId(), 'name' => $fileName, 'path' => $path, 'signature' => $deviceForFiles->getFileHash($path), @@ -1019,7 +1019,7 @@ class Builds extends Action 'metadata' => ['content_type' => $deviceForFiles->getFileMimeType($path)], ]); - Authorization::skip(fn () => $dbForPlatform->createDocument('bucket_' . $bucket->getSequence(), $file)); + Authorization::skip(fn () => $dbForPlatform->createDocument('bucket_' . $bucket->getInternalId(), $file)); $deployment->setAttribute($key, $fileId); } @@ -1055,7 +1055,7 @@ class Builds extends Action $deployment->setAttribute('status', 'ready'); $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); - if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { + if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); } @@ -1078,14 +1078,14 @@ class Builds extends Action $oldDeploymentInternalId = $resource->getAttribute('deploymentInternalId', ''); $resource->setAttribute('deploymentId', $deployment->getId()); - $resource->setAttribute('deploymentInternalId', $deployment->getSequence()); + $resource->setAttribute('deploymentInternalId', $deployment->getInternalId()); $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); $resource = $dbForProject->updateDocument('functions', $resource->getId(), $resource); $queries = [ - Query::equal("projectInternalId", [$project->getSequence()]), + Query::equal("projectInternalId", [$project->getInternalId()]), Query::equal("type", ["deployment"]), - Query::equal("deploymentResourceInternalId", [$resource->getSequence()]), + Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]), Query::equal('deploymentResourceType', ['function']), Query::equal('trigger', ['manual']), ]; @@ -1101,7 +1101,7 @@ class Builds extends Action $rulesUpdated = true; $rule = $rule ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); + ->setAttribute('deploymentInternalId', $deployment->getInternalId()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); }); break; @@ -1109,15 +1109,15 @@ class Builds extends Action $oldDeploymentInternalId = $resource->getAttribute('deploymentInternalId', ''); $resource->setAttribute('deploymentId', $deployment->getId()); - $resource->setAttribute('deploymentInternalId', $deployment->getSequence()); + $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->getSequence()]), + Query::equal("projectInternalId", [$project->getInternalId()]), Query::equal("type", ["deployment"]), - Query::equal("deploymentResourceInternalId", [$resource->getSequence()]), + Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]), Query::equal('deploymentResourceType', ['site']), Query::equal('trigger', ['manual']), ]; @@ -1131,7 +1131,7 @@ class Builds extends Action $this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { $rule = $rule ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); + ->setAttribute('deploymentInternalId', $deployment->getInternalId()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); }); @@ -1151,15 +1151,15 @@ class Builds extends Action $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->getId(), - 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $deployment->getId(), - 'deploymentResourceInternalId' => $deployment->getSequence(), + 'deploymentResourceInternalId' => $deployment->getInternalId(), 'deploymentVcsProviderBranch' => $branchName, 'status' => 'verified', 'certificateId' => '', @@ -1171,21 +1171,21 @@ class Builds extends Action $rule = $dbForPlatform->getDocument('rules', $ruleId); $rule = $rule ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); + ->setAttribute('deploymentInternalId', $deployment->getInternalId()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); } $this->listRules($project, [ - Query::equal("projectInternalId", [$project->getSequence()]), + Query::equal("projectInternalId", [$project->getInternalId()]), Query::equal("type", ["deployment"]), - Query::equal("deploymentResourceInternalId", [$resource->getSequence()]), + Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]), Query::equal('deploymentResourceType', ['site']), Query::equal("deploymentVcsProviderBranch", [$branchName]), Query::equal("trigger", ['manual']), ], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { $rule = $rule ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); + ->setAttribute('deploymentInternalId', $deployment->getInternalId()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); }); } @@ -1250,7 +1250,7 @@ class Builds extends Action $deployment->setAttribute('buildLogs', $message); $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); - if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { + if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); } @@ -1285,8 +1285,8 @@ class Builds extends Action ->addMetric(METRIC_BUILDS_COMPUTE_SUCCESS, (int)$deployment->getAttribute('buildDuration', 0) * 1000) ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_SUCCESS), 1) // per function ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_COMPUTE_SUCCESS), (int)$deployment->getAttribute('buildDuration', 0) * 1000) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), 1) // per function - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_SUCCESS), (int)$deployment->getAttribute('buildDuration', 0) * 1000); + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), 1) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_SUCCESS), (int)$deployment->getAttribute('buildDuration', 0) * 1000); break; case 'failed': $queue @@ -1294,8 +1294,8 @@ class Builds extends Action ->addMetric(METRIC_BUILDS_COMPUTE_FAILED, (int)$deployment->getAttribute('buildDuration', 0) * 1000) ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_FAILED), 1) // per function ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_COMPUTE_FAILED), (int)$deployment->getAttribute('buildDuration', 0) * 1000) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), 1) // per function - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_FAILED), (int)$deployment->getAttribute('buildDuration', 0) * 1000); + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), 1) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE_FAILED), (int)$deployment->getAttribute('buildDuration', 0) * 1000); break; } @@ -1308,10 +1308,10 @@ class Builds extends Action ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_STORAGE), $deployment->getAttribute('buildSize', 0)) ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_COMPUTE), (int)$deployment->getAttribute('buildDuration', 0) * 1000) ->addMetric(str_replace(['{resourceType}'], [$deployment->getAttribute('resourceType')], METRIC_RESOURCE_TYPE_BUILDS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS), 1) // per function - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $deployment->getAttribute('buildSize', 0)) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), (int)$deployment->getAttribute('buildDuration', 0) * 1000) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), 1) // per function + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $deployment->getAttribute('buildSize', 0)) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), (int)$deployment->getAttribute('buildDuration', 0) * 1000) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [$deployment->getAttribute('resourceType'), $resource->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $deployment->getAttribute('buildDuration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->setProject($project) ->trigger(); } @@ -1469,9 +1469,9 @@ class Builds extends Action }; $rule = Authorization::skip(fn () => $dbForPlatform->findOne('rules', [ - Query::equal("projectInternalId", [$project->getSequence()]), + Query::equal("projectInternalId", [$project->getInternalId()]), Query::equal("type", ["deployment"]), - Query::equal("deploymentInternalId", [$deployment->getSequence()]), + Query::equal("deploymentInternalId", [$deployment->getInternalId()]), ])); $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; @@ -1499,7 +1499,7 @@ class Builds extends Action do { $queries = \array_merge([ Query::limit($limit), - Query::equal("projectInternalId", [$project->getSequence()]) + Query::equal("projectInternalId", [$project->getInternalId()]) ], $queries); if ($cursor !== null) { diff --git a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Create.php index 54ff189c20..43f7d4ac02 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Create.php @@ -76,7 +76,7 @@ class Create extends Action Permission::update(Role::user($user->getId())), Permission::delete(Role::user($user->getId())), ], - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'projectId' => $project->getId(), 'name' => $name, 'expire' => $expire, diff --git a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Delete.php b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Delete.php index eac42be5f0..f6cb966f50 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Delete.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Delete.php @@ -63,7 +63,7 @@ class Delete extends Action $key = $dbForPlatform->getDocument('devKeys', $keyId); - if ($key === false || $key->isEmpty() || $key->getAttribute('projectInternalId') !== $project->getSequence()) { + if ($key === false || $key->isEmpty() || $key->getAttribute('projectInternalId') !== $project->getInternalId()) { throw new Exception(Exception::KEY_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Get.php b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Get.php index 6255976de4..bd472b26e7 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Get.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Get.php @@ -63,7 +63,7 @@ class Get extends Action $key = $dbForPlatform->getDocument('devKeys', $keyId); - if ($key === false || $key->isEmpty() || $key->getAttribute('projectInternalId') !== $project->getSequence()) { + if ($key === false || $key->isEmpty() || $key->getAttribute('projectInternalId') !== $project->getInternalId()) { throw new Exception(Exception::KEY_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Update.php b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Update.php index 33b91eb0b6..d5e6839174 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Update.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/Update.php @@ -65,7 +65,7 @@ class Update extends Action $key = $dbForPlatform->getDocument('devKeys', $keyId); - if ($key === false || $key->isEmpty() || $key->getAttribute('projectInternalId') !== $project->getSequence()) { + if ($key === false || $key->isEmpty() || $key->getAttribute('projectInternalId') !== $project->getInternalId()) { throw new Exception(Exception::KEY_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/XList.php b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/XList.php index 73e79a783a..864531d32d 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/XList.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/DevKeys/XList.php @@ -71,7 +71,7 @@ class XList extends Action throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); } - $queries[] = Query::equal('projectInternalId', [$project->getSequence()]); + $queries[] = Query::equal('projectInternalId', [$project->getInternalId()]); $keys = $dbForPlatform->find('devKeys', $queries); diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php index 33eb5313a0..e4d0d2899f 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -153,7 +153,7 @@ class Create extends Action $rule = new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain->get(), 'status' => $status, 'type' => 'api', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php index 0b68b80aa3..6c5a87a68d 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php @@ -165,16 +165,16 @@ class Create extends Action $rule = new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain->get(), 'status' => $status, 'type' => 'deployment', 'trigger' => 'manual', 'deploymentId' => $deployment->isEmpty() ? '' : $deployment->getId(), - 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getSequence(), + 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getInternalId(), 'deploymentResourceType' => 'function', 'deploymentResourceId' => $function->getId(), - 'deploymentResourceInternalId' => $function->getSequence(), + 'deploymentResourceInternalId' => $function->getInternalId(), 'deploymentVcsProviderBranch' => $branch, 'certificateId' => '', 'search' => implode(' ', [$ruleId, $domain->get(), $branch]), diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php index ed84b8498b..d0c9dbbbe3 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php @@ -157,7 +157,7 @@ class Create extends Action $rule = new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain->get(), 'status' => $status, 'type' => 'redirect', diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php index 7c2a640cdf..894c954a32 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php @@ -165,16 +165,16 @@ class Create extends Action $rule = new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain->get(), 'status' => $status, 'type' => 'deployment', 'trigger' => 'manual', 'deploymentId' => $deployment->isEmpty() ? '' : $deployment->getId(), - 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getSequence(), + 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getInternalId(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $site->getId(), - 'deploymentResourceInternalId' => $site->getSequence(), + 'deploymentResourceInternalId' => $site->getInternalId(), 'deploymentVcsProviderBranch' => $branch, 'certificateId' => '', 'search' => implode(' ', [$ruleId, $domain->get(), $branch]), diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php index 77d7a80f70..13b1e0c830 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php @@ -246,7 +246,7 @@ class Create extends Action Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'resourceInternalId' => $site->getSequence(), + 'resourceInternalId' => $site->getInternalId(), 'resourceId' => $site->getId(), 'resourceType' => 'sites', 'buildCommands' => \implode(' && ', $commands), @@ -263,7 +263,7 @@ class Create extends Action $site = $site ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('sites', $site->getId(), $site); @@ -278,15 +278,15 @@ class Create extends Action fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->isEmpty() ? '' : $deployment->getId(), - 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getSequence(), + 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getInternalId(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $site->getId(), - 'deploymentResourceInternalId' => $site->getSequence(), + 'deploymentResourceInternalId' => $site->getInternalId(), 'status' => 'verified', 'certificateId' => '', 'search' => implode(' ', [$ruleId, $domain]), @@ -312,7 +312,7 @@ class Create extends Action Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'resourceInternalId' => $site->getSequence(), + 'resourceInternalId' => $site->getInternalId(), 'resourceId' => $site->getId(), 'resourceType' => 'sites', 'buildCommands' => \implode(' && ', $commands), @@ -331,7 +331,7 @@ class Create extends Action $site = $site ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('sites', $site->getId(), $site); @@ -343,7 +343,7 @@ class Create extends Action fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php index 8717d04fc2..27db10c484 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php @@ -101,7 +101,7 @@ class Delete extends Action if ($site->getAttribute('latestDeploymentId') === $deployment->getId()) { $latestDeployment = $dbForProject->findOne('deployments', [ Query::equal('resourceType', ['sites']), - Query::equal('resourceInternalId', [$site->getSequence()]), + Query::equal('resourceInternalId', [$site->getInternalId()]), Query::orderDesc('$createdAt'), ]); $site = $dbForProject->updateDocument( @@ -109,7 +109,7 @@ class Delete extends Action $site->getId(), $site ->setAttribute('latestDeploymentCreatedAt', $latestDeployment->isEmpty() ? '' : $latestDeployment->getCreatedAt()) - ->setAttribute('latestDeploymentInternalId', $latestDeployment->isEmpty() ? '' : $latestDeployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $latestDeployment->isEmpty() ? '' : $latestDeployment->getInternalId()) ->setAttribute('latestDeploymentId', $latestDeployment->isEmpty() ? '' : $latestDeployment->getId()) ->setAttribute('latestDeploymentStatus', $latestDeployment->isEmpty() ? '' : $latestDeployment->getAttribute('status', '')) ); 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 739c701a2e..bff0735328 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php @@ -110,9 +110,9 @@ class Create extends Action $commands[] = $site->getAttribute('buildCommand', ''); } - $deployment->removeAttribute('$sequence'); + $deployment->removeAttribute('$internalId'); $deployment = $dbForProject->createDocument('deployments', $deployment->setAttributes([ - '$sequence' => '', + '$internalId' => '', '$id' => $deploymentId, 'sourcePath' => $destination, 'totalSize' => $deployment->getAttribute('sourceSize', 0), @@ -134,7 +134,7 @@ class Create extends Action $site = $site ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('sites', $site->getId(), $site); @@ -150,15 +150,15 @@ class Create extends Action fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->isEmpty() ? '' : $deployment->getId(), - 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getSequence(), + 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getInternalId(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $site->getId(), - 'deploymentResourceInternalId' => $site->getSequence(), + 'deploymentResourceInternalId' => $site->getInternalId(), 'status' => 'verified', 'certificateId' => '', 'owner' => 'Appwrite', 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 046ddd1ac8..2c6da43893 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php @@ -95,7 +95,7 @@ class Update extends Action 'status' => 'canceled' ])); - if ($deployment->getSequence() === $site->getAttribute('latestDeploymentInternalId', '')) { + if ($deployment->getInternalId() === $site->getAttribute('latestDeploymentInternalId', '')) { $site = $site->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('sites', $site->getId(), $site); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php index 5de688fbf8..5b29521ce5 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php @@ -153,7 +153,7 @@ class Create extends Base Permission::delete(Role::any()), ], 'resourceId' => $site->getId(), - 'resourceInternalId' => $site->getSequence(), + 'resourceInternalId' => $site->getInternalId(), 'resourceType' => 'sites', 'buildCommands' => \implode(' && ', $commands), 'buildOutput' => $site->getAttribute('outputDirectory', ''), @@ -165,7 +165,7 @@ class Create extends Base $site = $site ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentInternalId', $deployment->getInternalId()) ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument('sites', $site->getId(), $site); @@ -180,15 +180,15 @@ class Create extends Base fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'domain' => $domain, 'type' => 'deployment', 'trigger' => 'deployment', 'deploymentId' => $deployment->isEmpty() ? '' : $deployment->getId(), - 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getSequence(), + 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getInternalId(), 'deploymentResourceType' => 'site', 'deploymentResourceId' => $site->getId(), - 'deploymentResourceInternalId' => $site->getSequence(), + 'deploymentResourceInternalId' => $site->getInternalId(), 'status' => 'verified', 'certificateId' => '', 'owner' => 'Appwrite', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php index 306f756d87..d7cfc1d3ad 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php @@ -79,7 +79,7 @@ class XList extends Action } // Set resource queries - $queries[] = Query::equal('resourceInternalId', [$site->getSequence()]); + $queries[] = Query::equal('resourceInternalId', [$site->getInternalId()]); $queries[] = Query::equal('resourceType', ['sites']); /** diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Logs/Delete.php b/src/Appwrite/Platform/Modules/Sites/Http/Logs/Delete.php index 2d87321086..a411cee91f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Logs/Delete.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Logs/Delete.php @@ -71,7 +71,7 @@ class Delete extends Base throw new Exception(Exception::LOG_NOT_FOUND); } - if ($log->getAttribute('resourceType') !== 'sites' && $log->getAttribute('resourceInternalId') !== $site->getSequence()) { + if ($log->getAttribute('resourceType') !== 'sites' && $log->getAttribute('resourceInternalId') !== $site->getInternalId()) { throw new Exception(Exception::LOG_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php index 2ef7d75539..3d1ace2d20 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Logs/Get.php @@ -63,7 +63,7 @@ class Get extends Base $log = $dbForProject->getDocument('executions', $logId); - if ($log->getAttribute('resourceType') !== 'sites' && $log->getAttribute('resourceInternalId') !== $site->getSequence()) { + if ($log->getAttribute('resourceType') !== 'sites' && $log->getAttribute('resourceInternalId') !== $site->getInternalId()) { throw new Exception(Exception::LOG_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php index 7e2c587797..a873d32603 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php @@ -75,7 +75,7 @@ class XList extends Base } // Set internal queries - $queries[] = Query::equal('resourceInternalId', [$site->getSequence()]); + $queries[] = Query::equal('resourceInternalId', [$site->getInternalId()]); $queries[] = Query::equal('resourceType', ['sites']); /** diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php index 6dd1865047..c509799024 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php @@ -154,7 +154,7 @@ class Create extends Base 'search' => implode(' ', [$siteId, $name, $framework]), 'fallbackFile' => $fallbackFile, 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getSequence(), + 'installationInternalId' => $installation->getInternalId(), 'providerRepositoryId' => $providerRepositoryId, 'repositoryId' => '', 'repositoryInternalId' => '', @@ -180,18 +180,18 @@ class Create extends Base Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getSequence(), + 'installationInternalId' => $installation->getInternalId(), 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'providerRepositoryId' => $providerRepositoryId, 'resourceId' => $site->getId(), - 'resourceInternalId' => $site->getSequence(), + 'resourceInternalId' => $site->getInternalId(), 'resourceType' => 'site', 'providerPullRequestIds' => [] ])); $site->setAttribute('repositoryId', $repository->getId()); - $site->setAttribute('repositoryInternalId', $repository->getSequence()); + $site->setAttribute('repositoryInternalId', $repository->getInternalId()); } $site = $dbForProject->updateDocument('sites', $site->getId(), $site); 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 835068be88..7f1681c0f1 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php @@ -89,7 +89,7 @@ class Update extends Base $oldDeploymentInternalId = $site->getAttribute('deploymentInternalId', ''); $site = $dbForProject->updateDocument('sites', $site->getId(), new Document(array_merge($site->getArrayCopy(), [ - 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), 'deploymentScreenshotDark' => $deployment->getAttribute('screenshotDark', ''), 'deploymentScreenshotLight' => $deployment->getAttribute('screenshotLight', ''), @@ -100,7 +100,7 @@ class Update extends Base Query::equal('trigger', 'manual'), Query::equal("type", ["deployment"]), Query::equal("deploymentResourceType", ["site"]), - Query::equal("deploymentResourceInternalId", [$site->getSequence()]), + Query::equal("deploymentResourceInternalId", [$site->getInternalId()]), ]; if (empty($oldDeploymentInternalId)) { @@ -112,7 +112,7 @@ class Update extends Base $this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { $rule = $rule ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); + ->setAttribute('deploymentInternalId', $deployment->getInternalId()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); }); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 85f1ee8845..212b410178 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -173,8 +173,8 @@ class Update extends Base // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ - Query::equal('projectInternalId', [$project->getSequence()]), - Query::equal('resourceInternalId', [$site->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('resourceInternalId', [$site->getInternalId()]), Query::equal('resourceType', ['site']), Query::limit(100), ]); @@ -206,18 +206,18 @@ class Update extends Base Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getSequence(), + 'installationInternalId' => $installation->getInternalId(), 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), + 'projectInternalId' => $project->getInternalId(), 'providerRepositoryId' => $providerRepositoryId, 'resourceId' => $site->getId(), - 'resourceInternalId' => $site->getSequence(), + 'resourceInternalId' => $site->getInternalId(), 'resourceType' => 'site', 'providerPullRequestIds' => [] ])); $repositoryId = $repository->getId(); - $repositoryInternalId = $repository->getSequence(); + $repositoryInternalId = $repository->getInternalId(); } $live = true; @@ -256,7 +256,7 @@ class Update extends Base 'buildCommand' => $buildCommand, 'outputDirectory' => $outputDirectory, 'installationId' => $installation->getId(), - 'installationInternalId' => $installation->getSequence(), + 'installationInternalId' => $installation->getInternalId(), 'providerRepositoryId' => $providerRepositoryId, 'repositoryId' => $repositoryId, 'repositoryInternalId' => $repositoryInternalId, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php index f8df836085..8bf19a9c28 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Usage/Get.php @@ -74,20 +74,20 @@ class Get extends Base $stats = $usage = []; $days = $periods[$range]; $metrics = [ - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), - str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), - str_replace(['{siteInternalId}'], [$site->getSequence()], METRIC_SITES_ID_REQUESTS), - str_replace(['{siteInternalId}'], [$site->getSequence()], METRIC_SITES_ID_INBOUND), - str_replace(['{siteInternalId}'], [$site->getSequence()], METRIC_SITES_ID_OUTBOUND), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_MB_SECONDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_SUCCESS), + str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_SITES, $site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_FAILED), + str_replace(['{siteInternalId}'], [$site->getInternalId()], METRIC_SITES_ID_REQUESTS), + str_replace(['{siteInternalId}'], [$site->getInternalId()], METRIC_SITES_ID_INBOUND), + str_replace(['{siteInternalId}'], [$site->getInternalId()], METRIC_SITES_ID_OUTBOUND), ]; diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php index 88da635fe4..ff1a5c50ec 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Create.php @@ -85,7 +85,7 @@ class Create extends Base Permission::delete(Role::team(ID::custom($teamId), 'owner')), Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], - 'resourceInternalId' => $site->getSequence(), + 'resourceInternalId' => $site->getInternalId(), 'resourceId' => $site->getId(), 'resourceType' => 'site', 'key' => $key, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Delete.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Delete.php index ea927be367..e4594a7c3d 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Delete.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Delete.php @@ -66,7 +66,7 @@ class Delete extends Base } $variable = $dbForProject->getDocument('variables', $variableId); - if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $site->getSequence() || $variable->getAttribute('resourceType') !== 'site') { + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $site->getInternalId() || $variable->getAttribute('resourceType') !== 'site') { throw new Exception(Exception::VARIABLE_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php index 1c25f9e701..a14129d432 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Get.php @@ -68,7 +68,7 @@ class Get extends Base if ( $variable === false || $variable->isEmpty() || - $variable->getAttribute('resourceInternalId') !== $site->getSequence() || + $variable->getAttribute('resourceInternalId') !== $site->getInternalId() || $variable->getAttribute('resourceType') !== 'site' ) { throw new Exception(Exception::VARIABLE_NOT_FOUND); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Update.php index 698992f79f..cd438a0ebb 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Variables/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Variables/Update.php @@ -77,7 +77,7 @@ class Update extends Base } $variable = $dbForProject->getDocument('variables', $variableId); - if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $site->getSequence() || $variable->getAttribute('resourceType') !== 'site') { + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $site->getInternalId() || $variable->getAttribute('resourceType') !== 'site') { throw new Exception(Exception::VARIABLE_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Action.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Action.php index bcefaf353f..565ab7bab7 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Action.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Action.php @@ -29,9 +29,9 @@ class Action extends UtopiaAction $fileSecurity = $bucket->getAttribute('fileSecurity', false); if ($fileSecurity) { - $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); } else { - $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); + $file = Authorization::skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId)); } if ($file->isEmpty()) { diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php index dc1e5232b6..fb96849ed2 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Create.php @@ -94,7 +94,7 @@ class Create extends Action '$id' => ID::unique(), 'secret' => Auth::tokenGenerator(128), 'resourceId' => $bucketId . ':' . $fileId, - 'resourceInternalId' => $bucket->getSequence() . ':' . $file->getSequence(), + 'resourceInternalId' => $bucket->getInternalId() . ':' . $file->getInternalId(), 'resourceType' => TOKENS_RESOURCE_TYPE_FILES, 'expire' => $expire, ])); diff --git a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php index 628d9b768f..38fe10e2d9 100644 --- a/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php +++ b/src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/XList.php @@ -64,7 +64,7 @@ class XList extends Action $queries = Query::parseQueries($queries); $queries[] = Query::equal('resourceType', [TOKENS_RESOURCE_TYPE_FILES]); - $queries[] = Query::equal('resourceInternalId', [$bucket->getSequence() . ':' . $file->getSequence()]); + $queries[] = Query::equal('resourceInternalId', [$bucket->getInternalId() . ':' . $file->getInternalId()]); // Get cursor document if there was a cursor query $cursor = \array_filter($queries, function ($query) { return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]); diff --git a/src/Appwrite/Platform/Tasks/ScheduleBase.php b/src/Appwrite/Platform/Tasks/ScheduleBase.php index 6d0968a804..286ffe45cb 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleBase.php +++ b/src/Appwrite/Platform/Tasks/ScheduleBase.php @@ -124,7 +124,7 @@ abstract class ScheduleBase extends Action ); return [ - '$sequence' => $schedule->getSequence(), + '$internalId' => $schedule->getInternalId(), '$id' => $schedule->getId(), 'resourceId' => $schedule->getAttribute('resourceId'), 'schedule' => $schedule->getAttribute('schedule'), @@ -175,19 +175,19 @@ abstract class ScheduleBase extends Action $total = $total + $sum; foreach ($results as $document) { - $localDocument = $this->schedules[$document->getSequence()] ?? null; + $localDocument = $this->schedules[$document->getInternalId()] ?? null; if ($localDocument !== null) { if (!$document['active']) { Console::info("Removing: {$document['resourceType']}::{$document['resourceId']}"); - unset($this->schedules[$document->getSequence()]); + unset($this->schedules[$document->getInternalId()]); } elseif (strtotime($localDocument['resourceUpdatedAt']) !== strtotime($document['resourceUpdatedAt'])) { Console::info("Updating: {$document['resourceType']}::{$document['resourceId']}"); - $this->schedules[$document->getSequence()] = $getSchedule($document); + $this->schedules[$document->getInternalId()] = $getSchedule($document); } } else { try { - $this->schedules[$document->getSequence()] = $getSchedule($document); + $this->schedules[$document->getInternalId()] = $getSchedule($document); } catch (\Throwable $th) { $collectionId = static::getCollectionId(); Console::error("Failed to load schedule for project {$document['projectId']} {$collectionId} {$document['resourceId']}"); diff --git a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php index 27a7c1dbf1..6bf2f93afe 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php +++ b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php @@ -39,7 +39,7 @@ class ScheduleExecutions extends ScheduleBase $schedule['$id'], ); - unset($this->schedules[$schedule['$sequence']]); + unset($this->schedules[$schedule['$internalId']]); continue; } @@ -81,7 +81,7 @@ class ScheduleExecutions extends ScheduleBase $schedule['$id'], ); - unset($this->schedules[$schedule['$sequence']]); + unset($this->schedules[$schedule['$internalId']]); } } } diff --git a/src/Appwrite/Platform/Tasks/ScheduleMessages.php b/src/Appwrite/Platform/Tasks/ScheduleMessages.php index 4d971e1b36..5e65f7a8a6 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleMessages.php +++ b/src/Appwrite/Platform/Tasks/ScheduleMessages.php @@ -57,7 +57,7 @@ class ScheduleMessages extends ScheduleBase ); $this->recordEnqueueDelay($scheduledAt); - unset($this->schedules[$schedule['$sequence']]); + unset($this->schedules[$schedule['$internalId']]); }); } } diff --git a/src/Appwrite/Platform/Tasks/StatsResources.php b/src/Appwrite/Platform/Tasks/StatsResources.php index a0b5056b0f..ca2a6860ff 100644 --- a/src/Appwrite/Platform/Tasks/StatsResources.php +++ b/src/Appwrite/Platform/Tasks/StatsResources.php @@ -73,7 +73,7 @@ class StatsResources extends Action $queue ->setProject($project) ->trigger(); - Console::success('project: ' . $project->getId() . '(' . $project->getSequence() . ')' . ' queued'); + Console::success('project: ' . $project->getId() . '(' . $project->getInternalId() . ')' . ' queued'); }); }, $interval); diff --git a/src/Appwrite/Platform/Workers/Audits.php b/src/Appwrite/Platform/Workers/Audits.php index 19ca5181ce..76309145b8 100644 --- a/src/Appwrite/Platform/Workers/Audits.php +++ b/src/Appwrite/Platform/Workers/Audits.php @@ -91,7 +91,7 @@ class Audits extends Action // Create event data $eventData = [ - 'userId' => $user->getSequence(), + 'userId' => $user->getInternalId(), 'event' => $event, 'resource' => $resource, 'userAgent' => $userAgent, @@ -108,13 +108,13 @@ class Audits extends Action 'timestamp' => date("Y-m-d H:i:s", $message->getTimestamp()), ]; - if (isset($this->logs[$project->getSequence()])) { - $this->logs[$project->getSequence()]['logs'][] = $eventData; + if (isset($this->logs[$project->getInternalId()])) { + $this->logs[$project->getInternalId()]['logs'][] = $eventData; } else { - $this->logs[$project->getSequence()] = [ + $this->logs[$project->getInternalId()] = [ 'project' => new Document([ '$id' => $project->getId(), - '$sequence' => $project->getSequence(), + '$internalId' => $project->getInternalId(), 'database' => $project->getAttribute('database'), ]), 'logs' => [$eventData] @@ -130,7 +130,7 @@ class Audits extends Action if ($shouldProcessBatch) { try { - foreach ($this->logs as $sequence => $projectLogs) { + foreach ($this->logs as $internalId => $projectLogs) { $dbForProject = $getProjectDB($projectLogs['project']); Console::log('Processing batch with ' . count($projectLogs['logs']) . ' events'); @@ -139,7 +139,7 @@ class Audits extends Action $audit->logBatch($projectLogs['logs']); Console::success('Audit logs processed successfully'); - unset($this->logs[$sequence]); + unset($this->logs[$internalId]); } } catch (Throwable $e) { Console::error('Error processing audit logs: ' . $e->getMessage()); diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index a9104e0017..0dce51cb52 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -255,7 +255,7 @@ class Certificates extends Action $certificate = new Document(\array_merge($certificateDocument->getArrayCopy(), $certificate->getArrayCopy())); $certificate = $dbForPlatform->updateDocument('certificates', $certificate->getId(), $certificate); } else { - $certificate->removeAttribute('$sequence'); + $certificate->removeAttribute('$internalId'); $certificate = $dbForPlatform->createDocument('certificates', $certificate); } diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index 8c6f6f0252..b2691b420e 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -147,15 +147,15 @@ class Databases extends Action try { switch ($type) { case Database::VAR_RELATIONSHIP: - $relatedCollection = $dbForProject->getDocument('database_' . $database->getSequence(), $options['relatedCollection']); + $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { throw new DatabaseException('Collection not found'); } if ( !$dbForProject->createRelationship( - collection: 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), - relatedCollection: 'database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence(), + collection: 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), + relatedCollection: 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), type: $options['relationType'], twoWay: $options['twoWay'], id: $key, @@ -167,12 +167,12 @@ class Databases extends Action } if ($options['twoWay']) { - $relatedAttribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $options['twoWayKey']); + $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); $dbForProject->updateDocument('attributes', $relatedAttribute->getId(), $relatedAttribute->setAttribute('status', 'available')); } break; default: - if (!$dbForProject->createAttribute('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) { + if (!$dbForProject->createAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) { throw new Exception('Failed to create Attribute'); } } @@ -207,10 +207,10 @@ class Databases extends Action $this->trigger($database, $collection, $project, $event, $queueForRealtime, $attribute); if (! $relatedCollection->isEmpty()) { - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $relatedCollection->getId()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); } - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); } } @@ -257,18 +257,18 @@ class Databases extends Action try { if ($type === Database::VAR_RELATIONSHIP) { if ($options['twoWay']) { - $relatedCollection = $dbForProject->getDocument('database_' . $database->getSequence(), $options['relatedCollection']); + $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { throw new DatabaseException('Collection not found'); } - $relatedAttribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $options['twoWayKey']); + $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); } - if (!$dbForProject->deleteRelationship('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $key)) { + if (!$dbForProject->deleteRelationship('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { $dbForProject->updateDocument('attributes', $relatedAttribute->getId(), $relatedAttribute->setAttribute('status', 'stuck')); throw new DatabaseException('Failed to delete Relationship'); } - } elseif (!$dbForProject->deleteAttribute('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $key)) { + } elseif (!$dbForProject->deleteAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { throw new DatabaseException('Failed to delete Attribute'); } @@ -365,10 +365,10 @@ class Databases extends Action } } } finally { - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); if (! $relatedCollection->isEmpty()) { - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $relatedCollection->getId()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); } } } @@ -408,7 +408,7 @@ class Databases extends Action $project = $dbForPlatform->getDocument('projects', $projectId); try { - if (!$dbForProject->createIndex('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $key, $type, $attributes, $lengths, $orders)) { + if (!$dbForProject->createIndex('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $attributes, $lengths, $orders)) { throw new DatabaseException('Failed to create Index'); } $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); @@ -426,7 +426,7 @@ class Databases extends Action throw $e; } finally { $this->trigger($database, $collection, $project, $event, $queueForRealtime, null, $index); - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collectionId); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); } } @@ -461,7 +461,7 @@ class Databases extends Action $project = $dbForPlatform->getDocument('projects', $projectId); try { - if ($status !== 'failed' && !$dbForProject->deleteIndex('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $key)) { + if ($status !== 'failed' && !$dbForProject->deleteIndex('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { throw new DatabaseException('Failed to delete index'); } $dbForProject->deleteDocument('indexes', $index->getId()); @@ -482,7 +482,7 @@ class Databases extends Action } finally { $this->trigger($database, $collection, $project, $event, $queueForRealtime, null, $index); - $dbForProject->purgeCachedDocument('database_' . $database->getSequence(), $collection->getId()); + $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collection->getId()); } } @@ -495,11 +495,11 @@ class Databases extends Action */ protected function deleteDatabase(Document $database, Document $project, $dbForProject): void { - $this->deleteByGroup('database_' . $database->getSequence(), [], $dbForProject, function ($collection) use ($database, $project, $dbForProject) { + $this->deleteByGroup('database_' . $database->getInternalId(), [], $dbForProject, function ($collection) use ($database, $project, $dbForProject) { $this->deleteCollection($database, $collection, $project, $dbForProject); }); - $dbForProject->deleteCollection('database_' . $database->getSequence()); + $dbForProject->deleteCollection('database_' . $database->getInternalId()); } /** @@ -522,10 +522,10 @@ class Databases extends Action } $collectionId = $collection->getId(); - $collectionInternalId = $collection->getSequence(); - $databaseInternalId = $database->getSequence(); + $collectionInternalId = $collection->getInternalId(); + $databaseInternalId = $database->getInternalId(); - $dbForProject->deleteCollection('database_' . $databaseInternalId . '_collection_' . $collection->getSequence()); + $dbForProject->deleteCollection('database_' . $databaseInternalId . '_collection_' . $collection->getInternalId()); /** * Related collections relating to current collection diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 8ed96c76a2..43bc55583d 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -34,7 +34,7 @@ use Utopia\System\System; class Deletes extends Action { - protected array $selects = ['$sequence', '$id', '$collection', '$permissions', '$updatedAt']; + protected array $selects = ['$internalId', '$id', '$collection', '$permissions', '$updatedAt']; public static function getName(): string { @@ -277,7 +277,7 @@ class Deletes extends Action $this->deleteByGroup( 'subscribers', [ - Query::equal('topicInternalId', [$topic->getSequence()]), + Query::equal('topicInternalId', [$topic->getInternalId()]), Query::orderAsc(), ], $getProjectDB($project) @@ -298,7 +298,7 @@ class Deletes extends Action private function deleteSessionTargets(Document $project, callable $getProjectDB, Document $session): void { - Targets::delete($getProjectDB($project), Query::equal('sessionInternalId', [$session->getSequence()])); + Targets::delete($getProjectDB($project), Query::equal('sessionInternalId', [$session->getInternalId()])); } /** @@ -434,7 +434,7 @@ class Deletes extends Action public function deleteMemberships(callable $getProjectDB, Document $document, Document $project): void { $dbForProject = $getProjectDB($project); - $teamInternalId = $document->getSequence(); + $teamInternalId = $document->getInternalId(); // Delete Memberships $this->deleteByGroup( @@ -466,7 +466,7 @@ class Deletes extends Action { $projects = $dbForPlatform->find('projects', [ - Query::equal('teamInternalId', [$document->getSequence()]), + Query::equal('teamInternalId', [$document->getInternalId()]), Query::equal('region', [System::getEnv('_APP_REGION', 'default')]) ]); @@ -497,7 +497,7 @@ class Deletes extends Action */ private function deleteProject(Database $dbForPlatform, callable $getProjectDB, Device $deviceForFiles, Device $deviceForSites, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, Document $document): void { - $projectInternalId = $document->getSequence(); + $projectInternalId = $document->getInternalId(); $projectId = $document->getId(); try { @@ -637,7 +637,7 @@ class Deletes extends Action private function deleteUser(callable $getProjectDB, Document $document, Document $project): void { $userId = $document->getId(); - $userInternalId = $document->getSequence(); + $userInternalId = $document->getInternalId(); $dbForProject = $getProjectDB($project); // Delete all sessions of this user from the sessions table and update the sessions field of the user record @@ -769,7 +769,7 @@ class Deletes extends Action { $dbForProject = $getProjectDB($project); $siteId = $document->getId(); - $siteInternalId = $document->getSequence(); + $siteInternalId = $document->getInternalId(); /** * Delete rules for site @@ -779,7 +779,7 @@ class Deletes extends Action Query::equal('type', ['deployment']), Query::equal('deploymentResourceType', ['site']), Query::equal('deploymentResourceInternalId', [$siteInternalId]), - Query::equal('projectInternalId', [$project->getSequence()]) + Query::equal('projectInternalId', [$project->getInternalId()]) ], $dbForPlatform, function (Document $document) use ($dbForPlatform, $certificates) { $this->deleteRule($dbForPlatform, $document, $certificates); }); @@ -804,7 +804,7 @@ class Deletes extends Action Query::equal('resourceType', ['site']), Query::orderAsc() ], $dbForProject, function (Document $document) use ($project, $certificates, $deviceForSites, $deviceForBuilds, $deviceForFiles, $dbForPlatform, &$deploymentInternalIds) { - $deploymentInternalIds[] = $document->getSequence(); + $deploymentInternalIds[] = $document->getInternalId(); $deploymentIds[] = $document->getId(); $this->deleteBuildFiles($deviceForBuilds, $document); $this->deleteDeploymentFiles($deviceForSites, $document); @@ -827,7 +827,7 @@ class Deletes extends Action */ Console::info("Deleting VCS repositories and comments linked to site " . $siteId); $this->deleteByGroup('repositories', [ - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('resourceInternalId', [$siteInternalId]), Query::equal('resourceType', ['site']), ], $dbForPlatform, function (Document $document) use ($dbForPlatform) { @@ -855,7 +855,7 @@ class Deletes extends Action $projectId = $project->getId(); $dbForProject = $getProjectDB($project); $functionId = $document->getId(); - $functionInternalId = $document->getSequence(); + $functionInternalId = $document->getInternalId(); /** * Delete rules @@ -865,7 +865,7 @@ class Deletes extends Action Query::equal('type', ['deployment']), Query::equal('deploymentResourceType', ['function']), Query::equal('deploymentResourceInternalId', [$functionInternalId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), Query::orderAsc() ], $dbForPlatform, function (Document $document) use ($project, $dbForPlatform, $certificates) { $this->deleteRule($dbForPlatform, $document, $certificates); @@ -892,7 +892,7 @@ class Deletes extends Action Query::equal('resourceType', ['function']), Query::orderAsc() ], $dbForProject, function (Document $document) use ($dbForPlatform, $project, $certificates, $deviceForFunctions, $deviceForBuilds, &$deploymentInternalIds) { - $deploymentInternalIds[] = $document->getSequence(); + $deploymentInternalIds[] = $document->getInternalId(); $this->deleteDeploymentFiles($deviceForFunctions, $document); $this->deleteBuildFiles($deviceForBuilds, $document); }); @@ -913,7 +913,7 @@ class Deletes extends Action */ Console::info("Deleting VCS repositories and comments linked to function " . $functionId); $this->deleteByGroup('repositories', [ - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('resourceInternalId', [$functionInternalId]), Query::equal('resourceType', ['function']), Query::orderAsc() @@ -957,7 +957,7 @@ class Deletes extends Action } foreach ($screenshotIds as $id) { - $file = ValidatorAuthorization::skip(fn () => $dbForPlatform->getDocument('bucket_' . $bucket->getSequence(), $id)); + $file = ValidatorAuthorization::skip(fn () => $dbForPlatform->getDocument('bucket_' . $bucket->getInternalId(), $id)); if ($file->isEmpty()) { Console::error('Failed to get deployment screenshot: ' . $id); @@ -1060,7 +1060,7 @@ class Deletes extends Action $projectId = $project->getId(); $dbForProject = $getProjectDB($project); $deploymentId = $document->getId(); - $deploymentInternalId = $document->getSequence(); + $deploymentInternalId = $document->getInternalId(); /** * Delete deployment files @@ -1089,7 +1089,7 @@ class Deletes extends Action Query::equal('trigger', ['deployment']), Query::equal('type', ['deployment']), Query::equal('deploymentInternalId', [$deploymentInternalId]), - Query::equal('projectInternalId', [$project->getSequence()]) + Query::equal('projectInternalId', [$project->getInternalId()]) ], $dbForPlatform, function (Document $document) use ($dbForPlatform, $certificates) { $this->deleteRule($dbForPlatform, $document, $certificates); }); @@ -1211,7 +1211,7 @@ class Deletes extends Action { $dbForProject = $getProjectDB($project); - $dbForProject->deleteCollection('bucket_' . $document->getSequence()); + $dbForProject->deleteCollection('bucket_' . $document->getInternalId()); $deviceForFiles->deletePath($document->getId()); } @@ -1229,7 +1229,7 @@ class Deletes extends Action $dbForProject = $getProjectDB($project); $this->listByGroup('functions', [ - Query::equal('installationInternalId', [$document->getSequence()]) + Query::equal('installationInternalId', [$document->getInternalId()]) ], $dbForProject, function ($function) use ($dbForProject, $dbForPlatform) { $dbForPlatform->deleteDocument('repositories', $function->getAttribute('repositoryId')); @@ -1260,7 +1260,7 @@ class Deletes extends Action $this->listByGroup( 'deployments', [ - Query::equal('resourceInternalId', [$function->getSequence()]), + Query::equal('resourceInternalId', [$function->getInternalId()]), Query::equal('resourceType', ['functions']), ], $getProjectDB($project), diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index a9126583ce..c8c68a58ba 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -280,7 +280,7 @@ class Functions extends Action $execution = new Document([ '$id' => $executionId, '$permissions' => $user->isEmpty() ? [] : [Permission::read(Role::user($user->getId()))], - 'resourceInternalId' => $function->getSequence(), + 'resourceInternalId' => $function->getInternalId(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', 'deploymentInternalId' => '', @@ -420,10 +420,10 @@ class Functions extends Action $execution = new Document([ '$id' => $executionId, '$permissions' => $user->isEmpty() ? [] : [Permission::read(Role::user($user->getId()))], - 'resourceInternalId' => $function->getSequence(), + 'resourceInternalId' => $function->getInternalId(), 'resourceId' => $function->getId(), 'resourceType' => 'functions', - 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), 'trigger' => $trigger, 'status' => 'processing', @@ -572,13 +572,13 @@ class Functions extends Action ->setProject($project) ->addMetric(METRIC_EXECUTIONS, 1) ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS), 1) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), 1) ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000))// per project ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) ->addMetric(METRIC_EXECUTIONS_MB_SECONDS, (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->addMetric(str_replace(['{resourceType}'], [RESOURCE_TYPE_FUNCTIONS], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) - ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) + ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ->trigger() ; } diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index 2ee107a319..8491e91a6c 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -373,7 +373,7 @@ class Messaging extends Action throw new \Exception('Storage bucket with the requested ID could not be found'); } - $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); if ($file->isEmpty()) { throw new \Exception('Storage file with the requested ID could not be found'); } @@ -558,7 +558,7 @@ class Messaging extends Action throw new \Exception('Storage bucket with the requested ID could not be found'); } - $file = $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId); + $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId); if ($file->isEmpty()) { throw new \Exception('Storage file with the requested ID could not be found'); } diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 395ec1351e..b746365f20 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -368,7 +368,7 @@ class Migrations extends Action $this->updateMigrationDocument($migration, $projectDocument, $queueForRealtime); if ($migration->getAttribute('status', '') === 'failed') { - Console::error('Migration('.$migration->getSequence().':'.$migration->getId().') failed, Project('.$this->project->getSequence().':'.$this->project->getId().')'); + Console::error('Migration('.$migration->getInternalId().':'.$migration->getId().') failed, Project('.$this->project->getInternalId().':'.$this->project->getId().')'); if ($destination) { $destination->error(); diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index c68465f8df..19d1223d95 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -80,7 +80,7 @@ class StatsResources extends Action $this->countForProject($dbForPlatform, $getLogsDB, $getProjectDB, $project); $endTime = microtime(true); $executionTime = $endTime - $startTime; - Console::info('Project: ' . $project->getId() . '(' . $project->getSequence() . ') aggregated in ' . $executionTime .' seconds'); + Console::info('Project: ' . $project->getId() . '(' . $project->getInternalId() . ') aggregated in ' . $executionTime .' seconds'); } protected function countForProject(Database $dbForPlatform, callable $getLogsDB, callable $getProjectDB, Document $project): void @@ -105,17 +105,17 @@ class StatsResources extends Action $region = $project->getAttribute('region'); $platforms = $dbForPlatform->count('platforms', [ - Query::equal('projectInternalId', [$project->getSequence()]) + Query::equal('projectInternalId', [$project->getInternalId()]) ]); $webhooks = $dbForPlatform->count('webhooks', [ - Query::equal('projectInternalId', [$project->getSequence()]) + Query::equal('projectInternalId', [$project->getInternalId()]) ]); $keys = $dbForPlatform->count('keys', [ - Query::equal('projectInternalId', [$project->getSequence()]) + Query::equal('projectInternalId', [$project->getInternalId()]) ]); $domains = $dbForPlatform->count('rules', [ - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('owner', ['']), ]); @@ -216,13 +216,13 @@ class StatsResources extends Action $totalFiles = 0; $totalStorage = 0; $this->foreachDocument($dbForProject, 'buckets', [], function ($bucket) use ($dbForProject, $dbForLogs, $region, &$totalFiles, &$totalStorage) { - $files = $dbForProject->count('bucket_' . $bucket->getSequence()); + $files = $dbForProject->count('bucket_' . $bucket->getInternalId()); - $metric = str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES); + $metric = str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES); $this->createStatsDocuments($region, $metric, $files); - $storage = $dbForProject->sum('bucket_' . $bucket->getSequence(), 'sizeActual'); - $metric = str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES_STORAGE); + $storage = $dbForProject->sum('bucket_' . $bucket->getInternalId(), 'sizeActual'); + $metric = str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES_STORAGE); $this->createStatsDocuments($region, $metric, $storage); $totalStorage += $storage; @@ -241,10 +241,10 @@ class StatsResources extends Action $totalImageTransformations = 0; $last30Days = (new \DateTime())->sub(\DateInterval::createFromDateString('30 days'))->format('Y-m-d 00:00:00'); $this->foreachDocument($dbForProject, 'buckets', [], function ($bucket) use ($dbForProject, $last30Days, $region, &$totalImageTransformations) { - $imageTransformations = $dbForProject->count('bucket_' . $bucket->getSequence(), [ + $imageTransformations = $dbForProject->count('bucket_' . $bucket->getInternalId(), [ Query::greaterThanEqual('transformedAt', $last30Days), ]); - $metric = str_replace('{bucketInternalId}', $bucket->getSequence(), METRIC_BUCKET_ID_FILES_IMAGES_TRANSFORMED); + $metric = str_replace('{bucketInternalId}', $bucket->getInternalId(), METRIC_BUCKET_ID_FILES_IMAGES_TRANSFORMED); $this->createStatsDocuments($region, $metric, $imageTransformations); $totalImageTransformations += $imageTransformations; }); @@ -260,9 +260,9 @@ class StatsResources extends Action $totalDatabaseStorage = 0; $this->foreachDocument($dbForProject, 'databases', [], function ($database) use ($dbForProject, $region, &$totalCollections, &$totalDocuments, &$totalDatabaseStorage) { - $collections = $dbForProject->count('database_' . $database->getSequence()); + $collections = $dbForProject->count('database_' . $database->getInternalId()); - $metric = str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_COLLECTIONS); + $metric = str_replace('{databaseInternalId}', $database->getInternalId(), METRIC_DATABASE_ID_COLLECTIONS); $this->createStatsDocuments($region, $metric, $collections); [$documents, $storage] = $this->countForCollections($dbForProject, $database, $region); @@ -280,23 +280,23 @@ class StatsResources extends Action { $databaseDocuments = 0; $databaseStorage = 0; - $this->foreachDocument($dbForProject, 'database_' . $database->getSequence(), [], function ($collection) use ($dbForProject, $database, $region, &$databaseStorage, &$databaseDocuments) { - $documents = $dbForProject->count('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); - $metric = str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$database->getSequence(), $collection->getSequence()], METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS); + $this->foreachDocument($dbForProject, 'database_' . $database->getInternalId(), [], function ($collection) use ($dbForProject, $database, $region, &$databaseStorage, &$databaseDocuments) { + $documents = $dbForProject->count('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); + $metric = str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$database->getInternalId(), $collection->getInternalId()], METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS); $this->createStatsDocuments($region, $metric, $documents); $databaseDocuments += $documents; - $collectionStorage = $dbForProject->getSizeOfCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); - $metric = str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$database->getSequence(), $collection->getSequence()], METRIC_DATABASE_ID_COLLECTION_ID_STORAGE); + $collectionStorage = $dbForProject->getSizeOfCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId()); + $metric = str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$database->getInternalId(), $collection->getInternalId()], METRIC_DATABASE_ID_COLLECTION_ID_STORAGE); $this->createStatsDocuments($region, $metric, $collectionStorage); $databaseStorage += $collectionStorage; }); - $metric = str_replace(['{databaseInternalId}'], [$database->getSequence()], METRIC_DATABASE_ID_DOCUMENTS); + $metric = str_replace(['{databaseInternalId}'], [$database->getInternalId()], METRIC_DATABASE_ID_DOCUMENTS); $this->createStatsDocuments($region, $metric, $databaseDocuments); - $metric = str_replace(['{databaseInternalId}'], [$database->getSequence()], METRIC_DATABASE_ID_STORAGE); + $metric = str_replace(['{databaseInternalId}'], [$database->getInternalId()], METRIC_DATABASE_ID_STORAGE); $this->createStatsDocuments($region, $metric, $databaseStorage); return [$databaseDocuments, $databaseStorage]; @@ -337,33 +337,33 @@ class StatsResources extends Action $this->foreachDocument($dbForProject, 'functions', [], function (Document $function) use ($dbForProject, $region) { $functionDeploymentsStorage = $dbForProject->sum('deployments', 'sourceSize', [ - Query::equal('resourceInternalId', [$function->getSequence()]), + Query::equal('resourceInternalId', [$function->getInternalId()]), Query::equal('resourceType', [RESOURCE_TYPE_FUNCTIONS]), ]); - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), $functionDeploymentsStorage); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), $functionDeploymentsStorage); $functionDeployments = $dbForProject->count('deployments', [ - Query::equal('resourceInternalId', [$function->getSequence()]), + Query::equal('resourceInternalId', [$function->getInternalId()]), Query::equal('resourceType', [RESOURCE_TYPE_FUNCTIONS]), ]); - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), $functionDeployments); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), $functionDeployments); /** * As deployments and builds have 1-1 relationship, * the count for one should match the other */ - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS), $functionDeployments); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), $functionDeployments); $functionBuildsStorage = 0; $this->foreachDocument($dbForProject, 'deployments', [ - Query::equal('resourceInternalId', [$function->getSequence()]), + Query::equal('resourceInternalId', [$function->getInternalId()]), Query::equal('resourceType', [RESOURCE_TYPE_FUNCTIONS]), ], function (Document $deployment) use (&$functionBuildsStorage): void { $functionBuildsStorage += $deployment->getAttribute('buildSize', 0); }); - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $functionBuildsStorage); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $functionBuildsStorage); }); } @@ -387,29 +387,29 @@ class StatsResources extends Action $this->foreachDocument($dbForProject, 'sites', [], function (Document $site) use ($dbForProject, $region) { $siteDeploymentsStorage = $dbForProject->sum('deployments', 'sourceSize', [ - Query::equal('resourceInternalId', [$site->getSequence()]), + Query::equal('resourceInternalId', [$site->getInternalId()]), Query::equal('resourceType', [RESOURCE_TYPE_SITES]), ]); - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), $siteDeploymentsStorage); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE), $siteDeploymentsStorage); $siteDeployments = $dbForProject->count('deployments', [ - Query::equal('resourceInternalId', [$site->getSequence()]), + Query::equal('resourceInternalId', [$site->getInternalId()]), Query::equal('resourceType', [RESOURCE_TYPE_SITES]), ]); - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), $siteDeployments); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS), $siteDeployments); /** * As deployments and builds have 1-1 relationship, * the count for one should match the other */ - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS), $siteDeployments); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS), $siteDeployments); $siteBuildsStorage = $dbForProject->sum('deployments', 'buildSize', [ - Query::equal('resourceInternalId', [$site->getSequence()]), + Query::equal('resourceInternalId', [$site->getInternalId()]), Query::equal('resourceType', [RESOURCE_TYPE_SITES]), ]); - $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $siteBuildsStorage); + $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $siteBuildsStorage); }); } @@ -437,6 +437,6 @@ class StatsResources extends Action $this->documents ); $this->documents = []; - Console::success('Stats written to logs db for project: ' . $project->getId() . '(' . $project->getSequence() . ')'); + Console::success('Stats written to logs db for project: ' . $project->getId() . '(' . $project->getInternalId() . ')'); } } diff --git a/src/Appwrite/Platform/Workers/StatsUsage.php b/src/Appwrite/Platform/Workers/StatsUsage.php index 59b5a15ada..25c80fabdc 100644 --- a/src/Appwrite/Platform/Workers/StatsUsage.php +++ b/src/Appwrite/Platform/Workers/StatsUsage.php @@ -145,7 +145,7 @@ class StatsUsage extends Action $aggregationInterval = (int) System::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', '20'); $project = new Document($payload['project'] ?? []); - $projectId = $project->getSequence(); + $projectId = $project->getInternalId(); foreach ($payload['reduce'] ?? [] as $document) { if (empty($document)) { continue; @@ -211,8 +211,8 @@ class StatsUsage extends Action } break; case $document->getCollection() === 'databases': // databases - $collections = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{databaseInternalId}', $document->getSequence(), METRIC_DATABASE_ID_COLLECTIONS))); - $documents = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{databaseInternalId}', $document->getSequence(), METRIC_DATABASE_ID_DOCUMENTS))); + $collections = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{databaseInternalId}', $document->getInternalId(), METRIC_DATABASE_ID_COLLECTIONS))); + $documents = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{databaseInternalId}', $document->getInternalId(), METRIC_DATABASE_ID_DOCUMENTS))); if (!empty($collections['value'])) { $metrics[] = [ 'key' => METRIC_COLLECTIONS, @@ -232,7 +232,7 @@ class StatsUsage extends Action $databaseInternalId = $parts[1] ?? 0; $documents = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace( ['{databaseInternalId}', '{collectionInternalId}'], - [$databaseInternalId, $document->getSequence()], + [$databaseInternalId, $document->getInternalId()], METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS ))); @@ -249,8 +249,8 @@ class StatsUsage extends Action break; case $document->getCollection() === 'buckets': - $files = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getSequence(), METRIC_BUCKET_ID_FILES))); - $storage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getSequence(), METRIC_BUCKET_ID_FILES_STORAGE))); + $files = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getInternalId(), METRIC_BUCKET_ID_FILES))); + $storage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getInternalId(), METRIC_BUCKET_ID_FILES_STORAGE))); if (!empty($files['value'])) { $metrics[] = [ @@ -268,13 +268,13 @@ class StatsUsage extends Action break; case $document->getCollection() === 'functions' || $document->getCollection() === 'sites': - $deployments = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS))); - $deploymentsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE))); - $builds = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS))); - $buildsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE))); - $buildsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE))); - $executions = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS))); - $executionsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE))); + $deployments = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS))); + $deploymentsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_DEPLOYMENTS_STORAGE))); + $builds = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS))); + $buildsStorage = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE))); + $buildsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_BUILDS_COMPUTE))); + $executions = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS))); + $executionsCompute = $dbForProject->getDocument('stats', md5(self::INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], [$document->getCollection(), $document->getInternalId()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE))); if (!empty($deployments['value'])) { $metrics[] = [ @@ -357,7 +357,7 @@ class StatsUsage extends Action break; } } catch (Throwable $e) { - Console::error("[reducer] " . " {DateTime::now()} " . " {$project->getSequence()} " . " {$e->getMessage()}"); + Console::error("[reducer] " . " {DateTime::now()} " . " {$project->getInternalId()} " . " {$e->getMessage()}"); } } @@ -376,7 +376,7 @@ class StatsUsage extends Action continue; } - Console::log('['.DateTime::now().'] Id: '.$project->getId(). ' InternalId: '.$project->getSequence(). ' Db: '.$project->getAttribute('database').' ReceivedAt: '.$receivedAt. ' Keys: '.$numberOfKeys); + Console::log('['.DateTime::now().'] Id: '.$project->getId(). ' InternalId: '.$project->getInternalId(). ' Db: '.$project->getAttribute('database').' ReceivedAt: '.$receivedAt. ' Keys: '.$numberOfKeys); try { foreach ($stats['keys'] ?? [] as $key => $value) { @@ -402,23 +402,23 @@ class StatsUsage extends Action ]); - $this->projects[$project->getSequence()]['project'] = new Document([ + $this->projects[$project->getInternalId()]['project'] = new Document([ '$id' => $project->getId(), - '$sequence' => $project->getSequence(), + '$internalId' => $project->getInternalId(), 'database' => $project->getAttribute('database'), ]); - $this->projects[$project->getSequence()]['stats'][] = $document; + $this->projects[$project->getInternalId()]['stats'][] = $document; $this->prepareForLogsDB($project, $document); } } } catch (Exception $e) { - Console::error('[' . DateTime::now() . '] project [' . $project->getSequence() . '] database [' . $project['database'] . '] ' . ' ' . $e->getMessage()); + Console::error('[' . DateTime::now() . '] project [' . $project->getInternalId() . '] database [' . $project['database'] . '] ' . ' ' . $e->getMessage()); } } - foreach ($this->projects as $sequence => $projectStats) { - if (empty($sequence)) { + foreach ($this->projects as $internalId => $projectStats) { + if (empty($internalId)) { continue; } try { @@ -427,7 +427,7 @@ class StatsUsage extends Action $dbForProject->createOrUpdateDocumentsWithIncrease('stats', 'value', $projectStats['stats']); Console::success('Batch successfully written to DB'); - unset($this->projects[$sequence]); + unset($this->projects[$internalId]); } catch (Throwable $e) { Console::error('Error processing stats: ' . $e->getMessage()); } @@ -451,7 +451,7 @@ class StatsUsage extends Action } } $documentClone = clone $stat; - $documentClone->setAttribute('$tenant', (int) $project->getSequence()); + $documentClone->setAttribute('$tenant', (int) $project->getInternalId()); $this->statDocuments[] = $documentClone; } diff --git a/src/Appwrite/Platform/Workers/StatsUsageDump.php b/src/Appwrite/Platform/Workers/StatsUsageDump.php index 7c2da8fd4d..77ec3f13e6 100644 --- a/src/Appwrite/Platform/Workers/StatsUsageDump.php +++ b/src/Appwrite/Platform/Workers/StatsUsageDump.php @@ -126,7 +126,7 @@ class StatsUsageDump extends Action continue; } - Console::log('['.DateTime::now().'] Id: '.$project->getId(). ' InternalId: '.$project->getSequence(). ' Db: '.$project->getAttribute('database').' ReceivedAt: '.$receivedAt. ' Keys: '.$numberOfKeys); + Console::log('['.DateTime::now().'] Id: '.$project->getId(). ' InternalId: '.$project->getInternalId(). ' Db: '.$project->getAttribute('database').' ReceivedAt: '.$receivedAt. ' Keys: '.$numberOfKeys); try { /** @var Database $dbForProject */ @@ -169,7 +169,7 @@ class StatsUsageDump extends Action } } } catch (\Exception $e) { - Console::error('[' . DateTime::now() . '] project [' . $project->getSequence() . '] database [' . $project['database'] . '] ' . ' ' . $e->getMessage()); + Console::error('[' . DateTime::now() . '] project [' . $project->getInternalId() . '] database [' . $project['database'] . '] ' . ' ' . $e->getMessage()); } } } diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index 4c081aaa13..ada4d6faaa 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -176,7 +176,7 @@ class Webhooks extends Action $this->errors[] = $logs; $queueForStatsUsage ->addMetric(METRIC_WEBHOOKS_FAILED, 1) - ->addMetric(str_replace('{webhookInternalId}', $webhook->getSequence(), METRIC_WEBHOOK_ID_FAILED), 1) + ->addMetric(str_replace('{webhookInternalId}', $webhook->getInternalId(), METRIC_WEBHOOK_ID_FAILED), 1) ; @@ -186,7 +186,7 @@ class Webhooks extends Action $dbForPlatform->purgeCachedDocument('projects', $project->getId()); $queueForStatsUsage ->addMetric(METRIC_WEBHOOKS_SENT, 1) - ->addMetric(str_replace('{webhookInternalId}', $webhook->getSequence(), METRIC_WEBHOOK_ID_SENT), 1) + ->addMetric(str_replace('{webhookInternalId}', $webhook->getInternalId(), METRIC_WEBHOOK_ID_SENT), 1) ; } diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php index 20e7d5cb93..e8eafba5a0 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php @@ -71,8 +71,8 @@ class Base extends Queries 'array' => false, ]); - $sequence = new Document([ - 'key' => '$sequence', + $internalId = new Document([ + 'key' => '$internalId', 'type' => Database::VAR_STRING, 'array' => false, ]); @@ -82,7 +82,7 @@ class Base extends Queries new Offset(), new Cursor(), new Filter($attributes, APP_DATABASE_QUERY_MAX_VALUES), - new Order([...$attributes, $sequence]), + new Order([...$attributes, $internalId]), ]; parent::__construct($validators); diff --git a/src/Appwrite/Utopia/Response/Model/Document.php b/src/Appwrite/Utopia/Response/Model/Document.php index c4f7eb3044..41a10cee89 100644 --- a/src/Appwrite/Utopia/Response/Model/Document.php +++ b/src/Appwrite/Utopia/Response/Model/Document.php @@ -71,7 +71,7 @@ class Document extends Any public function filter(DatabaseDocument $document): DatabaseDocument { - $document->removeAttribute('$sequence'); + $document->removeAttribute('$internalId'); $document->removeAttribute('$collection'); $document->removeAttribute('$tenant'); diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 9c7e19c76c..9aed3684de 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -2003,9 +2003,9 @@ trait DatabasesBase $this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']); $this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']); $this->assertEquals(2019, $documents['body']['documents'][2]['releaseYear']); - $this->assertFalse(array_key_exists('$sequence', $documents['body']['documents'][0])); - $this->assertFalse(array_key_exists('$sequence', $documents['body']['documents'][1])); - $this->assertFalse(array_key_exists('$sequence', $documents['body']['documents'][2])); + $this->assertFalse(array_key_exists('$internalId', $documents['body']['documents'][0])); + $this->assertFalse(array_key_exists('$internalId', $documents['body']['documents'][1])); + $this->assertFalse(array_key_exists('$internalId', $documents['body']['documents'][2])); $this->assertCount(3, $documents['body']['documents']); foreach ($documents['body']['documents'] as $document) { @@ -2098,7 +2098,7 @@ trait DatabasesBase $this->assertEquals($response['body']['releaseYear'], $document['releaseYear']); $this->assertEquals($response['body']['$permissions'], $document['$permissions']); $this->assertEquals($response['body']['birthDay'], $document['birthDay']); - $this->assertFalse(array_key_exists('$sequence', $response['body'])); + $this->assertFalse(array_key_exists('$internalId', $response['body'])); $this->assertFalse(array_key_exists('$tenant', $response['body'])); } } @@ -4361,8 +4361,8 @@ trait DatabasesBase $this->assertArrayNotHasKey('$collection', $person1['body']); $this->assertArrayNotHasKey('$collection', $person1['body']['library']); - $this->assertArrayNotHasKey('$sequence', $person1['body']); - $this->assertArrayNotHasKey('$sequence', $person1['body']['library']); + $this->assertArrayNotHasKey('$internalId', $person1['body']); + $this->assertArrayNotHasKey('$internalId', $person1['body']['library']); $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $person['body']['$id'] . '/documents', array_merge([ 'content-type' => 'application/json', From 8ce46c791fddd83b4d965a266503c2ae27f14325 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 21 May 2025 15:16:25 -0700 Subject: [PATCH 28/31] fix(migration): set owner and region while migrating rules These attributes were added to the rules collection in 1.6.2, but the migration script was not updated to set them. Because they're empty, the 1.7 migration fails while updating rules documents because region is required. --- src/Appwrite/Migration/Version/V22.php | 34 ++++++++++++++++++++------ 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Migration/Version/V22.php b/src/Appwrite/Migration/Version/V22.php index 50d5bdbb85..a10017c99f 100644 --- a/src/Appwrite/Migration/Version/V22.php +++ b/src/Appwrite/Migration/Version/V22.php @@ -12,6 +12,7 @@ use Utopia\Database\Exception\Conflict; use Utopia\Database\Exception\Structure; use Utopia\Database\Exception\Timeout; use Utopia\Database\Query; +use Utopia\System\System; class V22 extends Migration { @@ -324,7 +325,9 @@ class V22 extends Migration 4. Fill "trigger" with "manual" 5. Fill "deploymentResourceType". If "resourceType" is "function", set "deploymentResourceType" to "function" 6. Fill "search" with "{$id} {domain}" - 7. Fill "deploymentId" and "deploymentInternalId". If "deploymentResourceType" is "function", get project DB, and find function with ID "resourceId". Then fill rule's "deploymentId" with function's "deployment", and "deploymentId" as backup + 7. Set "region" to project region + 8. Fill "owner" with "Appwrite" if "domain" ends with "functions" or "sites" + 9. Fill "deploymentId" and "deploymentInternalId". If "deploymentResourceType" is "function", get project DB, and find function with ID "resourceId". Then fill rule's "deploymentId" with function's "deployment", and "deploymentId" as backup */ $deploymentResourceType = null; @@ -346,14 +349,29 @@ class V22 extends Migration ->setAttribute('deploymentResourceType', $document->getAttribute('deploymentResourceType', $deploymentResourceType)) ->setAttribute('search', \implode(' ', [$document->getId(), $document->getAttribute('domain', '')])); + $project = $this->dbForProject->getDocument('projects', $document->getAttribute('projectId')); + + if ($project->isEmpty()) { + Console::warning("Project \"{$document->getAttribute('projectId')}\" not found for rule \"{$document->getId()}\""); + $document->setAttribute('region', System::getEnv('_APP_DEFAULT_REGION')); + break; + } + + $document->setAttribute('region', $project->getAttribute('region', System::getEnv('_APP_DEFAULT_REGION'))); + + $domain = $document->getAttribute('domain', ''); + $functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', ''); + $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); + $owner = $document->getAttribute('owner', ''); + if ( + empty($owner) && + (!empty($functionsDomain) && \str_ends_with($domain, $functionsDomain)) || + (!empty($sitesDomain) && \str_ends_with($domain, $sitesDomain)) + ) { + $document->setAttribute('owner', 'Appwrite'); + } + if ($deploymentResourceType === 'function') { - $project = $this->dbForProject->getDocument('projects', $document->getAttribute('projectId')); - - if ($project->isEmpty()) { - Console::warning("Project \"{$document->getAttribute('projectId')}\" not found for rule \"{$document->getId()}\""); - break; - } - $dbForOwnerProject = ($this->getProjectDB)($project); $function = $dbForOwnerProject->getDocument('functions', $resourceId); From 0ec7dcf08da747705b22f36d5ddff69b6bce665b Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Fri, 23 May 2025 15:07:45 -0700 Subject: [PATCH 29/31] Bump console to version 6.0.11 --- app/views/install/compose.phtml | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index f53a6f2545..d78bca7a38 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -177,7 +177,7 @@ $image = $this->getParam('image', ''); appwrite-console: <<: *x-logging container_name: appwrite-console - image: /console:6.0.8 + image: /console:6.0.11 restart: unless-stopped networks: - appwrite diff --git a/docker-compose.yml b/docker-compose.yml index 6c7900ac78..847e2fa72c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -213,7 +213,7 @@ services: appwrite-console: <<: *x-logging container_name: appwrite-console - image: appwrite/console:6.0.8 + image: appwrite/console:6.0.11 restart: unless-stopped networks: - appwrite From b932db34f3099ce3c90a1d94402601acae271030 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Fri, 23 May 2025 15:57:49 -0700 Subject: [PATCH 30/31] Bump appwrite version to 1.7.3 --- README-CN.md | 6 +++--- README.md | 6 +++--- app/init/constants.php | 2 +- src/Appwrite/Migration/Migration.php | 1 + 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README-CN.md b/README-CN.md index 811fe6435c..49a97aab53 100644 --- a/README-CN.md +++ b/README-CN.md @@ -72,7 +72,7 @@ docker run -it --rm \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \ --entrypoint="install" \ - appwrite/appwrite:1.7.2 + appwrite/appwrite:1.7.3 ``` ### Windows @@ -84,7 +84,7 @@ docker run -it --rm ^ --volume //var/run/docker.sock:/var/run/docker.sock ^ --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^ --entrypoint="install" ^ - appwrite/appwrite:1.7.2 + appwrite/appwrite:1.7.3 ``` #### PowerShell @@ -94,7 +94,7 @@ docker run -it --rm ` --volume /var/run/docker.sock:/var/run/docker.sock ` --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw ` --entrypoint="install" ` - appwrite/appwrite:1.7.2 + appwrite/appwrite:1.7.3 ``` 运行后,可以在浏览器上访问 http://localhost 找到 Appwrite 控制台。在非 Linux 的本机主机上完成安装后,服务器可能需要几分钟才能启动。 diff --git a/README.md b/README.md index f29be0bd61..d19d56fdd0 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ docker run -it --rm \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \ --entrypoint="install" \ - appwrite/appwrite:1.7.2 + appwrite/appwrite:1.7.3 ``` ### Windows @@ -90,7 +90,7 @@ docker run -it --rm ^ --volume //var/run/docker.sock:/var/run/docker.sock ^ --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^ --entrypoint="install" ^ - appwrite/appwrite:1.7.2 + appwrite/appwrite:1.7.3 ``` #### PowerShell @@ -100,7 +100,7 @@ docker run -it --rm ` --volume /var/run/docker.sock:/var/run/docker.sock ` --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw ` --entrypoint="install" ` - appwrite/appwrite:1.7.2 + appwrite/appwrite:1.7.3 ``` Once the Docker installation is complete, go to http://localhost to access the Appwrite console from your browser. Please note that on non-Linux native hosts, the server might take a few minutes to start after completing the installation. diff --git a/app/init/constants.php b/app/init/constants.php index f364b10d6e..e1b595a10f 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -38,7 +38,7 @@ const APP_RESOURCE_TOKEN_ACCESS = 24 * 60 * 60; // 24 hours const APP_FILE_ACCESS = 24 * 60 * 60; // 24 hours const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours const APP_CACHE_BUSTER = 4319; -const APP_VERSION_STABLE = '1.7.2'; +const APP_VERSION_STABLE = '1.7.3'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; const APP_DATABASE_ATTRIBUTE_ENUM = 'enum'; const APP_DATABASE_ATTRIBUTE_IP = 'ip'; diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 81ea1ef263..a2b1109eb3 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -87,6 +87,7 @@ abstract class Migration '1.7.0' => 'V22', '1.7.1' => 'V22', '1.7.2' => 'V22', + '1.7.3' => 'V22', ]; /** From 295e2773f33d4d13de2dde42aee24a8906c2975f Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Fri, 23 May 2025 17:39:54 -0700 Subject: [PATCH 31/31] fix(migration): _APP_DEFAULT_REGION is not a valid env var Across the rest of the codebase, we use _APP_REGION with 'default' as the fallback value. This commit updates the migration to do the same. --- src/Appwrite/Migration/Version/V22.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Migration/Version/V22.php b/src/Appwrite/Migration/Version/V22.php index a10017c99f..2a6a64ed48 100644 --- a/src/Appwrite/Migration/Version/V22.php +++ b/src/Appwrite/Migration/Version/V22.php @@ -353,11 +353,11 @@ class V22 extends Migration if ($project->isEmpty()) { Console::warning("Project \"{$document->getAttribute('projectId')}\" not found for rule \"{$document->getId()}\""); - $document->setAttribute('region', System::getEnv('_APP_DEFAULT_REGION')); + $document->setAttribute('region', System::getEnv('_APP_REGION', 'default')); break; } - $document->setAttribute('region', $project->getAttribute('region', System::getEnv('_APP_DEFAULT_REGION'))); + $document->setAttribute('region', $project->getAttribute('region', System::getEnv('_APP_REGION', 'default'))); $domain = $document->getAttribute('domain', ''); $functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', '');