From 55932594d01d0b753643572cfe53cead2add9e74 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 13:22:46 +0200 Subject: [PATCH 1/2] Updated migration script --- app/tasks/migrate.php | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/app/tasks/migrate.php b/app/tasks/migrate.php index e44488ce0b..abfd295d8d 100644 --- a/app/tasks/migrate.php +++ b/app/tasks/migrate.php @@ -7,15 +7,18 @@ use Utopia\CLI\Console; use Appwrite\Database\Database; use Appwrite\Database\Document; use Appwrite\Database\Validator\Authorization; +use Appwrite\Database\Adapter\MySQL as MySQLAdapter; +use Appwrite\Database\Adapter\Redis as RedisAdapter; $callbacks = [ '0.4.0' => function() { Console::log('I got nothing to do.'); }, - '0.5.0' => function($project) use ($register, $projectDB, $requset) { + + '0.5.0' => function($project) use ($register, $projectDB) { $db = $register->get('db'); - Console::log('Migrating project: '.$project->getId()); + Console::log('Migrating project: '.$project->getAttribute('name').' ('.$project->getId().')'); // Update all documents $uid -> $id @@ -46,6 +49,7 @@ $callbacks = [ try { $new = $projectDB->overwriteDocument($document->getArrayCopy()); } catch (\Throwable $th) { + var_dump($document); Console::error('Failed to update document: '.$th->getMessage()); continue; } @@ -107,6 +111,14 @@ function fixDocument(Document $document) { } } + if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_WEBHOOKS){ + $document->setAttribute('security', ($document->getAttribute('security')) ? true : false); + } + + if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_TASKS){ + $document->setAttribute('security', ($document->getAttribute('security')) ? true : false); + } + if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_USERS) { foreach($providers as $key => $provider) { if(!empty($document->getAttribute('oauth'.\ucfirst($key)))) { @@ -165,26 +177,38 @@ function fixDocument(Document $document) { $cli ->task('migrate') - ->action(function () use ($console, $projectDB, $consoleDB, $callbacks) { + ->action(function () use ($register, $callbacks) { Console::success('Starting Data Migration'); + $consoleDB = new Database(); + $consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); + $consoleDB->setNamespace('app_console'); // Main DB + $consoleDB->setMocks(Config::getParam('collections', [])); + + $projectDB = new Database(); + $projectDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); + $projectDB->setMocks(Config::getParam('collections', [])); + + $console = $consoleDB->getDocument('console'); + Authorization::disable(); $limit = 30; $sum = 30; $offset = 0; $projects = [$console]; + $count = 0; while ($sum >= 30) { foreach($projects as $project) { + $projectDB->setNamespace('app_'.$project->getId()); try { - $callbacks['0.5.0']($project); + $callbacks['0.5.0']($project, $projectDB); } catch (\Throwable $th) { + throw $th; Console::error('Failed to update project ("'.$project->getId().'") version with error: '.$th->getMessage()); - $projectDB->setNamespace('app_console'); - $projectDB->deleteDocument($project->getId()); } } @@ -201,8 +225,9 @@ $cli $sum = \count($projects); $offset = $offset + $limit; + $count = $count + $sum; - Console::log('Fetched '.$sum.' projects...'); + Console::log('Fetched '.$count.'/'.$consoleDB->getSum().' projects...'); } Console::success('Data Migration Completed'); From ef3822e6d8ea7f97c8b42036e52e2b4b40b45aa1 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 13:24:46 +0200 Subject: [PATCH 2/2] Added missing bin file --- bin/sdks | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 bin/sdks diff --git a/bin/sdks b/bin/sdks new file mode 100644 index 0000000000..bf117125f2 --- /dev/null +++ b/bin/sdks @@ -0,0 +1,3 @@ +#!/bin/sh + +php /usr/src/code/app/cli.php sdk $@ \ No newline at end of file