From 7feb0b4385264075c82c8d983b7d3d1a9b42bb6d Mon Sep 17 00:00:00 2001 From: jverdicc Date: Thu, 5 Mar 2026 05:53:05 -0500 Subject: [PATCH] fix: set WAL mode before transaction in etl-indexer --- crates/evidenceos-etl-indexer/src/main.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/evidenceos-etl-indexer/src/main.rs b/crates/evidenceos-etl-indexer/src/main.rs index 30d5a89..c9cfdf3 100644 --- a/crates/evidenceos-etl-indexer/src/main.rs +++ b/crates/evidenceos-etl-indexer/src/main.rs @@ -287,10 +287,7 @@ fn index_etl(etl_path: &Path) -> Result { fn apply_schema(conn: &Connection) -> Result<(), IndexerError> { conn.execute_batch( - "PRAGMA journal_mode=WAL; - PRAGMA synchronous=FULL; - PRAGMA foreign_keys=ON; - CREATE TABLE IF NOT EXISTS claim_capsules( + "CREATE TABLE IF NOT EXISTS claim_capsules( etl_index INTEGER PRIMARY KEY NOT NULL, capsule_hash TEXT, claim_id TEXT, @@ -342,8 +339,18 @@ fn apply_schema(conn: &Connection) -> Result<(), IndexerError> { Ok(()) } +fn apply_connection_pragmas(conn: &Connection) -> Result<(), IndexerError> { + conn.execute_batch( + "PRAGMA journal_mode=WAL; + PRAGMA synchronous=FULL; + PRAGMA foreign_keys=ON;", + )?; + Ok(()) +} + fn migrate_schema(db_path: &Path) -> Result<(), IndexerError> { let mut conn = Connection::open(db_path)?; + apply_connection_pragmas(&conn)?; let tx = conn.transaction()?; apply_schema(&tx)?; @@ -388,6 +395,7 @@ fn build_index(etl_path: &Path, out_path: &Path) -> Result<(), IndexerError> { } let mut conn = Connection::open(&tmp_path)?; + apply_connection_pragmas(&conn)?; let tx = conn.transaction()?; apply_schema(&tx)?; @@ -443,6 +451,7 @@ fn build_index(etl_path: &Path, out_path: &Path) -> Result<(), IndexerError> { params![digest, INDEX_SCHEMA_VERSION, TOOL_VERSION], )?; tx.commit()?; + drop(conn); if out_path.exists() { fs::remove_file(out_path)?;