pub struct Migrator { /* private fields */ }Implementations§
Source§impl Migrator
impl Migrator
pub fn new(context: MigrationContext) -> Self
pub fn add_migration(self, migration: Migration) -> Self
pub fn add_migrations(self, migrations: Vec<Migration>) -> Self
pub fn get_migrations(&self) -> &Vec<Migration>
pub fn get_pending_migrations(&self) -> Vec<&Migration>
pub fn get_applied_migrations(&self) -> Vec<&Migration>
pub fn latest_version(&self) -> Option<&str>
pub fn find_migration(&self, version: &str) -> Option<&Migration>
Sourcepub fn check_version_conflicts(&self) -> Result<(), DbError>
pub fn check_version_conflicts(&self) -> Result<(), DbError>
检测迁移版本冲突(重复版本号)
返回第一个冲突的版本号(如有)。
在 migrate/up/down 等执行方法入口处调用,确保迁移列表无重复版本。
Sourcepub async fn migrate(&mut self) -> Result<Vec<String>, DbError>
pub async fn migrate(&mut self) -> Result<Vec<String>, DbError>
执行所有待迁移(batch=0)的 up SQL
若数据库方言支持 DDL 事务(PostgreSQL/SQLite),则用事务包裹所有待执行迁移, 任一迁移失败时回滚全部变更,避免部分迁移导致的状态不一致。 不支持 DDL 事务的方言(MySQL/Oracle/SQL Server)逐条执行,失败时保留已执行的变更。
Sourcepub async fn up(
&mut self,
target_version: Option<&str>,
) -> Result<Vec<String>, DbError>
pub async fn up( &mut self, target_version: Option<&str>, ) -> Result<Vec<String>, DbError>
执行到指定版本(包括该版本)
Sourcepub async fn down(
&mut self,
target_version: Option<&str>,
) -> Result<Vec<String>, DbError>
pub async fn down( &mut self, target_version: Option<&str>, ) -> Result<Vec<String>, DbError>
回滚到指定版本(执行该版本之后所有迁移的 down SQL)
Sourcepub fn progress(&self) -> MigrationProgress
pub fn progress(&self) -> MigrationProgress
获取迁移进度
Auto Trait Implementations§
impl !RefUnwindSafe for Migrator
impl !UnwindSafe for Migrator
impl Freeze for Migrator
impl Send for Migrator
impl Sync for Migrator
impl Unpin for Migrator
impl UnsafeUnpin for Migrator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more