spawn_db/commands/migration/
build.rs1use crate::commands::{Command, Outcome, TelemetryDescribe, TelemetryInfo};
2use crate::config::Config;
3use crate::migrator::Migrator;
4use crate::variables::Variables;
5use anyhow::Result;
6
7pub struct BuildMigration {
8 pub migration: String,
9 pub pinned: bool,
10 pub variables: Option<Variables>,
11}
12
13impl TelemetryDescribe for BuildMigration {
14 fn telemetry(&self) -> TelemetryInfo {
15 TelemetryInfo::new("migration build").with_properties(vec![
16 ("opt_pinned", self.pinned.to_string()),
17 ("has_variables", self.variables.is_some().to_string()),
18 ])
19 }
20}
21
22impl Command for BuildMigration {
23 async fn execute(&self, config: &Config) -> Result<Outcome> {
24 let mgrtr = Migrator::new(config, &self.migration, self.pinned);
25 match mgrtr.generate_streaming(self.variables.clone()).await {
26 Ok(gen) => {
27 let mut buffer = Vec::new();
28 gen.render_to_writer(&mut buffer)
29 .map_err(std::io::Error::other)?;
30 let content = String::from_utf8(buffer)?;
31 Ok(Outcome::BuiltMigration { content })
32 }
33 Err(e) => Err(e),
34 }
35 }
36}