diff --git a/src/core/db/postgres_db.rs b/src/core/db/postgres_db.rs index f466000..5faebc3 100644 --- a/src/core/db/postgres_db.rs +++ b/src/core/db/postgres_db.rs @@ -2530,11 +2530,11 @@ impl PostgresDb { } } - pub async fn register_resource(&self, resource: super::postgres_db::ResourceRecord) -> Result { + pub async fn register_resource(&self, resource: super::postgres_db::ResourceRecord) -> Result<()> { let table = schema::table_name("resources"); - let id: i64 = sqlx::query_scalar(&format!( + sqlx::query(&format!( "INSERT INTO {} (resource_id, resource_type, category, capabilities, config, metadata, status) \ - VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id", table + VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT (resource_id) DO UPDATE SET status = EXCLUDED.status, last_heartbeat = NOW()", table )) .bind(&resource.resource_id) .bind(&resource.resource_type) @@ -2543,8 +2543,8 @@ impl PostgresDb { .bind(&resource.config) .bind(&resource.metadata) .bind("online") - .fetch_one(&self.pool).await?; - Ok(id) + .execute(&self.pool).await?; + Ok(()) } pub async fn heartbeat_resource(&self, resource_id: &str, status: &str) -> Result<()> {