Disclaimer
I’m not overly familiar with databases, so please take my thoughts with a pinch of salt. Hopefully, they’re of use
Background
In Custom Roam-style link I expressed some thoughts on the DB structure. In Application of Graph Theory to Roam link network I mention adding a new table to the DB. I should probably make a thread to further discussion on this.
Current Structure
The file org-roam.db
is an SQLite DB with the following four tables.
All fields not null, unless labelled as “nullable”
-
files
-
file
: text : unique -
hash
: text -
last_modified
: text
-
-
links
-
from
: text -
to
: text -
type
: text -
properties
: text
-
-
refs
-
ref
: text, unique -
file
: text
-
-
titles
-
file
: text -
tites
: nullable
-
It strikes me that there appears to be a bit of duplication (e.g. file) and redundantly small tables (e.g. titles
). I also suspect that the introduction of UUIDs for the notes could be rather convenient, and lead to one or two minor, but nice, advantages.
An idea of mine
Just a starting point.
FIlename and titles can change. It seems like a nice idea to have a stable UUID for each note. AIn the default filename the current time to the nearest second is used, e.g. 20200429235659
. Adding a created
field would thence be able to both record the creation date (could come in handy now and then), and should be able to serve as a UUID, as of course, the creation date doesn’t change . If somebody (somehow) creates two files within the same second, I think it would be fine to just pretend the second file was created a second later.
Adding a UUID also allows the links table to have stable connections. By this, I mean that links are impervious to file renaming, the UUID field would never need to be updated. Reducing the number of actions that need to be performed on a file rename seems beneficial. To me, on a surface glance, this seems more robust.
With the introduction of Custom Roam-style link files can be referenced using [[roam:title]]
notation. Since one would want such links to uniquely point to a file, it sounds sensible to require titles to be unique (I imagine with an on-save hook where the DB is updated, which probably already exists).
Proposed structure
-
notes
-
UUID
/created
: integer : unique (e.g. 20200429235659) -
file
: text : unique (e.g. “20200429235659-zettelkasten-method. org”) -
title
: text : unique (e.g. “The Zettelkasten Method”) -
hash
: text -
refs
: text : nullable
-
-
links
-
from
: number (UUID, e.g. 20200429235659) -
to
: number (UUID, e.g. 20200429231326) -
type
: text (e.g. “roam”) -
properties
: text
-
I’m not solid on what a ref
is, perhaps it does warrant it’s own little table? IDK.
Network charachteristics extension
Since it’s relevant, in Application of Graph Theory to Roam link network I mention a new table which I think would complement new network analysis capabilities. This is the proposed structure.
-
network_features
-
UUID
: number -
page_rank
: number -
betweeness_centrality
: number -
k_core
: number -
community_index
: number
-
Perhaps this should be merged with notes
? Again, IDK.
Let me know what you think