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

feat: Expand Store interface; add GetLatestVersion method in Provider #673

Closed
mfridman opened this issue Dec 18, 2023 · 0 comments · Fixed by #758
Closed

feat: Expand Store interface; add GetLatestVersion method in Provider #673

mfridman opened this issue Dec 18, 2023 · 0 comments · Fixed by #758

Comments

@mfridman
Copy link
Collaborator

For historic reasons, adding a GetLatestVersion query was challenging because goose did not hard-delete rows and instead marked them with is_applied = false. Which means you'd end up with something like this:

| id | version_id | is_applied |
|----|------------|------------|
|  1 |          0 | t          |
|  2 |          1 | t          |
|  3 |          2 | t          |
|  4 |          2 | f          |

See #131 (review) where we changed the underlying implementation to hard-delete the row.

This is why we list versions (in reverse order by id, or in rare circumstances the timestamp) and then get the highest version that has is_applied = true and that hasn't been previously deleted. But this is wasteful, since we query the entire table and discard 99% of the results on the client. Granted we probably could have done this with SQL, but this is easy to mess up across implementations.

In the new Provider, this functionality does not exist, so we can expand the interface to accommodate for a "get latest" query to avoid listing all versions.

Note

Latest version can mean 2 different things:

  1. Latest version is the max by version_id
  2. Latest version is the last applied migration by id or timestamp, irrespective of the version. This becomes especially important for out-of-order migrations.
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 a pull request may close this issue.

1 participant