paperspec0.1.0

13. The database form and the bundle

13.1 Portability#

sql/doc.sql defines the document tables and sql/store.sql a team store's tables. Both run unchanged on SQLite, Dolt and PostgreSQL, under these rules:

  1. No foreign keys; references are checked by validators, not by the database.
  2. Enumerations are VARCHAR with CHECK (… IN (…)).
  3. JSON values are canonical JSON in TEXT columns; booleans are INTEGER 0 or 1.
  4. Every table has a primary key, and key columns are VARCHAR with a length, as MySQL-compatible engines require.
  5. No table, column or index is named with a word reserved in SQLite, PostgreSQL or MySQL; so the formats' key, index, at, by, before and after are doc_key, idx, made_at, signer, before_hash and after_hash.

13.2 Tables#

TableOne row perNotes
worksworkIts key and same_as.
documentsdocumentEvery property of document.json as a column, plus provenance, roster and package_hash.
witnesseswitnessWith ord, its position in witnesses.json.
nodesnodeWith seq, its position in document order.
pages, locations, refspage, location, reference
correctionscorrectionThe common properties as columns; the rest in details.
node_idsretired ID or alias
receipts, revocationsreceipt, revocation
suspectssuspect
package_filesasset, dataset file or derived fileIts path, SHA-256, size and whether its bytes were present. Bytes go to the asset store.
citationscite run and referenceDerived on load.
receipt_nodesnode a receipt listsDerived on load.

A 30-page paper is about 3,000 nodes, so 500 documents are about a million and a half rows, which SQLite and Dolt hold comfortably.

13.3 Load and unload#

Loading a package is a pure function of the package: each record becomes a row, an optional property absent from the record is NULL, and JSON-valued properties are stored as canonical JSON. Unloading writes each file back from its rows in the file's defined order, omitting optional properties that are NULL and optional files that have no rows, copies the other files from the asset store, and writes the manifest. Unloading gives the package back byte for byte, and its manifest hash with it; the suite checks this for every fixture.

13.4 The store tables#

store.sql adds what a team adds to its documents: roster_keys, projects, members, project_documents, reading_paths, layers, annotations, annotation_targets (derived, so a reader finds the annotations on a node), datasets, dataset_values, digitizations, views, policies, submissions and grades. Each keeps its record whole in a record or descriptor column, with the columns a query needs beside it.

13.5 The bundle#

A bundle, scienting-bundle/1, is one SQLite file that a reader or a server queries. It holds the tables of doc.sql and store.sql, then those of sql/bundle-sqlite.sql:

TableHolds
bundle_metaname and value pairs: at least format (scienting-bundle/1), store, built_from (the store revision) and spec (the version of these specifications).
searchAn FTS5 index with one row per sentence, cell, equation outside a sentence and figure-text item, in document order: the document, the node, the unit, the context and the text. Withheld text is never indexed.
embeddings_metaReserved for embeddings with sqlite-vec: the model, its dimensions, and the rights use they were made under.

A search row's unit is sentence, cell, equation or figure-text. For a node, context is the kind of its parent, such as paragraph, heading, caption or row, and text is its normalized plain projection (3.6). An equation inside a sentence is searched as part of that sentence, so it has no row of its own. A figure-text item names its panel as the node, its role as the context and its normalized text as the text.

At team scale this is all the search a team needs. A team can download its bundle and use it offline. Because a bundle holds text, it is served only under the rights of 14, checked again whenever text is served.

Source: spec/13-database.md · raw