diff --git a/migra-cli/src/commands/upgrade.rs b/migra-cli/src/commands/upgrade.rs index c83829e..0d166f5 100644 --- a/migra-cli/src/commands/upgrade.rs +++ b/migra-cli/src/commands/upgrade.rs @@ -27,7 +27,11 @@ pub(crate) fn upgrade_pending_migrations(config: Config, opts: UpgradeCommandOpt } } } else { - for migration in pending_migrations.iter() { + let upgrade_migrations_number = opts + .migrations_number + .unwrap_or_else(|| pending_migrations.len()); + + for migration in &pending_migrations[..upgrade_migrations_number] { print_migration_info(migration); manager.upgrade(migration)?; } diff --git a/migra-cli/src/opts.rs b/migra-cli/src/opts.rs index b62abaf..c1cf383 100644 --- a/migra-cli/src/opts.rs +++ b/migra-cli/src/opts.rs @@ -51,6 +51,10 @@ pub(crate) struct UpgradeCommandOpt { /// in the database. #[structopt(long = "name")] pub migration_name: Option, + + /// How many existing migrations do we have to update. + #[structopt(long = "number", short = "n")] + pub migrations_number: Option, } #[derive(Debug, StructOpt)] diff --git a/migra-cli/tests/commands.rs b/migra-cli/tests/commands.rs index e2aef16..c1c691a 100644 --- a/migra-cli/tests/commands.rs +++ b/migra-cli/tests/commands.rs @@ -246,13 +246,8 @@ Pending migrations: .arg("-c") .arg(path_to_file("Migra_env.toml")) .arg("up") - .assert() - .success(); - - Command::cargo_bin("migra")? - .arg("-c") - .arg(path_to_file("Migra_env.toml")) - .arg("down") + .arg("-n") + .arg("1") .assert() .success();