1
0
Fork 0
mirror of synced 2024-08-27 16:11:28 +12:00

Merge pull request #5709 from appwrite/refactor-collections-config-db-pools

refactor collections config
This commit is contained in:
Christy Jacob 2023-06-15 20:41:29 +05:30 committed by GitHub
commit b0a70d22ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 1693 additions and 1670 deletions

View file

@ -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

View file

@ -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.');
} }

View file

@ -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) {

View file

@ -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.');
} }

View file

@ -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.');
} }

View file

@ -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) {

View file

@ -15,7 +15,8 @@ class CollectionsTest extends TestCase
public function testDuplicateRules(): void public function testDuplicateRules(): void
{ {
foreach ($this->collections as $key => $collection) { foreach ($this->collections as $key => $sections) {
foreach ($sections as $key => $collection) {
if (array_key_exists('attributes', $collection)) { if (array_key_exists('attributes', $collection)) {
foreach ($collection['attributes'] as $check) { foreach ($collection['attributes'] as $check) {
$occurrences = 0; $occurrences = 0;
@ -30,3 +31,4 @@ class CollectionsTest extends TestCase
} }
} }
} }
}