spawn_db/commands/migration/
pin.rs1use crate::commands::{Command, Outcome, TelemetryDescribe, TelemetryInfo};
2use crate::config::Config;
3use crate::pinfile::LockData;
4use crate::store::pinner::spawn::Spawn;
5use crate::store::pinner::Pinner;
6use anyhow::{Context, Result};
7
8pub struct PinMigration {
9 pub migration: String,
10}
11
12impl TelemetryDescribe for PinMigration {
13 fn telemetry(&self) -> TelemetryInfo {
14 TelemetryInfo::new("migration pin")
15 }
16}
17
18impl Command for PinMigration {
19 async fn execute(&self, config: &Config) -> Result<Outcome> {
20 let mut pinner = Spawn::new(
21 config.pather().pinned_folder(),
22 config.pather().components_folder(),
23 )
24 .context("could not get pinned_folder")?;
25
26 let root = pinner
27 .snapshot(config.operator())
28 .await
29 .context("error calling pinner snapshot")?;
30
31 let lock_file_path = config.pather().migration_lock_file_path(&self.migration);
32 let toml_str = toml::to_string_pretty(&LockData { pin: root.clone() })
33 .context("could not not convert pin data to toml")?;
34
35 config
36 .operator()
37 .write(&lock_file_path, toml_str)
38 .await
39 .context("failed writing migration lockfile")?;
40
41 Ok(Outcome::PinnedMigration { hash: root })
42 }
43}