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

Update HasPending logic to account for out-of-order errors #762

Merged
merged 9 commits into from
May 3, 2024

Conversation

mfridman
Copy link
Collaborator

@mfridman mfridman commented May 1, 2024

Fix #761

This PR reverts the optimization in #758 and uses the same up logic to check whether all migrations have been applied. I.e., if allow missing (out-of-order) is disabled, which is the default, we report an error instead of false and nil error.

This avoids silently ignoring missing migrations, which is typically true for timestamp-based migrations.

I do wish we could optimize this because, for those who convert timestamp -> sequential hybrid migrations and gate for the correct ordering in CI, it's not possible to get into this state. It'd be nice for those folks to benefit from more efficient checks along this code path.

check.Number(t, target, len(fsys))
_, err = p.HasPending(ctx)
check.HasError(t, err)
check.Contains(t, err.Error(), "missing (out-of-order) migration")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal was to optimize the pending check by only checking the latest migration, but this is not correct since the default behavior SHOULD BE to fail if there are missing (out-of-order) migrations.

And we can only know if there are missing migrations by checking all of them. I wish there was a better way.

Maybe an "ignore missing" option for those who enforce behavior in CI pipelines?

check.NoError(t, err)
// TODO(mf): revisit the pending check behavior in addition to the HasPending
// method.
current, target, err := p.CheckPending(ctx)
Copy link
Collaborator Author

@mfridman mfridman May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given CheckPending only gets the current (db) and target (fsys) versions, I'm starting to reconsider the naming. I really don't want to give users the impression that it can be used for "pending" checks.

Some alternatives

  • VersionCheck
  • PendingVersion
  • CompareVersion
  • GetVersions (there is a GetDBVersion) this might be a compliment
  • CurrentAndTarget

Copy link
Collaborator Author

@mfridman mfridman May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will tackle this in a separate PR, it's unreleased yet, so a breaking change here may be warranted. I think it'll just be a name change, leaning towards GetVersions() (current, target int64, err error).

EDIT: for brevity #764

@mfridman mfridman merged commit 8c8def4 into master May 3, 2024
5 checks passed
@mfridman mfridman deleted the mf/fix-has-pending branch September 17, 2024 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fail when there is a pending migration and out of order migrations are not allowed
1 participant