Skip to content

Conversation

@dullbananas
Copy link
Contributor

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.

@weiznich weiznich requested a review from a team November 25, 2025 15:27
Copy link
Member

@weiznich weiznich left a 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub enum Range {
pub enum MigrationRange {

to avoid collisions with the Range type from the stdlib.

Comment on lines +59 to +63
fn run_pending_migrations_in_range<S: MigrationSource<DB>>(
&mut self,
source: S,
range: &Range,
) -> Result<Vec<MigrationVersion<'_>>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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<'_>>> {

Comment on lines +105 to +109
fn revert_last_migrations_in_range<S: MigrationSource<DB>>(
&mut self,
source: S,
range: &Range,
) -> Result<Vec<MigrationVersion<'_>>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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<'_>>> {

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