Add organization/site/tags support for machine grouping
- Added organization, site, tags columns to connect_machines table - Agent now sends org/site/tags from embedded config in AgentStatus - Server stores org/site/tags metadata in database - Enables grouping machines by client/site/tag in dashboard
This commit is contained in:
@@ -116,3 +116,34 @@ pub async fn delete_machine(pool: &PgPool, agent_id: &str) -> Result<(), sqlx::E
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Update machine organization, site, and tags
|
||||
pub async fn update_machine_metadata(
|
||||
pool: &PgPool,
|
||||
agent_id: &str,
|
||||
organization: Option<&str>,
|
||||
site: Option<&str>,
|
||||
tags: &[String],
|
||||
) -> Result<(), sqlx::Error> {
|
||||
// Only update if at least one value is provided
|
||||
if organization.is_none() && site.is_none() && tags.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
sqlx::query(
|
||||
r#"
|
||||
UPDATE connect_machines SET
|
||||
organization = COALESCE($1, organization),
|
||||
site = COALESCE($2, site),
|
||||
tags = CASE WHEN $3::text[] = '{}' THEN tags ELSE $3 END
|
||||
WHERE agent_id = $4
|
||||
"#,
|
||||
)
|
||||
.bind(organization)
|
||||
.bind(site)
|
||||
.bind(tags)
|
||||
.bind(agent_id)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user