At least in PostgreSQL, at most one reference is allowed. My undirected
recursion code used a UNION of two recursive steps, one for each
direction. That is invalid, so instead I define a CTE that's a union of
the edges and their reverse, and do a single recursion step on that CTE
instead of on the edge table itself.
I thought SQL arrays were common and PersistList corresponded to SQL
array values. But that isn't the case. PersistList seems to be
serialized as a JSON list, and `filterClause` uses IN, not ANY. So I'm
doing the same thing here and using IN.
Note that I'm building the list myself using Text concatenation, not
using `filterClause`, because the latter takes a filter on an existing
`PersistEntity` while my filters often apply to temporary tables.
The transitive reduction query works by removing all the edges which
aren't the only paths between their nodes, i.e. longer paths exist. The
first step is to pick all the paths which include 2 or more edges.
The initial code did that appending in-edges to all paths, which results
with unnecessary duplicates and an INNER JOIN. Now, instead, just pick
all the paths with length of more than 3 nodes. This is hopefully not
just simpler, but also faster.
I used this chance to make some name changes, add some utils, tweak some
imports, remove more `setTitle`s and so on. I also made person, repo,
key and project creation forms verify CI-uniqueness.
I decided to add some safety to routes:
- Use dedicated newtypes
- Use CI for the CI-unique DB fields
Since such a change requires so many changes in many source files, this
is also a chance to do other such breaking changes. I'm recording the
change gradually. It won't build until I finish, so for now don't waste
time trying to build the app.