From ac666f97a34f1cd75cb84ffae817f25bcf7cff60 Mon Sep 17 00:00:00 2001 From: Ruslan Date: Wed, 17 Jan 2024 11:52:54 -0500 Subject: [PATCH] fix: update total statements in the migration when it is being executed The reason for this is that users are required to edit existing migration files to resolve partial failure issues. Without keeping total in sync, such migration would be considered still pending, because total != applied. Issue: https://github.com/ariga/atlas/issues/2455 --- sql/migrate/migrate.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sql/migrate/migrate.go b/sql/migrate/migrate.go index 8ce9b5f1059..ba4c2204510 100644 --- a/sql/migrate/migrate.go +++ b/sql/migrate/migrate.go @@ -812,6 +812,12 @@ func (e *Executor) Execute(ctx context.Context, m File) (err error) { Hash: hash, } } + + // Update total statements in the existing revision to support + // statement-level granularity in cases when users add new statements to + // existing migrations to resolve partial failures. + r.Total = len(stmts) + // Save once to mark as started in the database. if err = e.writeRevision(ctx, r); err != nil { return err