Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
dzlk17 committed Oct 30, 2024
1 parent 3c1359c commit 709b44e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion database/migrations/0002_team.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CREATE TABLE team(
team_id TEXT NOT NULL UNIQUE,
grafana_id TEXT NOT NULL UNIQUE,
grafana_id TEXT UNIQUE,
team_name TEXT NOT NULL,
personal BOOLEAN NOT NULL,
subscription subscription,
Expand Down
16 changes: 0 additions & 16 deletions database/src/tables/registered_app/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,4 @@ impl Db {
.await
.map_err(|e| e.into());
}

pub async fn get_registered_app_by_team_id(
&self,
team_id: &String,
) -> Result<Vec<DbRegisteredApp>, DbError> {
let query = format!(
"SELECT * FROM {REGISTERED_APPS_TABLE_NAME} WHERE team_id = $1 AND deactivated_at IS NULL"
);
let typed_query = query_as::<_, DbRegisteredApp>(&query);

return typed_query
.bind(&team_id)
.fetch_all(&self.connection_pool)
.await
.map_err(|e| e.into());
}
}
12 changes: 12 additions & 0 deletions database/src/tables/team/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ impl Db {
Err(e) => Err(e).map_err(|e| e.into()),
}
}

pub async fn clear_all_grafana_ids(&self) -> Result<(), DbError> {
let query_body =
format!("UPDATE {TEAM_TABLE_NAME} SET grafana_id = NULL WHERE deactivated_at IS NULL",);

let query_result = query(&query_body).execute(&self.connection_pool).await;

match query_result {
Ok(_) => Ok(()),
Err(e) => Err(e).map_err(|e| e.into()),
}
}
}

#[cfg(feature = "cloud_integration_tests")]
Expand Down
6 changes: 5 additions & 1 deletion server/src/bin/grafana_restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ async fn main() {
// Setup template dashboards
import_template_dashboards(&grafana_client_conf).await;

if let Err(err) = db.clear_all_grafana_ids().await {
panic!("Failed to clear grafana ids in database: {:?}", err);
}

let teams = match db.get_all_teams().await {
Ok(teams) => teams,
Err(e) => {
Expand Down Expand Up @@ -84,7 +88,7 @@ async fn main() {
}
};
}
let apps = match db.get_registered_app_by_team_id(&team.team_id).await {
let apps = match db.get_registered_apps_by_team_id(&team.team_id).await {
Ok(apps) => apps,
Err(e) => {
panic!("Failed to get apps. Error: {:?}", e);
Expand Down

0 comments on commit 709b44e

Please sign in to comment.