Skip to content

Commit f63f2b6

Browse files
committed
migration-print
1 parent e046c41 commit f63f2b6

File tree

5 files changed

+905
-0
lines changed

5 files changed

+905
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/schema/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ smallvec.workspace = true
3030
hashbrown.workspace = true
3131
enum-as-inner.workspace = true
3232
enum-map.workspace = true
33+
colored.workspace = true
3334

3435
[dev-dependencies]
3536
spacetimedb-lib = { path = "../lib", features = ["test"] }

crates/schema/src/auto_migrate.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use core::{cmp::Ordering, ops::BitOr};
22

33
use crate::{def::*, error::PrettyAlgebraicType, identifier::Identifier};
4+
use ansi_formatter::{AnsiFormatter, ColorScheme};
5+
use formatter::format_plan;
46
use spacetimedb_data_structures::{
57
error_stream::{CollectAllErrors, CombineErrors, ErrorStream},
68
map::HashSet,
@@ -13,6 +15,8 @@ use spacetimedb_sats::{
1315
layout::{HasLayout, SumTypeLayout},
1416
WithTypespace,
1517
};
18+
mod ansi_formatter;
19+
mod formatter;
1620

1721
pub type Result<T> = std::result::Result<T, ErrorStream<AutoMigrateError>>;
1822

@@ -39,6 +43,20 @@ impl<'def> MigratePlan<'def> {
3943
MigratePlan::Auto(plan) => plan.new,
4044
}
4145
}
46+
47+
pub fn pretty_print(&self) -> anyhow::Result<String> {
48+
match self {
49+
MigratePlan::Manual(_) => {
50+
anyhow::bail!("Manual migration plans are not yet supported for pretty printing.")
51+
}
52+
MigratePlan::Auto(plan) => {
53+
let mut fmt = AnsiFormatter::new(1024, ColorScheme::default());
54+
format_plan(&mut fmt, plan)
55+
.map_err(|e| anyhow::anyhow!("Failed to format migration plan: {e}"))
56+
.map(|_| fmt.to_string())
57+
}
58+
}
59+
}
4260
}
4361

4462
/// A plan for a manual migration.

0 commit comments

Comments
 (0)