update: events schema, response models for database usages.

This commit is contained in:
Darshan
2025-05-07 13:23:27 +05:30
parent 28a74e664d
commit 8610687b87
10 changed files with 131 additions and 42 deletions
+1 -1
View File
@@ -114,7 +114,7 @@ return [
],
],
'indexes' => [
'$model' => Response::MODEL_INDEX,
'$model' => Response::MODEL_COLUMN_INDEX,
'$resource' => true,
'$description' => 'This event triggers on any indexes event.',
'create' => [
@@ -123,13 +123,13 @@ class Get extends Action
$response->dynamic(new Document([
'range' => $range,
'tablesTotal' => $usage[$metrics[0]]['total'],
'rowsTotal' => $usage[$metrics[1]]['total'],
'collectionsTotal' => $usage[$metrics[0]]['total'],
'documentsTotal' => $usage[$metrics[1]]['total'],
'storageTotal' => $usage[$metrics[2]]['total'],
'databaseReadsTotal' => $usage[$metrics[3]]['total'],
'databaseWritesTotal' => $usage[$metrics[4]]['total'],
'tables' => $usage[$metrics[0]]['data'],
'rows' => $usage[$metrics[1]]['data'],
'collections' => $usage[$metrics[0]]['data'],
'documents' => $usage[$metrics[1]]['data'],
'storage' => $usage[$metrics[2]]['data'],
'databaseReads' => $usage[$metrics[3]]['data'],
'databaseWrites' => $usage[$metrics[4]]['data'],
@@ -116,14 +116,14 @@ class XList extends Action
$response->dynamic(new Document([
'range' => $range,
'databasesTotal' => $usage[$metrics[0]]['total'],
'tablesTotal' => $usage[$metrics[1]]['total'],
'rowsTotal' => $usage[$metrics[2]]['total'],
'collectionsTotal' => $usage[$metrics[1]]['total'],
'documentsTotal' => $usage[$metrics[2]]['total'],
'storageTotal' => $usage[$metrics[3]]['total'],
'databasesReadsTotal' => $usage[$metrics[4]]['total'],
'databasesWritesTotal' => $usage[$metrics[5]]['total'],
'databases' => $usage[$metrics[0]]['data'],
'tables' => $usage[$metrics[1]]['data'],
'rows' => $usage[$metrics[2]]['data'],
'collections' => $usage[$metrics[1]]['data'],
'documents' => $usage[$metrics[2]]['data'],
'storage' => $usage[$metrics[3]]['data'],
'databasesReads' => $usage[$metrics[4]]['data'],
'databasesWrites' => $usage[$metrics[5]]['data'],
+5
View File
@@ -38,6 +38,7 @@ use Appwrite\Utopia\Response\Model\ColumnDatetime;
use Appwrite\Utopia\Response\Model\ColumnEmail;
use Appwrite\Utopia\Response\Model\ColumnEnum;
use Appwrite\Utopia\Response\Model\ColumnFloat;
use Appwrite\Utopia\Response\Model\ColumnIndex;
use Appwrite\Utopia\Response\Model\ColumnInteger;
use Appwrite\Utopia\Response\Model\ColumnIP;
use Appwrite\Utopia\Response\Model\ColumnList;
@@ -182,6 +183,8 @@ class Response extends SwooleResponse
public const MODEL_TABLE_LIST = 'tableList';
public const MODEL_INDEX = 'index';
public const MODEL_INDEX_LIST = 'indexList';
public const MODEL_COLUMN_INDEX = 'columnIndex';
public const MODEL_COLUMN_INDEX_LIST = 'columnIndexList';
public const MODEL_DOCUMENT = 'document';
public const MODEL_DOCUMENT_LIST = 'documentList';
public const MODEL_ROW = 'row';
@@ -416,6 +419,7 @@ class Response extends SwooleResponse
->setModel(new BaseList('Collections List', self::MODEL_COLLECTION_LIST, 'collections', self::MODEL_COLLECTION))
->setModel(new BaseList('Databases List', self::MODEL_DATABASE_LIST, 'databases', self::MODEL_DATABASE))
->setModel(new BaseList('Indexes List', self::MODEL_INDEX_LIST, 'indexes', self::MODEL_INDEX))
->setModel(new BaseList('Column Indexes List', self::MODEL_COLUMN_INDEX_LIST, 'indexes', self::MODEL_COLUMN_INDEX))
->setModel(new BaseList('Users List', self::MODEL_USER_LIST, 'users', self::MODEL_USER))
->setModel(new BaseList('Sessions List', self::MODEL_SESSION_LIST, 'sessions', self::MODEL_SESSION))
->setModel(new BaseList('Identities List', self::MODEL_IDENTITY_LIST, 'identities', self::MODEL_IDENTITY))
@@ -493,6 +497,7 @@ class Response extends SwooleResponse
->setModel(new ColumnDatetime())
->setModel(new ColumnRelationship())
->setModel(new Index())
->setModel(new ColumnIndex())
->setModel(new Row())
->setModel(new ModelDocument())
->setModel(new Log())
@@ -0,0 +1,94 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
use Utopia\Database\Document;
class ColumnIndex extends Model
{
public function __construct()
{
$this
->addRule('key', [
'type' => self::TYPE_STRING,
'description' => 'Index Key.',
'default' => '',
'example' => 'index1',
])
->addRule('type', [
'type' => self::TYPE_STRING,
'description' => 'Index type.',
'default' => '',
'example' => 'primary',
])
->addRule('status', [
'type' => self::TYPE_STRING,
'description' => 'Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed`',
'default' => '',
'example' => 'available',
])
->addRule('error', [
'type' => self::TYPE_STRING,
'description' => 'Error message. Displays error generated on failure of creating or deleting an index.',
'default' => '',
'example' => 'string',
])
->addRule('columns', [
'type' => self::TYPE_STRING,
'description' => 'Index columns.',
'default' => [],
'example' => [],
'array' => true,
])
->addRule('orders', [
'type' => self::TYPE_STRING,
'description' => 'Index orders.',
'default' => [],
'example' => [],
'array' => true,
'required' => false,
])
->addRule('$createdAt', [
'type' => self::TYPE_DATETIME,
'description' => 'Index creation date in ISO 8601 format.',
'default' => '',
'example' => self::TYPE_DATETIME_EXAMPLE,
])
->addRule('$updatedAt', [
'type' => self::TYPE_DATETIME,
'description' => 'Index update date in ISO 8601 format.',
'default' => '',
'example' => self::TYPE_DATETIME_EXAMPLE,
]);
}
/**
* Get Name
*/
public function getName(): string
{
return 'Index';
}
/**
* Get Collection
*/
public function getType(): string
{
return Response::MODEL_COLUMN_INDEX;
}
public function filter(Document $document): Document
{
$columns = $document->getAttribute('attributes', []);
$document
->removeAttribute('attributes')
->setAttribute('columns', $columns);
return $document;
}
}
+1 -14
View File
@@ -4,7 +4,6 @@ namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
use Utopia\Database\Document;
class Index extends Model
{
@@ -35,7 +34,7 @@ class Index extends Model
'default' => '',
'example' => 'string',
])
->addRule('columns', [
->addRule('attributes', [
'type' => self::TYPE_STRING,
'description' => 'Index attributes.',
'default' => [],
@@ -79,16 +78,4 @@ class Index extends Model
{
return Response::MODEL_INDEX;
}
public function filter(Document $document): Document
{
$columns = $document->getAttribute('attributes', []);
$document
->removeAttribute('attributes')
->setAttribute('columns', $columns);
return $document;
}
}
+1 -1
View File
@@ -79,7 +79,7 @@ class Table extends Model
'array' => true,
])
->addRule('indexes', [
'type' => Response::MODEL_INDEX,
'type' => Response::MODEL_COLUMN_INDEX,
'description' => 'Table indexes.',
'default' => [],
'example' => new \stdClass(),
@@ -5,6 +5,7 @@ namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
// TODO: check what do we use for - collectionsTotal, documentsTotal, collections, documents
class UsageDatabase extends Model
{
public function __construct()
@@ -16,15 +17,15 @@ class UsageDatabase extends Model
'default' => '',
'example' => '30d',
])
->addRule('tablesTotal', [
->addRule('collectionsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of tables.',
'description' => 'Total aggregated number of collections.',
'default' => 0,
'example' => 0,
])
->addRule('rowsTotal', [
->addRule('collectionsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of rows.',
'description' => 'Total aggregated number of documents.',
'default' => 0,
'example' => 0,
])
@@ -46,16 +47,16 @@ class UsageDatabase extends Model
'default' => 0,
'example' => 0,
])
->addRule('tables', [
->addRule('collections', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated number of tables per period.',
'description' => 'Aggregated number of collections per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('rows', [
->addRule('documents', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated number of rows per period.',
'description' => 'Aggregated number of documents per period.',
'default' => [],
'example' => [],
'array' => true
@@ -5,6 +5,7 @@ namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
// TODO: check what do we use for - collectionsTotal, documentsTotal, collections, documents
class UsageDatabases extends Model
{
public function __construct()
@@ -22,15 +23,15 @@ class UsageDatabases extends Model
'default' => 0,
'example' => 0,
])
->addRule('tablesTotal', [
->addRule('collectionsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of tables.',
'description' => 'Total aggregated number of collections.',
'default' => 0,
'example' => 0,
])
->addRule('rowsTotal', [
->addRule('documentsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of rows.',
'description' => 'Total aggregated number of documents.',
'default' => 0,
'example' => 0,
])
@@ -59,16 +60,16 @@ class UsageDatabases extends Model
'example' => [],
'array' => true
])
->addRule('tables', [
->addRule('collections', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated number of tables per period.',
'description' => 'Aggregated number of collections per period.',
'default' => [],
'example' => [],
'array' => true
])
->addRule('rows', [
->addRule('documents', [
'type' => Response::MODEL_METRIC,
'description' => 'Aggregated number of rows per period.',
'description' => 'Aggregated number of documents per period.',
'default' => [],
'example' => [],
'array' => true
@@ -5,6 +5,7 @@ namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
// TODO: check what do we use for - documents.
class UsageProject extends Model
{
public function __construct()
@@ -16,9 +17,9 @@ class UsageProject extends Model
'default' => 0,
'example' => 0,
])
->addRule('rowsTotal', [
->addRule('documentsTotal', [
'type' => self::TYPE_INTEGER,
'description' => 'Total aggregated number of rows.',
'description' => 'Total aggregated number of documents.',
'default' => 0,
'example' => 0,
])