Update for function name change
This commit is contained in:
parent
eeb0eed29b
commit
464b913e90
11 changed files with 42 additions and 46 deletions
|
@ -71,7 +71,7 @@ CLI::setResource('dbForConsole', function ($pools, $cache) {
|
||||||
$collections = Config::getParam('collections', [])['console'];
|
$collections = Config::getParam('collections', [])['console'];
|
||||||
$last = \array_key_last($collections);
|
$last = \array_key_last($collections);
|
||||||
|
|
||||||
if (!($dbForConsole->exists($dbForConsole->getDefaultDatabase(), $last))) { /** TODO cache ready variable using registry */
|
if (!($dbForConsole->exists($dbForConsole->getDatabase(), $last))) { /** TODO cache ready variable using registry */
|
||||||
throw new Exception('Tables not ready yet.');
|
throw new Exception('Tables not ready yet.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) {
|
||||||
$dbForConsole->createCollection($key, $attributes, $indexes);
|
$dbForConsole->createCollection($key, $attributes, $indexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dbForConsole->getDocument('buckets', 'default')->isEmpty() && !$dbForConsole->exists($dbForConsole->getDefaultDatabase(), 'bucket_1')) {
|
if ($dbForConsole->getDocument('buckets', 'default')->isEmpty() && !$dbForConsole->exists($dbForConsole->getDatabase(), 'bucket_1')) {
|
||||||
Console::success('[Setup] - Creating default bucket...');
|
Console::success('[Setup] - Creating default bucket...');
|
||||||
$dbForConsole->createDocument('buckets', new Document([
|
$dbForConsole->createDocument('buckets', new Document([
|
||||||
'$id' => ID::custom('default'),
|
'$id' => ID::custom('default'),
|
||||||
|
|
44
app/init.php
44
app/init.php
|
@ -12,11 +12,11 @@ if (\file_exists(__DIR__ . '/../vendor/autoload.php')) {
|
||||||
require_once __DIR__ . '/../vendor/autoload.php';
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
ini_set('memory_limit', '512M');
|
\ini_set('memory_limit', '512M');
|
||||||
ini_set('display_errors', 1);
|
\ini_set('display_errors', 1);
|
||||||
ini_set('display_startup_errors', 1);
|
\ini_set('display_startup_errors', 1);
|
||||||
ini_set('default_socket_timeout', -1);
|
\ini_set('default_socket_timeout', -1);
|
||||||
error_reporting(E_ALL);
|
\error_reporting(E_ALL);
|
||||||
|
|
||||||
use Appwrite\Event\Migration;
|
use Appwrite\Event\Migration;
|
||||||
use Appwrite\Extend\Exception;
|
use Appwrite\Extend\Exception;
|
||||||
|
@ -34,6 +34,7 @@ use Appwrite\OpenSSL\OpenSSL;
|
||||||
use Appwrite\URL\URL as AppwriteURL;
|
use Appwrite\URL\URL as AppwriteURL;
|
||||||
use Appwrite\Usage\Stats;
|
use Appwrite\Usage\Stats;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
|
use Utopia\CLI\Console;
|
||||||
use Utopia\Logger\Logger;
|
use Utopia\Logger\Logger;
|
||||||
use Utopia\Cache\Adapter\Redis as RedisCache;
|
use Utopia\Cache\Adapter\Redis as RedisCache;
|
||||||
use Utopia\Cache\Cache;
|
use Utopia\Cache\Cache;
|
||||||
|
@ -653,14 +654,13 @@ $register->set('pools', function () {
|
||||||
|
|
||||||
foreach ($connections as $key => $connection) {
|
foreach ($connections as $key => $connection) {
|
||||||
$type = $connection['type'] ?? '';
|
$type = $connection['type'] ?? '';
|
||||||
$dsns = $connection['dsns'] ?? '';
|
$multiple = $connection['multiple'] ?? false;
|
||||||
$multipe = $connection['multiple'] ?? false;
|
|
||||||
$schemes = $connection['schemes'] ?? [];
|
$schemes = $connection['schemes'] ?? [];
|
||||||
$config = [];
|
$config = [];
|
||||||
$dsns = explode(',', $connection['dsns'] ?? '');
|
$dsns = explode(',', $connection['dsns'] ?? '');
|
||||||
foreach ($dsns as &$dsn) {
|
foreach ($dsns as &$dsn) {
|
||||||
$dsn = explode('=', $dsn);
|
$dsn = explode('=', $dsn);
|
||||||
$name = ($multipe) ? $key . '_' . $dsn[0] : $key;
|
$name = ($multiple) ? $key . '_' . $dsn[0] : $key;
|
||||||
$dsn = $dsn[1] ?? '';
|
$dsn = $dsn[1] ?? '';
|
||||||
$config[] = $name;
|
$config[] = $name;
|
||||||
if (empty($dsn)) {
|
if (empty($dsn)) {
|
||||||
|
@ -732,7 +732,7 @@ $register->set('pools', function () {
|
||||||
default => null
|
default => null
|
||||||
};
|
};
|
||||||
|
|
||||||
$adapter->setDefaultDatabase($dsn->getPath());
|
$adapter->setDatabase($dsn->getPath());
|
||||||
break;
|
break;
|
||||||
case 'pubsub':
|
case 'pubsub':
|
||||||
$adapter = $resource();
|
$adapter = $resource();
|
||||||
|
@ -1136,8 +1136,7 @@ App::setResource('dbForConsole', function (Group $pools, Cache $cache) {
|
||||||
$dbAdapter = $pools
|
$dbAdapter = $pools
|
||||||
->get('console')
|
->get('console')
|
||||||
->pop()
|
->pop()
|
||||||
->getResource()
|
->getResource();
|
||||||
;
|
|
||||||
|
|
||||||
$database = new Database($dbAdapter, $cache);
|
$database = new Database($dbAdapter, $cache);
|
||||||
|
|
||||||
|
@ -1247,21 +1246,14 @@ function getDevice($root): Device
|
||||||
Console::warning($e->getMessage() . 'Invalid DSN. Defaulting to Local device.');
|
Console::warning($e->getMessage() . 'Invalid DSN. Defaulting to Local device.');
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($device) {
|
return match ($device) {
|
||||||
case Storage::DEVICE_S3:
|
Storage::DEVICE_S3 => new S3($root, $accessKey, $accessSecret, $bucket, $region, $acl),
|
||||||
return new S3($root, $accessKey, $accessSecret, $bucket, $region, $acl);
|
STORAGE::DEVICE_DO_SPACES => new DOSpaces($root, $accessKey, $accessSecret, $bucket, $region, $acl),
|
||||||
case STORAGE::DEVICE_DO_SPACES:
|
Storage::DEVICE_BACKBLAZE => new Backblaze($root, $accessKey, $accessSecret, $bucket, $region, $acl),
|
||||||
return new DOSpaces($root, $accessKey, $accessSecret, $bucket, $region, $acl);
|
Storage::DEVICE_LINODE => new Linode($root, $accessKey, $accessSecret, $bucket, $region, $acl),
|
||||||
case Storage::DEVICE_BACKBLAZE:
|
Storage::DEVICE_WASABI => new Wasabi($root, $accessKey, $accessSecret, $bucket, $region, $acl),
|
||||||
return new Backblaze($root, $accessKey, $accessSecret, $bucket, $region, $acl);
|
default => new Local($root),
|
||||||
case Storage::DEVICE_LINODE:
|
};
|
||||||
return new Linode($root, $accessKey, $accessSecret, $bucket, $region, $acl);
|
|
||||||
case Storage::DEVICE_WASABI:
|
|
||||||
return new Wasabi($root, $accessKey, $accessSecret, $bucket, $region, $acl);
|
|
||||||
case Storage::DEVICE_LOCAL:
|
|
||||||
default:
|
|
||||||
return new Local($root);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
switch (strtolower(App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL) ?? '')) {
|
switch (strtolower(App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL) ?? '')) {
|
||||||
case Storage::DEVICE_LOCAL:
|
case Storage::DEVICE_LOCAL:
|
||||||
|
|
4
appwrite.json
Normal file
4
appwrite.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"projectId": "console",
|
||||||
|
"projectName": ""
|
||||||
|
}
|
|
@ -388,7 +388,7 @@ abstract class Migration
|
||||||
*/
|
*/
|
||||||
protected function changeAttributeInternalType(string $collection, string $attribute, string $type): void
|
protected function changeAttributeInternalType(string $collection, string $attribute, string $type): void
|
||||||
{
|
{
|
||||||
$stmt = $this->pdo->prepare("ALTER TABLE `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$collection}` MODIFY `$attribute` $type;");
|
$stmt = $this->pdo->prepare("ALTER TABLE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$collection}` MODIFY `$attribute` $type;");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|
|
@ -295,7 +295,7 @@ class V15 extends Migration
|
||||||
protected function removeWritePermissions(string $table): void
|
protected function removeWritePermissions(string $table): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->pdo->prepare("DELETE FROM `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _type = 'write'")->execute();
|
$this->pdo->prepare("DELETE FROM `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _type = 'write'")->execute();
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
Console::warning("Remove 'write' permissions from {$table}: {$th->getMessage()}");
|
Console::warning("Remove 'write' permissions from {$table}: {$th->getMessage()}");
|
||||||
}
|
}
|
||||||
|
@ -311,7 +311,7 @@ class V15 extends Migration
|
||||||
*/
|
*/
|
||||||
protected function getSQLColumnTypes(string $table): array
|
protected function getSQLColumnTypes(string $table): array
|
||||||
{
|
{
|
||||||
$query = $this->pdo->prepare("SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '_{$this->project->getInternalId()}_{$table}' AND table_schema = '{$this->projectDB->getDefaultDatabase()}'");
|
$query = $this->pdo->prepare("SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '_{$this->project->getInternalId()}_{$table}' AND table_schema = '{$this->projectDB->getDatabase()}'");
|
||||||
$query->execute();
|
$query->execute();
|
||||||
|
|
||||||
return array_reduce($query->fetchAll(), function (array $carry, array $item) {
|
return array_reduce($query->fetchAll(), function (array $carry, array $item) {
|
||||||
|
@ -333,8 +333,8 @@ class V15 extends Migration
|
||||||
|
|
||||||
if ($columns[$attribute] === 'int') {
|
if ($columns[$attribute] === 'int') {
|
||||||
try {
|
try {
|
||||||
$this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} VARCHAR(64)")->execute();
|
$this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} VARCHAR(64)")->execute();
|
||||||
$this->pdo->prepare("UPDATE `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$table}` SET {$attribute} = IF({$attribute} = 0, NULL, FROM_UNIXTIME({$attribute}))")->execute();
|
$this->pdo->prepare("UPDATE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` SET {$attribute} = IF({$attribute} = 0, NULL, FROM_UNIXTIME({$attribute}))")->execute();
|
||||||
$columns[$attribute] = 'varchar';
|
$columns[$attribute] = 'varchar';
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
Console::warning($th->getMessage());
|
Console::warning($th->getMessage());
|
||||||
|
@ -343,7 +343,7 @@ class V15 extends Migration
|
||||||
|
|
||||||
if ($columns[$attribute] === 'varchar') {
|
if ($columns[$attribute] === 'varchar') {
|
||||||
try {
|
try {
|
||||||
$this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} DATETIME(3)")->execute();
|
$this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} DATETIME(3)")->execute();
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
Console::warning($th->getMessage());
|
Console::warning($th->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -389,7 +389,7 @@ class V15 extends Migration
|
||||||
|
|
||||||
if (!array_key_exists('_permissions', $columns)) {
|
if (!array_key_exists('_permissions', $columns)) {
|
||||||
try {
|
try {
|
||||||
$this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$table}` ADD `_permissions` MEDIUMTEXT DEFAULT NULL")->execute();
|
$this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` ADD `_permissions` MEDIUMTEXT DEFAULT NULL")->execute();
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
Console::warning("Add '_permissions' column to '{$table}': {$th->getMessage()}");
|
Console::warning("Add '_permissions' column to '{$table}': {$th->getMessage()}");
|
||||||
}
|
}
|
||||||
|
@ -410,7 +410,7 @@ class V15 extends Migration
|
||||||
{
|
{
|
||||||
$table ??= $document->getCollection();
|
$table ??= $document->getCollection();
|
||||||
|
|
||||||
$query = $this->pdo->prepare("SELECT * FROM `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _document = '{$document->getId()}'");
|
$query = $this->pdo->prepare("SELECT * FROM `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _document = '{$document->getId()}'");
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$results = $query->fetchAll();
|
$results = $query->fetchAll();
|
||||||
$permissions = [];
|
$permissions = [];
|
||||||
|
@ -1472,9 +1472,9 @@ class V15 extends Migration
|
||||||
$from = $this->pdo->quote($from);
|
$from = $this->pdo->quote($from);
|
||||||
$to = $this->pdo->quote($to);
|
$to = $this->pdo->quote($to);
|
||||||
|
|
||||||
$this->pdo->prepare("UPDATE `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_stats` SET metric = {$to} WHERE metric = {$from}")->execute();
|
$this->pdo->prepare("UPDATE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_stats` SET metric = {$to} WHERE metric = {$from}")->execute();
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
Console::warning("Migrating steps from {$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}_stats:" . $th->getMessage());
|
Console::warning("Migrating steps from {$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_stats:" . $th->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,7 +244,7 @@ class V18 extends Migration
|
||||||
/**
|
/**
|
||||||
* Create 'documentSecurity' column
|
* Create 'documentSecurity' column
|
||||||
*/
|
*/
|
||||||
$this->pdo->prepare("ALTER TABLE `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}__metadata` ADD COLUMN IF NOT EXISTS documentSecurity TINYINT(1);")->execute();
|
$this->pdo->prepare("ALTER TABLE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}__metadata` ADD COLUMN IF NOT EXISTS documentSecurity TINYINT(1);")->execute();
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
Console::warning($th->getMessage());
|
Console::warning($th->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ class V18 extends Migration
|
||||||
/**
|
/**
|
||||||
* Set 'documentSecurity' column to 1 if NULL
|
* Set 'documentSecurity' column to 1 if NULL
|
||||||
*/
|
*/
|
||||||
$this->pdo->prepare("UPDATE `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}__metadata` SET documentSecurity = 1 WHERE documentSecurity IS NULL")->execute();
|
$this->pdo->prepare("UPDATE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}__metadata` SET documentSecurity = 1 WHERE documentSecurity IS NULL")->execute();
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
Console::warning($th->getMessage());
|
Console::warning($th->getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ class V19 extends Migration
|
||||||
|
|
||||||
protected function migrateDomains(): void
|
protected function migrateDomains(): void
|
||||||
{
|
{
|
||||||
if ($this->consoleDB->exists($this->consoleDB->getDefaultDatabase(), 'domains')) {
|
if ($this->consoleDB->exists($this->consoleDB->getDatabase(), 'domains')) {
|
||||||
foreach ($this->documentsIterator('domains') as $domain) {
|
foreach ($this->documentsIterator('domains') as $domain) {
|
||||||
$status = 'created';
|
$status = 'created';
|
||||||
if ($domain->getAttribute('verification', false)) {
|
if ($domain->getAttribute('verification', false)) {
|
||||||
|
|
|
@ -122,7 +122,7 @@ class CalcTierStats extends Action
|
||||||
->getResource();
|
->getResource();
|
||||||
|
|
||||||
$dbForProject = new Database($adapter, $cache);
|
$dbForProject = new Database($adapter, $cache);
|
||||||
$dbForProject->setDefaultDatabase('appwrite');
|
$dbForProject->setDatabase('appwrite');
|
||||||
$dbForProject->setNamespace('_' . $project->getInternalId());
|
$dbForProject->setNamespace('_' . $project->getInternalId());
|
||||||
|
|
||||||
/** Get Project ID */
|
/** Get Project ID */
|
||||||
|
|
|
@ -90,12 +90,12 @@ class DeleteOrphanedProjects extends Action
|
||||||
->getResource();
|
->getResource();
|
||||||
|
|
||||||
$dbForProject = new Database($adapter, $cache);
|
$dbForProject = new Database($adapter, $cache);
|
||||||
$dbForProject->setDefaultDatabase('appwrite');
|
$dbForProject->setDatabase('appwrite');
|
||||||
$dbForProject->setNamespace('_' . $project->getInternalId());
|
$dbForProject->setNamespace('_' . $project->getInternalId());
|
||||||
|
|
||||||
$collectionsCreated = 0;
|
$collectionsCreated = 0;
|
||||||
$cnt++;
|
$cnt++;
|
||||||
if ($dbForProject->exists($dbForProject->getDefaultDatabase(), Database::METADATA)) {
|
if ($dbForProject->exists($dbForProject->getDatabase(), Database::METADATA)) {
|
||||||
$collectionsCreated = $dbForProject->count(Database::METADATA);
|
$collectionsCreated = $dbForProject->count(Database::METADATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class DeleteOrphanedProjects extends Action
|
||||||
$dbForConsole->deleteDocument('projects', $project->getId());
|
$dbForConsole->deleteDocument('projects', $project->getId());
|
||||||
$dbForConsole->deleteCachedDocument('projects', $project->getId());
|
$dbForConsole->deleteCachedDocument('projects', $project->getId());
|
||||||
|
|
||||||
if ($dbForProject->exists($dbForProject->getDefaultDatabase(), Database::METADATA)) {
|
if ($dbForProject->exists($dbForProject->getDatabase(), Database::METADATA)) {
|
||||||
try {
|
try {
|
||||||
$dbForProject->deleteCollection(Database::METADATA);
|
$dbForProject->deleteCollection(Database::METADATA);
|
||||||
$dbForProject->deleteCachedCollection(Database::METADATA);
|
$dbForProject->deleteCachedCollection(Database::METADATA);
|
||||||
|
|
|
@ -81,7 +81,7 @@ class Hamster extends Action
|
||||||
->getResource();
|
->getResource();
|
||||||
|
|
||||||
$dbForProject = new Database($adapter, $cache);
|
$dbForProject = new Database($adapter, $cache);
|
||||||
$dbForProject->setDefaultDatabase('appwrite');
|
$dbForProject->setDatabase('appwrite');
|
||||||
$dbForProject->setNamespace('_' . $project->getInternalId());
|
$dbForProject->setNamespace('_' . $project->getInternalId());
|
||||||
|
|
||||||
$statsPerProject = [];
|
$statsPerProject = [];
|
||||||
|
|
Loading…
Reference in a new issue