Skip to content
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

Support targeting a specific schema version for migrations #2534

Closed
inahga opened this issue Jun 7, 2023 · 0 comments · Fixed by #2538
Closed

Support targeting a specific schema version for migrations #2534

inahga opened this issue Jun 7, 2023 · 0 comments · Fixed by #2538
Labels
enhancement New feature or request

Comments

@inahga
Copy link
Contributor

inahga commented Jun 7, 2023

Is your feature request related to a problem? Please describe.
We would like to be able to specify the schema version of our database in source control, and execute downgrades/upgrades in a source-driven way. To accomplish this, we need to be able to have direct control over the schema version of the database.

We have multiple environments that might need to be on different schema versions, while our source of truth for migrations may be several versions ahead. Thus, we want to keep versioning in source control.

Describe the solution you'd like

We would like a CLI flag for run and revert called --target <VERSION> which takes the schema version that the database should be taken to.

If run, it will apply only the migrations that get the DB to that version,. If revert, it will apply the correct down migrations to take the DB to that version.

We would also accept a subcommand of sqlx migrate called target, i.e. sqlx migrate target <VERSION> which does whatever is necessary to take the DB to that version.

Describe alternatives you've considered

We could have our automation change the migrations that are available to sqlx, i.e. delete any migrations at runtime that are unnecessary. This is rather hacky, and introduces a lot of error-prone shell glue into our automation.

Refinery does support {up,down}grading to a target version, but we are already invested deeply into the sqlx ecosystem.

We can write some Rust glue around the sqlx API to accomplish the same thing, but it seemed wiser to try and get the feature upstream instead.

Additional context
I'm more than happy to contribute the work needed, just inquiring first to gauge the maintainers' interest in such a feature and any thoughts on design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant