Skip to content
Merged
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
26 changes: 26 additions & 0 deletions sqlx-core/src/migrate/migrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@ impl Migrator {
})
}

/// Creates a new instance with the given migrations.
///
///
/// # Examples
///
/// ```rust,no_run
/// use sqlx::{ SqlSafeStr, migrate::{Migration, MigrationType::*, Migrator}};
///
/// // Define your migrations.
/// // You can also use include_str!("./xxx.sql") instead of hard-coded SQL statements.
/// let migrations = vec![
/// Migration::new(1, "user".into(), ReversibleUp, "create table uesrs ( ... )".into_sql_str(), false),
/// Migration::new(2, "post".into(), ReversibleUp, "create table posts ( ... )".into_sql_str(), false),
/// // add more...
/// ];
/// 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);
Self {
migrations: Cow::Owned(migrations),
..Self::DEFAULT
}
}

/// Override the name of the table used to track executed migrations.
///
/// May be schema-qualified and/or contain quotes. Defaults to `_sqlx_migrations`.
Expand Down
Loading