Skip to content

Commit

Permalink
run migrations in a transaction
Browse files Browse the repository at this point in the history
we get an `implementation of sqlx::Acquire is not general enough` error
to get arround that, we use the hidden `run_direct`, which is made
specifically to go arround that error.
  • Loading branch information
trinity-1686a committed Mar 26, 2024
1 parent 698555a commit 794da30
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ static MIGRATOR: Migrator = sqlx::migrate!("migrations/postgresql");
/// `quickwit-metastore/migrations` directory.
#[instrument(skip_all)]
pub(super) async fn run_migrations(pool: &TrackedPool<Postgres>) -> MetastoreResult<()> {
let tx = pool.begin().await?;
let migrate_result = MIGRATOR.run(pool).await;
let mut tx = pool.begin().await?;
let conn = tx.acquire().await?;
// this is an hidden function, made to get "around the annoying "implementation of `Acquire`
// is not general enough" error", which is the error we get otherwise.
let migrate_result = MIGRATOR.run_direct(conn).await;

let Err(migrate_error) = migrate_result else {
tx.commit().await?;
Expand Down

0 comments on commit 794da30

Please sign in to comment.