Skip to content

Finish the schema while it's free: a schema version, bytes for hashes and batch IDs, STRICT tables, and a total decision order - #99

Merged
nedtwigg merged 6 commits into
mainfrom
schema-finish
Nov 28, 2026
Merged

nedtwigg merged 6 commits into
mainfrom
schema-finish

Conversation

@nedtwigg

Copy link
Copy Markdown
Member

Follows #98, while no project's history is worth keeping. Each of these is cheap now and a migration later.

  • A schema version. schema_version holds one row, since real D1 refuses PRAGMA user_version. initStoreSchema checks it in a request before setting anything up: a store with none of the tables gets version 1, and one at another version, or with tables and no version, throws StoreSchemaError and is left as it was. The CLI reports an older store as old-store, as before, and a newer one as a new newer-store.
  • Image and built Storybook hashes as their 32 bytes, as Use integer keys for content-hash lookups and store Git SHAs and decision UUIDs as bytes #98 did for commit SHAs.
  • Batch IDs as 16 bytes: a batch's own and the one it reused, as Use integer keys for content-hash lookups and store Git SHAs and decision UUIDs as bytes #98 did for a decision's batch. The conversions are in store/src/core/sql-bytes.ts, and the batch lookups share one fragment.
  • Every table STRICT, which can't be added to a table later without rebuilding it.
  • A total order for decisions. The merge rule and the comparison now break a tie in time and verdict by batch ID, then commit SHA and image hash, in SQL and in newestFirst. Before, two stores given the same decisions in a different order could read a render differently. Both new tests fail without the fix.

The reset. #98 hasn't been released, so one reset covers both. OPERATIONS.md → Resetting a project store now also drops environments, stories, actors, and schema_version. Without that, a reset store would keep three non-STRICT tables and be refused for having tables and no version.

Verified.

  • pnpm test passes: store 658, CLI 532, UI 119, render 148, site 19.
  • The scan check now also covers keeping images and built Storybooks. It allows a scan of a one-row subquery, which Use integer keys for content-hash lookups and store Git SHAs and decision UUIDs as bytes #98's hash lookup joins from.
  • On real D1, in the sandbox project's database, which this release's reset wipes anyway, with scratch tables dropped afterwards: unhex with one and two arguments, STRICT with WITHOUT ROWID, STRICT refusing a wrong type, and the version stamp's sqlite_master query.
  • The opt-in live D1 suites still can't run here, since ~/.config/selfie/d1.env is gone.

Left for later.

  • The CLI's own tables (notes, render_keys) have no version and aren't STRICT, so the CLI still treats a missing column as old-store.
  • The Worker answers a refused store with a plain 500. preflight could check each project database's version before a release instead.

🤖 Generated with Claude Code

nedtwigg and others added 5 commits November 28, 2026 12:14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orybooks, and say each rule once

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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.

One spec nit inline: a refused store isn't left quite as it was.

Comment thread docs/specs/renders.md Resolved
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nedtwigg
nedtwigg merged commit 04ff6a2 into main Nov 28, 2026
5 checks passed
@nedtwigg
nedtwigg deleted the schema-finish branch November 28, 2026 21:12
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