Skip to main content

SchemaSync

Struct SchemaSync 

Source
pub struct SchemaSync { /* private fields */ }
Expand description

Schema Sync 协调器

Implementations§

Source§

impl SchemaSync

Source

pub fn new(entity_tables: Vec<TableDef>) -> Self

创建 SchemaSync(按方言选择 DDL 生成器)

Source

pub fn with_generator( entity_tables: Vec<TableDef>, ddl_generator: Box<dyn DdlGenerator>, ) -> Self

创建 SchemaSync(指定 DDL 生成器)

Source

pub fn with_rename_threshold(self, max_distance: usize, max_ratio: f64) -> Self

配置重命名检测阈值(v2.2.0 B-2)

Source

pub async fn sync_dry_run( &self, conn: &mut dyn Connection, ) -> Result<Vec<String>, DbError>

干运行:计算 DDL 但不执行

  1. introspect → 读取 DB 现有表结构
  2. diff → 计算变更
  3. 检查破坏性变更 → 若有则返回 Err(DestructiveChangeDetected)
  4. generate → 生成 DDL
Source

pub async fn sync( &self, conn: &mut dyn Connection, ) -> Result<SyncResult, DbError>

执行同步:事务内执行 DDL

  1. sync_dry_run → 获取 DDL
  2. begin_transaction
  3. 逐条执行 DDL
  4. commit / rollback
Source

pub fn diff_against(&self, db_tables: &[TableDef]) -> SchemaDiff

仅计算 diff(不连接 DB)

Source

pub async fn destructive_sync( &self, conn: &mut dyn Connection, confirm: Confirm, hooks: Option<&dyn DataMigrationHook>, ) -> Result<DestructiveSyncResult, DbError>

执行破坏性同步(v2.2.0 B-2)

显式执行破坏性 DDL(DROP COLUMN / RENAME COLUMN),需 Confirm::Yes 确认。 事务内原子执行,每条破坏性 DDL 前调用对应钩子。

§参数
  • conn:数据库连接
  • confirm:显式确认(必须 Confirm::Yes 才执行)
  • hooks:可选数据迁移钩子
§异常处理
  • confirm == Confirm::No → 返回 Err 要求显式确认
  • 钩子失败 → ROLLBACK 返回 Err
  • DDL 执行失败 → ROLLBACK 返回 Err

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more