chore(cli): move migrations to separate dir

This commit is contained in:
Dmitriy Pleshevskiy 2021-02-05 01:46:18 +03:00
parent e8cce2fca5
commit 4a9ece8c02
2 changed files with 9 additions and 3 deletions

View File

@ -95,9 +95,15 @@ impl Config {
.build() .build()
} }
pub fn migration_dir_path(&self) -> PathBuf {
PathBuilder::from(&self.directory_path())
.append("migrations")
.build()
}
pub fn migration_dirs(&self) -> io::Result<Vec<PathBuf>> { pub fn migration_dirs(&self) -> io::Result<Vec<PathBuf>> {
let mut entries = self let mut entries = self
.directory_path() .migration_dir_path()
.read_dir()? .read_dir()?
.map(|res| res.map(|e| e.path())) .map(|res| res.map(|e| e.path()))
.collect::<Result<Vec<_>, io::Error>>()?; .collect::<Result<Vec<_>, io::Error>>()?;

View File

@ -53,11 +53,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}) })
.collect(); .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)) .append(format!("{}_{}", now, migration_name))
.build(); .build();
if !migration_dir_path.exists() { 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) let upgrade_migration_path = PathBuilder::from(&migration_dir_path)