migra/migra-cli/src/main.rs

53 lines
1.4 KiB
Rust
Raw Normal View History

2021-01-31 02:38:35 +03:00
#![deny(clippy::all)]
2021-02-21 18:22:00 +03:00
#![forbid(unsafe_code)]
2021-01-31 02:38:35 +03:00
mod commands;
mod config;
2021-02-05 01:37:25 +03:00
mod database;
2021-02-10 01:13:27 +03:00
mod error;
2021-01-31 02:54:23 +03:00
mod opts;
2021-01-31 02:38:35 +03:00
use crate::error::StdResult;
use config::Config;
use opts::{AppOpt, Command, StructOpt};
use std::io;
2021-01-31 02:38:35 +03:00
fn main() -> StdResult<()> {
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 => {
commands::initialize_migra_manifest(opt.config)?;
}
Command::Apply(opts) => {
2021-02-02 00:53:33 +03:00
let config = Config::read(opt.config)?;
commands::apply_sql(config, opts)?;
2021-01-31 02:38:35 +03:00
}
Command::Make(opts) => {
let config = Config::read(opt.config)?;
commands::make_migration(config, opts)?;
}
Command::List => {
let config = Config::read(opt.config)?;
commands::print_migration_lists(config)?;
}
Command::Upgrade(opts) => {
let config = Config::read(opt.config)?;
commands::upgrade_pending_migrations(config, opts)?;
}
Command::Downgrade(opts) => {
let config = Config::read(opt.config)?;
commands::rollback_applied_migrations(config, opts)?;
2021-02-02 00:53:33 +03:00
}
Command::Completions(opts) => {
AppOpt::clap().gen_completions_to(
env!("CARGO_BIN_NAME"),
opts.into(),
&mut io::stdout(),
);
}
2021-01-31 02:38:35 +03:00
}
Ok(())
2021-01-31 02:38:35 +03:00
}