Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update total statements in the migration when it is being executed #2456

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: #2455
ruslic19 committed Jan 17, 2024
commit ac666f97a34f1cd75cb84ffae817f25bcf7cff60
6 changes: 6 additions & 0 deletions sql/migrate/migrate.go
Original file line number Diff line number Diff line change
@@ -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