Splitting an org-roam collection
org-roam supports multiple directories and it should work fine if you start that way, but if you’ve already got an org-roam project that you need to split up, it’s a pain in the butt.
Here’s how I managed to divide my org-roam project into multiple directories after much trial and error and googling.
A note before continuing: If you’re googling around for this you’re going to find a bunch of old commands from when people were upgrading from v1 to v2. Many of these won’t work because their names have been changed.
Step 1 config cleanup
Remove these from your init.el
(config.el
in doom emacs)
(setq org-roam-directory (file-truename "~/Documents/org-roam")) (org-roam-db-autosync-mode)
Setting a default org-roam-directory is just going to cause you headaches and accidentally writing to the wrong place. Leaving the autosync in there will just cause errors when you load.
Step 2 .dir-locals.el
create a .dir-locals.el
file with contents like this. It should be in the directory specified by org-roam-directory
((nil . ((org-roam-directory . "/absolute/path/to/project") │ (org-roam-db-location . "/absolute/path/to/project/org-roam.db")))) (org-roam-db-autosync-mode)
Warning: emacs doesn’t actually read this file until you open something in the same directory or one of the subdirectories. This means that until you do that org-roam-directory
is either unset, or set to whatever it was last.
So, always start an org-roam editing session by opening one of the files in the project.
Step 3
Copy over the subset of files that you want to be part of this project into the directory alongside the .dir-locals.el
(dailies should be in a dailies
subfolder).
Make sure you do not have the *.db
file from the original project.
Step 4
Open every single one of those files. I tried every relevant command I could find that didn’t invole doing this. None worked.
Evaluate (org-roam-db-sync)
If you get errors about uniqueness constraint then run the following
(org-id-update-id-locations (org-roam-list-files))
Then re-evaluate (org-roam-db-sync)
No, I have no idea how it’s possible that the brand new sqlite database could possibly have uniqueness constraints but somehow this is a thing that happens.
Step 5
Wonder if maybe you should be using org-multi-wiki instead. I know I am…
Months Later…
I really wanted to like org-roam. The pitch is great, but I just kept having database related problems.
In the end I switched to Denote and have been very happy every since. He’s taken a unix style approach of using simple, proven, filesystem based tools, and making something really useful by combining them. Because of what it’s based on it “just works”.
Check out the author’s intro video on YouTube.
If org-roam is working for you, then stick with it. If it starts giving you headaches like it did me, then definitely check out Denote. I think it solves the same problem in a much simpler, and more reliable way.