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 {
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)?;
}

View file

@ -51,6 +51,10 @@ pub(crate) struct UpgradeCommandOpt {
/// in the database.
#[structopt(long = "name")]
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)]

View file

@ -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();