From 941b11da63600aaa5169053da0db7651f38c5132 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Mon, 27 Jul 2026 17:11:15 +0530 Subject: [PATCH] fix(vcs): scope region check to project DB access on installation deleted Region mismatch now only skips the functions/sites disconnect step (which needs the project's own database), not the platform-level repositories/installations cleanup, avoiding orphaned records across regions. Also checks the project's assigned database pool for the current region instead of comparing a region attribute directly, matching the existing check in Deployment::createGitDeployments. --- .../Modules/VCS/Http/GitHub/Events/Create.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php index 7010584e84..6a87450cd9 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php @@ -8,13 +8,16 @@ use Appwrite\Platform\Modules\VCS\Http\GitHub\Deployment; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; use Appwrite\Vcs\Factory as VcsFactory; +use Utopia\Config\Config; use Utopia\Console; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; +use Utopia\DSN\DSN; use Utopia\Platform\Scope\HTTP; use Utopia\Span\Span; +use Utopia\System\System; use Utopia\VCS\Adapter\Git\GitHub; class Create extends Action @@ -121,7 +124,7 @@ class Create extends Action $projectId = $installation->getAttribute('projectId', ''); $project = $authorization->skip(fn () => $dbForPlatform->getDocument('projects', $projectId)); - if (!$project->isEmpty()) { + if (!$project->isEmpty() && $this->isProjectInCurrentRegion($project)) { $dbForProject = $getProjectDB($project); foreach (['functions', 'sites'] as $collection) { @@ -179,6 +182,24 @@ class Create extends Action } while ($installationCursor !== null); } + private function isProjectInCurrentRegion(Document $project): bool + { + try { + $dsn = new DSN($project->getAttribute('database')); + $databaseName = $dsn->getHost(); + } catch (\InvalidArgumentException) { + $databaseName = $project->getAttribute('database'); + } + + $databases = Config::getParam('pools-database', []); + if (!\in_array($databaseName, $databases)) { + Console::warning("Skipping project {$project->getId()}: database '{$databaseName}' is not part of region " . System::getEnv('_APP_REGION')); + return false; + } + + return true; + } + private function handlePushEvent( array $parsedPayload, VcsFactory $vcsFactory,