Skip to content

Add run_through_version method for versioned migrations #3878

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

breuhan
Copy link

@breuhan breuhan commented May 28, 2025

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 the Migrator'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 a target 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

@abonander
Copy link
Collaborator

@breuhan
Copy link
Author

breuhan commented Jun 3, 2025

Yes it is a similar change, but on a deeper level. What is missing from that PR is the query for the latest applied migration and the query for the latest_version() from the Migration source. I'm also happy if that could be integrated.

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.

2 participants