Skip to content

feat(macos): saved queries and history on the core stores - #4611

Merged
datlechin merged 6 commits into
mainfrom
feat/macos-core-history-profiles
Nov 26, 2026
Merged

datlechin merged 6 commits into
mainfrom
feat/macos-core-history-profiles

Conversation

@datlechin

@datlechin datlechin commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Mac stores, lane M3 (core ADR 0010, slices 3 and 9): the saved queries and folders, favourite tables and databases, table folders and the query history get a core copy in Application Support/TablePro/Core/state/history.db, every record under the Mac's own id.

Core (additive, C# regenerated), one API for the Mac and iOS:

  • SavedQueryStore.contents, write_records, replace_records: every connection's queries and folders with their ids, times, place and keyword, and a digest; a removed folder changes no other row.
  • FavouriteStore.contents, write_records, replace_tables, replace_databases, one digest per kind.
  • TableFolderStore.contents, write_records, replace_records.
  • QueryHistoryStore.put_entries (runs an app recorded, with outcome and error text, or moved in, no core session), record_ids, remove_entries, delete_for_connection.
  • Every replace_* takes the digest it was based on and refuses with storage.import_outdated, writing nothing, when the store moved since; the check runs before any validation.
  • Each write is one commit with one journal call naming the record ids it wrote and removed (ADR 0060).

Mac:

  • CoreMirror copies a Swift store into the core after every write and at launch. It keeps a digest per record of what both sides held when they last agreed (com.TablePro.coreMirror.<store>):
    • a record either side changed goes to the other, the Swift store's version when both did;
    • the first push replaces the core whole under the digest precondition; an outdated refusal waits for the next push;
    • a record missing from a Swift store that holds less than it should (a damaged saved-queries file waiting for a refill, a document that does not decode) is not taken for a deletion, and nothing is written over it;
    • writes back into a Swift store are compare-and-set in the same actor step, so an edit made during a push is never written over;
    • one record the core refuses is retried alone, keeps its last agreement and goes again on the next push.
  • A collision the core settles (ADR 0052: a second query of one name becomes <name> (2), a second keyword is cleared) is written back into sql_favorites.db and marked dirty, so the rename syncs over iCloud.
  • QueryHistoryCoreMirror puts each run into the core as it is recorded. Its agreement is a core_mirror table inside query_history.db, so a damaged file set aside takes it along and the core keeps its runs. A delete, filtered clear or connection delete removes those runs from the core and reports a failure while the core still holds them; Clear History clears the core whole; a retention pass reaches the core.
  • The Swift stores stay what this build reads and what the previous stable reads, unchanged in format. The History pane, Insights, plan and Rewind snapshots, saved-query versions and the keyword rules keep their own SQL.
  • P1-M4: SQLFavoriteManager.applyRemote checks the policy on the saved-queries store's actor right before each pulled write, through a lock-protected stop count from SyncCoordinator, so a stop that lands while a write waits for the store commits nothing after it.
  • .claude/rules/data-sync-storage.md: rows for the saved queries, favourite databases, table folders, the core's copy and both agreement records.
  • apple/scripts/probes/check-history-downgrade.sh: T-DWN with this build and the previous stable in one sandbox.
  • apple/changelog.d/4611.changed.md: two saved queries of one name in one connection.

Not here:

  • SSH and credential profiles live in the core's connections.json, which the slice 2 lane moves.
  • The History pane reads the core once the core's history holds the Mac's own columns (database, schema, source, statement type, first-row and server time, fingerprints) and filters.

Test plan

  • cargo test -p tablepro-storage --lib: 434 passed, including whole-store writes and replaces, a stale digest refused, two names settled, history put and remove, the journal's ids.
  • cargo test -p tablepro-ffi --no-default-features --test host_stores: 4 passed.
  • New Swift suites: SavedQueryCoreMirrorTests, FavoriteCoreMirrorTests, QueryHistoryCoreMirrorTests, including both P1-M4 stops, deletions on both sides after a crash, unreadable favourites, a set-aside history file and a settlement of a record already agreed.
  • verify.sh --jobs 4 build for macOS on the MacBook build host: PASS.
  • verify.sh --jobs 4 test, the whole Unit plan: 34,135 executed, 34,134 passed, 1 failed, 2 skipped. The one failure is TableProEditorKitTests/TreeSitterClientTests/test_cancelAllEditsUntilFinalOne(), in the editor package this PR does not touch; run alone it passed and test_editsDuringSetup() failed instead, both cancellation timing under a load average of 45 to 64 on 10 cores.
  • T-DWN, check-history-downgrade.sh with this build's Debug app and TablePro 0.88.0: PASS.
  • Codex: three review rounds (round 3 found no critical or high) and two security passes; every finding fixed.

@datlechin
datlechin merged commit d1e2db4 into main Nov 26, 2026
31 of 35 checks passed
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