diff --git a/src/data/mod.rs b/src/data/mod.rs index 656d19880..ed5ce4952 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -122,7 +122,7 @@ impl Data { Ok(self .list_indexes()? .into_iter() - .find(|i| i.name == name.as_ref())) + .find(|i| i.uid == name.as_ref())) } pub fn create_index(&self, name: impl AsRef, primary_key: Option>) -> anyhow::Result { diff --git a/src/index_controller/local_index_controller/mod.rs b/src/index_controller/local_index_controller/mod.rs index 47de1a370..14efe42c7 100644 --- a/src/index_controller/local_index_controller/mod.rs +++ b/src/index_controller/local_index_controller/mod.rs @@ -70,7 +70,7 @@ impl IndexController for LocalIndexController { } let meta = IndexMetadata { - name: index_name, + uid: index_name, uuid: meta.uuid.clone(), created_at: meta.created_at, updated_at: meta.created_at, @@ -124,18 +124,18 @@ impl IndexController for LocalIndexController { fn list_indexes(&self) -> anyhow::Result> { let metas = self.indexes.list_indexes()?; let mut output_meta = Vec::new(); - for (name, meta, primary_key) in metas { + for (uid, meta, primary_key) in metas { let created_at = meta.created_at; let uuid = meta.uuid; let updated_at = self - .all_update_status(&name)? + .all_update_status(&uid)? .iter() .filter_map(|u| u.processed().map(|u| u.processed_at)) .max() .unwrap_or(created_at); let index_meta = IndexMetadata { - name, + uid, created_at, updated_at, uuid, @@ -146,7 +146,7 @@ impl IndexController for LocalIndexController { Ok(output_meta) } - fn update_index(&self, name: impl AsRef, index_settings: IndexSettings) -> anyhow::Result { + fn update_index(&self, uid: impl AsRef, index_settings: IndexSettings) -> anyhow::Result { if index_settings.name.is_some() { bail!("can't udpate an index name.") } @@ -154,7 +154,7 @@ impl IndexController for LocalIndexController { let (primary_key, meta) = match index_settings.primary_key { Some(ref primary_key) => { self.indexes - .update_index(&name, |index| { + .update_index(&uid, |index| { let mut txn = index.write_txn()?; if index.primary_key(&txn)?.is_some() { bail!("primary key already exists.") @@ -166,8 +166,8 @@ impl IndexController for LocalIndexController { }, None => { let (index, meta) = self.indexes - .index_with_meta(&name)? - .with_context(|| format!("index {:?} doesn't exist.", name.as_ref()))?; + .index_with_meta(&uid)? + .with_context(|| format!("index {:?} doesn't exist.", uid.as_ref()))?; let primary_key = index .primary_key(&index.read_txn()?)? .map(String::from); @@ -176,7 +176,7 @@ impl IndexController for LocalIndexController { }; Ok(IndexMetadata { - name: name.as_ref().to_string(), + uid: uid.as_ref().to_string(), uuid: meta.uuid.clone(), created_at: meta.created_at, updated_at: meta.updated_at, diff --git a/src/index_controller/mod.rs b/src/index_controller/mod.rs index 5bdaf8737..b20e43749 100644 --- a/src/index_controller/mod.rs +++ b/src/index_controller/mod.rs @@ -21,7 +21,7 @@ pub type UpdateStatus = updates::UpdateStatus; #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "camelCase")] pub struct IndexMetadata { - pub name: String, + pub uid: String, uuid: Uuid, created_at: DateTime, updated_at: DateTime, @@ -223,8 +223,8 @@ pub(crate) mod test { let indexes = controller.list_indexes().unwrap(); assert_eq!(indexes.len(), 2); - assert_eq!(indexes[0].name, "test_index"); - assert_eq!(indexes[1].name, "test_index2"); + assert_eq!(indexes[0].uid, "test_index"); + assert_eq!(indexes[1].uid, "test_index2"); assert_eq!(indexes[1].primary_key.clone().unwrap(), "foo"); } @@ -252,7 +252,7 @@ pub(crate) mod test { }; let result = controller.update_index("test", settings).unwrap(); - assert_eq!(result.name, "test"); + assert_eq!(result.uid, "test"); assert_eq!(result.created_at, result.updated_at); assert!(result.primary_key.is_none()); @@ -271,7 +271,7 @@ pub(crate) mod test { }; let result = controller.update_index("test", settings.clone()).unwrap(); - assert_eq!(result.name, "test"); + assert_eq!(result.uid, "test"); assert!(result.created_at < result.updated_at); assert_eq!(result.primary_key.unwrap(), "foo"); diff --git a/src/index_controller/updates.rs b/src/index_controller/updates.rs index 900987ba6..b8f1e31f4 100644 --- a/src/index_controller/updates.rs +++ b/src/index_controller/updates.rs @@ -2,6 +2,7 @@ use chrono::{Utc, DateTime}; use serde::{Serialize, Deserialize}; #[derive(Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] pub struct Pending { pub update_id: u64, pub meta: M, @@ -115,7 +116,7 @@ impl Failed { } #[derive(Debug, PartialEq, Eq, Hash, Serialize)] -#[serde(tag = "status")] +#[serde(tag = "status", rename_all = "camelCase")] pub enum UpdateStatus { Processing(Processing), Pending(Pending), diff --git a/src/option.rs b/src/option.rs index 38f99880e..c88110ccd 100644 --- a/src/option.rs +++ b/src/option.rs @@ -64,7 +64,6 @@ pub struct IndexerOpts { pub indexing_jobs: Option, } -#[cfg(test)] impl Default for IndexerOpts { fn default() -> Self { Self { diff --git a/src/routes/index.rs b/src/routes/index.rs index 62684ddaa..2c478432b 100644 --- a/src/routes/index.rs +++ b/src/routes/index.rs @@ -52,7 +52,7 @@ async fn get_index( #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] struct IndexCreateRequest { - name: String, + uid: String, primary_key: Option, } @@ -61,7 +61,7 @@ async fn create_index( data: web::Data, body: web::Json, ) -> Result { - match data.create_index(&body.name, body.primary_key.clone()) { + match data.create_index(&body.uid, body.primary_key.clone()) { Ok(meta) => { let json = serde_json::to_string(&meta).unwrap(); Ok(HttpResponse::Ok().body(json))