Merge pull request #5709 from appwrite/refactor-collections-config-db-pools
refactor collections config
This commit is contained in:
commit
b0a70d22ab
8 changed files with 1693 additions and 1670 deletions
|
@ -61,7 +61,7 @@ CLI::setResource('dbForConsole', function ($pools, $cache) {
|
||||||
$dbForConsole->setNamespace('console');
|
$dbForConsole->setNamespace('console');
|
||||||
|
|
||||||
// Ensure tables exist
|
// Ensure tables exist
|
||||||
$collections = Config::getParam('collections', []);
|
$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->getDefaultDatabase(), $last))) { /** TODO cache ready variable using registry */
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -179,7 +179,7 @@ App::post('/v1/databases')
|
||||||
]));
|
]));
|
||||||
$database = $dbForProject->getDocument('databases', $databaseId);
|
$database = $dbForProject->getDocument('databases', $databaseId);
|
||||||
|
|
||||||
$collections = Config::getParam('collections', [])['collections'] ?? [];
|
$collections = (Config::getParam('collections', [])['databases'] ?? [])['collections'] ?? [];
|
||||||
if (empty($collections)) {
|
if (empty($collections)) {
|
||||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'The "collections" collection is not configured.');
|
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'The "collections" collection is not configured.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,7 @@ App::post('/v1/projects')
|
||||||
$adapter->setup();
|
$adapter->setup();
|
||||||
|
|
||||||
/** @var array $collections */
|
/** @var array $collections */
|
||||||
$collections = Config::getParam('collections', []);
|
$collections = Config::getParam('collections', [])['projects'] ?? [];
|
||||||
|
|
||||||
foreach ($collections as $key => $collection) {
|
foreach ($collections as $key => $collection) {
|
||||||
if (($collection['$collection'] ?? '') !== Database::METADATA) {
|
if (($collection['$collection'] ?? '') !== Database::METADATA) {
|
||||||
|
|
|
@ -80,7 +80,7 @@ App::post('/v1/storage/buckets')
|
||||||
$permissions = Permission::aggregate($permissions);
|
$permissions = Permission::aggregate($permissions);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$files = Config::getParam('collections', [])['files'] ?? [];
|
$files = (Config::getParam('collections', [])['buckets'] ?? [])['files'] ?? [];
|
||||||
if (empty($files)) {
|
if (empty($files)) {
|
||||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Files collection is not configured.');
|
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Files collection is not configured.');
|
||||||
}
|
}
|
||||||
|
|
10
app/http.php
10
app/http.php
|
@ -84,9 +84,6 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) {
|
||||||
|
|
||||||
Console::success('[Setup] - Server database init started...');
|
Console::success('[Setup] - Server database init started...');
|
||||||
|
|
||||||
/** @var array $collections */
|
|
||||||
$collections = Config::getParam('collections', []);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$cache = $app->getResource('cache'); /** @var Utopia\Cache\Cache $cache */
|
$cache = $app->getResource('cache'); /** @var Utopia\Cache\Cache $cache */
|
||||||
Console::success('[Setup] - Creating database: appwrite...');
|
Console::success('[Setup] - Creating database: appwrite...');
|
||||||
|
@ -105,7 +102,10 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) {
|
||||||
$adapter->setup();
|
$adapter->setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($collections as $key => $collection) {
|
/** @var array $collections */
|
||||||
|
$collections = Config::getParam('collections', []);
|
||||||
|
$consoleCollections = $collections['console'];
|
||||||
|
foreach ($consoleCollections as $key => $collection) {
|
||||||
if (($collection['$collection'] ?? '') !== Database::METADATA) {
|
if (($collection['$collection'] ?? '') !== Database::METADATA) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) {
|
||||||
$bucket = $dbForConsole->getDocument('buckets', 'default');
|
$bucket = $dbForConsole->getDocument('buckets', 'default');
|
||||||
|
|
||||||
Console::success('[Setup] - Creating files collection for default bucket...');
|
Console::success('[Setup] - Creating files collection for default bucket...');
|
||||||
$files = $collections['files'] ?? [];
|
$files = $collections['buckets']['files'] ?? [];
|
||||||
if (empty($files)) {
|
if (empty($files)) {
|
||||||
throw new Exception('Files collection is not configured.');
|
throw new Exception('Files collection is not configured.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,9 @@ class Base extends Queries
|
||||||
*/
|
*/
|
||||||
public function __construct(string $collection, array $allowedAttributes)
|
public function __construct(string $collection, array $allowedAttributes)
|
||||||
{
|
{
|
||||||
$collection = Config::getParam('collections', [])[$collection];
|
$config = Config::getParam('collections', []);
|
||||||
|
$collections = array_merge($config['console'], $config['projects'], $config['buckets'], $config['databases']);
|
||||||
|
$collection = $collections[$collection];
|
||||||
// array for constant lookup time
|
// array for constant lookup time
|
||||||
$allowedAttributesLookup = [];
|
$allowedAttributesLookup = [];
|
||||||
foreach ($allowedAttributes as $attribute) {
|
foreach ($allowedAttributes as $attribute) {
|
||||||
|
|
|
@ -15,16 +15,18 @@ class CollectionsTest extends TestCase
|
||||||
|
|
||||||
public function testDuplicateRules(): void
|
public function testDuplicateRules(): void
|
||||||
{
|
{
|
||||||
foreach ($this->collections as $key => $collection) {
|
foreach ($this->collections as $key => $sections) {
|
||||||
if (array_key_exists('attributes', $collection)) {
|
foreach ($sections as $key => $collection) {
|
||||||
foreach ($collection['attributes'] as $check) {
|
if (array_key_exists('attributes', $collection)) {
|
||||||
$occurrences = 0;
|
foreach ($collection['attributes'] as $check) {
|
||||||
foreach ($collection['attributes'] as $attribute) {
|
$occurrences = 0;
|
||||||
if ($attribute['$id'] == $check['$id']) {
|
foreach ($collection['attributes'] as $attribute) {
|
||||||
$occurrences++;
|
if ($attribute['$id'] == $check['$id']) {
|
||||||
|
$occurrences++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$this->assertEquals(1, $occurrences);
|
||||||
}
|
}
|
||||||
$this->assertEquals(1, $occurrences);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue