mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:19:04 +00:00
Centralize SQLite connection configuration (#34808)
## What changed - Add `SqliteConfig` to own the resolved SQLite home, runtime database paths, and shared read/write and read-only pool settings. - Pass the configuration through state and local thread-store consumers, replacing standalone path helpers and duplicated connection setup. GitOrigin-RevId: 7351b08da94b5c8b6c0bbe492f86aeeca0699d3c
This commit is contained in:
1 parent
a59a419afa
commit
946ed315a4
35 files changed
+445
-397
No files matched your search
@@ -175,8 +175,9 @@ mod tests {
|
||||
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string())
|
||||
.await
|
||||
.expect("initialize runtime");
|
||||
let write_pool = crate::SqliteConfig::new_for_testing(codex_home.as_path().abs())
|
||||
.open_read_write_pool(&crate::state_db_path(codex_home.as_path()))
|
||||
let sqlite = crate::SqliteConfig::new_for_testing(codex_home.as_path().abs());
|
||||
let write_pool = sqlite
|
||||
.open_read_write_pool(&sqlite.state_db_path())
|
||||
.await
|
||||
.expect("open write pool");
|
||||
let mut write_connection = write_pool.acquire().await.expect("open write connection");
|
||||
|
||||
@@ -545,7 +545,6 @@ mod tests {
|
||||
use super::test_support::unique_temp_dir;
|
||||
use crate::LogEntry;
|
||||
use crate::LogQuery;
|
||||
use crate::logs_db_path;
|
||||
use crate::migrations::LOGS_MIGRATOR;
|
||||
use chrono::Utc;
|
||||
use codex_utils_absolute_path::test_support::PathExt;
|
||||
@@ -596,7 +595,9 @@ mod tests {
|
||||
.await
|
||||
.expect("insert test logs");
|
||||
|
||||
let logs_count = log_row_count(logs_db_path(codex_home.as_path()).as_path()).await;
|
||||
let logs_path =
|
||||
crate::SqliteConfig::new_for_testing(codex_home.as_path().abs()).logs_db_path();
|
||||
let logs_count = log_row_count(logs_path.as_path()).await;
|
||||
|
||||
assert_eq!(logs_count, 1);
|
||||
|
||||
@@ -609,7 +610,8 @@ mod tests {
|
||||
tokio::fs::create_dir_all(&codex_home)
|
||||
.await
|
||||
.expect("create codex home");
|
||||
let logs_path = logs_db_path(codex_home.as_path());
|
||||
let logs_path =
|
||||
crate::SqliteConfig::new_for_testing(codex_home.as_path().abs()).logs_db_path();
|
||||
let old_logs_migrator = Migrator {
|
||||
migrations: Cow::Owned(vec![LOGS_MIGRATOR.migrations[0].clone()]),
|
||||
ignore_missing: false,
|
||||
@@ -706,7 +708,9 @@ mod tests {
|
||||
.await
|
||||
.expect("initialize runtime");
|
||||
|
||||
let pool = open_db_pool(logs_db_path(codex_home.as_path()).as_path()).await;
|
||||
let logs_path =
|
||||
crate::SqliteConfig::new_for_testing(codex_home.as_path().abs()).logs_db_path();
|
||||
let pool = open_db_pool(logs_path.as_path()).await;
|
||||
let auto_vacuum = sqlx::query_scalar::<_, i64>("PRAGMA auto_vacuum")
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
use super::*;
|
||||
use crate::runtime::test_support::unique_temp_dir;
|
||||
use codex_utils_absolute_path::test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn backup_moves_only_requested_runtime_db_files_to_backup_folder() -> std::io::Result<()> {
|
||||
let sqlite_home = unique_temp_dir();
|
||||
tokio::fs::create_dir_all(sqlite_home.as_path()).await?;
|
||||
let runtime_paths = super::super::runtime_db_paths(sqlite_home.as_path());
|
||||
let sqlite = crate::SqliteConfig::new_for_testing(sqlite_home.as_path().abs());
|
||||
let runtime_paths = sqlite.runtime_db_paths();
|
||||
let mut expected_paths = Vec::new();
|
||||
for db_path in runtime_paths.iter().map(|db| db.path.as_path()) {
|
||||
for path in sqlite_paths(db_path) {
|
||||
@@ -14,7 +16,7 @@ async fn backup_moves_only_requested_runtime_db_files_to_backup_folder() -> std:
|
||||
expected_paths.push(path);
|
||||
}
|
||||
}
|
||||
let failed_db_path = super::super::logs_db_path(sqlite_home.as_path());
|
||||
let failed_db_path = sqlite.logs_db_path();
|
||||
let failed_paths = sqlite_paths(failed_db_path.as_path());
|
||||
|
||||
let backups = backup_runtime_db_for_fresh_start(failed_db_path.as_path()).await?;
|
||||
@@ -48,7 +50,9 @@ async fn backup_replaces_blocking_sqlite_home_file() -> std::io::Result<()> {
|
||||
tokio::fs::write(sqlite_home.as_path(), b"not-a-directory").await?;
|
||||
|
||||
let backups = backup_runtime_db_for_fresh_start(
|
||||
super::super::state_db_path(sqlite_home.as_path()).as_path(),
|
||||
crate::SqliteConfig::new_for_testing(sqlite_home.as_path().abs())
|
||||
.state_db_path()
|
||||
.as_path(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -79,7 +83,7 @@ async fn runtime_db_path_for_corruption_error_returns_failed_database_path() ->
|
||||
{
|
||||
let sqlite_home = unique_temp_dir();
|
||||
tokio::fs::create_dir_all(sqlite_home.as_path()).await?;
|
||||
let path = super::super::state_db_path(sqlite_home.as_path());
|
||||
let path = crate::SqliteConfig::new_for_testing(sqlite_home.as_path().abs()).state_db_path();
|
||||
tokio::fs::write(path.as_path(), b"not sqlite").await?;
|
||||
|
||||
let err = match super::super::StateRuntime::init(sqlite_home, "openai".to_string()).await {
|
||||
|
||||
@@ -157,7 +157,6 @@ mod tests {
|
||||
use super::StateRuntime;
|
||||
use super::test_support::unique_temp_dir;
|
||||
use crate::migrations::STATE_MIGRATOR;
|
||||
use crate::state_db_path;
|
||||
use codex_utils_absolute_path::test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use sqlx::migrate::Migrator;
|
||||
@@ -344,8 +343,9 @@ mod tests {
|
||||
table_name: STATE_MIGRATOR.table_name.clone(),
|
||||
create_schemas: STATE_MIGRATOR.create_schemas.clone(),
|
||||
};
|
||||
let pool = crate::SqliteConfig::new_for_testing(codex_home.as_path().abs())
|
||||
.open_read_write_pool(&state_db_path(codex_home.as_path()))
|
||||
let sqlite = crate::SqliteConfig::new_for_testing(codex_home.as_path().abs());
|
||||
let pool = sqlite
|
||||
.open_read_write_pool(&sqlite.state_db_path())
|
||||
.await
|
||||
.expect("open old state db");
|
||||
old_state_migrator
|
||||
|
||||
Reference in new issue
Block a user