meerkat_sqlite/lib.rs
1//! Shared SQLite mechanics for Meerkat stores.
2//!
3//! This crate is the single home for the connection policy, schema-evolution,
4//! and maintenance-fence machinery that was previously copy-pasted across the
5//! store crates (six independently authored PRAGMA setups with divergent busy
6//! timeouts, `CREATE TABLE IF NOT EXISTS` everywhere, and no version ledger).
7//! See `docs/plans/storage-unification-plan.md` (Phase 3) in the workspace
8//! root for the design rationale.
9//!
10//! What lives here:
11//!
12//! - [`profile`]: DDL-free connection opening under named policy profiles
13//! ([`ConnectionProfile::Primary`], [`ConnectionProfile::ReadOnly`],
14//! [`ConnectionProfile::Maintenance`]). Opening a connection never runs
15//! schema DDL; stores apply their [`ledger`] domain after opening. The
16//! optional [`OpenOptions::schema_preflight`] proves an exact current,
17//! released-predecessor, or fresh-domain shape before any mutating pragma,
18//! [`JournalPolicy`] states per profile whether an open establishes WAL or
19//! preserves the mode it finds, and [`WriteContact`] types each profile's
20//! honest no-write guarantee (WAL reads may need sidecar files).
21//! - [`ledger`]: the per-file migration ledger (`meerkat_schema(domain,
22//! version)`) with the pinned concurrent-open transaction protocol and the
23//! typed refusals for future, pre-floor, gap, unledgered-owned, and
24//! fingerprint-mismatched shapes. Ledger state that is malformed (wrong
25//! shape, duplicate rows, non-positive versions) is refused typed, never
26//! healed.
27//! - [`json_column`]: the TEXT-or-BLOB tolerant JSON column codec.
28//! - [`fence`]: the per-operation maintenance-fence guards. Store operations
29//! take a shared guard; offline migration takes the exclusive side and
30//! waits for in-flight operations to drain. Stores built on this crate hold
31//! no bespoke opener, which is what makes them fence-aware for free.
32//! - [`error`]: the crate error type plus the storage-level error
33//! classification (transient / corrupt) that store crates layer their
34//! staleness semantics on top of. Adoption contract: store crates route
35//! every raw rusqlite error through [`classify_sqlite_error`] instead of
36//! re-matching SQLite error codes locally.
37//!
38//! # Retryability
39//!
40//! Error classification alone does not authorize a retry: a transient failure
41//! can land after a write committed but before success became observable, and
42//! blind retry duplicates non-idempotent effects. Automatic retry is only
43//! sound for idempotent or CAS-keyed operations; an indeterminate
44//! non-idempotent write requires outcome reconciliation (read back, then
45//! decide) before any retry. Bounded waiting for lock contention is the
46//! connection busy handler's job, not a caller retry loop.
47
48pub mod error;
49pub mod fence;
50pub mod json_column;
51pub mod ledger;
52pub mod profile;
53
54pub use error::{
55 BridgeEligibility, SqliteErrorClass, SqliteStoreError, classify_sqlite_error, is_busy_or_locked,
56};
57pub use fence::{ExclusiveFence, OperationGuard, fence_lock_path};
58pub use json_column::JsonColumnBytes;
59pub use ledger::{
60 LedgerReport, MaintenanceBridgeReport, MaintenancePrepareFn, MaintenancePrepareReport,
61 MaintenanceRecordRefusal, Migration, SchemaDomain, SchemaObject, SchemaObjectKind,
62 SchemaPredecessor, apply_domain_migrations, bridge_unledgered_domain, domain_version,
63 preflight_schema_eligibility, verify_released_schema_fingerprint,
64 verify_released_schema_structure,
65};
66pub use profile::{
67 ConnectionProfile, JournalPolicy, OpenOptions, SHARED_BUSY_TIMEOUT, WriteContact,
68 begin_immediate, open, open_with,
69};
70/// The connection type [`open`] returns, so callers can name it without
71/// taking their own direct `rusqlite` dependency.
72pub use rusqlite::Connection;