Enhance index update functionality to support renaming by adding new_uid field. Update related structures and methods to handle the new index UID during updates, ensuring backward compatibility with existing index operations.

This commit is contained in:
Quentin de Quelen
2025-08-05 19:18:05 +02:00
committed by Tamo
parent 0f1c78b185
commit ae2d0a67a4
15 changed files with 547 additions and 119 deletions

View File

@ -132,6 +132,11 @@ pub struct DetailsView {
pub payload_size: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub indexes: Option<BTreeMap<String, DetailsExportIndexSettings>>,
// index rename
#[serde(skip_serializing_if = "Option::is_none")]
pub old_index_uid: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub new_index_uid: Option<String>,
}
impl DetailsView {
@ -292,6 +297,18 @@ impl DetailsView {
(None, Some(to)) | (Some(to), None) => Some(to),
(Some(_), Some(to)) => Some(to),
},
old_index_uid: match (self.old_index_uid.clone(), other.old_index_uid.clone()) {
(None, None) => None,
(None, Some(uid)) | (Some(uid), None) => Some(uid),
// We should never be able to batch multiple renames at the same time.
(Some(left), Some(_right)) => Some(left),
},
new_index_uid: match (self.new_index_uid.clone(), other.new_index_uid.clone()) {
(None, None) => None,
(None, Some(uid)) | (Some(uid), None) => Some(uid),
// We should never be able to batch multiple renames at the same time.
(Some(left), Some(_right)) => Some(left),
},
}
}
}
@ -324,9 +341,11 @@ impl From<Details> for DetailsView {
settings.hide_secrets();
DetailsView { settings: Some(settings), ..DetailsView::default() }
}
Details::IndexInfo { primary_key } => {
DetailsView { primary_key: Some(primary_key), ..DetailsView::default() }
}
Details::IndexInfo { primary_key, new_uid } => DetailsView {
primary_key: Some(primary_key),
new_index_uid: new_uid.clone(),
..DetailsView::default()
},
Details::DocumentDeletion {
provided_ids: received_document_ids,
deleted_documents,

View File

@ -140,10 +140,7 @@ pub enum KindWithContent {
IndexUpdate {
index_uid: String,
primary_key: Option<String>,
},
IndexRename {
index_uid: String,
new_index_uid: String,
new_index_uid: Option<String>,
},
IndexSwap {
swaps: Vec<IndexSwap>,
@ -178,13 +175,6 @@ pub struct IndexSwap {
pub indexes: (String, String),
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct IndexRenameDetails {
pub old_uid: String,
pub new_uid: String,
}
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct ExportIndexSettings {
@ -204,7 +194,6 @@ impl KindWithContent {
KindWithContent::IndexCreation { .. } => Kind::IndexCreation,
KindWithContent::IndexDeletion { .. } => Kind::IndexDeletion,
KindWithContent::IndexUpdate { .. } => Kind::IndexUpdate,
KindWithContent::IndexRename { .. } => Kind::IndexRename,
KindWithContent::IndexSwap { .. } => Kind::IndexSwap,
KindWithContent::TaskCancelation { .. } => Kind::TaskCancelation,
KindWithContent::TaskDeletion { .. } => Kind::TaskDeletion,
@ -232,9 +221,14 @@ impl KindWithContent {
| DocumentClear { index_uid }
| SettingsUpdate { index_uid, .. }
| IndexCreation { index_uid, .. }
| IndexUpdate { index_uid, .. }
| IndexDeletion { index_uid } => vec![index_uid],
IndexRename { index_uid, new_index_uid } => vec![index_uid, new_index_uid],
IndexUpdate { index_uid, new_index_uid, .. } => {
let mut indexes = vec![index_uid.as_str()];
if let Some(new_uid) = new_index_uid {
indexes.push(new_uid.as_str());
}
indexes
}
IndexSwap { swaps } => {
let mut indexes = HashSet::<&str>::default();
for swap in swaps {
@ -283,13 +277,12 @@ impl KindWithContent {
KindWithContent::SettingsUpdate { new_settings, .. } => {
Some(Details::SettingsUpdate { settings: new_settings.clone() })
}
KindWithContent::IndexCreation { primary_key, .. }
| KindWithContent::IndexUpdate { primary_key, .. } => {
Some(Details::IndexInfo { primary_key: primary_key.clone() })
KindWithContent::IndexCreation { primary_key, .. } => {
Some(Details::IndexInfo { primary_key: primary_key.clone(), new_uid: None })
}
KindWithContent::IndexRename { index_uid, new_index_uid } => {
Some(Details::IndexRename {
old_uid: index_uid.clone(),
KindWithContent::IndexUpdate { primary_key, new_index_uid, .. } => {
Some(Details::IndexInfo {
primary_key: primary_key.clone(),
new_uid: new_index_uid.clone(),
})
}
@ -363,16 +356,15 @@ impl KindWithContent {
Some(Details::SettingsUpdate { settings: new_settings.clone() })
}
KindWithContent::IndexDeletion { .. } => None,
KindWithContent::IndexRename { index_uid, new_index_uid } => {
Some(Details::IndexRename {
old_uid: index_uid.clone(),
KindWithContent::IndexCreation { primary_key, .. } => {
Some(Details::IndexInfo { primary_key: primary_key.clone(), new_uid: None })
}
KindWithContent::IndexUpdate { primary_key, new_index_uid, .. } => {
Some(Details::IndexInfo {
primary_key: primary_key.clone(),
new_uid: new_index_uid.clone(),
})
}
KindWithContent::IndexCreation { primary_key, .. }
| KindWithContent::IndexUpdate { primary_key, .. } => {
Some(Details::IndexInfo { primary_key: primary_key.clone() })
}
KindWithContent::IndexSwap { .. } => {
todo!()
}
@ -426,10 +418,13 @@ impl From<&KindWithContent> for Option<Details> {
}
KindWithContent::IndexDeletion { .. } => None,
KindWithContent::IndexCreation { primary_key, .. } => {
Some(Details::IndexInfo { primary_key: primary_key.clone() })
Some(Details::IndexInfo { primary_key: primary_key.clone(), new_uid: None })
}
KindWithContent::IndexUpdate { primary_key, .. } => {
Some(Details::IndexInfo { primary_key: primary_key.clone() })
KindWithContent::IndexUpdate { primary_key, new_index_uid, .. } => {
Some(Details::IndexInfo {
primary_key: primary_key.clone(),
new_uid: new_index_uid.clone(),
})
}
KindWithContent::IndexSwap { .. } => None,
KindWithContent::TaskCancelation { query, tasks } => Some(Details::TaskCancelation {
@ -563,7 +558,6 @@ pub enum Kind {
IndexCreation,
IndexDeletion,
IndexUpdate,
IndexRename,
IndexSwap,
TaskCancelation,
TaskDeletion,
@ -582,8 +576,7 @@ impl Kind {
| Kind::SettingsUpdate
| Kind::IndexCreation
| Kind::IndexDeletion
| Kind::IndexUpdate
| Kind::IndexRename => true,
| Kind::IndexUpdate => true,
Kind::IndexSwap
| Kind::TaskCancelation
| Kind::TaskDeletion
@ -604,7 +597,6 @@ impl Display for Kind {
Kind::IndexCreation => write!(f, "indexCreation"),
Kind::IndexDeletion => write!(f, "indexDeletion"),
Kind::IndexUpdate => write!(f, "indexUpdate"),
Kind::IndexRename => write!(f, "indexRename"),
Kind::IndexSwap => write!(f, "indexSwap"),
Kind::TaskCancelation => write!(f, "taskCancelation"),
Kind::TaskDeletion => write!(f, "taskDeletion"),
@ -623,8 +615,6 @@ impl FromStr for Kind {
Ok(Kind::IndexCreation)
} else if kind.eq_ignore_ascii_case("indexUpdate") {
Ok(Kind::IndexUpdate)
} else if kind.eq_ignore_ascii_case("indexRename") {
Ok(Kind::IndexRename)
} else if kind.eq_ignore_ascii_case("indexSwap") {
Ok(Kind::IndexSwap)
} else if kind.eq_ignore_ascii_case("indexDeletion") {
@ -687,6 +677,7 @@ pub enum Details {
},
IndexInfo {
primary_key: Option<String>,
new_uid: Option<String>,
},
DocumentDeletion {
provided_ids: usize,
@ -722,7 +713,6 @@ pub enum Details {
IndexSwap {
swaps: Vec<IndexSwap>,
},
IndexRename(IndexRenameDetails),
Export {
url: String,
api_key: Option<String>,
@ -768,7 +758,6 @@ impl Details {
Self::SettingsUpdate { .. }
| Self::IndexInfo { .. }
| Self::Dump { .. }
| Self::IndexRename { .. }
| Self::Export { .. }
| Self::UpgradeDatabase { .. }
| Self::IndexSwap { .. } => (),