2021-02-13 00:39:39 +03:00
|
|
|
use crate::config::Config;
|
2021-02-15 13:06:09 +03:00
|
|
|
use crate::migration::{DatabaseMigrationManager, MigrationManager};
|
2021-02-13 00:39:39 +03:00
|
|
|
use crate::opts::ApplyCommandOpt;
|
|
|
|
use crate::path::PathBuilder;
|
|
|
|
use crate::StdResult;
|
2021-02-13 23:44:41 +03:00
|
|
|
use std::convert::TryFrom;
|
2021-02-13 00:39:39 +03:00
|
|
|
|
|
|
|
pub(crate) fn apply_sql(config: Config, opts: ApplyCommandOpt) -> StdResult<()> {
|
2021-02-18 12:29:09 +03:00
|
|
|
let mut manager = MigrationManager::try_from(&config)?;
|
2021-02-13 00:39:39 +03:00
|
|
|
|
|
|
|
let file_path = PathBuilder::from(config.directory_path())
|
|
|
|
.append(opts.file_name)
|
|
|
|
.default_extension("sql")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let content = std::fs::read_to_string(file_path)?;
|
|
|
|
|
2021-02-15 13:06:09 +03:00
|
|
|
match manager.apply_sql(&content) {
|
2021-02-13 00:39:39 +03:00
|
|
|
Ok(_) => {
|
|
|
|
println!("File was applied successfully");
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
println!("{}", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|