get project db for CLI
This commit is contained in:
parent
5b1f8bb2a4
commit
ff6c6003fc
24
app/cli.php
24
app/cli.php
|
@ -12,6 +12,7 @@ use Utopia\Config\Config;
|
||||||
use Utopia\Database\Database;
|
use Utopia\Database\Database;
|
||||||
use Utopia\Database\Validator\Authorization;
|
use Utopia\Database\Validator\Authorization;
|
||||||
use InfluxDB\Database as InfluxDatabase;
|
use InfluxDB\Database as InfluxDatabase;
|
||||||
|
use Utopia\Database\Document;
|
||||||
|
|
||||||
function getInfluxDB(): InfluxDatabase
|
function getInfluxDB(): InfluxDatabase
|
||||||
{
|
{
|
||||||
|
@ -59,6 +60,29 @@ function getConsoleDB(): Database
|
||||||
return $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
|
function getCache(): Cache
|
||||||
{
|
{
|
||||||
global $register;
|
global $register;
|
||||||
|
|
Loading…
Reference in a new issue