Skip to content

maint: squash migrations into a v1 baseline before first release - #34

Merged
karngyan merged 1 commit into
mainfrom
maint/squash-schema-v1
Jul 17, 2026
Merged

maint: squash migrations into a v1 baseline before first release#34
karngyan merged 1 commit into
mainfrom
maint/squash-schema-v1

Conversation

@karngyan

Copy link
Copy Markdown
Contributor

Claim

Autophagy has never shipped. This replaces the eight development-time SQLite migrations (0001..0008) with a single squashed 0001_initial_schema.sql v1 baseline, so the first release presents one clean origin schema rather than eight fossilized diffs (three of which — 0005, 0007, 0008 — recreate whole tables to alter CHECK constraints). The "migrations are ordered and immutable" rule protects released users; its scope begins at this first release. See ADR 0012.

The equivalence proof

The baseline was derived from the applied v8 schema by reconstructing DDL from sqlite_master (formatting normalized, good comments kept) — not transcribed from memory — then given clean unquoted table names in place of the quoted rename artifacts the old recreate-copy-rename chain left behind.

tests/schema_equivalence.rs is load-bearing: it builds one database from the eight legacy migrations (preserved verbatim under tests/legacy/) and one from the shipped baseline, then asserts:

  • identical full sqlite_master (every table, index, trigger, virtual table, and FTS5 shadow table), normalized (whitespace collapsed, identifier quotes stripped); and
  • identical per-table table_info / index_list / foreign_key_list pragmas.

No drift is tolerated. CHECK expressions live only in the SQL text, so the normalized-DDL comparison is what pins them.

The adoption story

Exactly one database exists in the wild — the author's own, at v8 with the full eight-row schema_migrations ledger. A pre-release courtesy shim in migration.rs recognises that exact ledger (each of the eight checksums verified against embedded constants) and, on open, adopts it in one transaction: the eight ledger rows become the single v1 baseline row (with the baseline's real checksum) and user_version is reset to 1. Because the schema is already identical, adoption never touches a table — only the ledger. Any other unexpected version still errors (DatabaseTooNew); a second open is a no-op. The shim and its LEGACY_V8_CHECKSUMS are documented for removal post-adoption (ADR 0012).

The macOS app's knownSchemaVersion drops to 1; a not-yet-adopted v8 database classifies as newer-than-known and reads read-only until the CLI adopts it.

Verification

  • mise run check — exit 0
  • mise run demo — green
  • swift test (apps/macos) — 36 passed
  • Real-data: against a copy of the author's real v8 database, first status adopted it to schema v1; all counts preserved (69,400 events · 320 sessions · 2 candidates · 34,911 signatures); ledger collapsed to one v1 row; second open idempotent. Copy deleted; the real database was never opened by this build and remains at v8.

Privacy

Local-only; touches no event, mutation, or audit data. Adoption rewrites a handful of ledger rows in place on the user's own database, copies nothing off the machine, and refuses any ledger it does not recognise byte-for-byte.

🤖 Generated with Claude Code

Replace the eight development-time migrations (0001..0008) with a single
0001_initial_schema.sql. The store never shipped, so no external database
depends on the old chain; the immutability rule protects released users and
its scope begins at this first release (ADR 0012). 0005/0007/0008 recreated
whole tables to alter CHECKs, so the old chain's final schema was scattered
and carried quoted rename artifacts in sqlite_master.

The baseline was derived from the applied v8 schema (reconstructed from
sqlite_master, not transcribed) and is schema-identical to it. A load-bearing
test (tests/schema_equivalence.rs) builds one DB from the legacy chain
(preserved verbatim under tests/legacy/) and one from the shipped baseline and
asserts identical normalized sqlite_master plus per-table table_info /
index_list / foreign_key_list pragmas.

A pre-release adoption shim recognises the one known legacy database (v8 with
the full eight-row ledger and matching checksums) and, on open, rewrites the
ledger to the single v1 baseline row and resets user_version to 1 in one
transaction — never touching a table, since the schema is already identical.
Any other unexpected version still errors (DatabaseTooNew). A second open is a
no-op. The shim and its embedded checksums are marked for removal post-adoption.

macOS knownSchemaVersion -> 1; a not-yet-adopted v8 database classifies as
newer-than-known and reads read-only until the CLI adopts it.

Verification: mise run check (exit 0), mise run demo (green), swift test (36
passed). Against a copy of the author's real v8 database: adoption succeeded
to schema v1, all counts preserved (69,400 events, 320 sessions, 2 candidates,
34,911 signatures), second open idempotent; copy deleted, real DB untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LY7xtercMc3NtLeX2z4YV
@karngyan
karngyan merged commit e9bf0e0 into main Jul 17, 2026
2 checks passed
@karngyan
karngyan deleted the maint/squash-schema-v1 branch July 17, 2026 11:02
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.

1 participant