Print the subject hierarchy as a tree on cards, remove the QR code

Each card now shows, under the call number, the Library of Congress
outline levels for its class (from the published outline, down to the
narrowest range) followed by the place or topic from the catalogue
record's subject heading, one level per line. Existing books get the
subject part filled in by a background job at startup that changes
nothing else about them.

The QR code and everything that read it are removed; the subjects line
on the card is replaced by the tree.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-19 14:06:50 -07:00
1 parent c9b2c2e8c9
commit 7ae1bcef0a
46 files changed
+8591 -545

No files matched your search

+46
View File
@@ -59,3 +59,49 @@ test('settings and cache', () => {
db.cache.set('k', 'w');
assert.equal(db.cache.get('k'), 'w');
});
test('a database made before the hierarchy tail gets the column; old books read as not looked for', async () => {
const { DatabaseSync } = await import('node:sqlite');
const { mkdtempSync, rmSync } = await import('node:fs');
const { tmpdir } = await import('node:os');
const { join } = await import('node:path');
const dir = mkdtempSync(join(tmpdir(), 'booksorter-migrate-'));
try {
const path = join(dir, 'old.db');
const old = new DatabaseSync(path);
old.exec(`
CREATE TABLE books (
id INTEGER PRIMARY KEY AUTOINCREMENT, isbn13 TEXT UNIQUE, lccn TEXT, title TEXT NOT NULL, subtitle TEXT,
authors TEXT NOT NULL DEFAULT '[]', publisher TEXT, year INTEGER, subjects TEXT NOT NULL DEFAULT '[]',
call_number TEXT, sort_key TEXT, confidence TEXT, source TEXT, dewey TEXT,
status TEXT NOT NULL DEFAULT 'pending', attention_reason TEXT, manual_override INTEGER NOT NULL DEFAULT 0,
in_queue INTEGER NOT NULL DEFAULT 0, printed_at TEXT, created_at TEXT NOT NULL, updated_at TEXT NOT NULL
);
CREATE TABLE source_cache (key TEXT PRIMARY KEY, body TEXT NOT NULL);
CREATE TABLE settings (key TEXT PRIMARY KEY, value TEXT NOT NULL);
INSERT INTO books (isbn13, title, call_number, sort_key, confidence, source, status, in_queue, printed_at, created_at, updated_at)
VALUES ('9780874805451', 'Canyoneering 3', 'GV199.42.U82 G733 1997', 'GV 0199.42 U82 G733 1997', 'exact', 'loc-isbn',
'resolved', 1, '2026-01-02T00:00:00.000Z', '2026-01-01T00:00:00.000Z', '2026-01-01T00:00:00.000Z');
`);
old.close();
const db = openDb(path);
const before = db.listBooks()[0]!;
assert.equal(before.hierarchyTail, null);
assert.equal(before.callNumber, 'GV199.42.U82 G733 1997');
assert.deepEqual(db.listTailMissingIds(), [before.id]);
const after = db.updateBook(before.id, { hierarchyTail: ['Utah'] })!;
assert.deepEqual(after.hierarchyTail, ['Utah']);
assert.equal(after.printedAt, before.printedAt);
assert.equal(db.updateBook(before.id, { hierarchyTail: [] })!.hierarchyTail?.length, 0);
assert.deepEqual(db.listTailMissingIds(), []);
assert.equal(db.updateBook(before.id, { hierarchyTail: null })!.hierarchyTail, null);
db.close();
const again = openDb(path); // opening a migrated database again is harmless
assert.equal(again.listBooks().length, 1);
again.close();
} finally {
rmSync(dir, { recursive: true, force: true });
}
});