From f6f8816e2b19f2c567d397707e1d22c8ba75e425 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Sat, 17 Feb 2024 11:29:49 +0000 Subject: [PATCH] Migration Fixes --- app/init.php | 2 +- composer.lock | 10 ++--- src/Appwrite/Migration/Version/V20.php | 53 ++++++++++++-------------- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/app/init.php b/app/init.php index db4fe4d669..528ecdf777 100644 --- a/app/init.php +++ b/app/init.php @@ -113,7 +113,7 @@ const APP_KEY_ACCCESS = 24 * 60 * 60; // 24 hours const APP_USER_ACCCESS = 24 * 60 * 60; // 24 hours const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours const APP_CACHE_BUSTER = 329; -const APP_VERSION_STABLE = '1.4.13'; +const APP_VERSION_STABLE = '1.5.0'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; const APP_DATABASE_ATTRIBUTE_ENUM = 'enum'; const APP_DATABASE_ATTRIBUTE_IP = 'ip'; diff --git a/composer.lock b/composer.lock index 3956a87327..86c9472447 100644 --- a/composer.lock +++ b/composer.lock @@ -5019,16 +5019,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.8.1", + "version": "3.9.0", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "14f5fff1e64118595db5408e946f3a22c75807f7" + "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/14f5fff1e64118595db5408e946f3a22c75807f7", - "reference": "14f5fff1e64118595db5408e946f3a22c75807f7", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/d63cee4890a8afaf86a22e51ad4d97c91dd4579b", + "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b", "shasum": "" }, "require": { @@ -5095,7 +5095,7 @@ "type": "open_collective" } ], - "time": "2024-01-11T20:47:48+00:00" + "time": "2024-02-16T15:06:51+00:00" }, { "name": "swoole/ide-helper", diff --git a/src/Appwrite/Migration/Version/V20.php b/src/Appwrite/Migration/Version/V20.php index 0e7434c56c..abc2bdac8e 100644 --- a/src/Appwrite/Migration/Version/V20.php +++ b/src/Appwrite/Migration/Version/V20.php @@ -30,8 +30,8 @@ class V20 extends Migration foreach (['subQueryIndexes', 'subQueryPlatforms', 'subQueryDomains', 'subQueryKeys', 'subQueryWebhooks', 'subQuerySessions', 'subQueryTokens', 'subQueryMemberships', 'subQueryVariables', 'subQueryChallenges', 'subQueryProjectVariables', 'subQueryTargets', 'subQueryTopicTargets'] as $name) { Database::addFilter( $name, - fn() => null, - fn() => [] + fn () => null, + fn () => [] ); } @@ -47,14 +47,16 @@ class V20 extends Migration Console::info('Migrating Collections'); $this->migrateCollections(); - Console::info('Migrating Functions'); - $this->migrateFunctions(); + if ($this->project->getInternalId() !== 'console') { + Console::info('Migrating Functions'); + $this->migrateFunctions(); - Console::info('Migrating Databases'); - $this->migrateDatabases(); + Console::info('Migrating Databases'); + $this->migrateDatabases(); - Console::info('Migrating Buckets'); - $this->migrateBuckets(); + Console::info('Migrating Buckets'); + $this->migrateBuckets(); + } Console::info('Migrating Documents'); $this->forEachDocument([$this, 'fixDocument']); @@ -75,25 +77,23 @@ class V20 extends Migration }; // Support database array type migration (user collections) - foreach ( - $this->documentsIterator('attributes', [ + if ($collectionType === 'projects') { + foreach ($this->documentsIterator('attributes', [ Query::equal('array', [true]), - ]) as $attribute - ) { - $foundIndex = false; - foreach ( - $this->documentsIterator('indexes', [ - Query::equal('databaseInternalId', [$attribute['databaseInternalId']]), - Query::equal('collectionInternalId', [$attribute['collectionInternalId']]), - ]) as $index - ) { - if (in_array($attribute['key'], $index['attributes'])) { - $this->projectDB->deleteIndex($index['collectionId'], $index['$id']); - $foundIndex = true; + ]) as $attribute) { + $foundIndex = false; + foreach ($this->documentsIterator('indexes', [ + Query::equal('databaseInternalId', [$attribute['databaseInternalId']]), + Query::equal('collectionInternalId', [$attribute['collectionInternalId']]), + ]) as $index) { + if (in_array($attribute['key'], $index['attributes'])) { + $this->projectDB->deleteIndex($index['collectionId'], $index['$id']); + $foundIndex = true; + } + } + if ($foundIndex === true) { + $this->projectDB->updateAttribute($attribute['collectionInternalId'], $attribute['key'], $attribute['type']); } - } - if ($foundIndex === true) { - $this->projectDB->updateAttribute($attribute['collectionInternalId'], $attribute['key'], $attribute['type']); } } @@ -323,7 +323,6 @@ class V20 extends Migration */ protected function createInfMetric(string $metric, int $value): void { - try { /** * Creating inf metric @@ -351,7 +350,6 @@ class V20 extends Migration */ protected function migrateUsageMetrics(string $from, string $to): void { - /** * inf metric */ @@ -411,7 +409,6 @@ class V20 extends Migration */ private function migrateFunctions(): void { - $this->migrateUsageMetrics('deployment.$all.storage.size', 'deployments.storage'); $this->migrateUsageMetrics('builds.$all.compute.total', 'builds'); $this->migrateUsageMetrics('builds.$all.compute.time', 'builds.compute');