Skip to content

Commit

Permalink
Don't destroy the db
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Dec 6, 2023
1 parent 6f39962 commit c231530
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,13 @@ impl Database {
pub async fn new(config: &DatabaseConfig) -> eyre::Result<Self> {
let connection_string = config.to_connection_string();

let pool = loop {
if !Postgres::database_exists(&connection_string).await? {
Postgres::create_database(&connection_string).await?;
}

let pool = Pool::connect(&connection_string).await?;

if let Err(err) = MIGRATOR.run(&pool).await {
tracing::error!("{err:?}");
tracing::warn!("Migration mismatch dropping previosu db");
drop(pool);
// Drop the DB if it's out of date - ONLY FOR TESTING
Postgres::drop_database(&connection_string).await?;
} else {
break pool;
}
};
if !Postgres::database_exists(&connection_string).await? {
Postgres::create_database(&connection_string).await?;
}

let pool = Pool::connect(&connection_string).await?;

MIGRATOR.run(&pool).await?;

Ok(Self { pool })
}
Expand Down

0 comments on commit c231530

Please sign in to comment.