♻️ Replace diesel_async_migrations with diesel_migrations, refactor

diesel test init
This commit is contained in:
2025-03-08 17:46:45 +01:00
parent 5a77407297
commit 7a46101b42
6 changed files with 159 additions and 152 deletions

View File

@ -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
}