From af2dbcb06e8a51bd816ac5031d1cf2af360151c7 Mon Sep 17 00:00:00 2001 From: fabianlindfors Date: Wed, 5 Jan 2022 14:42:47 +0100 Subject: [PATCH] Remove truncation of migrations during abort The migrations aren't updated so they shouldn't truncated during an abort either. Also fixes the indexing for contexts during aborts. --- src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f28a8dd..d40545c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,7 +94,7 @@ impl Reshape { self.state.applying(remaining_migrations.clone()); self.state.save(&mut self.db)?; - println!(" Applying {} migrations\n", remaining_migrations.len()); + println!("Applying {} migrations\n", remaining_migrations.len()); helpers::set_up_helpers(&mut self.db, current_migration) .context("failed to set up helpers")?; @@ -351,8 +351,6 @@ impl Reshape { // Abort all pending migrations abort_migrations(&mut transaction, remaining_migrations)?; - let keep_count = self.state.migrations.len() - remaining_migrations.len(); - self.state.migrations.truncate(keep_count); self.state.status = state::Status::Idle; self.state .save(&mut transaction) @@ -368,9 +366,10 @@ impl Reshape { fn abort_migrations(db: &mut dyn Conn, migrations: &[Migration]) -> anyhow::Result<()> { // Abort all migrations in reverse order - for (migration_index, migration) in migrations.iter().rev().enumerate() { + for (migration_index, migration) in migrations.iter().enumerate().rev() { print!("Aborting '{}' ", migration.name); - for (action_index, action) in migration.actions.iter().rev().enumerate() { + + for (action_index, action) in migration.actions.iter().enumerate().rev() { let ctx = MigrationContext::new(migration_index, action_index); action .abort(&ctx, db)