Add run_through_version method for versioned migrations #3878
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.
Description:
The sqlx library already has a feature in sqlx-cli https://github.com/launchbadge/sqlx/blob/main/sqlx-cli/src/migrate.rs
To run migration till a specific version. Unfortunately this functionality isn't yet exposed to the library.
Therefore, this PR introduces three new public functions to the
Migrator
struct:latest_version()
: Returns the highest version number among all migrations defined in theMigrator
's source.latest_applied_version()
: Retrieves the highest version number of migrations that have already been successfully applied to the database.run_through_version(target: i64)
: Allows running "up" migrations against the database specifically up to atarget
version. This is enabling users to apply only a subset of pending migrations.I also added tests to run the new functionality against different database backends.
Is this a breaking change?
no, everything is backwards and forwards compatible. Only added function