fix: Create org if it doesn't exist

pull/24376/head
Carol (Nichols || Goulding) 2020-04-02 10:57:32 -04:00
parent 6549bebf2c
commit a7d33b803c
1 changed files with 7 additions and 3 deletions

View File

@ -116,10 +116,14 @@ impl Database {
org_id: u32,
bucket_name: &str,
) -> Result<Option<u32>, StorageError> {
if !self.organizations.read().await.contains_key(&org_id) {
let mut orgs = self.organizations.write().await;
orgs.insert(org_id, RwLock::new(Organization::default()));
}
let orgs = self.organizations.read().await;
let org = orgs.get(&org_id).ok_or_else(|| StorageError {
description: format!("org {} not found", org_id),
})?;
let org = orgs.get(&org_id).expect("Should have found or just inserted org");
let id = match org.read().await.bucket_name_to_id.get(bucket_name) {
Some(id) => Some(*id),