diff --git a/sea-orm-migration/Cargo.toml b/sea-orm-migration/Cargo.toml index ead55d5eaf..bffacc1e35 100644 --- a/sea-orm-migration/Cargo.toml +++ b/sea-orm-migration/Cargo.toml @@ -20,7 +20,7 @@ path = "src/lib.rs" [dependencies] async-std = { version = "^1", features = ["attributes", "tokio1"] } async-trait = { version = "^0.1" } -clap = { version = "^2.33" } +clap = { version = "^3.1.17", features = ["env"] } dotenv = { version = "^0.15" } sea-orm = { version = "^0.8.0", path = "../", default-features = false, features = ["macros"] } sea-orm-cli = { version = "^0.8.0", path = "../sea-orm-cli", default-features = false } diff --git a/sea-orm-migration/src/cli.rs b/sea-orm-migration/src/cli.rs index c00e4824e9..ae2a9f1099 100644 --- a/sea-orm-migration/src/cli.rs +++ b/sea-orm-migration/src/cli.rs @@ -1,4 +1,4 @@ -use clap::App; +use clap::Command; use dotenv::dotenv; use std::{fmt::Display, process::exit}; use tracing_subscriber::{prelude::*, EnvFilter}; @@ -19,21 +19,21 @@ where get_matches(migrator, db, app).await; } -pub async fn get_matches(_: M, db: &DbConn, app: App<'static, 'static>) +pub async fn get_matches(_: M, db: &DbConn, app: Command<'static>) where M: MigratorTrait, { let matches = app.get_matches(); let mut verbose = false; let filter = match matches.subcommand() { - (_, None) => "sea_schema::migration=info", - (_, Some(args)) => match args.is_present("VERBOSE") { + Some((_, args)) => match args.is_present("VERBOSE") { true => { verbose = true; "debug" } false => "sea_schema::migration=info", }, + None => "sea_schema::migration=info", }; let filter_layer = EnvFilter::try_new(filter).unwrap(); if verbose { @@ -53,23 +53,30 @@ where .init() }; match matches.subcommand() { - ("fresh", _) => M::fresh(db).await, - ("refresh", _) => M::refresh(db).await, - ("reset", _) => M::reset(db).await, - ("status", _) => M::status(db).await, - ("up", None) => M::up(db, None).await, - ("down", None) => M::down(db, Some(1)).await, - ("up", Some(args)) => { - let str = args.value_of("NUM_MIGRATION").unwrap_or_default(); - let steps = str.parse().ok(); - M::up(db, steps).await - } - ("down", Some(args)) => { - let str = args.value_of("NUM_MIGRATION").unwrap(); - let steps = str.parse().ok().unwrap_or(1); - M::down(db, Some(steps)).await - } - _ => M::up(db, None).await, + Some((cmd, args)) => match cmd { + "fresh" => M::fresh(db).await, + "refresh" => M::refresh(db).await, + "reset" => M::reset(db).await, + "status" => M::status(db).await, + "up" => match args.subcommand() { + Some(_) => { + let str = args.value_of("NUM_MIGRATION").unwrap_or_default(); + let steps = str.parse().ok(); + M::up(db, steps).await + } + None => M::up(db, None).await, + }, + "down" => match args.subcommand() { + Some(_) => { + let str = args.value_of("NUM_MIGRATION").unwrap(); + let steps = str.parse().ok().unwrap_or(1); + M::down(db, Some(steps)).await + } + None => M::down(db, Some(1)).await, + }, + _ => M::up(db, None).await, + }, + None => M::up(db, None).await, } .unwrap_or_else(handle_error); } diff --git a/sea-orm-migration/src/manager.rs b/sea-orm-migration/src/manager.rs index ef0f5f38cc..60f4bc4aa9 100644 --- a/sea-orm-migration/src/manager.rs +++ b/sea-orm-migration/src/manager.rs @@ -1,10 +1,10 @@ use sea_orm::sea_query::{ extension::postgres::{TypeAlterStatement, TypeCreateStatement, TypeDropStatement}, - Alias, Expr, ForeignKeyCreateStatement, ForeignKeyDropStatement, IndexCreateStatement, - IndexDropStatement, Query, TableAlterStatement, TableCreateStatement, TableDropStatement, - TableRenameStatement, TableTruncateStatement, + ForeignKeyCreateStatement, ForeignKeyDropStatement, IndexCreateStatement, IndexDropStatement, + TableAlterStatement, TableCreateStatement, TableDropStatement, TableRenameStatement, + TableTruncateStatement, }; -use sea_orm::{Condition, ConnectionTrait, DbBackend, DbConn, DbErr, Statement, StatementBuilder}; +use sea_orm::{ConnectionTrait, DbBackend, DbConn, DbErr, StatementBuilder}; use sea_schema::{mysql::MySql, postgres::Postgres, probe::SchemaProbe, sqlite::Sqlite}; /// Helper struct for writing migration scripts in migration file