diff --git a/graph/fixes/fix-sqlite-pragma-foreign-keys-is-per-connection-not-per-poo-49a800.md b/graph/fixes/fix-sqlite-pragma-foreign-keys-is-per-connection-not-per-poo-49a800.md new file mode 100644 index 00000000000..307e1e23d65 --- /dev/null +++ b/graph/fixes/fix-sqlite-pragma-foreign-keys-is-per-connection-not-per-poo-49a800.md @@ -0,0 +1,38 @@ +--- +id: 49a8001d-b3b9-4a29-911a-956db4b37f21 +type: fix +title: "Fix: SQLite PRAGMA foreign_keys is per-connection, not per-pool" +tags: [sba-scout, rust, sqlx, sqlite, fix, pragma, connection-pool] +importance: 0.7 +confidence: 0.8 +created: "2026-02-28T16:53:04.445263+00:00" +updated: "2026-02-28T16:53:04.445263+00:00" +--- + +# SQLite PRAGMA Scope with sqlx Connection Pools + +**Project:** sba-scout (Rust) + +## Problem + +When using sqlx connection pools, `PRAGMA` statements only affect the specific connection they run on. Running `PRAGMA foreign_keys = OFF` via `pool.execute()` may use a different connection than subsequent queries — so FK enforcement remains on for those queries. + +## Fix + +Use `SqliteConnectOptions::foreign_keys(false)` to apply the setting to **every** connection the pool creates, not just whichever one happens to handle the PRAGMA execute call. + +```rust +let opts = SqliteConnectOptions::from_str(&db_url)? + .foreign_keys(false) + .create_if_missing(true); + +let pool = SqlitePool::connect_with(opts).await?; +``` + +## Context + +For sba-scout, FK enforcement was disabled entirely because transactions reference players/teams that may not exist locally (data arrives out of order from the API). + +## General Rule + +Any SQLite session-level setting (PRAGMA) must be applied at the connection options level when using a pool, not via a one-off `execute()` call.