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
|
|
|
|
2021-03-26 02:10:41 +03:00
|
|
|
#[macro_use]
|
|
|
|
extern crate cfg_if;
|
|
|
|
|
|
|
|
#[cfg(not(any(feature = "postgres", feature = "mysql")))]
|
|
|
|
compile_error!(r#"Either features "postgres" or "mysql" must be enabled for "migra" crate"#);
|
|
|
|
|
2021-02-13 00:39:39 +03:00
|
|
|
mod commands;
|
2021-01-31 03:23:43 +03:00
|
|
|
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
|
|
|
|
2021-02-13 00:39:39 +03:00
|
|
|
use crate::error::StdResult;
|
2021-01-31 03:23:43 +03:00
|
|
|
use config::Config;
|
2021-02-13 00:39:39 +03:00
|
|
|
use opts::{AppOpt, Command, StructOpt};
|
2021-02-23 18:16:26 +03:00
|
|
|
use std::io;
|
2021-01-31 02:38:35 +03:00
|
|
|
|
2021-02-13 00:39:39 +03:00
|
|
|
fn main() -> StdResult<()> {
|
2021-02-26 01:21:29 +03:00
|
|
|
#[cfg(feature = "dotenv")]
|
|
|
|
dotenv::dotenv().ok();
|
|
|
|
|
2021-01-31 02:38:35 +03:00
|
|
|
let opt = AppOpt::from_args();
|
2021-01-31 03:23:43 +03:00
|
|
|
|
2021-02-02 00:53:33 +03:00
|
|
|
match opt.command {
|
|
|
|
Command::Init => {
|
2021-02-13 00:39:39 +03:00
|
|
|
commands::initialize_migra_manifest(opt.config)?;
|
2021-02-01 23:51:23 +03:00
|
|
|
}
|
2021-02-13 00:39:39 +03:00
|
|
|
Command::Apply(opts) => {
|
2021-02-02 00:53:33 +03:00
|
|
|
let config = Config::read(opt.config)?;
|
2021-02-13 00:39:39 +03:00
|
|
|
commands::apply_sql(config, opts)?;
|
2021-01-31 02:38:35 +03:00
|
|
|
}
|
2021-02-13 00:39:39 +03:00
|
|
|
Command::Make(opts) => {
|
2021-02-03 01:03:56 +03:00
|
|
|
let config = Config::read(opt.config)?;
|
2021-02-13 00:39:39 +03:00
|
|
|
commands::make_migration(config, opts)?;
|
2021-02-03 01:03:56 +03:00
|
|
|
}
|
2021-02-02 23:50:42 +03:00
|
|
|
Command::List => {
|
|
|
|
let config = Config::read(opt.config)?;
|
2021-02-13 00:39:39 +03:00
|
|
|
commands::print_migration_lists(config)?;
|
2021-02-02 23:50:42 +03:00
|
|
|
}
|
2021-02-25 00:47:13 +03:00
|
|
|
Command::Upgrade(opts) => {
|
2021-02-06 01:22:00 +03:00
|
|
|
let config = Config::read(opt.config)?;
|
2021-02-25 00:47:13 +03:00
|
|
|
commands::upgrade_pending_migrations(config, opts)?;
|
2021-02-06 01:22:00 +03:00
|
|
|
}
|
2021-02-25 00:03:51 +03:00
|
|
|
Command::Downgrade(opts) => {
|
2021-02-06 01:37:30 +03:00
|
|
|
let config = Config::read(opt.config)?;
|
2021-02-25 00:03:51 +03:00
|
|
|
commands::rollback_applied_migrations(config, opts)?;
|
2021-02-02 00:53:33 +03:00
|
|
|
}
|
2021-02-23 18:16:26 +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
|
|
|
}
|
2021-01-31 03:23:43 +03:00
|
|
|
|
|
|
|
Ok(())
|
2021-01-31 02:38:35 +03:00
|
|
|
}
|