mirror of
https://github.com/narrrl/narl-workspace.git
synced 2026-11-04 00:47:01 +01:00
Node update, delete and move each ran as separate statements, with the slug chosen outside the write that took it. They are now one transaction each, opened with BEGIN IMMEDIATE so a read-then-write cannot fail with SQLITE_BUSY halfway. Creating a node, a space or a file does the same. A delete is one function, delete_subtree, used by the API and the SFTP mount alike: SFTP deletes used to skip the media cleanup and orphan the files a document embedded. Rows go in the transaction, bytes after the commit. Deleting a media row that backs a file in the tree is refused; the media browser marks those files and stops counting them as documents that embed them. A space can no longer be moved into a folder. The diary is found by a role column (migration 0013) instead of its slug, so renaming it no longer breaks the reminder or the agenda, and it cannot be deleted. The same migration adds the unique index root slugs never had. A card is done exactly when it is in the last list: a done patch now moves the card, a card made in the done list is stamped, and adding or deleting lists settles the board. Seeding a fresh board is atomic, and a card links only to a document. Uploads are fsynced before the rename, and zip entries are written aside and renamed like any other upload. A sweep at start and once a day removes leftover .part files, files no row knows, and uploads nothing has embedded for a week. Before a new build migrates the database it writes a VACUUM INTO copy, diary.db.pre-<version>, since migrations only go forward.
13 lines
730 B
SQL
13 lines
730 B
SQL
-- What a space is for, where the code has to know. The diary used to be found
|
|
-- by its slug, so renaming it — which moves the slug — left the reminder
|
|
-- believing nothing had been written in it, ever. A role survives a rename.
|
|
ALTER TABLE nodes ADD COLUMN role TEXT;
|
|
UPDATE nodes SET role = 'diary'
|
|
WHERE parent_id IS NULL AND kind = 'space' AND slug = 'diary';
|
|
CREATE UNIQUE INDEX idx_nodes_role ON nodes (role) WHERE role IS NOT NULL;
|
|
|
|
-- (parent_id, slug) is unique, but SQLite counts every NULL as distinct, so
|
|
-- that index never covered the spaces themselves: root slugs were unique only
|
|
-- because the code checked before it inserted.
|
|
CREATE UNIQUE INDEX idx_nodes_root_slug ON nodes (slug) WHERE parent_id IS NULL;
|