|
1 | | -use clap::{crate_authors, crate_version, value_parser, Arg, Command}; |
| 1 | +use clap::{crate_authors, crate_version, value_parser, Arg, ArgAction, Command}; |
2 | 2 | use dialoguer::{console::Term, theme::ColorfulTheme, Input, MultiSelect, Password, Select}; |
3 | 3 | use dotenv::dotenv; |
4 | 4 | use std::env; |
5 | 5 | use thoth::api::account::model::{AccountData, LinkedPublisher}; |
6 | 6 | use thoth::api::account::service::{all_emails, all_publishers, register, update_password}; |
7 | | -use thoth::api::db::{establish_connection, run_migrations}; |
| 7 | +use thoth::api::db::{establish_connection, revert_migrations, run_migrations}; |
8 | 8 | use thoth::api_server; |
9 | 9 | use thoth::app_server; |
10 | 10 | use thoth::export_server; |
@@ -129,7 +129,16 @@ fn thoth_commands() -> Command { |
129 | 129 | .about(env!("CARGO_PKG_DESCRIPTION")) |
130 | 130 | .subcommand_required(true) |
131 | 131 | .arg_required_else_help(true) |
132 | | - .subcommand(Command::new("migrate").about("Run the database migrations")) |
| 132 | + .subcommand( |
| 133 | + Command::new("migrate") |
| 134 | + .about("Run the database migrations") |
| 135 | + .arg( |
| 136 | + Arg::new("revert") |
| 137 | + .long("revert") |
| 138 | + .help("Revert all database migrations") |
| 139 | + .action(ArgAction::SetTrue), |
| 140 | + ), |
| 141 | + ) |
133 | 142 | .subcommand( |
134 | 143 | Command::new("start") |
135 | 144 | .about("Start an instance of Thoth API or GUI") |
@@ -240,7 +249,10 @@ fn main() -> ThothResult<()> { |
240 | 249 | } |
241 | 250 | _ => unreachable!(), |
242 | 251 | }, |
243 | | - Some(("migrate", _)) => run_migrations(), |
| 252 | + Some(("migrate", migrate_matches)) => match migrate_matches.get_flag("revert") { |
| 253 | + true => revert_migrations(), |
| 254 | + false => run_migrations(), |
| 255 | + }, |
244 | 256 | Some(("init", init_matches)) => { |
245 | 257 | let host = init_matches.get_one::<String>("host").unwrap().to_owned(); |
246 | 258 | let port = init_matches.get_one::<String>("port").unwrap().to_owned(); |
|
0 commit comments