-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add run_pending_migrations_in_range and revert_last_migrations_in_range #4886
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
base: main
Are you sure you want to change the base?
Conversation
weiznich
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this PR. I think this is a good addition to diesel_migrations. Before merging I would like to address the minor style nits I've put comments on and also I would like to see:
- A changelog entry
- At least a test for each new method
| /// Controls the amount of migrations that are run or reverted | ||
| #[derive(Debug, Hash, PartialEq, Eq)] | ||
| #[non_exhaustive] | ||
| pub enum Range { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| pub enum Range { | |
| pub enum MigrationRange { |
to avoid collisions with the Range type from the stdlib.
| fn run_pending_migrations_in_range<S: MigrationSource<DB>>( | ||
| &mut self, | ||
| source: S, | ||
| range: &Range, | ||
| ) -> Result<Vec<MigrationVersion<'_>>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fn run_pending_migrations_in_range<S: MigrationSource<DB>>( | |
| &mut self, | |
| source: S, | |
| range: &Range, | |
| ) -> Result<Vec<MigrationVersion<'_>>> { | |
| fn run_pending_migrations_in_range( | |
| &mut self, | |
| source: impl MigrationSource<DB>, | |
| range: &Range, | |
| ) -> Result<Vec<MigrationVersion<'_>>> { |
| fn revert_last_migrations_in_range<S: MigrationSource<DB>>( | ||
| &mut self, | ||
| source: S, | ||
| range: &Range, | ||
| ) -> Result<Vec<MigrationVersion<'_>>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fn revert_last_migrations_in_range<S: MigrationSource<DB>>( | |
| &mut self, | |
| source: S, | |
| range: &Range, | |
| ) -> Result<Vec<MigrationVersion<'_>>> { | |
| fn revert_last_migrations_in_range( | |
| &mut self, | |
| source: impl MigrationSource<DB>, | |
| range: &Range, | |
| ) -> Result<Vec<MigrationVersion<'_>>> { |
With this change, the code for running a specific number of migrations is now in the diesel_migrations library instead of diesel_cli, so it can be used by a custom migration CLI. There's now a lot less code in diesel_cli, and a custom migration CLI would be similarly affected.
In the future, variant(s) like
Range::StopBefore(MigrationVersion)could be added to allow reverting to a specific version of the schema without manually counting the number of migrations to revert.