2022-10-22 16:35:42 +02:00
|
|
|
#![allow(clippy::type_complexity)]
|
|
|
|
#![allow(clippy::wrong_self_convention)]
|
|
|
|
|
2022-10-20 18:00:07 +02:00
|
|
|
use meilisearch_types::error::ResponseError;
|
|
|
|
use meilisearch_types::keys::Key;
|
|
|
|
use meilisearch_types::milli::update::IndexDocumentsMethod;
|
|
|
|
use meilisearch_types::settings::Unchecked;
|
2022-10-26 12:57:29 +02:00
|
|
|
use meilisearch_types::tasks::{Details, IndexSwap, KindWithContent, Status, Task, TaskId};
|
2022-10-20 18:00:07 +02:00
|
|
|
use meilisearch_types::InstanceUid;
|
2022-10-17 15:11:35 +02:00
|
|
|
use roaring::RoaringBitmap;
|
2022-09-29 16:17:06 +02:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use time::OffsetDateTime;
|
|
|
|
|
2022-10-02 13:24:59 +02:00
|
|
|
mod error;
|
2022-10-03 16:12:01 +02:00
|
|
|
mod reader;
|
2022-10-02 13:24:59 +02:00
|
|
|
mod writer;
|
|
|
|
|
|
|
|
pub use error::Error;
|
2022-10-16 01:39:01 +02:00
|
|
|
pub use reader::{DumpReader, UpdateFile};
|
2022-10-02 13:24:59 +02:00
|
|
|
pub use writer::DumpWriter;
|
2022-09-29 16:17:06 +02:00
|
|
|
|
2022-10-03 16:12:01 +02:00
|
|
|
const CURRENT_DUMP_VERSION: Version = Version::V6;
|
2022-09-29 16:17:06 +02:00
|
|
|
|
|
|
|
type Result<T> = std::result::Result<T, Error>;
|
|
|
|
|
2022-11-30 14:51:21 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
2022-09-29 16:17:06 +02:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2022-10-05 20:11:07 +02:00
|
|
|
pub struct Metadata {
|
2022-10-03 16:12:01 +02:00
|
|
|
pub dump_version: Version,
|
2022-09-29 16:17:06 +02:00
|
|
|
pub db_version: String,
|
2022-10-03 16:12:01 +02:00
|
|
|
#[serde(with = "time::serde::rfc3339")]
|
2022-09-29 16:17:06 +02:00
|
|
|
pub dump_date: OffsetDateTime,
|
|
|
|
}
|
2022-10-03 16:12:01 +02:00
|
|
|
|
2022-11-30 14:51:21 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
2022-10-04 19:13:30 +02:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct IndexMetadata {
|
|
|
|
pub uid: String,
|
|
|
|
pub primary_key: Option<String>,
|
|
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
|
|
pub created_at: OffsetDateTime,
|
|
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
|
|
pub updated_at: OffsetDateTime,
|
|
|
|
}
|
|
|
|
|
2022-11-30 14:51:21 +01:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
|
2022-10-03 16:12:01 +02:00
|
|
|
pub enum Version {
|
|
|
|
V1,
|
|
|
|
V2,
|
|
|
|
V3,
|
|
|
|
V4,
|
|
|
|
V5,
|
|
|
|
V6,
|
|
|
|
}
|
2022-10-03 18:50:06 +02:00
|
|
|
|
2022-10-16 01:39:01 +02:00
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
2022-10-13 16:03:23 +02:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct TaskDump {
|
|
|
|
pub uid: TaskId,
|
|
|
|
#[serde(default)]
|
|
|
|
pub index_uid: Option<String>,
|
|
|
|
pub status: Status,
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
pub kind: KindDump,
|
|
|
|
|
2022-10-18 13:57:58 +02:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub canceled_by: Option<TaskId>,
|
|
|
|
|
2022-10-13 16:03:23 +02:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub details: Option<Details>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub error: Option<ResponseError>,
|
|
|
|
|
|
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
|
|
pub enqueued_at: OffsetDateTime,
|
|
|
|
#[serde(
|
|
|
|
with = "time::serde::rfc3339::option",
|
|
|
|
skip_serializing_if = "Option::is_none",
|
|
|
|
default
|
|
|
|
)]
|
|
|
|
pub started_at: Option<OffsetDateTime>,
|
|
|
|
#[serde(
|
|
|
|
with = "time::serde::rfc3339::option",
|
|
|
|
skip_serializing_if = "Option::is_none",
|
|
|
|
default
|
|
|
|
)]
|
|
|
|
pub finished_at: Option<OffsetDateTime>,
|
|
|
|
}
|
|
|
|
|
2022-11-28 16:27:41 +01:00
|
|
|
// A `Kind` specific version made for the dump. If modified you may break the dump.
|
2022-10-16 01:39:01 +02:00
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
2022-10-13 16:03:23 +02:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub enum KindDump {
|
|
|
|
DocumentImport {
|
|
|
|
primary_key: Option<String>,
|
|
|
|
method: IndexDocumentsMethod,
|
|
|
|
documents_count: u64,
|
|
|
|
allow_index_creation: bool,
|
|
|
|
},
|
|
|
|
DocumentDeletion {
|
|
|
|
documents_ids: Vec<String>,
|
|
|
|
},
|
|
|
|
DocumentClear,
|
2023-03-07 10:02:04 +01:00
|
|
|
DocumentDeletionByFilter {
|
2023-05-02 22:36:56 +02:00
|
|
|
filter: serde_json::Value,
|
2023-03-07 10:02:04 +01:00
|
|
|
},
|
2022-10-13 16:03:23 +02:00
|
|
|
Settings {
|
2022-10-22 16:35:42 +02:00
|
|
|
settings: Box<meilisearch_types::settings::Settings<Unchecked>>,
|
2022-10-13 16:03:23 +02:00
|
|
|
is_deletion: bool,
|
|
|
|
allow_index_creation: bool,
|
|
|
|
},
|
|
|
|
IndexDeletion,
|
|
|
|
IndexCreation {
|
|
|
|
primary_key: Option<String>,
|
|
|
|
},
|
|
|
|
IndexUpdate {
|
|
|
|
primary_key: Option<String>,
|
|
|
|
},
|
2022-10-26 13:43:57 +02:00
|
|
|
IndexSwap {
|
|
|
|
swaps: Vec<IndexSwap>,
|
|
|
|
},
|
2022-10-17 17:19:17 +02:00
|
|
|
TaskCancelation {
|
|
|
|
query: String,
|
2022-10-18 13:47:22 +02:00
|
|
|
tasks: RoaringBitmap,
|
2022-10-13 16:03:23 +02:00
|
|
|
},
|
2022-10-17 18:11:28 +02:00
|
|
|
TasksDeletion {
|
2022-10-13 16:03:23 +02:00
|
|
|
query: String,
|
2022-10-17 15:11:35 +02:00
|
|
|
tasks: RoaringBitmap,
|
2022-10-13 16:03:23 +02:00
|
|
|
},
|
2022-10-24 19:08:15 +02:00
|
|
|
DumpCreation {
|
2022-10-17 17:38:31 +02:00
|
|
|
keys: Vec<Key>,
|
|
|
|
instance_uid: Option<InstanceUid>,
|
2022-10-16 01:39:01 +02:00
|
|
|
},
|
2022-10-25 10:44:58 +02:00
|
|
|
SnapshotCreation,
|
2022-10-13 16:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Task> for TaskDump {
|
|
|
|
fn from(task: Task) -> Self {
|
|
|
|
TaskDump {
|
|
|
|
uid: task.uid,
|
|
|
|
index_uid: task.index_uid().map(|uid| uid.to_string()),
|
|
|
|
status: task.status,
|
|
|
|
kind: task.kind.into(),
|
2022-10-18 13:57:58 +02:00
|
|
|
canceled_by: task.canceled_by,
|
2022-10-13 16:03:23 +02:00
|
|
|
details: task.details,
|
|
|
|
error: task.error,
|
|
|
|
enqueued_at: task.enqueued_at,
|
|
|
|
started_at: task.started_at,
|
|
|
|
finished_at: task.finished_at,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<KindWithContent> for KindDump {
|
|
|
|
fn from(kind: KindWithContent) -> Self {
|
|
|
|
match kind {
|
2022-10-21 18:03:10 +02:00
|
|
|
KindWithContent::DocumentAdditionOrUpdate {
|
2022-10-13 16:03:23 +02:00
|
|
|
primary_key,
|
|
|
|
method,
|
|
|
|
documents_count,
|
|
|
|
allow_index_creation,
|
|
|
|
..
|
|
|
|
} => KindDump::DocumentImport {
|
|
|
|
primary_key,
|
|
|
|
method,
|
|
|
|
documents_count,
|
|
|
|
allow_index_creation,
|
|
|
|
},
|
|
|
|
KindWithContent::DocumentDeletion { documents_ids, .. } => {
|
|
|
|
KindDump::DocumentDeletion { documents_ids }
|
|
|
|
}
|
2023-03-07 10:02:04 +01:00
|
|
|
KindWithContent::DocumentDeletionByFilter { filter_expr, .. } => {
|
2023-05-02 22:36:56 +02:00
|
|
|
KindDump::DocumentDeletionByFilter { filter: filter_expr }
|
2023-03-07 10:02:04 +01:00
|
|
|
}
|
2022-10-13 16:03:23 +02:00
|
|
|
KindWithContent::DocumentClear { .. } => KindDump::DocumentClear,
|
2022-10-21 18:03:10 +02:00
|
|
|
KindWithContent::SettingsUpdate {
|
|
|
|
new_settings,
|
|
|
|
is_deletion,
|
|
|
|
allow_index_creation,
|
|
|
|
..
|
2022-10-20 18:00:07 +02:00
|
|
|
} => KindDump::Settings { settings: new_settings, is_deletion, allow_index_creation },
|
2022-10-13 16:03:23 +02:00
|
|
|
KindWithContent::IndexDeletion { .. } => KindDump::IndexDeletion,
|
|
|
|
KindWithContent::IndexCreation { primary_key, .. } => {
|
|
|
|
KindDump::IndexCreation { primary_key }
|
|
|
|
}
|
|
|
|
KindWithContent::IndexUpdate { primary_key, .. } => {
|
|
|
|
KindDump::IndexUpdate { primary_key }
|
|
|
|
}
|
2022-10-17 16:30:18 +02:00
|
|
|
KindWithContent::IndexSwap { swaps } => KindDump::IndexSwap { swaps },
|
2022-10-17 17:19:17 +02:00
|
|
|
KindWithContent::TaskCancelation { query, tasks } => {
|
|
|
|
KindDump::TaskCancelation { query, tasks }
|
|
|
|
}
|
2022-10-17 15:11:35 +02:00
|
|
|
KindWithContent::TaskDeletion { query, tasks } => {
|
2022-10-17 18:11:28 +02:00
|
|
|
KindDump::TasksDeletion { query, tasks }
|
2022-10-17 15:11:35 +02:00
|
|
|
}
|
2022-11-28 16:27:41 +01:00
|
|
|
KindWithContent::DumpCreation { keys, instance_uid } => {
|
|
|
|
KindDump::DumpCreation { keys, instance_uid }
|
2022-10-20 18:00:07 +02:00
|
|
|
}
|
2022-10-25 10:44:58 +02:00
|
|
|
KindWithContent::SnapshotCreation => KindDump::SnapshotCreation,
|
2022-10-13 16:03:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-03 18:50:06 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
pub(crate) mod test {
|
2022-10-20 18:00:07 +02:00
|
|
|
use std::fs::File;
|
2023-01-30 17:17:35 +01:00
|
|
|
use std::io::Seek;
|
2022-10-20 18:00:07 +02:00
|
|
|
use std::str::FromStr;
|
2022-10-03 18:50:06 +02:00
|
|
|
|
|
|
|
use big_s::S;
|
2023-06-28 14:50:01 +02:00
|
|
|
use maplit::{btreemap, btreeset};
|
|
|
|
use meilisearch_types::facet_values_sort::FacetValuesSort;
|
2023-07-06 14:22:29 +02:00
|
|
|
use meilisearch_types::features::RuntimeTogglableFeatures;
|
2023-02-08 14:54:05 +01:00
|
|
|
use meilisearch_types::index_uid_pattern::IndexUidPattern;
|
2022-10-13 16:21:54 +02:00
|
|
|
use meilisearch_types::keys::{Action, Key};
|
2023-06-28 14:50:01 +02:00
|
|
|
use meilisearch_types::milli;
|
2022-10-20 18:00:07 +02:00
|
|
|
use meilisearch_types::milli::update::Setting;
|
2023-06-28 14:50:01 +02:00
|
|
|
use meilisearch_types::settings::{Checked, FacetingSettings, Settings};
|
2022-10-20 18:00:07 +02:00
|
|
|
use meilisearch_types::tasks::{Details, Status};
|
2022-10-03 18:50:06 +02:00
|
|
|
use serde_json::{json, Map, Value};
|
2022-10-13 16:21:54 +02:00
|
|
|
use time::macros::datetime;
|
2022-10-03 18:50:06 +02:00
|
|
|
use uuid::Uuid;
|
|
|
|
|
2022-10-20 18:00:07 +02:00
|
|
|
use crate::reader::Document;
|
|
|
|
use crate::{DumpReader, DumpWriter, IndexMetadata, KindDump, TaskDump, Version};
|
2022-10-03 18:50:06 +02:00
|
|
|
|
|
|
|
pub fn create_test_instance_uid() -> Uuid {
|
|
|
|
Uuid::parse_str("9e15e977-f2ae-4761-943f-1eaf75fd736d").unwrap()
|
|
|
|
}
|
|
|
|
|
2022-10-04 19:13:30 +02:00
|
|
|
pub fn create_test_index_metadata() -> IndexMetadata {
|
|
|
|
IndexMetadata {
|
|
|
|
uid: S("doggo"),
|
|
|
|
primary_key: None,
|
|
|
|
created_at: datetime!(2022-11-20 12:00 UTC),
|
|
|
|
updated_at: datetime!(2022-11-21 00:00 UTC),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-03 18:50:06 +02:00
|
|
|
pub fn create_test_documents() -> Vec<Map<String, Value>> {
|
|
|
|
vec![
|
|
|
|
json!({ "id": 1, "race": "golden retriever", "name": "paul", "age": 4 })
|
|
|
|
.as_object()
|
|
|
|
.unwrap()
|
|
|
|
.clone(),
|
|
|
|
json!({ "id": 2, "race": "bernese mountain", "name": "tamo", "age": 6 })
|
|
|
|
.as_object()
|
|
|
|
.unwrap()
|
|
|
|
.clone(),
|
|
|
|
json!({ "id": 3, "race": "great pyrenees", "name": "patou", "age": 5 })
|
|
|
|
.as_object()
|
|
|
|
.unwrap()
|
|
|
|
.clone(),
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create_test_settings() -> Settings<Checked> {
|
|
|
|
let settings = Settings {
|
2023-01-11 12:33:56 +01:00
|
|
|
displayed_attributes: Setting::Set(vec![S("race"), S("name")]),
|
|
|
|
searchable_attributes: Setting::Set(vec![S("name"), S("race")]),
|
|
|
|
filterable_attributes: Setting::Set(btreeset! { S("race"), S("age") }),
|
|
|
|
sortable_attributes: Setting::Set(btreeset! { S("age") }),
|
|
|
|
ranking_rules: Setting::NotSet,
|
|
|
|
stop_words: Setting::NotSet,
|
2023-07-24 17:00:18 +02:00
|
|
|
non_separator_tokens: Setting::NotSet,
|
|
|
|
separator_tokens: Setting::NotSet,
|
|
|
|
dictionary: Setting::NotSet,
|
2023-01-11 12:33:56 +01:00
|
|
|
synonyms: Setting::NotSet,
|
|
|
|
distinct_attribute: Setting::NotSet,
|
|
|
|
typo_tolerance: Setting::NotSet,
|
2023-06-28 14:50:01 +02:00
|
|
|
faceting: Setting::Set(FacetingSettings {
|
|
|
|
max_values_per_facet: Setting::Set(111),
|
|
|
|
sort_facet_values_by: Setting::Set(
|
|
|
|
btreemap! { S("age") => FacetValuesSort::Count },
|
|
|
|
),
|
|
|
|
}),
|
2023-01-11 12:33:56 +01:00
|
|
|
pagination: Setting::NotSet,
|
2022-10-03 18:50:06 +02:00
|
|
|
_kind: std::marker::PhantomData,
|
|
|
|
};
|
|
|
|
settings.check()
|
|
|
|
}
|
|
|
|
|
2022-10-13 16:03:23 +02:00
|
|
|
pub fn create_test_tasks() -> Vec<(TaskDump, Option<Vec<Document>>)> {
|
2022-10-03 18:50:06 +02:00
|
|
|
vec![
|
|
|
|
(
|
2022-10-13 16:03:23 +02:00
|
|
|
TaskDump {
|
2022-10-03 18:50:06 +02:00
|
|
|
uid: 0,
|
2022-10-13 16:03:23 +02:00
|
|
|
index_uid: Some(S("doggo")),
|
2022-10-03 18:50:06 +02:00
|
|
|
status: Status::Succeeded,
|
2022-10-13 16:03:23 +02:00
|
|
|
kind: KindDump::DocumentImport {
|
2022-10-11 18:26:49 +02:00
|
|
|
method: milli::update::IndexDocumentsMethod::UpdateDocuments,
|
2022-10-09 17:30:34 +02:00
|
|
|
allow_index_creation: true,
|
2022-10-13 16:03:23 +02:00
|
|
|
primary_key: Some(S("bone")),
|
|
|
|
documents_count: 12,
|
2022-10-09 17:30:34 +02:00
|
|
|
},
|
2022-10-18 13:57:58 +02:00
|
|
|
canceled_by: None,
|
2022-10-21 18:03:10 +02:00
|
|
|
details: Some(Details::DocumentAdditionOrUpdate {
|
2022-10-13 16:03:23 +02:00
|
|
|
received_documents: 12,
|
|
|
|
indexed_documents: Some(10),
|
2022-10-03 18:50:06 +02:00
|
|
|
}),
|
|
|
|
error: None,
|
|
|
|
enqueued_at: datetime!(2022-11-11 0:00 UTC),
|
|
|
|
started_at: Some(datetime!(2022-11-20 0:00 UTC)),
|
|
|
|
finished_at: Some(datetime!(2022-11-21 0:00 UTC)),
|
|
|
|
},
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
(
|
2022-10-13 16:03:23 +02:00
|
|
|
TaskDump {
|
2022-10-03 18:50:06 +02:00
|
|
|
uid: 1,
|
2022-10-13 16:03:23 +02:00
|
|
|
index_uid: Some(S("doggo")),
|
2022-10-03 18:50:06 +02:00
|
|
|
status: Status::Enqueued,
|
2022-10-13 16:03:23 +02:00
|
|
|
kind: KindDump::DocumentImport {
|
2022-10-11 18:26:49 +02:00
|
|
|
method: milli::update::IndexDocumentsMethod::UpdateDocuments,
|
2022-10-09 17:30:34 +02:00
|
|
|
allow_index_creation: true,
|
2022-10-13 16:03:23 +02:00
|
|
|
primary_key: None,
|
|
|
|
documents_count: 2,
|
2022-10-09 17:30:34 +02:00
|
|
|
},
|
2022-10-18 13:57:58 +02:00
|
|
|
canceled_by: None,
|
2022-10-21 18:03:10 +02:00
|
|
|
details: Some(Details::DocumentAdditionOrUpdate {
|
2022-10-13 16:03:23 +02:00
|
|
|
received_documents: 2,
|
|
|
|
indexed_documents: None,
|
|
|
|
}),
|
2022-10-03 18:50:06 +02:00
|
|
|
error: None,
|
|
|
|
enqueued_at: datetime!(2022-11-11 0:00 UTC),
|
2022-10-13 16:03:23 +02:00
|
|
|
started_at: None,
|
|
|
|
finished_at: None,
|
2022-10-03 18:50:06 +02:00
|
|
|
},
|
2022-10-10 18:57:27 +02:00
|
|
|
Some(vec![
|
2022-10-20 18:00:07 +02:00
|
|
|
json!({ "id": 4, "race": "leonberg" }).as_object().unwrap().clone(),
|
|
|
|
json!({ "id": 5, "race": "patou" }).as_object().unwrap().clone(),
|
2022-10-10 18:57:27 +02:00
|
|
|
]),
|
2022-10-03 18:50:06 +02:00
|
|
|
),
|
|
|
|
(
|
2022-10-13 16:03:23 +02:00
|
|
|
TaskDump {
|
2022-10-03 18:50:06 +02:00
|
|
|
uid: 5,
|
2022-10-13 16:03:23 +02:00
|
|
|
index_uid: Some(S("catto")),
|
2022-10-03 18:50:06 +02:00
|
|
|
status: Status::Enqueued,
|
2022-10-13 16:03:23 +02:00
|
|
|
kind: KindDump::IndexDeletion,
|
2022-10-18 13:57:58 +02:00
|
|
|
canceled_by: None,
|
2022-10-03 18:50:06 +02:00
|
|
|
details: None,
|
|
|
|
error: None,
|
|
|
|
enqueued_at: datetime!(2022-11-15 0:00 UTC),
|
|
|
|
started_at: None,
|
|
|
|
finished_at: None,
|
|
|
|
},
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create_test_api_keys() -> Vec<Key> {
|
|
|
|
vec![
|
|
|
|
Key {
|
|
|
|
description: Some(S("The main key to manage all the doggos")),
|
|
|
|
name: Some(S("doggos_key")),
|
|
|
|
uid: Uuid::from_str("9f8a34da-b6b2-42f0-939b-dbd4c3448655").unwrap(),
|
|
|
|
actions: vec![Action::DocumentsAll],
|
2023-02-08 14:54:05 +01:00
|
|
|
indexes: vec![IndexUidPattern::from_str("doggos").unwrap()],
|
2022-10-03 18:50:06 +02:00
|
|
|
expires_at: Some(datetime!(4130-03-14 12:21 UTC)),
|
|
|
|
created_at: datetime!(1960-11-15 0:00 UTC),
|
|
|
|
updated_at: datetime!(2022-11-10 0:00 UTC),
|
|
|
|
},
|
|
|
|
Key {
|
|
|
|
description: Some(S("The master key for everything and even the doggos")),
|
|
|
|
name: Some(S("master_key")),
|
|
|
|
uid: Uuid::from_str("4622f717-1c00-47bb-a494-39d76a49b591").unwrap(),
|
|
|
|
actions: vec![Action::All],
|
2023-02-08 14:54:05 +01:00
|
|
|
indexes: vec![IndexUidPattern::all()],
|
2022-10-03 18:50:06 +02:00
|
|
|
expires_at: None,
|
|
|
|
created_at: datetime!(0000-01-01 00:01 UTC),
|
|
|
|
updated_at: datetime!(1964-05-04 17:25 UTC),
|
|
|
|
},
|
|
|
|
Key {
|
|
|
|
description: Some(S("The useless key to for nothing nor the doggos")),
|
|
|
|
name: Some(S("useless_key")),
|
|
|
|
uid: Uuid::from_str("fb80b58b-0a34-412f-8ba7-1ce868f8ac5c").unwrap(),
|
|
|
|
actions: vec![],
|
|
|
|
indexes: vec![],
|
|
|
|
expires_at: None,
|
|
|
|
created_at: datetime!(400-02-29 0:00 UTC),
|
|
|
|
updated_at: datetime!(1024-02-29 0:00 UTC),
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create_test_dump() -> File {
|
|
|
|
let instance_uid = create_test_instance_uid();
|
2022-10-22 16:35:42 +02:00
|
|
|
let dump = DumpWriter::new(Some(instance_uid)).unwrap();
|
2022-10-03 18:50:06 +02:00
|
|
|
|
|
|
|
// ========== Adding an index
|
|
|
|
let documents = create_test_documents();
|
|
|
|
let settings = create_test_settings();
|
|
|
|
|
2022-10-20 18:00:07 +02:00
|
|
|
let mut index = dump.create_index("doggos", &create_test_index_metadata()).unwrap();
|
2022-10-03 18:50:06 +02:00
|
|
|
for document in &documents {
|
|
|
|
index.push_document(document).unwrap();
|
|
|
|
}
|
2022-10-17 17:04:52 +02:00
|
|
|
index.flush().unwrap();
|
2022-10-03 18:50:06 +02:00
|
|
|
index.settings(&settings).unwrap();
|
|
|
|
|
|
|
|
// ========== pushing the task queue
|
|
|
|
let tasks = create_test_tasks();
|
|
|
|
|
|
|
|
let mut task_queue = dump.create_tasks_queue().unwrap();
|
|
|
|
for (task, update_file) in &tasks {
|
2022-10-10 19:57:47 +02:00
|
|
|
let mut update = task_queue.push_task(task).unwrap();
|
|
|
|
if let Some(update_file) = update_file {
|
|
|
|
for u in update_file {
|
|
|
|
update.push_document(u).unwrap();
|
|
|
|
}
|
|
|
|
}
|
2022-10-03 18:50:06 +02:00
|
|
|
}
|
2022-10-17 17:04:52 +02:00
|
|
|
task_queue.flush().unwrap();
|
2022-10-03 18:50:06 +02:00
|
|
|
|
|
|
|
// ========== pushing the api keys
|
|
|
|
let api_keys = create_test_api_keys();
|
|
|
|
|
|
|
|
let mut keys = dump.create_keys().unwrap();
|
|
|
|
for key in &api_keys {
|
|
|
|
keys.push_key(key).unwrap();
|
|
|
|
}
|
2022-10-17 17:04:52 +02:00
|
|
|
keys.flush().unwrap();
|
2022-10-03 18:50:06 +02:00
|
|
|
|
2023-07-06 14:22:29 +02:00
|
|
|
// ========== experimental features
|
|
|
|
let features = create_test_features();
|
|
|
|
|
|
|
|
dump.create_experimental_features(features).unwrap();
|
2023-06-26 12:24:55 +02:00
|
|
|
|
2022-10-03 18:50:06 +02:00
|
|
|
// create the dump
|
|
|
|
let mut file = tempfile::tempfile().unwrap();
|
|
|
|
dump.persist_to(&mut file).unwrap();
|
2023-01-30 17:17:35 +01:00
|
|
|
file.rewind().unwrap();
|
2022-10-03 18:50:06 +02:00
|
|
|
|
|
|
|
file
|
|
|
|
}
|
|
|
|
|
2023-07-06 14:22:29 +02:00
|
|
|
fn create_test_features() -> RuntimeTogglableFeatures {
|
|
|
|
RuntimeTogglableFeatures { vector_store: true, ..Default::default() }
|
|
|
|
}
|
|
|
|
|
2022-10-03 18:50:06 +02:00
|
|
|
#[test]
|
2022-10-04 19:13:30 +02:00
|
|
|
fn test_creating_and_read_dump() {
|
2022-10-03 18:50:06 +02:00
|
|
|
let mut file = create_test_dump();
|
2022-10-13 16:21:54 +02:00
|
|
|
let mut dump = DumpReader::open(&mut file).unwrap();
|
2022-10-03 18:50:06 +02:00
|
|
|
|
|
|
|
// ==== checking the top level infos
|
|
|
|
assert_eq!(dump.version(), Version::V6);
|
|
|
|
assert!(dump.date().is_some());
|
2022-10-20 18:00:07 +02:00
|
|
|
assert_eq!(dump.instance_uid().unwrap().unwrap(), create_test_instance_uid());
|
2022-10-03 18:50:06 +02:00
|
|
|
|
|
|
|
// ==== checking the index
|
|
|
|
let mut indexes = dump.indexes().unwrap();
|
|
|
|
let mut index = indexes.next().unwrap().unwrap();
|
|
|
|
assert!(indexes.next().is_none()); // there was only one index in the dump
|
|
|
|
|
|
|
|
for (document, expected) in index.documents().unwrap().zip(create_test_documents()) {
|
|
|
|
assert_eq!(document.unwrap(), expected);
|
|
|
|
}
|
|
|
|
assert_eq!(index.settings().unwrap(), create_test_settings());
|
2022-10-04 19:13:30 +02:00
|
|
|
assert_eq!(index.metadata(), &create_test_index_metadata());
|
|
|
|
|
|
|
|
drop(index);
|
|
|
|
drop(indexes);
|
2022-10-03 18:50:06 +02:00
|
|
|
|
|
|
|
// ==== checking the task queue
|
2022-10-17 17:38:31 +02:00
|
|
|
for (task, expected) in dump.tasks().unwrap().zip(create_test_tasks()) {
|
2022-10-03 18:50:06 +02:00
|
|
|
let (task, content_file) = task.unwrap();
|
|
|
|
assert_eq!(task, expected.0);
|
|
|
|
|
|
|
|
if let Some(expected_update) = expected.1 {
|
|
|
|
assert!(
|
|
|
|
content_file.is_some(),
|
|
|
|
"A content file was expected for the task {}.",
|
|
|
|
expected.0.uid
|
|
|
|
);
|
2022-10-20 18:00:07 +02:00
|
|
|
let updates = content_file.unwrap().collect::<Result<Vec<_>, _>>().unwrap();
|
2022-10-10 18:57:27 +02:00
|
|
|
assert_eq!(updates, expected_update);
|
2022-10-03 18:50:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ==== checking the keys
|
2022-10-17 17:38:31 +02:00
|
|
|
for (key, expected) in dump.keys().unwrap().zip(create_test_api_keys()) {
|
2022-10-03 18:50:06 +02:00
|
|
|
assert_eq!(key.unwrap(), expected);
|
|
|
|
}
|
2023-07-06 14:22:29 +02:00
|
|
|
|
|
|
|
// ==== checking the features
|
|
|
|
let expected = create_test_features();
|
|
|
|
assert_eq!(dump.features().unwrap().unwrap(), expected);
|
2022-10-03 18:50:06 +02:00
|
|
|
}
|
|
|
|
}
|