Skip to content

Commit

Permalink
may as well use a transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcountryman committed Sep 21, 2023
1 parent 95ca4f4 commit 39d20a7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/sqlx_store/postgres_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ impl PostgresStore {

/// Migrate the session schema.
pub async fn migrate(&self) -> sqlx::Result<()> {
let mut tx = self.pool.begin().await?;

let create_schema_query = format!(
"create schema if not exists {schema_name}",
schema_name = self.schema_name,
);
sqlx::query(&create_schema_query)
.execute(&self.pool)
.await?;
sqlx::query(&create_schema_query).execute(&mut *tx).await?;

let create_table_query = format!(
r#"
Expand All @@ -47,7 +47,9 @@ impl PostgresStore {
schema_name = self.schema_name,
table_name = self.table_name
);
sqlx::query(&create_table_query).execute(&self.pool).await?;
sqlx::query(&create_table_query).execute(&mut *tx).await?;

tx.commit().await?;

Ok(())
}
Expand Down

0 comments on commit 39d20a7

Please sign in to comment.