From bd89fd4bf5d99b608d2473bd00fff345f15bfc22 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 30 Aug 2023 13:40:02 -0700 Subject: [PATCH] Fix domains migration The previous approach tried to migrate the 'rules' collection, but that didn't work because the data was in the 'domains' collection. Since the 'domains' collection was removed, the migration is now done when migrating the 'projects' collection by fetching the domains and then creating the rule documents. --- src/Appwrite/Migration/Version/V19.php | 57 +++++++++++++++----------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/src/Appwrite/Migration/Version/V19.php b/src/Appwrite/Migration/Version/V19.php index 921aacbded..d59aa8302c 100644 --- a/src/Appwrite/Migration/Version/V19.php +++ b/src/Appwrite/Migration/Version/V19.php @@ -10,6 +10,7 @@ use Utopia\Database\Database; use Utopia\Database\DateTime; use Utopia\Database\Document; use Utopia\Database\Exception; +use Utopia\Database\Query; class V19 extends Migration { @@ -33,6 +34,11 @@ class V19 extends Migration Console::info('Migrating Collections'); $this->migrateCollections(); + if ($this->project->getId() == 'console') { + Console::info('Migrating Domains'); + $this->migrateDomains(); + } + Console::info('Migrating Buckets'); $this->migrateBuckets(); @@ -43,6 +49,33 @@ class V19 extends Migration $this->cleanCollections(); } + protected function migrateDomains(): void + { + foreach ($this->documentsIterator('domains') as $domain) { + $status = 'created'; + if ($domain->getAttribute('verification', false)) { + $status = 'verified'; + } + + $ruleDocument = new Document([ + 'projectId' => $domain->getAttribute('projectId'), + 'projectInternalId' => $domain->getAttribute('projectInternalId'), + 'domain' => $domain->getAttribute('domain'), + 'resourceType' => 'api', + 'resourceInternalId' => '', + 'resourceId' => '', + 'status' => $status, + 'certificateId' => $domain->getAttribute('certificateId'), + ]); + + try { + $this->consoleDB->createDocument('rules', $ruleDocument); + } catch (\Throwable $th) { + Console::warning("Error migrating domain {$domain->getAttribute('domain')}: {$th->getMessage()}"); + } + } + } + /** * Migrating all Bucket tables. * @@ -611,30 +644,6 @@ class V19 extends Migration $document->setAttribute('smtp', []); $document->setAttribute('templates', []); - break; - case 'rules': - $status = 'created'; - if ($document->getAttribute('verification', false)) { - $status = 'verified'; - } - - $ruleDocument = new Document([ - 'projectId' => $this->project->getId(), - 'projectInternalId' => $this->project->getInternalId(), - 'domain' => $document->getAttribute('domain'), - 'resourceType' => 'api', - 'resourceInternalId' => '', - 'resourceId' => '', - 'status' => $status, - 'certificateId' => $document->getAttribute('certificateId'), - ]); - - try { - $this->consoleDB->createDocument('rules', $ruleDocument); - } catch (\Throwable $th) { - Console::warning("Error migrating domain {$document->getAttribute('domain')}: {$th->getMessage()}"); - } - break; default: break;