db_migrate/commands/
create.rs1use crate::{migration::MigrationManager, CommandOutput};
2use anyhow::Result;
3use clap::Args;
4use colored::*;
5
6#[derive(Args)]
7pub struct CreateCommand {
8 description: String,
10}
11
12impl CreateCommand {
13 pub async fn execute(&self, manager: &MigrationManager) -> Result<CommandOutput> {
14 if self.description.trim().is_empty() {
16 return Ok(CommandOutput::error("Migration description cannot be empty"));
17 }
18
19 let file_path = manager.create_migration_file(&self.description).await?;
21
22 let filename = file_path
23 .file_name()
24 .and_then(|n| n.to_str())
25 .unwrap_or("unknown");
26
27 let message = format!(
28 "{} Created migration file: {}",
29 "✅".green(),
30 filename.bright_cyan()
31 );
32
33 Ok(CommandOutput::success_with_data(
34 message,
35 serde_json::json!({
36 "file_path": file_path.to_string_lossy(),
37 "filename": filename
38 })
39 ))
40 }
41}