Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions sqlx-core/src/migrate/migration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use sha2::{Digest, Sha384};
use std::borrow::Cow;
use std::cmp::Ordering;

use crate::sql_str::SqlStr;

Expand All @@ -15,6 +16,28 @@ pub struct Migration {
pub no_tx: bool,
}

impl PartialEq for Migration {
fn eq(&self, other: &Self) -> bool {
self.version == other.version && self.migration_type == other.migration_type
}
}

impl Eq for Migration {}

impl PartialOrd for Migration {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl Ord for Migration {
fn cmp(&self, other: &Self) -> Ordering {
self.version
.cmp(&other.version)
.then_with(|| self.migration_type.cmp(&other.migration_type))
}
}

impl Migration {
pub fn new(
version: i64,
Expand Down
2 changes: 1 addition & 1 deletion sqlx-core/src/migrate/migration_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::Migrator;

/// Migration Type represents the type of migration
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum MigrationType {
/// Simple migration are single file migrations with no up / down queries
Simple,
Expand Down
3 changes: 1 addition & 2 deletions sqlx-core/src/migrate/migrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ impl Migrator {
/// let m = Migrator::with_migrations(migrations);
/// ```
pub fn with_migrations(mut migrations: Vec<Migration>) -> Self {
// Ensure that we are sorted by version in ascending order.
migrations.sort_by_key(|m| m.version);
migrations.sort();
Self {
migrations: Cow::Owned(migrations),
..Self::DEFAULT
Expand Down
3 changes: 1 addition & 2 deletions sqlx-core/src/migrate/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ pub fn resolve_blocking_with_config(
));
}

// Ensure that we are sorted by version in ascending order.
migrations.sort_by_key(|(m, _)| m.version);
migrations.sort();

Ok(migrations)
}
Expand Down
Loading