From 21d40f4849fd4c7eaf5feedbd6fc4cc6028182b4 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 9 Sep 2022 19:50:05 +0200 Subject: [PATCH] fix: qa --- app/tasks/migrate.php | 10 ++++++++++ src/Appwrite/Migration/Version/V15.php | 22 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/tasks/migrate.php b/app/tasks/migrate.php index 058010bf93..f0ab71a964 100644 --- a/app/tasks/migrate.php +++ b/app/tasks/migrate.php @@ -45,6 +45,9 @@ $cli $limit = 30; $sum = 30; $offset = 0; + /** + * @var \Utopia\Database\Document[] $projects + */ $projects = [$console]; $count = 0; @@ -60,6 +63,13 @@ $cli while (!empty($projects)) { foreach ($projects as $project) { + /** + * Skip user projects with id 'console' + */ + if ($project->getId() === 'console' && $project->getInternalId() !== 'console') { + continue; + } + try { $migration ->setProject($project, $projectDB, $consoleDB) diff --git a/src/Appwrite/Migration/Version/V15.php b/src/Appwrite/Migration/Version/V15.php index a60de1b041..e94c93ef2f 100644 --- a/src/Appwrite/Migration/Version/V15.php +++ b/src/Appwrite/Migration/Version/V15.php @@ -28,7 +28,7 @@ class V15 extends Migration /** * Disable SubQueries for Performance. */ - foreach (['subQueryAttributes', 'subQueryIndexes', 'subQueryPlatforms', 'subQueryDomains', 'subQueryKeys', 'subQueryWebhooks', 'subQuerySessions', 'subQueryTokens', 'subQueryMemberships', 'subqueryVariables'] as $name) { + foreach (['subQueryIndexes', 'subQueryPlatforms', 'subQueryDomains', 'subQueryKeys', 'subQueryWebhooks', 'subQuerySessions', 'subQueryTokens', 'subQueryMemberships', 'subqueryVariables'] as $name) { Database::addFilter( $name, fn () => null, @@ -151,12 +151,32 @@ class V15 extends Migration $this->projectDB->updateDocument($databaseTable, $collection->getId(), $collection); Console::info("Migrating Documents of {$collection->getId()} ({$collection->getAttribute('name')})"); + $requiredAttributes = array_reduce($collection->getAttribute('attributes', []), function (array $carry, Document $item) { + if ($item->getAttribute('required', false)) { + $carry = array_merge($carry, [ + $item->getAttribute('key') => $item->getAttribute('default') + ]); + } + return $carry; + }, []); + foreach ($this->documentsIterator($collectionTable) as $document) { + foreach ($document->getAttributes() as $attribute => $default) { + if (array_key_exists($attribute, $requiredAttributes)) { + if (is_null($default)) { + Console::warning("Skipping migration for Document {$document->getId()} in Collection {$collection->getId()} ({$collection->getAttribute('name')}) because of missing required attribute \"{$attribute}\" without default value."); + + continue 2; + } + $document->setAttribute($attribute, $default); + } + } $this->populatePermissionsAttribute( document: $document, table: $collectionTable, addCreatePermission: false ); + $this->projectDB->updateDocument($collectionTable, $document->getId(), $document); } $this->removeWritePermissions($collectionTable);