fix(updates): auto-continue client upgrade on update-all

This commit is contained in:
zipg authored and GitHub committed 2026-09-23 14:43:14 +08:00
1 parent 6471e37e5f
commit da95bd435f
10 files changed
+200 -61

No files matched your search

+20 -10
View File
@@ -53,6 +53,7 @@ pub struct AgentUpdateBlockersRequest {
pub struct AgentUpdateBlocker {
pub db_type: String,
pub label: String,
pub connections: Vec<String>,
}
#[derive(Deserialize)]
@@ -407,32 +408,37 @@ async fn ensure_no_agent_update_blockers(
state: &dbx_core::connection::AppState,
db_types: &[String],
) -> Result<(), String> {
let blockers = update_blockers_from_keys(state.prepare_agent_driver_updates(db_types).await, db_types);
let blockers = update_blockers_from_connections(state.prepare_agent_driver_updates(db_types).await, db_types);
if blockers.is_empty() {
return Ok(());
}
let labels = blockers.into_iter().map(|blocker| blocker.label).collect::<Vec<_>>().join(", ");
let labels = blockers
.into_iter()
.flat_map(|blocker| if blocker.connections.is_empty() { vec![blocker.label] } else { blocker.connections })
.collect::<Vec<_>>()
.join(", ");
Err(format!("Close these database connections before updating drivers: {labels}"))
}
async fn agent_update_blockers(state: &dbx_core::connection::AppState, db_types: &[String]) -> Vec<AgentUpdateBlocker> {
update_blockers_from_keys(state.active_agent_connection_driver_keys().await, db_types)
update_blockers_from_connections(state.active_agent_connection_driver_connections().await, db_types)
}
fn update_blockers_from_keys(
active_keys: std::collections::HashSet<String>,
fn update_blockers_from_connections(
active_connections: std::collections::HashMap<String, Vec<String>>,
db_types: &[String],
) -> Vec<AgentUpdateBlocker> {
let candidate_keys: std::collections::HashSet<&str> = db_types.iter().map(String::as_str).collect();
if candidate_keys.is_empty() {
return Vec::new();
}
let mut blockers = active_keys
let mut blockers = active_connections
.into_iter()
.filter(|key| candidate_keys.contains(key.as_str()))
.map(|db_type| AgentUpdateBlocker {
.filter(|(key, _)| candidate_keys.contains(key.as_str()))
.map(|(db_type, connections)| AgentUpdateBlocker {
label: dbx_core::agent_catalog::label_for_key(&db_type).unwrap_or(&db_type).to_string(),
db_type,
connections,
})
.collect::<Vec<_>>();
blockers.sort_by(|left, right| left.label.cmp(&right.label));
@@ -472,12 +478,16 @@ mod tests {
#[test]
fn update_blockers_include_active_duckdb_connections() {
let active_keys = ["duckdb".to_string(), "oracle".to_string()].into_iter().collect();
let blockers = update_blockers_from_keys(active_keys, &["duckdb".to_string()]);
let active_connections = std::collections::HashMap::from([
("duckdb".to_string(), vec!["本地分析".to_string()]),
("oracle".to_string(), vec!["生产 Oracle".to_string()]),
]);
let blockers = update_blockers_from_connections(active_connections, &["duckdb".to_string()]);
assert_eq!(blockers.len(), 1);
assert_eq!(blockers[0].db_type, "duckdb");
assert_eq!(blockers[0].label, "DuckDB");
assert_eq!(blockers[0].connections, vec!["本地分析"]);
}
#[test]