migra/migra-cli/src/main.rs

46 lines
1.2 KiB
Rust
Raw Normal View History

2021-01-31 02:38:35 +03:00
#![deny(clippy::all)]
mod config;
2021-01-31 02:54:23 +03:00
mod opts;
2021-01-31 02:38:35 +03:00
use config::Config;
2021-02-02 00:53:33 +03:00
use opts::{AppOpt, ApplyCommandOpt, Command, StructOpt};
use std::fs;
2021-01-31 02:38:35 +03:00
fn main() -> Result<(), Box<dyn std::error::Error>> {
2021-01-31 02:38:35 +03:00
let opt = AppOpt::from_args();
2021-02-02 00:53:33 +03:00
match opt.command {
Command::Init => {
Config::initialize()?;
}
2021-02-02 00:53:33 +03:00
Command::Apply(ApplyCommandOpt { file_name }) => {
let config = Config::read(opt.config)?;
let mut client = migra_core::database::connect(&config.database.connection)?;
let file_path = migra_core::path::PathBuilder::from(config.root)
.append(config.directory)
.append(file_name)
.default_extension("sql")
.build();
let content = fs::read_to_string(file_path)?;
match migra_core::database::apply_sql(&mut client, &content) {
Ok(_) => {
println!("File was applied successfully")
}
Err(err) => {
println!("{}", err)
}
}
2021-01-31 02:38:35 +03:00
}
2021-02-02 00:55:41 +03:00
Command::List | Command::Upgrade | Command::Downgrade => {
2021-02-02 00:53:33 +03:00
unimplemented!();
}
2021-01-31 02:38:35 +03:00
}
Ok(())
2021-01-31 02:38:35 +03:00
}