diff --git a/app/cli.php b/app/cli.php index 3a62c80816..23cea75306 100644 --- a/app/cli.php +++ b/app/cli.php @@ -12,6 +12,7 @@ use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\Validator\Authorization; use InfluxDB\Database as InfluxDatabase; +use Utopia\Database\Document; function getInfluxDB(): InfluxDatabase { @@ -59,6 +60,29 @@ function getConsoleDB(): Database return $database; } + +function getProjectDB(Document $project): Database +{ + global $register; + + $pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */ + + if ($project->isEmpty() || $project->getId() === 'console') { + return getConsoleDB(); + } + + $dbAdapter = $pools + ->get($project->getAttribute('database')) + ->pop() + ->getResource() + ; + + $database = new Database($dbAdapter, getCache()); + $database->setNamespace('_' . $project->getInternalId()); + + return $database; +} + function getCache(): Cache { global $register;