fix the import of the dumpv4&v5 when there is no instance-uid + rename the Kind+KindWithContent+Details variant for the DocumentImport and the Setting

This commit is contained in:
Irevoire 2022-10-21 18:03:10 +02:00 committed by Clément Renault
parent 131fe30934
commit 8d1408c65e
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
14 changed files with 98 additions and 77 deletions

View file

@ -149,7 +149,7 @@ impl From<Task> for TaskDump {
impl From<KindWithContent> for KindDump {
fn from(kind: KindWithContent) -> Self {
match kind {
KindWithContent::DocumentImport {
KindWithContent::DocumentAdditionOrUpdate {
primary_key,
method,
documents_count,
@ -165,8 +165,11 @@ impl From<KindWithContent> for KindDump {
KindDump::DocumentDeletion { documents_ids }
}
KindWithContent::DocumentClear { .. } => KindDump::DocumentClear,
KindWithContent::Settings {
new_settings, is_deletion, allow_index_creation, ..
KindWithContent::SettingsUpdate {
new_settings,
is_deletion,
allow_index_creation,
..
} => KindDump::Settings { settings: new_settings, is_deletion, allow_index_creation },
KindWithContent::IndexDeletion { .. } => KindDump::IndexDeletion,
KindWithContent::IndexCreation { primary_key, .. } => {
@ -274,7 +277,7 @@ pub(crate) mod test {
documents_count: 12,
},
canceled_by: None,
details: Some(Details::DocumentAddition {
details: Some(Details::DocumentAdditionOrUpdate {
received_documents: 12,
indexed_documents: Some(10),
}),
@ -297,7 +300,7 @@ pub(crate) mod test {
documents_count: 2,
},
canceled_by: None,
details: Some(Details::DocumentAddition {
details: Some(Details::DocumentAdditionOrUpdate {
received_documents: 2,
indexed_documents: None,
}),

View file

@ -60,7 +60,11 @@ impl CompatV5ToV6 {
};
Ok(Box::new(tasks.map(move |task| {
task.and_then(|(task, content_file)| {
let task_view: v5::tasks::TaskView = task.clone().into();
let mut task_view: v5::tasks::TaskView = task.clone().into();
if task_view.status == v5::Status::Processing {
task_view.started_at = None;
}
let task = v6::Task {
uid: task_view.uid,
@ -124,13 +128,13 @@ impl CompatV5ToV6 {
canceled_by: None,
details: task_view.details.map(|details| match details {
v5::Details::DocumentAddition { received_documents, indexed_documents } => {
v6::Details::DocumentAddition {
v6::Details::DocumentAdditionOrUpdate {
received_documents: received_documents as u64,
indexed_documents: indexed_documents.map(|i| i as u64),
}
}
v5::Details::Settings { settings } => {
v6::Details::Settings { settings: settings.into() }
v6::Details::SettingsUpdate { settings: settings.into() }
}
v5::Details::IndexInfo { primary_key } => {
v6::Details::IndexInfo { primary_key }

View file

@ -1,5 +1,5 @@
use std::fs::{self, File};
use std::io::{BufRead, BufReader};
use std::io::{BufRead, BufReader, ErrorKind};
use std::path::Path;
use serde::{Deserialize, Serialize};
@ -88,8 +88,11 @@ impl V4Reader {
}
pub fn instance_uid(&self) -> Result<Option<Uuid>> {
let uuid = fs::read_to_string(self.dump.path().join("instance-uid"))?;
Ok(Some(Uuid::parse_str(&uuid)?))
match fs::read_to_string(self.dump.path().join("instance-uid")) {
Ok(uuid) => Ok(Some(Uuid::parse_str(&uuid)?)),
Err(e) if e.kind() == ErrorKind::NotFound => Ok(None),
Err(e) => Err(e.into()),
}
}
pub fn indexes(&self) -> Result<impl Iterator<Item = Result<V4IndexReader>> + '_> {

View file

@ -33,7 +33,7 @@
//!
use std::fs::{self, File};
use std::io::{BufRead, BufReader, Seek, SeekFrom};
use std::io::{BufRead, BufReader, ErrorKind, Seek, SeekFrom};
use std::path::Path;
use serde::{Deserialize, Serialize};
@ -129,8 +129,11 @@ impl V5Reader {
}
pub fn instance_uid(&self) -> Result<Option<Uuid>> {
let uuid = fs::read_to_string(self.dump.path().join("instance-uid"))?;
Ok(Some(Uuid::parse_str(&uuid)?))
match fs::read_to_string(self.dump.path().join("instance-uid")) {
Ok(uuid) => Ok(Some(Uuid::parse_str(&uuid)?)),
Err(e) if e.kind() == ErrorKind::NotFound => Ok(None),
Err(e) => Err(e.into()),
}
}
pub fn indexes(&self) -> Result<impl Iterator<Item = Result<V5IndexReader>> + '_> {

View file

@ -326,7 +326,7 @@ impl From<TaskContent> for TaskType {
}
}
#[derive(Debug, Deserialize)]
#[derive(Debug, PartialEq, Eq, Deserialize)]
#[cfg_attr(test, derive(serde::Serialize))]
#[serde(rename_all = "camelCase")]
pub enum TaskStatus {