pub struct MigrationRunner { /* private fields */ }Expand description
Runs schema migrations against a SQLite database.
MigrationRunner tracks which migrations have been applied in a
schema_versions table and only executes those that have not yet been
applied. Migrations are executed in version order inside transactions.
§Thread safety
The runner is safe to use from multiple tasks. Concurrent calls to
run_pending are safe because each migration
runs inside a BEGIN EXCLUSIVE transaction, which serializes access
at the database level.
Implementations§
Source§impl MigrationRunner
impl MigrationRunner
Sourcepub fn new(pool: Pool<Sqlite>) -> MigrationRunner
pub fn new(pool: Pool<Sqlite>) -> MigrationRunner
Creates a new runner with the built-in migrations.
Sourcepub const fn with_migrations(
pool: Pool<Sqlite>,
migrations: &'static [Migration],
) -> MigrationRunner
pub const fn with_migrations( pool: Pool<Sqlite>, migrations: &'static [Migration], ) -> MigrationRunner
Creates a new runner with a custom set of migrations.
This is primarily useful for testing. In production, prefer new.
Sourcepub async fn current_version(&self) -> Result<u32, Error>
pub async fn current_version(&self) -> Result<u32, Error>
Returns the highest migration version that has been applied, or 0 if
no migrations have been applied yet.
§Errors
Returns an error if the database cannot be queried.
Sourcepub async fn pending_migrations(&self) -> Result<Vec<&Migration>, Error>
pub async fn pending_migrations(&self) -> Result<Vec<&Migration>, Error>
Returns the list of migrations that have not yet been applied.
§Errors
Returns an error if the current version cannot be determined.
Sourcepub async fn run_pending(&self) -> Result<Vec<u32>, Error>
pub async fn run_pending(&self) -> Result<Vec<u32>, Error>
Applies all pending migrations in version order.
Each migration runs inside its own transaction. If a migration fails, the transaction is rolled back and the error is returned; previously applied migrations in this call remain committed.
Returns the list of version numbers that were applied.
§Errors
Returns an error if any migration fails to apply.
Trait Implementations§
Source§impl Clone for MigrationRunner
impl Clone for MigrationRunner
Source§fn clone(&self) -> MigrationRunner
fn clone(&self) -> MigrationRunner
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for MigrationRunner
impl !RefUnwindSafe for MigrationRunner
impl Send for MigrationRunner
impl Sync for MigrationRunner
impl Unpin for MigrationRunner
impl UnsafeUnpin for MigrationRunner
impl !UnwindSafe for MigrationRunner
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request