Add support for setting a default migrator#4326
Open
Kobzol wants to merge 1 commit into
Open
Conversation
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.
This PR contains an implementation sketch for setting a default migrator for
#[sqlx::test]macros, because repeating all the migrations for each such macro can produce a lot of code bloat and slow compilation times (see #4318 and https://kobzol.github.io/rust/2026/06/21/optimizing-sqlx-test-rebuild-time.html for more details).It is configured in the config:
When a
#[sqlx::test]macro doesn't specify themigrationsnor themigratorfield, and a default migrator is set, it will load it the migrations from it (via a Rust path), rather than inlining the migrations in the expanded#[sqlx::test]output.So it turns from
to
I'm not sure in which config section this makes the most sense, so far I added it to the default
migratesection, but maybe it should have a new dedicatedtestsection?I didn't write tests or document the config option yet, because I first wanted to get a vibe check whether you find the approach reasonable.
TODO:
Does your PR solve an issue?
Fixes: #4318
Is this a breaking change?
No, it is a new opt-in option in the sqlx TOML config.