lmrc-postgres 0.3.16

PostgreSQL management library for the LMRC Stack - comprehensive library for managing PostgreSQL installations on remote servers via SSH
Documentation
//! PostgreSQL uninstallation example
//!
//! This example demonstrates how to uninstall PostgreSQL.

use lmrc_postgres::{PostgresConfig, PostgresManager};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    tracing_subscriber::fmt::init();

    let config = PostgresConfig::builder()
        .version("15")
        .database_name("myapp")
        .username("myuser")
        .password("mypassword")
        .build()?;

    let manager = PostgresManager::builder()
        .config(config)
        .server_ip("192.168.1.100")
        .ssh_user("root")
        .ssh_password("ssh_password")
        .build()?;

    // Check if PostgreSQL is installed
    if manager.is_installed().await? {
        println!("PostgreSQL is installed");

        // Option 1: Uninstall but keep data
        println!("\nOption 1: Uninstall but keep data");
        println!("This will remove PostgreSQL but preserve databases and configuration");
        // manager.uninstall(false).await?;

        // Option 2: Completely remove everything (purge)
        println!("\nOption 2: Completely remove (purge)");
        println!("This will remove PostgreSQL and all data");
        println!("⚠️  WARNING: This will delete all databases!");

        // Uncomment to actually uninstall:
        // manager.uninstall(true).await?;

        println!("\nUninstallation completed successfully!");
    } else {
        println!("PostgreSQL is not installed");
    }

    // Verify uninstallation
    if !manager.is_installed().await? {
        println!("✓ PostgreSQL has been uninstalled");
    }

    Ok(())
}