get project db key by region

This commit is contained in:
shimon 2024-07-31 13:23:51 +03:00
parent 29e169fe95
commit 00fc34a2a4

View file

@ -17,9 +17,6 @@ use Utopia\Validator\Text;
class Migrate extends Action
{
/**
* @var Redis
*/
protected Redis $redis;
public static function getName(): string
@ -38,20 +35,10 @@ class Migrate extends Action
->inject('register')
->callback(fn ($version, $dbForConsole, $getProjectDB, Registry $register) => $this->action($version, $dbForConsole, $getProjectDB, $register));
$this->redis = new Redis();
$this->redis->connect(
System::getEnv('_APP_REDIS_HOST', null),
System::getEnv('_APP_REDIS_PORT', 6379),
3,
null,
10
);
}
private function clearProjectsCache(Document $project)
{
try {
do {
$iterator = null;
@ -64,24 +51,33 @@ class Migrate extends Action
}
} while ($iterator > 0);
} catch (\Throwable $th) {
Console::error('Failed to clear project ("' . $project->getId() . '") cache with error: ' . $th->getMessage());
Console::error('Failed to clear project ("'.$project->getId().'") cache with error: '.$th->getMessage());
}
}
public function action(string $version, Database $dbForConsole, callable $getProjectDB, Registry $register)
{
Authorization::disable();
if (!array_key_exists($version, Migration::$versions)) {
if (! array_key_exists($version, Migration::$versions)) {
Console::error("Version {$version} not found.");
Console::exit(1);
return;
}
$this->redis = new Redis();
$this->redis->connect(
System::getEnv('_APP_REDIS_HOST', null),
System::getEnv('_APP_REDIS_PORT', 6379),
3,
null,
10
);
$app = new App('UTC');
Console::success('Starting Data Migration to version ' . $version);
Console::success('Starting Data Migration to version '.$version);
$console = $app->getResource('console');
@ -101,11 +97,11 @@ class Migrate extends Action
$totalProjects = $dbForConsole->count('projects') + 1;
}
$class = 'Appwrite\\Migration\\Version\\' . Migration::$versions[$version];
$class = 'Appwrite\\Migration\\Version\\'.Migration::$versions[$version];
/** @var Migration $migration */
$migration = new $class();
while (!empty($projects)) {
while (! empty($projects)) {
foreach ($projects as $project) {
/**
* Skip user projects with id 'console'
@ -126,7 +122,7 @@ class Migrate extends Action
->setPDO($register->get('db', true))
->execute();
} catch (\Throwable $th) {
Console::error('Failed to update project ("' . $project->getId() . '") version with error: ' . $th->getMessage());
Console::error('Failed to update project ("'.$project->getId().'") version with error: '.$th->getMessage());
throw $th;
}
@ -139,7 +135,7 @@ class Migrate extends Action
$offset = $offset + $limit;
$count = $count + $sum;
Console::log('Migrated ' . $count . '/' . $totalProjects . ' projects...');
Console::log('Migrated '.$count.'/'.$totalProjects.' projects...');
}
Console::success('Data Migration Completed');