Skip to content

Feat - Appwrite Database using Utopia\Database - #1266

Merged
eldadfux merged 99 commits into
feat-database-indexingfrom
feat-db-refactor-routes
Jul 16, 2021
Merged

eldadfux merged 99 commits into
feat-database-indexingfrom
feat-db-refactor-routes

Conversation

@kodumbeats

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR leverages the new Utopia\Database library for the Appwrite Database service.

Test Plan

Unit tests in utopia-php/database and e2e tests here

Related PRs and Issues

N/A

Have you read the Contributing Guidelines on issues?

Yes.

Comment thread app/controllers/api/database.php Outdated
Comment thread app/controllers/api/database.php Outdated
Comment thread app/controllers/api/database.php Outdated
Comment thread app/controllers/api/database.php Outdated
Comment thread app/controllers/api/database.php Outdated
Comment thread src/Appwrite/Utopia/Response/Model/Attribute.php
Comment thread src/Appwrite/Utopia/Response/Model/Attribute.php Outdated
Comment thread src/Appwrite/Utopia/Response/Model/Index.php Outdated
Comment thread src/Appwrite/Utopia/Response/Model/Index.php Outdated
Comment thread src/Appwrite/Utopia/Response/Model/Index.php
Comment thread src/Appwrite/Utopia/Response/Model/Attribute.php Outdated
Comment thread app/controllers/api/database.php
Comment thread app/controllers/api/database.php Outdated
Comment thread src/Appwrite/Utopia/Response/Model/Collection.php Outdated
Comment thread app/workers/database.php

$dbForExternal = null;

go(function() use ($register, $projectId, &$dbForExternal) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TorstenDittmann @kodumbeats are we sure this update has no side effects? Would it be safer to apply the go() function only on the db setup process instead of on any new connection?

@kodumbeats

kodumbeats commented Jul 12, 2021 •

Copy link
Copy Markdown
Contributor Author

edit: imported incorrect authorization validator - now fixed 👍🏻

Having some trouble with the decrementing team count when deleting a user and their membership. Tests fail because of failing the authorization check in deleteDocument, despite my setting Authorization::disable() in the worker:

1) Tests\E2E\Services\Teams\TeamsCustomServerTest::testDeleteUserUpdatesTeamMembershipCount
Failed asserting that 1 matches expected 0.
stacktrace
appwrite-worker-deletes         | Deleting chunk #1. Found 1 documents
appwrite-worker-deletes         | [critical] (Job{v1-deletes} | ID: b926c62c45289333ca66c3bcb7c71fad | DeletesV1 | [{"projectId":"60ecbb227e651","type":"document","document":{"$id":"60ecbb2588b9d","$read":["user:60ecbb2588b9d","role:all"],"$write":["user:60ecbb2588b9d"],"email":"[email protected]","emailVerification":false,"status":0,"password":"$2y$08$pOqqbbYadpbk4M3O03ZY9e.Z5.RVfOZb5otBeMwB3bsEI1G1xY8Ni","passwordUpdate":0,"registration":1626127141,"reset":false,"name":"Friend User","prefs":[],"sessions":[],"tokens":[],"memberships":[{"$id":"60ecbb258c770","$read":["role:all"],"$write":["user:60ecbb2588b9d","team:60ecbb249d495\/owner"],"userId":"60ecbb2588b9d","teamId":"60ecbb249d495","roles":["admin","editor"],"invited":1626127141,"joined":1626127141,"confirm":true,"secret":"40ef00d5ebe003b880be5707155f75596dde2a3f4f61eb88f1a55c8c9bb2b4fc","$collection":"memberships"}],"$collection":"users"}}]) 
                                 has failed Utopia\Database\Exception\Authorization: Missing "write" permission for role "team:60ecbb249d495/owner". Only this scopes "["role:all"]" are given and only this are allowed "["user:60ecbb2588b9d","team:60ecbb249d495\/owner"]". in /usr/src/code/vendor/utopia-php/database/src/Database/Database.php:829
appwrite-worker-deletes         | Stack trace:
appwrite-worker-deletes         | #0 /usr/src/code/app/workers/deletes.php(271): Utopia\Database\Database->deleteDocument('memberships', '60ecbb258c770')
appwrite-worker-deletes         | #1 /usr/src/code/app/workers/deletes.php(399): DeletesV1->deleteById2(Object(Utopia\Database\Document), Object(Utopia\Database\Database), Object(Closure))
appwrite-worker-deletes         | #2 /usr/src/code/app/workers/deletes.php(168): DeletesV1->deleteByGroup2('memberships', Array, Object(Utopia\Database\Database), Object(Closure))
appwrite-worker-deletes         | #3 /usr/src/code/app/workers/deletes.php(55): DeletesV1->deleteUser2(Object(Appwrite\Database\Document), '60ecbb227e651')
appwrite-worker-deletes         | #4 /usr/src/code/src/Appwrite/Resque/Worker.php(22): DeletesV1->run()
appwrite-worker-deletes         | #5 /usr/src/code/vendor/resque/php-resque/lib/Resque/Job.php(201): Appwrite\Resque\Worker->perform()
appwrite-worker-deletes         | #6 /usr/src/code/vendor/resque/php-resque/lib/Resque/Worker.php(303): Resque_Job->perform()
appwrite-worker-deletes         | #7 /usr/src/code/vendor/resque/php-resque/lib/Resque/Worker.php(242): Resque_Worker->perform(Object(Resque_Job))
appwrite-worker-deletes         | #8 /usr/src/code/vendor/resque/php-resque/bin/resque(185): Resque_Worker->work('1', false)
appwrite-worker-deletes         | #9 {main}

Comment thread app/controllers/api/projects.php Outdated

$task = new Document([
'$id' => $dbForConsole->getId(),
'$projectId' => $project->getId(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this new attribute, and why does it have $ prefix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove the $ prefix (used the $collection attribute from the Document model as inspiration):
https://github.com/appwrite/appwrite/blob/feat-db-refactor-routes/src/Appwrite/Utopia/Response/Model/Document.php#L38-L43

However, we do need to pass the projectID to the tasks worker because tasks are stored at the project level:
https://github.com/appwrite/appwrite/blob/feat-db-refactor-routes/app/workers/tasks.php#L70

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ removed in c04e2ba

'default' => '',
'example' => '5e5ea5c16897e',
])
->addRule('$projectId', [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, not sure why we need this key.

@kodumbeats
kodumbeats marked this pull request as ready for review July 16, 2021 14:38
@eldadfux
eldadfux merged commit 19e9a13 into feat-database-indexing Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants