From 5ae534d291e1fa74d41d4ced63585ab3e12a5f9b Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 11 Jun 2023 10:59:44 +0300 Subject: [PATCH] Addressing comments --- src/Appwrite/Migration/Migration.php | 4 +- src/Appwrite/Migration/Version/V19.php | 60 +++----------------------- 2 files changed, 9 insertions(+), 55 deletions(-) diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 544e503ab5..6d315aa2e3 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -62,8 +62,8 @@ abstract class Migration '1.3.4' => 'V18', '1.3.5' => 'V18', '1.3.6' => 'V18', - //'1.3.7' => 'V18', - '1.3.7' => 'V19', + '1.3.7' => 'V18', + '1.4.0' => 'V19', ]; /** diff --git a/src/Appwrite/Migration/Version/V19.php b/src/Appwrite/Migration/Version/V19.php index 96c9376357..2e52539c91 100644 --- a/src/Appwrite/Migration/Version/V19.php +++ b/src/Appwrite/Migration/Version/V19.php @@ -6,8 +6,6 @@ use Appwrite\Migration\Migration; use Utopia\CLI\Console; use Utopia\Database\Database; use Utopia\Database\Document; -use Utopia\Database\Helpers\Permission; -use Utopia\Database\Helpers\Role; class V19 extends Migration { @@ -39,8 +37,8 @@ class V19 extends Migration Console::info('Migrating Buckets'); $this->migrateBuckets(); - //Console::info('Migrating Documents'); - // $this->forEachDocument([$this, 'fixDocument']); + Console::info('Migrating Documents'); + $this->forEachDocument([$this, 'fixDocument']); } /** @@ -99,46 +97,7 @@ class V19 extends Migration /** * Bump version number. */ - $document->setAttribute('version', '1.3.0'); - - /** - * Set default passwordHistory - */ - $document->setAttribute('auths', array_merge([ - 'passwordHistory' => 0, - 'passwordDictionary' => false, - ], $document->getAttribute('auths', []))); - break; - case 'users': - /** - * Default Password history - */ - $document->setAttribute('passwordHistory', $document->getAttribute('passwordHistory', [])); - break; - case 'teams': - /** - * Default prefs - */ - $document->setAttribute('prefs', $document->getAttribute('prefs', new \stdClass())); - break; - case 'attributes': - /** - * Default options - */ - $document->setAttribute('options', $document->getAttribute('options', new \stdClass())); - break; - case 'buckets': - /** - * Set the bucket permission in the metadata table - */ - try { - $internalBucketId = "bucket_{$this->project->getInternalId()}"; - $permissions = $document->getPermissions(); - $fileSecurity = $document->getAttribute('fileSecurity', false); - $this->projectDB->updateCollection($internalBucketId, $permissions, $fileSecurity); - } catch (\Throwable $th) { - Console::warning($th->getMessage()); - } + $document->setAttribute('version', '1.4.0'); break; } @@ -147,16 +106,11 @@ class V19 extends Migration protected function alterPermissionIndex($collectionName): void { - $collectionName = "`{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$collectionName}_perms`"; - try { - $this->pdo->prepare("ALTER TABLE {$collectionName} DROP INDEX `_permission`")->execute(); - } catch (\Throwable $th) { - Console::warning($th->getMessage()); - } - - try { - $this->pdo->prepare("ALTER TABLE {$collectionName} ADD INDEX `_permission` (`_permission`, `_type`, `_document`)")->execute(); + $this->pdo->prepare("ALTER TABLE `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$collectionName}_perms` + DROP INDEX `_permission`, + ADD INDEX `_permission` (`_permission`, `_type`, `_document`) + ")->execute(); } catch (\Throwable $th) { Console::warning($th->getMessage()); }