use std::collections::BTreeMap;
use std::collections::HashMap;
use anyhow::Result;
use serde::Deserialize;
use serde::Serialize;
use crate::*;
#[derive(Serialize, Deserialize, PartialEq)]
pub struct IndexDescription {
pub collection_name: String,
pub field_names: Vec<String>,
pub options: IndexOptions,
pub table_name: String,
}
#[derive(Serialize, Deserialize, PartialEq)]
pub struct CollectionDescription {
pub fields: BTreeMap<String, String>,
}
#[derive(Serialize, Deserialize)]
pub struct MetadataDocument {
pub version: u64, pub schema_version: u64, pub indices_by_collection: HashMap<String, IndexDescription>,
pub collections: HashMap<String, CollectionDescription>,
}
impl MetadataDocument {
pub fn compare(&self, other: &Self) -> Result<()> {
if self.version != other.version {
anyhow::bail!(
"Metadata version mimatch. This implementation of AnonDB does not support metadata version migration."
);
}
if self.indices_by_collection == other.indices_by_collection
&& self.collections == other.collections
{
return Ok(());
}
anyhow::bail!("Changes to schema detected, refusing to start");
}
}