fix postgres database ... already exists error
This commit is contained in:
@@ -75,11 +75,20 @@ impl Postgres {
|
||||
.await
|
||||
.context("Failed to connect to the PostgreSQL database")?;
|
||||
|
||||
// If this fails it's probably because the database already exists, which is exactly what
|
||||
// we want
|
||||
let _ = sqlx::query(&format!("CREATE DATABASE {}", config.database_name))
|
||||
match sqlx::query("SELECT datname FROM pg_database WHERE datname = $1")
|
||||
.bind(&config.database_name)
|
||||
.fetch_one(&mut connection)
|
||||
.await
|
||||
{
|
||||
Ok(_) => (),
|
||||
Err(sqlx::Error::RowNotFound) => {
|
||||
sqlx::query(&format!("CREATE DATABASE {}", config.database_name))
|
||||
.execute(&mut connection)
|
||||
.await;
|
||||
.await?;
|
||||
}
|
||||
Err(e) => return Err(e.into()),
|
||||
};
|
||||
|
||||
connection.close().await?;
|
||||
|
||||
let pool = PgPoolOptions::new()
|
||||
|
||||
Reference in New Issue
Block a user