Closed maxachis closed 1 week ago
quick search
is more or less deprecated in v2, but there may be other examples that would benefit. I'm all in favor of using views
to normalize how we grab information from the database, and keep it DRY; however, this is partially how I conceive of the database client
—isn't it partially to prevent repeating ourselves on the back end? Is this just a different thing?
@josh-chamberlain A valid point! And to some degree I concede it's a matter of preference, and we can certainly consolidate some of the backend logic without resorting to views. That being said, I think there are a few things which favor views:
Granted, the flip-side of this is that queries are somewhat less visible -- you'll need to be able to view them in the database rather than in a repo, and version control suffers as a result. So that's worth taking into account as well.
Gotcha, thanks @maxachis
Just to help keep my mental model accurate, I made an ADR here talking about the differences. Someday, we may want a little doc somewhere for explaining which views we're using + for what.
I'm gonna go ahead and marked this one closed, as while there are 1-2 queries which could be viewified, by and large, complex logic is increasingly present in the database!
@maxachis does this imply that SQLAlchemy obviates the need for views, or something else?
@josh-chamberlain This means that we have, over the course of making various refactors and in some cases SQLAlchemy changes, added various database views to the logic, so we've already resolved this in the background! Not everything is viewified, but by and large complex logic is moved to views.
Context
Some complex queries (looking at you, Quick Search logic) include a wide number of joins and other complex logic, which are sometimes repeated multiple times in the backend code. For example:
It may be useful to migrate some of this code to the database, and then have simpler queries in the app that simply query the relevant view.
Requirements
Tests
Docs
Open questions