From 8d9abd2f31f5302453b2b505f6d79e6335eac170 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Fri, 25 Apr 2025 16:06:35 -0700 Subject: [PATCH 1/2] fix(vcs): add missing attributes to 1.6.x migration --- src/Appwrite/Migration/Migration.php | 6 ++- src/Appwrite/Migration/Version/V21.php | 53 +++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 56016f1057..14c8a9cce2 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -92,7 +92,7 @@ abstract class Migration '1.5.11' => 'V20', '1.6.0' => 'V21', '1.6.1' => 'V21', - '1.6.2' => 'V22', + '1.6.2' => 'V21', ]; /** @@ -374,6 +374,10 @@ abstract class Migration default => 'projects', }; + if ($from === 'files') { + $collectionType = 'buckets'; + } + $collection = $this->collections[$collectionType][$from] ?? null; if (is_null($collection)) { diff --git a/src/Appwrite/Migration/Version/V21.php b/src/Appwrite/Migration/Version/V21.php index 0a89221b12..04e5adc5fb 100644 --- a/src/Appwrite/Migration/Version/V21.php +++ b/src/Appwrite/Migration/Version/V21.php @@ -74,6 +74,27 @@ class V21 extends Migration Console::warning("'accessedAt' from {$id}: {$th->getMessage()}"); } break; + case 'rules': + $attributesToCreate = ['owner', 'region']; + foreach ($attributesToCreate as $attribute) { + // Create attribute + try { + $this->createAttributeFromCollection($this->projectDB, $id, $attribute); + } catch (Throwable $th) { + Console::warning("'$attribute' from {$id}: {$th->getMessage()}"); + } + } + + $indexesToCreate = ['_key_owner', '_key_region']; + foreach ($indexesToCreate as $index) { + // Create index + try { + $this->createIndexFromCollection($this->projectDB, $id, $index); + } catch (Throwable $th) { + Console::warning("'$index' from {$id}: {$th->getMessage()}"); + } + } + break; case 'platforms': // Increase 'type' length to 255 try { @@ -82,6 +103,17 @@ class V21 extends Migration Console::warning("'type' from {$id}: {$th->getMessage()}"); } break; + case 'installations': + $attributesToCreate = ['personalAccessToken', 'personalAccessTokenExpiry', 'personalRefreshToken']; + foreach ($attributesToCreate as $attribute) { + // Create attribute + try { + $this->createAttributeFromCollection($this->projectDB, $id, $attribute); + } catch (Throwable $th) { + Console::warning("'$attribute' from {$id}: {$th->getMessage()}"); + } + } + break; case 'migrations': // Create destination attribute try { @@ -217,11 +249,30 @@ class V21 extends Migration foreach ($this->documentsIterator('buckets') as $bucket) { $bucketId = 'bucket_' . $bucket['$internalId']; + Console::log("Migrating Bucket {$bucketId} {$bucket->getId()} ({$bucket->getAttribute('name')})"); + try { $this->projectDB->updateAttribute($bucketId, 'metadata', size: 65534); + } catch (\Throwable $th) { + Console::warning("'metadata' from {$bucketId}: {$th->getMessage()}"); + } + + try { + $this->createAttributeFromCollection($this->projectDB, $bucketId, 'transformedAt', 'files'); + } catch (\Throwable $th) { + Console::warning("'transformedAt' from {$bucketId}: {$th->getMessage()}"); + } + + try { + $this->createIndexFromCollection($this->projectDB, $bucketId, '_key_transformedAt', 'files'); + } catch (\Throwable $th) { + Console::warning("'_key_transformedAt' from {$bucketId}: {$th->getMessage()}"); + } + + try { $this->projectDB->purgeCachedCollection($bucketId); } catch (\Throwable $th) { - Console::warning("'bucketId' from {$bucketId}: {$th->getMessage()}"); + Console::warning("purging {$bucketId}: {$th->getMessage()}"); } } } From 101283f345e6f9fb3ca3c4022281f39943dca217 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Fri, 25 Apr 2025 16:07:59 -0700 Subject: [PATCH 2/2] fix: prevent update migration from clearing scopes and resetting specs --- src/Appwrite/Migration/Version/V21.php | 12 ++-- src/Appwrite/Migration/Version/V22.php | 83 -------------------------- 2 files changed, 8 insertions(+), 87 deletions(-) delete mode 100644 src/Appwrite/Migration/Version/V22.php diff --git a/src/Appwrite/Migration/Version/V21.php b/src/Appwrite/Migration/Version/V21.php index 04e5adc5fb..c072c81a34 100644 --- a/src/Appwrite/Migration/Version/V21.php +++ b/src/Appwrite/Migration/Version/V21.php @@ -229,11 +229,15 @@ class V21 extends Migration $document->setAttribute('accessedAt', DateTime::now()); break; case 'functions': - // Add scopes attribute - $document->setAttribute('scopes', []); + // Set scopes attribute + if (empty($document->getAttribute('scopes', []))) { + $document->setAttribute('scopes', []); + } - // Add size attribute - $document->setAttribute('specification', APP_FUNCTION_SPECIFICATION_DEFAULT); + // Set specification attribute + if (empty($document->getAttribute('specification'))) { + $document->setAttribute('specification', APP_FUNCTION_SPECIFICATION_DEFAULT); + } } return $document; diff --git a/src/Appwrite/Migration/Version/V22.php b/src/Appwrite/Migration/Version/V22.php deleted file mode 100644 index 4d15662112..0000000000 --- a/src/Appwrite/Migration/Version/V22.php +++ /dev/null @@ -1,83 +0,0 @@ - null, - fn () => [] - ); - } - - Console::info('Migrating Collections'); - $this->migrateCollections(); - } - - /** - * Migrate Collections. - * - * @return void - * @throws Exception|Throwable - */ - private function migrateCollections(): void - { - $internalProjectId = $this->project->getInternalId(); - $collectionType = match ($internalProjectId) { - 'console' => 'console', - default => 'projects', - }; - - $collections = $this->collections[$collectionType]; - foreach ($collections as $collection) { - $id = $collection['$id']; - - Console::log("Migrating Collection \"{$id}\""); - - $this->projectDB->setNamespace("_$internalProjectId"); - - switch ($id) { - case 'installations': - // Create personalAccessToken attribute - try { - $this->createAttributeFromCollection($this->projectDB, $id, 'personalAccessToken'); - } catch (Throwable $th) { - Console::warning("'personalAccessToken' from {$id}: {$th->getMessage()}"); - } - - // Create personalAccessTokenExpiry attribute - try { - $this->createAttributeFromCollection($this->projectDB, $id, 'personalAccessTokenExpiry'); - } catch (Throwable $th) { - Console::warning("'personalAccessTokenExpiry' from {$id}: {$th->getMessage()}"); - } - - // Create personalRefreshToken attribute - try { - $this->createAttributeFromCollection($this->projectDB, $id, 'personalRefreshToken'); - } catch (Throwable $th) { - Console::warning("'personalRefreshToken' from {$id}: {$th->getMessage()}"); - } - break; - } - - usleep(50000); - } - } -}