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)]
14pub struct SnapshotCommand {
15 }
17
18impl SnapshotCommand {
19 pub(crate) fn run(self, db: &Db, _config: &Config) -> Result<()> {
20 println!();
21 println!(
22 " {}",
23 style("Current Schema Snapshot").cyan().bold().underlined()
24 );
25 println!();
26
27 let snapshot_file = SnapshotFile::new(toasty::schema::db::Schema::clone(&db.schema().db));
28
29 let snapshot_str = snapshot_file.to_string();
31 for line in snapshot_str.lines() {
32 if line.starts_with('[') {
33 println!(" {}", style(line).yellow().bold());
34 } else if line.contains('=') {
35 let parts: Vec<&str> = line.splitn(2, '=').collect();
36 if parts.len() == 2 {
37 println!(
38 " {}{} {}",
39 style(parts[0]).cyan(),
40 style("=").dim(),
41 style(parts[1]).green()
42 );
43 } else {
44 println!(" {}", style(line).dim());
45 }
46 } else if line.trim().is_empty() {
47 println!();
48 } else {
49 println!(" {}", style(line).dim());
50 }
51 }
52
53 println!();
54 Ok(())
55 }
56}