use relationships everywhere

in order to use sqlalchemy's expire_on_commit=False optimization,
we need to make sure that objects are kept up to date.

This means we cannot rely on ForeignKey ondelete/onupdate behavior,
we must use sqlalchemy's local relationship cascades

The main key here is that we must use relationships to set foreign-key relations,
e.g. APIToken.user = user instead of APIToken.user_id = user.id.

It also means that we cannot use passive_deletes,
which allows sqlalchemy to defer to the database's more efficient ON DELETE behavior.

This makes deletions more expensive in particular,
but should improve db performance overall.
This commit is contained in:
Min RK
2018-04-17 10:54:14 +02:00
parent 15e4b1ad8b
commit b1840e8be7
4 changed files with 152 additions and 27 deletions

View File

@@ -280,7 +280,7 @@ def test_get_self(app):
db.commit()
oauth_token = orm.OAuthAccessToken(
user=u.orm_user,
client_id=oauth_client.identifier,
client=oauth_client,
token=token,
grant_type=orm.GrantType.authorization_code,
)