pub struct InitializationHandler { /* private fields */ }Expand description
Batch DDL migration executor with tracking.
Maintains a _dbkit_migrations table so already-applied migrations
are skipped on subsequent runs. Each migration is identified by a
user-provided name and a content hash.
The tracking table DDL and the internal queries are backend-aware (Postgres / MySQL / SQLite), so the migration runner works on any backend. The user-supplied migration SQL is still backend-native — write it for the database you connected to.
Implementations§
Source§impl InitializationHandler
impl InitializationHandler
Sourcepub fn new(pool: AnyPool, backend: Backend) -> Self
pub fn new(pool: AnyPool, backend: Backend) -> Self
Create a handler for the given pool and backend.
The backend is typically obtained from
ConnectionManager::backend.
Sourcepub async fn run_named_migration(
&self,
name: &str,
sql: &str,
) -> Result<(), DbkitError>
pub async fn run_named_migration( &self, name: &str, sql: &str, ) -> Result<(), DbkitError>
Run a named migration. Skips if already applied with the same content hash.
If the migration name exists but the hash differs, it returns an error (content changed after being applied).
Sourcepub async fn run_migrations(&self, sql: &str) -> Result<(), DbkitError>
pub async fn run_migrations(&self, sql: &str) -> Result<(), DbkitError>
Run migrations from a SQL string (semicolon-separated DDL statements).
Statements are split on ;, so this does not support SQL that embeds
semicolons inside a single statement (string literals, PL/pgSQL
function bodies, triggers). Run such migrations as a single statement
through WriteOp::BatchDDL directly.
This is the simple/legacy API — it runs all statements unconditionally
without tracking. Use run_named_migration
for tracked migrations.
Sourcepub async fn applied_migrations(
&self,
) -> Result<Vec<(String, String, String)>, DbkitError>
pub async fn applied_migrations( &self, ) -> Result<Vec<(String, String, String)>, DbkitError>
List all applied migrations (name, hash, applied_at) in application order.
Auto Trait Implementations§
impl !RefUnwindSafe for InitializationHandler
impl !UnwindSafe for InitializationHandler
impl Freeze for InitializationHandler
impl Send for InitializationHandler
impl Sync for InitializationHandler
impl Unpin for InitializationHandler
impl UnsafeUnpin for InitializationHandler
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
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>
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