♻️ Replace diesel_async_migrations with diesel_migrations, refactor
diesel test init
This commit is contained in:
@ -1,9 +1,23 @@
|
||||
use diesel_async::AsyncPgConnection;
|
||||
use diesel_async_migrations::EmbeddedMigrations;
|
||||
use diesel::pg::Pg;
|
||||
use diesel_async::AsyncConnection;
|
||||
use diesel_async::async_connection_wrapper::AsyncConnectionWrapper;
|
||||
use diesel_migrations::{EmbeddedMigrations, MigrationHarness};
|
||||
use tokio::task::JoinError;
|
||||
|
||||
pub async fn run_migrations(
|
||||
migrations: &EmbeddedMigrations,
|
||||
conn: &mut AsyncPgConnection,
|
||||
) -> Result<(), diesel::result::Error> {
|
||||
migrations.run_pending_migrations(conn).await
|
||||
/// Run Diesel migrations using an async connection.
|
||||
/// Only works with Postgres.
|
||||
pub async fn run_migrations<A>(
|
||||
async_connection: A,
|
||||
migrations: EmbeddedMigrations,
|
||||
) -> Result<(), JoinError>
|
||||
where
|
||||
A: AsyncConnection<Backend = Pg> + 'static,
|
||||
{
|
||||
let mut async_wrapper: AsyncConnectionWrapper<A> =
|
||||
AsyncConnectionWrapper::from(async_connection);
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
async_wrapper.run_pending_migrations(migrations).unwrap();
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
Reference in New Issue
Block a user