Skip to main content

open_meta_db

Function open_meta_db 

Source
pub fn open_meta_db(db_path: impl AsRef<Path>) -> Result<Connection>
Expand description

Open a SQLite database with Reflex’s standard pragmas.

Every connection to meta.db (and to the symbol cache, which lives in the same file) MUST go through this helper. Plain Connection::open leaves SQLite at its defaults, which caused three separate production failures:

  1. No busy_timeout — the default is 0, so BEGIN IMMEDIATE returned database is locked instantly whenever the background symbol indexer held a write. Agents saw a raw SQLite error instead of a retry.
  2. No journal_mode=WAL — readers blocked writers and vice versa, and CacheManager::checkpoint_wal was issuing wal_checkpoint(TRUNCATE) against a rollback-journal database, where it does nothing.
  3. No foreign_keys=ON — SQLite disables foreign keys per connection by default, so the ON DELETE CASCADE clauses in the schema never fired and deleting a row from files orphaned its file_branches / file_dependencies / file_exports rows.

Pragma order is load-bearing: journal_mode=WAL itself can return SQLITE_BUSY when another connection is attached, so busy_timeout must be set first.

Set REFLEX_SQLITE_JOURNAL=delete to opt out of WAL on network filesystems, where WAL requires shared-memory support that NFS/SMB do not reliably provide.