Skip to main content

patchworks/ui/
schema_diff.rs

1//! Schema diff tree rendering.
2
3use egui::{Color32, RichText, Ui};
4
5use crate::db::types::SchemaDiff;
6
7/// Renders schema diff results.
8pub fn render_schema_diff(ui: &mut Ui, schema_diff: &SchemaDiff) {
9    ui.heading("Schema Diff");
10
11    for table in &schema_diff.added_tables {
12        egui::CollapsingHeader::new(
13            RichText::new(format!("+ {}", table.name)).color(Color32::GREEN),
14        )
15        .default_open(true)
16        .show(ui, |ui| {
17            for column in &table.columns {
18                ui.colored_label(
19                    Color32::GREEN,
20                    format!("+ {} {}", column.name, column.col_type),
21                );
22            }
23        });
24    }
25
26    for table in &schema_diff.removed_tables {
27        egui::CollapsingHeader::new(RichText::new(format!("- {}", table.name)).color(Color32::RED))
28            .default_open(true)
29            .show(ui, |ui| {
30                for column in &table.columns {
31                    ui.colored_label(
32                        Color32::RED,
33                        format!("- {} {}", column.name, column.col_type),
34                    );
35                }
36            });
37    }
38
39    for table in &schema_diff.modified_tables {
40        egui::CollapsingHeader::new(
41            RichText::new(format!("~ {}", table.table_name)).color(Color32::YELLOW),
42        )
43        .default_open(true)
44        .show(ui, |ui| {
45            for column in &table.added_columns {
46                ui.colored_label(
47                    Color32::GREEN,
48                    format!("+ {} {}", column.name, column.col_type),
49                );
50            }
51            for column in &table.removed_columns {
52                ui.colored_label(
53                    Color32::RED,
54                    format!("- {} {}", column.name, column.col_type),
55                );
56            }
57            for (left, right) in &table.modified_columns {
58                ui.colored_label(
59                    Color32::YELLOW,
60                    format!("~ {}: {} -> {}", left.name, left.col_type, right.col_type),
61                );
62            }
63        });
64    }
65
66    if !schema_diff.unchanged_tables.is_empty() {
67        ui.separator();
68        ui.label(RichText::new("Unchanged").strong());
69        for table in &schema_diff.unchanged_tables {
70            ui.label(table);
71        }
72    }
73}