diff --git a/migra-cli/src/commands/make.rs b/migra-cli/src/commands/make.rs index ec3eed6..96f3ca6 100644 --- a/migra-cli/src/commands/make.rs +++ b/migra-cli/src/commands/make.rs @@ -6,7 +6,8 @@ use std::fs; pub(crate) fn make_migration(app: &App, opts: MakeCommandOpt) -> StdResult<()> { let config = app.config()?; - let now = Local::now().format("%y%m%d%H%M%S"); + let date_format = config.migrations.date_format(); + let formatted_current_timestamp = Local::now().format(&date_format); let migration_name: String = opts .migration_name @@ -18,9 +19,10 @@ pub(crate) fn make_migration(app: &App, opts: MakeCommandOpt) -> StdResult<()> { }) .collect(); - let migration_dir_path = config - .migration_dir_path() - .join(format!("{}_{}", now, migration_name)); + let migration_dir_path = config.migration_dir_path().join(format!( + "{}_{}", + formatted_current_timestamp, migration_name + )); if !migration_dir_path.exists() { fs::create_dir_all(&migration_dir_path)?; } diff --git a/migra-cli/src/config.rs b/migra-cli/src/config.rs index 0631d88..8b20496 100644 --- a/migra-cli/src/config.rs +++ b/migra-cli/src/config.rs @@ -148,6 +148,8 @@ pub(crate) struct MigrationsConfig { #[serde(default = "default_migrations_table_name")] table_name: String, + + date_format: Option, } impl Default for MigrationsConfig { @@ -155,6 +157,7 @@ impl Default for MigrationsConfig { MigrationsConfig { directory: default_migrations_directory(), table_name: default_migrations_table_name(), + date_format: None, } } } @@ -189,6 +192,12 @@ impl MigrationsConfig { self.table_name.clone() } } + + pub fn date_format(&self) -> String { + self.date_format + .clone() + .unwrap_or_else(|| String::from("%y%m%d%H%M%S")) + } } //===========================================================================//