From 177a70e41cd6ce9e9a39a630e81ae3d89c4fe742 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Sun, 1 Mar 2026 20:08:46 -0600 Subject: [PATCH] store: Fix: sqlx in-memory SQLite pool requires max_connections=1 --- ...e-pool-requires-max-connections1-1b71b1.md | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 graph/fixes/fix-sqlx-in-memory-sqlite-pool-requires-max-connections1-1b71b1.md diff --git a/graph/fixes/fix-sqlx-in-memory-sqlite-pool-requires-max-connections1-1b71b1.md b/graph/fixes/fix-sqlx-in-memory-sqlite-pool-requires-max-connections1-1b71b1.md new file mode 100644 index 00000000000..23d28510523 --- /dev/null +++ b/graph/fixes/fix-sqlx-in-memory-sqlite-pool-requires-max-connections1-1b71b1.md @@ -0,0 +1,43 @@ +--- +id: 1b71b163-b56f-4226-9731-a76ef245e532 +type: fix +title: "Fix: sqlx in-memory SQLite pool requires max_connections=1" +tags: [sba-scouting, rust, sqlx, sqlite, testing, fix, in-memory] +importance: 0.8 +confidence: 0.8 +created: "2026-03-02T02:08:46.895029+00:00" +updated: "2026-03-02T02:08:46.895029+00:00" +--- + +# sqlx In-Memory SQLite Pool: max_connections Must Be 1 + +## Problem +Integration tests using `:memory:` SQLite failed with "no such table" errors after wrapping `create_tables` in a transaction. + +## Root Cause +With `max_connections > 1`, each connection in the pool gets its own separate in-memory database. A transaction on connection A (e.g. `pool.begin()` for `create_tables`) is invisible to queries on connection B. In-memory SQLite databases are per-connection — there is no shared state across connections. + +## Fix +Detect `:memory:` path and force `max_connections(1)`. Also skip WAL journal mode for in-memory DBs (WAL requires a file). + +```rust +let pool = if db_path == ":memory:" { + SqlitePoolOptions::new() + .max_connections(1) + .connect(":memory:") + .await? +} else { + SqlitePoolOptions::new() + .max_connections(5) + .connect(&format!("sqlite:{db_path}")) + .await? +}; + +// Only set WAL for file-backed DBs +if db_path != ":memory:" { + sqlx::query("PRAGMA journal_mode=WAL").execute(&pool).await?; +} +``` + +## Impact +All 5 integration tests were broken until this was applied. Applies to any test setup using `create_tables` inside a transaction with a shared pool.