From 4a9ece8c021263431137630970dd121f80a6707e Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Fri, 5 Feb 2021 01:46:18 +0300 Subject: [PATCH] chore(cli): move migrations to separate dir --- migra-cli/src/config.rs | 8 +++++++- migra-cli/src/main.rs | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/migra-cli/src/config.rs b/migra-cli/src/config.rs index d87afb1..1a36713 100644 --- a/migra-cli/src/config.rs +++ b/migra-cli/src/config.rs @@ -95,9 +95,15 @@ impl Config { .build() } + pub fn migration_dir_path(&self) -> PathBuf { + PathBuilder::from(&self.directory_path()) + .append("migrations") + .build() + } + pub fn migration_dirs(&self) -> io::Result> { let mut entries = self - .directory_path() + .migration_dir_path() .read_dir()? .map(|res| res.map(|e| e.path())) .collect::, io::Error>>()?; diff --git a/migra-cli/src/main.rs b/migra-cli/src/main.rs index 3782944..317dd65 100644 --- a/migra-cli/src/main.rs +++ b/migra-cli/src/main.rs @@ -53,11 +53,11 @@ fn main() -> Result<(), Box> { }) .collect(); - let migration_dir_path = PathBuilder::from(config.directory_path()) + let migration_dir_path = PathBuilder::from(config.migration_dir_path()) .append(format!("{}_{}", now, migration_name)) .build(); if !migration_dir_path.exists() { - fs::create_dir(&migration_dir_path)?; + fs::create_dir_all(&migration_dir_path)?; } let upgrade_migration_path = PathBuilder::from(&migration_dir_path)