feat: add date format option
This commit is contained in:
parent
11874bd8a4
commit
def6534fd1
2 changed files with 15 additions and 4 deletions
|
@ -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)?;
|
||||
}
|
||||
|
|
|
@ -148,6 +148,8 @@ pub(crate) struct MigrationsConfig {
|
|||
|
||||
#[serde(default = "default_migrations_table_name")]
|
||||
table_name: String,
|
||||
|
||||
date_format: Option<String>,
|
||||
}
|
||||
|
||||
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"))
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================//
|
||||
|
|
Reference in a new issue