Skip to content

Commit

Permalink
feat(rust): make sure that reset can not remove postgres data
Browse files Browse the repository at this point in the history
  • Loading branch information
etorreborre committed Jan 10, 2025
1 parent ce286dc commit cddc6b1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions implementations/rust/ockam/ockam_api/src/cli_state/cli_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tokio::sync::broadcast::{channel, Receiver, Sender};

use ockam::SqlxDatabase;
use ockam_core::env::get_env_with_default;
use ockam_node::database::{DatabaseConfiguration, OCKAM_SQLITE_IN_MEMORY};
use ockam_node::database::{DatabaseConfiguration, DatabaseType, OCKAM_SQLITE_IN_MEMORY};
use ockam_node::Executor;

use crate::cli_state::error::Result;
Expand Down Expand Up @@ -136,11 +136,19 @@ impl CliState {
}

/// Stop nodes and remove all the directories storing state
/// Don't touch the database data if Postgres is used and reset was called accidentally.
pub async fn reset(&self) -> Result<()> {
self.delete_all_named_identities().await?;
self.delete_all_nodes().await?;
self.delete_all_named_vaults().await?;
self.delete().await
if Self::make_database_configuration(&self.mode)?.database_type() == DatabaseType::Postgres
{
Err(CliStateError::InvalidOperation(
"Cannot reset the database when using Postgres".to_string(),
))
} else {
self.delete_all_named_identities().await?;
self.delete_all_nodes().await?;
self.delete_all_named_vaults().await?;
self.delete().await
}
}

/// Removes all the directories storing state without loading the current state
Expand All @@ -152,7 +160,6 @@ impl CliState {

/// Delete the local database and log files
pub async fn delete(&self) -> Result<()> {
self.database.drop_postgres_node_tables().await?;
self.delete_local_data()
}

Expand Down

0 comments on commit cddc6b1

Please sign in to comment.