mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-19 16:44:07 +00:00
Automatically infer migration type (#2664)
This commit is contained in:
@@ -24,6 +24,7 @@ pub enum MigrateError {
|
||||
#[error("migration {0} is newer than the latest applied migration {1}")]
|
||||
VersionTooNew(i64, i64),
|
||||
|
||||
#[deprecated = "migration types are now inferred"]
|
||||
#[error("cannot mix reversible migrations with simple migrations. All migrations should be reversible or simple migrations")]
|
||||
InvalidMixReversibleAndSimple,
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use super::Migrator;
|
||||
|
||||
/// Migration Type represents the type of migration
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub enum MigrationType {
|
||||
@@ -71,4 +73,17 @@ impl MigrationType {
|
||||
MigrationType::ReversibleDown => "-- Add down migration script here\n",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn infer(migrator: &Migrator, reversible: bool) -> MigrationType {
|
||||
match migrator.iter().next() {
|
||||
Some(first_migration) => first_migration.migration_type,
|
||||
None => {
|
||||
if reversible {
|
||||
MigrationType::ReversibleUp
|
||||
} else {
|
||||
MigrationType::Simple
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user