pub struct AsyncMigrationHarness<C> { /* private fields */ }
migrations
only.Expand description
A diesel-migration MigrationHarness
to run migrations
via an AsyncConnection
Internally this harness is using tokio::task::block_in_place
and AsyncConnectionWrapper
to utilize sync Diesel’s migration infrastructure. For most applications this shouldn’t
be problematic as migrations are usually run at application startup and most applications
default to use the multithreaded tokio runtime. In turn this also means that you cannot use
this migration harness if you use the current thread variant of the tokio runtime or if
you run migrations in a very special setup (e.g by using tokio::select!
or tokio::join!
on a future produced by running the migrations). Consider manually construct a blocking task via
tokio::task::spawn_blocking
instead.
§Example
use diesel_async::AsyncMigrationHarness;
use diesel_migrations::{FileBasedMigrations, MigrationHarness};
let mut connection = connection_no_data().await;
// Alternativly use `diesel_migrations::embed_migrations!()`
// to get a list of migrations
let migrations = FileBasedMigrations::find_migrations_directory()?;
let mut harness = AsyncMigrationHarness::new(connection);
harness.run_pending_migrations(migrations)?;
// get back the connection from the harness
let connection = harness.into_inner();
§Example with pool
let config = AsyncDieselConnectionManager::<diesel_async::AsyncPgConnection>::new(db_url);
use diesel_async::pooled_connection::deadpool::Pool;
use diesel_async::AsyncMigrationHarness;
use diesel_migrations::{FileBasedMigrations, MigrationHarness};
// Alternativly use `diesel_migrations::embed_migrations!()`
// to get a list of migrations
let migrations = FileBasedMigrations::find_migrations_directory()?;
let pool = Pool::builder(get_config()).build()?;
let mut harness = AsyncMigrationHarness::new(pool.get().await?);
harness.run_pending_migrations(migrations)?;
Implementations§
Source§impl<C> AsyncMigrationHarness<C>where
C: AsyncConnection,
impl<C> AsyncMigrationHarness<C>where
C: AsyncConnection,
Sourcepub fn new(connection: C) -> Self
pub fn new(connection: C) -> Self
Construct a new AsyncMigrationHarness
from a given connection
Sourcepub fn into_inner(self) -> C
pub fn into_inner(self) -> C
Return the connection stored inside this instance of AsyncMigrationHarness
Trait Implementations§
Source§impl<C> From<C> for AsyncMigrationHarness<C>where
C: AsyncConnection,
impl<C> From<C> for AsyncMigrationHarness<C>where
C: AsyncConnection,
Source§impl<C> MigrationHarness<<C as AsyncConnectionCore>::Backend> for AsyncMigrationHarness<C>where
C: AsyncConnection,
AsyncConnectionWrapper<C, Tokio>: Connection<Backend = C::Backend> + MigrationHarness<C::Backend>,
impl<C> MigrationHarness<<C as AsyncConnectionCore>::Backend> for AsyncMigrationHarness<C>where
C: AsyncConnection,
AsyncConnectionWrapper<C, Tokio>: Connection<Backend = C::Backend> + MigrationHarness<C::Backend>,
Source§fn run_migration(
&mut self,
migration: &dyn Migration<C::Backend>,
) -> Result<MigrationVersion<'static>>
fn run_migration( &mut self, migration: &dyn Migration<C::Backend>, ) -> Result<MigrationVersion<'static>>
Source§fn revert_migration(
&mut self,
migration: &dyn Migration<C::Backend>,
) -> Result<MigrationVersion<'static>>
fn revert_migration( &mut self, migration: &dyn Migration<C::Backend>, ) -> Result<MigrationVersion<'static>>
Source§fn applied_migrations(&mut self) -> Result<Vec<MigrationVersion<'static>>>
fn applied_migrations(&mut self) -> Result<Vec<MigrationVersion<'static>>>
Source§fn has_pending_migration<S>(
&mut self,
source: S,
) -> Result<bool, Box<dyn Error + Sync + Send>>where
S: MigrationSource<DB>,
fn has_pending_migration<S>(
&mut self,
source: S,
) -> Result<bool, Box<dyn Error + Sync + Send>>where
S: MigrationSource<DB>,
Source§fn run_pending_migrations<S>(
&mut self,
source: S,
) -> Result<Vec<MigrationVersion<'_>>, Box<dyn Error + Sync + Send>>where
S: MigrationSource<DB>,
fn run_pending_migrations<S>(
&mut self,
source: S,
) -> Result<Vec<MigrationVersion<'_>>, Box<dyn Error + Sync + Send>>where
S: MigrationSource<DB>,
Source§fn run_next_migration<S>(
&mut self,
source: S,
) -> Result<MigrationVersion<'_>, Box<dyn Error + Sync + Send>>where
S: MigrationSource<DB>,
fn run_next_migration<S>(
&mut self,
source: S,
) -> Result<MigrationVersion<'_>, Box<dyn Error + Sync + Send>>where
S: MigrationSource<DB>,
Source§fn revert_all_migrations<S>(
&mut self,
source: S,
) -> Result<Vec<MigrationVersion<'_>>, Box<dyn Error + Sync + Send>>where
S: MigrationSource<DB>,
fn revert_all_migrations<S>(
&mut self,
source: S,
) -> Result<Vec<MigrationVersion<'_>>, Box<dyn Error + Sync + Send>>where
S: MigrationSource<DB>,
Source§fn revert_last_migration<S>(
&mut self,
source: S,
) -> Result<MigrationVersion<'static>, Box<dyn Error + Sync + Send>>where
S: MigrationSource<DB>,
fn revert_last_migration<S>(
&mut self,
source: S,
) -> Result<MigrationVersion<'static>, Box<dyn Error + Sync + Send>>where
S: MigrationSource<DB>,
Auto Trait Implementations§
impl<C> !Freeze for AsyncMigrationHarness<C>
impl<C> RefUnwindSafe for AsyncMigrationHarness<C>where
C: RefUnwindSafe,
impl<C> Send for AsyncMigrationHarness<C>where
C: Send,
impl<C> Sync for AsyncMigrationHarness<C>where
C: Sync,
impl<C> Unpin for AsyncMigrationHarness<C>where
C: Unpin,
impl<C> UnwindSafe for AsyncMigrationHarness<C>where
C: UnwindSafe,
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT
modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL
modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self
to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self
to an expression for Diesel’s query builder. Read moreSource§impl<T, Conn> RunQueryDsl<Conn> for T
impl<T, Conn> RunQueryDsl<Conn> for T
Source§fn execute<'conn, 'query>(
self,
conn: &'conn mut Conn,
) -> Conn::ExecuteFuture<'conn, 'query>
fn execute<'conn, 'query>( self, conn: &'conn mut Conn, ) -> Conn::ExecuteFuture<'conn, 'query>
Source§fn load<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> LoadFuture<'conn, 'query, Self, Conn, U>
fn load<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> LoadFuture<'conn, 'query, Self, Conn, U>
Source§fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
Stream
] with the returned rows. Read moreSource§fn get_result<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> GetResult<'conn, 'query, Self, Conn, U>
fn get_result<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> GetResult<'conn, 'query, Self, Conn, U>
Source§fn get_results<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> LoadFuture<'conn, 'query, Self, Conn, U>
fn get_results<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> LoadFuture<'conn, 'query, Self, Conn, U>
Vec
with the affected rows. Read more