Centralize SQLite connection configuration (#33938)

## What changed

- Add `SqliteConfig` as the shared entry point for read-write and read-only SQLite pools.
- Apply consistent WAL, synchronization, auto-vacuum, busy-timeout, logging, and pool-size settings to writable Codex databases.
- Route state runtime, audit, CLI, and test database connections through the shared configuration.

## Testing

- Run migration tests against temporary on-disk databases opened through `SqliteConfig`, including the concurrent-writer repair case.

GitOrigin-RevId: e3946b98bde04c47574532ac8b1a7bb2b03edd97
This commit is contained in:
Adam Perry @ OpenAI authored and copyberry committed 2026-07-18 02:06:13 +00:00
1 parent 23899f7cb6
commit 6bd3f5e3db
14 files changed
+220 -166

No files matched your search

+5 -6
View File
@@ -110,7 +110,6 @@ WHERE id = 1
#[cfg(test)]
mod tests {
use super::StateRuntime;
use super::base_sqlite_options;
use super::test_support::unique_temp_dir;
use chrono::Utc;
use pretty_assertions::assert_eq;
@@ -175,11 +174,11 @@ mod tests {
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string())
.await
.expect("initialize runtime");
let mut write_connection = sqlx::SqliteConnection::connect_with(&base_sqlite_options(
&crate::state_db_path(codex_home.as_path()),
))
.await
.expect("open write connection");
let write_pool = crate::SqliteConfig::new_for_testing(codex_home.clone())
.open_read_write_pool(&crate::state_db_path(codex_home.as_path()))
.await
.expect("open write pool");
let mut write_connection = write_pool.acquire().await.expect("open write connection");
let write_transaction = write_connection
.begin_with("BEGIN IMMEDIATE")
.await
+8 -15
View File
@@ -551,18 +551,14 @@ mod tests {
use pretty_assertions::assert_eq;
use sqlx::SqlitePool;
use sqlx::migrate::Migrator;
use sqlx::sqlite::SqliteConnectOptions;
use std::borrow::Cow;
use std::path::Path;
async fn open_db_pool(path: &Path) -> SqlitePool {
SqlitePool::connect_with(
SqliteConnectOptions::new()
.filename(path)
.create_if_missing(false),
)
.await
.expect("open sqlite pool")
crate::SqliteConfig::new_for_testing(path.parent().unwrap_or(path).to_path_buf())
.open_read_write_pool(path)
.await
.expect("open sqlite pool")
}
async fn log_row_count(path: &Path) -> i64 {
@@ -621,13 +617,10 @@ mod tests {
table_name: LOGS_MIGRATOR.table_name.clone(),
create_schemas: LOGS_MIGRATOR.create_schemas.clone(),
};
let pool = SqlitePool::connect_with(
SqliteConnectOptions::new()
.filename(&logs_path)
.create_if_missing(true),
)
.await
.expect("open old logs db");
let pool = crate::SqliteConfig::new_for_testing(codex_home.clone())
.open_read_write_pool(&logs_path)
.await
.expect("open old logs db");
old_logs_migrator
.run(&pool)
.await
+4 -9
View File
@@ -159,9 +159,7 @@ mod tests {
use crate::migrations::STATE_MIGRATOR;
use crate::state_db_path;
use pretty_assertions::assert_eq;
use sqlx::SqlitePool;
use sqlx::migrate::Migrator;
use sqlx::sqlite::SqliteConnectOptions;
use std::borrow::Cow;
#[tokio::test]
@@ -338,13 +336,10 @@ mod tests {
table_name: STATE_MIGRATOR.table_name.clone(),
create_schemas: STATE_MIGRATOR.create_schemas.clone(),
};
let pool = SqlitePool::connect_with(
SqliteConnectOptions::new()
.filename(state_db_path(codex_home.as_path()))
.create_if_missing(true),
)
.await
.expect("open old state db");
let pool = crate::SqliteConfig::new_for_testing(codex_home.clone())
.open_read_write_pool(&state_db_path(codex_home.as_path()))
.await
.expect("open old state db");
old_state_migrator
.run(&pool)
.await
+1 -1
View File
@@ -27,7 +27,7 @@ use uuid::Uuid;
use crate::ThreadMetadata;
#[cfg(test)]
pub(super) fn unique_temp_dir() -> PathBuf {
pub(crate) fn unique_temp_dir() -> PathBuf {
let nanos = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map_or(0, |duration| duration.as_nanos());