mielin_cli/types/
migration.rs

1//! Migration-related data structures
2
3use crate::output::MultiFormatDisplay;
4use comfy_table::{presets::UTF8_FULL, Cell, Color, ContentArrangement, Table};
5use serde::Serialize;
6
7#[derive(Debug, Serialize)]
8pub struct MigrationEntry {
9    pub id: String,
10    pub agent_id: String,
11    pub source: String,
12    pub target: String,
13    pub status: String,
14    pub started_at: String,
15    pub duration_ms: Option<u64>,
16}
17
18#[derive(Debug, Serialize)]
19pub struct MigrationHistory {
20    pub migrations: Vec<MigrationEntry>,
21    pub total: usize,
22}
23
24impl MultiFormatDisplay for MigrationHistory {
25    fn to_table(&self) -> Table {
26        let mut table = Table::new();
27        table
28            .load_preset(UTF8_FULL)
29            .set_content_arrangement(ContentArrangement::Dynamic)
30            .set_header(vec![
31                Cell::new("ID").fg(Color::Cyan),
32                Cell::new("AGENT").fg(Color::Cyan),
33                Cell::new("SOURCE").fg(Color::Cyan),
34                Cell::new("TARGET").fg(Color::Cyan),
35                Cell::new("STATUS").fg(Color::Cyan),
36                Cell::new("DURATION").fg(Color::Cyan),
37            ]);
38
39        for m in &self.migrations {
40            let status_color = match m.status.as_str() {
41                "Completed" => Color::Green,
42                "Failed" => Color::Red,
43                "InProgress" => Color::Blue,
44                _ => Color::White,
45            };
46
47            let duration = m
48                .duration_ms
49                .map(|d| format!("{}ms", d))
50                .unwrap_or_else(|| "-".to_string());
51
52            table.add_row(vec![
53                Cell::new(&m.id[..8]),
54                Cell::new(&m.agent_id[..8]),
55                Cell::new(&m.source[..8]),
56                Cell::new(&m.target[..8]),
57                Cell::new(&m.status).fg(status_color),
58                Cell::new(duration),
59            ]);
60        }
61
62        table
63    }
64
65    fn to_quiet(&self) -> String {
66        self.migrations
67            .iter()
68            .map(|m| m.id.clone())
69            .collect::<Vec<_>>()
70            .join("\n")
71    }
72}