feat: add config to downgrade command
it's new flag --all that rollbacks all applied migrations from database.
This commit is contained in:
parent
fef34be5ac
commit
8aa57a00bc
3 changed files with 10 additions and 3 deletions
migra-cli
|
@ -15,7 +15,11 @@ pub(crate) fn rollback_applied_migrations(
|
|||
let applied_migrations = manager.applied_migration_names()?;
|
||||
let migrations = config.migrations()?;
|
||||
|
||||
let rollback_migrations_number = cmp::min(opts.migrations_number, applied_migrations.len());
|
||||
let rollback_migrations_number = if opts.all_migrations {
|
||||
applied_migrations.len()
|
||||
} else {
|
||||
cmp::min(opts.migrations_number, applied_migrations.len())
|
||||
};
|
||||
|
||||
for migration_name in &applied_migrations[..rollback_migrations_number] {
|
||||
if let Some(migration) = migrations.iter().find(|m| m.name() == migration_name) {
|
||||
|
|
|
@ -49,6 +49,10 @@ pub(crate) struct DowngradeCommandOpt {
|
|||
/// How many applied migrations do we have to rollback
|
||||
#[structopt(long = "number", short = "n", default_value = "1")]
|
||||
pub migrations_number: usize,
|
||||
|
||||
/// Rolls back all applied migrations. Ignores --number option.
|
||||
#[structopt(long = "all")]
|
||||
pub all_migrations: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
|
|
|
@ -229,8 +229,7 @@ Pending migrations:
|
|||
.arg("-c")
|
||||
.arg(path_to_file("Migra_env.toml"))
|
||||
.arg("down")
|
||||
.arg("-n")
|
||||
.arg("2")
|
||||
.arg("--all")
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
|
|
Reference in a new issue