From a2cb3c135fb15af0993b6ffd869882025da6760d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 11 Apr 2023 23:42:06 +1200 Subject: [PATCH] Fix migration of floats --- app/init.php | 2 +- app/tasks/migrate.php | 2 +- src/Appwrite/Migration/Version/V18.php | 29 ++++++++------------------ 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/app/init.php b/app/init.php index 6620985cdc..980040da68 100644 --- a/app/init.php +++ b/app/init.php @@ -101,7 +101,7 @@ const APP_LIMIT_LIST_DEFAULT = 25; // Default maximum number of items to return const APP_KEY_ACCCESS = 24 * 60 * 60; // 24 hours const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours const APP_CACHE_BUSTER = 501; -const APP_VERSION_STABLE = '1.2.1'; +const APP_VERSION_STABLE = '1.3.0'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; const APP_DATABASE_ATTRIBUTE_ENUM = 'enum'; const APP_DATABASE_ATTRIBUTE_IP = 'ip'; diff --git a/app/tasks/migrate.php b/app/tasks/migrate.php index ded157e54b..7bb52f8970 100644 --- a/app/tasks/migrate.php +++ b/app/tasks/migrate.php @@ -88,8 +88,8 @@ $cli ->setPDO($register->get('db')) ->execute(); } catch (\Throwable $th) { - throw $th; Console::error('Failed to update project ("' . $project->getId() . '") version with error: ' . $th->getMessage()); + throw $th; } clearProjectsCache($redis, $project); diff --git a/src/Appwrite/Migration/Version/V18.php b/src/Appwrite/Migration/Version/V18.php index 7ae982da5c..7951168568 100644 --- a/src/Appwrite/Migration/Version/V18.php +++ b/src/Appwrite/Migration/Version/V18.php @@ -41,10 +41,9 @@ class V18 extends Migration $this->migrateCollections(); Console::info('Migrating Documents'); - $this->forEachDocument([$this, 'migrateDocument']); - - Console::info('Migrating Cache'); - $this->forEachDocument([$this, 'migrateCache']); + $this->forEachDocument(function (Document $document) { + $this->migrateDocument($document); + }); } /** @@ -59,15 +58,16 @@ class V18 extends Migration $databaseTable = "database_{$database->getInternalId()}"; Console::info("Migrating Collections of {$database->getId()} ({$database->getAttribute('name')})"); + foreach ($this->documentsIterator($databaseTable) as $collection) { $collectionTable = "{$databaseTable}_collection_{$collection->getInternalId()}"; - $floats = \array_filter($collection->getAttributes(), function ($attribute) { - return $attribute->getAttribute('type') === Database::VAR_FLOAT; + $floats = \array_filter($collection['attributes'] ?? [], function ($attribute) { + return $attribute['type'] === Database::VAR_FLOAT; }); foreach ($floats as $attribute) { - $this->changeAttributeInternalType($collectionTable, $attribute->getId(), 'DOUBLE'); + $this->changeAttributeInternalType($collectionTable, $attribute['key'], 'DOUBLE'); } } } @@ -85,12 +85,12 @@ class V18 extends Migration Console::log("Migrating Collection \"{$id}\""); - $floats = \array_filter($collection, function ($attribute) { + $floats = \array_filter($collection['attributes'] ?? [], function ($attribute) { return $attribute['type'] === Database::VAR_FLOAT; }); foreach ($floats as $attribute) { - $this->changeAttributeInternalType($id, $attribute->getId(), 'DOUBLE'); + $this->changeAttributeInternalType($id, $attribute['$id'], 'DOUBLE'); } switch ($id) { @@ -146,15 +146,4 @@ class V18 extends Migration return $document; } - - private function migrateCache(Document $document) - { - $key = "cache-_{$this->project->getInternalId()}:{$document->getCollection()}:{$document->getId()}"; - $value = $this->redis->get($key); - - if ($value) { - $this->redis->del($key); - $this->redis->set($key . ':*', $value); - } - } }