Skip to content

desktop/src-tauri/crates/core/src/storage/mod.rs

Comment 1, line 1

desktop/src-tauri/crates/core/src/storage/mod.rs:1

//! SQLite storage: one writer, WAL, synchronous=FULL and bounded busy_timeout.

Comment 2, line 2

desktop/src-tauri/crates/core/src/storage/mod.rs:2

//! Check schema versions without automatic migrations; see architecture.md#database and the data rules.

Comment 3, line 12

desktop/src-tauri/crates/core/src/storage/mod.rs:12

/// Default bounded busy_timeout avoids indefinite waits behind readers/writers.

Comment 4, line 15

desktop/src-tauri/crates/core/src/storage/mod.rs:15

// SQLite's built-in lower/NOCASE handles only ASCII. Apply matching Unicode

Comment 5, line 16

desktop/src-tauri/crates/core/src/storage/mod.rs:16

// lowercase rules in SQL filters and Rust grouping, including historical rows.

Comment 6, line 39

desktop/src-tauri/crates/core/src/storage/mod.rs:39

/// Latest supported schema; None selects schema::SCHEMA_VERSION.

Comment 7, line 52

desktop/src-tauri/crates/core/src/storage/mod.rs:52

/// Single-writer storage handle.

Comment 8, line 66

desktop/src-tauri/crates/core/src/storage/mod.rs:66

/// Open/create the database, configure pragmas and check/create the expected schema;

Comment 9, line 67

desktop/src-tauri/crates/core/src/storage/mod.rs:67

/// mark running jobs left by the previous process as interrupted.

Comment 10, line 86

desktop/src-tauri/crates/core/src/storage/mod.rs:86

/// Read-only connection, alongside one background writer and a few readers.

Comment 11, line 87

desktop/src-tauri/crates/core/src/storage/mod.rs:87

/// Do not migrate or persist pragma settings; WAL permits concurrent writer access.

Comment 12, line 88

desktop/src-tauri/crates/core/src/storage/mod.rs:88

/// Missing/unreadable databases return errors instead of creating an empty replacement.

Comment 13, line 108

desktop/src-tauri/crates/core/src/storage/mod.rs:108

// Current prerelease policy does not migrate databases version by version.

Comment 14, line 109

desktop/src-tauri/crates/core/src/storage/mod.rs:109

// A version mismatch returns an error for application-level rebuild/exit handling.

Comment 15, line 110

desktop/src-tauri/crates/core/src/storage/mod.rs:110

// A new database with user_version=0 receives the full schema.

Comment 16, line 112

desktop/src-tauri/crates/core/src/storage/mod.rs:112

// Distinguish a new database from an unversioned one by checking for the settings table.

Comment 17, line 119

desktop/src-tauri/crates/core/src/storage/mod.rs:119

// Create the schema in one step for a new database.

Comment 18, line 123

desktop/src-tauri/crates/core/src/storage/mod.rs:123

// A settings table without a version identifies an old database requiring rebuilding.

Comment 19, line 130

desktop/src-tauri/crates/core/src/storage/mod.rs:130

// Prerelease version mismatches require rebuilding rather than automatic migration.

Comment 20, line 138

desktop/src-tauri/crates/core/src/storage/mod.rs:138

// journal_mode persists; in-memory databases return memory instead of WAL.

Comment 21, line 143

desktop/src-tauri/crates/core/src/storage/mod.rs:143

// These optional acceleration indexes do not change the schema version.

Comment 22, line 144

desktop/src-tauri/crates/core/src/storage/mod.rs:144

// Partial indexes avoid repeated full scans for uncommon coverage gaps.

Comment 23, line 165

desktop/src-tauri/crates/core/src/storage/mod.rs:165

/// Drop only the optional query cache for explicit uncached measurements.

Comment 24, line 174

desktop/src-tauri/crates/core/src/storage/mod.rs:174

/// Current user_version.

Comment 25, line 181

desktop/src-tauri/crates/core/src/storage/mod.rs:181

/// Monotonic data revision; queries use one revision for a consistent view.

Comment 26, line 186

desktop/src-tauri/crates/core/src/storage/mod.rs:186

/// Increment and return the data revision, within a transaction only.

Comment 27, line 203

desktop/src-tauri/crates/core/src/storage/mod.rs:203

/// Recover jobs by marking running as interrupted, without relying on PID files.

Comment 28, line 213

desktop/src-tauri/crates/core/src/storage/mod.rs:213

/// Ensure this source host exists and return its opaque stable ID (data-contract.md#provenance).

Comment 29, line 214

desktop/src-tauri/crates/core/src/storage/mod.rs:214

/// - First call persists host-<32hex> in origin_hosts with is_local=1 and

Comment 30, line 215

desktop/src-tauri/crates/core/src/storage/mod.rs:215

/// settings.local_origin_host_id; do not identify hosts by name, IP or hardware fingerprint.

Comment 31, line 216

desktop/src-tauri/crates/core/src/storage/mod.rs:216

/// - Later calls return the same ID and record hostname observations; a rename

Comment 32, line 217

desktop/src-tauri/crates/core/src/storage/mod.rs:217

/// creates no new identity or duplicate usage, and names never enter keys.

Comment 33, line 218

desktop/src-tauri/crates/core/src/storage/mod.rs:218

/// - Copying a database to another machine does not claim its history automatically.

Comment 34, line 219

desktop/src-tauri/crates/core/src/storage/mod.rs:219

/// Callers supply ownership explicitly; source conflicts require mapping/confirmation (M1a).

Comment 35, line 269

desktop/src-tauri/crates/core/src/storage/mod.rs:269

/// Current local host ID, or None before initialization.

Comment 36, line 282

desktop/src-tauri/crates/core/src/storage/mod.rs:282

/// Retain historical hostname observations without changing host identity.

Comment 37, line 302

desktop/src-tauri/crates/core/src/storage/mod.rs:302

/// Register an imported source host and return host_id; repeated registration keeps the same identity.