message: Update postgres check for existing database/schema
diff: @@ -666,14 +666,38 @@ impl WalletStrategy for DatabasePerWalletStrategy {
  debug!("connecting to postgres, url_base: {:?}", url_base);
  let conn = postgres::Connection::connect(&url_base[..], config.tls())?;
  + // select metadata for this wallet to ensure it DOESN'T exist
  + let mut schema_result = {
  + let mut rows = conn.query(
  + "SELECT value FROM metadata WHERE wallet_id",
  + &[&id]);
  + match rows.as_mut() {
  + Ok(rows_data) => {
  + match rows_data.iter().next() {
  + Some(_) => {
  + error!("Metadata was found for wallet id '{}' which indicates this wallet already exists.", id);
  + Err(WalletStorageError::AlreadyExists)
  + },
  + None => Ok(())
  + }
  + },
  + Err(_) => Ok(())
  + }
  + };
  +
  + match schema_result {
  + Ok(_) => {
  debug!("creating wallets DB");
  let create_db_sql = str::replace(_CREATE_WALLET_DATABASE, "$1", id);
  - let mut schema_result = match conn.execute(&create_db_sql, &[]) {
  + schema_result = match conn.execute(&create_db_sql, &[]) {
  Ok(_) => Ok(()),
  Err(_error) => {
  Err(WalletStorageError::AlreadyExists)
  }
  };
  + },
  + Err(_) => ()
  + };
  conn.finish()?;
  debug!("connecting to wallet as user");
  