AI WIP | Commonize SQLite store setup in atuin-common (sqlite feature) - #3661
Draft
markovejnovic wants to merge 8 commits into
Draft
AI WIP | Commonize SQLite store setup in atuin-common (sqlite feature)#3661markovejnovic wants to merge 8 commits into
markovejnovic wants to merge 8 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Six SQLite-backed stores each hand-rolled the same
new(path, timeout)pool setup — broken-symlink guard, parent-dir creation, theSqliteConnectOptionspragma chain,SqlitePoolOptionswithacquire_timeout, and (for two) a0o600chmod. This extracts that into one feature-gated builder inatuin-commonand migrates every store onto it.The shared builder
New
#[cfg(feature = "sqlite")]moduleatuin_common::sqlite:open()handles the filesystem prep (:memory:skip, broken-symlink guard, parent-dir creation), applies the configured pragmas, connects the pool, and optionally restricts the file to0o600. There's alsoversion(&pool)(consolidating the three identicalsqlite_version()methods). Migrations stay per-store (they use thesqlx::migrate!macro, which must expand at the call site).Feature:
sqlite = ["sqlx/sqlite", "sqlx/regexp"]onatuin-common, enabled by the four consuming crates. This also closes a latent footgun:atuin-kv/atuin-scriptscall.with_regexp()but never enabled sqlx'sregexpfeature themselves — it only worked via cross-crate feature unification. That capability is now explicitly owned byatuin-common.Behavior preservation
The builder is faithful to which setters each store called —
synchronousisOption(unset ⇒ not called ⇒ sqlx default FULL),foreign_keys/regexpare opt-in,optimize_on_close/create_if_missingare universal. Each store's resultingSqliteConnectOptionsis identical to before:Intentional changes (called out for review)
process::exit(1)→ returnedsqlx::Error. The old code calledstd::process::exit(1)from library code; the builder returns an error that propagates to the CLI's normal error handling. Themetaandaistores, which had no broken-symlink guard, gain this (strictly safer) check — harmless, they only ever pass real or:memory:paths.0o600restriction now runs right after connect, before migrations (meta/ai). Behavior-equivalent for the final on-disk permission (same single main-db file), a marginally tighter window.:memory:filesystem prep is skipped uniformly. history/record previously ran the fs-prep even for in-memory paths (which happened to succeed); now unified with meta/ai.Verification
cargo build --workspace,cargo clippy --workspace --all-targets -- -D warnings, andcargo test --workspace --liball clean.grep SqliteConnectOptionsfinds zero direct constructions across the six stores — all go through the builder.:memory:); each store's existing suite validates its own migration.history.db); confidence comes from the per-store base-vs-head config comparison, the builder tests, and the full workspace suite.🤖 Generated with Claude Code