Skip to main content

spawn_db/commands/migration/
new.rs

1use crate::commands::{Command, Outcome, TelemetryDescribe, TelemetryInfo};
2use crate::config::Config;
3use crate::migrator::Migrator;
4use anyhow::Result;
5
6pub struct NewMigration {
7    pub name: String,
8}
9
10impl TelemetryDescribe for NewMigration {
11    fn telemetry(&self) -> TelemetryInfo {
12        TelemetryInfo::new("migration new")
13    }
14}
15
16impl Command for NewMigration {
17    async fn execute(&self, config: &Config) -> Result<Outcome> {
18        let migration_name = format!(
19            "{}-{}",
20            chrono::Utc::now().format("%Y%m%d%H%M%S"),
21            self.name
22        );
23        println!("creating migration with name {}", &migration_name);
24        let mg = Migrator::new(config, &migration_name, false);
25
26        Ok(Outcome::NewMigration(mg.create_migration().await?))
27    }
28}