From 15ec0ac0ce9e6965c4cb4ed877f74ea31ebbf1fc Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 15 Sep 2026 14:15:52 +0530 Subject: [PATCH] fix(migrations): strip dev key scopes and stop hiding devKeys cleanup failures V25 removes devKeys.read and devKeys.write from key, function and site scopes. The devKeys attribute and collection are deleted only when they exist, and a failed delete now aborts the migration instead of logging a warning, since project documents cannot be decoded while the attribute remains. --- src/Appwrite/Migration/Version/V25.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index b1bfb152ea..6a9d6d95f9 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -73,16 +73,16 @@ class V25 extends Migration Console::warning("Failed to create index \"_key_accessedAt\" from {$id}: {$th->getMessage()}"); } - try { + $attributes = \array_map( + fn (Document $attribute) => $attribute->getId(), + $this->dbForProject->getCollection($id)->getAttribute('attributes', []) + ); + if (\in_array('devKeys', $attributes, true)) { $this->dbForProject->deleteAttribute($id, 'devKeys'); - } catch (Throwable $th) { - Console::warning("Failed to delete attribute \"devKeys\" from {$id}: {$th->getMessage()}"); } - try { + if (!$this->dbForProject->getCollection('devKeys')->isEmpty()) { $this->dbForProject->deleteCollection('devKeys'); - } catch (Throwable $th) { - Console::warning("Failed to delete collection \"devKeys\": {$th->getMessage()}"); } } $this->dbForProject->purgeCachedCollection($id); @@ -267,6 +267,15 @@ class V25 extends Migration protected function migrateDocument(Document $document): Document { + if (\in_array($document->getCollection(), ['keys', 'functions', 'sites'], true)) { + $scopes = $document->getAttribute('scopes', []); + if (\is_array($scopes) && \array_intersect($scopes, ['devKeys.read', 'devKeys.write']) !== []) { + $document->setAttribute('scopes', \array_values(\array_diff($scopes, ['devKeys.read', 'devKeys.write']))); + } + + return $document; + } + if ($document->getCollection() !== 'migrations') { return $document; }