From 883cfedc469176b6d0f57a8f9bbd9cd01b6462f7 Mon Sep 17 00:00:00 2001 From: shimon Date: Thu, 1 Feb 2024 22:14:09 +0200 Subject: [PATCH] updates --- src/Appwrite/Migration/Version/V20.php | 29 +++++++++++++++++++++---- src/Appwrite/Platform/Tasks/Migrate.php | 1 - 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Migration/Version/V20.php b/src/Appwrite/Migration/Version/V20.php index 30f1f4fab0..5831d46fc5 100644 --- a/src/Appwrite/Migration/Version/V20.php +++ b/src/Appwrite/Migration/Version/V20.php @@ -72,9 +72,26 @@ class V20 extends Migration default => 'projects', }; - $databases = $this->projectDB->find('databases', []); - foreach ($databases as $database) { - var_dump($database); + // Support database array type migration (user collections) + $attributes = $this->projectDB->find('attributes', [ + Query::equal('array', [true]), + ]); + + foreach ($attributes as $attribute) { + $indexes = $this->projectDB->find('indexes', [ + Query::equal('databaseInternalId', [$attribute['databaseInternalId']]), + Query::equal('collectionInternalId', [$attribute['collectionInternalId']]), + ]); + $foundIndex = 0; + foreach ($indexes as $index) { + if (in_array($attribute['key'], $index['attributes'])) { + $this->projectDB->deleteIndex($index['collectionId'], $index['_uid']); + $foundIndex = 1; + } + } + if ($foundIndex === 1) { + $this->projectDB->updateAttribute($attribute['collectionInternalId'], $attribute['key'], Database::VAR_STRING); + } } $collections = $this->collections[$collectionType]; @@ -86,14 +103,18 @@ class V20 extends Migration $this->projectDB->setNamespace("_$internalProjectId"); // Support database array type migration + $foundIndex = 0; foreach ($collection['attributes'] ?? [] as $attribute) { if ($attribute['array'] === true) { foreach ($collection['indexes'] ?? [] as $index) { if (in_array($attribute['$id'], $index['attributes'])) { $this->projectDB->deleteIndex($id, $index['$id']); + $foundIndex = 1; } } - $this->projectDB->updateAttribute($id, $attribute['$id'], Database::VAR_STRING); + if ($foundIndex === 1) { + $this->projectDB->updateAttribute($id, $attribute['$id'], Database::VAR_STRING); + } } } diff --git a/src/Appwrite/Platform/Tasks/Migrate.php b/src/Appwrite/Platform/Tasks/Migrate.php index ce37cbd8d4..682b9b5559 100644 --- a/src/Appwrite/Platform/Tasks/Migrate.php +++ b/src/Appwrite/Platform/Tasks/Migrate.php @@ -93,7 +93,6 @@ class Migrate extends Action // TODO: Iterate through all project DBs /** @var Database $projectDB */ $projectDB = $getProjectDB($project); - var_dump($project); $migration ->setProject($project, $projectDB, $dbForConsole) ->setPDO($register->get('db', true))