Skip to content

revert target-version does not behave as expected #4231

@Steve-Z

Description

@Steve-Z

I have found these related issues/pull requests

None

Description

If I use sqlx-cli (version 0.7.4) with command sqlx migrate revert --target-version <version>, my intended target is skipped and other migrations are reverted instead.

I posted this in discussions (#4218), but no replies in 4 days. After thinking about the logic for a few days, I think this may be an unintentional bug (seems unlikely because --target-version is a standard option for run or revert) or, at best, a poor user experience -- counterintuitive.

Reproduction steps

Opposite of what I expected:

steve@pop-os:~/Coding/rust_projects/webdev/bookmarks-rs$ sqlx migrate revert --dry-run --target-version 20240330153006 -D $DATABASE_URL/bookmarks
Can apply 20250905212818/revert test (0ns)
Can apply 20250428203929/revert mirror pinboard (0ns)
Skipped 20240330153006/revert use tag arrays (0ns) 

It skips the target script, but reverts the others?

When I use the run command it behaves as I expected:

steve@pop-os:~/Coding/rust_projects/webdev/bookmarks-rs$ sqlx migrate run --dry-run --target-version 20240330153006 -D $DATABASE_URL/bookmarks
Can apply 20240330153006/migrate use tag arrays (0ns)
Skipped 20250428203929/migrate mirror pinboard (0ns)
Skipped 20250905212818/migrate test (0ns) 

It runs the target and skips the others. I am showing my dry-run but the executed commands behaved the same.

Am I missing something? This revert behavior seems counterintuitive.

SQLx version

0.8.6

Enabled SQLx features

"runtime-tokio", "postgres", "tls-rustls", "chrono"

Database server and version

Postgres 18.3

Operating system

Pop_OS 22.04

Rust version

1.87.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions