From f6f8816e2b19f2c567d397707e1d22c8ba75e425 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Sat, 17 Feb 2024 11:29:49 +0000 Subject: [PATCH 1/8] 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'); From 461795b6ff742016c128bb344be1ea32c1fc773c Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Sun, 18 Feb 2024 08:35:26 +0000 Subject: [PATCH 2/8] Update V17.php --- src/Appwrite/Utopia/Request/Filters/V17.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Appwrite/Utopia/Request/Filters/V17.php b/src/Appwrite/Utopia/Request/Filters/V17.php index 246b52deae..d7a4039d7e 100644 --- a/src/Appwrite/Utopia/Request/Filters/V17.php +++ b/src/Appwrite/Utopia/Request/Filters/V17.php @@ -59,6 +59,10 @@ class V17 extends Filter private function convertOldQueries(array $content): array { + if (!isset($content['queries'])) { + return $content; + } + $parsed = []; foreach ($content['queries'] as $query) { try { From bfe861f8464db978db76390e57c3c8217706fb00 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Tue, 20 Feb 2024 15:05:42 +0000 Subject: [PATCH 3/8] Run Linter --- src/Appwrite/Migration/Version/V20.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Migration/Version/V20.php b/src/Appwrite/Migration/Version/V20.php index abc2bdac8e..fdf2f5163f 100644 --- a/src/Appwrite/Migration/Version/V20.php +++ b/src/Appwrite/Migration/Version/V20.php @@ -78,14 +78,18 @@ class V20 extends Migration // Support database array type migration (user collections) if ($collectionType === 'projects') { - foreach ($this->documentsIterator('attributes', [ + foreach ( + $this->documentsIterator('attributes', [ Query::equal('array', [true]), - ]) as $attribute) { + ]) as $attribute + ) { $foundIndex = false; - foreach ($this->documentsIterator('indexes', [ + foreach ( + $this->documentsIterator('indexes', [ Query::equal('databaseInternalId', [$attribute['databaseInternalId']]), Query::equal('collectionInternalId', [$attribute['collectionInternalId']]), - ]) as $index) { + ]) as $index + ) { if (in_array($attribute['key'], $index['attributes'])) { $this->projectDB->deleteIndex($index['collectionId'], $index['$id']); $foundIndex = true; From a5d6af9dedf3c2e5a09300cd66e0c1927a08c165 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Tue, 20 Feb 2024 15:47:55 +0000 Subject: [PATCH 4/8] Add 'factors' migration --- src/Appwrite/Migration/Version/V20.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Appwrite/Migration/Version/V20.php b/src/Appwrite/Migration/Version/V20.php index fdf2f5163f..f43da066c4 100644 --- a/src/Appwrite/Migration/Version/V20.php +++ b/src/Appwrite/Migration/Version/V20.php @@ -540,6 +540,7 @@ class V20 extends Migration $duration = $this->project->getAttribute('auths', [])['duration'] ?? Auth::TOKEN_EXPIRATION_LOGIN_LONG; $expire = DateTime::addSeconds(new \DateTime(), $duration); $document->setAttribute('expire', $expire); + $document->setAttribute('factors', ['email']); break; } return $document; From 370e814b8c5f87b51eafb9e92a4d13ca98b3d030 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 21 Feb 2024 09:31:52 +0000 Subject: [PATCH 5/8] Update Factors Session Migration --- src/Appwrite/Migration/Version/V20.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Migration/Version/V20.php b/src/Appwrite/Migration/Version/V20.php index f43da066c4..1796629db0 100644 --- a/src/Appwrite/Migration/Version/V20.php +++ b/src/Appwrite/Migration/Version/V20.php @@ -540,7 +540,14 @@ class V20 extends Migration $duration = $this->project->getAttribute('auths', [])['duration'] ?? Auth::TOKEN_EXPIRATION_LOGIN_LONG; $expire = DateTime::addSeconds(new \DateTime(), $duration); $document->setAttribute('expire', $expire); - $document->setAttribute('factors', ['email']); + + $factors = match ($document->getAttribute('provider')) { + Auth::SESSION_PROVIDER_ANONYMOUS => ['anonymous'], + Auth::SESSION_PROVIDER_PHONE => ['phone'], + default => ['email'], + }; + + $document->setAttribute('factors', $factors); break; } return $document; From a2b9dbc2081d6890109e18484d0e0628a14e1560 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 21 Feb 2024 09:42:04 +0000 Subject: [PATCH 6/8] Update V20.php --- src/Appwrite/Migration/Version/V20.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Appwrite/Migration/Version/V20.php b/src/Appwrite/Migration/Version/V20.php index 1796629db0..61f84c919b 100644 --- a/src/Appwrite/Migration/Version/V20.php +++ b/src/Appwrite/Migration/Version/V20.php @@ -47,6 +47,7 @@ class V20 extends Migration Console::info('Migrating Collections'); $this->migrateCollections(); + // No need to migrate stats for console if ($this->project->getInternalId() !== 'console') { Console::info('Migrating Functions'); $this->migrateFunctions(); From d020730a74eccc20b541bd2be6b9be942080e1a1 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 21 Feb 2024 10:20:55 +0000 Subject: [PATCH 7/8] Address Shimon's comments --- src/Appwrite/Migration/Version/V20.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Migration/Version/V20.php b/src/Appwrite/Migration/Version/V20.php index 61f84c919b..e0055300e0 100644 --- a/src/Appwrite/Migration/Version/V20.php +++ b/src/Appwrite/Migration/Version/V20.php @@ -35,12 +35,6 @@ class V20 extends Migration ); } - $this->migrateUsageMetrics('project.$all.network.requests', 'network.requests'); - $this->migrateUsageMetrics('project.$all.network.outbound', 'network.outbound'); - $this->migrateUsageMetrics('project.$all.network.inbound', 'network.inbound'); - $this->migrateUsageMetrics('users.$all.count.total', 'users'); - $this->migrateSessionsMetric(); - Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')'); $this->projectDB->setNamespace("_{$this->project->getInternalId()}"); @@ -49,6 +43,12 @@ class V20 extends Migration // No need to migrate stats for 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'); + $this->migrateUsageMetrics('users.$all.count.total', 'users'); + $this->migrateSessionsMetric(); + Console::info('Migrating Functions'); $this->migrateFunctions(); From bdf044ed8cb81c0851e69f2206843386ae927a69 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 22 Feb 2024 10:21:25 +0000 Subject: [PATCH 8/8] Update 'email' to 'password' in factors --- src/Appwrite/Migration/Version/V20.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Migration/Version/V20.php b/src/Appwrite/Migration/Version/V20.php index e0055300e0..0ef899588e 100644 --- a/src/Appwrite/Migration/Version/V20.php +++ b/src/Appwrite/Migration/Version/V20.php @@ -545,7 +545,7 @@ class V20 extends Migration $factors = match ($document->getAttribute('provider')) { Auth::SESSION_PROVIDER_ANONYMOUS => ['anonymous'], Auth::SESSION_PROVIDER_PHONE => ['phone'], - default => ['email'], + default => ['password'], }; $document->setAttribute('factors', $factors);