toasty_cli/migration/
snapshot.rs1use super::SnapshotFile;
2use crate::Config;
3use anyhow::Result;
4use clap::Parser;
5use console::style;
6use toasty::Db;
7
8#[derive(Parser, Debug)]
9pub struct SnapshotCommand {
10 }
12
13impl SnapshotCommand {
14 pub(crate) fn run(self, db: &Db, _config: &Config) -> Result<()> {
15 println!();
16 println!(
17 " {}",
18 style("Current Schema Snapshot").cyan().bold().underlined()
19 );
20 println!();
21
22 let snapshot_file = SnapshotFile::new(toasty::schema::db::Schema::clone(&db.schema().db));
23
24 let snapshot_str = snapshot_file.to_string();
26 for line in snapshot_str.lines() {
27 if line.starts_with('[') {
28 println!(" {}", style(line).yellow().bold());
29 } else if line.contains('=') {
30 let parts: Vec<&str> = line.splitn(2, '=').collect();
31 if parts.len() == 2 {
32 println!(
33 " {}{} {}",
34 style(parts[0]).cyan(),
35 style("=").dim(),
36 style(parts[1]).green()
37 );
38 } else {
39 println!(" {}", style(line).dim());
40 }
41 } else if line.trim().is_empty() {
42 println!();
43 } else {
44 println!(" {}", style(line).dim());
45 }
46 }
47
48 println!();
49 Ok(())
50 }
51}