Skip to content

Use integer keys for content-hash lookups and store Git SHAs and decision UUIDs as bytes - #98

Merged
nedtwigg merged 3 commits into
mainfrom
schema-audit
Nov 28, 2026
Merged

nedtwigg merged 3 commits into
mainfrom
schema-audit

Conversation

@nedtwigg

@nedtwigg nedtwigg commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

SQLite storage

  • Images and built Storybooks use the first 53 bits of their content hash as an integer primary key. Reads confirm the full hash at that key. A zero prefix or a collision uses the negative-key range. Both tables drop their secondary full-hash index. A single atomic insert derives the prefix, handles retries, and returns the assigned key.
  • Decisions store the originating batch UUID in 16 bytes. Sync still exchanges canonical lowercase UUIDs, including when the originating batch has never reached this store.
  • Commits store SHA-1 and SHA-256 digests as raw bytes behind a unique index. Edges, batches, and decisions reference compact SQLite-assigned integers. Git and sync still use full lowercase hex.

Measurements

Local SQLite with 100,000 distinct image hashes used 8.07 MB after compaction, down from 16.10 MB. Inserts took 247 ms versus 448 ms. Bulk checks for 100,000 existing images took 33 ms versus 36 ms. These are median SQL timings over five runs per layout with prepared inputs. A separate 200,000-decision fixture used 11.20 MB with binary UUIDs versus 15.32 MB with text UUIDs. The store and render rationale files give the workloads and the commit-key measurements.

Rollout and verification

OPERATIONS.md lists the project tables to reset before deploying to an existing store. The reset discards project history and metadata. Re-pushing can reuse existing blob bytes.

Store, UI, renderer, CLI, and site suites passed locally. Coverage includes overlapping writers, positive and zero-prefix collisions, lost responses, render writes, bulk lookups, and binary ID round trips. The site suite used a separate localhost port. Hosted D1 credentials were unavailable.

@selfie-bot selfie-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrading the CLI breaks every existing local store, and nothing tells a user how to recover. openProject in cli/src/project.ts calls initStoreSchema on every command, so an old $SELFIE_HOME/<slug>/store.db (default ~/.config/selfie) fails every selfie command with SQLite's no such column: sha_bytes. The reset steps in OPERATIONS.md cover only the project D1 databases. Their last step, "push the batches and decisions you want to publish again", depends on those same local stores, and a new CLI can no longer open them. Either the store or the CLI could catch this failure and show a message that names the reset, which is the same five tables dropped locally. OPERATIONS.md should also say whether the republish has to happen from the old CLI before upgrading. Details inline.

Comment thread OPERATIONS.md Resolved
Comment thread docs/specs/renders.md Resolved
@nedtwigg nedtwigg changed the title Store Git commit SHAs as raw bytes and document SQLite key choices Use integer keys for content-hash lookups and store Git SHAs and decision UUIDs as bytes Nov 28, 2026
@nedtwigg
nedtwigg merged commit 725ef87 into main Nov 28, 2026
5 checks passed
@nedtwigg
nedtwigg deleted the schema-audit branch November 28, 2026 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants