refactor(hive-c0re): shared sqlite open helper with busy timeout

one db::open owns the parent-dir + connection + busy_timeout dance for
every host-side store (broker/approvals/questions/schedules/power in
broker.sqlite, build_logs, audit_log); schema + migrations stay per
store. same-file connections now wait out concurrent writers instead
of risking SQLITE_BUSY.
This commit is contained in:
müde 2026-07-06 20:46:57 +02:00
commit 380c6ad47f
8 changed files with 45 additions and 41 deletions

View file

@ -87,17 +87,7 @@ impl PowerStore {
/// `agent_power` table exists. `db_path` is the same sqlite file
/// the broker / approvals / questions stores open.
pub fn open(db_path: &Path) -> Result<Self> {
if let Some(parent) = db_path.parent() {
std::fs::create_dir_all(parent)
.with_context(|| format!("create agent_power db parent {}", parent.display()))?;
}
let conn = Connection::open(db_path)
.with_context(|| format!("open agent_power db {}", db_path.display()))?;
// Several modules hold their own connection to this file (the
// broker / approvals / questions pattern); wait out a
// concurrent writer instead of surfacing SQLITE_BUSY.
conn.busy_timeout(std::time::Duration::from_secs(5))
.context("set agent_power busy_timeout")?;
let conn = crate::db::open(db_path, "agent_power")?;
conn.execute_batch(SCHEMA)
.context("apply agent_power schema")?;
Ok(Self {