Skip to content

Commit

Permalink
fix: PostgresDB initialization and add db_url parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Dec 18, 2023
1 parent 59bd23c commit 7118006
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 2 additions & 8 deletions moksha-mint/src/database/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ pub struct PostgresDB {
}

impl PostgresDB {
pub async fn new() -> Result<PostgresDB, sqlx::Error> {
pub async fn new(url: &str) -> Result<PostgresDB, sqlx::Error> {
Ok(PostgresDB {
pool: PgPoolOptions::new()
.max_connections(5)
.connect(
&dotenvy::var("MINT_DB_URL")
.expect("environment variable MINT_DB_URL is not set"),
)
.await?,
pool: PgPoolOptions::new().max_connections(5).connect(url).await?,
})
}

Expand Down
7 changes: 6 additions & 1 deletion moksha-mint/src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ impl MintBuilder {
None => panic!("Lightning backend not set"),
};

let db = Arc::new(crate::database::postgres::PostgresDB::new().await?);
let db = Arc::new(
crate::database::postgres::PostgresDB::new(
self.db_url.expect("MINT_DB_URL not set").as_str(),
)
.await?,
);
db.migrate().await;

let fee_config = LightningFeeConfig::new(
Expand Down

0 comments on commit 7118006

Please sign in to comment.