pub struct DatabaseInitializer { /* private fields */ }Expand description
持有数据库连接并执行 crate::table::TableDefinition 声明的结构同步。
Implementations§
Source§impl DatabaseInitializer
impl DatabaseInitializer
Sourcepub async fn validate_table_definition(
&self,
table: &TableDefinition,
) -> Result<SchemaValidationReport, BaseError>
pub async fn validate_table_definition( &self, table: &TableDefinition, ) -> Result<SchemaValidationReport, BaseError>
从 MySQL information_schema 读取当前列并验证表定义的运行期字段契约。
本方法只读,不生成或执行 ALTER;数据库额外列不视为问题。
Sourcepub async fn plan_table_definitions(
&self,
definitions: &[&TableDefinition],
) -> Result<SchemaSyncReport, BaseError>
pub async fn plan_table_definitions( &self, definitions: &[&TableDefinition], ) -> Result<SchemaSyncReport, BaseError>
只读取当前数据库 schema 并计算待执行变更,不获取同步锁、不执行 DDL。
适用于生产启动门禁:返回非空 changes 表示数据库尚未与定义对齐;不兼容
变更仍返回错误。调用方若要实际应用变更,应使用 Self::sync_table_definitions。
Sourcepub async fn preflight_table_definitions(
&self,
definitions: &[&TableDefinition],
) -> Result<SchemaPreflightReport, BaseError>
pub async fn preflight_table_definitions( &self, definitions: &[&TableDefinition], ) -> Result<SchemaPreflightReport, BaseError>
只读预检结构计划及会阻止新约束生效的旧数据。
Sourcepub async fn sync_table_definitions(
&self,
definitions: &[&TableDefinition],
) -> Result<SchemaSyncReport, BaseError>
pub async fn sync_table_definitions( &self, definitions: &[&TableDefinition], ) -> Result<SchemaSyncReport, BaseError>
同步一组不可变表定义,使用单个数据库级 advisory lock 串行化多实例启动。
Auto Trait Implementations§
impl !RefUnwindSafe for DatabaseInitializer
impl !UnwindSafe for DatabaseInitializer
impl Freeze for DatabaseInitializer
impl Send for DatabaseInitializer
impl Sync for DatabaseInitializer
impl Unpin for DatabaseInitializer
impl UnsafeUnpin for DatabaseInitializer
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