Docs / CATALOG-DATABASE
Catalog database (local SQLite)
Source: docs/CATALOG-DATABASE.md
Every console, game and controller the user adds — from a URL, an upload, a
local file, a registry entry or a saved configuration — is persisted in a
local SQLite database. This is the source of truth for the user's catalog. No
server, account, credential or network upload is involved.
Files
Path (under GAMECOMPOSER_DATA_DIR, else the OS data folder) |
Role |
|---|---|
catalog.sqlite3 (+ WAL/SHM sidecars) |
Authoritative catalog and provenance. |
library.json |
Backwards-compatible mirror; still written and still read. Never deleted. |
library/files/<sha[:2]>/<sha>/<file> |
Content-addressed bytes (ROM, emulator binary, cover image). |
Schema (version 1)
CREATE TABLE catalog_meta (
key TEXT PRIMARY KEY,
value TEXT NOT NULL
);
CREATE TABLE catalog_items (
id TEXT PRIMARY KEY,
kind TEXT NOT NULL CHECK (kind IN ('console','game','controller')),
source TEXT NOT NULL, -- registry | url | upload | local | config
provenance TEXT NOT NULL, -- registry | url | upload | file | config
name TEXT NOT NULL,
platform TEXT,
console_id TEXT,
url TEXT, -- original URL, when the entry came from one
sha256 TEXT, -- SHA-256 of the stored bytes
size INTEGER, -- byte size
license TEXT, -- when known (e.g. gopher64 is GPL-3.0)
added_at INTEGER NOT NULL, -- epoch seconds
favorite INTEGER NOT NULL DEFAULT 0,
data TEXT NOT NULL -- full JSON entry, unchanged by the DB
);
CREATE INDEX catalog_items_kind ON catalog_items(kind);
CREATE INDEX catalog_items_sha ON catalog_items(sha256);
CREATE INDEX catalog_items_url ON catalog_items(url);
catalog_meta stores schemaVersion and migratedFromJson. data preserves
all existing library fields (storedPath, consoleId, notes, lastPlayedAt,
settings/mappings, …) so older builds and exports keep working.
Migration and read-through
- On the first open of a data folder, every item in
library.jsonis copied
intocatalog_itemswithINSERT OR IGNORE; the JSON file is left byte-for-byte
untouched and themigratedFromJsonmarker is written. - On later opens the database is read first. If the JSON mirror contains an
entry whose id is not in the database (e.g. copied in by hand while the app
was off), that entry is added to the DB and the mirror is reconciled. Nothing
in the database is overwritten by a stale mirror. - Mutations write the database first, then the JSON mirror. A removed item is
deleted from both. A failed JSON write cannot lose catalog data.
Provenance and dedupe
library.addFromUrl/Library.add_from_urlfetch an HTTPS URL, verify an
optional pinned SHA-256 and size, store the bytes in the blob store and write
a row withprovenance = 'url', the URL, digest, byte size, license (if known)
andaddedAt.library.addUploadrecordsprovenance = 'upload'; local ROMs recordfile;
registry picksregistry; saved configurationsconfig.- A second URL or file with the same SHA-256 for the same kind returns the
existing entry instead of creating a duplicate (find_by_sha256). library.findByUrlandlibrary.findBySha256expose the indexes through the
same JSON request envelope as the other operations.
Operations using the database
All existing operations keep their behavior and now read/write the DB:
library.list, library.add, library.addLocalGame, library.addLocalFolder,
library.updateGame, library.updateItem, library.remove, library.favorite,
library.addConsole, library.addController, sandbox.create,
sandbox.createLocal, registry.catalog, registry.preview.
New additive operations: library.addFromUrl, library.addUpload,
library.inspectUrl, library.findByUrl, library.findBySha256,
sandbox.composeFromUrls, sandbox.createFromUrls.
Tests: tests/registry/test_catalog_database.py covers first-run migration,
read-through, SHA-256 dedupe, URL lookup, persistence across a fresh Library
instance, and URL → catalog → sandbox persistence. No third-party dependency
is added: sqlite3 ships with Python.

