Archived
1
0
Fork 0

feat: add command to upgrade command

... which adds the possibility to specify the number of
existing migrations to be updated
This commit is contained in:
Dmitriy Pleshevskiy 2021-02-25 00:56:08 +03:00
parent bd57c75dfc
commit f4539f7877
3 changed files with 11 additions and 8 deletions

View file

@ -27,7 +27,11 @@ pub(crate) fn upgrade_pending_migrations(config: Config, opts: UpgradeCommandOpt
} }
} }
} else { } 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); print_migration_info(migration);
manager.upgrade(migration)?; manager.upgrade(migration)?;
} }

View file

@ -51,6 +51,10 @@ pub(crate) struct UpgradeCommandOpt {
/// in the database. /// in the database.
#[structopt(long = "name")] #[structopt(long = "name")]
pub migration_name: Option<String>, pub migration_name: Option<String>,
/// How many existing migrations do we have to update.
#[structopt(long = "number", short = "n")]
pub migrations_number: Option<usize>,
} }
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]

View file

@ -246,13 +246,8 @@ Pending migrations:
.arg("-c") .arg("-c")
.arg(path_to_file("Migra_env.toml")) .arg(path_to_file("Migra_env.toml"))
.arg("up") .arg("up")
.assert() .arg("-n")
.success(); .arg("1")
Command::cargo_bin("migra")?
.arg("-c")
.arg(path_to_file("Migra_env.toml"))
.arg("down")
.assert() .assert()
.success(); .success();