fix(source/aws_s3): paginate ListObjects to load >1000 migrations - #1412
Open
EylonLevy wants to merge 1 commit into
Open
fix(source/aws_s3): paginate ListObjects to load >1000 migrations#1412EylonLevy wants to merge 1 commit into
EylonLevy wants to merge 1 commit into
Conversation
Signed-off-by: eylon <eylon@vybs.co>
Author
|
@Fontinalis Hey, can you please take a look? This is an issue for a big project using go migrate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
source/aws_s3loads migrations with a single, non-paginatedListObjectscall:The S3
ListObjectsAPI returns at most 1000 keys per response and setsIsTruncated=truewhen more exist. The driver never checksIsTruncatedand never continues past the first page, so any bucket/prefix holding more than 1000 objects has its remaining keys silently dropped from the migration listing.Why it matters
A migrations directory with ~500 migrations (an
.up.sql+.down.sqlper version = ~1000 files) crosses the 1000-key boundary. Once it does, the highest-numbered migration files are the ones truncated away (they sort last lexicographically). The migrator then never sees the newest migrations:Up()returnsErrNoChangeand callers get a false "database is up to date" while migrations silently fail to apply.Fix
Replace the single
ListObjectscall withListObjectsPages, accumulatingContentsfrom every page.ListObjectsPagesis already part of thes3iface.S3APIinterface the driver depends on, so there is no interface or signature change. The diff is minimal — the per-object parsing loop is unchanged, just moved into the page callback, and an append error is propagated out after pagination completes.Test
Added
TestLoadMigrationsPaginates, which registers 300 versions (600 objects) behind a fake S3 client that serves them in 50-object pages, then asserts every version — including the highest-numbered one that falls well beyond the first page — is loaded and readable. The fake gains aListObjectsPagesimplementation (reusing its existingListObjectsfiltering) and apageSizeknob to force the multi-page path. Before this fix the driver would have only seen the first page.golangci-lint run ./source/aws_s3/...reports 0 issues.